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