@NAME = "Океан-240.2"


# Файл справки
@HELP_FILE = okean/okean.html

# Тактовые частоты
@CPU_FREQUENCY = 2400000  # CPU
@PIT_FREQUENCY = 1500000  # PIT


# ПЗУ

ifndef CFG_BIOS_VER
  @CFG_BIOS_VER = 6
endif

if CFG_BIOS_VER == 5
  @ROM = "okean/rel5_mon.bin"
  @CPM_ROM = "okean/rel5_cpm.bin"
  @NAME = "Океан-240.2 REL.5 No FDD"
endif

if CFG_BIOS_VER == 6
  @ROM = "okean/rel6_mon.bin"
  @CPM_ROM = "okean/rel6_cpm.bin"
  @NAME = "Океан-240.2 REL.6"
  define FDD
endif

if CFG_BIOS_VER == 7
  @ROM = "okean/rel7_mon.bin"
  @CPM_ROM = "okean/rel7_cpm.bin"
  @NAME = "Океан-240.2 REL.7"
  define FDD
endif

if CFG_BIOS_VER == 7m
  @ROM = "okean/rel7m_mon.bin"
  @CPM_ROM = "okean/rel7m_cpm.bin"
  @NAME = "Океан-240.2 REL.7 (MC7007)"
  define MATRIX_KBD
  define FDD
endif

if CFG_BIOS_VER == 8
  @ROM = "okean/rel8_mon.bin"
  @CPM_ROM = "okean/rel8_cpm.bin"
  @NAME = "Океан-240.2 REL.8"
  define FDD
endif

if CFG_BIOS_VER == 8p
  @ROM = "okean/rel8p_mon.bin"
  @CPM_ROM = "okean/rel8p_cpm.bin"
  @NAME = "Океан-240.2 REL.8' (192K RAM DISK)"
  define FDD
  define RAMDISK_192K
endif


######## Window ########

EmuWindow window
window.caption = @NAME

# Default window size for window.windowStyle = fixed (default = 800, 600)
#window.defaultWindowSize = 768, 512
window.defaultWindowSize = 800, 600

# Window style: autosize, resizable, fixed, fullscreen (default = autosise)
window.windowStyle = autosize
#window.windowStyle = resizable

# Window scaling option: 1x, 2x, 3x, 4x, 5x, fit, bestFit (default = bestFit)
window.frameScale = 2x

# Window fields mixing: none, mix, interlace, scanline (default = none)
#window.fieldsMixing = mix

# Image smoothing (default = sharp)
window.smoothing = sharp

# Aspect correction (default = no)
window.aspectCorrection = yes

# Wide screen (16:9): yes, no, custom (default = no)
window.wideScreen = no

# Screen format for window.wideScreen = custom
window.customScreenFormat = 1.111



######## Platform ########

platform.helpFile = @HELP_FILE

# Code page: rk, koi8 (default = rk)
platform.codePage = koi8

Rom biosRom = @ROM, 0x2000
biosRom.addrMask = 0x1FFF

Rom cpmRom = @CPM_ROM, 0x2000

AddrSpace roms
roms.range = &cpmRom, 0x0000, 0x1FFF
roms.range = &biosRom, 0x2000, 0x3FFF

Ram ram0 = 0x10000
Ram ram1 = 0x10000
Ram ram2 = 0x10000
Ram ram3 = 0x10000
Ram ram4 = 0x10000
Ram ram5 = 0x10000
Ram ram6 = 0x10000
Ram ram7 = 0x10000

# bits 1-3
AddrSpaceMapper rams = 8

rams.page = 0, &ram0
rams.page = 1, &ram1
rams.page = 2, &ram2
rams.page = 3, &ram3
rams.page = 4, &ram4
rams.page = 5, &ram5
rams.page = 6, &ram6
rams.page = 7, &ram7

AddrSpace hiRams
hiRams.range = &rams, 0x0000, 0x7FFF, 0x8000
hiRams.range = &rams, 0x8000, 0xFFFF, 0x8000

AddrSpaceMapper rams2 = 2
rams2.page = 0, &rams
rams2.page = 1, &hiRams

AddrSpace as0
as0.range = &rams2, 0x0000, 0xBFFF
as0.range = &roms,  0xC000, 0xFFFF

#AddrSpace as1
#as1.range = &rams2, 0x0000, 0xffff

AddrSpace as2
as2.range = &biosRom, 0x0000, 0xFFFF

#AddrSpace as3
#as3.range = &biosRom, 0x0000, 0xFFFF

AddrSpaceMapper addrSpace = 4
addrSpace.page = 0, &as0
addrSpace.page = 1, &rams2
addrSpace.page = 2, &as2
addrSpace.page = 3, &as2

OkeanRenderer crtRenderer
crtRenderer.visibleArea = no
crtRenderer.screenMemory = &ram0
crtRenderer.screenMemory2 = &ram1

OkeanCore core
core.window = &window
core.crtRenderer = &crtRenderer

Ppi8255 ppi1
Ppi8255 ppi2
Ppi8255 ppi3

OkeanKbdLayout kbdLayout

ifndef MATRIX_KBD
  OkeanKeyboard keyboard

  connect keyboard.keyCode -> ppi1.portA
  connect ppi1.portC[7] -> keyboard.ack
else
  OkeanMatrixKeyboard keyboard

  connect keyboard.rowData -> ppi1.portA
  connect keyboard.shift -> ppi1.portB[6]
  connect keyboard.ctrl -> ppi1.portB[5]
  connect keyboard.column -> ppi1.portC[0-3]
  connect ppi1.portC[4] -> keyboard.ack
endif

AddrSpace ioAddrSpace

#GeneralSoundSource tapeSoundSource
#connect ppi1.portB[2] -> tapeSoundSource.input

Covox tapeSoundSource = 3
connect ppi3.portC[0-2] -> tapeSoundSource.value

connect crtRenderer.hblank -> ppi1.portB[0]
connect crtRenderer.vblank -> ppi1.portB[1]

Pit8253 pit
pit.frequency = @PIT_FREQUENCY

Pit8253Helper pitHelper
pit.helper = 0, &pitHelper

Pic8259 pic
core.pic = &pic

connect pit.out0 -> pic.irq(4)
connect keyboard.strobe -> pic.irq(1)

GeneralSoundSource beepSoundSource
connect ppi3.portC[3] -> beepSoundSource.input

connect ppi2.portA -> crtRenderer.vscroll
connect ppi2.portB[1-3] -> rams.page
connect ppi2.portB[0] -> rams2.page
connect ppi2.portB[4-5] -> addrSpace.page
connect ppi2.portC -> crtRenderer.hscroll

connect ppi3.portB[0-2] -> crtRenderer.palette
connect ppi3.portB[3-5] -> crtRenderer.bgColor
connect ppi3.portB[6] -> crtRenderer.mode
connect ppi3.portB[7] -> crtRenderer.page

ioAddrSpace.range = &ppi1, 0x40, 0x5f
ioAddrSpace.range = &pit, 0x60, 0x7f
ioAddrSpace.range = &pic, 0x80, 0x9f
ioAddrSpace.range = &ppi2, 0xc0, 0xdf
ioAddrSpace.range = &ppi3, 0xe0, 0xff

ifdef FDD
  Fdc1793 fdc
  ioAddrSpace.range = &fdc, 0x20, 0x23

  OkeanFddRegisters fddRegisters
  fddRegisters.fdc = &fdc
  ioAddrSpace.range = &fddRegisters, 0x24, 0x25
endif

Cpu8080 cpu
cpu.frequency = @CPU_FREQUENCY
cpu.startAddr = 0x0000
cpu.addrSpace = &addrSpace
cpu.ioAddrSpace = &ioAddrSpace
cpu.core = &core
pic.cpu = &cpu


ifndef RAMDISK_192K
  RamDisk ramDisk = 1, 0x10000
  ramDisk.page = 0, &ram1
  ramDisk.filter = "Файлы RAM-диска Океана (*.ramdisk)|*.ramdisk|Все файлы (*.*)|*"
else
  RamDisk ramDisk = 3, 0x10000
  ramDisk.page = 0, &ram1
  ramDisk.page = 1, &ram2
  ramDisk.page = 2, &ram3
  ramDisk.filter = "Файлы RAM-диска Океана (*.ramdisk)|*.ramdisk|Все файлы (*.*)|*"
endif


######## File I/O ########

OkeanFileLoader loader
loader.addrSpace = &addrSpace
loader.filter = "Файлы Океана (*.ok;*.com)|*.ok;*.OK;*.com;*.COM|HEX-файлы (*.hex)|*.hex;*.HEX|Все файлы (*.*)|*"
loader.skipTicks = 2500000

ifdef FDD
  FdImage diskB = 80, 2, 9, 512
  diskB.label = B
  diskB.filter = "Образы дисков Океана (*.okd)|*.okd;*.OKD|Все файлы (*.*)|*"

  FdImage diskC = 80, 2, 9, 512
  diskC.label = C
  diskC.filter = "Образы дисков Океана (*.okd)|*.okd;*.OKD|Все файлы (*.*)|*"

  fdc.fdImage = 0, &diskB
  fdc.fdImage = 1, &diskC
endif
