]> pd.if.org Git - mmurtl/blob - ossource/video.asm
autocommit for file dated 2003-12-29 17:36:54
[mmurtl] / ossource / video.asm
1 ;   MMURTL Operating System Source Code\r
2 ;   Copyright 1991,1992,1993,1994 Richard A. Burgess\r
3 ;   ALL RIGHTS RESERVED\r
4 ;   Version 1.0\r
5 \r
6 ;This module contains ALL Video code & Data\r
7 ;    (along with EdLine for lack of a better place)\r
8 ;\r
9 ;This module supports MMURTL's Virtual Text Video.\r
10 ;All video calls are based on the video information in the job's\r
11 ;Job Control Block.\r
12 ;\r
13 ;Virtual video buffers allow a job to output data even when it is\r
14 ;not assigned to the real video display buffer.\r
15 ;\r
16 ;The call SetVidOwner is the key. It swaps virtual buffers for the real one\r
17 ;and changes the current pointer in that job's JCB.  It also updates\r
18 ;the cursor in the correct place on entry.\r
19 ;\r
20 ; The following calls are implemented here:\r
21 ;\r
22 ;------------------------------\r
23 ;GetVidOwner(pdJobNumRet)\r
24 ; Desc: This returns the Job Number that currently has active video\r
25 ; screen.\r
26 ;------------------------------\r
27 ;SetVidOwner(ddJobNum)\r
28 ; Desc: This selects the screen that you see.  This call is used\r
29 ; by the monitor in conjunction with the SetKbdOwner call to change\r
30 ; who gets the keystrokes and video (should be the same app).\r
31 ; The internal debugger is the only code that will use this call\r
32 ; and not move the keyboard also.  It has it's own keyboard code\r
33 ; (else how could it debug the real keyboard code??)\r
34 ; Params:\r
35 ;   ddJobNum is the new Job to get the active screen\r
36 ;   (the one to be displayed)\r
37 ;------------------------------\r
38 ;SetNormVid(dAttr)\r
39 ; Desc: This selects the normal background attribute and fill char\r
40 ; used by ClrScr and ScrollVid on the screen.\r
41 ; Params:\r
42 ;   dCharAttr is the Character and aAttr values used in\r
43 ;   standard video operation on the current screen\r
44 ;\r
45 ;------------------------------\r
46 ;GetNormVid(pVidRet)\r
47 ;\r
48 ; Desc: This returns the value the normal screen attribute\r
49 ; used by ClrScr and ScrollVid on the screen.\r
50 ;\r
51 ; Params:\r
52 ;   pVidRet points to the character where you want the NormVid\r
53 ;   attribute returned.\r
54 ;\r
55 ;------------------------------\r
56 ;ClrScr ();\r
57 ;\r
58 ; Desc:\r
59 ;   This clears the screen for the executing job. It may or may not\r
60 ;   be the one you are viewing...\r
61 ;\r
62 ;------------------------------\r
63 ;TTYOut (pTextOut, ddTextOut, ddAttrib)\r
64 ;\r
65 ;   Desc: This places characters on the screen in a TTY fashion at the\r
66 ;   X & Y coordinates that are in effect for that screen.\r
67 ;   The following characters in the stream are interpreted as follows:\r
68 ;   Hex   Action\r
69 ;   0A    Line Feed\r
70 ;     The cursor (next active character placement) will be on the\r
71 ;     following line at column 0.  If this line is below the bottom\r
72 ;     of the screen, the entire screen will be scrolled up on line,\r
73 ;     the bottom line will be blanked, and the cursor will be placed\r
74 ;     on the last line in the first column.\r
75 ;   0D    Carriage Return\r
76 ;     The Cursor will be moved to column zero on the current line.\r
77 ;   08    BackSpace - The cursor will be moved one column to the left.\r
78 ;     If already at column 0, Backspace will have no effect.\r
79 ;     The backspace is non-destructive (no chars are changed)\r
80 ;\r
81 ;   pTextOut is a NEAR Ptr to the text.\r
82 ;   ddTextOut is the number of chars of text.\r
83 ;   ddAttrib is the attribute/Color you want.\r
84 ;\r
85 ;------------------------------\r
86 ;PutVidChars(ddCol,ddLine,pChars,sChars,ddAttrib)\r
87 ;\r
88 ; Desc: This places characters on the screen without affecting\r
89 ;   the current TTY coordinates or the TTY data.  It is independent\r
90 ;   of the current video "Stream."\r
91 ;\r
92 ; Params:\r
93 ;   ddCol is the column to start on (0-79)\r
94 ;   ddLine is the line (0-24)\r
95 ;   pChars is a pointer the text to be displayed\r
96 ;   sChars is the number of chars\r
97 ;   ddAtrib is the color/attribute to use during display\r
98 ;    which applies to all of the characters on this\r
99 ;    call to PutVidChars.\r
100 ;------------------------------\r
101 ;GetVidChar(ddCol,ddLine,pCharRet,pAttrRet)\r
102 ;\r
103 ; Desc: This returns the current character and attribute\r
104 ;   from the screen coordinates you specify.\r
105 ;\r
106 ; Params:\r
107 ;   ddCol is the column to start on (0-79)\r
108 ;   ddLine is the line (0-24)\r
109 ;   pCharRet is a pointer where you want the character returned\r
110 ;   pAttrRet is a pointer where you want the attribute returned\r
111 ;------------------------------\r
112 ;PutVidAttrs(ddCol,ddLine,sChars,dAttr)\r
113 ;\r
114 ; Desc: This sets screen colors (attrs) for the without affecting\r
115 ;   the current TTY coordinates or the character data. It is independent\r
116 ;   of the current video "Stream."\r
117 ;\r
118 ; Params:\r
119 ;   ddCol is the column to start on (0-79)\r
120 ;   ddLine is the line (0-24)\r
121 ;   sChars is the number of char spaces to place dAttr\r
122 ;   dAttr is the color/attribute to fill the character spaces with\r
123 ;\r
124 ;------------------------------\r
125 ;ScrollVid(ddULCol,ddULline,nddCols,nddLines, ddfUp)\r
126 ;\r
127 ; Desc: This scrolls the described square area on the screen either\r
128 ;   UP or DOWN one line.  If ddfUp is NON-ZERO the scroll will be UP.\r
129 ;   The line left blank is filled with NormAttr from JCB.\r
130 ; Parms:\r
131 ;   ddULCol is the UPERR LEFT column to start on (0-79)\r
132 ;   ddULLine is the UPPER LEFT line (0-24)\r
133 ;   nddCols is the number of columns to be scrolled.\r
134 ;   nddLines is the count of lines to be scrolled.\r
135 ;   ddfUp is NON-ZERO to cause the scroll to be up (vise down).\r
136 ;\r
137 ;   If you want to scroll the entire screen UP one line, the\r
138 ;   params would be  ScrollVid(VidNum, 0,0,80,25,1).\r
139 ;   In this case the top line is lost (not really scrolled),\r
140 ;   and the bottom line would be blanked. Infact, if you specified\r
141 ;   (Vidnum, 0,1,80,24,1) you would get the same results.\r
142 ;\r
143 ;------------------------------\r
144 ;SetXY(NewX,NewY)\r
145 ; Desc: Position VGA cursor (Text mode) to the X & Y position.\r
146 ;\r
147 ; Params:\r
148 ;   NewX is the new horizontal cursor postion\r
149 ;   NewY is the new vertical cursor position\r
150 ;\r
151 ;------------------------------\r
152 ;GetXY(pXRet,pYRet)\r
153 ; Desc: Returns the current X & Y position for your job.\r
154 ;\r
155 ; Params:\r
156 ;   pXRet is a ptr where you want the current horizontal cursor postion\r
157 ;   pYRet is a ptr where you want the current vertical cursor position\r
158 ;\r
159 .DATA\r
160 .INCLUDE MOSEDF.INC\r
161 .INCLUDE JOB.INC\r
162 \r
163 ;This is the data for the virtual character video service.\r
164 ;The video code is fully reentrant because each job has it's own\r
165 ;video screen.  Only one of these screens will be the active video\r
166 ;display.\r
167 ;\r
168 ;Video Equates and Types\r
169 ;\r
170 CRTCPort1   EQU 03D4h   ;Index port for CRTC\r
171 CRTCPort2   EQU 03D5h   ;Data port for CRTC\r
172 CRTCAddHi   EQU 0Ch     ;Register for lo byte of Video address\r
173 CRTCAddLo   EQU 0Dh     ;Register for lo byte of Video address\r
174 CRTCCurHi   EQU 0Eh     ;Register for lo byte of Cursor address\r
175 CRTCCurLo   EQU 0Fh     ;Register for lo byte of Cursor address\r
176 CRTC0C      DB 0        ;CRT Reg 0C HiByte address value\r
177 CRTC0D      DB 0        ;CRT Reg 0D LoByte address value\r
178 \r
179 PUBLIC ddVidOwner   DD 1        ;JCB that currently owns video\r
180                                 ;Default to monitor (Job 1)\r
181 \r
182 ;End of Data & Equates\r
183 ;\r
184 ;============================================================================\r
185 ; BEGIN INTERNAL CODE FOR VIDEO\r
186 ;============================================================================\r
187 ;\r
188 .CODE\r
189 ;\r
190 EXTRN GetpJCB NEAR\r
191 EXTRN GetpCrntJCB NEAR\r
192 EXTRN ReadDbgKbd NEAR\r
193 EXTRN GetCrntJobNum NEAR\r
194 \r
195 ;InitVideo makes Video Screen 0 the default screen. That\r
196 ;makes the VGATextBase address 0B8000h\r
197 ;\r
198 PUBLIC InitVideo:\r
199         MOV AL, CRTCAddHi       ;Index of hi byte\r
200         MOV DX, CRTCPort1       ;Index Port\r
201         OUT DX, AL\r
202         MOV AL, CRTC0C          ;hi byte value to send\r
203         MOV DX, CRTCPort2       ;Data Port\r
204         OUT DX, AL\r
205         ;\r
206         MOV AL, CRTCAddLo       ;Index of lo byte\r
207         MOV DX, CRTCPort1       ;Index Port\r
208         OUT DX, AL\r
209         MOV AL, CRTC0D          ;lo byte value to send\r
210         MOV DX, CRTCPort2       ;Data Port\r
211         OUT DX, AL\r
212         RETN\r
213 ;\r
214 ;============================================================================\r
215 ; BEGIN PUBLIC CODE FOR VIDEO\r
216 ;============================================================================\r
217 ;\r
218 ;============================================================================\r
219 ; SetVidOwner - Make a new a screen actively displayed.\r
220 ; EAX Returns NON-Zero if JOB number is invalid\r
221 \r
222 ddJobVidCV  EQU DWORD PTR [EBP+12]\r
223 \r
224 PUBLIC __SetVidOwner:\r
225         PUSH EBP                ;\r
226         MOV EBP,ESP             ;\r
227         MOV EAX, ddJobVidCV     ;\r
228         CMP EAX, ddVidOwner     ;Already own it?\r
229         JNE ChgVid01            ;No\r
230         XOR EAX, EAX            ;Yes\r
231         JMP ChgVidDone\r
232 ChgVid01:\r
233         CALL GetpJCB                    ;Leaves ptr to new vid JCB in EAX\r
234         CMP DWORD PTR [EAX+pVidMem] ,0  ;Got valid video memory???\r
235         JNE ChgVid02                    ;Yes\r
236         MOV EAX, ErcVidNum      ;NO! Give em an error!\r
237         JMP ChgVidDone\r
238 ChgVid02:\r
239         ;Save data on screen to CURRENT job's pVirtVid\r
240         MOV EAX, ddVidOwner\r
241         CALL GetpJCB\r
242         PUSH VGATextBase        ;Source\r
243         MOV EBX, [EAX+pVirtVid] ;Destination\r
244         PUSH EBX\r
245         PUSH 4000               ;Size of video\r
246         CALL FWORD PTR _CopyData    ;Do it!\r
247 \r
248         ;Make pVidMem same as pVirtVid for CURRENT OWNER\r
249         MOV EAX, ddVidOwner\r
250         CALL GetpJCB            ;Leaves ptr to new vid JCB in EAX\r
251         MOV EBX, [EAX+pVirtVid]\r
252         MOV [EAX+pVidMem], EBX\r
253 \r
254         ;Update current video owner to NEW owner\r
255 \r
256         MOV EAX, ddJobVidCV     ;\r
257         MOV ddVidOwner, EAX\r
258 \r
259         ;Copy in Data from new pVirtVid\r
260 \r
261         MOV EAX, ddVidOwner\r
262         CALL GetpJCB\r
263         MOV EBX, [EAX+pVirtVid] ;Source\r
264         PUSH EBX\r
265         PUSH VGATextBase        ;Destination\r
266         PUSH 4000               ;Size of video\r
267         CALL FWORD PTR _CopyData    ;Do it!\r
268 \r
269         ;Make new pVidMem real video screen for new owner\r
270 \r
271         MOV EAX, ddVidOwner\r
272         CALL GetpJCB\r
273         MOV EBX, VGATextBase\r
274         MOV [EAX+pVidMem], EBX\r
275 \r
276         ;Set Cursor position\r
277 \r
278         MOV EAX, ddVidOwner\r
279         CALL GetpJCB\r
280         MOV ECX, EAX\r
281         MOV EBX, [ECX+CrntX]    ;Get current X for new screen\r
282         MOV EAX, [EBX+CrntY]    ;Current Y\r
283         CALL HardXY             ;Set it up\r
284         XOR EAX, EAX            ;No Error\r
285 ChgVidDone:\r
286         MOV ESP,EBP             ;\r
287         POP EBP                 ;\r
288         RETF 4\r
289 \r
290 ;============================================================================\r
291 ; SetNormVid - Sets the normal video attribute (color) used in\r
292 ; ClrScr, EditLine, and ScrollVid.\r
293 ; EAX Returns Zero (No Error)\r
294 \r
295 ddNormVid   EQU DWORD PTR [EBP+12]\r
296 \r
297 PUBLIC __SetNormVid:\r
298         PUSH EBP                ;\r
299         MOV EBP,ESP             ;\r
300         CALL GetpCrntJCB        ;pJCB -> EAX\r
301         MOV EBX, ddNormVid      ;\r
302         MOV [EAX+NormAttr], EBX ;\r
303         XOR EAX, EAX\r
304         POP EBP                 ;\r
305         RETF 4\r
306 \r
307 ;============================================================================\r
308 ; GetNormVid - Returns the normal video attribute (color) used in\r
309 ; ClrScr, EditLine, and ScrollVid.\r
310 ; EAX Returns Zero (No Error)\r
311 \r
312 pdNormVidRet EQU DWORD PTR [EBP+12]\r
313 \r
314 PUBLIC __GetNormVid:\r
315         PUSH EBP                ;\r
316         MOV EBP,ESP             ;\r
317         CALL GetpCrntJCB        ;pJCB -> EAX\r
318         MOV EBX, [EAX+NormAttr] ;\r
319         MOV ESI, pdNormVidRet   ;\r
320         MOV [ESI], BL           ;\r
321         XOR EAX, EAX\r
322         POP EBP                 ;\r
323         RETF 4\r
324 \r
325 ;============================================================================\r
326 ; GetVidOwner - Returns the Job number of current active video\r
327 ;  number to the caller.\r
328 ;=============================================================================\r
329 \r
330 pVidNumRet  EQU DWORD PTR [EBP+12]\r
331 \r
332 PUBLIC __GetVidOwner:\r
333         PUSH EBP                ;\r
334         MOV EBP,ESP             ;\r
335         MOV ESI, pVidNumRet     ;\r
336         MOV EAX, ddVidOwner     ;\r
337         MOV [ESI], EAX          ;\r
338         XOR EAX, EAX            ; no error obviously\r
339         MOV ESP,EBP             ;\r
340         POP EBP                 ;\r
341         RETF 4\r
342 \r
343 ;=============================================================================\r
344 ; Clear caller's video screen (Use Space and Attr from JCB NormAttr)\r
345 ;=============================================================================\r
346 ;\r
347 PUBLIC __ClrScr:\r
348         PUSH EBP                ;\r
349         MOV EBP,ESP             ;\r
350         CALL GetpCrntJCB        ;Leaves ptr to current JCB in EAX\r
351         MOV EBX, EAX\r
352         MOV EDI,[EBX+pVidMem]   ;EDI points to his video memory\r
353         MOV EAX, [EBX+NormAttr] ;Attr\r
354         SHL EAX, 8              ;\r
355         MOV AL, 20h             ;\r
356         MOV DX, AX\r
357         SHL EAX, 16\r
358         MOV AX, DX              ;Fill Char & Attr\r
359         MOV ECX,0400h\r
360         CLD\r
361         REP STOSD\r
362         PUSH 0\r
363         PUSH 0\r
364         CALL FWORD PTR _SetXY   ;Erc in EAX on Return\r
365         MOV ESP,EBP             ;\r
366         POP EBP                 ;\r
367         RETF\r
368 \r
369 ;=============================================================================\r
370 ; TTYOut:\r
371 ;=============================================================================\r
372 \r
373 pTextOut    EQU DWORD PTR [EBP+20]\r
374 sTextOut    EQU DWORD PTR [EBP+16]\r
375 dAttrText   EQU DWORD PTR [EBP+12]\r
376 \r
377 DataByte    EQU BYTE PTR [ECX]\r
378 \r
379 PUBLIC __TTYOut:\r
380         PUSH EBP                ;\r
381         MOV EBP,ESP             ;\r
382         CALL GetpCrntJCB        ;Leaves ptr to current JCB in EAX\r
383         MOV EBX, EAX\r
384         MOV EAX, sTextOut       ;make sure count isn't null\r
385         OR EAX, EAX\r
386         JZ TTYDone\r
387 \r
388 TTY00:\r
389         MOV EAX,[EBX+CrntX]     ; EAX has CrntX (col)\r
390         MOV EDX,[EBX+CrntY]     ; EDX has CrntY (line)\r
391         MOV ECX,pTextOut\r
392 \r
393         CMP DataByte,0Ah        ; LF?\r
394         JNE TTY02\r
395         INC EDX\r
396         CMP EDX,[EBX+nLines]    ; Equal to or past the bottom?\r
397         JB  TTY06               ; No\r
398         JMP TTYScr              ; Yes, goto scroll\r
399 TTY02:\r
400         CMP DataByte,0Dh        ; CR?\r
401         JNE TTY03\r
402         MOV EAX,0\r
403         JMP TTY06\r
404 TTY03:\r
405         CMP DataByte,08h        ; BackSpace?\r
406         JNE TTY04\r
407         CMP EAX,0\r
408         JE  TTY04\r
409         DEC EAX\r
410         JMP TTY06\r
411 TTY04:\r
412         PUSH EBX                ;Save pointer to VCB\r
413 \r
414         PUSH EAX                ;X (Param 1)\r
415         PUSH EDX                ;Y (Param 2)\r
416         PUSH ECX                ;pointer to text char (Param3)\r
417         PUSH 1                  ;Param 4 (nchars)\r
418         MOV ECX,dAttrText       ;\r
419         PUSH ECX                ;Param 5\r
420         CALL FWORD PTR _PutVidChars ;\r
421         POP EBX                 ;restore ptr to VCB\r
422         CMP EAX, 0\r
423         JNE TTYDone\r
424         MOV EAX, [EBX+CrntX]\r
425         MOV EDX, [EBX+CrntY]\r
426         INC EAX                 ;Next column\r
427         CMP EAX,[EBX+nCols]\r
428         JNE TTY06               ;Make cursor follow\r
429         MOV EAX,0\r
430         INC EDX\r
431         CMP EDX,[EBX+nLines]    ; past the bottom?\r
432         JNE TTY06               ; No - goto 06 else fall thru\r
433 \r
434 TTYScr:\r
435         DEC EDX                 ; back up one line\r
436         PUSH EAX                ;Save registers (scroll eats em)\r
437         PUSH EBX\r
438         PUSH ECX\r
439         PUSH EDX\r
440 \r
441         PUSH 0\r
442         PUSH 0\r
443         PUSH 80\r
444         PUSH 25\r
445         PUSH 1                  ;fUP (non zero)\r
446         CALL FWORD PTR _ScrollVid   ;Ignore error\r
447         POP EDX                 ;restore registers\r
448         POP ECX\r
449         POP EBX\r
450         POP EAX                 ;Fall thru to\r
451 \r
452 TTY06:\r
453         PUSH EBX                ;save ptr to pJCB\r
454 \r
455         PUSH EAX\r
456         PUSH EDX\r
457         CALL FWORD PTR _SetXY\r
458 \r
459         POP EBX                 ;Restore ptr to VCB\r
460         CMP EAX, 0\r
461         JNE TTYDone\r
462         DEC sTextOut\r
463         JZ TTYDone\r
464         INC pTextOut\r
465         JMP TTY00               ; Go back for next char\r
466 TTYDone:\r
467         MOV ESP,EBP             ;\r
468         POP EBP                 ;\r
469         RETF 12\r
470 \r
471 \r
472 \r
473 ;=============================================================================\r
474 ; PutVidAttrs:\r
475 ; Desc: This sets screen colors (attrs) for the without affecting\r
476 ;   the current TTY coordinates or the character data. It is independent\r
477 ;   of the current video "Stream."\r
478 ;\r
479 ; Params:\r
480 ;   ddCol is the column to start on (0-79)\r
481 ;   ddLine is the line (0-24)\r
482 ;   sChars is the number of char spaces to place dAttr\r
483 ;   dAttr is the color/attribute to fill the character spaces with\r
484 ;\r
485 ; Start Position in screen memory is (Line * 80 + (Column*2))\r
486 ; pass Char, then Color, pass char, then color etc... DO NOT EXCEED 2000!\r
487 ; Needs to be fixed to tell if ECX + sDDChars will go off screen...\r
488 ;\r
489 ;=============================================================================\r
490 \r
491 oADDX       EQU DWORD PTR [EBP+24] ;Param 1 COLUMN\r
492 oADDY       EQU DWORD PTR [EBP+20] ;Param 2 LINE\r
493 sADDChars   EQU DWORD PTR [EBP+16] ;Param 3 sChars\r
494 sADDColor   EQU DWORD PTR [EBP+12] ;Param 4 Attr\r
495 \r
496 PUBLIC __PutVidAttrs:\r
497         PUSH EBP                ;\r
498         MOV EBP,ESP             ;\r
499 \r
500         CALL GetpCrntJCB        ;Leaves ptr to current JCB in EAX\r
501         MOV EBX, EAX\r
502 \r
503         MOV EDI, [EBX+pVidMem]  ;point to this VCBs video memory\r
504         MOV EBX,oADDx           ;x Position\r
505         SHL EBX,1               ;Times 2\r
506         MOV EAX,oADDy           ;y Position\r
507         MOV ECX,0A0h            ;Times 160 (char/attrs per line)\r
508         MUL ECX                 ;Times nColumns\r
509         ADD EAX,EBX\r
510         CMP EAX,0F9Eh           ;Last legal posn on screen\r
511         JBE PutAttrs00\r
512         MOV EAX, ErcVidParam\r
513         JMP PcADone\r
514 PutAttrs00:\r
515         MOV ECX,sADDChars\r
516         OR ECX, ECX\r
517         JZ PcADone\r
518         ADD EDI,EAX\r
519         MOV EAX,sADDColor\r
520         CLD\r
521 pcAMore:\r
522         INC EDI                 ;Pass the char value\r
523         STOSB                   ;Move Color in\r
524         LOOP pcAMore\r
525         XOR EAX, EAX            ;No Error!\r
526 pcADone:\r
527         MOV ESP,EBP             ;\r
528         POP EBP                 ;\r
529         RETF 16\r
530 \r
531 ;=============================================================================\r
532 ; PutVidChars:\r
533 ; This Places characters on the VGA Character Screen in the XY Coords\r
534 ;  Params\r
535 ;  1) DD X (Column 0-79)\r
536 ;  2) DD Y (Line 0-24)\r
537 ;  3) DD Near Ptr (relative to DS) of string\r
538 ;  4) DD Size of String\r
539 ;  5) DD (of which the low order byte is the Color)\r
540 ;\r
541 ; Start Position in screen memory is (Line * 80 + (Column*2))\r
542 ; Put Char, then Color, then char, then color etc... DO NOT EXCEED 2000!\r
543 ; Needs to be fixed to tell if ECX + sDDChars will go off screen...\r
544 ;\r
545 ;=============================================================================\r
546 \r
547 oDDX        EQU DWORD PTR [EBP+28] ;Param 1 COLUMN\r
548 oDDY        EQU DWORD PTR [EBP+24] ;Param 2 LINE\r
549 pDDChars    EQU DWORD PTR [EBP+20] ;Param 3 pChars\r
550 sDDChars    EQU DWORD PTR [EBP+16] ;Param 4 sChars\r
551 sDDColor    EQU DWORD PTR [EBP+12] ;Param 5 Attr\r
552 \r
553 PUBLIC __PutVidChars:\r
554         PUSH EBP                ;\r
555         MOV EBP,ESP             ;\r
556                 CLI\r
557         CALL GetpCrntJCB        ;Leaves ptr to current JCB in EAX\r
558         MOV EBX, EAX\r
559         MOV EDI, [EBX+pVidMem]  ;point to this VCBs video memory\r
560                 STI\r
561         MOV EBX,oDDx\r
562         SHL EBX,1               ;Times 2\r
563         MOV EAX,oDDy\r
564         MOV ECX,0A0h            ;Times 160\r
565         MUL ECX                 ;Times nColumns\r
566         ADD EAX,EBX\r
567         CMP EAX,0F9Eh           ;Last legal posn on screen\r
568         JBE PutChars00\r
569         MOV EAX, ErcVidParam\r
570         JMP PcDone\r
571 PutChars00:\r
572         MOV ECX,sDDChars\r
573         OR ECX, ECX\r
574         JZ PcDone\r
575         MOV ESI,pDDChars\r
576         ADD EDI,EAX\r
577         MOV EAX,sDDColor\r
578         CLD\r
579 pcMore:\r
580         MOVSB                   ;Move Char in\r
581         STOSB                   ;Move Color in\r
582         LOOP pcMore\r
583         XOR EAX, EAX            ;No Error!\r
584 pcDone:\r
585         MOV ESP,EBP             ;\r
586         POP EBP                 ;\r
587         RETF 20\r
588 \r
589 ;=============================================================================\r
590 ;GetVidChar(ddCol,ddLine,pCharRet,pAttrRet)\r
591 ;\r
592 ; Desc: This returns the current character and attribute\r
593 ;   from the screen coordinates you specify.\r
594 ;\r
595 ; Params:\r
596 ;   ddCol is the column to start on (0-79)\r
597 ;   ddLine is the line (0-24)\r
598 ;   pCharRet is a pointer where you want the character returned\r
599 ;   pAttrRet is a pointer where you want the attribute returned\r
600 ;\r
601 \r
602 oGDDX       EQU DWORD PTR [EBP+24] ;Param 1 COLUMN\r
603 oGDDY       EQU DWORD PTR [EBP+20] ;Param 2 LINE\r
604 pGDDCRet    EQU DWORD PTR [EBP+16] ;Param 3 pCharRet\r
605 pGDDARet    EQU DWORD PTR [EBP+12] ;Param 4 pAttrRet\r
606 \r
607 PUBLIC __GetVidChar:\r
608         PUSH EBP                ;\r
609         MOV EBP,ESP             ;\r
610         CALL GetpCrntJCB        ;Leaves ptr to current JCB in EAX\r
611         MOV EBX, EAX\r
612 \r
613         MOV EDI, [EBX+pVidMem]  ;point to this VCBs video memory\r
614         MOV EBX,oGDDx\r
615         SHL EBX,1               ;Times 2\r
616         MOV EAX,oGDDy\r
617         MOV ECX,0A0h            ;Times 160\r
618         MUL ECX                 ;Times nColumns\r
619         ADD EAX,EBX\r
620         CMP EAX,0F9Eh           ;Last legal posn on screen\r
621         JBE GetChar00\r
622         MOV EAX, ErcVidParam\r
623         JMP PcGDone\r
624 GetChar00:\r
625         ADD EDI,EAX             ;EDI now points to char\r
626         MOV ESI,pGDDCRet\r
627         MOV AL, [EDI]\r
628         MOV [ESI], AL           ;Give them the char\r
629         INC EDI                 ;Move to Attr\r
630         MOV ESI,pGDDARet\r
631         MOV AL, [EDI]\r
632         MOV [ESI], AL           ;Give them the Attr\r
633         XOR EAX, EAX            ;No Error!\r
634 pcGDone:\r
635         MOV ESP,EBP             ;\r
636         POP EBP                 ;\r
637         RETF 20\r
638 ;=============================================================================\r
639 ; ScrollVid:\r
640 ; This scrolls the defined area up or down one line.\r
641 ;  Params\r
642 ;  1) Upper Left column X (Column 0-79)\r
643 ;  2) Upper Left line Y (Line 0-24)\r
644 ;  3) nCols to scroll\r
645 ;  4) nLines to scroll\r
646 ;  5) TRUE for up (any NON zero QUAD)\r
647 ;\r
648 ;  We check all params for validity. ErcVidParam is returned if one is\r
649 ;  invalid.\r
650 ;=============================================================================\r
651 \r
652 oULX        EQU DWORD PTR [EBP+28] ;Param 1 COLUMN\r
653 oULY        EQU DWORD PTR [EBP+24] ;Param 2 LINE\r
654 nddCols     EQU DWORD PTR [EBP+20] ;Param 3 Number of columns\r
655 nddLines    EQU DWORD PTR [EBP+16] ;Param 4 Number of Lines\r
656 ddfUP       EQU DWORD PTR [EBP+12] ;Param 5 Attr\r
657 \r
658 PUBLIC __ScrollVid:\r
659         PUSH EBP                ;\r
660         MOV EBP,ESP             ;\r
661         CALL GetpCrntJCB        ;Leaves ptr to current JCB in EAX\r
662         MOV EBX, EAX            ;Save pJCB & use in EBX\r
663         MOV EAX, oULX\r
664         CMP EAX, 79\r
665         JA svErcExit\r
666         ADD EAX, nddCols\r
667         CMP EAX, 80\r
668         JA svErcExit\r
669         MOV EAX, oULY\r
670         CMP EAX, 24\r
671         JA svErcExit\r
672         ADD EAX, nddLines\r
673         CMP EAX, 25\r
674         JA svErcExit\r
675 \r
676         CMP ddfUP, 0        ;Scroll UP?\r
677         JNE svUP0           ;Yes... Scroll UP!\r
678 \r
679 ;Scroll DOWN begins\r
680 \r
681         MOV EAX, oULY       ;First line\r
682         ADD EAX, nddLines   ;Last line\r
683         MOV ECX, 160\r
684         MUL ECX                 ;times nBytes per line\r
685         MOV EDI, [EBX+pVidMem]  ;EDI points to video memory 0,0\r
686         MOV EDX, EBX            ;Save pJCB\r
687         ADD EDI, EAX            ;EDI is ptr to 1st dest line\r
688         ADD EDI, oULX       ;offset into line\r
689         ADD EDI, oULX       ;add again for attributes\r
690         MOV ESI, EDI        ;\r
691         SUB ESI, 160        ;ESI is 1st source line\r
692         MOV EBX, ESI        ;Save in EBX for reload\r
693         MOV EAX, nDDLines   ;How many lines to move\r
694         DEC EAX             ;one less than window height\r
695 svDOWN1:\r
696         MOV ECX, nddCols    ;How many WORDS per line to move\r
697         REP MOVSW           ;Move a line (of WORDS!)\r
698         MOV EDI, EBX        ;Reload Dest to next line\r
699         MOV ESI, EDI\r
700         SUB ESI, 160\r
701         MOV EBX, ESI        ;Save again\r
702         DEC EAX\r
703         JNZ svDOWN1\r
704         MOV EAX, [EDX+NormAttr] ;Normal video attributes!!!\r
705         SHL EAX, 8\r
706         MOV AL, 20h             ;Space\r
707         MOV EDI, EBX            ;Put the last line into EDI\r
708         MOV ECX, nddCols\r
709         CLD\r
710         REP STOSW\r
711         XOR EAX, EAX        ;No error\r
712         JMP svDone\r
713                             ;No... scroll down begins\r
714 svUP0:\r
715         MOV EAX, oULY       ;First line\r
716         MOV ECX, 160\r
717         MUL ECX                 ;times nBytes per line\r
718         MOV EDI, [EBX+pVidMem]  ;EDI points to video memory 0,0\r
719         MOV EDX, EBX            ;Save pJCB\r
720         ADD EDI, EAX            ;EDI is ptr to 1st dest line\r
721         ADD EDI, oULX       ;offset into line\r
722         ADD EDI, oULX       ;add again for attributes\r
723         MOV ESI, EDI        ;\r
724         ADD ESI, 160        ;ESI is 1st source line\r
725         MOV EBX, ESI        ;Save in EBX for reload\r
726         MOV EAX, nDDLines   ;How many lines to move\r
727         DEC EAX             ;two less than window height\r
728 svUP1:\r
729         MOV ECX, nddCols    ;How many WORDS per line to move\r
730         REP MOVSW           ;Move a line (of WORDS!)\r
731         MOV EDI, EBX        ;Reload Dest to next line\r
732         MOV ESI, EDI\r
733         ADD ESI, 160\r
734         MOV EBX, ESI        ;Save again\r
735         DEC EAX\r
736         JNZ svUP1\r
737         MOV EAX, [EDX+NormAttr] ;Normal video attributes!!!\r
738         SHL EAX, 8\r
739         MOV AL, 20h             ;Space\r
740         MOV EDI, EBX        ;Put the last line into EDI\r
741         SUB EDI, 160\r
742         MOV ECX, nddCols\r
743         CLD\r
744         REP STOSW\r
745         XOR EAX, EAX        ;No error\r
746         JMP svDone\r
747 svErcExit:                  ;Error exits will jump here\r
748         MOV EAX, ErcVidParam\r
749 svDone:\r
750         MOV ESP,EBP             ;\r
751         POP EBP                 ;\r
752         RETF 20\r
753 ;\r
754 ;=============================================================\r
755 ; HardXY - Intenal  Internal to support SetXY and SetVidOwner\r
756 ;           This sets the hardware cursor position\r
757 ; Input:\r
758 ;   EAX : New Y position\r
759 ;   EBX : New X position\r
760 ; Used:\r
761 ;   EAX, EBX, EDX, Flags\r
762 ; Output:\r
763 ;   None\r
764 \r
765 HardXY:\r
766         MOV ECX,80\r
767         MUL ECX                 ; Line * 80\r
768         ADD EAX,EBX             ; Line plus column\r
769         MOV DX,CRTCPort1        ; Index register\r
770         PUSH EAX\r
771         MOV AL,CRTCCurLo\r
772         OUT DX,AL               ; Index 0Fh for low byte\r
773         POP EAX\r
774         MOV DX,CRTCPort2        ; Data register\r
775         OUT DX,AL               ; Send Low byte out\r
776         SHR EAX,08              ; shift hi byte into AL\r
777         PUSH EAX\r
778         MOV DX,CRTCPort1\r
779         MOV AL,CRTCCurHi\r
780         OUT DX,AL               ; Index for High byte\r
781         POP EAX\r
782         MOV DX,CRTCPort2\r
783         OUT DX,AL               ; Send High byte out\r
784         RETN\r
785 ;\r
786 ;=============================================================================\r
787 ; SetXY:\r
788 ; Position VGA cursor (Text mode) to the X & Y position.\r
789 ; Also sets hardware CrntX and CrntY cursor position if\r
790 ; crnt job is assigned the real screen\r
791 ;=============================================================================\r
792 \r
793 NewX        EQU DWORD PTR [EBP+16]\r
794 NewY        EQU DWORD PTR [EBP+12]\r
795 \r
796 PUBLIC __SetXY:\r
797         PUSH EBP                ;\r
798         MOV EBP,ESP             ;\r
799         CALL GetpCrntJCB        ;Leaves ptr to current JCB in EAX\r
800         MOV EBX, EAX\r
801 \r
802         MOV ECX,NewX            ; Column\r
803         MOV EDX,NewY            ; Line\r
804         MOV [EBX+CrntX],ECX     ; This saves it in the VCB\r
805         MOV [EBX+CrntY],EDX     ;\r
806 \r
807         CALL GetCrntJobNum      ;Leaves ptr to current JCB in EAX\r
808         CMP EAX, ddVidOwner\r
809         JNE GotoXYDone          ;If not on Active screen, skip it\r
810 \r
811         MOV EAX,NewY            ;Setup to call HardXY\r
812         MOV EBX,NewX\r
813         CALL HardXY\r
814 GotoXYDone:\r
815         XOR EAX,EAX             ;No Error\r
816         MOV ESP,EBP             ;\r
817         POP EBP                 ;\r
818         RETF 8\r
819 \r
820 ;=============================================================================\r
821 ; GetXY:\r
822 ; Returns position of VGA cursor (Text mode X & Y position).\r
823 ; This appliies to the values for the caller's VCB\r
824 ;=============================================================================\r
825 \r
826 pXret       EQU DWORD PTR [EBP+16]\r
827 pYret       EQU DWORD PTR [EBP+12]\r
828 \r
829 PUBLIC __GetXY:\r
830         PUSH EBP                ;\r
831         MOV EBP,ESP             ;\r
832         CALL GetpCrntJCB        ;Leaves ptr to current JCB in EAX\r
833         MOV EBX, EAX\r
834 \r
835         MOV EAX,[EBX+CrntX]     ; Column\r
836         MOV ESI,pXret\r
837         MOV [ESI], EAX\r
838         MOV EAX,[EBX+CrntY]     ; Line\r
839         MOV ESI,pYret\r
840         MOV [ESI], EAX\r
841         XOR EAX,EAX\r
842 QXYDone:\r
843         MOV ESP,EBP             ;\r
844         POP EBP                 ;\r
845         RETF 8\r
846 \r
847 \r
848 ;=============================================================================\r
849 ; EditLine\r
850 ; Reads a line of text from the keyboard and puts it into the\r
851 ; specified string with full line editing features.\r
852 ;\r
853 ; EditLine(pStr, dCrntLen, dMaxLen, pdLenRet, pbExitChar): dError\r
854 ;\r
855 ; Param 1 is a NEAR Ptr to string to be edited\r
856 ; Param 2 is current length of string to edit (80 Max)\r
857 ; Param 3 is the max length the string can be (80 Max)\r
858 ; Param 4 is a NEAR Ptr to a DD where the length of the string is returned\r
859 ; Param 5 is a pointer to a Byte where the exit key from the edit\r
860 ;        operation is returned.\r
861 ; Param 6 is the editing attribute to use.\r
862 ;\r
863 ; Display and keyboard are handled entirely inside EditLine.\r
864 ; The following keys are recognized and handled inside, any other key\r
865 ; causes Editline to exit returning the string in it's current condition\r
866 ; and returning the key that caused the exit to pKeyRet:\r
867 ;\r
868 ; 08 (Backspace) move cursor to left replacing char with 20h\r
869 ;     which is a destructive backspace\r
870 ; 20-7E Hex places character in current position and advances position\r
871 \r
872 ; Any other keystroke causes the edit line routine to be exited\r
873 ; with that keystroke returned to pExitKeyRet\r
874 ;\r
875 ;\r
876 ;=============================================================================\r
877 \r
878 pEdString       EQU DWORD PTR [EBP+32]\r
879 ddSzCrnt        EQU DWORD PTR [EBP+28]\r
880 ddSzMax         EQU DWORD PTR [EBP+24]\r
881 pddSzRet        EQU DWORD PTR [EBP+20]\r
882 pExitKeyRet     EQU DWORD PTR [EBP+16]\r
883 dEditAttr       EQU DWORD PTR [EBP+12]\r
884 \r
885 ;Local vars EditX and EditY hold position of first char of text\r
886 ;CrntX is the cursor postion\r
887 ;\r
888 PosnX           EQU DWORD PTR [EBP-04]\r
889 EditX           EQU DWORD PTR [EBP-08]\r
890 EditY           EQU DWORD PTR [EBP-12]\r
891 KeyCode         EQU DWORD PTR [EBP-16]\r
892 \r
893 PUBLIC __EditLine:\r
894         PUSH EBP                ;\r
895         MOV EBP,ESP             ;\r
896         SUB ESP, 16\r
897 \r
898         CMP ddSzCrnt, 80     ;Is it currently too long?\r
899         JA BadEdit\r
900         CMP ddSzMax, 80      ;Is Max len to long?\r
901         JA BadEdit\r
902         MOV EAX, ddSzCrnt\r
903         CMP EAX, ddSzMax     ;Is Crnt len > Max???\r
904         JA BadEdit\r
905 \r
906         LEA EAX, EditX          ;Get current cursor posns in local vars\r
907         PUSH EAX\r
908         LEA EAX, EditY\r
909         PUSH EAX\r
910         CALL FWORD PTR _GetXY\r
911         CMP EAX, 0\r
912         JNE EditDone         ;Bad Erc from call\r
913 \r
914         MOV EAX, EditX\r
915         ADD EAX, ddSzCrnt\r
916         MOV PosnX, EAX       ;make PosnX end of string\r
917 \r
918         MOV ECX, ddSzMax\r
919         SUB ECX, ddSzCrnt    ;ECX  how many bytes to zero\r
920         JZ  EdLn01           ;None to zero out\r
921         MOV ESI, pEdString   ;Initialize currrent string\r
922         ADD ESI, ddSzCrnt    ;ESI ptr to 1st empty byte\r
923         MOV AL, 20h          ;fill with spaces\r
924 Edln00:\r
925         MOV [ESI], AL\r
926         INC ESI\r
927         LOOP Edln00\r
928 \r
929 EdLn01:\r
930         PUSH PosnX\r
931         PUSH EditY\r
932         CALL FWORD PTR _SetXY\r
933         CMP EAX, 0\r
934         JNE EditDone\r
935 \r
936 EdLn02:\r
937         PUSH EditX              ;Display current string\r
938         PUSH EditY\r
939         PUSH pEdString\r
940         PUSH ddSzMax\r
941         PUSH dEditAttr          ;Attribute they selected\r
942         CALL FWORD PTR _PutVidChars\r
943         CMP EAX, 0\r
944         JNE EditDone\r
945 EdLn03:\r
946         LEA EAX, KeyCode\r
947         PUSH EAX\r
948         CMP ddVidOwner, 2       ;Debugger???\r
949         JE EdLn035\r
950         PUSH 1                  ;Wait for a key\r
951         CALL FWORD PTR _ReadKbd ;Get a key\r
952         JMP SHORT EdLn036\r
953 EdLn035:\r
954         CALL ReadDbgKbd\r
955 EdLn036:\r
956         MOV EAX, KeyCode\r
957         AND EAX, 07Fh\r
958         OR  EAX, EAX\r
959         JZ  EdLn03\r
960         CMP EAX, 08h            ;BackSpace?\r
961         JNE EdLn04              ;No - Next test\r
962 EdLn037:\r
963         CMP ddSzCrnt, 0\r
964         JE EdLn01\r
965         DEC PosnX\r
966         DEC ddSzCrnt\r
967         MOV ESI, pEdString\r
968         MOV ECX, ddSzCrnt\r
969         MOV BYTE PTR [ESI+ECX], 20h\r
970         JMP Edln01\r
971 EdLn04: CMP EAX, 03h            ;Left?\r
972         JNE EdLn045             ;No - Next test\r
973         JMP EdLn037\r
974 EdLn045:\r
975         CMP EAX, 83h            ;Num-Left?\r
976         JNE EdLn046             ;No - Next test\r
977         JMP EdLn037\r
978 EdLn046:\r
979         CMP EAX, 0Dh            ;CR?\r
980         JNE EdLn05              ;No - Next test\r
981         JMP EdLn07\r
982 EdLn05: CMP EAX, 1Bh            ;Escape?\r
983         JNE EdLn06              ;No - Next test\r
984         JMP EdLn07\r
985 EdLn06:\r
986         CMP EAX, 7Eh            ;Is it above text?\r
987         JA  EdLn07              ;Yes, Exit!\r
988         CMP EAX, 20h            ;Is it below text??\r
989         JB  EdLn07              ;Yes, Exit\r
990         MOV ESI, pEdString      ;It's really a char!\r
991         MOV ECX, ddSzCrnt\r
992         MOV BYTE PTR [ESI+ECX], AL\r
993         MOV ECX, ddSzMax\r
994         CMP ddSzCrnt, ECX\r
995         JAE EdLn01\r
996         INC PosnX\r
997         INC ddSzCrnt\r
998         JMP EdLn01\r
999 EdLn07:\r
1000         MOV ESI,pExitKeyRet\r
1001         MOV [ESI], AL\r
1002         MOV ESI,pddSzRet\r
1003         MOV EAX, ddSzCrnt\r
1004         MOV [ESI], EAX\r
1005 \r
1006         PUSH EditX              ;Display current string w/Norm Attrs\r
1007         PUSH EditY\r
1008         PUSH pEdString\r
1009         PUSH ddSzMax\r
1010         CALL GetpCrntJCB        ;Leaves ptr to current JCB in EAX\r
1011         MOV EBX, [EAX+NormAttr]\r
1012         PUSH EBX                ;Normal Attribute from JCB\r
1013         CALL FWORD PTR _PutVidChars ;Ignore error (we are leaving anyway)\r
1014         XOR EAX, EAX\r
1015         JMP EditDone\r
1016 BadEdit:\r
1017         MOV EAX, ErcEditParam\r
1018 EditDone:\r
1019         MOV ESP,EBP             ;\r
1020         POP EBP                 ;\r
1021         RETF 24\r
1022 \r
1023 ;===================== END OF MODULE ================\r