Microsoft (R) Macro Assembler Version 6.14.8444		    10/04/17 17:31:08
BIOS_Next186.asm					     Page 1 - 1


				; This file is part of the Next186 SoC PC project
				; http://opencores.org/project,next186

				; Filename: BIOS_Next186.asm
				; Description: Part of the Next186 SoC PC project, ROM BIOS code
				; Version 1.0
				; Creation date: Feb-Jun 2013

				; Author: Nicolae Dumitrache 
				; e-mail: ndumitrache@opencores.org

				; -------------------------------------------------------------------------------------
				 
				; Copyright (C) 2013 Nicolae Dumitrache
				 
				; This source file may be used and distributed without 
				; restriction provided that this copyright statement is not 
				; removed from the file and that any derivative work contains 
				; the original copyright notice and the associated disclaimer.
				 
				; This source file is free software; you can redistribute it 
				; and/or modify it under the terms of the GNU Lesser General 
				; Public License as published by the Free Software Foundation;
				; either version 2.1 of the License, or (at your option) any 
				; later version. 
				 
				; This source is distributed in the hope that it will be 
				; useful, but WITHOUT ANY WARRANTY; without even the implied 
				; warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
				; PURPOSE. See the GNU Lesser General Public License for more 
				; details. 
				 
				; You should have received a copy of the GNU Lesser General 
				; Public License along with this source; if not, download it 
				; from http://www.opencores.org/lgpl.shtml 
				 
				; -----------------------------------------------------------------------

				; Additional Comments: 
				; Assembled with MASM v6.14.8444
				; Next186 SoC PC have no ROM, only RAM. The bootstrap code is the initial value of cache 
				;  (last half 1K = 4 lines of 256bytes each), initially marked as "dirty", in order to
				;  be saved in RAM at first flush
				; The bootstrap code may load the BIOS from SD, or from RS232, and place it at F000:E000



				.186
				.model tiny
 0000				.code

 = 0001				SCANCODE1   equ 1

				;-------------------------- BIOS data area (BDA) -----------------
				;40:0000   2  Base port address of first RS-232 adapter (COM1) See COM Ports
				;40:0002   2  Port of COM2
				;40:0004   2  Port of COM3
				;40:0006   2  Port of COM4
				;40:0008   2  Base port addr of first parallel printer (LPT1)  Printer Ports
				;40:000A   2  Port of LPT2
				;40:000C   2  Port of LPT3
				;40:000E   2  Port of LPT4
				;40:0010   2  Equipment/hardware installed/active; see Equipment List
				;40:0012   1  Errors in PCjr infrared keyboard link
				;40:0013   2  Total memory in K-bytes (same as obtained via INT 12H)
				;40:0015   2  Scratch pad for manufacturing error tests
				;
				;40:0017   2  Keyboard status bits; see Keyboard Shift Status Flags
				;40:0019   1  Current (accumulating) value of Alt+numpad pseudo-key input;
				;             normally 0.  When [Alt] is released, value is stored in
				;             keyboard buffer at 001e.
				;40:001a   2  Addr of keyboard buffer head (keystroke at that addr is next)
				;40:001c   2  Address of keyboard buffer tail
				;40:001e  32  Keyboard buffer.  BIOS stores keystrokes here (head and tail
				;             point to addresses from 041eH to 043dH inclusive).
				;
				;40:003e   1  Diskette drive needs recalibration (bit 0=A, bit 1=B, etc.)
				;             bits 4-5 indicate which drive is currently selected
				;40:003f   1  Diskette motor is running (bit 0=drive A, bit 1=B, etc.)
				;40:0040   1  Time until motor off. INT 08H turns motor off when this is 0.
				;40:0041   1  Diskette error status; same as status returned by INT 13H
				;40:0042   7  Diskette controller status information area
				;
				;40:0049   1  Current active video mode.  See Video Modes and INT 10H.
				;40:004a   2  Screen width in text columns
				;40:004c   2  Length (in bytes) of video area (regen size)
				;40:004e   2  Offset from video segment of active video memory page
				;40:0050  16  Cursor location (8 byte-pairs; low byte=clm, hi byte=row)
				;40:0060   2  Cursor size/shape.  Low byte=end scan line; hi byte=start line.
				;40:0062   1  Current active video page number
				;40:0063   2  Port address for 6845 video controller chip; see CGA I/O Ports
				;40:0065   1  Current value of 6845 video ctrlr CRT_MODE (port 3x8H register)
				;40:0066   1  Current value of 6845 video ctrlr CRT_PALETTE (port 3x9H reg)
				;
				;40:0067   5  Cassette data area or POST data area
				;               40:0067: 1 byte mouse buffer counter (DataCounter)
				;               40:0068: 1 byte mouse packet size (PacketSize): 0 for 3 bytes, 1 for 4 bytes (Intellimouse)
				;				40:0069: 2 bytes palette offset during set video mode	
				;
				;40:006c   4  Timer tick counter (count of 55ms ticks since CPU reset)
				;40:0070   1  Timer overflow flag (timer has rolled over 24 hr)
				;40:0071   1  Ctrl-Break flag.  Bit 7=1 when break was pressed.  This never
				;             gets reset unless you do it yourself.
				;
				;40:0072   2  1234H means Ctrl+Alt+Del reboot is in progress.  BIOS checks
				;             this to avoid doing a "cold boot" with the time-consuming POST
				;             4321H means reset, preserving memory
				;             5678H, 9abcH, and abcdH (are internal PC Convertible codes)
				;
				;40:0074   4  PCjr diskette or AT hard disk control area
				;  (0074)   1 Status of last fixed-disk drive operation
				;  (0075)   1 Number of hard disk drives for AT
				;  (0077)   1 Hard disk port for XT.  See XT Hard Disk Ports.
				;40:0078   4  Printer time-out values (478H=Lpt1, 478H=Lpt2...)
				;40:007c   4  RS-232 time-out values  (47cH=Com1, 47dH=Com2...)
				;
				;40:0080   2  AT PS/2 keyboard buffer offset start address (usually 01eH)
				;40:0082   2                                   end address (usually 003eH)
				;
				;40:0084   1  EGA text rows-1  (maximum valid row value)
				;40:0085   2  EGA bytes per character (scan-lines/char used in active mode)
				;40:0087   1  EGA flags; see EgaMiscInfoRec
				;40:0088   1  EGA flags; see EgaMiscInfo2Rec
				;40:0089   1  VGA flags; see VgaFlagsRec
				;             See also:  EGA/VGA Data Areas
				;
				;40:008b   1  AT PS/2 Media control: data rate, step rate
				;40:008c   1  AT PS/2 Hard disk drive controller status
				;40:008d   1  AT PS/2 Hard disk drive error status
				;40:008e   1  AT PS/2 Hard disk drive interrupt control
				;
				;40:0090   1  AT PS/2 Disk media state bits for drive 0
				;40:0091   1                                for drive 1
				;40:0092   1  AT PS/2 Disk operation started flag for drive 0
				;40:0093   1                                      for drive 1

				;40:0094   1  AT PS/2 Present cylinder number for drive 0
				;40:0095   1                                  for drive 1
						; 2 - Number of 512bytes sectors of HD0
				;
				;40:0096   1  AT Keyboard flag bit 4=1 (10H) if 101-key keyboard is attached
				;40:0097   1  AT Keyboard flag for LED 'key lock' display
				;             bits 0-2 are ScrollLock, NumLock, CapsLock
				;
				;40:0098   4  AT Pointer to 8-bit user wait flag; see INT 15H 86H
				;40:009c   4  AT Microseconds before user wait is done
				;40:00a0   1  AT User wait activity flag:
				;                01H=busy, 80H=posted, 00H=acknowledged
				;
				;40:00a1   7  AT Reserved for network adapters
				;               40:00a1: 4 bytes far pointer to mouse callback (HandlerPtr)
				;               40:00a5: 3 bytes mouse buffer (DataBuffer)
				;
				;40:00a8   4  EGA Address of table of pointers; see EgaSavePtrRec
				;40:00ac  68  Reserved
				;40:00f0  16  (IAC) Inter-Aapplication Communication area.  Programs may use
				;             this area to store status, etc.  Might get overwritten by
				;             another program.

				; http://www.ctyme.com/intr/int.htm

				; video memory: 8 physical segments at 0a000h, 0b000h, 0c000h, 0d000h, 0e000h, 0f000h, 10000h, 11000h
				; Memory segments mapping
				; 1Mb virtual seg address   physical seg address
				;       0000h                   0000h
				;       1000h                   1000h
				;       2000h                   2000h
				;       3000h                   3000h
				;       4000h                   4000h
				;       5000h                   5000h
				;       6000h                   6000h
				;       7000h                   7000h
				;       8000h                   8000h
				;       9000h                   9000h
				;       a000h                   a000h       - video
				;       b000h                   b000h       - video
				;       c000h                   12000h
				;       d000h                   13000h
				;       e000h                   14000h
				;       f000h                   15000h


 = 0200				RAMSize   equ    200h        ; 64KB segments

				; Graphics character set
 = bios - 800h			font8x8		equ	bios - 800h        
 = font8x8 - 1000h		font8x16	equ	font8x8 - 1000h    
 = font8x16 - 0e00h		font8x14	equ	font8x16 - 0e00h


						org 0e000h
 E000				bios:        
 E000 4E 65 78 74 31 38		biosmsg     db 'Next186 FleaFPGA SoC PC BIOS (C) 2014 Nicolae Dumitrache', 0
       36 20 46 6C 65 61
       46 50 47 41 20 53
       6F 43 20 50 43 20
       42 49 4F 53 20 28
       43 29 20 32 30 31
       34 20 4E 69 63 6F
       6C 61 65 20 44 75
       6D 69 74 72 61 63
       68 65 00
 E039 4D 42 20 53 44 20		msgmb       db 'MB SD Card', 13, 10, 0
       43 61 72 64 0D 0A
       00
 E046 50 53 32 20 4B 42		msgkb       db 'PS2 KB detected', 13, 10, 0
       20 64 65 74 65 63
       74 65 64 0D 0A 00

						org 0e05bh
 E05B				coldboot:
 E05B				warmboot:
 E05B  FA					cli
 E05C  FC					cld
 E05D  B8 0030					mov     ax, 30h
 E060  8E D0					mov     ss, ax
 E062  BC 0100					mov     sp, 100h
						
 E065  6A 00					push    0
 E067  9D					popf
						
 E068  B0 36					mov     al, 36h
 E06A  E6 43					out     43h, al
 E06C  33 C0					xor     ax, ax
 E06E  E7 07			        out     7, ax       ; NMIonIORQ_HI = 0
 E070  E6 40					out     40h, al
 E072  E6 40					out     40h, al      ; 18Hz PIT CH0
 E074  E6 61					out     61h, al      ; speaker off
 E076  F6 D0					not     al
 E078  E6 21					out     21h, al      ; disable all interrupts
 E07A  E6 A1					out		0a1h, al
 E07C  E7 06			        out     6, ax       ; NMIonIORQ_LO = 255 -> disabled
						

				; ------------------ MAP init
 E07E  E8 152D					call    flush
 E081  B8 0015					mov     ax, 15h     ; BIOS physical segment 15h mapped on virtual segment 0ch
 E084  E7 8C					out     8ch, ax
 E086  68 C000					push    0c000h
 E089  07					pop     es
 E08A  68 F000					push    0f000h
 E08D  1F					pop     ds
 E08E  33 F6					xor     si, si
 E090  33 FF					xor     di, di
 E092  B9 8000					mov     cx, 8000h
 E095  F3/ A5					rep     movsw       ; copy BIOS virtual segment 0fh over physical segment 15h

 E097  E8 1514					call    flush
 E09A  BA 0080					mov     dx, 80h      
 E09D  33 C0					xor     ax, ax
 E09F				mapi:        
 E09F  EF					out     dx, ax
 E0A0  40					inc     ax
 E0A1  42					inc     dx
 E0A2  3C 0C					cmp     al, 0ch
 E0A4  75 02					jne     short mapi1
 E0A6  04 06					add     al, 6
 E0A8				mapi1:        
 E0A8  3C 16					cmp     al, 16h
 E0AA  75 F3					jne     short mapi
						
				; -------------------- Interrupt table init
 E0AC  6A 00					push    0
 E0AE  1F					pop     ds
 E0AF  1E					push    ds
 E0B0  07					pop     es
 E0B1  33 F6					xor     si, si
 E0B3  BF 0004					mov     di, 4
 E0B6  C7 04 F5AD R				mov     word ptr [si], offset defint
 E0BA  8C 4C 02					mov     word ptr [si+2], cs
 E0BD  B9 00FE					mov     cx, 256-2
 E0C0  F3/ A5					rep     movsw
 E0C2  C7 06 001C E2F4 R			mov     word ptr ds:[7*4], offset int07
 E0C8  C7 06 0020 E324 R			mov     word ptr ds:[8*4], offset int08
 E0CE  C7 06 0024 E36A R			mov     word ptr ds:[9*4], offset int09
 E0D4  C7 06 0040 E589 R			mov     word ptr ds:[10h*4], offset int10        
 E0DA  C7 06 0044 EE18 R			mov     word ptr ds:[11h*4], offset int11        
 E0E0  C7 06 0048 EE21 R			mov     word ptr ds:[12h*4], offset int12        
 E0E6  C7 06 004C EE2A R			mov     word ptr ds:[13h*4], offset int13        
 E0EC  C7 06 0050 F017 R			mov     word ptr ds:[14h*4], offset int14        
 E0F2  C7 06 0054 F168 R			mov     word ptr ds:[15h*4], offset int15
 E0F8  C7 06 0058 F300 R			mov     word ptr ds:[16h*4], offset int16
 E0FE  C7 06 0060 F3EB R			mov     word ptr ds:[18h*4], offset int18
 E104  C7 06 0064 F46A R			mov     word ptr ds:[19h*4], offset int19
 E10A  C7 06 0068 F484 R			mov     word ptr ds:[1ah*4], offset int1a
 E110  C7 06 01C0 F4B0 R			mov     word ptr ds:[70h*4], offset int70
 E116  C7 06 01D0 F4DE R			mov     word ptr ds:[74h*4], offset int74

				; ------------------- BDA init
 E11C  6A 40					push    40h
 E11E  1F					pop     ds
 E11F  1E					push    ds
 E120  07					pop     es
 E121  33 FF					xor     di, di
 E123  33 F6					xor     si, si
 E125  33 C0					xor     ax, ax
 E127  B1 80					mov     cl, 80h
 E129  F3/ AB					rep     stosw
 E12B  C7 04 03F8				mov		word ptr [si+00h], 3f8h	 ; COM1 base port address
 E12F  C7 44 08 0378				mov		word ptr [si+08h], 378h	 ; LPT1 base port address
 E134  C6 44 10 24				mov     byte ptr [si+10h], 24h   ; equipment word (color 80x25, PS2 mouse present)
 E138  C7 44 13 0280				mov     word ptr [si+13h], 640   ; memory size in KB
 E13D  83 44 1A 1E				add     word ptr [si+1ah], 1eh   ; next char pointer in kb buffer
 E141  83 44 1C 1E				add     word ptr [si+1ch], 1eh   ; last char pointer in kb buffer
 E145  C7 44 60 0E0F				mov     word ptr [si+60h], 0e0fh ; cursor shape
 E14A  C7 44 63 03D4				mov     word ptr [si+63h], 3d4h  ; video port address
 E14F  83 84 0080 1E				add     word ptr [si+80h], 1eh   ; start kb buffer
 E154  83 84 0082 3E				add     word ptr [si+82h], 3eh   ; end kb buffer
 E159  C7 84 0087 0940				mov     word ptr [si+87h], 0940h ; video adapter options (512Kb video)
 E15F  C7 84 0089 0B71				mov     word ptr [si+89h], 0b71h ; VGA video flags: 400 line text mode, default palette loading on (0), blinking on
 E165  C6 84 0096 10				mov     byte ptr [si+96h], 10h   ; 101 keyboard installed
				 
				; ------------------- Graph mode init
 E16A  B8 0003					mov     ax, 3
 E16D  CD 10					int     10h

				 ; ------------------- KB init ----------------
 E16F  B0 AE					mov     al, 0aeh
 E171  E6 64					out     64h, al     ; enable kb
 E173  B0 A7					mov     al, 0a7h
 E175  E6 64					out     64h, al     ; disable mouse
 E177  B9 0019					mov     cx, 25
 E17A				kbi1:       
 E17A  E8 13F9					call    getps2byte
 E17D  E2 FB					loop    short kbi1  ; wait for kb timeout
 E17F  B4 FF					mov     ah, 0ffh    ; reset kb
 E181  F8					clc                 ; kb command
 E182  E8 140B					call    sendcmd   
 E185  72 31					jc      short nokb
 E187  B1 19					mov     cl, 25
 E189				kbi2:        
 E189  49					dec     cx
 E18A  E3 2C					jcxz    short nokb
 E18C  E8 13E7					call    getps2byte
 E18F  72 F8					jc      short kbi2  ; wait for BAT
 E191  3C AA					cmp     al, 0aah
 E193  75 23					jne     short nokb
 E195  B4 F2					mov     ah, 0f2h    ; kb id
 E197  E8 13F6					call    sendcmd     ; CF = 0
 E19A  72 1C					jc      short nokb
 E19C  E8 13D7					call    getps2byte
 E19F  3C AB					cmp     al, 0abh
 E1A1  75 15					jne     short nokb
 E1A3  E8 13D0					call    getps2byte
 E1A6  3C 83					cmp     al, 83h
				; set scan code 1
				IFDEF SCANCODE1
 E1A8  75 0E					jne     short nokb
 E1AA  B4 F0					mov     ah, 0f0h    ; kb scan set
 E1AC  E8 13E1					call    sendcmd   
 E1AF  72 07					jc      short nokb
 E1B1  B4 01					mov     ah, 1       ; scan set 1
 E1B3  E8 13DA					call    sendcmd   
 E1B6  73 05					jnc     short kbok
				ELSE
				ENDIF        

 E1B8				nokb:   
 E1B8  C6 06 0096 00				mov     byte ptr KbdFlags3, 0   ; kb not present
 E1BD				kbok:
 E1BD  B0 AD					mov     al, 0adh
 E1BF  E6 64					out     64h, al      ; disable kb interface

				; ------------------- Mouse init ----------------
 E1C1  B0 A8					mov     al, 0a8h
 E1C3  E6 64					out     64h, al      ; enable mouse
 E1C5				mousei0:        
 E1C5  E8 13AE					call    getps2byte
 E1C8  73 FB					jnc     short mousei0
 E1CA  B4 FF					mov     ah, 0ffh
 E1CC  E8 13C1					call    sendcmd      ; reset mouse (CF = 1)
 E1CF  72 15					jc      short nomouse
 E1D1  B1 19					mov     cl, 25
 E1D3				mousei1:        
 E1D3  49					dec     cx
 E1D4  E3 10					jcxz    short nomouse
 E1D6  E8 139D					call    getps2byte
 E1D9  72 F8					jc      short mousei1
 E1DB  3C AA					cmp     al, 0aah     ; BAT
 E1DD  75 07					jne     short nomouse
 E1DF  E8 1394					call    getps2byte
 E1E2  3C 00					cmp     al, 0        ; mouse ID
 E1E4  74 09					je      short mouseok
 E1E6				nomouse:
 E1E6  B0 A7					mov     al, 0a7h        
 E1E8  E6 64					out     64h, al      ; disable mouse
 E1EA  80 26 0010 FB				and     byte ptr EquipmentWord, not 4 ; ps2 mouse not present in equipement word
 E1EF				mouseok:
 E1EF  E8 13AF					call    enableKbIfPresent

 E1F2  B0 20					mov     al, 20h
 E1F4  E6 64					out     64h, al
 E1F6  E4 60					in      al, 60h
 E1F8  0C 03					or      al, 3
 E1FA  8A E0					mov     ah, al
 E1FC  B0 60					mov     al, 60h
 E1FE  E6 64					out     64h, al
 E200  8A C4					mov     al, ah
 E202  E6 60					out     60h, al     ; enable 8042 mouse and kb interrupts

 E204  B8 0000					mov     ax, 0		; 1000-1   ; 1ms
 E207  E7 70					out     70h, ax     ; set RTC frequency (stop)

				;		mov     al, 0
 E209  E6 21					out     21h, al     ; enable all PIC interrupts (8h, 9h, 0ch)
 E20B  E6 A1					out		0a1h, al	; enable all PIC interrupts (70h, 74h)
 E20D  E6 01					out		1, al		; intialize COM mux
 E20F  40					inc		ax
 E210  E7 01					out		1, ax		; enable auto flush on vblank
 E212  FB					sti                 ; enable CPU interrupts

				; ---------------------- COM flush
 E213  B4 03			        mov     ah, 3       ; get serial port status
 E215  33 D2			        xor     dx, dx      ; COM1
 E217				COMFlush:
 E217  CD 14			        int     14h
 E219  D0 EC			        shr     ah, 1
 E21B  B4 02			        mov     ah, 2
 E21D  72 F8			        jc      short COMFlush

				; ---------------------   HDD init
 E21F  E8 157A					call    sdinit
 E222  A3 0094					mov     HDSize, ax
 E225  0E					push    cs
 E226  07					pop     es
 E227  BE E000 R				mov     si, offset biosmsg
 E22A  E8 13BF					call    prts
 E22D  BE E27E R				mov     si, offset bioscont
 E230  E8 13B9					call    prts
 E233  A1 0094					mov     ax, HDSize
 E236  D1 E8					shr     ax, 1
 E238  E8 1398					call    dispAX
 E23B  BE E039 R				mov     si, offset msgmb
 E23E  E8 13AB					call    prts
 E241  F6 06 0096 10				test    byte ptr KbdFlags3, 10h
 E246  74 06					jz      nokbmsg
 E248  BE E046 R				mov     si, offset msgkb
 E24B  E8 139E					call    prts
 E24E				nokbmsg:
 E24E  F6 06 0010 04				test    byte ptr EquipmentWord, 4
 E253  74 06					jz      nomousemsg
 E255  BE E269 R				mov     si, offset msgmouse
 E258  E8 1391					call    prts
 E25B				nomousemsg:

				;-------------- HD bootstrap
 E25B  B8 00E3					mov		ax, 00e3h
 E25E  CD 14					int		14h		; init COM to 9.6K, 8n1
 E260  B8 0305					mov     ax, 305h
 E263  33 DB					xor     bx, bx
 E265  CD 16					int     16h     ; set typematic rate and delay to fastest
 E267  CD 19					int     19h

 E269 50 53 32 20 4D 6F		msgmouse    db 'PS2 Mouse detected', 13, 10, 0        
       75 73 65 20 64 65
       74 65 63 74 65 64
       0D 0A 00
 E27E 0D 0A 43 50 55 3A		bioscont    db 13, 10, 'CPU: 80186 25Mhz (25MIPS, 50Mhz 32bit bus)', 13, 10
       20 38 30 31 38 36
       20 32 35 4D 68 7A
       20 28 32 35 4D 49
       50 53 2C 20 35 30
       4D 68 7A 20 33 32
       62 69 74 20 62 75
       73 29 0D 0A
 E2AC  52 41 4D 3A 20 33				db 'RAM: 32MB SDR 100Mhz', 13, 10
       32 4D 42 20 53 44
       52 20 31 30 30 4D
       68 7A 0D 0A
 E2C2  43 61 63 68 65 3A				db 'Cache: 8KB, 4-way, 128x256 bytes data/inst', 13, 10
       20 38 4B 42 2C 20
       34 2D 77 61 79 2C
       20 31 32 38 78 32
       35 36 20 62 79 74
       65 73 20 64 61 74
       61 2F 69 6E 73 74
       0D 0A
 E2EE  48 44 30 3A 20 00				db 'HD0: ', 0

				; ---------------------------- INT 07 ---------------------
 E2F4				int07 proc near ; coprocessor ESC sequence
 E2F4  50					push    ax
 E2F5  53					push    bx
 E2F6  1E					push    ds
 E2F7  55					push    bp
 E2F8  8B EC					mov     bp, sp
 E2FA  C5 5E 08					lds     bx, [bp+8]  
 E2FD				int07_pfx:        
 E2FD  8A 07					mov     al, [bx]
 E2FF  43					inc     bx
 E300  24 F8					and     al, 0f8h
 E302  3C D8					cmp     al, 0d8h        ; ESC code
 E304  75 F7					jne     short int07_pfx
							  
 E306  80 3F C0					cmp     byte ptr [bx], 0c0h ; mod reg r/m of ESC 8087 instruction
 E309  1A C0					sbb     al, al
 E30B  22 07					and     al, [bx]
 E30D  25 00C7					and     ax, 0c7h
 E310  3C 06					cmp     al, 6
 E312  75 02					jne     int072
 E314  B0 80					mov     al, 80h
 E316				int072:
 E316  C0 E8 06					shr     al, 6
 E319  40					inc     ax
 E31A  03 C3					add     ax, bx
 E31C  89 46 08					mov     [bp+8], ax
 E31F  5D					pop     bp
 E320  1F					pop     ds
 E321  5B					pop     bx
 E322  58					pop     ax
 E323  CF					iret
 E324				int07 endp


				; ---------------------------- INT 08 ---------------------
 E324				int08 proc near
 E324  1E					push    ds
 E325  53					push    bx
 E326  6A 40					push    40h
 E328  1F					pop     ds
 E329  BB 006C					mov     bx, 6ch
 E32C  83 07 01					add     word ptr [bx], 1
 E32F  83 57 02 00				adc     word ptr [bx+2], 0
 E333  83 7F 02 18				cmp     word ptr [bx+2], 18h
 E337  75 13					jne     short int081
 E339  81 3F 00B0				cmp     word ptr [bx], 0b0h
 E33D  75 0D					jne     short int081
 E33F  C7 07 0000				mov     word ptr [bx], 0
 E343  C7 47 02 0000				mov     word ptr [bx+2], 0
 E348  C6 47 04 01				mov     byte ptr [bx+4], 1
 E34C				int081:
 E34C  CD 1C					int     1ch
 E34E  FB					sti
 E34F  50					push    ax
 E350  B4 04					mov     ah, 4
 E352				kloop:        
 E352  E4 64					in      al, 64h
 E354  A8 01					test    al, 1
 E356  74 0E					jz      short nokey
 E358  FE CC					dec     ah
 E35A  75 F6					jnz     short kloop
 E35C  A8 20					test    al, 20h
 E35E  74 04					jz      short kbdata
 E360  CD 74					int     74h
 E362  EB 02					jmp     short nokey
 E364				kbdata:
 E364  CD 09					int     9h        
 E366				nokey:
 E366  58					pop     ax
 E367  5B					pop     bx
 E368  1F					pop     ds
 E369  CF					iret
 E36A				int08 endp

				; --------------------- INT 09 - keyboard ------------------
 = ds:[17h]			KbdFlags1       equ     <ds:[17h]>
 = ds:[18h]			KbdFlags2       equ     <ds:[18h]>
 = ds:[19h]			AltKpd          equ     <ds:[19h]>
 = ds:[71h]			CtrlBreak       equ     <ds:[71h]>
 = ds:[96h]			KbdFlags3       equ     <ds:[96h]>
 = ds:[97h]			KbdFlags4       equ     <ds:[97h]>

				; Bits for the KbdFlags1
 = 0001				RShfDown        equ     1
 = 0002				LShfDown        equ     2
 = 0004				CtrlDown        equ     4
 = 0008				AltDown         equ     8
 = 0010				ScrLock         equ     10h
 = 0020				NumLock         equ     20h
 = 0040				CapsLock        equ     40h
 = 0080				Insert          equ     80h

				; Bits for the KbdFlags2
 = 0001				LCtrDown        equ     1
 = 0002				LAltDown        equ     2
 = 0004				SysReqDown      equ     4
 = 0008				Pause           equ     8
 = 0010				ScrLockDown     equ     10h
 = 0020				NumLockDown     equ     20h
 = 0040				CapsLockDown    equ     40h
 = 0080				InsDown         equ     80h
				 
				; Bits for the KbdFlags3
 = 0001				LastE1          equ     1
 = 0002				LastE0          equ     2
 = 0004				RCtrDown        equ     4
 = 0008				RAltDown        equ     8
 = 0020				LastF0          equ     20h

				; Bits for the KbdFlags4
 = 0001				ScrLockLED      equ     1
 = 0002				NumLockLED      equ     2
 = 0004				CapsLockLED     equ     4
 = 0008				SetRepeat       equ     8       ; Set auto repeat command in progress
 = 0010				AckReceived     equ     10h
 = 0040				LEDUpdate       equ     40h

				IFDEF SCANCODE1

 E36A				int09 proc near
 E36A  60					pusha
 E36B  1E					push    ds
 E36C  06					push    es
 E36D  6A 40					push    40h
 E36F  1F					pop     ds
 E370  E4 60					in      al, 60h         ; al contains the scan code
 E372  8B 16 0017				mov     dx, KbdFlags1
 E376  8B 0E 0096				mov     cx, KbdFlags3
 E37A  3C FA					cmp     al, 0fah        ; ACK
 E37C  75 1F					jne     short noACK
				; ------------ manage ACK response
 E37E  F6 C5 40					test    ch, LEDUpdate
 E381  74 14					jz      short ToggleACK ; no LED update
 E383  F6 C5 10					test    ch, AckReceived
 E386  75 0C					jnz     short SecondACK ; second ACK received
 E388  8A E5					mov     ah, ch          ; LED update command sent, ACK received, need to send second byte
 E38A  80 E4 07					and     ah, ScrLockLED or NumLockLED or CapsLockLED
 E38D  B3 00					mov     bl, 0
 E38F  E8 11BF					call    sendps2byte
 E392  EB 03					jmp     short ToggleACK
 E394				SecondACK:        
 E394  80 F5 40					xor     ch, LEDUpdate   ; second ACK, clear LED update bit
 E397				ToggleACK:
 E397  80 F5 10					xor     ch, AckReceived ; toggle ACK bit 
 E39A				SetFlags1:                                  
 E39A  E9 01AF					jmp     SetFlags               
						
				; ------------ no ACK
 E39D				noACK:
 E39D  B4 4F					mov     ah,4fh
 E39F  F9					stc
 E3A0  CD 15					int     15h
 E3A2  72 03 E9 01C8				jnc     int09Exit
 E3A7  3C E0					cmp     al, 0e0h
 E3A9  75 05					jne     short noE0
 E3AB  80 C9 02					or      cl, LastE0
 E3AE  EB EA					jmp     short SetFlags1
 E3B0				noE0:
 E3B0  3C E1					cmp     al, 0e1h
 E3B2  75 05					jne     short noE1
 E3B4  80 C9 01					or      cl, LastE1
 E3B7  EB E1					jmp     short SetFlags1
 E3B9				noE1:   
 E3B9  3C 53					cmp     al, 53h     ; is DEL?
 E3BB  75 18					jne     short noDEL
 E3BD  8A E2					mov     ah, dl
 E3BF  80 E4 0C					and     ah, CtrlDown or AltDown
 E3C2  80 FC 0C					cmp     ah, CtrlDown or AltDown
 E3C5  74 03 E9 010F				jne     NormalKey   ; is DEL, but no CTRL+ALt+DEL
 E3CA  C7 06 0072 1234				mov     word ptr ds:[72h], 1234h    ; warm boot flag
 E3D0  EA					db      0eah
 E3D1  0000 FFFF				dw      0, 0ffffh       ; reboot
 E3D5				noDEL:
 E3D5  F6 C1 02					test    cl, LastE0
 E3D8  75 24					jnz     short noRSUp    ; ignore fake shifts
 E3DA  3C 2A					cmp     al, 2ah         ; left shift
 E3DC  75 05					jne     short noLSDown
 E3DE  80 CA 02					or      dl, LShfDown
 E3E1  EB 63					jmp     short SetFlagsKey2
 E3E3				noLSDown:
 E3E3  3C AA					cmp     al, 2ah or 80h
 E3E5  75 05					jne     short noLSUp
 E3E7  80 E2 FD					and     dl, not LShfDown
 E3EA  EB 5A					jmp     short SetFlagsKey2
 E3EC				noLSUp:
 E3EC  3C 36					cmp     al, 36h         ; right shift
 E3EE  75 05					jne     short noRSDown
 E3F0  80 CA 01					or      dl, RShfDown
 E3F3  EB 51					jmp     short SetFlagsKey2
 E3F5				noRSDown:
 E3F5  3C B6					cmp     al, 36h or 80h
 E3F7  75 05					jne     short noRSUP
 E3F9  80 E2 FE					and     dl, not RShfDown
 E3FC  EB 48					jmp     short SetFlagsKey2
 E3FE				noRSUp:
 E3FE  3C 38					cmp     al, 38h         ; ALT
 E400  75 13					jne     short noALTDown
 E402  F6 C1 02					test    cl, LastE0
 E405  74 08					jz      short LALTDn
 E407  80 C9 08					or      cl, RAltDown
 E40A  80 CA 08					or      dl, AltDown
 E40D  EB 37					jmp     short SetFlagsKey2
 E40F				LALTDn:
 E40F  81 CA 0208				or      dx, (LAltDown shl 8) or AltDown
 E413  EB 31					jmp     short SetFlagsKey2
 E415				noALTDown:
 E415  3C B8					cmp     al, 38h or 80h
 E417  75 1E					jne     short noALTUp
 E419  F6 C1 02					test    cl, LastE0
 E41C  74 08					jz      short LALTUp
 E41E  80 E1 F7					and     cl, not RAltDown
 E421  80 E2 F7					and     dl, not AltDown
 E424  EB 04					jmp     short ALTup
 E426				LALTUp:
 E426  81 E2 FDF7				and     dx, not ((LAltDown shl 8) or AltDown)
 E42A				ALTUp:
 E42A  33 C0					xor     ax, ax
 E42C  86 06 0019				xchg    al, AltKpd
 E430  84 C0					test    al, al
 E432  74 12					jz      short SetFlagsKey2     
 E434  E9 0107					jmp     pushKey
 E437				noALTUp:
 E437  3C 1D					cmp     al, 1dh         ; CTL
 E439  75 13					jne     short noCTLDown
 E43B  F6 C1 02					test    cl, lastE0
 E43E  74 08					jz      short LCTLDn
 E440  80 C9 04					or      cl, RCtrDown
 E443  80 CA 04					or      dl, CtrlDown
 E446				SetFlagsKey2:        
 E446  EB 79					jmp     short SetFlagsKey1
 E448				LCTLDn:
 E448  81 CA 0104				or      dx, (LCtrDown shl 8) or CtrlDown
 E44C  EB 73					jmp     short SetFlagsKey1
 E44E				noCTLDown:
 E44E  3C 9D					cmp     al, 1dh or 80h
 E450  75 13					jne     short noCTLUp
 E452  F6 C1 02					test    cl, LastE0
 E455  74 08					jz      short LCTLUp
 E457  80 E1 FB					and     cl, not RCtrDown
 E45A  80 E2 FB					and     dl, not CtrlDown
 E45D  EB 62					jmp     short SetFlagsKey1
 E45F				LCTLUp:
 E45F  81 E2 FEFB				and     dx,  not ((LCtrDown shl 8) or CtrlDown)
 E463  EB 5C					jmp     short SetFlagsKey1
 E465				noCTLUp:
 E465  BB 3A40					mov     bx, 3a00h + CapsLock
 E468  E8 0108					call    KeyLock
 E46B  73 54					jnc     short SetFlagsKey1
						
 E46D  BB 4610					mov     bx, 4600h + ScrLock
 E470  52					push    dx          ; save ScrLock state bit (dl)
 E471  E8 00FF					call    KeyLock
 E474  5B					pop     bx          ; restore ScrLock state bit (bl)
 E475  72 21					jc      short noScrLock
 E477  F6 C2 04					test    dl, CtrlDown
 E47A  74 45					jz      short SetFlagsKey1; no break, just ScollLock
 E47C  8A D3					mov     dl, bl      ; restore ScrLock flag
 E47E  F6 C7 10					test    bh, ScrLockDown
 E481  75 3E					jnz     short SetFlagsKey1 
 E483  C6 06 0071 80				mov     byte ptr CtrlBreak, 80h   ; CTRL+BREAK flag
 E488  A1 0080					mov     ax, Buffer
 E48B  A3 001A					mov     HeadPtr, ax
 E48E  A3 001C					mov     TailPtr, ax
 E491  CD 1B					int     1bh
 E493  33 C0					xor     ax, ax
 E495  E9 00A6					jmp     pushkey
 E498				noScrLock:        
 E498  F6 C1 02					test    cl, LastE0  ; INS
 E49B  75 0A					jnz     short testINS
 E49D  F6 C2 03					test    dl, RShfDown or LShfDown
 E4A0  75 05					jnz     short testINS
 E4A2  F6 C2 20					test    dl, NumLock
 E4A5  75 06					jnz     short NoIns      
 E4A7				testINS:
 E4A7  BB 5280					mov     bx, 5200h + Insert
 E4AA  E8 00C6					call    KeyLock  
 E4AD				noIns:
 E4AD  BB 4520					mov     bx, 4500h + NumLock
 E4B0  52					push    dx          ; save NumLock state bit (dl)
 E4B1  E8 00BF					call    KeyLock
 E4B4  5B					pop     bx          ; restore NumLock state bit (bl)
 E4B5  72 22					jc      short NormalKey   ; CTRL+NumLock = Pause
 E4B7  F6 C2 04					test    dl, CtrlDown
 E4BA  74 05					jz      short SetFlagsKey1
 E4BC  8A D3					mov     dl, bl      ; restore NumLock flag
 E4BE  80 CE 08					or      dh, Pause   ; set Pause bit
 E4C1				SetFlagsKey1:
 E4C1  E9 0085					jmp     SetFlagsKey
 E4C4				E0Key:
 E4C4  BF FB2C R				mov     di, offset E0KeyList
 E4C7  51					push    cx
 E4C8  B9 000C					mov     cx, E0KeyIndex - E0KeyList
 E4CB  FC					cld
 E4CC  0E					push    cs
 E4CD  07					pop     es
 E4CE  F2/ AE					repne   scasb
 E4D0  59					pop     cx
 E4D1  75 76					jne     short SetFlagsKey
 E4D3  26: 8A 45 0B				mov     al, es:[di + E0KeyIndex - E0KeyList - 1]
 E4D7  EB 14					jmp     short KeyDown
 E4D9				NormalKey:
 E4D9  A8 80					test    al, 80h
 E4DB  75 6C					jnz     short SetFlagsKey ; key up
 E4DD  F6 C1 02					test    cl, LastE0
 E4E0  75 E2					jnz     short E0Key
 E4E2  3C 59					cmp     al, 59h
 E4E4  1A E4					sbb     ah, ah
 E4E6  22 C4					and     al, ah
 E4E8  BB FAD3 R				mov     bx, offset KeyIndex
 E4EB  2E: D7					xlat    cs:[bx]
 E4ED				KeyDown:
 E4ED  33 DB					xor     bx, bx 
 E4EF  F6 C2 03					test    dl, RShfDown or LShfDown
 E4F2  74 02					jz      short noShift
 E4F4  B3 02					mov     bl, 2
 E4F6				noShift:
 E4F6  3C 1A					cmp     al, 26
 E4F8  77 0A					ja      short noCaps
 E4FA  F6 C2 40					test    dl, CapsLock
 E4FD  74 13					jz      short noNum
 E4FF  80 F3 02					xor     bl, 2
 E502  EB 0E					jmp     short noNum 
 E504				noCaps:
 E504  3C 25					cmp     al, 37
 E506  77 0A					ja      short noNum
 E508  F6 C2 20					test    dl, NumLock
 E50B  75 02					jnz     short NumDown
 E50D  B3 02					mov     bl, 2
 E50F				NumDown:
 E50F  80 F3 02					xor     bl, 2
 E512				noNum:        
 E512  F6 C2 04					test    dl, CtrlDown
 E515  74 02					jz      short noCtrl
 E517  B3 04					mov     bl, 4
 E519				noCtrl:
 E519  F6 C2 08					test    dl, AltDown
 E51C  74 02					jz      short noAlt
 E51E  B3 06					mov     bl, 6
 E520				noAlt:
 E520  98					cbw
 E521  C1 E0 03					shl     ax, 3
 E524  03 D8					add     bx, ax
 E526  2E: 8B 87 FB44 R				mov     ax, cs:KeyCode[bx]
 E52B  83 F8 0A					cmp     ax, 000ah
 E52E  77 0E					ja      short pushKey
 E530  48					dec     ax
 E531  78 16					js      short SetFlagsKey     ; ax was 0
 E533  8A 26 0019				mov     ah, AltKpd
 E537  D5 0A					aad
 E539  A2 0019					mov     AltKpd, al
 E53C  EB 0B					jmp     short SetFlagsKey
 E53E				pushKey:                
 E53E  51					push    cx
 E53F  8B C8					mov     cx, ax
 E541  B4 05					mov     ah, 5
 E543  CD 16					int     16h
 E545  59					pop     cx
 E546  80 E6 F7					and     dh, not Pause    ; clear Pause bit
 E549				SetFlagsKey:
 E549  80 E1 FC					and     cl, not (LastE0 or LastE1)    ; not prefix key code, clear all prefixes
 E54C				SetFlags:
 E54C  8A C2					mov     al, dl
 E54E  C0 E8 04					shr     al, 4
 E551  32 C5					xor     al, ch
 E553  24 07					and     al, 7
 E555  74 10					jz      short SF1   ; no LEDs to update
 E557  F6 C5 58					test    ch, SetRepeat or AckReceived or LEDUpdate
 E55A  75 0B					jnz     short SF1   ; can not update LEDS, so just write the flags and exit
 E55C  0C 40					or      al, LEDUpdate
 E55E  32 E8					xor     ch, al      ; insert the LEDs in KbdFlags4
 E560  B4 ED					mov     ah, 0edh    ; set LED
 E562  B3 00					mov     bl, 0
 E564  E8 0FEA					call    sendps2byte
 E567				SF1:        
 E567  89 16 0017				mov     KbdFlags1, dx
 E56B  89 0E 0096				mov     KbdFlags3, cx
						
 E56F				int09Exit:
 E56F  07					pop     es
 E570  1F					pop     ds
 E571  61					popa
 E572  CF					iret
 E573				int09 endp

				ELSE    ; SCANCODE2
				ENDIF

 E573				KeyLock proc near   ; input: BH = expected scan code, al = scan code, BL = key lock flag. Returns CF=1 to continue, CF=0 to exit
 E573  32 F8					xor     bh, al
 E575  75 09					jnz     short s2
 E577  8A E6					mov     ah, dh
 E579  0A F3					or      dh, bl      ; set flag
 E57B  32 E6					xor     ah, dh      ; get flag difference
 E57D  32 D4					xor     dl, ah      ; toggle only if key was not already down
 E57F  C3					ret
 E580  80 FF 80			s2:     cmp     bh, 80h
 E583  F9					stc
 E584  75 02					jne     short exit
 E586  32 F3					xor     dh, bl      ; key up
 E588				exit:
 E588  C3					ret
 E589				KeyLock endp


				; --------------------- INT 10h - Video ----------------
 = ds:[49h]			ActiveVideoMode     equ <ds:[49h]>  ; 1  byte
 = ds:[4ah]			ScreenWidth         equ <ds:[4ah]>  ; 2  Screen width in text columns
 = ds:[4ch]			RegenLength         equ <ds:[4ch]>  ; 2  Length (in bytes) of video area (regen size)
 = ds:[4eh]			PageOffset          equ <ds:[4eh]>  ; 2  Offset from video segment of active video memory page
 = ds:[50h]			CursorPos           equ <ds:[50h]>  ; 16 Cursor location (8 byte-pairs; low byte=col, hi byte=row)
 = ds:[60h]			CursorShape         equ <ds:[60h]>  ; 2  Cursor size/shape.  Low byte=end scan line; hi byte=start line.
 = ds:[62h]			ActivePage          equ <ds:[62h]>  ; 1  Current active video page number
 = ds:[63h]			PortAddress         equ <ds:[63h]>  ; 2  Port address for 6845 video controller chip; see CGA I/O Ports
 = ds:[65h]			CrtMode             equ <ds:[65h]>  ; 1  Current value of 6845 video ctrlr CRT_MODE (port 3x8H register)
 = ds:[66h]			CrtPalette          equ <ds:[66h]>  ; 1  Current value of 6845 video ctrlr CRT_PALETTE (port 3x9H reg)
 = ds:[84h]			ScreenRows          equ <ds:[84h]>  ; 1  EGA text rows-1  (maximum valid row value)
 = ds:[85h]			ScanLinesChar       equ <ds:[85h]>  ; 2  EGA bytes per character (scan-lines/char used in active mode)
 = ds:[87h]			EgaMiscInfo         equ <ds:[87h]>  ; 1  EGA flags; see EgaMiscInfoRec
 = ds:[88h]			EgaMiscInfo2        equ <ds:[88h]>  ; 1  EGA flags; see EgaMiscInfo2Rec
 = ds:[89h]			VgaFlags            equ <ds:[89h]>  ; 1  VGA flags; see VgaFlagsRec
 = ds:[8ah]			VgaFlags2           equ <ds:[8ah]>  ; 1  VGA flags2
 = ds:[69h]			PalOffset			equ <ds:[69h]>  ; 2  current palette offset (temporary during the video mode set)


 E589				int10 proc near     
 E589  FB					sti                     ; no interrupt reentrant
 E58A  FC					cld
 E58B  1E					push    ds
 E58C  56					push    si
 E58D  6A 40					push    40h
 E58F  1F					pop     ds
 E590  80 FC 4F					cmp     ah, 4fh
 E593  74 16					je      short svga
 E595  80 FC 1C					cmp     ah, 1ch
 E598  77 0E					ja      short exit
 E59A  8B F0					mov     si, ax
 E59C  C1 EE 07					shr     si, 7
 E59F  81 E6 01FE				and     si, 1feh
 E5A3  2E: FF 94 EDDE R				call    cs:vidtbl[si]
 E5A8				exit:        
 E5A8  5E					pop     si
 E5A9  1F					pop     ds
 E5AA  CF					iret
 E5AB				svga:
 E5AB  3C 05					cmp     al, 5
 E5AD  74 77					je      short VESAMemControl
 E5AF  3C 01					cmp     al, 1
 E5B1  72 0D					jb      short VESAGetInfo
 E5B3  74 24					je      short VESAGetModeInfo
 E5B5  3C 03					cmp     al, 3
 E5B7  72 37					jb      short VESASetMode
 E5B9  74 4F					je      short VESAGetMode
 E5BB  B8 0100					mov     ax, 100h
 E5BE  EB E8					jmp     short exit

				; ---------------- VESA fn00
 E5C0				VESAGetInfo:
 E5C0  51					push    cx
 E5C1  57					push    di
 E5C2  BE E652 R				mov     si, offset VESAInfo
 E5C5  B9 000A					mov     cx, 10
 E5C8  F3/ 2E: A5				rep     movsw es:[di], cs:[si]
 E5CB  B1 76					mov     cl, 118     ; 236 bytes 0
 E5CD				VESASupportedClear:        
 E5CD  33 C0					xor     ax, ax
 E5CF  F3/ AB					rep     stosw
 E5D1  5F					pop     di
 E5D2  59					pop     cx     
 E5D3				VESASupported:
 E5D3  B4 00					mov     ah, 0       ; success    
 E5D5				VESASupportedErr:
 E5D5  B0 4F					mov     al, 4fh
 E5D7  EB CF					jmp     short exit

				; ---------------- VESA fn01
 E5D9				VESAGetModeInfo:
 E5D9  81 F9 0101				cmp     cx, 101h
 E5DD				VESAGetModeInfo1:        
 E5DD  B4 01					mov     ah, 1       ; error
 E5DF  75 F4					jne     short VESASupportedErr
 E5E1  51					push    cx
 E5E2  57					push    di
 E5E3  B9 0009					mov     cx, 9
 E5E6  BE E67D R				mov     si, offset VESAModeInfo
 E5E9  F3/ 2E: A5				rep     movsw es:[di], cs:[si]
 E5EC  B1 77					mov     cl, 119       
 E5EE  EB DD					jmp     short VESASupportedClear

				; ---------------- VESA fn02
 E5F0				VESASetMode:
 E5F0  6B C3 02					imul    ax, bx, 2
 E5F3  3D 0202					cmp     ax, 101h*2
 E5F6  75 0A					jne     short VESASetMode1      
 E5F8  8D 87 23FF				lea     ax, [bx+23ffh]
 E5FC  86 E0					xchg    ah, al
 E5FE  CD 10					int     10h
 E600  EB D1					jmp     short VESASupported   
 E602				VESASetMode1:
 E602  8A C3					mov     al, bl
 E604  B4 00					mov     ah, 0
 E606  CD 10					int     10h
 E608  EB C9					jmp     short VESASupported

				; ---------------- VESA fn03
 E60A				VESAGetMode:
 E60A  8A 3E 0087				mov     bh, EgaMiscInfo
 E60E  80 E7 80					and     bh, 80h
 E611  8A 1E 0049				mov     bl, ActiveVideoMode
 E615  80 FB 25					cmp     bl, 25h
 E618  74 06					je      short VESAGetMode1
 E61A  0A DF					or      bl, bh
 E61C  B7 00					mov     bh, 0
 E61E  EB B3					jmp     short VESASupported
 E620				VESAGetMode1:
 E620  81 C3 00DC				add     bx, 257-25h        
 E624  EB AD					jmp     short VESASupported

				; ---------------- VESA fn05
 E626				VESAMemControl:
				;        test    bx, not 101h                ; BX validation
				;        jnz     short VESAGetModeInfo1      ; error
 E626  0E					push    cs
 E627  68 E5D3 R				push    offset VESASupported
				;        call    VESAMemControlCB
				;        jmp     short VESASupported
 E62A				VESAMemControlCB:
 E62A  9C					pushf
 E62B  FA					cli
 E62C  50					push    ax
 E62D  52					push    dx
 E62E  8B C3					mov     ax, bx
 E630  83 E0 01					and     ax, 1
 E633  04 8A					add     al, 8ah
 E635  92					xchg    ax, dx
 E636  83 E0 07					and     ax, 7
 E639  04 0A					add     al, 0ah
 E63B  84 FF					test    bh, bh
 E63D  75 08					jnz     getpageinfo
 E63F  E8 0F6C					call    flush
 E642  EF					out     dx, ax          
 E643  5A					pop     dx
 E644  58					pop     ax
 E645  9D					popf
 E646  CB					retf
 E647				getpageinfo:
 E647  ED					in      ax, dx
 E648  2C 0A					sub     al, 0ah
 E64A  83 E0 07					and     ax, 7
 E64D  92					xchg    ax, dx
 E64E  58					pop     ax
 E64F  58					pop     ax                
 E650  9D					popf
 E651  CB					retf
				   
 E652 56 45 53 41		VESAInfo    db  'VESA'
 E656  0100 E666 R F000					dw  100h, VESAOEM, 0f000h, 2, 0, VESAModes, 0f000h, 8
       0002 0000 E679 R
       F000 0008
 E666 4E 69 63 6F 6C 61		VESAOEM     db  'Nicolae Dumitrache', 0
       65 20 44 75 6D 69
       74 72 61 63 68 65
       00
 E679 0101 FFFF			VESAModes   dw  101h, 0ffffh
 E67D				VESAModeInfo:
				;Bit(s)  Description - mode attributes 
				;0      mode supported by present hardware configuration
				;1      optional information available (must be =1 for VBE v1.2+)
				;2      BIOS output supported
				;3      set if color, clear if monochrome
				;4      set if graphics mode, clear if text mode
				;---VBE v2.0+ ---
				;5      mode is not VGA-compatible
				;6      bank-switched mode not supported
				;7      linear framebuffer mode supported
				;8      double-scan mode available (e.g. 320x200 and 320x240)
				;---VBE v3.0 ---
				;9      interlaced mode available
				;10     hardware supports triple buffering
				;11     hardware supports stereoscopic display
				;12     dual display start address support
				;13-15  reserved
 E67D  0099					dw  0000000010011001b       
				;Bit(s)  Description - window attributes
				;0      exists
				;1      readable
				;2      writable
				;3-7    reserved
 E67F  07 07					db  00000111b, 00000111b
 E681  0040 0040 A000				dw  64, 64, 0a000h, 0b000h, VESAMemControlCB, 0f000h, 640
       B000 E62A R F000
       0280

 E68F 00			p3c0r10	db		0	; port 3c0h reg 10h mirror
				; --------------- fn 00h, set video mode
 E690				setmode:
 E690  60					pusha
 E691  06					push    es
 E692  02 C0					add     al, al      ; CF = cls bit
 E694  D0 16 0087				rcl     byte ptr EgaMiscInfo, 1
 E698  D0 0E 0087				ror     byte ptr EgaMiscInfo, 1

 E69C  50					push	ax
 E69D  BA 03C4					mov		dx, 3c4h
 E6A0  B8 0F02					mov		ax, 0f02h
 E6A3  EF					out		dx, ax		; enable all write planes
 E6A4  B8 0804					mov		ax, 0804h
 E6A7  EF					out		dx, ax		; clear planar mode
 E6A8  B2 CE					mov		dl, 0ceh
 E6AA  B8 0001					mov		ax, 0001h
 E6AD  EF					out		dx, ax		; disable set/reset
 E6AE  B0 03					mov		al, 03h
 E6B0  EF					out		dx, ax		; reset logical op and rotate count
 E6B1  B0 05					mov		al, 05h
 E6B3  EF					out		dx, ax		; set write mode to 00 (CPU access)
 E6B4  B8 FF07					mov		ax, 0ff07h
 E6B7  EF			        out     dx, ax      ; set color don't care to 0Fh
 E6B8  40			        inc     ax
 E6B9  EF					out		dx, ax		; set bitmask to CPU access
 E6BA  58					pop		ax

 E6BB  3C 06					cmp     al, 3*2
 E6BD  77 2E					ja      short setmode1
 E6BF  B0 B6					mov     al, 0b6h        ; reset sound generator
 E6C1  E6 43					out     43h, al
 E6C3  B0 00					mov     al, 0
 E6C5  E6 42					out     42h, al
 E6C7  E6 42					out     42h, al
 E6C9  B8 0806					mov     ax, 0806h   ; text mode (80x25, 16 colors), flash enabled
 E6CC  C7 06 004A 0050				mov     word ptr ScreenWidth, 80
 E6D2  C7 06 004C 1000				mov     word ptr RegenLength, 1000h
 E6D8  BB B800					mov     bx, 0b800h  ; segment
 E6DB  B9 4000					mov     cx, 4000h   ; video len/2
 E6DE  BE 0720					mov     si, 0720h   ; clear value
 E6E1  BF 8F14					mov		di, 08f14h  ; 400lines, 14h offset
 E6E4  C7 06 0069 FA03 R			mov		word ptr PalOffset, offset PalVGA
 E6EA  E9 00AE					jmp     setmode2
 E6ED				setmode1:
 E6ED  3C 1A					cmp		al,	0dh*2
 E6EF  75 19					jne		short setmode12
 E6F1  BF 8F14					mov		di, 08f14h	; 400 lines, 14h offset
 E6F4  B4 11					mov		ah, 11h		; graphic, 640x480x16, half -> 320x200x16
 E6F6  C7 06 004A 0028				mov     word ptr ScreenWidth, 40
 E6FC  C7 06 004C 2000				mov     word ptr RegenLength, 2000h
 E702  C7 06 0069 F933 R			mov		word ptr PalOffset, offset PalEGA
 E708  EB 3F					jmp		short setmode121
 E70A				setmode12:	
 E70A  3C 1C					cmp		al, 0eh*2	; 640x200x16
 E70C  75 19					jne		short setmode122
 E70E  C7 06 0069 F933 R			mov		word ptr PalOffset, offset PalEGA
 E714  BF 8F28					mov		di, 8f28h	; 400lines, 28h offset
 E717				setmode1221:
 E717  B4 01					mov		ah, 1		; graphic, 640x400
 E719  C7 06 004A 0050				mov     word ptr ScreenWidth, 80
 E71F  C7 06 004C 4000				mov     word ptr RegenLength, 04000h
 E725  EB 22					jmp		short setmode121
 E727				setmode122:
 E727  C7 06 0069 FA03 R			mov		word ptr PalOffset, offset PalVGA
 E72D  3C 20					cmp		al, 10h*2
 E72F  BF 5D28					mov		di, 5d28h	; 350lines, 28h offset
 E732  74 E3					je		short setmode1221	; 640x350x16
 E734  3C 24					cmp		al, 12h*2
 E736  75 20					jne		short setmode13
 E738  BF DF28					mov		di, 0df28h	; 480lines, 28h offset
 E73B  B4 01					mov		ah, 1		; graphic, 640x480x16
 E73D  C7 06 004A 0050				mov     word ptr ScreenWidth, 80
 E743  C7 06 004C A000				mov     word ptr RegenLength, 0a000h
 E749				setmode121:
 E749  50					push	ax
 E74A  BA 03C4					mov		dx, 3c4h
 E74D  B8 FF02					mov		ax, 0ff02h
 E750  EF					out		dx, ax		; set write all planes
 E751  B8 0004					mov		ax, 0004h
 E754  EF					out		dx, ax		; set planar mode
 E755  58					pop		ax
 E756  EB 3B					jmp		short setmode21
 E758				setmode13:    
 E758  3C 26					cmp     al, 13h*2
 E75A  75 19					jne     short setmode3    
 E75C  B4 41					mov     ah, 41h     ; graphic mode, 320x200, 256 colors
 E75E  C7 06 004A 0028				mov     word ptr ScreenWidth, 40
 E764  C7 06 004C 0000				mov     word ptr RegenLength, 0000h
 E76A  BF 8F28					mov		di, 08f28h	; 400 lines, 28h offset
 E76D  C7 06 0069 F863 R			mov		word ptr PalOffset, offset Pal256
 E773  EB 1E					jmp     short setmode21
 E775				setmode3:
 E775  3C 4A					cmp     al, 25h*2
 E777  74 03 E9 00C7				jne		setmodeexit
 E77C  BF DF50					mov		di, 0df50h	; 480 lines, 50h offset
 E77F  B4 01					mov     ah, 1       ; graphic mode, 640x480, 256 colors
 E781  C7 06 004A 0050				mov     word ptr ScreenWidth, 80
 E787  C7 06 004C 0000				mov     word ptr RegenLength, 0000h
 E78D  C7 06 0069 F863 R			mov		word ptr PalOffset, offset Pal256
 E793				setmode21:
 E793  BB A000					mov     bx, 0a000h  ; segment
 E796  B9 8000					mov     cx, 8000h   ; video len/2
 E799  33 F6					xor     si, si      ; clear value
 E79B				setmode2:
 E79B  D0 E8					shr     al, 1
 E79D  A2 0049					mov     ActiveVideoMode, al
 E7A0  50					push    ax
 E7A1  51					push    cx
 E7A2  24 0B					and		al, 0bh		
 E7A4  3C 03					cmp		al, 3
 E7A6  B8 4009					mov		ax, 4009h	; build the reg 09h data (lcr9 and repln) of VGA port 3d4h
 E7A9  80 DC FF					sbb		ah, -1		; repln count (1 for graphic modes 0dh, 0eh, 13h)
 E7AC  50					push	ax
 E7AD  1E					push    ds
 E7AE  07					pop     es
 E7AF  BA 03D4					mov		dx, 3d4h
 E7B2  8B C7					mov		ax, di
 E7B4  B0 12					mov		al, 12h     ; vde
 E7B6  EF					out		dx, ax		; set scanlines
 E7B7  97					xchg	ax, di
 E7B8  8A E0					mov		ah, al
 E7BA  B0 13					mov		al, 13h
 E7BC  EF					out		dx, ax		; set offset
 E7BD  B8 1207			        mov     ax, 1207h   ; lcr8, vde8
 E7C0  EF			        out     dx, ax
 E7C1  58			        pop		ax			;	mov     ax, 4009h   ; lcr9
 E7C2  EF			        out     dx, ax
 E7C3  B8 FF18			        mov     ax, 0ff18h  ; lcr7..0
 E7C6  EF			        out     dx,ax
 E7C7  33 C0					xor     ax, ax
 E7C9  BF 0050					mov     di, offset CursorPos
 E7CC  B9 0008					mov     cx, 8
 E7CF  F3/ AB					rep     stosw           ; reset cursor position for all pages
 E7D1  B8 0500					mov     ax, 0500h
 E7D4  CD 10					int     10h             ; set page0
 E7D6  59					pop     cx
 E7D7  F6 06 0087 80				test    byte ptr EgaMiscInfo, 80h
 E7DC  75 16					jnz     short setmode4    ; no clear video memory

 E7DE  8E C3					mov     es, bx
 E7E0				clearnext:
 E7E0  96					xchg    ax, si
 E7E1  33 FF					xor     di, di
 E7E3  51					push	cx
 E7E4  F3/ AB					rep     stosw        
 E7E6  59					pop		cx
 E7E7  80 FF A0					cmp		bh, 0a0h
 E7EA  75 08					jnz		short clearok
 E7EC  96					xchg	ax, si
 E7ED  40					inc		ax
 E7EE  CD 10					int		10h
 E7F0  3C 08					cmp		al, 8
 E7F2  75 EC					jnz		short clearnext				
 E7F4				clearok:

 E7F4				setmode4:
 E7F4  BA 03DA					mov		dx, 3dah
 E7F7  EC					in		al, dx
 E7F8  58					pop     ax
 E7F9  BA 03C0					mov     dx, 3c0h
 E7FC  B0 10					mov     al, 10h
 E7FE  EE					out     dx, al
 E7FF  8A C4					mov     al, ah      
 E801  EE					out     dx, al          ; set video mode
 E802  2E: A2 E68F R				mov		cs:p3c0r10, al
 E806  B0 13					mov		al, 13h
 E808  EE					out 	dx, al
 E809  B0 00					mov		al, 0
 E80B  EE					out		dx, al		; 0 pan

 E80C  B8 1114					mov     ax, 1114h
 E80F  CD 10					int     10h         ; set 8x16 ROM font
 E811  B8 1123					mov     ax, 1123h
 E814  CD 10					int     10h         ; set ROM 8x8 font for graphics mode
 E816  B4 01					mov     ah, 1
 E818  B9 0607					mov		cx, 607h	; scanlines 13 and 14
 E81B  CD 10					int     10h         ; show cursor
 E81D  F6 06 0089 08				test    byte ptr VgaFlags, 8  ; test default palette loading
 E822  75 1F					jnz     short setmodeexit     ; no default palette
 E824  B8 1012					mov     ax, 1012h
 E827  33 DB					xor     bx, bx
 E829  B9 0040					mov     cx, 40h    
 E82C  8B 16 0069				mov     dx, PalOffset
 E830  0E					push    cs
 E831  07					pop     es
 E832  CD 10					int     10h             ; set default palette
 E834  B0 02					mov		al, 02h
 E836  81 C2 00C0				add		dx, 40h*3
 E83A  CD 10					int		10h				; set default palette EGA registers
 E83C  B0 13					mov		al, 13h
 E83E  BB 0001					mov		bx, 0001h		; select page0
 E841  CD 10					int		10h
 E843				setmodeexit:
 E843  07					pop     es
 E844  61					popa
 E845				nullproc:
 E845  C3					ret        

				; --------------- fn 01h, set cursor shape and visibility
 E846				cursor:     ; CH = start line (0-7), CH bit 5 = 1  -> cursor off
							; CL = end line (0-7)
 E846  50					push    ax
 E847  52					push    dx
 E848  89 0E 0060				mov		[CursorShape], cx
 E84C  F6 06 0085 10				test	byte ptr [ScanLinesChar], 10h
 E851  74 04					jz		short cursor8
 E853  03 C9					add		cx, cx
 E855  FE C5					inc		ch
 E857				cursor8:
 E857  BA 03D4					mov     dx, 3d4h
 E85A  B0 0A					mov     al, 0ah
 E85C  8A E5					mov		ah, ch
 E85E  EF					out     dx, ax
 E85F  40					inc		ax
 E860  8A E1					mov     ah, cl
 E862  EF					out     dx, ax
 E863  5A					pop     dx
 E864  58					pop     ax
 E865  C3					ret

				;---------------- fn 02h, set cursor pos
 E866				curpos:
 E866  50					push    ax
 E867  53					push    bx
 E868  8A C7					mov     al, bh
 E86A  C1 EB 07					shr     bx, 7
 E86D  83 E3 0E					and     bx, 0eh
 E870  89 57 50					mov     CursorPos[bx], dx
 E873  80 3E 0049 03				cmp     byte ptr ActiveVideoMode, 3
 E878  75 1E					jne     short curpos1
 E87A  3A 06 0062				cmp     al, ActivePage
 E87E  75 18					jne     short curpos1
 E880  52					push    dx
 E881  33 C0					xor     ax, ax
 E883  86 C6					xchg    al, dh        
 E885  6B C0 50					imul    ax, 80
 E888  03 C2					add     ax, dx
 E88A  BA 03D4					mov     dx, 3d4h
 E88D  50					push    ax
 E88E  8A E0					mov 	ah, al
 E890  B0 0F					mov		al, 0fh
 E892  EF					out		dx, ax
 E893  58					pop		ax
 E894  B0 0E					mov		al, 0eh
 E896  EF					out 	dx, ax
 E897  5A					pop     dx
 E898				curpos1:        
 E898  5B					pop     bx
 E899  58					pop     ax
 E89A  C3					ret

				;---------------- fn 03h, get cursor pos
 E89B				getcurpos:
 E89B  53					push    bx
 E89C  C1 EB 07					shr     bx, 7
 E89F  83 E3 0E					and     bx, 0eh
 E8A2  8B 57 50					mov     dx, CursorPos[bx]
 E8A5  8B 0E 0060				mov     cx, CursorShape
 E8A9  5B					pop     bx
 E8AA  C3					ret

				;---------------- fn 04h, light pen
 E8AB				lightpen:
 E8AB  B4 00					mov     ah, 0   ; not triggered
 E8AD  C3					ret

				;---------------- fn 05h, set active video page
 E8AE				apage:
 E8AE  60					pusha
 E8AF  E8 0CFC					call    flush
 E8B2  24 07					and     al, 7
 E8B4  8A F8					mov     bh, al
 E8B6  A2 0062					mov     ActivePage, al
 E8B9  A0 0049					mov     al, ActiveVideoMode
 E8BC  3C 13					cmp     al, 13h
 E8BE  73 19					jae		short apage1
 E8C0  3C 03					cmp     al, 3
 E8C2  77 25					ja		short apage2
 E8C4  B8 000A					mov     ax, 0ah
 E8C7  E7 8A					out     8ah, ax
 E8C9  40					inc     ax
 E8CA  E7 8B					out     8bh, ax
 E8CC  B4 03					mov     ah, 3
 E8CE  CD 10					int     10h        ; get cursor pos
 E8D0  B4 02					mov     ah, 2
 E8D2  CD 10					int     10h        ; set cursor pos
 E8D4  B8 0400					mov		ax, 400h
 E8D7  EB 13					jmp     short apage4
 E8D9				apage1:	
 E8D9  B8 000A					mov     ax, 0ah		; mode 13h and 25h
 E8DC  02 C7					add     al, bh
 E8DE  E7 8A					out     8ah, ax
 E8E0  40					inc     ax
 E8E1  3C 12					cmp     al, 12h
 E8E3  75 02					jne     short apage3
 E8E5  B0 0A					mov     al, 0ah
 E8E7				apage3: 
 E8E7  E7 8B					out     8bh, ax
 E8E9				apage2:
 E8E9  A1 004C					mov	ax, RegenLength
 E8EC				apage4:
 E8EC  C1 EB 08					shr     bx, 8      ; page number
 E8EF  F7 E3					mul     bx
 E8F1  8B D8					mov     bx, ax     ; 1 means 4 bytes, or 2 characters
 E8F3  C1 E0 02					shl     ax, 2	   ; 1 means 1 byte   
 E8F6  A3 004E					mov     PageOffset, ax
 E8F9  BA 03D4					mov     dx, 3d4h
 E8FC  8A E3					mov		ah, bl
 E8FE  B0 0D					mov		al, 0dh
 E900  EF					out		dx, ax
 E901  8A E7					mov		ah, bh
 E903  48					dec		ax
 E904  EF					out		dx, ax
 E905  61					popa
 E906  C3					ret

				;---------------- fn 06h, scroll up / clr
 E907				scrollup:
 E907  60					pusha
 E908  06					push    es
 E909  87 CA					xchg    cx, dx
 E90B  2B CA					sub     cx, dx
 E90D  41					inc     cx
 E90E  E8 0047					call    scr_params
 E911				scrollup6:        
 E911  68 B800					push    0b800h          ; segment
 E914  07					pop     es
 E915  02 D2					add     dl, dl
 E917  03 FF					add     di, di
 E919  03 3E 004E				add     di, PageOffset  ; di = top left corner address
 E91D  91					xchg    ax, cx          ; ah = 0
 E91E  84 DB					test    bl, bl
 E920  74 13					jz      short scrollup3       ; clear
 E922  2A E3					sub     ah, bl
 E924  72 0F					jb      short scrollup3       ; clear
 E926  03 F7					add     si, di
 E928				scrollup4:        
 E928  8A C8					mov     cl, al
 E92A  F3/ 26: A5				rep     movsw es:[si], es:[di]
 E92D  03 F2					add     si, dx
 E92F  03 FA					add     di, dx
 E931  FE CC					dec     ah              
 E933  79 F3					jns     short scrollup4       ; ch = lines - 1
 E935				scrollup3:                      
 E935  02 E3					add     ah, bl          ; clear rectangle: DI=address, ah=lines, al=columns, bh=attribute
 E937  93					xchg    ax, bx
 E938  B0 20					mov     al, ' '
 E93A				scrollup5:
 E93A  8A CB					mov     cl, bl
 E93C  F3/ AB					rep     stosw
 E93E  03 FA					add     di, dx
 E940  FE CF					dec     bh
 E942  79 F6					jns     short scrollup5       ; ch = lines - 1
 E944				scrollexit:
 E944  07					pop     es
 E945  61					popa
 E946  C3					ret

				;---------------- fn 07h, scroll dn / clr
 E947				scrolldn:
 E947  FD					std
 E948  60					pusha
 E949  06					push    es
 E94A  F7 D9					neg     cx
 E94C  03 CA					add     cx, dx
 E94E  41					inc     cx
 E94F  E8 0006					call    scr_params
 E952  F7 DA					neg     dx
 E954  F7 DE					neg     si
 E956  EB B9					jmp     short scrollup6

 E958				scr_params:
 E958  8A D8					mov     bl, al          ; lines
 E95A  33 C0					xor     ax, ax
 E95C  86 C6					xchg    al, dh
 E95E  6B F8 50					imul    di, ax, 80
 E961  03 FA					add     di, dx
 E963  B2 50					mov     dl, 80          ; dh = 0
 E965  2A D1					sub     dl, cl
 E967  8A C3					mov     al, bl
 E969  69 F0 00A0				imul    si, ax, 160
 E96D  C3					ret
				;---------------- fn 08h, read char/attr
 E96E				readchar:
 E96E  53					push    bx
 E96F  E8 0004					call    mode3chaddr
 E972  8B 07					mov     ax, [bx]
 E974  5B					pop     bx
 E975  C3					ret

 E976				mode3chaddr:    ; returns current char address in mode3 in ds:bx. Input: bh=page, ds=40h 
 E976  50					push    ax
 E977  81 E3 0700				and     bx, 700h
 E97B  8D 87 B800				lea     ax, [bx+0b800h]
 E97F  C1 EB 07					shr     bx, 7
 E982  8B 5F 50					mov     bx, CursorPos[bx]
 E985  8E D8					mov     ds, ax
 E987  33 C0					xor     ax, ax
 E989  86 C7					xchg    al, bh
 E98B  6B C0 50					imul    ax, 80
 E98E  03 D8					add     bx, ax
 E990  03 DB					add     bx, bx
 E992  58					pop     ax
 E993  C3					ret

				;---------------- fn 09h, write char/attr
 E994				writecharattr:
 E994  50					push    ax
 E995  06					push    es
 E996  53					push    bx
 E997  51					push    cx
 E998  8A E3					mov     ah, bl
 E99A  E8 FFD9					call    mode3chaddr
 E99D  1E					push    ds
 E99E  07					pop     es
 E99F  87 FB					xchg    di, bx
 E9A1  F3/ AB					rep     stosw
 E9A3  87 FB					xchg    di, bx
 E9A5  59					pop     cx
 E9A6  5B					pop     bx
 E9A7  07					pop     es
 E9A8  58					pop     ax
 E9A9  C3					ret

				;---------------- fn 0ah, write char
 E9AA				writechar:
 E9AA  E3 0E					jcxz    short writecharskip
 E9AC  53					push    bx
 E9AD  51					push    cx
 E9AE  E8 FFC5					call    mode3chaddr
 E9B1				writechar3:        
 E9B1  88 07					mov     [bx], al
 E9B3  83 C3 02					add     bx, 2
 E9B6  E2 F9					loop    short writechar3
 E9B8  59					pop     cx
 E9B9  5B					pop     bx
 E9BA				writecharskip:        
 E9BA  C3					ret

				;---------------- fn 0eh, write char as TTY
 E9BB				writecharTTY:
 E9BB  50					push    ax
 E9BC  53					push    bx
 E9BD  52					push    dx
 E9BE  8A 1E 0062				mov     bl, ActivePage
 E9C2  B7 00					mov     bh, 0
 E9C4  03 DB					add     bx, bx
 E9C6  8B 57 50					mov     dx, CursorPos[bx]
 E9C9  C1 E3 07					shl     bx, 7
 E9CC  B4 0A					mov     ah, 0ah
 E9CE  E8 0008					call    tty
 E9D1  B4 02					mov     ah, 2       ; set cursor pos
 E9D3  CD 10					int     10h
 E9D5  5A					pop     dx
 E9D6  5B					pop     bx
 E9D7  58					pop     ax 
 E9D8  C3					ret        

 E9D9				tty:    ; dx=xy, bh=page, al=char, bl=attr, ah=0ah(no attr) or 09h(with attr)
 E9D9  F7 06 0018 0008				test    word ptr KbdFlags2, Pause
 E9DF  75 F8					jnz     short tty
 E9E1  51					push    cx
 E9E2  3C 07					cmp     al, 7
 E9E4  74 1A					je      short bell
 E9E6  3C 08					cmp     al, 8
 E9E8  74 18					je      short bs
 E9EA  3C 0A					cmp     al, 0ah
 E9EC  74 22					je      short cr
 E9EE  3C 0D					cmp     al, 0dh
 E9F0  74 18					je      short lf
 E9F2  B9 0001					mov     cx, 1
 E9F5  CD 10					int     10h         ; write char at cursor
 E9F7  42					inc     dx
 E9F8  3A 16 004A				cmp     dl, ScreenWidth
 E9FC  73 10					jae     short crlf
 E9FE				tty1:
 E9FE  59					pop     cx
 E9FF  C3					ret
 EA00				bell:
				; TODO bell code        
 EA00  EB FC					jmp     short tty1
 EA02				bs:
 EA02  80 EA 01					sub     dl, 1
 EA05  80 D2 00					adc     dl, 0      
 EA08  EB F4					jmp     short tty1
 EA0A				lf:
 EA0A  B2 00					mov     dl, 0
 EA0C  EB F0					jmp     short tty1
 EA0E				crlf:
 EA0E  B2 00					mov     dl, 0        
 EA10				cr:        
 EA10  FE C6					inc     dh
 EA12  3A 36 0084				cmp     dh, ScreenRows
 EA16  76 E6					jbe     short tty1
 EA18  FE CE					dec     dh
				;        mov     ah, 8
				;        int     10h         ; read attribute at cursor pos
 EA1A  53					push    bx          ; save active page in bh
 EA1B  52					push    dx
				;        xchg    ax, bx
 EA1C  B7 07					mov     bh, 7       ; default attribute
 EA1E  B8 0601					mov     ax, 601h    
 EA21  8A 36 0084				mov     dh, ScreenRows
 EA25  8A 16 004A				mov     dl, ScreenWidth
 EA29  4A					dec     dx
 EA2A  33 C9					xor     cx, cx
 EA2C  CD 10					int     10h         ; scroll up
 EA2E  5A					pop     dx
 EA2F  5B					pop     bx          ; restore active page in bh         
 EA30  EB CC					jmp     short tty1
						
				;---------------- fn 0fh, read video mode
 EA32				readmode:
 EA32  A0 0087					mov     al, EgaMiscInfo
 EA35  24 80					and     al, 80h
 EA37  0A 06 0049				or      al, ActiveVideoMode
 EA3B  8A 26 004A				mov     ah, ScreenWidth
 EA3F  8A 3E 0062				mov     bh, ActivePage
 EA43  C3					ret


				;---------------- fn 10h, palette
 EA44 EA8A R EA89 R EA9A R	paltable    dw  setonereg, palexit, setallreg, setblink, palexit, palexit, palexit, readonereg, readoverscan, readallreg, palexit, palexit, palexit, palexit, palexit, palexit
       EAAE R EA89 R EA89 R
       EA89 R EADA R EB06 R
       EAEF R EA89 R EA89 R
       EA89 R EA89 R EA89 R
       EA89 R
 EA64  EB09 R EA89 R EB1F R				dw  setoneDAC, palexit, setblockDAC, paging, palexit, readoneDAC, palexit, readblockDAC, setPELmask, getPELmask, getpaging, grayscale
       EB30 R EA89 R EB60 R
       EA89 R EB78 R EB89 R
       EB92 R EB9B R EBB1 R

 EA7C				pal:
 EA7C  3C 1B					cmp     al, 1bh
 EA7E  77 09					ja      short palexit
 EA80  8B F0					mov     si, ax
 EA82  03 F6					add     si, si
 EA84  2E: FF 94 CA44 R				call    cs:paltable[si-2000h]
 EA89				palexit:
 EA89  C3					ret

 EA8A				setonereg:
 EA8A  60					pusha
 EA8B  BA 03DA					mov		dx, 3dah
 EA8E  EC					in		al, dx
 EA8F  BA 03C0					mov		dx, 3c0h
 EA92  8A C3					mov		al, bl
 EA94  EE					out		dx, al
 EA95  8A C7					mov		al, bh
 EA97  EE					out		dx, al
 EA98  61					popa
 EA99				setonereg1:        
 EA99  C3					ret        

 EA9A				setallreg:
 EA9A  60					pusha
 EA9B  B0 00					mov     al, 0
 EA9D  8B F2					mov     si, dx
 EA9F  B3 0F					mov     bl, 15
 EAA1				setallreg1:        
 EAA1  26: 8A 7C 0F				mov     bh, es:[si+15]
 EAA5  CD 10					int     10h
 EAA7  4E					dec     si
 EAA8  FE CB					dec     bl
 EAAA  79 F5					jns     short setallreg1
 EAAC  61					popa
 EAAD  C3					ret

 EAAE				setblink:
 EAAE  60					pusha
 EAAF  BA 03DA					mov		dx, 3dah
 EAB2  EC					in		al, dx
 EAB3  BA 03C0					mov     dx, 3c0h
 EAB6  B0 10					mov     al, 10h
 EAB8  EE					out     dx, al
 EAB9  2E: A0 E68F R				mov		al, cs:p3c0r10      
 EABD  C0 E3 03					shl     bl, 3
 EAC0  32 C3					xor		al, bl
 EAC2  24 F7					and		al, not 8
 EAC4  32 C3					xor		al, bl
 EAC6  EE					out     dx, al          ; set blink flag
 EAC7  2E: A2 E68F R				mov		cs:p3c0r10, al
 EACB  C0 E0 02					shl     al, 2
 EACE  32 06 0089				xor     al, VgaFlags
 EAD2  24 20					and     al, 20h
 EAD4  30 06 0089				xor     VgaFlags, al
 EAD8				setblink1:
 EAD8  61					popa
 EAD9  C3					ret

 EADA				readonereg:
 EADA  52					push	dx
 EADB  50					push	ax
 EADC  BA 03DA					mov		dx, 3dah
 EADF  EC					in		al, dx
 EAE0  BA 03C0					mov		dx, 3c0h
 EAE3  8A C3					mov		al, bl
 EAE5  EE					out		dx, al
 EAE6  42					inc		dx
 EAE7  EC					in		al, dx
 EAE8  4A					dec		dx
 EAE9  EE					out		dx, al
 EAEA  8A F8					mov		bh, al
 EAEC  58					pop		ax
 EAED  5A					pop		dx
 EAEE  C3					ret

 EAEF				readallreg:
 EAEF  60					pusha
 EAF0  8B FA					mov     di, dx
 EAF2  B3 00					mov     bl, 0
 EAF4				readllreg1:
 EAF4  B0 07					mov     al, 7
 EAF6  CD 10					int     10h
 EAF8  8A C7					mov     al, bh
 EAFA  AA					stosb
 EAFB  43					inc     bx
 EAFC  80 FB 10					cmp     bl, 16
 EAFF  75 F3					jne     short readllreg1
 EB01  B0 00					mov     al, 0   ; overscan color
 EB03  AA					stosb
 EB04  61					popa
 EB05  C3					ret

 EB06				readoverscan:
 EB06  B7 00					mov     bh, 0
 EB08  C3					ret

 EB09				setoneDAC:
 EB09  50					push    ax
 EB0A  52					push    dx
 EB0B  92					xchg    ax, dx
 EB0C  8A C3					mov     al, bl
 EB0E  BA 03C8					mov     dx, 3c8h
 EB11  EE					out     dx, al
 EB12  42					inc     dx
 EB13  8A C4					mov     al, ah
 EB15  EE					out     dx, al
 EB16  8A C5					mov     al, ch
 EB18  EE					out     dx, al
 EB19  8A C1					mov     al, cl
 EB1B  EE					out     dx, al
 EB1C  5A					pop     dx
 EB1D  58					pop     ax
 EB1E  C3					ret

 EB1F				setblockDAC:
 EB1F  60					pusha
 EB20  8B F2					mov     si, dx
 EB22  BA 03C8					mov     dx, 3c8h
 EB25  93					xchg    ax, bx
 EB26  EE					out     dx, al
 EB27  42					inc     dx
 EB28  6B C9 03					imul    cx, 3
 EB2B  F3/ 26: 6E				rep     outsb dx, es:[si]
 EB2E  61					popa
 EB2F  C3					ret

 EB30				paging:
 EB30  60					pusha
 EB31  BA 03DA					mov		dx, 3dah
 EB34  EC					in		al, dx
 EB35  BA 03C0					mov		dx, 3c0h
 EB38  84 DB					test    bl, bl
 EB3A  2E: A0 E68F R				mov		al, cs:p3c0r10
 EB3E  75 11					jnz     short paging1
 EB40  02 C0					add		al, al
 EB42  D0 CF					ror		bh, 1
 EB44  D0 D8					rcr		al, 1
 EB46  2E: A2 E68F R				mov		cs:p3c0r10, al
 EB4A  50					push	ax
 EB4B  B0 10					mov		al, 10h
 EB4D  EE					out		dx, al
 EB4E  58					pop		ax
 EB4F  EB 0C					jmp     short paging2
 EB51				paging1:
 EB51  02 C0					add		al, al
 EB53  72 03					jc		paging3
 EB55  C0 E7 02					shl		bh, 2
 EB58				paging3:
 EB58  B0 14					mov		al, 14h
 EB5A  EE					out		dx, al
 EB5B  8A C7					mov		al, bh
 EB5D				paging2:        
 EB5D  EE					out		dx, al
 EB5E  61					popa
 EB5F  C3					ret

 EB60				readoneDAC:
 EB60  50					push    ax
 EB61  52					push    dx
 EB62  8A C3					mov     al, bl
 EB64  BA 03C7					mov     dx, 3c7h
 EB67  EE					out     dx, al
 EB68  42					inc     dx
 EB69  42					inc     dx
 EB6A  EC					in      al, dx
 EB6B  8A E0					mov     ah, al
 EB6D  EC					in      al, dx
 EB6E  8A E8					mov     ch, al
 EB70  EC					in      al, dx
 EB71  8A C8					mov     cl, al
 EB73  5A					pop     dx
 EB74  8A F4					mov     dh, ah
 EB76  58					pop     ax             
 EB77  C3					ret

 EB78				readblockDAC:
 EB78  60					pusha
 EB79  8B FA					mov     di, dx
 EB7B  BA 03C7					mov     dx, 3c7h
 EB7E  93					xchg    ax, bx
 EB7F  EE					out     dx, al
 EB80  42					inc     dx
 EB81  42					inc     dx
 EB82  6B C9 03					imul    cx, 3
 EB85  F3/ 6C					rep     insb                
 EB87  61					popa
 EB88  C3					ret

 EB89				setPELmask:
 EB89  52					push    dx
 EB8A  93					xchg    ax, bx
 EB8B  BA 03C6					mov     dx, 3c6h
 EB8E  EE					out     dx, al
 EB8F  93					xchg    ax, bx
 EB90  5A					pop     dx
 EB91  C3					ret

 EB92				getPELmask:
 EB92  52					push    dx
 EB93  93					xchg    ax, bx
 EB94  BA 03C6					mov     dx, 3c6h
 EB97  EC					in      al, dx
 EB98  93					xchg    ax, bx
 EB99  5A					pop     dx
 EB9A  C3					ret

 EB9B				getpaging:
 EB9B  B3 14					mov		bl, 14h
 EB9D  E8 FF3A					call	readonereg	; returns BH
 EBA0  2E: 8A 1E E68F R				mov		bl, cs:p3c0r10
 EBA5  80 E7 0F					and		bh, 0fh
 EBA8  C0 EB 07					shr		bl, 7
 EBAB  75 03					jnz		short getpaging1
 EBAD  C0 EF 02					shr		bh, 2
 EBB0				getpaging1:
 EBB0  C3					ret

 EBB1				grayscale:
 EBB1  E3 2B					jcxz    short grayscale2
 EBB3  60					pusha
 EBB4  8A F9					mov     bh, cl
 EBB6				grayscale1:        
 EBB6  B0 15					mov     al, 15h
 EBB8  CD 10					int     10h
 EBBA  C1 EA 08					shr     dx, 8
 EBBD  6B F2 4D					imul    si, dx, 77
 EBC0  8A D5					mov     dl, ch
 EBC2  69 D2 0097				imul    dx, 151
 EBC6  B5 00					mov     ch, 0
 EBC8  6B C9 1C					imul    cx, 28
 EBCB  03 D6					add     dx, si
 EBCD  03 D1					add     dx, cx
 EBCF  8A EE					mov     ch, dh
 EBD1  8A CE					mov     cl, dh
 EBD3  B0 10					mov     al, 10h
 EBD5  CD 10					int     10h
 EBD7  FE C3					inc     bl
 EBD9  FE CF					dec     bh
 EBDB  75 D9					jne     short grayscale1        
 EBDD  61					popa
 EBDE				grayscale2:        
 EBDE  C3					ret


				;---------------- fn 11h, character generator
 EBDF				loadUDF:    ; CX=chars, DX=first char, BH=bytes/char, ES:BP=font
 EBDF  60					pusha
 EBE0  92					xchg    ax, dx
 EBE1  87 CB					xchg    cx, bx
 EBE3  C1 E9 10					shr     cx, 16 ; 8 when fonts are installed
 EBE6  BA 03CB					mov     dx, 03cbh
 EBE9  8B F5					mov     si, bp
 EBEB				loadUDF1:
 EBEB  EF					out     dx, ax
 EBEC  51					push    cx
 EBED  F3/ 26: 6E		        rep     outsb dx, es:[si]
 EBF0  59					pop     cx
 EBF1  40					inc     ax
 EBF2  4B					dec     bx
 EBF3  75 F6					jnz     short loadUDF1
 EBF5  61					popa
 EBF6  A8 10					test    al, 10h
 EBF8  74 31					jz      short loadUDFexit
 EBFA  6A 40					push    40h
 EBFC  1F					pop     ds
 EBFD  50					push    ax
 EBFE  B8 0190					mov     ax, 400 ; screen lines in text mode
 EC01  F6 F7					div     bh
 EC03  48					dec     ax
 EC04  A2 0084					mov     ScreenRows, al
 EC07  88 3E 0085				mov     byte ptr ScanLinesChar, bh
 EC0B  2E: A0 E68F R				mov		al, cs:p3c0r10		; set/reset half bit
 EC0F  32 C7					xor		al, bh		
 EC11  0C 10					or		al, 10h
 EC13  32 C7					xor		al, bh
 EC15  A8 01					test	al, 1
 EC17  75 11					jnz		short loadUDFexit1	; not in text mode
 EC19  50					push	ax
 EC1A  BA 03DA					mov		dx, 3dah
 EC1D  EC					in		al, dx
 EC1E  BA 03C0					mov		dx, 3c0h
 EC21  B0 10					mov		al, 10h
 EC23  EE					out		dx, al
 EC24  58					pop		ax
 EC25  EE					out		dx, al
 EC26  2E: A2 E68F R				mov		cs:p3c0r10, al
 EC2A				loadUDFexit1:
 EC2A  58					pop     ax 
 EC2B				loadUDFexit:        
 EC2B  C3					ret

 EC2C				chargen:
 EC2C  A8 EF					test    al, not 10h     ; test for 00h and 10h  ; UDF
 EC2E  74 AF					jz      short loadUDF
 EC30  A8 EE					test    al, not 11h     ; test for 01h and 11h  ; 8x14
 EC32  74 26					jz      short loadROMfont16
 EC34  A8 ED					test    al, not 12h     ; test for 02h and 12h  ; 8x8
 EC36  74 17					jz      short loadROMfont8
 EC38  A8 EB					test    al, not 14h     ; test for 04h and 14h  ; 8x16
 EC3A  74 1E					jz      short loadROMfont16
 EC3C  3C 20					cmp     al, 20h
 EC3E  72 EB					jb      loadUDFexit
 EC40  74 30					je      short set1f
 EC42  3C 21					cmp     al, 21h
 EC44  74 37					je      short setgrUDF
 EC46  3C 24					cmp     al, 24h
 EC48  76 60					jbe     short setROMgrFont
 EC4A  3C 30					cmp     al, 30h
 EC4C  74 7A					je      short getfontinfo
 EC4E  C3					ret

 EC4F				loadROMFont8:
 EC4F  60					pusha
 EC50  BB 0800					mov     bx, 0800h       ; 8x8 chars, block 0
 EC53  2E: 8B 2E ECF9 R				mov     bp, cs:fontinfo[2]
 EC58  EB 09					jmp     short loadROMFont161
					 
 EC5A				loadROMFont16:
 EC5A  60					pusha
 EC5B  BB 1000					mov     bx, 1000h       ; 8x16 chars, block 0
 EC5E  2E: 8B 2E ECFF R				mov     bp, cs:fontinfo[8]
 EC63				loadROMFont161:
 EC63  B9 0100					mov     cx, 100h        ; all chars
 EC66  33 D2					xor     dx, dx
 EC68  06					push    es
 EC69  0E					push    cs
 EC6A  07					pop     es
 EC6B  24 10					and     al, 10h
 EC6D  CD 10					int     10h             ; loadUDF
 EC6F  07					pop     es
 EC70  61					popa
 EC71  C3					ret

 EC72				set1f:
 EC72  33 F6					xor     si, si
 EC74  8E DE					mov     ds, si
 EC76  89 6C 7C					mov     [si+1fh*4], bp
 EC79  8C 44 7E					mov     [si+1fh*4+2], es
 EC7C  C3					ret
						
 EC7D				setgrUDF:
 EC7D  60					pusha
 EC7E  E3 AB					jcxz    short loadUDFexit
 EC80  1E					push    ds
 EC81  33 F6					xor     si, si
 EC83  8E DE					mov     ds, si
 EC85  89 AC 010C				mov     [si+43h*4], bp
 EC89  8C 84 010E				mov     [si+43h*4+2], es
 EC8D  1F					pop     ds
 EC8E  B8 00C8					mov     ax, 200
 EC91  80 3E 0049 13				cmp     byte ptr ActiveVideoMode, 13h
 EC96  72 10					jb      short setgrUDFexit
 EC98  74 03					je      short setgrUDF1
 EC9A  B8 01E0					mov     ax, 480         ; mode 25h, 480 lines
 EC9D				setgrUDF1:
 EC9D  89 0E 0085				mov     ScanLinesChar, cx
 ECA1  99					cwd
 ECA2  F7 F1					div     cx
 ECA4  48					dec     ax
 ECA5  A2 0084					mov     ScreenRows, al
 ECA8				setgrUDFexit:
 ECA8  61					popa
 ECA9  C3					ret

 ECAA				setROMgrFont:       
 ECAA  60					pusha
 ECAB  06					push    es
 ECAC  B9 0008					mov     cx, 8
 ECAF  0E					push    cs
 ECB0  07					pop     es
 ECB1  BD D800 R				mov     bp, font8x8
 ECB4  3C 23					cmp     al, 23h
 ECB6  74 03					je      short setROMgrFont1
 ECB8  BD C800 R				mov     bp, offset font8x16
 ECBB				setROMgrFont1:        
 ECBB  B0 21					mov     al, 21h
 ECBD  CD 10					int     10h     ; set graphic UDF
 ECBF  48					dec     ax
 ECC0  BD DC00 R				mov     bp, font8x8 + 128*8
 ECC3  CD 10					int     10h     ; set INT 1fh
 ECC5  07					pop     es
 ECC6  61					popa
 ECC7  C3					ret
						
 ECC8				getfontinfo:
 ECC8  8B 0E 0085				mov     cx, ScanLinesChar
 ECCC  8A 16 0084				mov     dl, ScreenRows
 ECD0  80 FF 01					cmp     bh, 1
 ECD3  77 0E					ja      short getfontinfo1
 ECD5  6A 00					push    0
 ECD7  1F					pop     ds
 ECD8  C4 2E 007C				les     bp, ds:[1fh*4] 
 ECDC  72 18					jb      short getfontinfoexit
 ECDE  C4 2E 010C				les     bp, ds:[43h*4]
 ECE2  C3					ret
 ECE3				getfontinfo1:
 ECE3  80 FF 07					cmp     bh, 7
 ECE6  77 0E					ja      short getfontinfoexit
 ECE8  8B F3					mov     si, bx
 ECEA  C1 EE 08					shr     si, 8
 ECED  03 F6					add     si, si
 ECEF  2E: 8B AC ECF3 R				mov     bp, cs:fontinfo[si-4]
 ECF4  0E					push    cs
 ECF5  07					pop     es                    
 ECF6				getfontinfoexit:
 ECF6  C3					ret

 ECF7 BA00 R D800 R DC00 R	fontinfo    dw  font8x14, font8x8, font8x8+128*8, font8x14, font8x16, font8x16
       BA00 R C800 R C800 R

				;---------------- fn 12h, special functions
 ED03				special:
 ED03  80 FB 10					cmp     bl, 10h
 ED06  75 0B					jne     short special1
 ED08  8A 0E 0088				mov     cl, EgaMiscInfo2    ; cl = switch settings
 ED0C  83 E1 0F					and     cx, 15              ; ch <- 0 (feature bits)
 ED0F  BB 0003					mov     bx, 3               ; bh <- 0 (color mode), bl = video memory size
 ED12  C3					ret
 ED13				special1:
 ED13  80 FB 31					cmp     bl, 31h
 ED16  75 0F					jne     short special2
 ED18  F6 D8					neg     al
 ED1A  32 06 0089				xor     al, VgaFlags
 ED1E  24 08					and     al, 8       ; transfer palette loading bit to VgaFlags
 ED20  30 06 0089				xor     VgaFlags, al
 ED24  B0 12					mov     al, 12h     ; supported function
 ED26  C3					ret
 ED27				special2:
 ED27  B0 00					mov     al, 0       ; unsupported function
 ED29  C3					ret


				;---------------- fn 13h, write string
 ED2A				writestr:
 ED2A  E3 31					jcxz    short wstrexit
 ED2C  60					pusha
 ED2D  8B F3					mov     si, bx
 ED2F  C1 EE 08					shr     si, 8
 ED32  03 F6					add     si, si
 ED34  FF 74 50					push    CursorPos[si]
 ED37  B4 09					mov     ah, 9       ; write tty char/attribute
 ED39				wstr1:        
 ED39  50					push    ax
 ED3A  A8 02					test    al, 2
 ED3C  26: 8A 46 00				mov     al, es:[bp]
 ED40  74 05					jz      short noattr
 ED42  45					inc     bp
 ED43  26: 8A 5E 00				mov     bl, es:[bp]
 ED47				noattr:
 ED47  45					inc     bp
 ED48  89 54 50					mov     CursorPos[si], dx
 ED4B  E8 FC8B					call    tty
 ED4E  58					pop     ax
 ED4F  E2 E8					loop    short wstr1
 ED51  8F 44 50					pop     CursorPos[si]
 ED54  A8 01					test    al, 1
 ED56  74 04					jz      short wstr2             
 ED58  B4 02					mov     ah, 2       ; set cursor pos
 ED5A  CD 10					int     10h                
 ED5C				wstr2:        
 ED5C  61					popa
 ED5D				wstrexit:        
 ED5D  C3					ret

				;---------------- fn 1ah, get/set display combination code
 ED5E				getdcc:
 ED5E  3C 01					cmp     al, 1
 ED60  77 0C					ja      short getdccexit
 ED62  8A C4					mov     al, ah
 ED64  74 03					je      short setdcc
 ED66  BB 0008					mov     bx, 08h
 ED69				dccval  label word        
 ED69				setdcc:
 ED69  2E: 89 1E ED67 R				mov     cs:[dccval-2], bx
 ED6E				getdccexit:        
 ED6E  C3					ret        

				;---------------- fn 1bh, query status
 ED6F				querystatus:
 ED6F  60					pusha
 ED70  B8 EDCE R				mov     ax, offset staticfunctable
 ED73  AB					stosw
 ED74  8C C8					mov     ax, cs
 ED76  AB					stosw
 ED77  BE 0049					mov     si, offset ActiveVideoMode
 ED7A  80 3C 12					cmp     byte ptr [si], 12h
 ED7D  B9 0021					mov     cx, 33          ; info copied from BDA        
 ED80  F3/ A4					rep     movsb
 ED82  B8 0008					mov     ax, 8
 ED85  AB					stosw                   ; display info (one VGA analog color monitor)
 ED86  BB 0208					mov     bx, 208h        ; 400 scan lines, 8 pages
 ED89  B0 10					mov     al, 10h         ; 16 colors         
 ED8B  72 14					jb      short querystatus1	; mode03h
 ED8D  BB 0302					mov		bx, 302h	; 480 scan lines, 2 pageS
 ED90  74 0F					je		short querystatus1	; mode12h 
 ED92  B7 00					mov     bh, 0           ; scan lines code (0=200, 1=350, 2=400, 3=480)
 ED94  B8 0100					mov     ax, 100h        ; 256 colors
 ED97  80 3E 0049 13				cmp     byte ptr ActiveVideoMode, 13h
 ED9C  74 0D					je      short querystatus3     ; mode13h
 ED9E  BB 0301					mov     bx, 301h        ; 480 scan lines, 1 page
 EDA1				querystatus1:
 EDA1  80 3E 0049 0D				cmp		byte ptr ActiveVideoMode, 0dh
 EDA6  75 03					jne		short querystatus3
 EDA8  BB 0008					mov		bx, 0008h	; 200 scan lines, 8 pages
 EDAB				querystatus3:
 EDAB  AB					stosw
 EDAC  93					xchg    ax, bx
 EDAD  AB					stosw
 EDAE  33 C0					xor     ax, ax
 EDB0  AB					stosw                   ; font block info (45)
 EDB1  A0 0089					mov     al, VgaFlags
 EDB4  24 2F					and     al, 00101111b
 EDB6  AB					stosw        
 EDB7  AB					stosw
 EDB8  A0 0087					mov     al, EgaMiscInfo
 EDBB  C0 E8 04					shr     al, 4
 EDBE  24 07					and     al, 7           ; video memory size
 EDC0  AB					stosw
 EDC1  B0 02					mov     al, 2
 EDC3  AA					stosb                   ; color display attached
 EDC4  B1 06					mov     cl, 6
 EDC6  33 C0					xor     ax, ax
 EDC8  F3/ AB					rep     stosw           ; 12 reserved bytes
 EDCA  61					popa
 EDCB  8A C4					mov     al, ah          ; supported function
 EDCD  C3					ret

 EDCE 0C			staticfunctable db  00001100b   ; video modes 2h, 3h supported
 EDCF  60							db  01100000b	; video mode 0dh, 0eh supported
 EDD0  0D							db  00001101b   ; video modes 10h, 12h, 13h supported
 EDD1  00							db  00000000b
 EDD2  20							db  00100000b   ; video mode 25h supported
 EDD3  00 00							db  0, 0
 EDD5  04							db  00000100b   ; 400 scanline supported
 EDD6  01							db  1           ; font blocks available in text mode
 EDD7  01							db  1           ; max active font blocks available in text mode

				;Bit(s)  Description
				;0      all modes on all displays function supported
				;1      gray summing function supported
				;2      character font loading function supported
				;3      default palette loading enable/disable supported
				;4      cursor emulation function supported
				;5      EGA palette present
				;6      color palette present
				;7      color-register paging function supported
				;8      light pen supported (see AH=04h)
				;9      save/restore state function 1Ch supported
				;10     intensity/blinking function supported (see AX=1003h)
				;11     Display Combination Code supported (see #00039)
				;12-15  unused (0)
 EDD8  EF					db  11101111b   ; miscellaneous function support flags 
 EDD9  0C					db  00001100b   ; miscellaneous function support flags
								 
 EDDA  00 00					db  0, 0        ; reserved
 EDDC  00					db  0           ; save pointer function flags
 EDDD  00					db  0           ; reserved  

					   
 EDDE E690 R E846 R E866 R	vidtbl  dw  setmode, cursor, curpos, getcurpos, lightpen, apage, scrollup, scrolldn, readchar, writecharattr
       E89B R E8AB R E8AE R
       E907 R E947 R E96E R
       E994 R
 EDF2  E9AA R E845 R E845 R			dw  writechar, nullproc, nullproc, nullproc, writecharTTY, readmode
       E845 R E9BB R EA32 R
 EDFE  EA7C R EC2C R ED03 R			dw  pal, chargen, special, writestr, nullproc, nullproc, nullproc, nullproc, nullproc, nullproc, getdcc, querystatus, nullproc
       ED2A R E845 R E845 R
       E845 R E845 R E845 R
       E845 R ED5E R ED6F R
       E845 R
 EE18				int10 endp

				; --------------------- INT 11h - Equipment ----------------
 = ds:[10h]			EquipmentWord       equ     <ds:[10h]>

 EE18				int11   proc near
 EE18  1E					push    ds
 EE19  6A 40					push    40h
 EE1B  1F					pop     ds
 EE1C  A1 0010					mov     ax, EquipmentWord
 EE1F  1F					pop     ds
 EE20  CF					iret
 EE21				int11   endp

				; --------------------- INT 12h - Memory size ----------------
 = ds:[13h]			MemorySize       equ     <ds:[13h]>

 EE21				int12   proc near
 EE21  1E					push    ds
 EE22  6A 40					push    40h
 EE24  1F					pop     ds
 EE25  A1 0013					mov     ax, MemorySize
 EE28  1F					pop     ds
 EE29  CF					iret        
 EE2A				int12   endp

				; --------------------- INT 13h - Disk services ----------------
 = ds:[74h]			HDLastError       equ     <ds:[74h]>
 = ds:[92h]			HDOpStarted       equ     <ds:[92h]>    ; bit 3: in INT13h (all other bits must be 0)
 = ds:[94h]			HDSize            equ     <ds:[94h]>

 EE2A				int13   proc near
 EE2A  1E					push    ds
 EE2B  55					push    bp
 EE2C  6A 40					push    40h
 EE2E  1F					pop     ds
 EE2F  80 36 0092 08				xor     byte ptr HDOpStarted, 8
 EE34  74 13					jz      short inINT13
 EE36  FB					sti                     
 EE37  FC					cld
 EE38  80 FC 1A					cmp     ah, 1ah
 EE3B  76 10					jbe     short Disk1
 EE3D  80 EC 26					sub     ah, 41h-1bh     ; extensions
 EE40  80 FC 22					cmp     ah, 22h
 EE43  76 08					jbe     short Disk1
 EE45  B4 01					mov     ah, 1           ; bad command error
 EE47  EB 14					jmp     short exit
 EE49				inINT13:        
 EE49  B4 AA					mov     ah, 0aah        ; drive not ready
 EE4B  EB 14					jmp     short exit2
 EE4D				Disk1:
 EE4D  8B E8					mov     bp, ax
 EE4F  C1 ED 07					shr     bp, 7
 EE52  81 E5 01FE				and     bp, 1feh
 EE56  1E					push    ds
 EE57  2E: FF 96 EE75 R				call    cs:disktbl[bp]
 EE5C  1F					pop     ds
 EE5D				exit:        
 EE5D  88 26 0074				mov     HDLastError, ah
 EE61				exit2:
 EE61  80 36 0092 08				xor     byte ptr HDOpStarted, 8
 EE66  F6 DC					neg     ah              ; CF <- (AH != 0)
 EE68				exit1:
 EE68  8B EC					mov     bp, sp
 EE6A  D0 5E 08					rcr     byte ptr [bp+8], 1
 EE6D  D0 46 08					rol     byte ptr [bp+8], 1  ; insert error CF on stack
 EE70  F6 DC					neg     ah
 EE72  5D					pop     bp
 EE73  1F					pop     ds
 EE74  CF					iret

 EE75 EEE9 R EEEC R EEFB R	disktbl dw      DiskReset, DiskGetStatus, DiskRead, DiskWrite, DiskVerify, DiskFormat, DiskFormat, DiskFormat, DiskGetParams, DiskInit, DiskRead, DiskWrite, DiskSeek, DiskRst, DiskReadSectBuffer, DiskWriteSectBuffer
       EEF6 R EEF1 R EF45 R
       EF45 R EF45 R EF54 R
       EF45 R EEFB R EEF6 R
       EF45 R EF45 R F014 R
       F014 R
 EE95  EF45 R EF45 R EF45 R			dw      DiskReady, DiskRecalibrate, DiskDiag, DiskDiag, DiskDiag, DiskGetType, DiskChanged, DiskSetDASDType, DiskSetMediaType, DiskPark, DiskFormat,  DiskExtInstCheck, DiskExtRead, DiskExtWrite, DiskExtVerify, DiskExtLock
       EF45 R EF45 R EEBB R
       EEE9 R F014 R F014 R
       EEE9 R EF45 R EEDB R
       EF95 R EF90 R EF8B R
       F014 R
 EEB5  F014 R EF45 R EFC7 R			dw      DiskExtEject, DiskExtSeek, DiskExtGetParams

 EEBB				DiskGetType:
 EEBB  80 FA 80					cmp     dl, 80h
 EEBE  75 29					jne     short DiskReset ; ah=0, drive not present
 EEC0  8B 0E 0094				mov     cx, HDSize      
 EEC4  8B D1					mov     dx, cx
 EEC6  85 C9					test    cx, cx
 EEC8  74 1F					jz      short DiskReset ; ah=0, drive not present
 EECA  B4 FD					mov     ah, -3      ; HD present
 EECC  C1 E9 06					shr     cx, 6
 EECF  C1 E2 0A					shl     dx, 10      ; CX:DX = HDSize * 1024
 EED2				DiskGetTypeexit:        
 EED2  1F					pop     ds          ; discard ret address
 EED3  1F					pop     ds          ; discard DS
 EED4  80 36 0092 08				xor     byte ptr HDOpStarted, 8     ; CF <- 0 
 EED9  EB 8D					jmp     short   exit1        

 EEDB				DiskExtInstCheck:
 EEDB  86 DF					xchg    bl, bh
 EEDD  B4 FF					mov     ah, -1
 EEDF  B9 0001					mov     cx, 1       ; extended disk access functions (AH=42h-44h,47h,48h) supported
 EEE2  80 FA 80					cmp     dl, 80h
 EEE5  75 6A					jne     short notready
 EEE7  EB E9					jmp     short DiskGetTypeexit

 EEE9				DiskReset:
 EEE9				DiskChanged:
 EEE9				DiskPark:
 EEE9  B4 00					mov     ah, 0       ; success
 EEEB  C3					ret

 EEEC				DiskGetStatus:
 EEEC  8A 26 0074				mov     ah, HDLastError
 EEF0  C3					ret
					  
 EEF1				DiskVerify:
 EEF1  BD F69E R				mov     bp, sdverify
 EEF4  EB 08					jmp     short   DiskRead1
 EEF6				DiskWrite:
 EEF6  BD F71E R				mov     bp, sdwrite
 EEF9  EB 03					jmp     short   DiskRead1
 EEFB				DiskRead:
 EEFB  BD F6A3 R				mov     bp, sdread
 EEFE				DiskRead1:        
 EEFE  84 C0					test    al, al
 EF00  74 E7					jz      short DiskReset
 EF02  80 FA 80					cmp     dl, 80h
 EF05  75 4A					jne     short notready
 EF07  B4 04					mov     ah, 4
 EF09  F6 C1 3F					test    cl, 3fh
 EF0C  74 18					jz      short DiskReadend   ; bad sector 0
 EF0E  60					pusha
 EF0F  B4 00					mov     ah, 0
 EF11  50					push    ax
 EF12  E8 0012					call    HCStoLBA
 EF15  59					pop     cx
 EF16  51					push    cx        
 EF17  FF D5					call    bp              ; DX:AX sector, ES:BX buffer, CX=sectors, returns AX=read sectors
 EF19  59					pop     cx
 EF1A  2B C8					sub     cx, ax
 EF1C  F7 D9					neg     cx              ; CF=1 if cx != 0
 EF1E  C0 D4 03					rcl     ah, 3           ; AH = 4*CF (sector not found / read error)
 EF21  8E D8					mov     ds, ax
 EF23  61					popa
 EF24  8C D8					mov     ax, ds
 EF26				DiskReadend:
 EF26  C3					ret

 EF27				HCStoLBA:       ; CX = {cyl[7:0], cyl[9:8], sect[5:0]}, DH = head. Returns DX:AX LBA
 EF27  8A C5					mov     al, ch
 EF29  8A E1					mov     ah, cl
 EF2B  C0 EC 06					shr     ah, 6
 EF2E  C1 EA 08					shr     dx, 8
 EF31  6B D2 3F					imul    dx, 63
 EF34  83 E1 3F					and     cx, 3fh
 EF37  03 CA					add     cx, dx
 EF39  49					dec     cx
 EF3A  BA 3EC1					mov     dx, 255*63
 EF3D  F7 E2					mul     dx
 EF3F  03 C1					add     ax, cx
 EF41  83 D2 00					adc     dx, 0
 EF44  C3					ret       
				;    unsigned int s = cs & 0x3f;
				;    unsigned int c = ((cs & 0xc0) << 2) | (cs >> 8);
				;    return (c*255l + h)*63l + s - 1l;

 EF45				DiskFormat:
 EF45				DiskInit:
 EF45				DiskSeek:
 EF45				DiskRst:
 EF45				DiskReady:
 EF45				DiskRecalibrate:
 EF45				DiskDiag:
 EF45				DiskExtSeek:
 EF45  83 3E 0094 00				cmp     word ptr HDSize, 0
 EF4A  74 05					je      short notready
 EF4C  80 FA 80					cmp     dl, 80h
 EF4F  74 98					je      short DiskReset
 EF51				notready:        
 EF51  B4 AA					mov     ah, 0aah        ; disk not ready
 EF53  C3					ret

 EF54				DiskGetParams:
 EF54  80 FA 80					cmp     dl, 80h
 EF57  B4 07					mov     ah, 7
 EF59  75 CB					jne     short DiskReadend   ; ret
 EF5B  B3 00					mov     bl, 0   ; ???
 EF5D  A1 0094					mov     ax, HDSize
 EF60  8B D0					mov     dx, ax
 EF62  C1 E0 0A					shl     ax, 10
 EF65  C1 EA 06					shr     dx, 6
 EF68  83 E8 1E					sub     ax, 30
 EF6B  83 DA 00					sbb     dx, 0
 EF6E  B9 3EC1					mov     cx, 63*255
 EF71  F7 F1					div     cx
 EF73  48					dec     ax
 EF74  3D 03FE					cmp     ax, 3feh
 EF77  76 03					jbe     dgpok
 EF79  B8 03FE					mov     ax, 3feh
 EF7C				dgpok:        
 EF7C  86 C4					xchg    al, ah
 EF7E  C0 E0 06					shl     al, 6
 EF81  0C 3F					or      al, 3fh
 EF83  8B C8					mov     cx, ax
 EF85  BA FE01					mov     dx, 0fe01h
 EF88  33 C0					xor     ax, ax
 EF8A  C3					ret        

 EF8B				DiskExtVerify:
 EF8B  BD F69E R				mov     bp, sdverify
 EF8E  EB 08					jmp     short DiskExtRead1
 EF90				DiskExtWrite:
 EF90  BD F71E R				mov     bp, sdwrite
 EF93  EB 03					jmp     short DiskExtRead1
 EF95				DiskExtRead:
 EF95  BD F6A3 R				mov     bp, sdread
 EF98				DiskExtRead1:
 EF98  80 FA 80					cmp     dl, 80h
 EF9B  75 B4					jne     short notready
 EF9D  06					push    es
 EF9E  50					push    ax
 EF9F  60					pusha
 EFA0  8B DC					mov     bx, sp
 EFA2  36: 8E 5F 1A				mov     ds, ss:[bx+26]
 EFA6  8B 4C 02					mov     cx, [si+2]
 EFA9  C4 5C 04					les     bx, [si+4]
 EFAC  8B 44 08					mov     ax, [si+8]
 EFAF  8B 54 0A					mov     dx, [si+10]
 EFB2  1E					push    ds
 EFB3  56					push    si
 EFB4  FF D5					call    bp
 EFB6  5E					pop     si
 EFB7  1F					pop     ds
 EFB8  2B 44 02					sub     ax, [si+2]
 EFBB  01 44 02					add     [si+2], ax
 EFBE  61					popa
 EFBF  58					pop     ax
 EFC0  1A E4					sbb     ah, ah
 EFC2  80 E4 04					and     ah, 4
 EFC5  07					pop     es
 EFC6  C3					ret

 EFC7				DiskExtGetParams:
 EFC7  80 FA 80					cmp     dl, 80h
 EFCA  75 85					jne     short notready
 EFCC  50					push    ax
 EFCD  A1 0094					mov     ax, HDSize   
 EFD0  8B EC					mov     bp, sp
 EFD2  8E 5E 08					mov     ds, [bp+8]
 EFD5  33 ED					xor     bp, bp
 EFD7  C7 04 001A				mov     word ptr [si], 1ah      ; size
 EFDB  C7 44 02 000B				mov     word ptr [si+2], 0bh    ; flags
 EFE0  C7 44 04 03FF				mov     word ptr [si+4], 1023   ; cylinders
 EFE5  89 6C 06					mov     word ptr [si+6], bp
 EFE8  C7 44 08 00FF				mov     word ptr [si+8], 255    ; heads
 EFED  89 6C 0A					mov     word ptr [si+10], bp
 EFF0  C7 44 0C 003F				mov     word ptr [si+12], 63     ; sectors/track
 EFF5  89 6C 0E					mov     word ptr [si+14], bp
 EFF8  89 44 10					mov     word ptr [si+16], ax
 EFFB  C1 64 10 0A				shl     word ptr [si+16], 10
 EFFF  C1 E8 06					shr     ax, 6
 F002  89 44 12					mov     word ptr [si+18], ax
 F005  89 6C 14					mov     word ptr [si+20], bp
 F008  89 6C 16					mov     word ptr [si+22], bp
 F00B  C7 44 18 0200				mov     word ptr [si+24], 512   ; bytes/sector
 F010  58					pop     ax
 F011  B4 00					mov     ah, 0
 F013  C3					ret 

 F014				DiskReadSectBuffer:
 F014				DiskWriteSectBuffer:
 F014				DiskSetDASDType:
 F014				DiskSetMediaType:
 F014				DiskExtLock:
 F014				DiskExtEject:
 F014  B4 01					mov     ah, 1       ; unsupported fn
 F016  C3					ret

 F017				int13   endp


				OFFDX MACRO n
					IF n LE -3 OR n GE 3
						add		dx, n
					ENDIF
					IF n EQ -2
						dec		dx
					ENDIF 
					IF n EQ -1 or n EQ -2
						dec		dx
					ENDIF
					IF n EQ 1 or n EQ 2
						inc		dx
					ENDIF 
					IF n eq 2
						inc		dx
					ENDIF
				ENDM
				; --------------------- INT 14h - Serial port I/O ----------------
 = 0000				ComPort		equ		0
 = 0000				THR			equ		0	; Transmit holding buffer
 = 0000				RBR			equ		0	; Receive buffer
 = 0000				DLL			equ		0	; divisor latch low byte (DLAB = 1)
 = 0001				DLH			equ		1	; divisor latch high byte	(DLAB = 1)
 = 0001				IER			equ		1	; Interrupt enable register
 = 0003				LCR			equ		3	; line control register (DLAB, BrkEnable, PPP, S, LL)
 = 0005				LSR			equ		5	; line status register
 = 0006				MSR			equ		6	; Modem status register

				; AH=function number, AL=char sent or received, DX=zero based COM index. Preserve all registers except AX
 F017				int14 proc near
 F017  1E					push	ds
 F018  52					push	dx
 F019  56					push	si
 F01A  6A 40					push	40h
 F01C  1F					pop		ds
 F01D  8B F2					mov		si, dx
 F01F  03 F6					add		si, si
 F021  8B 14					mov		dx, ComPort[si]
						OFFDX	LCR
 F023  83 C2 03		     1			add		dx, LCR
 F026  8B F0					mov		si, ax
 F028  EC					in		al, dx
 F029  24 7F					and		al, 7fh		; clear DLAB bit
 F02B  EE					out		dx, al
						OFFDX	LSR-LCR
 F02C  42		     1			inc		dx
 F02D  42		     1			inc		dx
 F02E  8B C6					mov		ax, si
 F030  C1 EE 08					shr		si, 8
 F033  74 0D					jz		short SetCharFormat
 F035  4E					dec		si
 F036  74 43					jz		short STransmit
 F038  4E					dec		si
 F039  74 51					jz		short SReceive
 F03B  4E					dec		si
 F03C  74 33					jz		short GetPortStatus
				;		dec		si
				;		jz		short SetCharFormatExt
 F03E				SExit:
 F03E  5E					pop		si
 F03F  5A					pop		dx
 F040  1F					pop		ds
 F041  CF					iret

				; ----- Set COM char format --------
				; AL = BBBPPSLL (BB=000..111 for baud 110,150,300,600,1200,2400,4800,9600)
				; returns LSR in AH and MSR in AL
 F042				SetCharFormat:		; DX = LSR
 F042  52					push	dx
 F043  51					push	cx
 F044  8A C8					mov		cl, al
 F046  8A E8					mov		ch, al
						OFFDX	LCR-LSR
 F048  4A		     1			dec		dx
 F049  4A		     1			dec		dx
 F04A  EC					in		al, dx
 F04B  0C 80					or		al, 80h		; set DLAB=1
 F04D  EE					out		dx, al
 F04E  C0 E9 05					shr		cl, 5
 F051  B8 0417					mov		ax, 417h
 F054  74 05					jz		short Baud110
 F056  B8 0300					mov		ax, 300h
 F059  D3 E8					shr		ax, cl
 F05B				Baud110:
						OFFDX	DLL-LCR
 F05B  83 C2 FD		     1			add		dx, DLL-LCR
 F05E  EE					out		dx, al		; set baud low
						OFFDX	DLH-DLL
 F05F  42		     1			inc		dx
 F060  8A C4					mov		al, ah
 F062  EE					out		dx, al		; set baud high
		OFFDX	LCR-DLH
 F063  42		     1			inc		dx
 F064  42		     1			inc		dx
 F065  8A C5					mov		al, ch
 F067  24 1F					and		al, 1fh
 F069  EE					out		dx, al		; set format, DLAB=0

						OFFDX	IER-LCR
 F06A  4A		     1			dec		dx
 F06B  4A		     1			dec		dx
 F06C  32 C0					xor		al, al
 F06E  EE					out		dx, al		; disable all interrupts
 F06F  59					pop		cx
 F070  5A					pop		dx

				; ----- get COM port status --------
 F071				GetPortStatus:			; DX = LSR
						OFFDX	MSR-LSR
 F071  42		     1			inc		dx
 F072  EC					in		al, dx		; read modem status
						OFFDX	LSR-MSR
 F073  4A		     1			dec		dx
 F074				GetPortStatus1:
 F074  8A E0					mov		ah, al
 F076  EC					in		al, dx		; read line (port) status
 F077  86 E0					xchg	ah, al
 F079  EB C3					jmp		short SExit
						
				; ----- Transmit char to COM port --------
				; Waits for THRE(bit5 in LSR) and then sends AL. returns LSR in AH
 F07B				STransmit:			; DX = LSR
 F07B  52					push	dx
 F07C  8A E0					mov		ah, al
 F07E				STr1:
 F07E  EC					in		al, dx
 F07F  A8 20					test	al, 20h
 F081  74 FB					jz		short STr1
						OFFDX	THR-LSR
 F083  83 C2 FB		     1			add		dx, THR-LSR
 F086  8A C4					mov		al, ah
 F088  EE					out		dx, al
 F089				STr2:
 F089  5A					pop		dx
 F08A  EB E8					jmp		short GetPortStatus1

				; ----- receive char from COM port --------
				; Waits for RDA(bit0 in  LSR) and returns the received char in AL, and the LSR in AH
 F08C				SReceive:			; DX = LSR
 F08C  52					push	dx
 F08D				SReceive1:
 F08D  EC					in		al, dx
 F08E  A8 01					test	al, 1
 F090  74 FB					jz		short SReceive1
						OFFDX	RBR-LSR
 F092  83 C2 FB		     1			add		dx, RBR-LSR
 F095  EC					in		al, dx
 F096  EB F1					jmp		short Str2


				; ----- Set COM char format extended --------
				;SetCharFormatExt:
 F098				int14 endp

				; --------------------- INT 15h - Extended services ----------------
 = ds:[98h]			UFPtr           equ     <ds:[98h]>
 = ds:[9ch]			WaitCount       equ     <ds:[9ch]>
 = ds:[0a0h]			UWaitFlag       equ     <ds:[0a0h]>
 = ds:[0a1h]			HandlerPtr      equ     <ds:[0a1h]> ; 4 bytes
 = ds:[0a5h]			DataBuffer      equ     <ds:[0a5h]> ; 3 bytes
 = ds:[067h]			DataCounter     equ     <ds:[067h]> ; 1 byte
 = ds:[068h]			PacketSize      equ     <ds:[068h]> ; 1 byte, 0->3bytes, 1->4bytes
 = 7B60				FreeXMSKb       equ     RAMSize*64 - 640 - 512 - 32	;total - DOS - VGA - BIOS

				; ------------ MovExt
 F098				IncSeg: ; DX = segment port address
 F098  75 25					jnz     short SetSegExit
 F09A  ED					in      ax, dx
 F09B  25 01FF					and     ax, RAMSize - 1
 F09E  40					inc     ax
 F09F  83 F8 12					cmp     ax, 12h
 F0A2  75 02					jne     short IncSeg1
 F0A4  33 C0					xor     ax, ax
 F0A6				IncSeg1:
 F0A6  83 F8 0C					cmp     ax, 0ch
 F0A9  75 0B					jne     short SetSeg2
 F0AB				SetSeg: ; DX = segment port address, ax = logical segment (0..RAMSize-1)    
 F0AB  25 01FF					and     ax, RAMSize - 1
 F0AE  83 F8 0C					cmp     ax, 0ch
 F0B1  72 0B					jb      short SetSeg1
 F0B3  83 C0 06					add     ax, 6
 F0B6				SetSeg2:        
 F0B6  3D 0200					cmp     ax, RAMSize
 F0B9  72 03					jb      short SetSeg1
 F0BB  2D 01F4					sub     ax, RAMSize - 0ch
 F0BE				SetSeg1:
 F0BE  EF					out     dx, ax          
 F0BF				SetSegExit:              
 F0BF  C3					ret

 = 0001				MovSeg  equ     01h
 F0C0 0000			savess  dw      0
 F0C2 F0C6 R 0000		savesp  dw      MovExt, 0 ; tmp stack
				; Log(idx) to Phy(val) segment map (RAMSize segs): 0,1,2,3,4,5,6,7,8,9,a,b,12h,13h,...,RAMSize-2,RAMSize-1,c,d,e,f,10h,11h, then wrap to 0,1,2,...
 F0C6				MovExt:
 F0C6  06					push    es
 F0C7  1E					push    ds
 F0C8  60					pusha
 F0C9  FA					cli
 F0CA  2E: 8C 16 F0C0 R				mov     cs:savess, ss
 F0CF  0E					push    cs
 F0D0  17					pop     ss
 F0D1  2E: 87 26 F0C2 R				xchg    sp, cs:savesp
 F0D6  BA 0082					mov     dx, 80h + MovSeg + 1
 F0D9  E3 72					jcxz    short MovExt_exit
 F0DB  06					push    es
 F0DC  1F					pop     ds
 F0DD  FC					cld
 F0DE  8A 44 1C					mov     al, [si+1ch]
 F0E1  8A 64 1F					mov     ah, [si+1fh]
 F0E4  8A 5C 14					mov     bl, [si+14h]
 F0E7  8A 7C 17					mov     bh, [si+17h]
 F0EA  8B 7C 1A					mov     di, [si+1ah]
 F0ED  8B 74 12					mov     si, [si+12h]
 F0F0  E8 04BB					call    flush   
 F0F3  E8 FFB5					call    SetSeg      ; 02000h = destination, DX=82h
 F0F6  4A					dec     dx
 F0F7  93					xchg    ax, bx
 F0F8  E8 FFB0					call    SetSeg      ; 01000h = source, DX=81h
 F0FB  68 1000					push    MovSeg shl 12 
 F0FE  1F					pop     ds
 F0FF  68 2000					push    (MovSeg + 1) shl 12
 F102  07					pop     es
 F103  33 DB					xor     bx, bx
 F105  03 C9					add     cx, cx
 F107  13 DB					adc     bx, bx      ; BX:CX = bytes to transfer
				; move from 01000h:si to 02000h:di, 2*cx bytes
 F109				MovExtLoop:
 F109  42					inc     dx          ; 82h
 F10A  8B C6					mov     ax, si
 F10C  3B C7					cmp     ax, di
 F10E  77 02					ja      short MovExt1
 F110  8B C7					mov     ax, di
 F112				MovExt1:
 F112  F7 D8					neg     ax
 F114  83 D3 FF					adc     bx, -1
 F117  2B C8					sub     cx, ax
 F119  83 DB 00					sbb     bx, 0
 F11C  91					xchg    ax, cx      ; cx = bytes to move, bx:ax = bytes left for the next transfer
 F11D  79 05					jns     short MovExt2   ; ax <= bx:cx     
 F11F  03 C8					add     cx, ax
 F121  33 C0					xor     ax, ax
 F123  43					inc     bx
 F124				MovExt2:
 F124  A4					movsb               ; if CX = 0 transfer 10000h bytes
 F125  49					dec     cx
 F126  74 0F					jz      short MovExt_next
 F128  F7 C6 0001				test    si, 1       ; read align
 F12C  74 02					jz      short raligned
 F12E  A4					movsb
 F12F  49					dec     cx
 F130				raligned:
 F130  D1 E9					shr     cx, 1
 F132  F3/ A5					rep     movsw
 F134  73 01					jnc     short MovExt_next
 F136  A4					movsb
 F137				MovExt_next:
 F137  E8 0474					call    flush
 F13A  8B C8					mov     cx, ax
 F13C  0B C3					or      ax, bx
 F13E  74 0D					jz      short MovExt_exit  ; finalized
 F140  85 FF					test    di, di
 F142  E8 FF53					call    incseg      ; does nothing if ZF == 0, dx = 8bh
 F145  4A					dec     dx          ; 81h
 F146  85 F6					test    si, si      
 F148  E8 FF4D					call    incseg      ; dx = 81h
 F14B  EB BC					jmp     short MovExtLoop
 F14D				MovExt_exit:
 F14D  B8 0002					mov     ax, MovSeg + 1
 F150  EF					out     dx, ax      ; 82h
 F151  48					dec     ax
 F152  4A					dec     dx
 F153  EF					out     dx, ax      ; 81h
 F154  2E: 8E 16 F0C0 R				mov     ss, cs:savess
 F159  2E: 87 26 F0C2 R				xchg    sp, cs:savesp
 F15E  61					popa
 F15F  1F					pop     ds
 F160  07					pop     es
 F161  32 E4					xor     ah, ah
 F163  EB 38					jmp     short exit_ax
 F165				MovExtProxy:
 F165  E9 FF5E					jmp     MovExt        

 F168				int15:
 F168  80 FC 4F					cmp     ah, 4fh
 F16B  74 34					je      short exit_iret
 F16D  86 C4					xchg    al, ah
 F16F  3C 80					cmp     al, 80h
 F171  72 27					jb      short exit15; CF=1  for <80h
 F173  3C 83					cmp     al, 83h
 F175  72 22					jb      short done  ; no error for 80, 81, 82
 F177  74 29					je      short SetEventWait; 83
 F179  3C 86					cmp     al, 86h
 F17B  72 1D					jb      short exit15; CF=1 for 84, 85
 F17D  74 58					je      short Wait1 ; 86
 F17F  3C 88					cmp     al, 88h
 F181  72 E2					jb      short MovExtProxy ; 87
 F183  74 6B					je      short ExtSize     ; 88
 F185  3C 90					cmp     al, 90h
 F187  72 11					jb      short  exit15; CF=1 for 89..8f
 F189  3C 92					cmp     al, 92h
 F18B  72 0C					jb      short done  ; no error for 90, 91
 F18D  3C C0					cmp     al, 0c0h
 F18F  72 09					jb      short exit15; CF=1 for 92..bf
 F191  74 62					je      short GetConfig   ; c0
 F193  3C C2					cmp     al, 0c2h
 F195  72 03					jb      short exit15; CF=1 for c1
 F197  74 65					je      short Mouse ; c2
 F199				done:
 F199  F5					cmc                 ; CF=1 for >c2
 F19A				exit15:
 F19A  B8 8600					mov     ax, 8600h
 F19D				exit_ax:        
 F19D  FB					sti
 F19E  CA 0002					retf    2           ; discard flags (need to keep CF)
 F1A1				exit_iret:
 F1A1  CF					iret        

				; ------------ SetEventWait
 F1A2				SetEventWait:
 F1A2  1E					push    ds
 F1A3  6A 40					push    40h
 F1A5  1F					pop     ds
 F1A6  80 F4 01					xor     ah, 1
 F1A9  74 21					jz      short cancel
 F1AB  84 26 00A0				test    ah, byte ptr UWaitFlag ; ah=1
 F1AF  75 22					jnz     short busy  ; CF=0
 F1B1  B8 03E7					mov     ax, 1000-1  ; 1ms
 F1B4  E7 70					out     70h, ax     ; restart RTC timer
 F1B6  89 1E 0098				mov     UFPtr[0], bx
 F1BA  8C 06 009A				mov     UFPtr[2], es
 F1BE  03 C2					add     ax, dx
 F1C0  83 D1 00					adc     cx, 0
 F1C3  A3 009C					mov     WaitCount[0], ax
 F1C6  89 0E 009E				mov     WaitCount[2], cx
 F1CA  B4 01					mov     ah, 1       ; wait in progress
 F1CC				cancel:
 F1CC  88 26 00A0				mov     byte ptr UWaitFlag, ah   
 F1D0  CD 70					int     70h
 F1D2  F9					stc                 ; no error
 F1D3				busy:   
 F1D3  F5					cmc                 ; eror        
 F1D4				nowait:
 F1D4  1F					pop     ds
 F1D5  EB C3					jmp     short exit15

				; ------------ Wait
 F1D7				Wait1:
 F1D7  06					push    es
 F1D8  53					push    bx
 F1D9  B8 8300					mov     ax, 8300h
 F1DC  6A 4A					push    4ah
 F1DE  07					pop     es
 F1DF  33 DB					xor     bx, bx      ; user wait flag address=0040:00a0
 F1E1  CD 15					int     15h         ; returns with IF = 1
 F1E3  72 07					jc      short wbusy
 F1E5				wloop:        
 F1E5  F4					hlt   
 F1E6  26: F6 07 80				test    byte ptr es:[bx], 80h
 F1EA  74 F9					jz      short wloop
 F1EC				wbusy:        
 F1EC  5B					pop     bx
 F1ED  07					pop     es
 F1EE  EB AA					jmp     short exit15
						

				; ------------ ExtSize
 F1F0				ExtSize:
 F1F0  B8 7B60					mov     ax, FreeXMSKb
 F1F3  EB A8					jmp     short exit_ax
						
				; ------------ GetConfig
 F1F5				GetConfig:
 F1F5  33 C0					xor     ax, ax
 F1F7  0E					push    cs
 F1F8  07					pop     es
 F1F9  BB F2F6 R				mov     bx, offset SysParams
 F1FC  EB 9F					jmp     short exit_ax
						
				; ------------ Mouse 
 F1FE				Mouse:
 F1FE  1E					push    ds
 F1FF  52					push    dx
 F200  6A 40					push    40h
 F202  1F					pop     ds
 F203  F6 06 0010 04				test    byte ptr EquipmentWord, 4 ; ps2 mouse equipement word
 F208  75 16					jnz     short mouse_present
 F20A				if_err:
 F20A  B8 03A7					mov     ax, 03a7h   ; interface error (no mouse present)
 F20D  E6 64					out     64h, al     ; disable mouse
 F20F				errexit:        
 F20F  F9					stc                 ; error
 F210				exitok:        
 F210  9C					pushf               ; save CF
 F211  E4 A1					in      al, 0a1h
 F213  24 EF					and     al, not 10h     
 F215  E6 A1					out     0a1h, al    ; enable mouse interrupts
 F217  E8 0387					call    enableKbIfPresent
 F21A  9D					popf
 F21B  5A					pop     dx
 F21C  1F					pop     ds
 F21D  E9 FF7D					jmp     exit_ax
 F220				mouse_present:
 F220  8A C4					mov     al, ah                                  
 F222  B4 01					mov     ah, 1       ; invalid function
 F224  3C 07					cmp     al, 7
 F226  77 E7					ja      short errexit
 F228  50					push    ax
 F229  E4 A1					in      al, 0a1h
 F22B  0C 10					or      al, 10h     
 F22D  E6 A1					out     0a1h, al    ; disable mouse interrupts
 F22F  FB					sti                 ; allow interrupts for a short time, to flush possible pending KB/mouse requests
 F230  B0 AD					mov     al, 0adh
 F232  E6 64					out     64h, al     ; disable kb interface
 F234  58					pop     ax
 F235  3C 01					cmp     al, 1
 F237  FA					cli                 ; from now on we are working with ints disabled, as the following code is highly non re-entrant
 F238  72 1C					jb      short en_dis
 F23A  74 33					je      short reset
 F23C  3C 03					cmp     al, 3
 F23E  72 40					jb      short sampling
 F240  74 5D					je      short resolution
 F242  3C 05					cmp     al, 5
 F244  72 63					jb      short gettype
 F246  74 27					je      short reset
 F248  3C 06					cmp     al, 6
 F24A  74 75					je      short extend

				; ------------- set handler
 F24C  89 1E 00A1				mov     HandlerPtr[0], bx
 F250  8C 06 00A3				mov     HandlerPtr[2], es
 F254  EB 15					jmp     short exit_success1        

				; ------------- enable/disable
 F256				en_dis:
 F256  B8 02F5					mov     ax, 02f5h   ; ah = invalid input
 F259  2A C7					sub     al, bh
 F25B  38 E7					cmp     bh, ah
 F25D  73 B0					jnc     short errexit
 F25F  8A E0					mov     ah, al
 F261  E8 032C					call    sendcmd     ; enable/disable data reporting (CF = 1)
 F264				if_err1:        
 F264  72 A4					jc      short if_err
 F266				exit_success:
 F266  C6 06 0067 00				mov     byte ptr DataCounter, 0
 F26B				exit_success1:
 F26B  32 E4					xor     ah, ah      ; success
 F26D  EB A1					jmp     short exitok

				; ------------- reset
 F26F				reset:
 F26F  B4 F6					mov     ah, 0f6h    ; set defaults
 F271  F9					stc                 ; mouse command
 F272  E8 031B					call    sendcmd     
 F275  72 93					jc      short if_err
 F277  BB 00AA					mov     bx, 00aah
 F27A  88 3E 0068				mov     byte ptr PacketSize, bh ; 3bytes packet
 F27E  EB E6					jmp     short exit_success

				; ------------- sampling
 F280				sampling:
 F280  80 FF 06					cmp     bh, 6
 F283				badparam:
 F283  B4 02					mov     ah, 2       ; invalid input
 F285  77 88					ja      short errexit
 F287  C1 EB 08					shr     bx, 8
 F28A  2E: 8A A7 F2EF R				mov     ah, cs:sample_tbl[bx]
 F28F  50					push    ax
 F290  B4 F3					mov     ah, 0f3h    ; st sample rate
 F292				send2c:
 F292  F9					stc
 F293  E8 02FA					call    sendcmd              
 F296  58					pop     ax
 F297  72 CB					jc      short if_err1
 F299				send1c:
 F299  F9					stc
 F29A  E8 02F3					call    sendcmd
 F29D  EB C5					jmp     short if_err1

				; ------------- resolution
 F29F				resolution:
 F29F  80 FF 03					cmp     bh, 3
 F2A2  77 DF					ja      short badparam
 F2A4  53					push    bx
 F2A5  B4 E8					mov     ah, 0e8h    ; set resolution
 F2A7  EB E9					jmp     short send2c

				; ------------- gettype
 F2A9				gettype:
 F2A9  B4 F2					mov     ah, 0f2h
 F2AB  F9					stc
 F2AC  E8 02E1					call    sendcmd
 F2AF  72 B3					jc      short if_err1
 F2B1  E8 02C2					call    getps2byte
 F2B4  72 AE					jc      short if_err1
 F2B6  8A F8					mov     bh, al
 F2B8  F6 D8					neg     al          ; CF=1 if al != 0
 F2BA  12 C7					adc     al, bh
 F2BC  A2 0068					mov     byte ptr PacketSize, al ; 3 or 4 bytes packet
 F2BF  EB A5					jmp     short exit_success
						
				; ------------- extended commands
 F2C1				extend:
 F2C1  84 FF					test    bh, bh
 F2C3  75 1F					jnz     short setscaling
 F2C5  B4 E9					mov     ah, 0e9h    ; status request
 F2C7  F9					stc
 F2C8  E8 02C5					call    sendcmd
 F2CB  72 97					jc      short if_err1
 F2CD  E8 02A6					call    getps2byte
 F2D0  72 92					jc      short if_err1
 F2D2  8A D8					mov     bl, al
 F2D4  E8 029F					call    getps2byte
 F2D7  72 8B					jc      short if_err1
 F2D9  8A C8					mov     cl, al
 F2DB  E8 0298					call    getps2byte
 F2DE  72 84					jc      short if_err1
 F2E0  5A					pop     dx  
 F2E1  50					push    ax          ; replace dx on stack
 F2E2  EB 82					jmp     short exit_success
 F2E4				setscaling:    
 F2E4  80 FF 02					cmp     bh, 2
 F2E7  77 9A					ja      short badparam
 F2E9  B4 E5					mov     ah, 0e5h    ; set scaling 1:1 or 2:1
 F2EB  02 E7					add     ah, bh
 F2ED  EB AA					jmp     short send1c

 F2EF 0A 14 28 3C 50 64		sample_tbl  db  10, 20, 40, 60, 80, 100, 200
       C8
 F2F6 08 00 FC 00 00		SysParams   db  8, 0, 0fch, 0, 0
				;--------------------------------------------------------------------------
				; Feature byte 1
				; b7: 1=DMA channel 3 used by hard disk
				; b6: 1=2 interrupt controllers present
				; b5: 1=RTC present
				; b4: 1=BIOS calls int 15h/4Fh every key
				; b3: 1=wait for extern event supported (Int 15h/41h)
				; b2: 1=extended BIOS data area used
				; b1: 0=AT or ESDI bus, 1=MicroChannel
				; b0: 1=Dual bus (MicroChannel + ISA)
				;--------------------------------------------------------------------------
 F2FB  10						db      10h
				;--------------------------------------------------------------------------
				; Feature byte 2
				; b7: 1=32-bit DMA supported
				; b6: 1=int16h, function 9 supported
				; b5: 1=int15h/C6h (get POS data) supported
				; b4: 1=int15h/C7h (get mem map info) supported
				; b3: 1=int15h/C8h (en/dis CPU) supported
				; b2: 1=non-8042 kb controller
				; b1: 1=data streaming supported
				; b0: reserved
				;--------------------------------------------------------------------------
 F2FC  44						db      44h
				;--------------------------------------------------------------------------
				; Feature byte 3
				; b7: not used
				; b6: reserved
				; b5: reserved
				; b4: POST supports ROM-to-RAM enable/disable
				; b3: SCSI on system board
				; b2: info panel installed
				; b1: Initial Machine Load (IML) system - BIOS on disk
				; b0: SCSI supported in IML
				;--------------------------------------------------------------------------
 F2FD  00						db      0
				;--------------------------------------------------------------------------
				; Feature byte 4
				; b7: IBM private
				; b6: EEPROM present
				; b5-3: ABIOS presence (011 = not supported)
				; b2: private
				; b1: memory split above 16Mb supported
				; b0: POSTEXT directly supported by POST
				;--------------------------------------------------------------------------
 F2FE  00						db      0
				;--------------------------------------------------------------------------
				; Feature byte 5 (IBM)
				; b1: enhanced mouse
				; b0: flash EPROM
				;--------------------------------------------------------------------------
 F2FF  00						db      0                                                


				; --------------------- INT 16h - keyboard interface ----------------
				;       AH      Description
				;       --      ------------------------------------------------
				;       00h     Get a key from the keyboard, return code in AX.
				;       01h     Test for available key, ZF=1 if none, ZF=0 and
				;               AX contains next key code if key available.
				;       02h     Get shift status. Returns shift key status in AL.
				;       03h     Set Autorepeat rate. BH=0,1,2,3 (delay time in quarter seconds), BL=0..1Fh for 30 char/sec to 2 char/sec repeat rate.
				;       05h     Store scan code (in CX) in the type ahead buffer.
				;       10h     Get a key (same as 00h in this implementation).
				;       11h     Test for key (same as 01h).
				;       12h     Get extended key status. Returns status in AX.

 = ds:[19h]			AltKpd          equ     <ds:[19h]>
 = ds:[1ah]			HeadPtr         equ     <ds:[1ah]>
 = ds:[1ch]			TailPtr         equ     <ds:[1ch]>
 = ds:[80h]			Buffer          equ     <ds:[80h]>;1eh
 = ds:[82h]			EndBuf          equ     <ds:[82h]>;3eh

 F300				int16 proc near
 F300  1E					push    ds
 F301  56					push    si
 F302  6A 40					push    40h
 F304  1F					pop     ds
 F305  86 C4					xchg    al, ah          ;shorter opcodes for al than ah
 F307  48					dec     ax
 F308  A8 EF					test    al, 0EFh        ;Check for 01h and 11h
 F30A  74 3E					jz      short TestKey   ;TestKey does not need cld
 F30C  40					inc     ax
 F30D  FC					cld
 F30E  A8 EF					test    al, 0EFh        ;Check for 0h and 10h
 F310  74 1C					jz      short GetKey
 F312  3C 03					cmp     al, 3           ;Check for 02h and 03h
 F314  72 78					jb      short GetStatus
 F316  74 7B					je      short SetAutoRpt   
 F318  3C 05					cmp     al, 5           ;Check for StoreKey function.
 F31A  74 3D					je      short StoreKey
 F31C  3C 09					cmp     al, 9           ;Get KB functionality
 F31E  74 08					je      short kbfunc     
 F320  3C 12					cmp     al, 12h         ;Extended status call
 F322  74 56					je      short ExtStatus
 F324  3C 92					cmp     al, 92h         ;stupid keyb.com 
 F326  75 02					jne     short Exit
 F328				kbfunc:
 F328  B0 24					mov     al, 24h         ;AL=20h (fn 10h, 12h supported, set typematic supported)        
 F32A				Exit:        
 F32A  5E					pop     si
 F32B  1F					pop     ds
 F32C  CF					iret                    ; unknown function, Restores flags.

 F32D				GetKey1:                        ; wait for interrupt
 F32D  F4					hlt
 F32E				GetKey: ; ----------- fn 00h, 10h
 F32E  B4 11					mov     ah, 11h
 F330  CD 16					int     16h             ;See if key is available (IF becomes 1 after this int)
 F332  74 F9					jz      short GetKey1   ;Wait for keystroke.
 F334  FA					cli                     ;Critical region! Ints off.
 F335  8B 36 001A				mov     si, HeadPtr     ;Ptr to next character.
 F339  AD					lodsw                   ;Get the character, Bump up HeadPtr
 F33A  3B 36 0082				cmp     si, EndBuf
 F33E  72 04					jb      short noWrap
 F340  8B 36 0080				mov     si, Buffer
 F344				noWrap:             
 F344  89 36 001A				mov     HeadPtr, si
 F348  EB E0					jmp     short Exit

 F34A				TestKey: ; ---------- fn 01h
 F34A  8B 36 001A				mov     si, HeadPtr
 F34E  3B 36 001C				cmp     si, TailPtr     ;ZF=1, if empty buffer
 F352  AD					lodsw                   ;BIOS returns avail keycode.
 F353  FB					sti                     ;Ints back on.
 F354  5E					pop     si
 F355  1F					pop     ds
 F356  CA 0002					retf    2               ;Pop flags (ZF is important!)

 F359				StoreKey: ; ---------- fn 05h - Inserts the value in CX into the type ahead buffer.  
 F359  8B 36 001C				mov     si, TailPtr     ;Address where we can put next key code.
 F35D  89 0C					mov     [si], cx        ;Store the key code away
 F35F  46					inc     si
 F360  46					inc     si              ;Move on to next entry in buf
 F361  3B 36 0082				cmp     si, EndBuf
 F365  72 04					jb      short NoWrap1
 F367  8B 36 0080				mov     si, Buffer
 F36B				 NoWrap1:
 F36B  B0 01					mov     al, 1           ;no room
 F36D  3B 36 001A				cmp     si, HeadPtr     ;Data overrun?
 F371  74 B7					je      short Exit      ;if so, ignore key entry.
 F373  89 36 001C				mov     TailPtr, si
 F377  48					dec     ax              ;al=0
 F378  EB B0					jmp     short Exit       

 F37A				ExtStatus: ; ------- fn 12h - Retrieve the extended keyboard status and return it in AH, and the standard keyboard status in AL.    
 F37A  A0 0018					mov     al, KbdFlags2
 F37D  24 77					and     al, 01110111b   ;Clear final sysreq field, and final right alt bit.
 F37F  A8 04					test    al, 100b        ;Test cur sysreq bit.
 F381  74 02					jz      short NoSysReq  ;Skip if it's zero.
 F383  2C 84					sub     al, 10000100b   ;Set final sysreq bit, clear final right ctl bit.
 F385				NoSysReq:
 F385  8A 26 0096				mov     ah, KbdFlags3
 F389  80 E4 0C					and     ah, 1100b       ;Grab rt alt/ctrl bits.
 F38C  0A E0					or      ah, al          ;Merge into AH.

 F38E				GetStatus: ; --------- fn 02h     
 F38E  A0 0017					mov     al, KbdFlags1   ;Just return Std Status.
 F391				Exit1:
 F391  EB 97					jmp     short Exit

 F393				SetAutoRpt: ; ------ fn 03h
 F393  80 FC 05					cmp     ah, 5
 F396  75 92					jne     short Exit
 F398  52					push    dx
 F399  C0 E7 05					shl     bh, 5
 F39C  80 E3 1F					and     bl, 1fh
 F39F  0A DF					or      bl, bh
 F3A1  80 E3 7F					and     bl, 7fh
 F3A4  B4 00					mov     ah, 0           ; wait LED update progress to finalize
 F3A6  E8 0028					call    WaitFlag        ; leaves with IF=0
 F3A9  72 23					jc      short timeout
 F3AB  80 0E 0097 08				or      byte ptr KbdFlags4, SetRepeat    ; set auto repeat in progress
 F3B0  B4 F3					mov     ah, 0f3h        ; set typematic rate and delay
 F3B2  53					push    bx
 F3B3  32 DB					xor     bl, bl          ; send to kb
 F3B5  E8 0199					call    sendps2byte
 F3B8  5B					pop     bx
 F3B9  72 0E					jc      short timeout1  ; send timeout
 F3BB  B4 18					mov     ah, SetRepeat or AckReceived ; test if ACK received
 F3BD  E8 0011					call    WaitFlag
 F3C0  72 07					jc      short timeout1
 F3C2  8A E3					mov     ah, bl
 F3C4  32 DB					xor     bl, bl          ; send to kb
 F3C6  E8 0188					call    sendps2byte     ; send data
 F3C9				timeout1:
 F3C9  80 26 0097 F7				and     byte ptr KbdFlags4, not SetRepeat   
 F3CE				timeout:
 F3CE  5A					pop     dx
 F3CF  EB C0					jmp     short Exit1


 F3D1				WaitFlag:   ; ah = desired KbdFlags4 & (AckReceived | LEDUpdate | SetRepeat)
 F3D1  BA 03DA					mov     dx, 3dah
 F3D4  B7 C8					mov     bh, 8*25    ; wait for max 25 * VGA frame time
 F3D6				wf_loop:
 F3D6  FA					cli
 F3D7  A0 0097					mov     al, KbdFlags4
 F3DA  24 58					and     al, AckReceived or LEDUpdate or SetRepeat
 F3DC  38 E0					cmp     al, ah
 F3DE  74 0A					je      short wf_ok ; flag ok, CF=0
 F3E0  FB					sti
 F3E1  EC					in      al, dx      ; get vblank
 F3E2  32 C7					xor     al, bh
 F3E4  24 08					and     al, 8h
 F3E6  2A F8					sub     bh, al
 F3E8  73 EC					jnc     short wf_loop     ; IBF - buffer full, no timeout
 F3EA				wf_ok:
 F3EA  C3					ret
 F3EB				int16 endp

				; --------------------- INT 18h - BIOS Basic ------------------
 F3EB				int18 proc near
 F3EB  0E					push    cs
 F3EC  07					pop     es
 F3ED  BE F423 R				mov     si, offset booterrmsg
 F3F0  E8 01F9					call    prts
 F3F3  E8 01B8					call	flush

				;-------------- RS232 bootstrap
 F3F6  B0 B4					mov     al, 0b4h
 F3F8  E6 43					out     43h, al
 F3FA  B8 F000					mov     ax, 0f000h
 F3FD  E6 42					out     42h, al
 F3FF  E6 42					out     42h, al      ; 18Hz PIT CH2
 F401  E7 01					out		1, ax		; disable auto flush on vblank (bit0)
 F403  8E D8					mov		ds,ax
 F405  8E C0					mov		es,ax

 F407  BE 0100					mov		si,100h
 F40A  E8 0118					call	srecb
 F40D  FA					cli
 F40E  8A FC					mov		bh,ah
 F410  E8 0112					call	srecb
 F413  8A DC					mov		bl,ah
 F415				sloop:	
 F415  E8 010D					call	srecb
 F418  88 24					mov		[si],ah
 F41A  46					inc		si
 F41B  4B					dec		bx
 F41C  75 F7					jnz		short sloop
 F41E  EA					db		0eah
 F41F  0100 F000				dw		100h,0f000h

 F423 4E 6F 20 62 6F 6F		booterrmsg db   'No boot device available, waiting on RS232 (115200bps, f000:100) ...', 13, 10, 0
       74 20 64 65 76 69
       63 65 20 61 76 61
       69 6C 61 62 6C 65
       2C 20 77 61 69 74
       69 6E 67 20 6F 6E
       20 52 53 32 33 32
       20 28 31 31 35 32
       30 30 62 70 73 2C
       20 66 30 30 30 3A
       31 30 30 29 20 2E
       2E 2E 0D 0A 00
 F46A				int18 endp

				; --------------------- INT 19h - OS Bootstrap loader ------------------
 F46A				int19 proc near
 F46A  B8 0201					mov     ax, 201h
 F46D  B9 0001					mov     cx, 1
 F470  BA 0080					mov     dx, 80h
 F473  6A 00					push    0
 F475  07					pop     es
 F476  BB 7C00					mov     bx, 7c00h
 F479  CD 13					int     13h
 F47B  72 05					jc      int19err
 F47D  EA					db      0eah
 F47E  7C00 0000				dw      7c00h, 0     ; jmp far 0000h:7c00h
 F482				int19err:
 F482  CD 18					int     18h
 F484				int19 endp


				; --------------------- INT 1ah - Get System Time ------------------
 F484				int1a proc near
 F484  1E					push    ds
 F485  6A 40					push    40h
 F487  1F					pop     ds
 F488  80 FC 01					cmp     ah, 1
 F48B  77 12					ja      clockexit
 F48D  74 16					je      setclock
 F48F  8B 16 006C				mov     dx, ds:[6ch]    ; read clock
 F493  8B 0E 006E				mov     cx, ds:[6eh]
 F497  A0 0070					mov     al, ds:[70h]
 F49A				clockexit1:
 F49A  C6 06 0070 00				mov     byte ptr ds:[70h], 0
 F49F				clockexit:
 F49F  F5					cmc     ; CF = 1 on error
 F4A0  1F					pop     ds
 F4A1  FB					sti
 F4A2  CA 0002					retf    2

 F4A5				setclock:
 F4A5  89 16 006C				mov     ds:[6ch], dx
 F4A9  89 0E 006E				mov     ds:[6eh], cx
 F4AD  F9					stc
 F4AE  EB EA					jmp     short clockexit1    
 F4B0				int1a endp


				; --------------------- INT 70h - RTC ------------------
 F4B0				int70 proc near
 F4B0  1E					push    ds
 F4B1  6A 40					push    40h
 F4B3  1F					pop     ds
 F4B4  F6 06 00A0 01				test    byte ptr UWaitFlag, 1    ; is wait in progress?
 F4B9  74 1B					jz      short exit1
 F4BB  81 2E 009C 03E8				sub     word ptr WaitCount[0], 1000
 F4C1  83 1E 009E 00				sbb     word ptr WaitCount[2], 0
 F4C6  73 14					jnc     short exit
 F4C8  C6 06 00A0 00				mov     byte ptr UWaitFlag, 0
 F4CD  53					push    bx
 F4CE  C5 1E 0098				lds     bx, UFPtr
 F4D2  80 0F 80					or      byte ptr [bx], 80h
 F4D5  5B					pop     bx
 F4D6				exit1:
 F4D6  50					push	ax
 F4D7  33 C0					xor		ax, ax
 F4D9  E7 70					out		70h, ax	; stop RTC
 F4DB  58					pop		ax
 F4DC				exit: 
 F4DC  1F					pop     ds
 F4DD  CF					iret
 F4DE				int70 endp

						
				; --------------------- INT 74h - mouse ------------------
 F4DE				int74 proc near
 F4DE  FC					cld
 F4DF  60					pusha
 F4E0  1E					push    ds
 F4E1  6A 40					push    40h
 F4E3  1F					pop     ds
 F4E4  B4 00					mov     ah, 0
 F4E6  E4 60					in      al, 60h
 F4E8  8B D8					mov     bx, ax
 F4EA  FE 06 0067				inc     byte ptr DataCounter
 F4EE  A0 0067					mov     al, DataCounter
 F4F1  8B F0					mov     si, ax
 F4F3  2C 03					sub     al, 3
 F4F5  77 0C					ja      short docall
 F4F7  88 9C 00A4				mov     DataBuffer[si-1], bl
 F4FB  3A 06 0068				cmp     al, PacketSize
 F4FF  75 21					jne     short nocall
 F501  B3 00					mov     bl, 0
 F503				docall:
 F503  88 3E 0067				mov     byte ptr DataCounter, bh    ; BH=0
 F507  BE 00A3					mov     si, offset DataBuffer-2
 F50A  AD					lodsw
 F50B  0B 44 FC					or      ax, [si-4]
 F50E  74 12					jz      short nocall
 F510  FB					sti
 F511  06					push    es
 F512  B4 00					mov     ah, 0
 F514  AC					lodsb
 F515  50					push    ax
 F516  AC					lodsb
 F517  50					push    ax
 F518  AC					lodsb
 F519  50					push    ax
 F51A  53					push    bx
 F51B  FF 5C F9					call    far ptr [si-7]
 F51E  83 C4 08					add     sp, 8
 F521  07					pop     es
 F522				nocall:        
 F522  1F					pop     ds
 F523  61					popa
 F524  CF					iret
 F525				int74 endp


				; ----------------  serial receive byte 115200 bps --------------
 F525  B4 80			srecb:  mov     ah, 80h
 F527  BA 03DA					mov     dx, 3dah
 F52A  B9 FA52					mov     cx, -5aeh ; (half start bit)
 F52D  EC			srstb:  in      al, dx
 F52E  C0 E8 02					shr     al, 2
 F531  72 FA					jc      short srstb
 F533  E4 42					in      al, 42h ; lo counter
 F535  02 E8					add     ch, al
 F537  E4 42					in      al, 42h ; hi counter, ignore
 F539				l1:
 F539  E8 0008					call    dlybit
 F53C  EC					in      al, dx
 F53D  C0 E8 02					shr     al, 2
 F540  D0 DC					rcr     ah, 1
 F542  73 F5					jnc     short l1
 F544				dlybit:
 F544  81 E9 0A5B				sub     cx, 0a5bh  ;  (full bit)
 F548				dly1:
 F548  E4 42					in      al, 42h
 F54A  38 E8					cmp     al, ch
 F54C  E4 42					in      al, 42h
 F54E  75 F8					jnz     short dly1
 F550  C3					ret

				; -------------------- KB/Mouse access ----------------
 F551				sendps2byte proc near   ; ah=data, bl!=0 for mouse, 0 for kb. returns cf=1 if timeout (al = 8)
				; changes BH, AL
 F551  52					push    dx
 F552  BA 03DA					mov     dx, 3dah
 F555  B7 28					mov     bh, 8*5
 F557				sps2b2:
 F557  E4 64					in      al, 64h
 F559  A8 02					test    al, 2
 F55B  74 0B					jz      short sps2b1; buffer empty
 F55D  EC					in      al, dx      ; get vblank
 F55E  32 C7					xor     al, bh
 F560  24 08					and     al, 8h
 F562  2A F8					sub     bh, al
 F564  73 F1					jnc     short sps2b2; IBF - buffer full, no timeout
 F566  EB 0C					jmp     short exit  ; timeout, CF=1
 F568				sps2b1:
 F568  84 DB					test    bl, bl      ; CF=0
 F56A  74 04					jz      short sps2_kb
 F56C  B0 D4					mov     al, 0d4h    ; next mouse
 F56E  E6 64					out     64h, al
 F570				sps2_kb:
 F570  8A C4					mov     al, ah
 F572  E6 60					out     60h, al     ; send byte
 F574				exit:        
 F574  5A					pop     dx
 F575  C3					ret
 F576				sendps2byte endp

 F576				getps2byte proc near    ; returns al=data, zf=0 for mouse, 1 for kb, cf=1 if timeout (al=8)
				; changes BH, DX, AL
 F576  BA 03DA					mov     dx, 3dah
 F579  B7 28					mov     bh, 8*5
 F57B				gps2b2:
 F57B  E4 64					in      al, 64h
 F57D  A8 01					test    al, 1
 F57F  75 0A					jnz     short gps2b1     ; OBF (buffer full), continue
 F581  EC					in      al, dx     ; get vblank
 F582  32 C7					xor     al, bh
 F584  24 08					and     al, 8
 F586  2A F8					sub     bh, al
 F588  73 F1					jnc     short gps2b2     ; buffer empty, no timeout
 F58A  C3					ret                ; timeout, CF=1
 F58B				gps2b1:
 F58B  A8 20					test    al, 20h    ; CF=0, ZF <- !MOBF
 F58D  E4 60					in      al, 60h    ; read byte (if IF=1, this data may be invalid)
 F58F  C3					ret
 F590				getps2byte endp

 F590				sendcmd proc near     ; ah = command, CF=1 for mouse, CF=0 for kb. returns CF=1 on error
 F590  1A DB					sbb     bl, bl      ; bl <- CF
 F592  E8 FFBC					call    sendps2byte 
 F595  72 09					jc      short exit
 F597				retry:        
 F597  E8 FFDC					call    getps2byte
 F59A  72 04					jc      short exit        
 F59C  3C FA					cmp     al, 0fah    ; ack (returns CF=1 on error, when al=8)
 F59E  75 F7					jne     short retry
 F5A0				exit:
 F5A0  C3					ret
 F5A1				sendcmd endp

 F5A1				enableKbIfPresent proc near ; input DS = 40h
				; modify AL, flags
 F5A1  F6 06 0096 10				test    byte ptr KbdFlags3, 10h
 F5A6  74 04					jz      short noenablekb
 F5A8  B0 AE					mov     al, 0aeh
 F5AA  E6 64					out     64h, al     ; enable kb interface
 F5AC				noenablekb:        
 F5AC  C3					ret
 F5AD				enableKbIfPresent endp

				; ----------------------- default interrupt handler ---------------
 F5AD				defint  proc near
 F5AD  CF					iret
 F5AE				defint  endp             

				; ------------------------------- flush --------------------------
 F5AE				flush:
 F5AE  2E: 8F 06 F5CF R				pop     cs:flushret
 F5B3				flush_nostack:        
 F5B3  2E: 89 1E F5D1 R				mov     cs:flushbh, bx
 F5B8  BB 2000					mov     bx, 2000h       ; flush all cache lines
 F5BB				flush1:        
 F5BB  2E: 84 9F BF00				test    bl, cs:[bx + 0bf00h]
 F5C0  83 EB 40					sub		bx, 40h
 F5C3  75 F6					jnz     short flush1
 F5C5  2E: 8B 1E F5D1 R				mov     bx, cs:flushbh
 F5CA  2E: FF 26 F5CF R				jmp     word ptr cs:flushret
 F5CF 0000			flushret dw 0
 F5D1 0000			flushbh  dw 0          

				; ------------------------------- misc --------------------------
 F5D3				dispAX: 
 F5D3  52					push    dx
 F5D4  33 D2					xor     dx, dx
 F5D6  2E: F7 36 F5EA R				div     word ptr cs:ten
 F5DB  85 C0					test    ax, ax
 F5DD  74 03					jz      dispAX1
 F5DF  E8 FFF1					call    dispAX
 F5E2				dispAX1:
 F5E2  92					xchg    ax, dx
 F5E3  05 0E30					add     ax, 0e00h + '0'
 F5E6  CD 10					int     10h
 F5E8  5A					pop     dx
 F5E9  C3					ret        
 F5EA 000A			ten     dw      10

 F5EC				prts:   ; es:si = string
 F5EC  B4 0E					mov     ah, 0eh    
 F5EE  26: AC					lodsb   es:[si]
 F5F0  0A C0					or      al, al
 F5F2  74 04					jz      short prtse
 F5F4  CD 10					int     10h
 F5F6  EB F4					jmp     short prts
 F5F8				prtse:
 F5F8  C3					ret



				;---------------------  read/write byte ----------------------
 F5F9  B0 FF			sdrb:   mov al,0ffh
 F5FB				sdsb:               ; in AL=byte, DX = 03dah, out AX=result
 F5FB  EE					out     dx, al
 F5FC  03 C0					add     ax, ax
 F5FE  EE					out     dx, al
 F5FF  03 C0					add     ax, ax
 F601  EE					out     dx, al
 F602  03 C0					add     ax, ax
 F604  EE					out     dx, al
 F605  03 C0					add     ax, ax
 F607  EE					out     dx, al
 F608  03 C0					add     ax, ax
 F60A  EE					out     dx, al
 F60B  03 C0					add     ax, ax
 F60D  EE					out     dx, al
 F60E  03 C0					add     ax, ax
 F610  EE					out     dx, al
 F611  ED					in      ax, dx
 F612  C3					ret

				;---------------------  write block ----------------------
 F613				sdwblk proc near              ; in SI=data ptr, DX=03dah, CX=size
 F613  D1 E9					shr     cx, 1
 F615				sdwblk1:
 F615  AC					lodsb
 F616  EE					out     dx, al
 F617  03 C0					add     ax, ax
 F619  EE					out     dx, al
 F61A  03 C0					add     ax, ax
 F61C  EE					out     dx, al
 F61D  03 C0					add     ax, ax
 F61F  EE					out     dx, al
 F620  03 C0					add     ax, ax
 F622  EE					out     dx, al
 F623  03 C0					add     ax, ax
 F625  EE					out     dx, al
 F626  03 C0					add     ax, ax
 F628  EE					out     dx, al
 F629  03 C0					add     ax, ax
 F62B  EE					out     dx, al
 F62C  AC					lodsb
 F62D  EE					out     dx, al
 F62E  03 C0					add     ax, ax
 F630  EE					out     dx, al
 F631  03 C0					add     ax, ax
 F633  EE					out     dx, al
 F634  03 C0					add     ax, ax
 F636  EE					out     dx, al
 F637  03 C0					add     ax, ax
 F639  EE					out     dx, al
 F63A  03 C0					add     ax, ax
 F63C  EE					out     dx, al
 F63D  03 C0					add     ax, ax
 F63F  EE					out     dx, al
 F640  03 C0					add     ax, ax
 F642  EE					out     dx, al
 F643  E2 D0					loop    short sdwblk1
 F645  C3					ret
 F646				sdwblk endp

				;---------------------  read block ----------------------
 F646				sdrblk proc near              ; in DI=data ptr, DX=03dah, CX=size. Returns CF = 0
 F646  B0 FF					mov     al, 0ffh
 F648  EE					out     dx, al
 F649  D1 E9					shr     cx, 1         ; CF = 0
 F64B  EE					out     dx, al
 F64C  EB 05					jmp     short sdrblk2 
 F64E				sdrblk1:
 F64E  EE					out     dx, al
 F64F  88 25					mov     [di], ah
 F651  EE					out     dx, al
 F652  47					inc     di
 F653				sdrblk2:
 F653  EE					out     dx, al
 F654  90					nop
 F655  EE					out     dx, al
 F656  90					nop
 F657  EE					out     dx, al
 F658  90					nop
 F659  EE					out     dx, al
 F65A  90					nop
 F65B  EE					out     dx, al
 F65C  90					nop
 F65D  EE					out     dx, al
 F65E  ED					in      ax, dx
 F65F  EE					out     dx, al
 F660  88 25					mov     [di], ah
 F662  EE					out     dx, al
 F663  47					inc     di
 F664  EE					out     dx, al
 F665  90					nop
 F666  EE					out     dx, al
 F667  90					nop
 F668  EE					out     dx, al
 F669  90					nop
 F66A  EE					out     dx, al
 F66B  90					nop
 F66C  EE					out     dx, al
 F66D  90					nop
 F66E  EE					out     dx, al
 F66F  ED					in      ax, dx
 F670  E2 DC					loop    short sdrblk1
 F672  88 25					mov     [di], ah
 F674  47					inc     di
 F675  C3					ret
 F676				sdrblk endp

				;---------------------  verify block ----------------------
 F676				sdvblk:              ; in DI=data ptr, DX=03dah, CX=size. Returns CF=1 on error
 F676  53					push    bx
 F677  32 DB					xor     bl, bl
 F679				sdvblk1:
 F679  E8 FF7D					call    sdrb
 F67C  2A 25					sub     ah, [di]
 F67E  0A DC					or      bl, ah
 F680  47					inc     di
 F681  E2 F6					loop    short sdvblk1
 F683  F6 DB					neg     bl  ; CF=1 if BL != 0
 F685  5B					pop     bx
 F686  C3					ret

				;---------------------  write command ----------------------
 F687				sdcmd8T:
 F687  E8 FF6F					call    sdrb
 F68A				sdcmd:              ; in SI=6 bytes cmd buffer, DX=03dah, out AH = 0ffh on error
 F68A  B9 0006					mov     cx, 6
 F68D  E8 FF83					call    sdwblk
 F690				sdresp:
 F690  33 F6					xor     si, si
 F692				sdresp1:
 F692  E8 FF64					call    sdrb
 F695  46					inc     si
 F696  74 05					jz      short sdcmd1
 F698  80 FC FF					cmp     ah, 0ffh
 F69B  74 F5					je      short sdresp1
 F69D  C3			sdcmd1: ret         

				;---------------------  read ----------------------
 F69E				sdverify:
 F69E  68 F676 R				push    sdvblk
 F6A1  EB 03					jmp     short sdread1
 F6A3				sdread:   ; DX:AX sector, ES:BX buffer, CX=sectors. returns AX=read sectors
 F6A3  68 F646 R				push    sdrblk   ; push proc address (read or verify) on stack
 F6A6				sdread1:        
 F6A6  50					push    ax
 F6A7  8A C2					mov     al, dl
 F6A9  50					push    ax
 F6AA  B2 51					mov     dl, 51h  ; CMD17
 F6AC  83 F9 01					cmp     cx, 1
 F6AF  74 01					je      short sdr1s
 F6B1  42					inc     dx      ; CMD18 - multiple sectors
 F6B2				sdr1s:
 F6B2  52					push    dx
 F6B3  8B F4					mov     si, sp 

 F6B5  BA 03DA					mov     dx, 3dah
 F6B8  B4 01					mov     ah, 1
 F6BA  EF					out     dx, ax       ; CS on
 F6BB  8B FB					mov     di, bx
 F6BD  8B D9					mov     bx, cx
 F6BF  8B E9					mov     bp, cx       ; save sectors number
 F6C1  16					push    ss
 F6C2  1F					pop     ds
 F6C3  C6 44 05 FF			mov	byte ptr [si+5], 0ffh ; checksum
 F6C7  E8 FFC0					call    sdcmd
 F6CA  83 C4 06					add     sp, 6
 F6CD  0A E4					or      ah, ah
 F6CF  75 41					jnz     short sdr11   ; error
 F6D1  06					push    es
 F6D2  1F					pop     ds
 F6D3				sdrms:
 F6D3  8B C7					mov     ax, di
 F6D5  C1 E8 04					shr     ax, 4
 F6D8  8C DE					mov     si, ds
 F6DA  03 C6					add     ax, si
 F6DC  8E D8					mov     ds, ax
 F6DE  83 E7 0F					and     di, 15
 F6E1  E8 FFAC					call    sdresp     ; wait for 0feh token
 F6E4  80 FC FE					cmp     ah, 0feh
 F6E7  75 29					jne     short sdr11; read token error 
 F6E9  B5 02					mov     ch, 2      ; 512 byte sector
 F6EB  5E					pop     si
 F6EC  FF D6					call    si         ; sdrblk or sdvblk
 F6EE  56					push    si
 F6EF  9C					pushf
 F6F0  E8 FF06					call    sdrb       ; ignore CRC
 F6F3  E8 FF03					call    sdrb       ; ignore CRC
 F6F6  9D					popf
 F6F7  72 03					jc      short sdr3 ; verify error   
 F6F9  4B					dec     bx
 F6FA  75 D7					jnz     short sdrms; multiple sectors
 F6FC				sdr3:        
 F6FC  83 FD 01					cmp     bp, 1
 F6FF  74 11					je      short sdr11; single sector
 F701  BE F84B R				mov     si, offset SD_CMD12 ; stop transfer
 F704  0E					push    cs
 F705  1F					pop     ds
 F706  E8 FF81					call    sdcmd
 F709				sdr2:
 F709  D0 EC					shr     ah, 1
 F70B  73 05					jnc     short sdr11
 F70D  E8 FEE9					call    sdrb
 F710  EB F7					jmp     short sdr2
 F712				sdr11:
 F712  58					pop     ax         ; remove proc address from stack
 F713				sdr1:       
 F713  33 C0					xor     ax, ax
 F715  EF					out     dx, ax
 F716  E8 FEE0					call    sdrb       ; 8T
 F719  8B C5					mov     ax, bp
 F71B  2B C3					sub     ax, bx
 F71D  C3					ret     

				;---------------------  write ----------------------
 F71E				sdwrite:   ; DX:AX sector, ES:BX buffer, CX=sectors, returns AX=wrote sectors
 F71E  50					push    ax
 F71F  8A C2					mov     al, dl
 F721  50					push    ax
 F722  B2 58					mov     dl, 58h  ; CMD24
 F724  83 F9 01					cmp     cx, 1
 F727  74 01					je      short sdw1s
 F729  42					inc     dx      ; CMD25 - multiple sectors
 F72A				sdw1s:
 F72A  52					push    dx
 F72B  8B F4					mov     si, sp 

 F72D  BA 03DA					mov     dx, 3dah
 F730  B4 01					mov     ah, 1
 F732  EF					out     dx, ax       ; CS on
 F733  8B E9					mov     bp, cx       ; save sectors number
 F735  16					push    ss
 F736  1F					pop     ds
 F737  C6 44 05 FF			mov	byte ptr [si+5], 0ffh ; checksum
 F73B  E8 FF4C					call    sdcmd
 F73E  83 C4 06					add     sp, 6
 F741  8B F3					mov     si, bx
 F743  8B DD					mov     bx, bp
 F745  0A E4					or      ah, ah
 F747  75 CA					jnz     short sdr1   ; error
 F749  06					push    es
 F74A  1F					pop     ds
 F74B				sdwms:
 F74B  8B C6					mov     ax, si
 F74D  C1 E8 04					shr     ax, 4
 F750  8C DF					mov     di, ds
 F752  03 C7					add     ax, di
 F754  8E D8					mov     ds, ax
 F756  83 E6 0F					and     si, 15
 F759  B0 FE					mov     al, 0feh      ; start token
 F75B  83 FD 01					cmp     bp, 1
 F75E  74 02					je      short sdw1s1
 F760  B0 FC					mov     al, 0fch   ; multiple sectors
 F762				sdw1s1:        
 F762  E8 FE96					call    sdsb     
 F765  B5 02					mov     ch, 2      ; 512 byte sector
 F767  E8 FEA9					call    sdwblk
 F76A  E8 FE8C					call    sdrb       ; ignore CRC
 F76D  E8 FE89					call    sdrb       ; ignore CRC
 F770  E8 FE86					call    sdrb       ; read response byte xxx00101
 F773  80 E4 0E					and     ah, 0eh
 F776  80 FC 04					cmp     ah, 4
 F779  75 98					jne     short sdr1 ; write error
 F77B				sdwwait:
 F77B  E8 FE7B					call    sdrb
 F77E  D0 EC					shr     ah, 1
 F780  73 F9					jnc     short sdwwait     ; wait write completion
 F782  4B					dec     bx
 F783  75 C6					jnz     short sdwms       ; multiple sectors

 F785  83 FD 01					cmp     bp, 1
 F788  74 89					je      short sdr1
 F78A  B0 FD					mov     al, 0fdh     ; multiple end transfer
 F78C  E8 FE6C					call    sdsb 
 F78F  E8 FE67					call	sdrb     
 F792				sdwwait1:
 F792  E8 FE64					call    sdrb
 F795  D0 EC					shr     ah, 1
 F797  73 F9					jnc     short sdwwait1     ; wait write completion
 F799  E9 FF77					jmp     sdr1
						
				;---------------------  init SD ----------------------
 F79C				sdinit  proc near       ; returns AX = num kilosectors
 F79C  1E					push    ds
 F79D  51					push    cx
 F79E  52					push    dx
 F79F  56					push    si
 F7A0  57					push    di
 F7A1  BA 03DA					mov     dx, 3dah
 F7A4  B9 000A					mov     cx, 10
 F7A7				sdinit1:                   ; send 80T
 F7A7  E8 FE4F					call    sdrb
 F7AA  E2 FB					loop    short sdinit1

 F7AC  B4 01					mov     ah, 1
 F7AE  EF					out     dx, ax       ; select SD

 F7AF  BE F839 R				mov     si, offset SD_CMD0
 F7B2  0E					push    cs
 F7B3  1F					pop     ds
 F7B4  E8 FED3					call    sdcmd
 F7B7  FE CC					dec     ah
 F7B9  75 70					jnz     short sdexit ; error
						
 F7BB  BE F83F R				mov     si, offset SD_CMD8
 F7BE  E8 FEC6					call    sdcmd8T
 F7C1  FE CC					dec     ah
 F7C3  75 66					jnz     short sdexit ; error
 F7C5  B1 04					mov     cl, 4
 F7C7  2B E1					sub     sp, cx
 F7C9  8B FC					mov     di, sp
 F7CB  16					push    ss
 F7CC  1F					pop     ds
 F7CD  E8 FE76					call    sdrblk
 F7D0  58					pop     ax
 F7D1  58					pop     ax
 F7D2  80 FC AA					cmp     ah, 0aah
 F7D5  75 54					jne     short sdexit ; CMD8 error
 F7D7				repinit:        
 F7D7  BE F857 R				mov     si, offset SD_CMD55
 F7DA  0E					push    cs
 F7DB  1F					pop     ds
 F7DC  E8 FEA8					call    sdcmd8T
 F7DF  E8 FE17					call    sdrb
 F7E2  BE F851 R				mov     si, offset SD_CMD41
 F7E5  E8 FEA2					call    sdcmd
 F7E8  FE CC					dec     ah
 F7EA  74 EB					jz      short repinit
						
 F7EC  BE F85D R				mov     si, offset SD_CMD58
 F7EF  E8 FE95					call    sdcmd8T
 F7F2  B1 04					mov     cl, 4
 F7F4  2B E1					sub     sp, cx
 F7F6  8B FC					mov     di, sp
 F7F8  16					push    ss
 F7F9  1F					pop     ds
 F7FA  E8 FE49					call    sdrblk
 F7FD  58					pop     ax
 F7FE  A8 40					test    al, 40h     ; test OCR bit 30 (CCS)
 F800  58					pop     ax
 F801  74 28					jz      short sdexit; no SDHC

 F803  BE F845 R				mov     si, offset SD_CMD9 ; get size info
 F806  0E					push    cs
 F807  1F					pop     ds
 F808  E8 FE7C					call    sdcmd8T
 F80B  0A E4					or      ah, ah
 F80D  75 1C					jnz     short sdexit
 F80F  E8 FE7E					call    sdresp     ; wait for 0feh token
 F812  80 FC FE					cmp     ah, 0feh
 F815  75 14					jne     short sdexit
 F817  B1 12					mov     cl, 18       ; 16bytes + 2bytes CRC
 F819  2B E1					sub     sp, cx
 F81B  8B FC					mov     di, sp
 F81D  16					push    ss
 F81E  1F					pop     ds
 F81F  E8 FE24					call    sdrblk
 F822  8B 4D F6					mov     cx, [di-10]
 F825  C1 C1 08					rol     cx, 8
 F828  41					inc     cx
 F829  8B E7					mov     sp, di
 F82B				sdexit: 
 F82B  33 C0					xor     ax, ax       ; raise CS
 F82D  EF					out     dx, ax
 F82E  E8 FDC8					call    sdrb
 F831  5F					pop     di
 F832  5E					pop     si
 F833  5A					pop     dx
 F834  8B C1					mov     ax, cx       
 F836  59					pop     cx
 F837  1F					pop     ds
 F838  C3					ret
 F839				sdinit endp
					
 F839 40 00 00 00 00 95		SD_CMD0     db  40h, 0, 0, 0, 0, 95h
 F83F 48 00 00 01 AA 87		SD_CMD8     db  48h, 0, 0, 1, 0aah, 087h
 F845 49 00 00 00 00 FF		SD_CMD9     db  49h, 0, 0, 0, 0, 0ffh
 F84B 4C 00 00 00 00 FF		SD_CMD12    db  4ch, 0, 0, 0, 0, 0ffh
 F851 69 40 00 00 00 FF		SD_CMD41    db  69h, 40h, 0, 0, 0, 0ffh
 F857 77 00 00 00 00 FF		SD_CMD55    db  77h, 0, 0, 0, 0, 0ffh
 F85D 7A 00 00 00 00 FF		SD_CMD58    db  7ah, 0, 0, 0, 0, 0ffh


 F863				Pal256:
 F863  00 00 00 00 00 2A			db  00h,00h,00h, 00h,00h,2ah, 00h,2ah,00h, 00h,2ah,2ah, 2ah,00h,00h, 2ah,00h,2ah, 2ah,15h,00h, 2ah,2ah,2ah 
       00 2A 00 00 2A 2A
       2A 00 00 2A 00 2A
       2A 15 00 2A 2A 2A
 F87B  15 15 15 15 15 3F			db  15h,15h,15h, 15h,15h,3fh, 15h,3fh,15h, 15h,3fh,3fh, 3fh,15h,15h, 3fh,15h,3fh, 3fh,3fh,15h, 3fh,3fh,3fh 
       15 3F 15 15 3F 3F
       3F 15 15 3F 15 3F
       3F 3F 15 3F 3F 3F
 F893  00 00 00 05 05 05			db  00h,00h,00h, 05h,05h,05h, 08h,08h,08h, 0bh,0bh,0bh, 0eh,0eh,0eh, 11h,11h,11h, 14h,14h,14h, 18h,18h,18h 
       08 08 08 0B 0B 0B
       0E 0E 0E 11 11 11
       14 14 14 18 18 18
 F8AB  1C 1C 1C 20 20 20			db  1ch,1ch,1ch, 20h,20h,20h, 24h,24h,24h, 28h,28h,28h, 2dh,2dh,2dh, 32h,32h,32h, 38h,38h,38h, 3fh,3fh,3fh 
       24 24 24 28 28 28
       2D 2D 2D 32 32 32
       38 38 38 3F 3F 3F
 F8C3  00 00 3F 10 00 3F			db  00h,00h,3fh, 10h,00h,3fh, 1fh,00h,3fh, 2fh,00h,3fh, 3fh,00h,3fh, 3fh,00h,2fh, 3fh,00h,1fh, 3fh,00h,10h 
       1F 00 3F 2F 00 3F
       3F 00 3F 3F 00 2F
       3F 00 1F 3F 00 10
 F8DB  3F 00 00 3F 10 00			db  3fh,00h,00h, 3fh,10h,00h, 3fh,1fh,00h, 3fh,2fh,00h, 3fh,3fh,00h, 2fh,3fh,00h, 1fh,3fh,00h, 10h,3fh,00h 
       3F 1F 00 3F 2F 00
       3F 3F 00 2F 3F 00
       1F 3F 00 10 3F 00
 F8F3  00 3F 00 00 3F 10			db  00h,3fh,00h, 00h,3fh,10h, 00h,3fh,1fh, 00h,3fh,2fh, 00h,3fh,3fh, 00h,2fh,3fh, 00h,1fh,3fh, 00h,10h,3fh 
       00 3F 1F 00 3F 2F
       00 3F 3F 00 2F 3F
       00 1F 3F 00 10 3F
 F90B  1F 1F 3F 27 1F 3F			db  1fh,1fh,3fh, 27h,1fh,3fh, 2fh,1fh,3fh, 37h,1fh,3fh, 3fh,1fh,3fh, 3fh,1fh,37h, 3fh,1fh,2fh, 3fh,1fh,27h
       2F 1F 3F 37 1F 3F
       3F 1F 3F 3F 1F 37
       3F 1F 2F 3F 1F 27
 F923  00 01 02 03 04 05			db	00h, 01h, 02h, 03h, 04h, 05h, 06h, 07h, 08h, 09h, 0ah, 0bh, 0ch, 0dh, 0eh, 0fh	; EGA palette registers
       06 07 08 09 0A 0B
       0C 0D 0E 0F

				;		db  3fh,1fh,1fh, 3fh,27h,1fh, 3fh,2fh,1fh, 3fh,37h,1fh, 3fh,3fh,1fh, 37h,3fh,1fh, 2fh,3fh,1fh, 27h,3fh,1fh 
				;		db  1fh,3fh,1fh, 1fh,3fh,27h, 1fh,3fh,2fh, 1fh,3fh,37h, 1fh,3fh,3fh, 1fh,37h,3fh, 1fh,2fh,3fh, 1fh,27h,3fh 
				;		db  2dh,2dh,3fh, 31h,2dh,3fh, 36h,2dh,3fh, 3ah,2dh,3fh, 3fh,2dh,3fh, 3fh,2dh,3ah, 3fh,2dh,36h, 3fh,2dh,31h 
				;		db  3fh,2dh,2dh, 3fh,31h,2dh, 3fh,36h,2dh, 3fh,3ah,2dh, 3fh,3fh,2dh, 3ah,3fh,2dh, 36h,3fh,2dh, 31h,3fh,2dh 
				;		db  2dh,3fh,2dh, 2dh,3fh,31h, 2dh,3fh,36h, 2dh,3fh,3ah, 2dh,3fh,3fh, 2dh,3ah,3fh, 2dh,36h,3fh, 2dh,31h,3fh 
				;		db  00h,00h,1ch, 07h,00h,1ch, 0eh,00h,1ch, 15h,00h,1ch, 1ch,00h,1ch, 1ch,00h,15h, 1ch,00h,0eh, 1ch,00h,07h 
				;		db  1ch,00h,00h, 1ch,07h,00h, 1ch,0eh,00h, 1ch,15h,00h, 1ch,1ch,00h, 15h,1ch,00h, 0eh,1ch,00h, 07h,1ch,00h 
				;		db  00h,1ch,00h, 00h,1ch,07h, 00h,1ch,0eh, 00h,1ch,15h, 00h,1ch,1ch, 00h,15h,1ch, 00h,0eh,1ch, 00h,07h,1ch 

				;		db  0eh,0eh,1ch, 11h,0eh,1ch, 15h,0eh,1ch, 18h,0eh,1ch, 1ch,0eh,1ch, 1ch,0eh,18h, 1ch,0eh,15h, 1ch,0eh,11h 
				;		db  1ch,0eh,0eh, 1ch,11h,0eh, 1ch,15h,0eh, 1ch,18h,0eh, 1ch,1ch,0eh, 18h,1ch,0eh, 15h,1ch,0eh, 11h,1ch,0eh 
				;		db  0eh,1ch,0eh, 0eh,1ch,11h, 0eh,1ch,15h, 0eh,1ch,18h, 0eh,1ch,1ch, 0eh,18h,1ch, 0eh,15h,1ch, 0eh,11h,1ch 
				;		db  14h,14h,1ch, 16h,14h,1ch, 18h,14h,1ch, 1ah,14h,1ch, 1ch,14h,1ch, 1ch,14h,1ah, 1ch,14h,18h, 1ch,14h,16h 
				;		db  1ch,14h,14h, 1ch,16h,14h, 1ch,18h,14h, 1ch,1ah,14h, 1ch,1ch,14h, 1ah,1ch,14h, 18h,1ch,14h, 16h,1ch,14h 
				;		db  14h,1ch,14h, 14h,1ch,16h, 14h,1ch,18h, 14h,1ch,1ah, 14h,1ch,1ch, 14h,1ah,1ch, 14h,18h,1ch, 14h,16h,1ch 
				;		db  00h,00h,10h, 04h,00h,10h, 08h,00h,10h, 0ch,00h,10h, 10h,00h,10h, 10h,00h,0ch, 10h,00h,08h, 10h,00h,04h 
				;		db  10h,00h,00h, 10h,04h,00h, 10h,08h,00h, 10h,0ch,00h, 10h,10h,00h, 0ch,10h,00h, 08h,10h,00h, 04h,10h,00h 

				;		db  00h,10h,00h, 00h,10h,04h, 00h,10h,08h, 00h,10h,0ch, 00h,10h,10h, 00h,0ch,10h, 00h,08h,10h, 00h,04h,10h 
				;		db  08h,08h,10h, 0ah,08h,10h, 0ch,08h,10h, 0eh,08h,10h, 10h,08h,10h, 10h,08h,0eh, 10h,08h,0ch, 10h,08h,0ah 
				;		db  10h,08h,08h, 10h,0ah,08h, 10h,0ch,08h, 10h,0eh,08h, 10h,10h,08h, 0eh,10h,08h, 0ch,10h,08h, 0ah,10h,08h 
				;		db  08h,10h,08h, 08h,10h,0ah, 08h,10h,0ch, 08h,10h,0eh, 08h,10h,10h, 08h,0eh,10h, 08h,0ch,10h, 08h,0ah,10h 
				;		db  0bh,0bh,10h, 0ch,0bh,10h, 0dh,0bh,10h, 0fh,0bh,10h, 10h,0bh,10h, 10h,0bh,0fh, 10h,0bh,0dh, 10h,0bh,0ch 
				;		db  10h,0bh,0bh, 10h,0ch,0bh, 10h,0dh,0bh, 10h,0fh,0bh, 10h,10h,0bh, 0fh,10h,0bh, 0dh,10h,0bh, 0ch,10h,0bh 
				;		db  0bh,10h,0bh, 0bh,10h,0ch, 0bh,10h,0dh, 0bh,10h,0fh, 0bh,10h,10h, 0bh,0fh,10h, 0bh,0dh,10h, 0bh,0ch,10h 
				;		db  00h,00h,00h, 00h,00h,00h, 00h,00h,00h, 00h,00h,00h, 00h,00h,00h, 00h,00h,00h, 00h,00h,00h, 00h,00h,00h

 F933				PalEGA:
 F933  00 00 00 00 00 2A			db	00h,00h,00h, 00h,00h,2ah, 00h,2ah,00h, 00h,2ah,2ah, 2ah,00h,00h, 2ah,00h,2ah, 2ah,15h,00h, 2ah,2ah,2ah
       00 2A 00 00 2A 2A
       2A 00 00 2A 00 2A
       2A 15 00 2A 2A 2A
 F94B  00 00 00 00 00 2A			db	00h,00h,00h, 00h,00h,2ah, 00h,2ah,00h, 00h,2ah,2ah, 2ah,00h,00h, 2ah,00h,2ah, 2ah,15h,00h, 2ah,2ah,2ah
       00 2A 00 00 2A 2A
       2A 00 00 2A 00 2A
       2A 15 00 2A 2A 2A
 F963  15 15 15 15 15 3F			db	15h,15h,15h, 15h,15h,3fh, 15h,3fh,15h, 15h,3fh,3fh, 3fh,15h,15h, 3fh,15h,3fh, 3fh,3fh,15h, 3fh,3fh,3fh
       15 3F 15 15 3F 3F
       3F 15 15 3F 15 3F
       3F 3F 15 3F 3F 3F
 F97B  15 15 15 15 15 3F			db	15h,15h,15h, 15h,15h,3fh, 15h,3fh,15h, 15h,3fh,3fh, 3fh,15h,15h, 3fh,15h,3fh, 3fh,3fh,15h, 3fh,3fh,3fh
       15 3F 15 15 3F 3F
       3F 15 15 3F 15 3F
       3F 3F 15 3F 3F 3F
 F993  00 00 00 00 00 2A			db	00h,00h,00h, 00h,00h,2ah, 00h,2ah,00h, 00h,2ah,2ah, 2ah,00h,00h, 2ah,00h,2ah, 2ah,15h,00h, 2ah,2ah,2ah
       00 2A 00 00 2A 2A
       2A 00 00 2A 00 2A
       2A 15 00 2A 2A 2A
 F9AB  00 00 00 00 00 2A			db	00h,00h,00h, 00h,00h,2ah, 00h,2ah,00h, 00h,2ah,2ah, 2ah,00h,00h, 2ah,00h,2ah, 2ah,15h,00h, 2ah,2ah,2ah
       00 2A 00 00 2A 2A
       2A 00 00 2A 00 2A
       2A 15 00 2A 2A 2A
 F9C3  15 15 15 15 15 3F			db	15h,15h,15h, 15h,15h,3fh, 15h,3fh,15h, 15h,3fh,3fh, 3fh,15h,15h, 3fh,15h,3fh, 3fh,3fh,15h, 3fh,3fh,3fh
       15 3F 15 15 3F 3F
       3F 15 15 3F 15 3F
       3F 3F 15 3F 3F 3F
 F9DB  15 15 15 15 15 3F			db	15h,15h,15h, 15h,15h,3fh, 15h,3fh,15h, 15h,3fh,3fh, 3fh,15h,15h, 3fh,15h,3fh, 3fh,3fh,15h, 3fh,3fh,3fh
       15 3F 15 15 3F 3F
       3F 15 15 3F 15 3F
       3F 3F 15 3F 3F 3F
 F9F3  00 01 02 03 04 05			db	00h, 01h, 02h, 03h, 04h, 05h, 06h, 07h, 10h, 11h, 12h, 13h, 14h, 15h, 16h, 17h	; EGA palette registers
       06 07 10 11 12 13
       14 15 16 17

 FA03				PalVGA:
 FA03  00 00 00 00 00 2A			db	00h,00h,00h, 00h,00h,2ah, 00h,2ah,00h, 00h,2ah,2ah, 2ah,00h,00h, 2ah,00h,2ah, 2ah,2ah,00h, 2ah,2ah,2ah
       00 2A 00 00 2A 2A
       2A 00 00 2A 00 2A
       2A 2A 00 2A 2A 2A
 FA1B  00 00 15 00 00 3F			db	00h,00h,15h, 00h,00h,3fh, 00h,2ah,15h, 00h,2ah,3fh, 2ah,00h,15h, 2ah,00h,3fh, 2ah,2ah,15h, 2ah,2ah,3fh
       00 2A 15 00 2A 3F
       2A 00 15 2A 00 3F
       2A 2A 15 2A 2A 3F
 FA33  00 15 00 00 15 2A			db	00h,15h,00h, 00h,15h,2ah, 00h,3fh,00h, 00h,3fh,2ah, 2ah,15h,00h, 2ah,15h,2ah, 2ah,3fh,00h, 2ah,3fh,2ah
       00 3F 00 00 3F 2A
       2A 15 00 2A 15 2A
       2A 3F 00 2A 3F 2A
 FA4B  00 15 15 00 15 3F			db	00h,15h,15h, 00h,15h,3fh, 00h,3fh,15h, 00h,3fh,3fh, 2ah,15h,15h, 2ah,15h,3fh, 2ah,3fh,15h, 2ah,3fh,3fh
       00 3F 15 00 3F 3F
       2A 15 15 2A 15 3F
       2A 3F 15 2A 3F 3F
 FA63  15 00 00 15 00 2A			db	15h,00h,00h, 15h,00h,2ah, 15h,2ah,00h, 15h,2ah,2ah, 3fh,00h,00h, 3fh,00h,2ah, 3fh,2ah,00h, 3fh,2ah,2ah
       15 2A 00 15 2A 2A
       3F 00 00 3F 00 2A
       3F 2A 00 3F 2A 2A
 FA7B  15 00 15 15 00 3F			db	15h,00h,15h, 15h,00h,3fh, 15h,2ah,15h, 15h,2ah,3fh, 3fh,00h,15h, 3fh,00h,3fh, 3fh,2ah,15h, 3fh,2ah,3fh
       15 2A 15 15 2A 3F
       3F 00 15 3F 00 3F
       3F 2A 15 3F 2A 3F
 FA93  15 15 00 15 15 2A			db	15h,15h,00h, 15h,15h,2ah, 15h,3fh,00h, 15h,3fh,2ah, 3fh,15h,00h, 3fh,15h,2ah, 3fh,3fh,00h, 3fh,3fh,2ah
       15 3F 00 15 3F 2A
       3F 15 00 3F 15 2A
       3F 3F 00 3F 3F 2A
 FAAB  15 15 15 15 15 3F			db	15h,15h,15h, 15h,15h,3fh, 15h,3fh,15h, 15h,3fh,3fh, 3fh,15h,15h, 3fh,15h,3fh, 3fh,3fh,15h, 3fh,3fh,3fh
       15 3F 15 15 3F 3F
       3F 15 15 3F 15 3F
       3F 3F 15 3F 3F 3F
 FAC3  00 01 02 03 04 05			db	00h, 01h, 02h, 03h, 04h, 05h, 14h, 07h, 38h, 39h, 3ah, 3bh, 3ch, 3dh, 3eh, 3fh	; EGA palette registers
       14 07 38 39 3A 3B
       3C 3D 3E 3F

				IFDEF SCANCODE1 ; use SCANCODE1
 FAD3				KeyIndex:
 FAD3  00 52 31 32 34 33			db	0, 82, 49, 50, 52, 51, 54, 55    ;0-7
       36 37
 FADB  38 39 3C 3B 41 44			db 56, 57, 60, 59, 65, 68, 72, 47    ;8-f
       48 2F
 FAE3  01 05 09 0D 0C 12			db	1,  5,  9, 13, 12, 18, 21, 23    ;10-17
       15 17
 FAEB  18 1A 43 46 45 00			db 24, 26, 67, 70, 69,  0,  4,  3    ;18-1f
       04 03
 FAF3  08 0B 11 10 14 16			db	8, 11, 17, 16, 20, 22, 25, 64    ;20-27
       19 40
 FAFB  42 30 00 47 02 07			db 66, 48,  0, 71,  2,  7,  6, 10    ;28-2f
       06 0A
 FB03  0F 0E 13 3A 3D 3E			db 15, 14, 19, 58, 61, 62,  0, 87    ;30-37
       00 57
 FB0B  00 35 00 28 29 27			db	0, 53,  0, 40, 41, 39, 46, 38    ;38-3f
       2E 26
 FB13  2D 5A 2C 4F 2B 00			db 45, 90, 44, 79, 43,  0, 89, 29    ;40-47
       59 1D
 FB1B  22 24 56 1C 25 21			db 34, 36, 86, 28, 37, 33, 84, 27    ;48-4f
       54 1B
 FB23  20 23 1E 1F 00 00			db 32, 35, 30, 31,  0,  0,	0, 83    ;50-57  
       00 53
 FB2B  2A					db 42
 FB2C				E0KeyList:
 FB2C  35 1C 4F 4B 47 52		db	35h, 1ch, 4fh, 4bh, 47h, 52h, 53h, 50h, 4dh, 48h, 51h, 49h 
       53 50 4D 48 51 49

				ELSE    ; use SCANCODE2
				ENDIF

 FB38				E0KeyIndex:
 FB38  3F 45 49 4A 4B 4C		db	63,  69,  73,  74,  75,  76,  77,  78,  80,  81,  85,  88
       4D 4E 50 51 55 58

 FB44				KeyCode:	  
				; Keys affected by CapsLock
				;		norm   shft   ctrl   alt
 FB44  0000 0000 0000				dw	0000h, 0000h, 0000h, 0000h ;17 - <0>
       0000
 FB4C  1071 1051 1011				dw	1071h, 1051h, 1011h, 1000h ;15 - Q, (E0)PrevTrack <1>
       1000
 FB54  2C7A 2C5A 2C1A				dw	2c7ah, 2c5ah, 2c1ah, 2c00h ;1a - Z <2>
       2C00
 FB5C  1F73 1F53 1F13				dw	1f73h, 1f53h, 1f13h, 1f00h ;1b - S <3>
       1F00
 FB64  1E61 1E41 1E01				dw	1e61h, 1e41h, 1e01h, 1e00h ;1c - A <4>
       1E00
 FB6C  1177 1157 1117				dw	1177h, 1157h, 1117h, 1100h ;1d - W <5>
       1100
 FB74  2E63 2E43 2E03				dw	2e63h, 2e43h, 2e03h, 2e00h ;21 - C, (E0)Volume Down <6>
       2E00
 FB7C  2D78 2D58 2D18				dw	2d78h, 2d58h, 2d18h, 2d00h ;22 - X <7>
       2D00
 FB84  2064 2044 2004				dw	2064h, 2044h, 2004h, 2000h ;23 - D, (E0)Mute <8>
       2000
 FB8C  1265 1245 1205				dw	1265h, 1245h, 1205h, 1200h ;24 - E <9>
       1200
 FB94  2F76 2F56 2F16				dw	2f76h, 2f56h, 2f16h, 2f00h ;2a - V <10>
       2F00
 FB9C  2166 2146 2106				dw	2166h, 2146h, 2106h, 2100h ;2b - F, (E0)Calculator <11>
       2100
 FBA4  1474 1454 1414				dw	1474h, 1454h, 1414h, 1400h ;2c - T <12>
       1400
 FBAC  1372 1352 1312				dw	1372h, 1352h, 1312h, 1300h ;2d - R <13>
       1300
 FBB4  316E 314E 310E				dw	316eh, 314eh, 310eh, 3100h ;31 - N <14>
       3100
 FBBC  3062 3042 3002				dw	3062h, 3042h, 3002h, 3000h ;32 - B, (E0)Volume Up <15>
       3000
 FBC4  2368 2348 2308				dw	2368h, 2348h, 2308h, 2300h ;33 - H <16>
       2300
 FBCC  2267 2247 2207				dw	2267h, 2247h, 2207h, 2200h ;34 - G, (E0)Play/Pause <17>
       2200
 FBD4  1579 1559 1519				dw	1579h, 1559h, 1519h, 1500h ;35 - Y <18>
       1500
 FBDC  326D 324D 320D				dw	326dh, 324dh, 320dh, 3200h ;3a - M, (E0)WWW Home <19>
       3200
 FBE4  246A 244A 240A				dw	246ah, 244ah, 240ah, 2400h ;3b - J, (E0)Stop <20>
       2400
 FBEC  1675 1655 1615				dw	1675h, 1655h, 1615h, 1600h ;3c - U <21>
       1600
 FBF4  256B 254B 250B				dw	256bh, 254bh, 250bh, 2500h ;42 - K <22>
       2500
 FBFC  1769 1749 1709				dw	1769h, 1749h, 1709h, 1700h ;43 - I <23>
       1700
 FC04  186F 184F 180F				dw	186fh, 184fh, 180fh, 1800h ;44 - O <24>
       1800
 FC0C  266C 264C 260C				dw	266ch, 264ch, 260ch, 2600h ;4b - L <25>
       2600
 FC14  1970 1950 1910				dw	1970h, 1950h, 1910h, 1900h ;4d - P, (E0)Next Track <26>
       1900
				; keys affected by NumLock	
 FC1C  4F00 4F31 7500				dw	4f00h, 4f31h, 7500h, 0002h ;69 - KP1 <27>
       0002
 FC24  4B00 4B34 7300				dw	4b00h, 4b34h, 7300h, 0005h ;6b - KP4 <28>
       0005
 FC2C  4700 4737 7700				dw	4700h, 4737h, 7700h, 0008h ;6c - KP7 <29>
       0008
 FC34  5200 5230 9200				dw	5200h, 5230h, 9200h, 0001h ;70 - KP0 <30>
       0001
 FC3C  5300 532E 9300				dw	5300h, 532eh, 9300h, 0000h ;71 - KP. <31>
       0000
 FC44  5000 5032 9100				dw	5000h, 5032h, 9100h, 0003h ;72 - KP2 <32>
       0003
 FC4C  4D00 4D36 7400				dw	4d00h, 4d36h, 7400h, 0007h ;74 - KP6 <33>
       0007
 FC54  4800 4838 8D00				dw	4800h, 4838h, 8d00h, 0009h ;75 - KP8 <34>
       0009
 FC5C  5100 5133 7600				dw	5100h, 5133h, 7600h, 0004h ;7a - KP3 <35>
       0004
 FC64  4900 4939 8400				dw	4900h, 4939h, 8400h, 000ah ;7d - KP9 <36>
       000A
 FC6C  4C00 4C35 8F00				dw	4c00h, 4c35h, 8f00h, 0006h ;73 - KP5 --- on VMWare, it does not send 4c00 <37>
       0006
				; keys unaffected by CapsLock or N
 FC74  3F00 5800 6200				dw	3f00h, 5800h, 6200h, 6c00h ;03 - F5 <38>
       6C00
 FC7C  3D00 5600 6000				dw	3d00h, 5600h, 6000h, 6a00h ;04 - F3 <39>
       6A00
 FC84  3B00 5400 5E00				dw	3b00h, 5400h, 5e00h, 6800h ;05 - F1 <40>
       6800
 FC8C  3C00 5500 5F00				dw	3c00h, 5500h, 5f00h, 6900h ;06 - F2 <41>
       6900
 FC94  8600 8800 8A00				dw	8600h, 8800h, 8a00h, 8c00h ;07 - F12 <42>	
       8C00
 FC9C  4400 5D00 6700				dw	4400h, 5d00h, 6700h, 7100h ;09 - F10 <43>
       7100
 FCA4  4200 5B00 6500				dw	4200h, 5b00h, 6500h, 6f00h ;0a - F8 <44>
       6F00
 FCAC  4000 5900 6300				dw	4000h, 5900h, 6300h, 6d00h ;0b - F6 <45>
       6D00
 FCB4  3E00 5700 6100				dw	3e00h, 5700h, 6100h, 6b00h ;0c - F4 <46>
       6B00
 FCBC  0F09 0F00 9400				dw	0f09h, 0f00h, 9400h, 0000h ;0d - TAB <47>	
       0000
 FCC4  2960 297E 0000				dw	2960h, 297eh, 0000h, 2900h ;0e - ` ~ <48>	
       2900
 FCCC  0231 0221 0000				dw	0231h, 0221h, 0000h, 7800h ;16 - 1 ! <49>	
       7800
 FCD4  0332 0340 0300				dw	0332h, 0340h, 0300h, 7900h ;1e - 2 @ <50>	
       7900
 FCDC  0534 0524 0000				dw	0534h, 0524h, 0000h, 7b00h ;25 - 4 $ <51>
       7B00
 FCE4  0433 0423 0000				dw	0433h, 0423h, 0000h, 7a00h ;26 - 3 # <52>
       7A00
 FCEC  3920 3920 3920				dw	3920h, 3920h, 3920h, 3920h ;29 - SPC <53>	
       3920
 FCF4  0635 0625 0000				dw	0635h, 0625h, 0000h, 7c00h ;2e - 5 % <54>
       7C00
 FCFC  0736 075E 071E				dw	0736h, 075eh, 071eh, 7d00h ;36 - 6 ^ <55>
       7D00
 FD04  0837 0826 0000				dw	0837h, 0826h, 0000h, 7e00h ;3d - 7 & <56>
       7E00
 FD0C  0938 092A 0000				dw	0938h, 092ah, 0000h, 7f00h ;3e - 8 * <57>
       7F00
 FD14  332C 333C 0000				dw	332ch, 333ch, 0000h, 3300h ;41 - , < <58>
       3300
 FD1C  0B30 0B29 0000				dw	0b30h, 0b29h, 0000h, 8100h ;45 - 0 ) <59>
       8100
 FD24  0A39 0A28 0000				dw	0a39h, 0a28h, 0000h, 8000h ;46 - 9 ( <60>
       8000
 FD2C  342E 343E 0000				dw	342eh, 343eh, 0000h, 3400h ;49 - . > <61>
       3400
 FD34  352F 353F 0000				dw	352fh, 353fh, 0000h, 3500h ;4a - / ? <62>
       3500
 FD3C  E02F E02F 9500				dw	0e02fh, 0e02fh, 9500h, 0a400h ;4a - (e0)KP/ <63>
       A400
 FD44  273B 273A 0000				dw	273bh, 273ah, 0000h, 2700h ;4c - ; : <64>
       2700
 FD4C  0C2D 0C5F 0C1F				dw	0c2dh, 0c5fh, 0c1fh, 8200h ;4e - - _ <65>
       8200
 FD54  2827 2822 0000				dw	2827h, 2822h, 0000h, 2800h ;52 - ’ “ <66>
       2800
 FD5C  1A5B 1A7B 1A1B				dw	1a5bh, 1a7bh, 1a1bh, 1a00h ;54 - [ { <67>
       1A00
 FD64  0D3D 0D2B 0000				dw	0d3dh, 0d2bh, 0000h, 8300h ;55 - = + <68>	
       8300
 FD6C  1C0D 1C0D 1C0A				dw	1c0dh, 1c0dh, 1c0ah, 1c00h ;5a - Enter, (E0)KPEnter <69>
       1C00
 FD74  1B5D 1B7D 1B1D				dw	1b5dh, 1b7dh, 1b1dh, 1b00h ;5b - ] } <70>
       1B00
 FD7C  2B5C 2B7C 2B1C				dw	2b5ch, 2b7ch, 2b1ch, 2b00h ;5d - \ | <71>
       2B00
 FD84  0E08 0E08 0E7F				dw	0e08h, 0e08h, 0e7fh, 0e00h ;66 - BKSP <72>
       0E00
 FD8C  4F00 4F00 7500				dw	4f00h, 4f00h, 7500h, 9f00h ;69 - (E0)END <73>
       9F00
 FD94  4B00 4B00 7300				dw	4b00h, 4b00h, 7300h, 9b00h ;6b - (E0)LEFT <74>
       9B00
 FD9C  4700 4700 7700				dw	4700h, 4700h, 7700h, 9700h ;6c - (E0)HOME <75>
       9700
 FDA4  5200 5200 9200				dw	5200h, 5200h, 9200h, 0a200h ;70 - (E0)INS <76>
       A200
 FDAC  5300 5300 9300				dw	5300h, 5300h, 9300h, 0a300h ;71 - (E0)DEL <77>
       A300
 FDB4  5000 5000 9100				dw	5000h, 5000h, 9100h, 0a000h ;72 - (E0)DOWN <78>
       A000
 FDBC  4300 5C00 6600				dw	4300h, 5c00h, 6600h, 7000h ;01 - F9 <79>
       7000
 FDC4  4D00 4D00 7400				dw	4d00h, 4d00h, 7400h, 9d00h ;74 - (E0)RIGHT <80>
       9D00
 FDCC  4800 4800 8D00				dw	4800h, 4800h, 8d00h, 9800h ;75 - (E0)UP <81>
       9800
 FDD4  011B 011B 011B				dw	011bh, 011bh, 011bh, 0100h ;76 - ESC <82>
       0100
 FDDC  8500 8700 8900				dw	8500h, 8700h, 8900h, 8b00h ;78 - F11 <83>
       8B00
 FDE4  4E2B 4E2B 9000				dw	4e2bh, 4e2bh, 9000h, 4e00h ;79 - KP+ <84>
       4E00
 FDEC  5100 5100 7600				dw	5100h, 5100h, 7600h, 0a100h ;7a - (E0)PGDN <85>
       A100
 FDF4  4A2D 4A2D 8E00				dw	4a2dh, 4a2dh, 8e00h, 4a00h ;7b - KP- <86>
       4A00
 FDFC  372A 372A 9600				dw	372ah, 372ah, 9600h, 3700h ;7c - KP* --- on VMWare, it does not send 3710h with CTL <87>
       3700
 FE04  4900 4900 8400				dw	4900h, 4900h, 8400h, 9900h ;7d - (E0)PGUP <88>
       9900
 FE0C  4600 4600 4600				dw	4600h, 4600h, 4600h, 4600h ;7e - SCRL <89>
       4600
 FE14  4100 5A00 6400				dw	4100h, 5a00h, 6400h, 6e00h ;83 - F7 <90>
       6E00

				; ------------------------- POWER ON RESET -----------------------
						org     0fff0h
						
 FFF0  EA					db      0eah
 FFF1  E05B R F000				dw      coldboot, 0f000h
 FFF5  30 35 2F 30 39 2F			db      '05/09/17'
       31 37
 FFFD  FF FF 00					db      0ffh, 0ffh, 0
				end bios
Microsoft (R) Macro Assembler Version 6.14.8444		    10/04/17 17:31:08
BIOS_Next186.asm					     Symbols 2 - 1




Macros:

                N a m e                 Type

OFFDX  . . . . . . . . . . . . .	Proc


Segments and Groups:

                N a m e                 Size     Length   Align   Combine Class

DGROUP . . . . . . . . . . . . .	GROUP
_TEXT  . . . . . . . . . . . . .	16 Bit	 00010000 Word	  Public  'CODE'	
_DATA  . . . . . . . . . . . . .	16 Bit	 0000	  Word	  Public  'DATA'	


Procedures,  parameters and locals:

                N a m e                 Type     Value    Attr

KeyLock  . . . . . . . . . . . .	P Near	 E573	  _TEXT	Length= 0016 Public
  s2 . . . . . . . . . . . . . .	L Near	 E580	  _TEXT	
  exit . . . . . . . . . . . . .	L Near	 E588	  _TEXT	
defint . . . . . . . . . . . . .	P Near	 F5AD	  _TEXT	Length= 0001 Public
enableKbIfPresent  . . . . . . .	P Near	 F5A1	  _TEXT	Length= 000C Public
  noenablekb . . . . . . . . . .	L Near	 F5AC	  _TEXT	
getps2byte . . . . . . . . . . .	P Near	 F576	  _TEXT	Length= 001A Public
  gps2b2 . . . . . . . . . . . .	L Near	 F57B	  _TEXT	
  gps2b1 . . . . . . . . . . . .	L Near	 F58B	  _TEXT	
int07  . . . . . . . . . . . . .	P Near	 E2F4	  _TEXT	Length= 0030 Public
  int07_pfx  . . . . . . . . . .	L Near	 E2FD	  _TEXT	
  int072 . . . . . . . . . . . .	L Near	 E316	  _TEXT	
int08  . . . . . . . . . . . . .	P Near	 E324	  _TEXT	Length= 0046 Public
  int081 . . . . . . . . . . . .	L Near	 E34C	  _TEXT	
  kloop  . . . . . . . . . . . .	L Near	 E352	  _TEXT	
  kbdata . . . . . . . . . . . .	L Near	 E364	  _TEXT	
  nokey  . . . . . . . . . . . .	L Near	 E366	  _TEXT	
int09  . . . . . . . . . . . . .	P Near	 E36A	  _TEXT	Length= 0209 Public
  SecondACK  . . . . . . . . . .	L Near	 E394	  _TEXT	
  ToggleACK  . . . . . . . . . .	L Near	 E397	  _TEXT	
  SetFlags1  . . . . . . . . . .	L Near	 E39A	  _TEXT	
  noACK  . . . . . . . . . . . .	L Near	 E39D	  _TEXT	
  noE0 . . . . . . . . . . . . .	L Near	 E3B0	  _TEXT	
  noE1 . . . . . . . . . . . . .	L Near	 E3B9	  _TEXT	
  noDEL  . . . . . . . . . . . .	L Near	 E3D5	  _TEXT	
  noLSDown . . . . . . . . . . .	L Near	 E3E3	  _TEXT	
  noLSUp . . . . . . . . . . . .	L Near	 E3EC	  _TEXT	
  noRSDown . . . . . . . . . . .	L Near	 E3F5	  _TEXT	
  noRSUp . . . . . . . . . . . .	L Near	 E3FE	  _TEXT	
  LALTDn . . . . . . . . . . . .	L Near	 E40F	  _TEXT	
  noALTDown  . . . . . . . . . .	L Near	 E415	  _TEXT	
  LALTUp . . . . . . . . . . . .	L Near	 E426	  _TEXT	
  ALTUp  . . . . . . . . . . . .	L Near	 E42A	  _TEXT	
  noALTUp  . . . . . . . . . . .	L Near	 E437	  _TEXT	
  SetFlagsKey2 . . . . . . . . .	L Near	 E446	  _TEXT	
  LCTLDn . . . . . . . . . . . .	L Near	 E448	  _TEXT	
  noCTLDown  . . . . . . . . . .	L Near	 E44E	  _TEXT	
  LCTLUp . . . . . . . . . . . .	L Near	 E45F	  _TEXT	
  noCTLUp  . . . . . . . . . . .	L Near	 E465	  _TEXT	
  noScrLock  . . . . . . . . . .	L Near	 E498	  _TEXT	
  testINS  . . . . . . . . . . .	L Near	 E4A7	  _TEXT	
  noIns  . . . . . . . . . . . .	L Near	 E4AD	  _TEXT	
  SetFlagsKey1 . . . . . . . . .	L Near	 E4C1	  _TEXT	
  E0Key  . . . . . . . . . . . .	L Near	 E4C4	  _TEXT	
  NormalKey  . . . . . . . . . .	L Near	 E4D9	  _TEXT	
  KeyDown  . . . . . . . . . . .	L Near	 E4ED	  _TEXT	
  noShift  . . . . . . . . . . .	L Near	 E4F6	  _TEXT	
  noCaps . . . . . . . . . . . .	L Near	 E504	  _TEXT	
  NumDown  . . . . . . . . . . .	L Near	 E50F	  _TEXT	
  noNum  . . . . . . . . . . . .	L Near	 E512	  _TEXT	
  noCtrl . . . . . . . . . . . .	L Near	 E519	  _TEXT	
  noAlt  . . . . . . . . . . . .	L Near	 E520	  _TEXT	
  pushKey  . . . . . . . . . . .	L Near	 E53E	  _TEXT	
  SetFlagsKey  . . . . . . . . .	L Near	 E549	  _TEXT	
  SetFlags . . . . . . . . . . .	L Near	 E54C	  _TEXT	
  SF1  . . . . . . . . . . . . .	L Near	 E567	  _TEXT	
  int09Exit  . . . . . . . . . .	L Near	 E56F	  _TEXT	
int10  . . . . . . . . . . . . .	P Near	 E589	  _TEXT	Length= 088F Public
  exit . . . . . . . . . . . . .	L Near	 E5A8	  _TEXT	
  svga . . . . . . . . . . . . .	L Near	 E5AB	  _TEXT	
  VESAGetInfo  . . . . . . . . .	L Near	 E5C0	  _TEXT	
  VESASupportedClear . . . . . .	L Near	 E5CD	  _TEXT	
  VESASupported  . . . . . . . .	L Near	 E5D3	  _TEXT	
  VESASupportedErr . . . . . . .	L Near	 E5D5	  _TEXT	
  VESAGetModeInfo  . . . . . . .	L Near	 E5D9	  _TEXT	
  VESAGetModeInfo1 . . . . . . .	L Near	 E5DD	  _TEXT	
  VESASetMode  . . . . . . . . .	L Near	 E5F0	  _TEXT	
  VESASetMode1 . . . . . . . . .	L Near	 E602	  _TEXT	
  VESAGetMode  . . . . . . . . .	L Near	 E60A	  _TEXT	
  VESAGetMode1 . . . . . . . . .	L Near	 E620	  _TEXT	
  VESAMemControl . . . . . . . .	L Near	 E626	  _TEXT	
  VESAMemControlCB . . . . . . .	L Near	 E62A	  _TEXT	
  getpageinfo  . . . . . . . . .	L Near	 E647	  _TEXT	
  VESAModeInfo . . . . . . . . .	L Near	 E67D	  _TEXT	
  setmode  . . . . . . . . . . .	L Near	 E690	  _TEXT	
  setmode1 . . . . . . . . . . .	L Near	 E6ED	  _TEXT	
  setmode12  . . . . . . . . . .	L Near	 E70A	  _TEXT	
  setmode1221  . . . . . . . . .	L Near	 E717	  _TEXT	
  setmode122 . . . . . . . . . .	L Near	 E727	  _TEXT	
  setmode121 . . . . . . . . . .	L Near	 E749	  _TEXT	
  setmode13  . . . . . . . . . .	L Near	 E758	  _TEXT	
  setmode3 . . . . . . . . . . .	L Near	 E775	  _TEXT	
  setmode21  . . . . . . . . . .	L Near	 E793	  _TEXT	
  setmode2 . . . . . . . . . . .	L Near	 E79B	  _TEXT	
  clearnext  . . . . . . . . . .	L Near	 E7E0	  _TEXT	
  clearok  . . . . . . . . . . .	L Near	 E7F4	  _TEXT	
  setmode4 . . . . . . . . . . .	L Near	 E7F4	  _TEXT	
  setmodeexit  . . . . . . . . .	L Near	 E843	  _TEXT	
  nullproc . . . . . . . . . . .	L Near	 E845	  _TEXT	
  cursor . . . . . . . . . . . .	L Near	 E846	  _TEXT	
  cursor8  . . . . . . . . . . .	L Near	 E857	  _TEXT	
  curpos . . . . . . . . . . . .	L Near	 E866	  _TEXT	
  curpos1  . . . . . . . . . . .	L Near	 E898	  _TEXT	
  getcurpos  . . . . . . . . . .	L Near	 E89B	  _TEXT	
  lightpen . . . . . . . . . . .	L Near	 E8AB	  _TEXT	
  apage  . . . . . . . . . . . .	L Near	 E8AE	  _TEXT	
  apage1 . . . . . . . . . . . .	L Near	 E8D9	  _TEXT	
  apage3 . . . . . . . . . . . .	L Near	 E8E7	  _TEXT	
  apage2 . . . . . . . . . . . .	L Near	 E8E9	  _TEXT	
  apage4 . . . . . . . . . . . .	L Near	 E8EC	  _TEXT	
  scrollup . . . . . . . . . . .	L Near	 E907	  _TEXT	
  scrollup6  . . . . . . . . . .	L Near	 E911	  _TEXT	
  scrollup4  . . . . . . . . . .	L Near	 E928	  _TEXT	
  scrollup3  . . . . . . . . . .	L Near	 E935	  _TEXT	
  scrollup5  . . . . . . . . . .	L Near	 E93A	  _TEXT	
  scrollexit . . . . . . . . . .	L Near	 E944	  _TEXT	
  scrolldn . . . . . . . . . . .	L Near	 E947	  _TEXT	
  scr_params . . . . . . . . . .	L Near	 E958	  _TEXT	
  readchar . . . . . . . . . . .	L Near	 E96E	  _TEXT	
  mode3chaddr  . . . . . . . . .	L Near	 E976	  _TEXT	
  writecharattr  . . . . . . . .	L Near	 E994	  _TEXT	
  writechar  . . . . . . . . . .	L Near	 E9AA	  _TEXT	
  writechar3 . . . . . . . . . .	L Near	 E9B1	  _TEXT	
  writecharskip  . . . . . . . .	L Near	 E9BA	  _TEXT	
  writecharTTY . . . . . . . . .	L Near	 E9BB	  _TEXT	
  tty  . . . . . . . . . . . . .	L Near	 E9D9	  _TEXT	
  tty1 . . . . . . . . . . . . .	L Near	 E9FE	  _TEXT	
  bell . . . . . . . . . . . . .	L Near	 EA00	  _TEXT	
  bs . . . . . . . . . . . . . .	L Near	 EA02	  _TEXT	
  lf . . . . . . . . . . . . . .	L Near	 EA0A	  _TEXT	
  crlf . . . . . . . . . . . . .	L Near	 EA0E	  _TEXT	
  cr . . . . . . . . . . . . . .	L Near	 EA10	  _TEXT	
  readmode . . . . . . . . . . .	L Near	 EA32	  _TEXT	
  pal  . . . . . . . . . . . . .	L Near	 EA7C	  _TEXT	
  palexit  . . . . . . . . . . .	L Near	 EA89	  _TEXT	
  setonereg  . . . . . . . . . .	L Near	 EA8A	  _TEXT	
  setonereg1 . . . . . . . . . .	L Near	 EA99	  _TEXT	
  setallreg  . . . . . . . . . .	L Near	 EA9A	  _TEXT	
  setallreg1 . . . . . . . . . .	L Near	 EAA1	  _TEXT	
  setblink . . . . . . . . . . .	L Near	 EAAE	  _TEXT	
  setblink1  . . . . . . . . . .	L Near	 EAD8	  _TEXT	
  readonereg . . . . . . . . . .	L Near	 EADA	  _TEXT	
  readallreg . . . . . . . . . .	L Near	 EAEF	  _TEXT	
  readllreg1 . . . . . . . . . .	L Near	 EAF4	  _TEXT	
  readoverscan . . . . . . . . .	L Near	 EB06	  _TEXT	
  setoneDAC  . . . . . . . . . .	L Near	 EB09	  _TEXT	
  setblockDAC  . . . . . . . . .	L Near	 EB1F	  _TEXT	
  paging . . . . . . . . . . . .	L Near	 EB30	  _TEXT	
  paging1  . . . . . . . . . . .	L Near	 EB51	  _TEXT	
  paging3  . . . . . . . . . . .	L Near	 EB58	  _TEXT	
  paging2  . . . . . . . . . . .	L Near	 EB5D	  _TEXT	
  readoneDAC . . . . . . . . . .	L Near	 EB60	  _TEXT	
  readblockDAC . . . . . . . . .	L Near	 EB78	  _TEXT	
  setPELmask . . . . . . . . . .	L Near	 EB89	  _TEXT	
  getPELmask . . . . . . . . . .	L Near	 EB92	  _TEXT	
  getpaging  . . . . . . . . . .	L Near	 EB9B	  _TEXT	
  getpaging1 . . . . . . . . . .	L Near	 EBB0	  _TEXT	
  grayscale  . . . . . . . . . .	L Near	 EBB1	  _TEXT	
  grayscale1 . . . . . . . . . .	L Near	 EBB6	  _TEXT	
  grayscale2 . . . . . . . . . .	L Near	 EBDE	  _TEXT	
  loadUDF  . . . . . . . . . . .	L Near	 EBDF	  _TEXT	
  loadUDF1 . . . . . . . . . . .	L Near	 EBEB	  _TEXT	
  loadUDFexit1 . . . . . . . . .	L Near	 EC2A	  _TEXT	
  loadUDFexit  . . . . . . . . .	L Near	 EC2B	  _TEXT	
  chargen  . . . . . . . . . . .	L Near	 EC2C	  _TEXT	
  loadROMFont8 . . . . . . . . .	L Near	 EC4F	  _TEXT	
  loadROMFont16  . . . . . . . .	L Near	 EC5A	  _TEXT	
  loadROMFont161 . . . . . . . .	L Near	 EC63	  _TEXT	
  set1f  . . . . . . . . . . . .	L Near	 EC72	  _TEXT	
  setgrUDF . . . . . . . . . . .	L Near	 EC7D	  _TEXT	
  setgrUDF1  . . . . . . . . . .	L Near	 EC9D	  _TEXT	
  setgrUDFexit . . . . . . . . .	L Near	 ECA8	  _TEXT	
  setROMgrFont . . . . . . . . .	L Near	 ECAA	  _TEXT	
  setROMgrFont1  . . . . . . . .	L Near	 ECBB	  _TEXT	
  getfontinfo  . . . . . . . . .	L Near	 ECC8	  _TEXT	
  getfontinfo1 . . . . . . . . .	L Near	 ECE3	  _TEXT	
  getfontinfoexit  . . . . . . .	L Near	 ECF6	  _TEXT	
  special  . . . . . . . . . . .	L Near	 ED03	  _TEXT	
  special1 . . . . . . . . . . .	L Near	 ED13	  _TEXT	
  special2 . . . . . . . . . . .	L Near	 ED27	  _TEXT	
  writestr . . . . . . . . . . .	L Near	 ED2A	  _TEXT	
  wstr1  . . . . . . . . . . . .	L Near	 ED39	  _TEXT	
  noattr . . . . . . . . . . . .	L Near	 ED47	  _TEXT	
  wstr2  . . . . . . . . . . . .	L Near	 ED5C	  _TEXT	
  wstrexit . . . . . . . . . . .	L Near	 ED5D	  _TEXT	
  getdcc . . . . . . . . . . . .	L Near	 ED5E	  _TEXT	
  setdcc . . . . . . . . . . . .	L Near	 ED69	  _TEXT	
  getdccexit . . . . . . . . . .	L Near	 ED6E	  _TEXT	
  querystatus  . . . . . . . . .	L Near	 ED6F	  _TEXT	
  querystatus1 . . . . . . . . .	L Near	 EDA1	  _TEXT	
  querystatus3 . . . . . . . . .	L Near	 EDAB	  _TEXT	
int11  . . . . . . . . . . . . .	P Near	 EE18	  _TEXT	Length= 0009 Public
int12  . . . . . . . . . . . . .	P Near	 EE21	  _TEXT	Length= 0009 Public
int13  . . . . . . . . . . . . .	P Near	 EE2A	  _TEXT	Length= 01ED Public
  inINT13  . . . . . . . . . . .	L Near	 EE49	  _TEXT	
  Disk1  . . . . . . . . . . . .	L Near	 EE4D	  _TEXT	
  exit . . . . . . . . . . . . .	L Near	 EE5D	  _TEXT	
  exit2  . . . . . . . . . . . .	L Near	 EE61	  _TEXT	
  exit1  . . . . . . . . . . . .	L Near	 EE68	  _TEXT	
  DiskGetType  . . . . . . . . .	L Near	 EEBB	  _TEXT	
  DiskGetTypeexit  . . . . . . .	L Near	 EED2	  _TEXT	
  DiskExtInstCheck . . . . . . .	L Near	 EEDB	  _TEXT	
  DiskReset  . . . . . . . . . .	L Near	 EEE9	  _TEXT	
  DiskChanged  . . . . . . . . .	L Near	 EEE9	  _TEXT	
  DiskPark . . . . . . . . . . .	L Near	 EEE9	  _TEXT	
  DiskGetStatus  . . . . . . . .	L Near	 EEEC	  _TEXT	
  DiskVerify . . . . . . . . . .	L Near	 EEF1	  _TEXT	
  DiskWrite  . . . . . . . . . .	L Near	 EEF6	  _TEXT	
  DiskRead . . . . . . . . . . .	L Near	 EEFB	  _TEXT	
  DiskRead1  . . . . . . . . . .	L Near	 EEFE	  _TEXT	
  DiskReadend  . . . . . . . . .	L Near	 EF26	  _TEXT	
  HCStoLBA . . . . . . . . . . .	L Near	 EF27	  _TEXT	
  DiskFormat . . . . . . . . . .	L Near	 EF45	  _TEXT	
  DiskInit . . . . . . . . . . .	L Near	 EF45	  _TEXT	
  DiskSeek . . . . . . . . . . .	L Near	 EF45	  _TEXT	
  DiskRst  . . . . . . . . . . .	L Near	 EF45	  _TEXT	
  DiskReady  . . . . . . . . . .	L Near	 EF45	  _TEXT	
  DiskRecalibrate  . . . . . . .	L Near	 EF45	  _TEXT	
  DiskDiag . . . . . . . . . . .	L Near	 EF45	  _TEXT	
  DiskExtSeek  . . . . . . . . .	L Near	 EF45	  _TEXT	
  notready . . . . . . . . . . .	L Near	 EF51	  _TEXT	
  DiskGetParams  . . . . . . . .	L Near	 EF54	  _TEXT	
  dgpok  . . . . . . . . . . . .	L Near	 EF7C	  _TEXT	
  DiskExtVerify  . . . . . . . .	L Near	 EF8B	  _TEXT	
  DiskExtWrite . . . . . . . . .	L Near	 EF90	  _TEXT	
  DiskExtRead  . . . . . . . . .	L Near	 EF95	  _TEXT	
  DiskExtRead1 . . . . . . . . .	L Near	 EF98	  _TEXT	
  DiskExtGetParams . . . . . . .	L Near	 EFC7	  _TEXT	
  DiskReadSectBuffer . . . . . .	L Near	 F014	  _TEXT	
  DiskWriteSectBuffer  . . . . .	L Near	 F014	  _TEXT	
  DiskSetDASDType  . . . . . . .	L Near	 F014	  _TEXT	
  DiskSetMediaType . . . . . . .	L Near	 F014	  _TEXT	
  DiskExtLock  . . . . . . . . .	L Near	 F014	  _TEXT	
  DiskExtEject . . . . . . . . .	L Near	 F014	  _TEXT	
int14  . . . . . . . . . . . . .	P Near	 F017	  _TEXT	Length= 0081 Public
  SExit  . . . . . . . . . . . .	L Near	 F03E	  _TEXT	
  SetCharFormat  . . . . . . . .	L Near	 F042	  _TEXT	
  Baud110  . . . . . . . . . . .	L Near	 F05B	  _TEXT	
  GetPortStatus  . . . . . . . .	L Near	 F071	  _TEXT	
  GetPortStatus1 . . . . . . . .	L Near	 F074	  _TEXT	
  STransmit  . . . . . . . . . .	L Near	 F07B	  _TEXT	
  STr1 . . . . . . . . . . . . .	L Near	 F07E	  _TEXT	
  STr2 . . . . . . . . . . . . .	L Near	 F089	  _TEXT	
  SReceive . . . . . . . . . . .	L Near	 F08C	  _TEXT	
  SReceive1  . . . . . . . . . .	L Near	 F08D	  _TEXT	
int16  . . . . . . . . . . . . .	P Near	 F300	  _TEXT	Length= 00EB Public
  kbfunc . . . . . . . . . . . .	L Near	 F328	  _TEXT	
  Exit . . . . . . . . . . . . .	L Near	 F32A	  _TEXT	
  GetKey1  . . . . . . . . . . .	L Near	 F32D	  _TEXT	
  GetKey . . . . . . . . . . . .	L Near	 F32E	  _TEXT	
  noWrap . . . . . . . . . . . .	L Near	 F344	  _TEXT	
  TestKey  . . . . . . . . . . .	L Near	 F34A	  _TEXT	
  StoreKey . . . . . . . . . . .	L Near	 F359	  _TEXT	
  NoWrap1  . . . . . . . . . . .	L Near	 F36B	  _TEXT	
  ExtStatus  . . . . . . . . . .	L Near	 F37A	  _TEXT	
  NoSysReq . . . . . . . . . . .	L Near	 F385	  _TEXT	
  GetStatus  . . . . . . . . . .	L Near	 F38E	  _TEXT	
  Exit1  . . . . . . . . . . . .	L Near	 F391	  _TEXT	
  SetAutoRpt . . . . . . . . . .	L Near	 F393	  _TEXT	
  timeout1 . . . . . . . . . . .	L Near	 F3C9	  _TEXT	
  timeout  . . . . . . . . . . .	L Near	 F3CE	  _TEXT	
  WaitFlag . . . . . . . . . . .	L Near	 F3D1	  _TEXT	
  wf_loop  . . . . . . . . . . .	L Near	 F3D6	  _TEXT	
  wf_ok  . . . . . . . . . . . .	L Near	 F3EA	  _TEXT	
int18  . . . . . . . . . . . . .	P Near	 F3EB	  _TEXT	Length= 007F Public
  sloop  . . . . . . . . . . . .	L Near	 F415	  _TEXT	
int19  . . . . . . . . . . . . .	P Near	 F46A	  _TEXT	Length= 001A Public
  int19err . . . . . . . . . . .	L Near	 F482	  _TEXT	
int1a  . . . . . . . . . . . . .	P Near	 F484	  _TEXT	Length= 002C Public
  clockexit1 . . . . . . . . . .	L Near	 F49A	  _TEXT	
  clockexit  . . . . . . . . . .	L Near	 F49F	  _TEXT	
  setclock . . . . . . . . . . .	L Near	 F4A5	  _TEXT	
int70  . . . . . . . . . . . . .	P Near	 F4B0	  _TEXT	Length= 002E Public
  exit1  . . . . . . . . . . . .	L Near	 F4D6	  _TEXT	
  exit . . . . . . . . . . . . .	L Near	 F4DC	  _TEXT	
int74  . . . . . . . . . . . . .	P Near	 F4DE	  _TEXT	Length= 0047 Public
  docall . . . . . . . . . . . .	L Near	 F503	  _TEXT	
  nocall . . . . . . . . . . . .	L Near	 F522	  _TEXT	
sdinit . . . . . . . . . . . . .	P Near	 F79C	  _TEXT	Length= 009D Public
  sdinit1  . . . . . . . . . . .	L Near	 F7A7	  _TEXT	
  repinit  . . . . . . . . . . .	L Near	 F7D7	  _TEXT	
  sdexit . . . . . . . . . . . .	L Near	 F82B	  _TEXT	
sdrblk . . . . . . . . . . . . .	P Near	 F646	  _TEXT	Length= 0030 Public
  sdrblk1  . . . . . . . . . . .	L Near	 F64E	  _TEXT	
  sdrblk2  . . . . . . . . . . .	L Near	 F653	  _TEXT	
sdwblk . . . . . . . . . . . . .	P Near	 F613	  _TEXT	Length= 0033 Public
  sdwblk1  . . . . . . . . . . .	L Near	 F615	  _TEXT	
sendcmd  . . . . . . . . . . . .	P Near	 F590	  _TEXT	Length= 0011 Public
  retry  . . . . . . . . . . . .	L Near	 F597	  _TEXT	
  exit . . . . . . . . . . . . .	L Near	 F5A0	  _TEXT	
sendps2byte  . . . . . . . . . .	P Near	 F551	  _TEXT	Length= 0025 Public
  sps2b2 . . . . . . . . . . . .	L Near	 F557	  _TEXT	
  sps2b1 . . . . . . . . . . . .	L Near	 F568	  _TEXT	
  sps2_kb  . . . . . . . . . . .	L Near	 F570	  _TEXT	
  exit . . . . . . . . . . . . .	L Near	 F574	  _TEXT	


Symbols:

                N a m e                 Type     Value    Attr

@CodeSize  . . . . . . . . . . .	Number	 0000h	 
@DataSize  . . . . . . . . . . .	Number	 0000h	 
@Interface . . . . . . . . . . .	Number	 0000h	 
@Model . . . . . . . . . . . . .	Number	 0001h	 
@code  . . . . . . . . . . . . .	Text   	 DGROUP
@data  . . . . . . . . . . . . .	Text   	 DGROUP
@fardata?  . . . . . . . . . . .	Text   	 FAR_BSS
@fardata . . . . . . . . . . . .	Text   	 FAR_DATA
@stack . . . . . . . . . . . . .	Text   	 DGROUP
AckReceived  . . . . . . . . . .	Number	 0010h	 
ActivePage . . . . . . . . . . .	Text   	 ds:[62h]
ActiveVideoMode  . . . . . . . .	Text   	 ds:[49h]
AltDown  . . . . . . . . . . . .	Number	 0008h	 
AltKpd . . . . . . . . . . . . .	Text   	 ds:[19h]
Buffer . . . . . . . . . . . . .	Text   	 ds:[80h]
COMFlush . . . . . . . . . . . .	L Near	 E217	  _TEXT	
CapsLockDown . . . . . . . . . .	Number	 0040h	 
CapsLockLED  . . . . . . . . . .	Number	 0004h	 
CapsLock . . . . . . . . . . . .	Number	 0040h	 
ComPort  . . . . . . . . . . . .	Number	 0000h	 
CrtMode  . . . . . . . . . . . .	Text   	 ds:[65h]
CrtPalette . . . . . . . . . . .	Text   	 ds:[66h]
CtrlBreak  . . . . . . . . . . .	Text   	 ds:[71h]
CtrlDown . . . . . . . . . . . .	Number	 0004h	 
CursorPos  . . . . . . . . . . .	Text   	 ds:[50h]
CursorShape  . . . . . . . . . .	Text   	 ds:[60h]
DLH  . . . . . . . . . . . . . .	Number	 0001h	 
DLL  . . . . . . . . . . . . . .	Number	 0000h	 
DataBuffer . . . . . . . . . . .	Text   	 ds:[0a5h]
DataCounter  . . . . . . . . . .	Text   	 ds:[067h]
E0KeyIndex . . . . . . . . . . .	L Near	 FB38	  _TEXT	
E0KeyList  . . . . . . . . . . .	L Near	 FB2C	  _TEXT	
EgaMiscInfo2 . . . . . . . . . .	Text   	 ds:[88h]
EgaMiscInfo  . . . . . . . . . .	Text   	 ds:[87h]
EndBuf . . . . . . . . . . . . .	Text   	 ds:[82h]
EquipmentWord  . . . . . . . . .	Text   	 ds:[10h]
ExtSize  . . . . . . . . . . . .	L Near	 F1F0	  _TEXT	
FreeXMSKb  . . . . . . . . . . .	Number	 7B60h	 
GetConfig  . . . . . . . . . . .	L Near	 F1F5	  _TEXT	
HDLastError  . . . . . . . . . .	Text   	 ds:[74h]
HDOpStarted  . . . . . . . . . .	Text   	 ds:[92h]
HDSize . . . . . . . . . . . . .	Text   	 ds:[94h]
HandlerPtr . . . . . . . . . . .	Text   	 ds:[0a1h]
HeadPtr  . . . . . . . . . . . .	Text   	 ds:[1ah]
IER  . . . . . . . . . . . . . .	Number	 0001h	 
IncSeg1  . . . . . . . . . . . .	L Near	 F0A6	  _TEXT	
IncSeg . . . . . . . . . . . . .	L Near	 F098	  _TEXT	
InsDown  . . . . . . . . . . . .	Number	 0080h	 
Insert . . . . . . . . . . . . .	Number	 0080h	 
KbdFlags1  . . . . . . . . . . .	Text   	 ds:[17h]
KbdFlags2  . . . . . . . . . . .	Text   	 ds:[18h]
KbdFlags3  . . . . . . . . . . .	Text   	 ds:[96h]
KbdFlags4  . . . . . . . . . . .	Text   	 ds:[97h]
KeyCode  . . . . . . . . . . . .	L Near	 FB44	  _TEXT	
KeyIndex . . . . . . . . . . . .	L Near	 FAD3	  _TEXT	
LAltDown . . . . . . . . . . . .	Number	 0002h	 
LCR  . . . . . . . . . . . . . .	Number	 0003h	 
LCtrDown . . . . . . . . . . . .	Number	 0001h	 
LEDUpdate  . . . . . . . . . . .	Number	 0040h	 
LSR  . . . . . . . . . . . . . .	Number	 0005h	 
LShfDown . . . . . . . . . . . .	Number	 0002h	 
LastE0 . . . . . . . . . . . . .	Number	 0002h	 
LastE1 . . . . . . . . . . . . .	Number	 0001h	 
LastF0 . . . . . . . . . . . . .	Number	 0020h	 
MSR  . . . . . . . . . . . . . .	Number	 0006h	 
MemorySize . . . . . . . . . . .	Text   	 ds:[13h]
Mouse  . . . . . . . . . . . . .	L Near	 F1FE	  _TEXT	
MovExt1  . . . . . . . . . . . .	L Near	 F112	  _TEXT	
MovExt2  . . . . . . . . . . . .	L Near	 F124	  _TEXT	
MovExtLoop . . . . . . . . . . .	L Near	 F109	  _TEXT	
MovExtProxy  . . . . . . . . . .	L Near	 F165	  _TEXT	
MovExt_exit  . . . . . . . . . .	L Near	 F14D	  _TEXT	
MovExt_next  . . . . . . . . . .	L Near	 F137	  _TEXT	
MovExt . . . . . . . . . . . . .	L Near	 F0C6	  _TEXT	
MovSeg . . . . . . . . . . . . .	Number	 0001h	 
NumLockDown  . . . . . . . . . .	Number	 0020h	 
NumLockLED . . . . . . . . . . .	Number	 0002h	 
NumLock  . . . . . . . . . . . .	Number	 0020h	 
PacketSize . . . . . . . . . . .	Text   	 ds:[068h]
PageOffset . . . . . . . . . . .	Text   	 ds:[4eh]
Pal256 . . . . . . . . . . . . .	L Near	 F863	  _TEXT	
PalEGA . . . . . . . . . . . . .	L Near	 F933	  _TEXT	
PalOffset  . . . . . . . . . . .	Text   	 ds:[69h]
PalVGA . . . . . . . . . . . . .	L Near	 FA03	  _TEXT	
Pause  . . . . . . . . . . . . .	Number	 0008h	 
PortAddress  . . . . . . . . . .	Text   	 ds:[63h]
RAMSize  . . . . . . . . . . . .	Number	 0200h	 
RAltDown . . . . . . . . . . . .	Number	 0008h	 
RBR  . . . . . . . . . . . . . .	Number	 0000h	 
RCtrDown . . . . . . . . . . . .	Number	 0004h	 
RShfDown . . . . . . . . . . . .	Number	 0001h	 
RegenLength  . . . . . . . . . .	Text   	 ds:[4ch]
SCANCODE1  . . . . . . . . . . .	Number	 0001h	 
SD_CMD0  . . . . . . . . . . . .	Byte	 F839	  _TEXT	
SD_CMD12 . . . . . . . . . . . .	Byte	 F84B	  _TEXT	
SD_CMD41 . . . . . . . . . . . .	Byte	 F851	  _TEXT	
SD_CMD55 . . . . . . . . . . . .	Byte	 F857	  _TEXT	
SD_CMD58 . . . . . . . . . . . .	Byte	 F85D	  _TEXT	
SD_CMD8  . . . . . . . . . . . .	Byte	 F83F	  _TEXT	
SD_CMD9  . . . . . . . . . . . .	Byte	 F845	  _TEXT	
ScanLinesChar  . . . . . . . . .	Text   	 ds:[85h]
ScrLockDown  . . . . . . . . . .	Number	 0010h	 
ScrLockLED . . . . . . . . . . .	Number	 0001h	 
ScrLock  . . . . . . . . . . . .	Number	 0010h	 
ScreenRows . . . . . . . . . . .	Text   	 ds:[84h]
ScreenWidth  . . . . . . . . . .	Text   	 ds:[4ah]
SetEventWait . . . . . . . . . .	L Near	 F1A2	  _TEXT	
SetRepeat  . . . . . . . . . . .	Number	 0008h	 
SetSeg1  . . . . . . . . . . . .	L Near	 F0BE	  _TEXT	
SetSeg2  . . . . . . . . . . . .	L Near	 F0B6	  _TEXT	
SetSegExit . . . . . . . . . . .	L Near	 F0BF	  _TEXT	
SetSeg . . . . . . . . . . . . .	L Near	 F0AB	  _TEXT	
SysParams  . . . . . . . . . . .	Byte	 F2F6	  _TEXT	
SysReqDown . . . . . . . . . . .	Number	 0004h	 
THR  . . . . . . . . . . . . . .	Number	 0000h	 
TailPtr  . . . . . . . . . . . .	Text   	 ds:[1ch]
UFPtr  . . . . . . . . . . . . .	Text   	 ds:[98h]
UWaitFlag  . . . . . . . . . . .	Text   	 ds:[0a0h]
VESAInfo . . . . . . . . . . . .	Byte	 E652	  _TEXT	
VESAModes  . . . . . . . . . . .	Word	 E679	  _TEXT	
VESAOEM  . . . . . . . . . . . .	Byte	 E666	  _TEXT	
VgaFlags2  . . . . . . . . . . .	Text   	 ds:[8ah]
VgaFlags . . . . . . . . . . . .	Text   	 ds:[89h]
Wait1  . . . . . . . . . . . . .	L Near	 F1D7	  _TEXT	
WaitCount  . . . . . . . . . . .	Text   	 ds:[9ch]
badparam . . . . . . . . . . . .	L Near	 F283	  _TEXT	
bioscont . . . . . . . . . . . .	Byte	 E27E	  _TEXT	
biosmsg  . . . . . . . . . . . .	Byte	 E000	  _TEXT	
bios . . . . . . . . . . . . . .	L Near	 E000	  _TEXT	
booterrmsg . . . . . . . . . . .	Byte	 F423	  _TEXT	
busy . . . . . . . . . . . . . .	L Near	 F1D3	  _TEXT	
cancel . . . . . . . . . . . . .	L Near	 F1CC	  _TEXT	
coldboot . . . . . . . . . . . .	L Near	 E05B	  _TEXT	
dccval . . . . . . . . . . . . .	Word	 ED69	  _TEXT	
disktbl  . . . . . . . . . . . .	Word	 EE75	  _TEXT	
dispAX1  . . . . . . . . . . . .	L Near	 F5E2	  _TEXT	
dispAX . . . . . . . . . . . . .	L Near	 F5D3	  _TEXT	
dly1 . . . . . . . . . . . . . .	L Near	 F548	  _TEXT	
dlybit . . . . . . . . . . . . .	L Near	 F544	  _TEXT	
done . . . . . . . . . . . . . .	L Near	 F199	  _TEXT	
en_dis . . . . . . . . . . . . .	L Near	 F256	  _TEXT	
errexit  . . . . . . . . . . . .	L Near	 F20F	  _TEXT	
exit15 . . . . . . . . . . . . .	L Near	 F19A	  _TEXT	
exit_ax  . . . . . . . . . . . .	L Near	 F19D	  _TEXT	
exit_iret  . . . . . . . . . . .	L Near	 F1A1	  _TEXT	
exit_success1  . . . . . . . . .	L Near	 F26B	  _TEXT	
exit_success . . . . . . . . . .	L Near	 F266	  _TEXT	
exitok . . . . . . . . . . . . .	L Near	 F210	  _TEXT	
extend . . . . . . . . . . . . .	L Near	 F2C1	  _TEXT	
flush1 . . . . . . . . . . . . .	L Near	 F5BB	  _TEXT	
flush_nostack  . . . . . . . . .	L Near	 F5B3	  _TEXT	
flushbh  . . . . . . . . . . . .	Word	 F5D1	  _TEXT	
flushret . . . . . . . . . . . .	Word	 F5CF	  _TEXT	
flush  . . . . . . . . . . . . .	L Near	 F5AE	  _TEXT	
font8x14 . . . . . . . . . . . .	Text   	 font8x16 - 0e00h
font8x16 . . . . . . . . . . . .	Text   	 font8x8 - 1000h
font8x8  . . . . . . . . . . . .	Text   	 bios - 800h
fontinfo . . . . . . . . . . . .	Word	 ECF7	  _TEXT	
gettype  . . . . . . . . . . . .	L Near	 F2A9	  _TEXT	
if_err1  . . . . . . . . . . . .	L Near	 F264	  _TEXT	
if_err . . . . . . . . . . . . .	L Near	 F20A	  _TEXT	
int15  . . . . . . . . . . . . .	L Near	 F168	  _TEXT	
kbi1 . . . . . . . . . . . . . .	L Near	 E17A	  _TEXT	
kbi2 . . . . . . . . . . . . . .	L Near	 E189	  _TEXT	
kbok . . . . . . . . . . . . . .	L Near	 E1BD	  _TEXT	
l1 . . . . . . . . . . . . . . .	L Near	 F539	  _TEXT	
mapi1  . . . . . . . . . . . . .	L Near	 E0A8	  _TEXT	
mapi . . . . . . . . . . . . . .	L Near	 E09F	  _TEXT	
mouse_present  . . . . . . . . .	L Near	 F220	  _TEXT	
mousei0  . . . . . . . . . . . .	L Near	 E1C5	  _TEXT	
mousei1  . . . . . . . . . . . .	L Near	 E1D3	  _TEXT	
mouseok  . . . . . . . . . . . .	L Near	 E1EF	  _TEXT	
msgkb  . . . . . . . . . . . . .	Byte	 E046	  _TEXT	
msgmb  . . . . . . . . . . . . .	Byte	 E039	  _TEXT	
msgmouse . . . . . . . . . . . .	Byte	 E269	  _TEXT	
nokbmsg  . . . . . . . . . . . .	L Near	 E24E	  _TEXT	
nokb . . . . . . . . . . . . . .	L Near	 E1B8	  _TEXT	
nomousemsg . . . . . . . . . . .	L Near	 E25B	  _TEXT	
nomouse  . . . . . . . . . . . .	L Near	 E1E6	  _TEXT	
nowait . . . . . . . . . . . . .	L Near	 F1D4	  _TEXT	
p3c0r10  . . . . . . . . . . . .	Byte	 E68F	  _TEXT	
paltable . . . . . . . . . . . .	Word	 EA44	  _TEXT	
prtse  . . . . . . . . . . . . .	L Near	 F5F8	  _TEXT	
prts . . . . . . . . . . . . . .	L Near	 F5EC	  _TEXT	
raligned . . . . . . . . . . . .	L Near	 F130	  _TEXT	
reset  . . . . . . . . . . . . .	L Near	 F26F	  _TEXT	
resolution . . . . . . . . . . .	L Near	 F29F	  _TEXT	
sample_tbl . . . . . . . . . . .	Byte	 F2EF	  _TEXT	
sampling . . . . . . . . . . . .	L Near	 F280	  _TEXT	
savesp . . . . . . . . . . . . .	Word	 F0C2	  _TEXT	
savess . . . . . . . . . . . . .	Word	 F0C0	  _TEXT	
sdcmd1 . . . . . . . . . . . . .	L Near	 F69D	  _TEXT	
sdcmd8T  . . . . . . . . . . . .	L Near	 F687	  _TEXT	
sdcmd  . . . . . . . . . . . . .	L Near	 F68A	  _TEXT	
sdr11  . . . . . . . . . . . . .	L Near	 F712	  _TEXT	
sdr1s  . . . . . . . . . . . . .	L Near	 F6B2	  _TEXT	
sdr1 . . . . . . . . . . . . . .	L Near	 F713	  _TEXT	
sdr2 . . . . . . . . . . . . . .	L Near	 F709	  _TEXT	
sdr3 . . . . . . . . . . . . . .	L Near	 F6FC	  _TEXT	
sdrb . . . . . . . . . . . . . .	L Near	 F5F9	  _TEXT	
sdread1  . . . . . . . . . . . .	L Near	 F6A6	  _TEXT	
sdread . . . . . . . . . . . . .	L Near	 F6A3	  _TEXT	
sdresp1  . . . . . . . . . . . .	L Near	 F692	  _TEXT	
sdresp . . . . . . . . . . . . .	L Near	 F690	  _TEXT	
sdrms  . . . . . . . . . . . . .	L Near	 F6D3	  _TEXT	
sdsb . . . . . . . . . . . . . .	L Near	 F5FB	  _TEXT	
sdvblk1  . . . . . . . . . . . .	L Near	 F679	  _TEXT	
sdvblk . . . . . . . . . . . . .	L Near	 F676	  _TEXT	
sdverify . . . . . . . . . . . .	L Near	 F69E	  _TEXT	
sdw1s1 . . . . . . . . . . . . .	L Near	 F762	  _TEXT	
sdw1s  . . . . . . . . . . . . .	L Near	 F72A	  _TEXT	
sdwms  . . . . . . . . . . . . .	L Near	 F74B	  _TEXT	
sdwrite  . . . . . . . . . . . .	L Near	 F71E	  _TEXT	
sdwwait1 . . . . . . . . . . . .	L Near	 F792	  _TEXT	
sdwwait  . . . . . . . . . . . .	L Near	 F77B	  _TEXT	
send1c . . . . . . . . . . . . .	L Near	 F299	  _TEXT	
send2c . . . . . . . . . . . . .	L Near	 F292	  _TEXT	
setscaling . . . . . . . . . . .	L Near	 F2E4	  _TEXT	
srecb  . . . . . . . . . . . . .	L Near	 F525	  _TEXT	
srstb  . . . . . . . . . . . . .	L Near	 F52D	  _TEXT	
staticfunctable  . . . . . . . .	Byte	 EDCE	  _TEXT	
ten  . . . . . . . . . . . . . .	Word	 F5EA	  _TEXT	
vidtbl . . . . . . . . . . . . .	Word	 EDDE	  _TEXT	
warmboot . . . . . . . . . . . .	L Near	 E05B	  _TEXT	
wbusy  . . . . . . . . . . . . .	L Near	 F1EC	  _TEXT	
wloop  . . . . . . . . . . . . .	L Near	 F1E5	  _TEXT	

	   0 Warnings
	   0 Errors
