'******************************************************************************
'* 
'* TURBO PC/XT ISA MOTHERBOARD v.1.0 (MOTHERBOARD DEVICE)
'*
'* Supported platform/bus: X86
'*
'* Adapters: CGA
'* 
'* Version history:
'*  - v.1.0 by WadiM (initial emulation)
'*
'****************************************************************************** 

//parent PC/XT chipset implementation
public use object CHIPSET_PCXT

//motherboard name
DEVPARAM_NAME="TURBO PC/XT ISA Motherboard"

//motherboard name
DeviceName="TURBO PC/XT ISA Motherboard"
DebugName="TURBOXT_MB"

//variables
dim i as integer

'--------------------------------- Adapters -----------------------------------

//CGA video adapter
public use object VID_CGA as CGA : AddISADevice(CGA,-1,-1)
pc.WritePort(0x3D4)=CGA.CRT_INDEX_PORT : pc.ReadPort(0x3D4)=CGA.CRT_INDEX_PORT
pc.WritePort(0x3D5)=CGA.CRT_DATA_PORT  : pc.ReadPort(0x3D5)=CGA.CRT_DATA_PORT
pc.WritePort(0x3D8)=CGA.MODE_PORT      : pc.ReadPort(0x3D8)=CGA.MODE_PORT
pc.WritePort(0x3D9)=CGA.COLOR_PORT     : pc.ReadPort(0x3D9)=CGA.COLOR_PORT
pc.WritePort(0x3DB)=CGA.PEN_RESET_PORT : pc.WritePort(0x3DC)=CGA.PEN_SET_PORT
pc.ReadPort(0x3DA)=CGA.STATE_PORT
for i=0xB8000/1024 to (0xC0000/1024)-1 //CGA video memory
 mem.KBReader(i)=CGA.ReadMemory : mem.KBWriter(i)=CGA.WriteMemory 
next

'---------------------------- DEVICE Interface --------------------------------

//Device initialization
protected function DEV_INIT(stream as object,byref EventFreq as integer) as boolean
 dim i as integer, j as integer, s as string
 
 'parent call
 if not DEV_INIT(stream,EventFreq) then exit(false)

 'load ROM BIOS file
 s="bin\pcxt.rom" : mem.Bytes(0x100000-FileSize(s))=ArrayFile(s) 'main BIOS

 'mark non-conventional memory area as read-only 
 for i=0xA0000/1024 to 0xFFFFF/1024 : mem.KBAccess(i)=memReadOnly : next
 'mark CGA memory as read-write 
 for i=0xB8000/1024 to 0xBFFFF/1024 : mem.KBAccess(i)=memReadWrite : next

 'success 
 result=true
end
