@NAME = "Микроша"

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

# Тактовые частоты
@CPU_FREQUENCY = 1777777   # ВМ80, ВИ53, ВТ57
@CRT_FREQUENCY = 1333333   # ВГ75

# Основное ПЗУ и адреса перехвата
@ROM = "mikrosha/mikrosha.rom"
@F806_ADDR = 0xfc0d
@F80C_ADDR = 0xfcab
@F803_ADDR = 0xfed0

# Знакогенератор
@SYM_GEN  = "mikrosha/sgm.bin"       

# Шрифты 8x8, 8x12, 8x16
@FONT     = "mikrosha/fontm.bin"

# использовать контроллер НГМД
define USE_FDC

# RK-DOS
@DOS = "mikrosha/dos29.bin"

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


# Внешнее ПЗУ для wx/SDL-версии (NONE (default), ROMDISK)
#@CFG_EXT_STORAGE = ROMDISK
#@CFG_ROMDISK_FILE = "mikrosha/extrom.bin"


ifndef CFG_EXT_STORAGE
  @CFG_EXT_STORAGE = NONE
endif


if CFG_EXT_STORAGE == ROMDISK
  @EXT_ROM = @CFG_ROMDISK_FILE
endif


# Переопределить некоторые параметры, если Криста
ifdef KRISTA
  @NAME      = "Криста"
  @ROM       = "mikrosha/krista.rom"
  @SYM_GEN   = "mikrosha/sgk.bin"
  @FONT      = "mikrosha/fontk.bin"
  @HELP_FILE = "mikrosha/krista.html"
endif


######## 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, 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 = 0x8000

Rom rom = @ROM, 0x800

Ppi8255 ppi1
Ppi8255 ppi2

Dma8257 dma
dma.frequency = @CPU_FREQUENCY

Crt8275 crt
crt.frequency = @CRT_FREQUENCY
crt.dma = &dma, 2

ifdef KRISTA
  crt.lpenCorrection = 8
endif

Pit8253 pit
pit.frequency = @CPU_FREQUENCY

MikroshaPit8253SoundSource pitSoundSource
pitSoundSource.pit = &pit

MikroshaRenderer crtRenderer
crtRenderer.font = @SYM_GEN
crtRenderer.altFont = @FONT
crtRenderer.altRenderer = no
crtRenderer.visibleArea = no
crtRenderer.crt = &crt

# На "Кристе" сместить экран немного вправо, чтобы полностью помещалась рабочая область 64*25
ifdef KRISTA
  crtRenderer.visibleOffsetX = 13
endif

MikroshaCore core
core.window = &window
core.crtRenderer = &crtRenderer
crt.core = &core

Cpu8080 cpu

ifdef USE_FDC
  Rom fdcRom = @DOS, 0x1000

  Ppi8255 fdcPpi

  RkFddRegister fddReg
  RkFddController fdc
  fdc.fddRegister = &fddReg
  fdcPpi.circuit = &fdc

  AddrSpace fdcAddrSpace
  fdcAddrSpace.range = &fdcPpi, 0, 3
  fdcAddrSpace.range = &fddReg, 4, 4
  fdcAddrSpace.addrMask = 7
endif

AddrSpace addrSpace
addrSpace.range = &ram, 0, 0x7FFF
addrSpace.range = &ppi1, 0xC000, 0xC7FF
addrSpace.range = &ppi2, 0xC800, 0xCFFF
addrSpace.range = &crt, 0xD000, 0xD7FF
addrSpace.range = &pit, 0xD800, 0xDFFF


ifdef EXT_ROM
  Rom extRom = @EXT_ROM, 0x4000
  addrSpace.range = &extRom, 0x8000, 0xBFFF
else
  Cpu8080StatusWordSpace null = &cpu
  addrSpace.range = &null, 0x8000, 0xBFFF
endif

ifdef USE_FDC
  addrSpace.readRange = &fdcRom, 0xE000, 0xEFFF
  addrSpace.range = &fdcAddrSpace, 0xF000, 0xF7FF
else
  addrSpace.range = &null, 0xE000, 0xF7FF
endif

addrSpace.writeRange = &dma, 0xF800, 0xFFFF
addrSpace.readRange = &rom, 0xF800, 0xFFFF

cpu.frequency = @CPU_FREQUENCY
cpu.startAddr = 0xF800
cpu.addrSpace = &addrSpace
cpu.core = &core

dma.addrSpace = &addrSpace
dma.cpu = &cpu

GeneralSoundSource tapeSoundSource
#tapeSoundSource.muted = yes

ifndef KRISTA
  RkKbdLayout kbdLayout
else
  KristaKbdLayout kbdLayout
endif

kbdLayout.layout = smart

RkKeyboard keyboard
keyboard.matrix = "mikrosha"

MikroshaPpi8255Circuit ppiCircuit
ppiCircuit.rkKeyboard = &keyboard
ppiCircuit.pit = &pit
ppiCircuit.tapeSoundSource = &tapeSoundSource
ppiCircuit.pitSoundSource = &pitSoundSource

ppi1.circuit = &ppiCircuit

MikroshaPpi2Circuit ppiCircuit2
ppiCircuit2.crtRenderer = &crtRenderer
ppi2.circuit = &ppiCircuit2

KbdTapper kbdTapper
kbdTapper.pressTime = 70
kbdTapper.releaseTime = 70
kbdTapper.crDelay = 500



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

RkFileLoader loader
loader.addrSpace = &addrSpace
loader.filter = "Файлы Микроши (*.rkm)|*.rkm;*.RKM|Файлы RK-совместимых ПК (*.rk*)|*.rk;*.rk?;*.RK;*.RK?|Все файлы (*.*)|*"

TapeRedirector tapeInFile
tapeInFile.mode = "r"
tapeInFile.filter = "Файлы Микроши (*.rkm)|*.rkm;*.RKM|Файлы RK-совместимых ПК (*.rk*)|*.rk;*.rk?;*.RK;*.RK?|Все файлы (*.*)|*"

TapeRedirector tapeOutFile
tapeOutFile.mode = "w"
tapeOutFile.filter = "Файлы Микроши (*.rkm)|*.rkm|Файлы RK-совместимых ПК (*.rk)|*.rk|Все файлы (*.*)|*"

RkTapeOutHook tapeOutHook = @F80C_ADDR
tapeOutHook.tapeRedirector = &tapeOutFile
cpu.addHook = &tapeOutHook

# Подавить перехват при геренации звукового сигнала при сбросе
ifdef KRISTA
  tapeOutHook.suspendAfterResetForMs = 100
endif

RkTapeInHook tapeInHook = @F806_ADDR
tapeInHook.tapeRedirector = &tapeInFile
cpu.addHook = &tapeInHook

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

EmuObjectGroup tapeGrp
tapeGrp.addItem = &tapeOutHook
tapeGrp.addItem = &tapeInHook
tapeGrp.addItem = &closeFileHook
#tapeGrp.enabled = no

ifdef USE_FDC
  FdImage diskA = 80, 2, 1, 3125
  diskA.label = A
  diskA.readOnly = yes
  diskA.filter = "Образы дисков РК-86 (*.rkdisk, *.rdi)|*.rkdisk;*.rdi;*.RDI|Все файлы (*.*)|*"

  FdImage diskB = 80, 2, 1, 3125
  diskB.label = B
  diskB.filter = "Образы дисков РК-86 (*.rkdisk, *.rdi)|*.rkdisk;*.rdi;*.RDI|Все файлы (*.*)|*"

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


ifdef WX
  include "mikrosha/mikrosha_wx.inc"
endif
