'******************************************************************************
'* 
'* INIT OF SEGA GENESIS/MEGADRIVE (Video game console by Sega, 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 Genesis/Megadrive"

'Configuring memory space
mem.Size=16*1024*1024 : mem.Limit=0xFFFFFF '16 Mb of memory space

'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!")
if rom.Size>0x400000 then ErrorMsg("ROM image is too big!")
rom.Latched=true : rom.Detected=true : rom.Accessed=true
mem.Pos=0 : rom.Pos=0 : mem.Copy(rom.Object)  'load ROM to memory

'Processor
public use object CPU_M68000 as CPU 'processor m68000
cpu.Frequency=7670442 '7,67Mhz
mem.Pos=0 'load initial stack pointer (SP) and code start address (PC)
cpu.SP=shl(mem.Byte,24) or shl(mem.Byte,16) or shl(mem.Byte,8) or mem.Byte
cpu.PC=shl(mem.Byte,24) or shl(mem.Byte,16) or shl(mem.Byte,8) or mem.Byte

'Motherboard
public use object "mboard" as MB : pc.AddDevice(MB)

