'******************************************************************************
'* 
'* SPC X86/ISA MOTHERBOARD v.1.0 (MOTHERBOARD DEVICE)
'*
'* This m/board with ISA bus and virtual (scripted) BIOS was introduced 
'* in first releases of x86 in SPC :)
'*
'* Supported platform/bus: X86
'* 
'* Version history:
'*  - v.1.0 by WadiM (initial emulation)
'*
'* Adapters: CGA
'*
'****************************************************************************** 

//parent PC/AT chipset implementation
public use object CHIPSET_PCAT

//virtual BIOS
use module BIOS_SPCX86_PATH+"bios"

//motherboard name
DeviceName="SPC X86/ISA Motherboard"
DebugName="SPCAT_ISAMB"

//variables
dim i as integer

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

//VGA video adapter
public use object VID_VGA as VGA : AddDevice(VGA)
for i=0x3C0 to 0x3CF : pc.WritePort(i)=VGA.PORTS : pc.ReadPort(i)=VGA.PORTS : next
for i=0x3D0 to 0x3DF : pc.WritePort(i)=VGA.PORTS : pc.ReadPort(i)=VGA.PORTS : next
pc.WritePort(0x3B4)=VGA.PORTS : pc.ReadPort(0x3B4)=VGA.PORTS
pc.WritePort(0x3B5)=VGA.PORTS : pc.ReadPort(0x3B5)=VGA.PORTS
pc.WritePort(0x3BA)=VGA.PORTS : pc.ReadPort(0x3BA)=VGA.PORTS
pc.WritePort(0x3D4)=VGA.PORTS : pc.ReadPort(0x3D4)=VGA.PORTS
for i=0xA0000/1024 to (0xBFFFF/1024)-1 //VGA video memory
 mem.KBReader(i)=VGA.ReadMemory : mem.KBWriter(i)=VGA.WriteMemory 
next

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

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

 'generate main BIOS
 GenerateBIOS("vga")

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

 'success 
 result=true
end
