1 /* This is a screen print program for MMURTL. It runs
\r
2 like any other application on the system except it
\r
3 looks for a Global Hot key (CTRL-ALT-PrintScreen)
\r
4 and prints the REAL screen to LPT1 or a file.
\r
6 The screen print is straight text with CR/LF at the
\r
7 end of each line. Nulls and non-printable characters
\r
8 are converted to spaces.
\r
14 #include "\OSSource\MKernel.h"
\r
15 #include "\OSSource\MJob.h"
\r
16 #include "\OSSource\MVid.h"
\r
17 #include "\OSSource\MData.h"
\r
18 #include "\OSSource\MTimer.h"
\r
19 #include "\OSSource\MDevDrv.h"
\r
20 #include "\OSSource\Parallel.h"
\r
24 struct RqBlkType *pRqBlk; /* A pointer to a Reqeust Block */
\r
25 unsigned long AnExch; /* Where we wait for Requests */
\r
26 unsigned long Message[2]; /* The Message with the Request */
\r
27 long rqHndlG; /* Used for global print request */
\r
28 long rqHndlK; /* Used for keyboard request */
\r
32 long ourJob, printJob;
\r
36 long keycode, keycodeG;
\r
38 unsigned char buf[4160]; /* for a snapshot of the screen */
\r
40 /***************************************************
\r
41 Copies active screen memory to a working buffer.
\r
42 and beeps to let user know it's been done.
\r
43 ***************************************************/
\r
44 void CaptureScreen(void)
\r
46 CopyData(0xB8000, buf, 4000);
\r
47 Tone(1000,15); /* 1000 Hz for 100ms */
\r
48 Tone(300,15); /* 300 Hz for 100ms */
\r
52 /***************************************************
\r
53 This filles all nulls and NON ASCII chars in
\r
54 the capture buffer with spaces.
\r
55 ****************************************************/
\r
60 for (i=0; i<4000; i+=2)
\r
62 if ((buf[i] < 0x20) || (buf[i] > 0x7E))
\r
67 /***************************************************
\r
68 Sends the contents of the processed screen buffer
\r
69 to the file the user specified. LF is added to
\r
71 ****************************************************/
\r
73 void ScreenToFile(FILE *fh)
\r
76 for (i=0; i<25; i++)
\r
78 for (j=0; j<160; j+=2)
\r
80 fputc(buf[(i*160)+j], fh);
\r
87 /***************************************************
\r
88 Sends the contents of the processed screen buffer
\r
89 to the LPT1 device. CR/LF is added to each line.
\r
90 ****************************************************/
\r
92 void ScreenToLPT(void)
\r
98 /* If device status went OK, we open the printer port */
\r
100 /* device, dOpNum, dLBA, dnBlocks, pData */
\r
101 erc = DeviceOp(3, CmdOpenL, 0, 0, &i);
\r
105 printf("OpenLPT ERROR: %d \r\n", erc);
\r
109 for (i=0; i<25; i++)
\r
111 for (j=0; j<160; j+=2)
\r
113 erc = DeviceOp(3, CmdWriteB, 0, 1, &buf[(i*160)+j]);
\r
117 erc = DeviceOp(3, CmdWriteB, 0, 1, "\r");
\r
118 erc = DeviceOp(3, CmdWriteB, 0, 1, "\n");
\r
122 erc = DeviceOp(3, CmdWriteB, 0, 1, "\f");
\r
125 printf("Can't write to LPT. Error: %d\r\n", erc);
\r
127 /* device, dOpNum, dLBA, dnBlocks, pData */
\r
128 erc = DeviceOp(3, CmdCloseL, 0, 0, &i);
\r
130 printf("Can't close LPT. Error: %d\r\n", erc);
\r
135 /***************************************************
\r
136 Displays the menu after a user does something
\r
137 ****************************************************/
\r
141 printf("CTRL-ALT-PrintScrn will print the screen from any job you're viewing.\r\n");
\r
142 printf("Press:\r\n");
\r
143 printf(" 1) To direct screen prints to LPT1/Printer (default).\r\n");
\r
144 printf(" 2) To direct screen prints to a file.\r\n");
\r
145 printf(" 3) To terminte the screen print utility.\r\n\n");
\r
148 /***************************************************
\r
149 Main entry point for SPU.
\r
150 ****************************************************/
\r
152 void main(long argc, char *argv[])
\r
154 unsigned long OSError, x, y;
\r
155 unsigned char c, ExitChar;
\r
157 GetJobNum(&ourJob);
\r
158 SetJobName("ScreenPrint", 11);
\r
160 FillData(Filename, 80, ' ');
\r
164 OSError = AllocExch(&AnExch); /* get an exchange */
\r
166 if (OSError) /* look for a kernel error */
\r
169 SetNormVid(WHITE|BGBLACK);
\r
172 printf("Screen Print Utility installed as job number: %d.\r\n\n", ourJob);
\r
174 /* Leave a global request for a key with the keyboard service */
\r
176 OSError = Request("KEYBOARD", 2, AnExch, &rqHndlG, 0, &keycodeG,
\r
179 printf("Error %d on Global Keyboard Request\r\n", OSError);
\r
181 OSError = Request("KEYBOARD", 1, AnExch, &rqHndlK, 0, &keycode,
\r
182 4, 0, 0, 1, 0, 0); /* 1 in dData0 = Wait for key */
\r
185 printf("Error %d on ReadKey Request\r\n", OSError);
\r
191 /* We now have two requests waiting at the keyboard service.
\r
192 One is for the global key, the other is for a ReadKbd.
\r
193 When we Wait(), we will get one or the other back. We find
\r
194 out which one by checking the handle to see which it matches.
\r
195 Eaither someone wants the screen printed or the user
\r
196 has selcted a menu item.
\r
199 OSError = WaitMsg(AnExch, Message); /* Exch & pointer */
\r
204 if (Message[0] == rqHndlK) /* it was a menu item */
\r
207 c = keycode & 0x7f; /* lop off upper stuff in keycode */
\r
212 printf("Screen print directed to printer (LPT1)\r\n");
\r
213 strcpy(Filename, "LPT");
\r
217 printf("\r\nEnter filename to print to: ");
\r
219 EditLine(Filename, cbFilename, 50, &cbFilename,
\r
220 &ExitChar, BLACK|BGWHITE);
\r
221 if ((ExitChar == 0x0d) && (cbFilename))
\r
223 Filename[cbFilename] = 0; /* null terminte */
\r
231 /* cancel the global key request */
\r
232 OSError = Request("KEYBOARD", 3, AnExch, &rqHndlG, 0, 0,
\r
233 0, 0, 0, ourJob, 0, 0);
\r
234 OSError = WaitMsg(AnExch, Message);
\r
235 DeAllocExch(AnExch);
\r
239 /* leave another keyboard request */
\r
240 OSError = Request("KEYBOARD", 1, AnExch, &rqHndlK, 0, &keycode,
\r
241 4, 0, 0, 1, 0, 0); /* 1 in dData0 = Wait for key */
\r
245 else if (Message[0] == rqHndlG) /* It's a screen print!! */
\r
247 if ((keycodeG & 0xff) == 0x1C) /* it's us! */
\r
253 fh = fopen(Filename, "a");
\r
260 printf("Can't open file: %s\r\n", Filename);
\r
265 GetVidOwner(&printJob);
\r
267 printf("Screen print sent to %s for job %d\r\n\n",
\r
268 Filename, printJob);
\r
270 printf("Screen print sent to LPT1 for job %d\r\n\n",
\r
275 /* Leave another global request with the keyboard service */
\r
277 OSError = Request("KEYBOARD", 2, AnExch, &rqHndlG, 0, &keycodeG,
\r
283 printf("Error %d on WaitMsg from kernel\r\n", OSError);
\r
284 } /* Loop while(1) */
\r