VOGONS


Printing & clipboard-exchange - kludgy workaround for DOSBox under Windows

Topic actions

  • This topic is locked. You cannot reply or edit posts.

First post, by emendelson

User metadata
Rank Oldbie
Rank
Oldbie

With apologies to Qbix, who wrote that something like this would mislead people into thinking that DOSBox was for applications, not only for games:

Here is a kludgy, unofficial, unsupported, and probably very buggy system for printing from DOSBox to the current Windows printer. It supports DOS games that can output PCL, PostScript, or ASCII text to a printer - provided that those games can "print to a file." It also makes it possible to "print" PDF files from DOSBox. It doesn't matter if your Windows printer supports PCL or PostScript - this system takes PCL or PostScript output, and converts it so that it prints to any Windows printer, including primitive GDI printers.

Also, this system makes it possible to send text to the Windows clipboard and receive text from the Windows clipboard.

To use it, place the contents of the linked ZIP file into the same directory with your copy of DOSBox.exe. The contents of the ZIP file are: the DOSBoxPrinter.exe executable and two folders (PrintApps and PrintOut).

Optional: create a shortcut to DOSBoxPrinter.exe in which you add to DOSBoxPrinter.exe the same command-line parameters that you use when launching DOSBox.

Run DOSBoxPrinter.exe. It will launch the copy of DOSBox.exe in the same directory, with the no-console switch, and DOSBox will mount as drive P: the PrintOut folder that you copied from the ZIP file. If you add any command-line parameters to DOSBoxPrinter.exe, the same command-line parameters will be used when the DOSBoxPrinter program launches DOSBox.exe. The DOSBoxPrinter.exe program will continue running until you exit DOSBox. If you want to quit it at any time, right-click on the gray icon that appears in the taskbar tray while the program is running.

To print from a DOS game that supports PCL output, set the output print file in the game to "P:\OUTPUT.PCL".

To print from a DOS game that supports PostScript output, set the output print file in the game to "P:\OUTPUT.PS".

To print from a DOS game that only prints ASCII output, set the output print file in the game to "P:\OUTPUT.TMP" (notice: TMP, not TXT). If your game (like EDIT.COM) only supports LPT1, etc., but lets you enter a four-character port name, then try P:\@ instead of LPT1.

To create a PDF file instead of printing, change the output file name to PCLTOPDF.PCL, PSTOPDF.PS, or TXTTOPDF.TMP (depending on the kind of output your game supports). The PDF file will be created in a folder on your desktop named PDF, and will have an arbitrary name based on the current date and time. The PDF folder will be created if needed. (If your game, like EDIT.COM, only supports LPT1 etc., but lets you enter a four-character port name, then try P:\# instead of LPT1.)

To give the PDF output files a filename that includes the name of the game from which you created them, enter this command before running the game:

echo Name of My Game>p:\app-id.fil

The output PDF file will have a filename that looks like "Name of My Game 20120630124567.pdf". Delete p:\app-id.fil or replace it before running a different game.

When printing or creating a PDF file from ASCII output, the program tries to guess whether you are in North America (in which case it prints or creates a PDF with the letter page size) or elsewhere (in which case it prints or creates a PDF in the A4 page size). If it gets this wrong, please let me know. (When creating a PDF file from PostScript or PCL output, the program creates a PDF file with the page size specified in the DOS game.)

To send plain ASCII text to the Windows clipboard, copy to a file named P:\CLIPOUT.TMP. The contents of the file will be transferred to the Windows clipboard and the CLIPOUT.TMP file itself will be deleted.

If you use upper-ASCII characters (accented letters, etc), and you are in North America, use this filename instead: P:\CLIP437.TMP. If you are in Europe or any other region where the DOS codepage is 850, then use P:\CLIP850.TMP.

EDIT: For a memory-resident program that you can use to capture part or all of the screen so that it can be sent to the Windows clipboard (by being written to one of the three CLIP???.TMP filenames listed above) see a later post in this thread: Printing & clipboard-exchange - kludgy workaround for DOSBox under Windows

To get the contents of the Windows clipboard into DOSBox, either (1) run 4DOS and then run the 4DOS batch file P:\GETCLIP.BTM or (2) perform the following actions:

echo .>p:\getclip.tmp
[wait a second or two]
p:
rescan
type p:\clip.txt

EDIT: Or, in the current version of the program, simply press the {PAUSE} key on the keyboard to type the contents of the Windows clipboard into DOSBox at the current cursor location.

The program tries to handle upper-ASCII (accented etc.) characters correctly. If this fails, please let me know.

To view the name of the current default Windows printer, either (1) run 4DOS and then run the 4DOS batch file P:\WHICHPTR.BTM or (2) perform the following actions:

echo .>p:\whichptr.tmp
[wait a second or two]
p:
rescan
type p:\defptr.txt
del p:\defptr.txt

This system comes with no support of any kind, but I'll try to fix any bugs that get reported here.

The download is here:

https://dl.dropbox.com/u/271144/DOSBoxPrinter.zip

Last edited by emendelson on 2013-07-28, 19:04. Edited 4 times in total.

Reply 1 of 19, by emendelson

User metadata
Rank Oldbie
Rank
Oldbie

Update. The system now includes an option to select a specific Windows printer when printing from DOSBox. The printer can be any printer supported by Windows; it does not need to support PCL or PostScript. To use this option, set the output file in your DOS game to P:\SELECT.PCL for games that support PCL output, P:\SELECT.PS for games that support PostScript output, or P:\SELECT.TMP for games that print only ASCII output.

Last edited by emendelson on 2013-02-13, 05:08. Edited 1 time in total.

Reply 2 of 19, by Joey_sw

User metadata
Rank Oldbie
Rank
Oldbie

your current clipboard implementation doesn't really useful.

if you manage to do it like windows VDM (command prompt), it can be 'pasted' as you running the dos apps.

usually i run clipper-based apps on VDM,
and hit {Alt}+Space to invoke the menu,
click "Edit",
click "Paste"

as long the clipper apps doesn't expect the user to hit {Esc} or Function Keys {F#} or Arrow/Directional Keys or other Control Keys (Ctrl or Alt, Shift, etc...),
I could simulate the series of keypress into a text-clipboard, and paste it like above.

I often use that to entry batch of records.

-fffuuu

Reply 3 of 19, by Dominus

User metadata
Rank DOSBox Moderator
Rank
DOSBox Moderator

Hevhe, that's what you get when doing something like this for dosbox... 😉

But can't you send the clipboard directly to Dosbox? On OSX I'd script it roughly like 'get clipboard'(not sure how that can be done in Apple script, never done it before), then activate dosbox and send keypresses content of clipboard. Can't this be done with auto-it or autohotkey on Windows?

Windows 3.1x guide for DOSBox
60 seconds guide to DOSBox
DOSBox SVN snapshot for macOS (10.4-11.x ppc/intel 32/64bit) notarized for gatekeeper

Reply 5 of 19, by Dominus

User metadata
Rank DOSBox Moderator
Rank
DOSBox Moderator

Joey_sw, dosbox is not anywhere near the command prompt. Since dos had no clipboard this is not going to work as you want.
It will always be a kludgy workaround to do this.

Windows 3.1x guide for DOSBox
60 seconds guide to DOSBox
DOSBox SVN snapshot for macOS (10.4-11.x ppc/intel 32/64bit) notarized for gatekeeper

Reply 6 of 19, by emendelson

User metadata
Rank Oldbie
Rank
Oldbie
Dominus wrote:

Hevhe, that's what you get when doing something like this for dosbox... ;)

But can't you send the clipboard directly to Dosbox? On OSX I'd script it roughly like 'get clipboard'(not sure how that can be done in Apple script, never done it before), then activate dosbox and send keypresses content of clipboard. Can't this be done with auto-it or autohotkey on Windows?

Your wish is my command. The current version of DOSBoxPrinter.exe will paste the current contents of the Windows clipboard into DOSBox when you press the {PAUSE} key. (I tried Ctrl-Shift-V and Ctrl-Alt-V and Shift-Alt-V, but they all left the keyboard in a strange state in DOSBox.)

The problem with this (and the reason I didn't do it earlier) is that it only works with lower ASCII characters, so if there are any upper-ASCII characters (accented characters, diacritics, etc.) in the keyboard buffer, they may produce unexpected results. This problem doesn't occur with the method I provided earlier, where you read a file in DOSBox to get the contents of the Windows clipboard. EDIT: It now works with upper-ASCII characters also.

The only way to solve this would be parse every character in the clipboard buffer and replace any upper-ASCII character with an Alt-### string, and that's more than I'm willing to try.

(Incidentally, this is not easy at all under AppleScript in OS X, but it's certainly possible in AutoIt.)

Last edited by emendelson on 2013-07-28, 19:07. Edited 1 time in total.

Reply 7 of 19, by Dominus

User metadata
Rank DOSBox Moderator
Rank
DOSBox Moderator

Thanks for goung through all that trouble. I hope people appreciate it!

Windows 3.1x guide for DOSBox
60 seconds guide to DOSBox
DOSBox SVN snapshot for macOS (10.4-11.x ppc/intel 32/64bit) notarized for gatekeeper

Reply 8 of 19, by emendelson

User metadata
Rank Oldbie
Rank
Oldbie
Dominus wrote:

Thanks for going through all that trouble. I hope people appreciate it!

I've received so much help on this forum from you, ripsaw8080, TeaRex, h-a-l-9000, wd, HunterZ, ykhwong, and others, that it's a pleasure to offer something that may be even minimally useful to someone.

Reply 10 of 19, by RetroComp

User metadata
Rank Newbie
Rank
Newbie

Hi emendelson

emendelson wrote:

Here is a kludgy, unofficial, unsupported, and probably very buggy system for printing from DOSBox to the current Windows printer. It supports DOS games that can output PCL, PostScript, or ASCII text to a printer - provided that those games can "print to a file." It also makes it possible to "print" PDF files from DOSBox. It doesn't matter if your Windows printer supports PCL or PostScript - this system takes PCL or PostScript output, and converts it so that it prints to any Windows printer, including primitive GDI printers.

Also, this system makes it possible to send text to the Windows clipboard and receive text from the Windows clipboard.

Can you share the .au3 font file from your print solution, too?
I want to see how you implemented the "listener" to detect folder changes.
(Well, if you cannot share it, I will understand. No questions.)

I'm thinking about to join your work with this (barely documented) open source solution to emulate, convert and print old dot matrix "epson esc/p" files:
http://sourceforge.net/projects/txtprint/?source=navbar

The txtprint is built in xHarbour, and its implementation of "ESC/P" encoding is about 60% and the output is reasonable (and free...)
(This is a good tip.)

I´m learning a little bit of Harbour language right now to improve the txtprint. Basically, to add an option to choose the codepage before printing.

If I get some advance, I will share too.

Thank you for your efforts and the creation of dosboxprinter.
[]s Retrocomp.

Reply 11 of 19, by emendelson

User metadata
Rank Oldbie
Rank
Oldbie

For complicated reasons, I don't want to post the full code, but the file-watcher is easy. Define the directory that you want to watch and the file that you want to watch for, and then use this code:

... launch DOSBox here...

$procname = "dosbox.exe"
While 1
If Not ProcessExists($procname) Then
Exit
EndIf
If FileExists($prtfile) Then
... etc., etc.
EndIf
If FileExists($somethingElse) Then
... etc., etc.,
EndIf
Sleep(500)
Wend

$prtfile is defined as a specific file in the watched directory (which you define in relation to the folder from which the executable is run). You can similarly specify other files to watch for, and include them all in the same while/wend block. As written this checks for the existence of the files once every 500 milliseconds.

That should be all you need, and it's extremely simple.

Reply 12 of 19, by emendelson

User metadata
Rank Oldbie
Rank
Oldbie

It took me a long time to figure out something that should have been obvious, but it's easy to enhance this system to copy text from inside DOSBox (in text mode) to the Windows clipboard.

Start by downloading this file:

https://dl.dropboxusercontent.com/u/271144/DOSBoxSnipper.zip

It contains three patched versions of Tom Kihlken's SNIPPER.COM utility, originally written for PC Magazine. Copy them to the C: or any other drive that you use with the DOSBox Printer. If you only want to copy plain ASCII text from DOSBox to the Windows clipboard, run SNIPDBP.COM. If you expect to want to copy text that includes upper-ASCII (accented etc.) characters, and you are in North America, run SNIP437. COM; if you are in Western Europe, run SNIP850.COM instead.

Now, when you want to copy some text to the Windows clipboard, press Alt-W in DOSBox. Use the arrow keys to move the block cursor to the point where you want to START copying; press Enter, then use the arrow keys to select the block of text that you want to copy. When you are done, press the letter F (or press Enter, and choose F from the menu). You will be prompted to enter a filename, but use the default filename shown. After a second or two, the text you copied should be available in the Windows clipboard.

These programs are patched to save the selected text to a file, as described in the first post in this thread. The point of the programs is to make it possible to send text to the Windows clipboard without interfering with whatever program is running in DOSBox.

EDIT: Corrected mistyped filenames.

Last edited by emendelson on 2013-07-28, 13:04. Edited 2 times in total.

Reply 16 of 19, by Dominus

User metadata
Rank DOSBox Moderator
Rank
DOSBox Moderator

Seriously? After I just told you to try it in the other thread?

Windows 3.1x guide for DOSBox
60 seconds guide to DOSBox
DOSBox SVN snapshot for macOS (10.4-11.x ppc/intel 32/64bit) notarized for gatekeeper

Reply 18 of 19, by Dominus

User metadata
Rank DOSBox Moderator
Rank
DOSBox Moderator

You want to know something you could have tested already.

Windows 3.1x guide for DOSBox
60 seconds guide to DOSBox
DOSBox SVN snapshot for macOS (10.4-11.x ppc/intel 32/64bit) notarized for gatekeeper