'*****************************************************************************
'* 
'* BIOS DATA AREA INITIALIZATION (Executed by main "bios" script)
'* 
'* Note: - Called by main "bios" script
'* 
'*****************************************************************************

dim i as integer, k as integer, n as integer

'Serial ports I/O addresses, used by INT 14h (0 if not detected)
mem.Word(0x400)=0x3F8 'COM1
mem.Word(0x402)=0x2F8 'COM2
mem.Word(0x404)=0x000 'COM3
mem.Word(0x406)=0x000 'COM4

'Parallel ports I/O addresses, used by INT 17h (0 if not detected)
mem.Word(0x408)=0x00 'LPT1
mem.Word(0x40A)=0x00 'LPT2
mem.Word(0x40C)=0x00 'LPT3
mem.Word(0x40E)=0x00 'LPT4 on old BIOSes, EBDA segment on newer BIOSes (TODO)

'Installed hardware configuration word (used by INT 11h)
i=1                          'FDD installed (bit 0)
if cpu.HasFPU then i=i or 2  'FPU installed (bit 1)
i=i or 0                     'Pointing device (bit 2) TODO - mouse???
i=i or 0                     'Reserved (bit 3)    
                             'Initial video mode (bits 4-5,00-NoCGA,01-CGA40x25,
//if ucase(pc.VideoName)="CGA" then i=i or 0x20      '02-CGA80x25,03-Mono80x25)
i=i or 0x40                  'FDD count-1 (bits 6-7)
i=i or 0                     'Reserved (bit 8)
i=i or shl(2,9)              'COM ports count (bits 9-11)
i=i or 0                     'Game port installed (bit 12)
i=i or 0                     'Internal modem (bit 13)
i=i or 0                     'LPT ports count (bits 14-15)
mem.Word(0x410)=i            'Write result

'POST status byte
mem.Byte(0x412)=0

'Base memory size on kilobytes, used by INT 12h
mem.Word(0x413)=640 '640Kb

'PC, XT - adapter mem.size, AT - tests scratchpad
mem.Word(0x415)=0

'Keyboard main data area, used by INT 9h, INT 16h
mem.Word(0x417)=0       'status flags of service keys
mem.Byte(0x419)=0       'ALT+xxx code storage 
mem.Word(0x41A)=0x41E   'address of next char to process in keyboard buffer
mem.Word(0x41C)=0x41E   'address of next char to fill in keyboard buffer

'Keyboard buffer (32 bytes = 16 chars+scancodes), filled by INT 9h
for i=0x41E to 0x43D : mem.Byte(i)=0 : next 

'FDD main data area, used by INT 13h
mem.Word(0x43E)=0       'recalibration status
mem.Byte(0x43F)=0       'motor status
mem.Byte(0x440)=0       'motor stop counter (decremented by INT 08h)
mem.Byte(0x441)=0       'last operation status (=0 - no errors)

'FDD/HDD controllers command/status bytes
for i=0x443 to 0x448 : mem.Byte(i)=0 : next 

'Video main data area, used by INT 10h
mem.Byte(0x449)=3       'video mode index (3=CGA 80x25 16-colors)
mem.Word(0x44A)=80      'columns count
mem.Word(0x44C)=0x4000  'active video page size in bytes
mem.Word(0x44E)=0       'active video page offset in video memory
for i=0x450 to 0x45F    'cursor positions (row and column) for
mem.Byte(i)=0 : next    'each of eight video pages (for text modes)
mem.Word(0x460)=0x0706  'cursor size (top and bottom scanline indexes)
mem.Byte(0x462)=0       'active video page index
mem.Word(0x463)=0x3D4   'CRT controller I/O port address (3B4h-mono,3D4h-color)
mem.Byte(0x465)=0       'Last value, written to mode select port (3B8h/3D8h)
mem.Byte(0x466)=0       'Last value, written to CGA pallette port (3D9h)

'Start address after reset (used to exit from PMode when CPU is 286)
mem.Dword(0x467)=0xF000FFF0 'BIOS entry point 'TODO - make support in BIOS

'Last unexpected interrupt TODO
mem.Byte(0x46B)=0

'System time, used by INT 08h
mem.Dword(0x46C)=0      'timer counter (ticks count since midnight)
mem.Byte(0x470)=0       'timer overflow (days counter here)

'CTRL-Break key combination flag
mem.Byte(0x471)=0       'bit 7 is set if pressed

'Kind of action BIOS must do on POST start
mem.Word(0x472)=0       'Cold boot (=0), TODO - implement other actions

'HDD data area
mem.Byte(0x474)=0       'Disk last operation status (TODO)
mem.Byte(0x475)=2       'Fixed disk drives count (TODO other values)
mem.Word(0x476)=0       'reserved??? (TODO)

'LPT/COM timeout counters
mem.Bytes(0x478)=Array(0,0,0,0) 'LPT1..LPT4 (TODO - 47Bh as INT 4Bh flag)
mem.Bytes(0x47C)=Array(0,0,0,0) 'COM1..COM4

'AT-keyboard additional data area (TODO - must be used by INT 9h, INT 16h)
mem.Word(0x480)=0x1E    'keyboard buffer start offset in BIOS data segment 40h
mem.Word(0x482)=0x3E    'keyboard buffer end offset+1 in BIOS data segment 40h

'Video additional data area, used by INT 10h (used by EGA and newer VidBIOSes)
for i=0x484 to 0x48A : mem.Byte(i)=0 : next 'clear it
mem.Byte(0x484)=24       'Screen rows count-1
mem.Word(0x485)=8        'Rows in character (i.e. char height)
mem.Byte(0x487)=0        'EGA/VGA video control byte (TOCHECK - implementation)
mem.Byte(0x489)=0x81     'VGA/MCGA set modes control (VGA200TXT) (TOCHECK)
mem.Byte(0x48A)=2        'VGA/MCGA display combination index (TOCHECK)

'Disks additional data area
mem.Byte(0x48B)=0        'FDD media control byte (TODO) 
mem.Byte(0x48C)=0        'HDD controller status (TODO) 
mem.Byte(0x48D)=0        'HDD controller error status (TODO) 
mem.Byte(0x48E)=0        'HDD interrupt control (TODO) 
mem.Byte(0x48F)=0        'FDD controller information (TODO) 
mem.Byte(0x490)=0        'FDD_A media state (TODO) 
mem.Byte(0x491)=0        'FDD_B media state (TODO) 
mem.Byte(0x492)=0        'FDD_A media state at operation start (TODO) 
mem.Byte(0x493)=0        'FDD_B media state at operation start (TODO) 
mem.Byte(0x494)=0        'FDD_A current track index (TODO) 
mem.Byte(0x495)=0        'FDD_B current track index (TODO) 

'AT-keyboard additional data area (TODO - must be used by INT 9h, INT 16h)
mem.Word(0x496)=0        'Keyboard status word (TODO)

'Wait flags/counters
mem.Dword(0x498)=0        'Far pointer to user wait flag (TODO)
mem.Dword(0x49C)=0        'User timeout value in microseconds (TODO)
mem.Byte(0x4A0)=0         'RTC wait function flag (TODO)

'LAN-related area
mem.Bytes(0x4A1)=Array(0,0,0,0,0,0,0)  'TODO

'EGA/VGA video additional data area
mem.Dword(0x4A8)=0        'Far pointer to video save pointer table (TODO)
