@NAME = "ПК8020 Корвет"

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

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


# For SDL build: specify 1 or 2
#define CFG_OPTS 3

ifndef CFG_OPTS
  @CFG_OPTS = 2
endif

# Содержимое ПЗУ
if CFG_OPTS == 2
  @ROM1     = "korvet/rom1.bin"
  @ROM2     = "korvet/rom2.bin"
  @ROM3     = "korvet/rom3.bin"
else
  @ROM1     = "korvet/rom11.bin"
  @ROM2     = "korvet/rom12.bin"
  @ROM3     = "korvet/rom13.bin"
endif

# Знакогенератор
@FONT     = "korvet/font.bin"

# Файл с распределением памяти
@MEMMAP   = "korvet/mapper.mem"

# Адрес рабочей станции
@WS_ADDR = 0


ifndef CFG_PPI3
  @CFG_PPI3 = AY
endif


# Hooks
if CFG_OPTS == 2
  @BYTE_OUT   = 0x0DEE
  @HEADER_OUT = 0x0DC7
  @BYTE_IN    = 0x0E9E
  @HEADER_IN  = 0x0E4B
  @KBD_IN     = 0x0AF4
  @KBD_IN_SIG = CD060BCA
else
  @BYTE_OUT   = 0x0CE9
  @HEADER_OUT = 0x0CC3
  @BYTE_IN    = 0x0D9C
  @HEADER_IN  = 0x0D46
  @KBD_IN     = 0x0A39
  @KBD_IN_SIG = CD400ACA
endif
@BYTE_OUT_SIG   = F52A66F7
@HEADER_OUT_SIG = F53E0432
@BYTE_IN_SIG    = 3A6AF757
@HEADER_IN_SIG  = F33E0432


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

EmuWindow window
window.caption = @NAME

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

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

# Window fullscreen mode: yes, no (default = no)
window.fullscreen = no

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

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

# Image smoothing / post-processing: nearest, bilinear, sharp, custom (default = sharp)
window.smoothing = sharp

# Custom image shader: "shader name" or none (default = none)
#window.shader = crt-hyllian

# Convert image to grayscale
#window.desaturate = yes

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

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

# Gray window background (default: no)
#window.grayBackground = yes

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



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

platform.helpFile = @HELP_FILE

# Fast reset
platform.fastReset = yes
if CFG_OPTS == 2
  platform.fastResetCpuTicks = 23500000
else
  platform.fastResetCpuTicks = 27000000
endif

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

Ram ram = 0x10000

Rom rom1 = @ROM1, 0x2000
Rom rom2 = @ROM2, 0x2000
Rom rom3 = @ROM3, 0x2000

rom1.addrMask = 0x1FFF
rom2.addrMask = 0x1FFF
rom3.addrMask = 0x1FFF

KorvetGraphicsAdapter graphicsAdapter

KorvetTextAdapter textAdapter

KorvetRenderer crtRenderer
crtRenderer.font = @FONT
crtRenderer.graphicsAdapter = &graphicsAdapter
crtRenderer.textAdapter = &textAdapter
crtRenderer.visibleArea = yes

KorvetColorRegister colorReg
colorReg.graphicsAdapter = &graphicsAdapter

KorvetLutRegister lutReg
lutReg.crtRenderer = &crtRenderer

KorvetAddrSpaceSelector addrSpaceSelector

AddrSpace regs
regs.addrMask = 0xFF
regs.range = &addrSpaceSelector, 0x7F, 0x7F
regs.range = &colorReg, 0xBF, 0xBF
regs.range = &lutReg, 0xFB, 0xFB

Ppi8255 ppi1
Ppi8255 ppi2
Ppi8255 ppi3

KorvetFddMotor motor

KorvetPpi8255Circuit ppiCircuit
ppiCircuit.graphicsAdapter = &graphicsAdapter
ppiCircuit.textAdapter = &textAdapter
ppiCircuit.crtRenderer = &crtRenderer
ppiCircuit.fddMotor = &motor
ppiCircuit.addr = WS_ADDR
ppi1.circuit = &ppiCircuit

Covox tapeSoundSource = 4

Pit8253 pit
pit.frequency = @PIT_FREQUENCY

KorvetPit8253SoundSource pitSoundSource
pitSoundSource.pit = &pit

KorvetPpi8255Circuit2 ppiCircuit2
ppiCircuit2.covox = &tapeSoundSource
ppiCircuit2.pitSoundSource = &pitSoundSource
ppi2.circuit = &ppiCircuit2


if CFG_PPI3 == AY
  Psg3910 ay
  ay.frequency = 1750000
  KorvetPpiPsgAdapter psgAdapter
  psgAdapter.psg = &ay
  ppi3.circuit = &psgAdapter

  Psg3910SoundSource psgSoundSource
  psgSoundSource.psg = &ay

  # stereo (def.) | mono
  #psgSoundSource.mixing = stereo

endif


Pic8259 pic

Fdc1793 fdc
ppiCircuit.fdc = &fdc

AddrSpace devs
devs.addrMask = 0x3F
devs.range = &pit, 0x00, 0x03
devs.range = &ppi3, 0x08, 0x0B
devs.range = &fdc, 0x18, 0x1B
devs.range = &pic, 0x28, 0x29
devs.range = &ppi2, 0x30, 0x33
devs.range = &ppi1, 0x38, 0x3B

KorvetKeyboardRegisters kbRegs

KorvetAddrSpace addrSpace = @MEMMAP
addrSpace.page = 0, &ram
addrSpace.page = 1, &rom1
addrSpace.page = 2, &rom2
addrSpace.page = 3, &rom3
addrSpace.page = 4, &kbRegs
addrSpace.page = 5, &devs
addrSpace.page = 6, &regs
addrSpace.page = 7, &textAdapter
addrSpace.page = 8, &graphicsAdapter

addrSpaceSelector.addrSpace = &addrSpace

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

KorvetCpuCycleWaits cpuCycleWaits
cpu.cpuCycleWaits = &cpuCycleWaits

pic.cpu = &cpu

KorvetKbdLayout kbdLayout
kbdLayout.layout = smart

KorvetKeyboard keyboard
kbRegs.keyboard = &keyboard

KorvetCore core
core.window = &window
core.crtRenderer = &crtRenderer
core.ppiCircuit = &ppiCircuit
core.pit = &pit
core.pic = &pic

#crt.core = &core
cpu.core = &core
motor.core = &core
pit.core = 2, &core

KbdTapper kbdTapper
kbdTapper.pressTime = 40
kbdTapper.releaseTime = 40
kbdTapper.crDelay = 100



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

TapeRedirector msxTapeOutFile
msxTapeOutFile.mode = "w"
msxTapeOutFile.filter = "Cas-файлы MSX (*.cas)|*.cas|Все файлы (*.*)|*"

TapeRedirector msxTapeInFile
msxTapeInFile.mode = "r"
msxTapeInFile.filter = "Cas-файлы MSX (*.cas)|*.cas;*.CAS|Все файлы (*.*)|*"

FdImage diskA = 80, 2, 5, 1024
diskA.label = A
diskA.filter = "Образы дисков Корвета (*.kdi, *.dsk)|*.kdi;*.KDI;*.dsk;*.DSK|Все файлы (*.*)|*"
diskA.readOnly = yes
#diskA.fileName = "korvet/disk.kdi"

FdImage diskB = 80, 2, 5, 1024
diskB.label = B
diskB.filter = "Образы дисков Корвета (*.kdi, *.dsk)|*.kdi;*.KDI;*.dsk;*.DSK|Все файлы (*.*)|*"

FdImage diskC = 80, 2, 5, 1024
diskC.label = C
diskC.filter = "Образы дисков Корвета (*.kdi, *.dsk)|*.kdi;*.KDI;*.dsk;*.DSK|Все файлы (*.*)|*"

FdImage diskD = 80, 2, 5, 1024
diskD.label = D
diskD.filter = "Образы дисков Корвета (*.kdi, *.dsk)|*.kdi;*.KDI;*.dsk;*.DSK|Все файлы (*.*)|*"

fdc.fdImage = 0, &diskA
fdc.fdImage = 1, &diskB
fdc.fdImage = 2, &diskC
fdc.fdImage = 3, &diskD

MsxTapeOutHook msxTapeOutHook = @BYTE_OUT
msxTapeOutHook.signature = @BYTE_OUT_SIG
msxTapeOutHook.tapeRedirector = &msxTapeOutFile
cpu.addHook = &msxTapeOutHook

MsxTapeOutHeaderHook msxTapeOutHeaderHook = @HEADER_OUT
msxTapeOutHeaderHook.signature = @HEADER_OUT_SIG
msxTapeOutHeaderHook.tapeRedirector = &msxTapeOutFile
cpu.addHook = &msxTapeOutHeaderHook

MsxTapeInHook msxTapeInHook = @BYTE_IN
msxTapeInHook.signature = @BYTE_IN_SIG
msxTapeInHook.tapeRedirector = &msxTapeInFile
cpu.addHook = &msxTapeInHook

MsxTapeInHeaderHook msxTapeInHeaderHook = @HEADER_IN
msxTapeInHeaderHook.signature = @HEADER_IN_SIG
msxTapeInHeaderHook.tapeRedirector = &msxTapeInFile
cpu.addHook = &msxTapeInHeaderHook

CloseFileHook closeFileHook = @KBD_IN
closeFileHook.signature = @KBD_IN_SIG
closeFileHook.addTapeRedirector = &msxTapeInFile
closeFileHook.addTapeRedirector = &msxTapeOutFile
cpu.addHook = &closeFileHook

EmuObjectGroup tapeGrp
tapeGrp.addItem = &msxTapeOutHook
tapeGrp.addItem = &msxTapeOutHeaderHook
tapeGrp.addItem = &msxTapeInHook
tapeGrp.addItem = &msxTapeInHeaderHook
tapeGrp.addItem = &closeFileHook


ifdef WX
  include "korvet/korvet_wx.inc"
endif
