@NAME = "Орион-128 Z80-Card II"

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

# Монитор
@ROM = "orion/rom/M34zrk.bin"
#@ROM = "orion/rom/M35zrkd.bin"

# Тактовая частота
@FREQUENCY = 3500000


# ROM-диск
@ROM_DISK = "orion/romdisk2.bin"

# Файл настроек
@OPT_FILE = "orion/orion.opt"



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

EmuWindow window
window.caption = @NAME

# Default window size for window.windowStyle = fixed (default = 800, 600)
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.frameScale = bestFit

# 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 = 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

# Square pixels mode when aspectCorrection = no
window.squarePixels = yes


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

platform.helpFile = @HELP_FILE

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

# Fast reset
platform.fastReset = yes
platform.fastResetCpuTicks = 3000000

Ram ram0 = 0x10000
Ram ram1 = 0x10000
Ram ram2 = 0x10000
Ram ram3 = 0x10000

Ram ram4 = 0x10000
Ram ram5 = 0x10000
Ram ram6 = 0x10000
Ram ram7 = 0x10000

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

AddrSpaceMapper modernRam = 16
modernRam.page =  0, &ram0, 0x0000
modernRam.page =  1, &ram0, 0x4000
modernRam.page =  2, &ram0, 0x8000
modernRam.page =  3, &ram0, 0xC000
modernRam.page =  4, &ram1, 0x0000
modernRam.page =  5, &ram1, 0x4000
modernRam.page =  6, &ram1, 0x8000
modernRam.page =  7, &ram1, 0xC000
modernRam.page =  8, &ram2, 0x0000
modernRam.page =  9, &ram2, 0x4000
modernRam.page = 10, &ram2, 0x8000
modernRam.page = 11, &ram2, 0xC000
modernRam.page = 12, &ram3, 0x0000
modernRam.page = 13, &ram3, 0x4000
modernRam.page = 14, &ram3, 0x8000
modernRam.page = 15, &ram3, 0xC000

Rom rom = @ROM, 0x800

Ppi8255 ppi1
Ppi8255 ppi2
Ppi8255 ppi3

OrionColorModeSelector colorModeSelector
OrionMemPageSelector pageSelector
pageSelector.mapper = &ram

Register memPageSelector
Register newMemPageSelector

connect memPageSelector.output[0-2] -> classicRam.page
connect newMemPageSelector.output[0-3] -> modernRam.page

Register soundRegister
Register soundFlipRegister

OrionScreenSelector screenSelector

Fdc1793 fdc

OrionFddControlRegister fddReg
fddReg.fdc = &fdc
fddReg.type = standard

OrionFddControlRegister fddReg08
fddReg08.fdc = &fdc
fddReg08.type = spdos

OrionFddQueryRegister fddQReg
fddQReg.fdc = &fdc

Rtc14818 rtc

# binary format and 24h hours
rtc.pokeCmos = 0x0B, 0x06

# RTC signature
rtc.pokeCmos = 0x0E, 0x52
rtc.pokeCmos = 0x0F, 0x54
rtc.pokeCmos = 0x10, 0x43

AddrSpace fddSpace
fddSpace.range = &fdc, 0x00, 0x03
fddSpace.range = &fddQReg, 0x04, 0x04
fddSpace.range = &fddReg08, 0x08, 0x08
fddSpace.range = &fdc, 0x10, 0x13
fddSpace.range = &fddReg, 0x14, 0x14
fddSpace.range = &fddReg, 0x20, 0x20
fddSpace.range = &rtc, 0x60, 0x61


AddrSpace classicUpperSpace
classicUpperSpace.range = &ram0, 0x000, 0x3FF, 0xF000
classicUpperSpace.range = &ppi1, 0x400, 0x4FF                   
classicUpperSpace.range = &ppi2, 0x500, 0x5FF                   
classicUpperSpace.range = &ppi3, 0x600, 0x6FF                   
classicUpperSpace.range = &fddSpace, 0x700, 0x7FF               
classicUpperSpace.writeRange = &colorModeSelector, 0x800, 0x8FF 
classicUpperSpace.writeRange = &memPageSelector, 0x900, 0x9FF   
classicUpperSpace.writeRange = &screenSelector, 0xA00, 0xAFF    
classicUpperSpace.writeRange = &newMemPageSelector, 0xB00, 0xBFF
classicUpperSpace.writeRange = &soundRegister, 0xE00, 0xEFF     
classicUpperSpace.writeRange = &soundFlipRegister, 0xF00, 0xFFF 
classicUpperSpace.readRange = &rom, 0x800, 0xFFF                

AddrSpaceMapper upperSpace = 2
upperSpace.page = 0, &classicUpperSpace
upperSpace.page = 1, &classicRam, 0xF000

connect newMemPageSelector.output[5] -> upperSpace.page

AddrSpace classicAddrSpace
classicAddrSpace.range = &classicRam, 0x0000, 0xEFFF
classicAddrSpace.range = &upperSpace, 0xF000, 0xFFFF

AddrSpace modernAddrSpace
modernAddrSpace.range = &modernRam, 0x0000, 0x3FFF
modernAddrSpace.range = &classicRam, 0x4000, 0xEFFF, 0x4000
modernAddrSpace.range = &upperSpace, 0xF000, 0xFFFF

AddrSpaceMapper addrSpace = 2
addrSpace.page = 0, &modernAddrSpace
addrSpace.page = 1, &classicAddrSpace

connect newMemPageSelector.output[7] -> addrSpace.page

Psg3910 ay
ay.frequency = 1750000

Psg3910SoundSource psgSoundSource
psgSoundSource.psg = &ay

AddrDecoder ioAddrSpace
ioAddrSpace.writeDevice = &colorModeSelector, 0xFF, 0xF8
ioAddrSpace.writeDevice = &memPageSelector, 0xFF, 0xF9
ioAddrSpace.writeDevice = &screenSelector, 0xFF, 0xFA
ioAddrSpace.writeDevice = &newMemPageSelector, 0xFF, 0xFB
ioAddrSpace.writeDevice = &soundRegister, 0xFF, 0xFE
ioAddrSpace.writeDevice = &soundFlipRegister, 0xFF, 0xFF
ioAddrSpace.readDevice = &ay, 0xC0FF, 0xC0FD
ioAddrSpace.writeDevice = &ay, 0x80FF, 0x80FD, 0x4000, 14

OrionRenderer crtRenderer
crtRenderer.screenMemory = &ram0
crtRenderer.colorMemory = &ram1
crtRenderer.enable480 = yes

screenSelector.crtRenderer = &crtRenderer
colorModeSelector.crtRenderer = &crtRenderer

GeneralSoundSource beepSoundSource

connect ~soundRegister.output[4] -> beepSoundSource.input
connect soundFlipRegister.output -> beepSoundSource.flip

OrionCore core
core.window = &window
core.crtRenderer = &crtRenderer
core.beepSoundSource = &beepSoundSource
core.useInts = yes

connect newMemPageSelector.output[6] -> core.intGate

CpuZ80 cpu

cpu.frequency = @FREQUENCY
cpu.startAddr = 0xF800
cpu.addrSpace = &addrSpace
cpu.16bitPorts = yes
cpu.ioAddrSpace = &ioAddrSpace
cpu.core = &core

GeneralSoundSource tapeSoundSource
tapeSoundSource.muted = yes

RkKbdLayout kbdLayout
RkKeyboard keyboard

RkPpi8255Circuit ppiCircuit
ppiCircuit.rkKeyboard = &keyboard
ppiCircuit.tapeSoundSource = &tapeSoundSource

ppi1.circuit = &ppiCircuit

RkRomDisk romDisk = @ROM_DISK

ppi2.circuit = &romDisk

KbdTapper kbdTapper
kbdTapper.pressTime = 45
kbdTapper.releaseTime = 45
kbdTapper.crDelay = 600



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

OrionFileLoader loader
loader.addrSpace = &ram0
loader.ramDiskAddrSpace = &ram1
loader.filter = "Файлы Ориона (*.rko, *.bru, *.ord, *.ori)|*.rko;*.bru;*.ord;*.RKO;*.BRU;*.ORD;*.ORI|Все файлы (*.*)|*"

FdImage diskA = 80, 2, 5, 1024
diskA.label = A
diskA.filter = "Образы дисков Ориона (*.odi)|*.odi;*.ODI|Все файлы (*.*)|*"
#diskA.fileName = "disk9.odi"

FdImage diskB = 80, 2, 5, 1024
diskB.label = B
diskB.filter = "Образы дисков Ориона (*.odi)|*.odi;*.ODI|Все файлы (*.*)|*"

fdc.fdImage = 0, &diskA
fdc.fdImage = 1, &diskB

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



######## Include Saved Options ########

include @OPT_FILE



######## Configuration Window ########

ConfigTab configTab = @NAME
configTab.optFileName = @OPT_FILE

#window.frameScale
ConfigRadioSelector scaleSelector = &window, frameScale, "Масштабирование"
scaleSelector.addItem = 1x, "1x"
scaleSelector.addItem = 2x, "2x"
scaleSelector.addItem = 3x, "3x"
scaleSelector.addItem = 4x, "4x"
scaleSelector.addItem = 5x, "5x"
scaleSelector.addItem = fit, "Растянуть во все окно"
scaleSelector.addItem = bestFit, "Растянуть с целым коэффициентом"
configTab.addControl = 1, &scaleSelector

#window.windowStyle
ConfigRadioSelector styleSelector = &window, windowStyle, "Размер окна"
styleSelector.addItem = autosize, "Автоматически подстраивать"
styleSelector.addItem = resizable, "Изменяемый пользователем"
styleSelector.addItem = fixed, "Фиксированный"
configTab.addControl = 1, &styleSelector

#window.fieldsMixing
ConfigRadioSelector mixSelector = &window, fieldsMixing, "Смешивание полукадров"
mixSelector.addItem = none, "Выкл."
mixSelector.addItem = scanline, "Имитация линий растра"
configTab.addControl = 2, &mixSelector

#window.smoothing
ConfigRadioSelector smSelector = &window, smoothing, "Сглаживание"
smSelector.addItem = nearest, "Выкл."
smSelector.addItem = bilinear, "Билинейное"
smSelector.addItem = sharp, "Границы пикселей (рекомендуется)"
configTab.addControl = 1, &smSelector

#window.aspectCorrection
ConfigRadioSelector arSelector = &window, aspectCorrection, "Учитывать Aspect Ratio"
arSelector.addItem = no, "Нет (1:1)"
arSelector.addItem = yes, "Оригинальный AR"
configTab.addControl = 2, &arSelector

#window.wideScreen
ConfigRadioSelector wsSelector = &window, wideScreen, "Формат экрана"
wsSelector.addItem = no, "4:3"
wsSelector.addItem = yes, "16:9"
wsSelector.addItem = custom, "Пользовательский"
configTab.addControl = 2, &wsSelector

#crtRenderer.visibleArea
ConfigRadioSelector cropSelector = &crtRenderer, visibleArea, "Отображать реальный бордюр"
cropSelector.addItem = no, "Нет"
cropSelector.addItem = yes, "Да"
configTab.addControl = 1, &cropSelector

#kbdLayout.layout
ConfigRadioSelector laSelector = &kbdLayout, layout, "Раскладка клавиатуры"
laSelector.addItem = qwerty, "Qwerty"
laSelector.addItem = jcuken, "Йцукен"
laSelector.addItem = smart, "«Умная» раскладка"
configTab.addControl = 2, &laSelector

#crtRenderer.colorMode
ConfigRadioSelector colorSelector = &crtRenderer, colorMode, "Режим цвета"
colorSelector.addItem = color, "Цветной"
colorSelector.addItem = mono, "Ч/б"
configTab.addControl = 2, &colorSelector

ifdef USE_TAPE
  ConfigRadioSelector tapeSelector = &tapeGrp, enabled, "Перехват магнитофона"
  tapeSelector.addItem = yes, "Вкл."
  tapeSelector.addItem = no, "Выкл."
  configTab.addControl = 3, &tapeSelector
endif

#platform.codePage
ConfigRadioSelector codePageSelector = &platform, codePage, "Таблица символов отладчика"
codePageSelector.addItem = rk, "РК-86"
codePageSelector.addItem = koi8, "КОИ-8"
configTab.addControl = 3, &codePageSelector

#platform.fastReset
ConfigRadioSelector fastResetSelector = &platform, fastReset, "Быстрый сброс"
fastResetSelector.addItem = yes, "Вкл."
fastResetSelector.addItem = no, "Выкл."
configTab.addControl = 3, &fastResetSelector
