'******************************************************************************
'* 
'* INIT OF SEGA MASTER SYSTEM (Video game console by Sega, 1986-199x)
'*
'* Note: - This script always executed while emulation starting and then 
'*         "used" by other emulation scripts (to provide access to CPU etc.)
'*
'******************************************************************************

? "[INIT] Started emulation of Sega Master System"

'Configuring memory space and loading ROM to it 
dim rom as object=emuDrives.ROM(0) 'ROM drive
if not rom.Ready then ErrorMsg("Can not start without ROM image in slot!")
dim hdr_size as integer=(rom.Size and 0x3FFF) 'header size (if exists)
if (hdr_size>0) and (hdr_size<>512) then ErrorMsg("Unknown ROM image format!")
rom.Latched=true : rom.Detected=true : rom.Accessed=true
mem.Size=64*1024+rom.Size-hdr_size : mem.Limit=0xFFFF '64 Kb of memory
mem.Pos=0x10000 : rom.Pos=hdr_size : mem.Copy(rom.Object)  'load ROM to memory

'Assembling
public use object CPU_Z80 as CPU 'processor Z80
cpu.Frequency=3579545 '3,58Mhz
cpu.IRM=1 'interrupt processing mode 1
public use object "mboard" as MB : pc.AddDevice(MB) 'motherboard

