]> icculus.org git repositories - btb/d2x.git/blob - unused/bios/key.asm
use the orientation parameter of g3_draw_bitmap
[btb/d2x.git] / unused / bios / key.asm
1 ; THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
2 ; SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
3 ; END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
4 ; ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
5 ; IN USING, DISPLAYING,  AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
6 ; SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
7 ; FREE PURPOSES.  IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
8 ; CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES.  THE END-USER UNDERSTANDS
9 ; AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.  
10 ; COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
11 ;***************************************************************************
12 ;***************************************************************************
13 ;*****                                                                 *****
14 ;*****                                                                 *****
15 ;*****                        K E Y . A S M                            *****
16 ;*****                                                                 *****
17 ;***** Contains routines to get, buffer, and check key presses.        *****
18 ;*****                                                                 *****
19 ;*****                                                                 *****
20 ;***** PROCEDURES                                                      *****
21 ;*****                                                                 *****
22 ;***** key_init()  - Activates the keyboard package.                   *****
23 ;***** key_close() - Deactivates the keyboard package.                 *****
24 ;***** key_check() - Returns 1 if a buffered key is waiting.           *****
25 ;***** key_getch() - Waits for and returns a buffered keypress.        *****
26 ;***** key_flush() - Clears buffers and state array.                   *****
27 ;***** key_time() - Index by scan code. Contains the time key has been *****
28 ;*****             held down. NOT DONE YET.                            *****
29 ;*****                                                                 *****
30 ;*****                                                                 *****
31 ;***** VARIABLES                                                       *****
32 ;*****                                                                 *****
33 ;***** keyd_buffer_type -Set to 0 and key_getch() always returns 0.    *****
34 ;*****                  Set to 1 to so that ASCII codes are returned   *****
35 ;*****                  by key_getch().  Set to 2 and key_getch() returns*****
36 ;*****                  the buffered keyboard scan codes.              *****
37 ;***** keyd_repeat     - Set to 0 to not allow repeated keys in the    *****
38 ;*****                  keyboard buffer.  Set to 1 to allow repeats.   *****
39 ;***** keyd_pressed[] -Index by scan code. Contains 1 if key down else 0*****
40 ;*****                                                                 *****
41 ;*****                                                                 *****
42 ;***** CONSTANTS                                                       *****
43 ;*****                                                                 *****
44 ;***** Setting the DEBUG to 1 at compile time passes SysReq through    *****
45 ;***** to the debugger, and when the debugger is active, it will give  *****
46 ;***** the debugger any keys that are pressed.  Note that this only    *****
47 ;***** works with the Watcom VIDEO debugger at this time.  Setting     *****
48 ;***** DEBUG to 0 takes out all the debugging stuff.                   *****
49 ;*****                                                                 *****
50 ;***************************************************************************
51 ;***************************************************************************
52
53 DEBUG EQU 1
54 .386
55
56 ;************************************************************************
57 ;**************** FLAT MODEL DATA SEGMENT STUFF *************************
58 ;************************************************************************
59
60 _DATA   SEGMENT BYTE PUBLIC USE32 'DATA'
61
62 PUBLIC  _keyd_pressed     ; Must start with a _ so C can see the variable.
63
64                 _keyd_pressed   db  256 dup (?)
65
66                 keybuffer       dw  256 dup (?)     ; Use 256 so an inc wraps around
67
68                 TimeKeyWentDown dd  256 dup(0)
69                 TimeKeyHeldDown dd  256 dup(0)
70                 NumDowns        dd  256 dup(0)
71                 NumUps          dd  256 dup(0)
72
73                 MyCodeSegment   dw  ?
74
75 PUBLIC  _keyd_last_pressed
76                 _keyd_last_pressed  db 0
77 PUBLIC  _keyd_last_released
78                 _keyd_last_released db 0
79
80                 org_int_sel dw  ?
81                 org_int_off dd  ?
82                 keyhead      db  ?
83                 keytail      db  ?
84 PUBLIC  _keyd_buffer_type
85 PUBLIC  _keyd_repeat
86                 _keyd_buffer_type db  ?   ; 0=No buffer, 1=buffer ASCII, 2=buffer scans
87                 _keyd_repeat      db  ?
88
89                 E0Flag      db 0
90
91                 Installed   db  0
92
93 INCLUDE KEYS.INC
94
95
96 _DATA   ENDS
97
98 DGROUP  GROUP _DATA
99
100
101 ;************************************************************************
102 ;**************** FLAT MODEL CODE SEGMENT STUFF *************************
103 ;************************************************************************
104
105 _TEXT   SEGMENT BYTE PUBLIC USE32 'CODE'
106
107                 ASSUME  ds:_DATA
108                 ASSUME  cs:_TEXT
109
110
111 ;************************************************************************
112 ;************************************************************************
113 ;*****                                                              *****
114 ;*****                   K E Y _ T O _ A S C I I _                  *****
115 ;*****                                                              *****
116 ;************************************************************************
117 ;************************************************************************
118
119 PUBLIC  key_to_ascii_
120
121 key_to_ascii_:
122
123                 ; EAX = scancode
124                 push    ebx
125
126                 mov     bl, ah
127                 and     bl, 011111110b
128                 cmp     bl, 0
129                 jne     CantDoKey
130
131                 cmp     al, 127
132                 jae     CantDoKey
133
134                 and     ah, 01b        ; take away ctrl and alt codes
135                 shl     al, 1
136                 shr     eax, 1
137                 and     eax, 0ffh
138                 mov     al, byte ptr key1[eax]
139                 pop     ebx
140                 ret
141
142 CantDoKey:
143                 pop     ebx
144                 mov     eax, 255
145                 ret
146
147
148 public key_clear_times_,key_clear_counts_
149
150 ;clear the array of key down times.
151 key_clear_times_:       push    eax
152         push    ecx
153         push    edi
154         xor     eax,eax
155         mov     ecx,256
156         lea     edi,TimeKeyHeldDown
157         rep     stosd   ;clear array
158         pop     edi
159         pop     ecx
160         pop     eax
161         ret
162
163 ;clear the arrays of key down counts
164 key_clear_counts_:      push    eax
165         push    ecx
166         push    edi
167         xor     eax,eax
168         mov     ecx,256
169         lea     edi,NumDowns
170         rep     stosd   ;clear array
171         mov     ecx,256
172         lea     edi,NumUps
173         rep     stosd   ;clear array
174         pop     edi
175         pop     ecx
176         pop     eax
177         ret
178
179
180 PUBLIC  key_down_time_
181
182 key_down_time_:
183
184                 EXTERNDEF   timer_get_milliseconds_:NEAR
185
186                 push    edx
187                 push    ecx
188                 push    ebx
189
190                 mov     ebx, eax
191                 xor     eax, eax
192
193                 cmp     _keyd_pressed[ebx], 0
194                 je      NotPressed
195
196                 call    get_modifiers   ;shift,alt,ctrl?
197                 or      ah,ah
198                 jz      read_time
199                 xor     eax,eax
200                 jmp     NotPressed
201 read_time:
202
203                 mov     ecx, TimeKeyWentDown[ebx*4]
204                 cli
205                 call    timer_get_milliseconds_
206                 mov     TimeKeyWentDown[ebx*4], eax
207                 sub     eax, ecx        ; EAX = time held since last
208
209 NotPressed:
210                 add     eax, TimeKeyHeldDown[ebx*4]
211                 mov     TimeKeyHeldDown[ebx*4], 0
212
213                 sti
214                 pop     ebx
215                 pop     ecx
216                 pop     edx
217                 ret
218
219 PUBLIC  key_down_count_
220 key_down_count_:
221                 push    ebx
222                 mov     ebx, eax
223                 cli
224                 mov     eax, NumDowns[ebx*4]
225                 mov     NumDowns[ebx*4], 0
226                 sti
227                 pop     ebx
228                 ret
229
230 PUBLIC  key_up_count_
231 key_up_count_:
232                 push    ebx
233                 mov     ebx, eax
234                 cli
235                 mov     eax, NumUps[ebx*4]
236                 mov     NumUps[ebx*4], 0
237                 sti
238                 pop     ebx
239                 ret
240
241
242
243 ;************************************************************************
244 ;************************************************************************
245 ;*****                                                              *****
246 ;*****                   K E Y _ F L U S H                          *****
247 ;*****                                                              *****
248 ;************************************************************************
249 ;************************************************************************
250
251 PUBLIC  key_flush_
252
253 key_flush_:
254                 push    eax
255                 push    ecx
256                 push    edi
257
258                 cli
259                 mov     keyhead,0
260                 mov     keytail,255
261                 mov     E0Flag, 0
262
263                 ; Clear the keyboard array
264                 mov     edi, offset _keyd_pressed
265                 mov     ecx, 32
266                 mov     eax,0
267                 rep     stosd
268                 sti
269
270                 pop     edi
271                 pop     ecx
272                 pop     eax
273                 ret
274
275 ;************************************************************************
276 ;************************************************************************
277 ;*****                                                              *****
278 ;*****                   K E Y _ I N I T                            *****
279 ;*****                                                              *****
280 ;************************************************************************
281 ;************************************************************************
282
283 PUBLIC  key_init_
284
285 key_init_:
286                 push    eax
287                 push    ebx
288                 push    ds
289                 push    es
290
291                 ;**************************************************************
292                 ;******************* INITIALIZE key QUEUE **********************
293                 ;**************************************************************
294
295
296                 mov     _keyd_buffer_type,1
297                 mov     _keyd_repeat,1
298                 mov     E0Flag, 0
299
300                 ; Clear the keyboard array
301                 call    key_flush_
302
303
304                 cmp     Installed, 0
305                 jne     AlreadyInstalled
306
307                 ;**************************************************************
308                 ;******************* SAVE OLD INT9 HANDLER ********************
309                 ;**************************************************************
310
311                 mov     Installed, 1
312
313                 mov     eax, 03509h             ; DOS Get Vector 09h
314                 int     21h                     ; Call DOS
315                 mov     org_int_sel, es         ; Save old interrupt selector
316                 mov     org_int_off, ebx        ; Save old interrupt offset
317
318
319                 ;**************************************************************
320                 ;***************** INSTALL NEW INT9 HANDLER *******************
321                 ;**************************************************************
322
323                 mov     eax, 02509h             ; DOS Set Vector 09h
324                 mov     edx, offset key_handler  ; Point DS:EDX to new handler
325                 mov     bx, cs
326                 mov     MyCodeSegment, bx
327                 mov     ds, bx
328                 int     21h
329
330
331 AlreadyInstalled:
332
333                 pop     es
334                 pop     ds
335                 pop     ebx
336                 pop     eax
337
338                 ret
339
340
341 ;************************************************************************
342 ;************************************************************************
343 ;*****                                                              *****
344 ;*****                   K E Y _ C L O S E _                          *****
345 ;*****                                                              *****
346 ;************************************************************************
347 ;************************************************************************
348
349 PUBLIC  key_close_
350
351 key_close_:
352                 push    eax
353                 push    ebx
354                 push    edx
355                 push    ds
356
357
358                 cmp     Installed, 0
359                 je      @f
360
361                 ;**************************************************************
362                 ;***************** RESTORE OLD INT9 HANDLER *******************
363                 ;**************************************************************
364
365                 mov     Installed, 0
366
367                 ; Clear the BIOS buffer
368                 mov     ebx, 041ch
369                 mov     al, byte ptr [ebx]
370                 mov     ebx, 041ah
371                 mov     byte ptr [ebx], al
372
373                 mov     eax, 02509h         ; DOS Set Vector 09h
374                 mov     edx, org_int_off
375                 mov     ds, org_int_sel
376                 int     21h
377
378 @@:     pop     ds
379                 pop     edx
380                 pop     ebx
381                 pop     eax
382
383                 ret
384
385 ;************************************************************************
386 ;************************************************************************
387 ;*****                                                              *****
388 ;*****                   K E Y _ C H E C K _                          *****
389 ;*****                                                              *****
390 ;************************************************************************
391 ;************************************************************************
392
393 PUBLIC  key_checkch_       ; Must end with a _ so C can see the function.
394
395 key_checkch_:
396                 push    ebx
397
398                 xor     eax, eax
399                 cmp     Installed, 0
400                 je      NoKey
401
402                 cli
403                 mov     bl, keytail
404                 inc     bl
405                 cmp     bl, keyhead
406                 je      Nokey
407                 mov     eax, 1
408
409 Nokey:
410                 sti
411                 pop     ebx
412                 ret
413
414 ;************************************************************************
415 ;************************************************************************
416 ;*****                                                              *****
417 ;*****                 K E Y _ D E B U G                              *****
418 ;*****                                                              *****
419 ;************************************************************************
420 ;************************************************************************
421
422 PUBLIC  key_debug_
423 key_debug_:
424                 int 3h
425                 ret
426
427
428 ;************************************************************************
429 ;************************************************************************
430 ;*****                                                              *****
431 ;*****                   K E Y _ G E T C H _                          *****
432 ;*****                                                              *****
433 ;************************************************************************
434 ;************************************************************************
435
436 PUBLIC  key_getch_       ; Must end with a _ so C can see the function.
437
438 key_getch_:
439                 push    ebx
440
441                 xor     eax, eax
442                 xor     ebx, ebx
443                 cmp     Installed, 0
444                 jne     StillNoKey
445                 pop     ebx
446                 ret
447
448 StillNoKey:
449                 cli             ; Critical section
450                 mov     bl, keytail
451                 inc     bl
452                 cmp     bl, keyhead
453                 sti
454                 je      StillNoKey
455
456                 cli             ; Critical section
457                 xor     ebx, ebx
458                 mov     bl, keyhead
459                 mov     ax, word ptr keybuffer[ebx*2]
460                 inc     BYTE PTR keyhead
461                 sti
462
463                 pop     ebx
464                 ret
465
466
467 ;************************************************************************
468 ;************************************************************************
469 ;*****                                                              *****
470 ;*****                   K E Y _ I N K E Y _                        *****
471 ;*****                                                              *****
472 ;************************************************************************
473 ;************************************************************************
474
475 PUBLIC  key_inkey_       ; Must end with a _ so C can see the function.
476
477 key_inkey_:
478                 push    ebx
479
480                 xor     eax, eax
481                 xor     ebx, ebx
482
483                 cmp     Installed, 0
484                 je      NoInkey
485
486                 cli             ; Critical section
487                 mov     bl, keytail
488                 inc     bl
489                 cmp     bl, keyhead
490                 sti
491                 je      NoInkey
492
493                 cli             ; Critical section
494                 mov     bl, keyhead
495                 mov     ax, word ptr keybuffer[ebx*2]
496                 inc     BYTE PTR keyhead
497                 sti
498 NoInkey:
499                 pop     ebx
500                 ret
501
502 PUBLIC  key_peekkey_       ; Must end with a _ so C can see the function.
503
504 key_peekkey_:
505                 push    ebx
506
507                 xor     eax, eax
508                 xor     ebx, ebx
509
510                 cmp     Installed, 0
511                 je      NoPeek
512
513                 cli             ; Critical section
514                 mov     bl, keytail
515                 inc     bl
516                 cmp     bl, keyhead
517                 sti
518                 je      NoPeek
519
520                 cli             ; Critical section
521                 mov     bl, keyhead
522                 mov     ax, word ptr keybuffer[ebx*2]
523                 sti
524 NoPeek:
525                 pop     ebx
526                 ret
527
528
529
530 ;************************************************************************
531 ;************************************************************************
532 ;*****                                                              *****
533 ;*****                   K E Y _ H A N D L E R                        *****
534 ;*****                                                              *****
535 ;************************************************************************
536 ;************************************************************************
537
538 PUBLIC  key_handler      ; Must end with a _ so C can see the function.
539
540 key_handler:
541                 EXTERNDEF   timer_get_milliseconds_:NEAR
542
543                 pushfd              ; Save flags in case we have to chain to original
544                 push    eax
545                 push    ebx
546                 push    ecx
547                 push    edx
548                 push    ds
549
550                 mov     ax, DGROUP  ; Point to our data segment, since this is an
551                 mov     ds, ax      ; interrupt and we don't know where we were.
552
553 IFDEF DEBUG
554                 call    CheckForDebugger
555                 jnc     @f
556                 mov eax, 0b0000h+78*2
557                 mov byte ptr [eax], 'D'
558                 jmp      SkipBuffer      ; If debugger is active, then skip buffer
559 @@:     mov eax, 0b0000h+78*2
560                 mov byte ptr [eax], 'I'
561
562                 ; Clear the BIOS buffer
563                 mov     ebx, 041ch
564                 mov     al, byte ptr [ebx]
565                 mov     ebx, 041ah
566                 mov     byte ptr [ebx], al
567 ENDIF
568
569                 ;**************************************************************
570                 ;****************** READ IN THE SCAN CODE *********************
571                 ;**************************************************************
572                 ; Reads the scan code from the keyboard and masks off the
573                 ; scan code and puts it in EAX.
574
575                 xor     eax, eax
576                 in      al, 060h        ; Get scan code from keyboard
577
578                 cmp     al, 0E0h
579                 jne     NotE0Code
580
581 E0Code:
582                 mov     E0Flag, 128
583                 jmp     SkipBuffer
584
585 NotE0Code:
586                 mov     bl,al                   ; Save scan code in BL
587                 and     bl,01111111b
588                 add     bl, E0Flag
589                 mov     E0Flag,0
590                 xor     bh,bh                   ; clear for index use
591                 and     al,10000000b            ; keep break bit, if set
592                 xor     al,10000000b            ; flip bit - 1 means pressed
593                                                                                 ;          - 0 means released
594                 rol     al,1                    ; put it in bit 0
595                 xchg    ax, bx
596
597                 ; AX = Key code
598                 ; BX = 1 if pressed, 0 if released.
599                 cmp     bx,  1
600                 je      pkeyDown
601
602                 ;**************************************************************
603                 ;******************* HANDLE A RELEASED KEY ********************
604                 ;**************************************************************
605                 ; Unmarks the key press in EAX from the scancode array.
606
607
608                 mov     _keyd_last_released, al
609                 mov     byte ptr _keyd_pressed[eax], 0
610                 inc     NumUps[eax*4]
611
612                 push    eax
613                 xor     ah,ah
614                 call    get_modifiers
615                 or      ah,ah   ;check modifiers
616                 pop     eax
617                 jnz     skip_time
618
619                 push    edx
620                 push    eax
621                 call    timer_get_milliseconds_
622                 mov     edx, eax
623                 pop     eax
624                 sub     edx, TimeKeyWentDown[eax*4]
625                 add     TimeKeyHeldDown[eax*4], edx
626                 pop     edx
627 skip_time:
628
629                 jmp     pdone
630
631 pkeyDown:
632
633                 ;**************************************************************
634                 ;****************** HANDLE A NEWLY PRESSED KEY ****************
635                 ;**************************************************************
636                 ;Marks the key press in EAX in the scancode array.
637
638
639                 mov     _keyd_last_pressed, al
640                 ; Check if the key is repeating or if it just got pressed.
641                 cmp     byte ptr _keyd_pressed[eax], 1
642                 je      AlreadyDown
643
644                 mov     byte ptr _keyd_pressed[eax], 1
645                 ; Set the time
646
647                 push    edx
648                 push    eax
649                 call    timer_get_milliseconds_
650                 mov     edx, eax
651                 pop     eax
652                 mov     TimeKeyWentDown[eax*4], edx
653                 pop     edx
654
655                 inc     NumDowns[eax*4]
656
657                 jmp     TryBuffer
658
659                 ;**************************************************************
660                 ;******************** HANDLE A PRESSED KEY ********************
661                 ;**************************************************************
662                 ; Adds key scan code in EAX to the keybuffer array.
663
664 AlreadyDown:
665                 cmp     _keyd_repeat, 0
666                 je      SkipBuffer
667
668 TryBuffer:
669                 cmp     _keyd_buffer_type, 0
670                 je      SkipBuffer          ; Buffer = 0 means don't buffer anything.
671
672                 ; Dont buffer shift, ctrl, or alt keys.
673                 ;cmp     al, 02ah       ; Right Shift
674                 ;je      SkipBuffer
675                 ;cmp     al, 036h       ; Left Shift
676                 ;je      SkipBuffer
677                 ;cmp     al, 038h       ; Left Alt
678                 ;je      SkipBuffer
679                 ;cmp     al, 0b8h       ; Right Alt
680                 ;je      SkipBuffer
681                 ;cmp     al, 01dh       ; Left Ctrl
682                 ;je      SkipBuffer
683                 ;cmp     al, 09dh       ' Right Ctrl
684                 ;je      SkipBuffer
685
686                 cmp     al, 0AAh        ; garbage key
687                 je      SkipBuffer
688
689                 call    get_modifiers  ;returns ah
690
691 BufferAX:
692
693                 xor     ebx, ebx
694                 mov     bl, keytail
695                 inc     bl
696                 inc     bl
697
698                 ; If the buffer is full then don't buffer this key
699                 cmp     bl, keyhead
700                 je      SkipBuffer
701                 dec     bl
702
703                 mov     word ptr keybuffer[ebx*2], ax
704                 mov     keytail, bl
705
706 SkipBuffer:
707
708 pdone:
709
710
711 ;**************************************************************
712 ;*************** FINISH UP THE KEYBOARD INTERRUPT *************
713 ;**************************************************************
714
715 ; If in debugger, pass control to dos interrupt.
716 IFDEF DEBUG
717                 pop     ds          ; Nothing left on stack but flags
718                 pop     edx
719                 pop     ecx
720                 pop     ebx
721                 pop     eax
722
723                 sub     esp, 8              ; Save space for IRETD frame
724                 push    ds                  ; Save registers we use.
725                 push    eax
726                 mov     ax, DGROUP
727                 mov     ds, ax              ; Set DS to our data segment
728                 mov     eax, org_int_off   ; put original handler address
729                 mov     [esp+8], eax        ;   in the IRETD frame
730                 movzx   eax, org_int_sel
731                 mov     [esp+12], eax
732                 pop     eax                 ; Restore registers
733                 pop     ds
734                 iretd                       ; Chain to previous handler
735 ENDIF
736
737 ; Resets the keyboard, PIC, restores stack, returns.
738                 in      al, 61h         ; Get current port 61h state
739                 or      al, 10000000b   ; Turn on bit 7 to signal clear keybrd
740                 out     61h, al         ; Send to port
741                 and     al, 01111111b   ; Turn off bit 7 to signal break
742                 out     61h, al         ; Send to port
743                 mov     al, 20h         ; Reset interrupt controller
744                 out     20h, al
745                 sti                     ; Reenable interrupts
746                 pop     ds
747                 pop     edx             ; Restore all of the saved registers.
748                 pop     ecx
749                 pop     ebx
750                 pop     eax
751                 popfd
752                 iretd               ; Interrupt must return with IRETD
753
754 ;returns ah=bitmask of shift,ctrl,alt keys
755 get_modifiers:          push    ecx
756
757                 xor     ah,ah
758
759                 ; Check the shift keys
760                 mov     cl, _keyd_pressed[ 036h ]
761                 or      cl, _keyd_pressed[ 02ah ]
762                 or      ah, cl
763
764                 ; Check the alt key
765                 mov     cl, _keyd_pressed[ 038h ]
766                 or      cl, _keyd_pressed[ 0b8h ]
767                 shl     cl, 1
768                 or      ah, cl
769
770                 ; Check the ctrl key
771                 mov     cl, _keyd_pressed[ 01dh ]
772                 or      cl, _keyd_pressed[ 09dh ]
773                 shl     cl, 2
774                 or      ah, cl
775
776                 pop     ecx
777                 ret
778
779 IFDEF DEBUG
780 CheckForDebugger:
781         ; Returns CF=0 if debugger isn't active
782         ;         CF=1 if debugger is active
783
784                 ;*************************** DEBUG ******************************
785                 ; When we're in the VIDEO debugger, we want to pass control to
786                 ; the original interrupt.  So, to tell if the debugger is active,
787                 ; I check if video page 1 is the active page since that is what
788                 ; page the debugger uses, and if that works, I check the top of
789                 ; the screen to see if the texxt "Control" is there, which should
790                 ; only be there when we're in the debugger.
791
792                 push    eax
793                 ;mov     eax, 0462h          ; Address 0462 stores BIOS current page
794                 ;cmp     BYTE PTR [eax], 1
795                 ;jne     NoDebuggerOnColor
796                 ;mov     eax, 0b8000h+4096   ; 4096 = offset to 2nd video mem page
797                 ;cmp     BYTE PTR [eax+2],'C'
798                 ;jne     NoDebuggerOnColor
799                 ;cmp     BYTE PTR [eax+4],'o'
800                 ;jne     NoDebuggerOnColor
801                 ;cmp     BYTE PTR [eax+6],'n'
802                 ;jne     NoDebuggerOnColor
803                 ;cmp     BYTE PTR [eax+8],'t'
804                 ;jne     NoDebuggerOnColor
805                 ;cmp     BYTE PTR [eax+10],'r'
806                 ;jne     NoDebuggerOnColor
807                 ;cmp     BYTE PTR [eax+12],'o'
808                 ;jne     NoDebuggerOnColor
809                 ;cmp     BYTE PTR [eax+14],'l'
810                 ;jne     NoDebuggerOnColor
811                 ;jmp     ActiveDebugger
812                 ;NoDebuggerOnColor:
813                 ; First, see if there is a mono debugger...
814
815                 ;mov     eax, 0b0000h        ; 4096 = offset to mono video mem
816                 ;cmp     BYTE PTR [eax+2],'C'
817                 ;jne     NoActiveDebugger
818                 ;cmp     BYTE PTR [eax+4],'o'
819                 ;jne     NoActiveDebugger
820                 ;cmp     BYTE PTR [eax+6],'n'
821                 ;jne     NoActiveDebugger
822                 ;cmp     BYTE PTR [eax+8],'t'
823                 ;jne     NoActiveDebugger
824                 ;cmp     BYTE PTR [eax+10],'r'
825                 ;jne     NoActiveDebugger
826                 ;cmp     BYTE PTR [eax+12],'o'
827                 ;jne     NoActiveDebugger
828                 ;cmp     BYTE PTR [eax+14],'l'
829                 ;jne     NoActiveDebugger
830
831                 mov     eax, 0b0000h        ; 4096 = offset to mono video mem
832                 add     eax, 24*80*2
833
834
835                 cmp     BYTE PTR [eax+0],'D'
836                 jne     NextTest
837                 cmp     BYTE PTR [eax+2],'B'
838                 jne     NextTest
839                 cmp     BYTE PTR [eax+4],'G'
840                 jne     NextTest
841                 cmp     BYTE PTR [eax+6],'>'
842                 jne     NextTest
843
844                 ;Found DBG>, so consider debugger active:
845                 jmp     ActiveDebugger
846
847 NextTest:
848                 cmp     BYTE PTR [eax+14],'<'
849                 jne     NextTest1
850                 cmp     BYTE PTR [eax+16],'i'
851                 jne     NextTest1
852                 cmp     BYTE PTR [eax+18],'>'
853                 jne     NextTest1
854                 cmp     BYTE PTR [eax+20],' '
855                 jne     NextTest1
856                 cmp     BYTE PTR [eax+22],'-'
857                 jne     NextTest1
858
859                 ; Found <i> - , so consider debugger active:
860                 jmp     ActiveDebugger
861
862 NextTest1:
863                 cmp     BYTE PTR [eax+0], 200
864                 jne     NextTest2
865                 cmp     BYTE PTR [eax+2], 27
866                 jne     NextTest2
867                 cmp     BYTE PTR [eax+4], 17
868                 jne     NextTest2
869
870                 ; Found either the help screen or view screen, so consider
871                 ; debugger active
872                 jmp     ActiveDebugger
873
874 NextTest2:
875                 ; Now we see if its active by looking for the "Executing..."
876                 ; text on the bottom of the mono screen
877                 ;mov     eax, 0b0000h        ; 4096 = offset to mono video mem
878                 ;add     eax, 24*80*2
879                 ;cmp     BYTE PTR [eax+0],'E'
880                 ;je      NoActiveDebugger
881                 ;cmp     BYTE PTR [eax+2],'x'
882                 ;je      NoActiveDebugger
883                 ;cmp     BYTE PTR [eax+4],'e'
884                 ;je      NoActiveDebugger
885                 ;cmp     BYTE PTR [eax+6],'c'
886                 ;je      NoActiveDebugger
887
888 NoActiveDebugger:
889                 pop     eax
890                 clc
891                 ret
892
893 ActiveDebugger:
894                 pop     eax
895                 stc
896                 ret
897
898 ENDIF
899
900 _TEXT   ENDS
901
902                 END
903
904