ifndef NAME
  @NAME = "Специалист"
endif

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

# Основное ПЗУ
ifndef ROM
  @ROM = "spec/spec_m2.rom"
endif

# Адреса перехвата
@C806_ADDR = 0xC377
@C80C_ADDR = 0xC3d0
@C803_ADDR = 0xC337

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

# Тип клавиатуры
ifndef KBD
  @KBD = "original"
endif

ifndef CFG_AY
  @CFG_AY = NONE
endif

if CFG_AY != NONE
  define AY
  if CFG_AY == TS
    define TS
  endif
endif

ifndef CFG_INTS
  @CFG_INTS = OFF
endif

if CFG_INTS == ON
  define INTS
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.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

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

Ram ram = 0x9000
SpecVideoRam videoRam = 0x3000

Rom rom = @ROM, 0x3000

Ppi8255 ppi1
Ppi8255 ppi2

ifdef AY
  Psg3910 ay
  ay.frequency = 1783333

  Psg3910SoundSource psgSoundSource
  psgSoundSource.psg = &ay

  ifdef TS
    Psg3910 ay2
    ay2.frequency = 1783333

    Psg3910SoundSource psgSoundSource2
    psgSoundSource2.psg = &ay2
    psgSoundSource2.polarity = negative

    TurboSound ts
    ts.psg1 = &ay
    ts.psg2 = &ay2
  endif

endif


AddrSpace addrSpace
addrSpace.range = &ram,      0x0000, 0x8FFF
addrSpace.range = &videoRam, 0x9000, 0xBFFF
addrSpace.range = &rom,      0xC000, 0xEFFF
addrSpace.range = &ppi2,     0xF800, 0xFFFF

ifndef SDOS
  ifndef AY
    addrSpace.range = &ppi1,     0xF000, 0xF7FF
  else
    addrSpace.range = &ppi1,     0xF000, 0xF3FF
  endif
endif

ifdef SDOS
  Rom sdos = @SDOS_ROM, 0xA00
  addrSpace.range = &sdos,     0xD000, 0xD9FF

  Ram sdosRam = 0x600
  addrSpace.range = &sdosRam, 0xDA00, 0xDFFF

  SdCard sdCard
  sdCard.imageFile = @CFG_SD_IMG

  SdAdapter sdAdapter
  sdAdapter.type = hwmpvv
  sdAdapter.sdCard = &sdCard

  ifndef AY
    addrSpace.range = &sdAdapter, 0xF000, 0xF7FF
  else
    addrSpace.range = &sdAdapter, 0xF000, 0xF3FF
  endif
endif

ifdef AY
  AddrSpace ayAddrSpace
  ayAddrSpace.addrMask = 0x0003

  ifndef TS
    ayAddrSpace.readRange = &ay, 0, 0, 0
    ayAddrSpace.writeRange = &ay, 1, 1, 0
    ayAddrSpace.range = &ay, 3, 3, 1
  else
    ayAddrSpace.readRange = &ts, 0, 0, 0
    ayAddrSpace.writeRange = &ts, 1, 1, 0
    ayAddrSpace.range = &ts, 3, 3, 1
  endif

  addrSpace.range = &ayAddrSpace, 0xF400, 0xF47F
endif

ifdef SD_CARD
  RkSdController sdCard = @CFG_SD_DIR
  sdCard.model = spec
  ppi1.circuit = &sdCard
endif

SpecRenderer crtRenderer
crtRenderer.screenMemory = &videoRam
crtRenderer.colorMode = 8color

SpecCore core
core.window = &window
core.crtRenderer = &crtRenderer

ifdef INTS
  core.useInts = yes
endif

ifndef Z80
  Cpu8080 cpu
else
  CpuZ80 cpu
endif

cpu.frequency = 2000000
cpu.startAddr = 0xC000
cpu.addrSpace = &addrSpace
cpu.core = &core

GeneralSoundSource tapeSoundSource
tapeSoundSource.muted = yes
GeneralSoundSource beepSoundSource

SpecKbdLayout kbdLayout
SpecKeyboard keyboard
keyboard.matrix = @KBD

SpecPpi8255Circuit ppiCircuit
ppiCircuit.specKeyboard = &keyboard
ppiCircuit.videoRam = &videoRam
ppiCircuit.tapeSoundSource = &tapeSoundSource
ppiCircuit.beepSoundSource = &beepSoundSource

ppi2.circuit = &ppiCircuit



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

SpecFileLoader loader
loader.addrSpace = &addrSpace
loader.filter = "Файлы Специалиста (*.rks)|*.rks;*.RKS|Все файлы (*.*)|*"

TapeRedirector tapeInFile
tapeInFile.mode = "r"
tapeInFile.filter = "Файлы Специалиста (*.rks)|*.rks;*.RKS|Файлы RK-совместимых ПК (*.rk?)|*.rk;*.rk?;*.RK;*.RK?|Все файлы (*.*)|*"

TapeRedirector tapeOutFile
tapeOutFile.mode = "w"
tapeOutFile.filter = "Файлы Специалиста (*.rks)|*.rks|Файлы RK-совместимых ПК (*.rk)|*.rk|Все файлы (*.*)|*"

RkTapeOutHook tapeOutHook = @C80C_ADDR
tapeOutHook.outReg = A
tapeOutHook.tapeRedirector = &tapeOutFile
cpu.addHook = &tapeOutHook

RkTapeInHook tapeInHook = @C806_ADDR
tapeInHook.tapeRedirector = &tapeInFile
#tapeInHook.enabled = no
tapeInHook.suspendAfterResetForMs = 200
cpu.addHook = &tapeInHook

CloseFileHook closeFileHook = @C803_ADDR
closeFileHook.addTapeRedirector = &tapeInFile
closeFileHook.addTapeRedirector = &tapeOutFile
cpu.addHook = &closeFileHook

EmuObjectGroup tapeGrp
tapeGrp.addItem = &tapeOutHook
tapeGrp.addItem = &tapeInHook
tapeGrp.addItem = &closeFileHook
tapeGrp.enabled = yes


ifdef WX
  include "spec/spec_wx.inc"
endif
