@NAME = "Партнер-01.01"


# For SDL build: specify 3, 2, 1 or 1.03
#define CFG_ROMSET_VER 3

ifndef CFG_ROMSET_VER
  @CFG_ROMSET_VER = 3
endif

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

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

# Содержимое ПЗУ
# ПЗУ 1 (Basic)
# ПЗУ 2 (Assembler + Monitor)

if CFG_ROMSET_VER == 3
  @ROM1     = "partner/romp1.bin"
  @ROM2     = "partner/romp2.bin"
  define MSX
endif

if CFG_ROMSET_VER == 2
  @ROM1     = "partner/rompv12_1.bin"
  @ROM2     = "partner/rompv2_2.bin"
  define MSX
endif

if CFG_ROMSET_VER == 1
  @ROM1     = "partner/rompv12_1.bin"
  @ROM2     = "partner/rompv1_2.bin"
endif

if CFG_ROMSET_VER == 1.03
  @ROM1     = "partner/rompv103_1.bin"
  @ROM2     = "partner/rompv103_2.bin"
endif

# Знакогенератор
if CFG_ROMSET_VER != V103
  @SYM_GEN  = "partner/sgp.bin"
else
  @SYM_GEN  = "partner/sgp103.bin"
endif

@MCPG_ROM = "partner/mcpgrom.bin"   # ПЗУ МЦПГ
@FDC_ROM  = "partner/fddrom.bin"    # ПЗУ контроллера НГМД
@SD_ROM   = "partner/sdrom.bin"     # ПЗУ SD-контроллера
@D14      = "partner/d14.bin"       # ПЗУ распределения памяти

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

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


# Директория SD-карты
ifndef CFG_SD_DIR
  @CFG_SD_DIR = "partner/sdcard/"
endif


# Точки перехвата
@F803 = 0xfd7b
@F806 = 0xfba2
@F80C = 0xfc55


# переопределенире точек перехвата для В.1
if CFG_ROMSET_VER == 1
  @F803 = 0xfd43
  @F806 = 0xfb6a
  @F80C = 0xfc1d
endif

# переопределенире точек перехвата для В.103
if CFG_ROMSET_VER == 1.03
  @F803 = 0xfd34
  @F806 = 0xfb6a
  @F80C = 0xfc0e
endif

ifdef MSX
  @F83F = 0xf4c9
  @F842 = 0xf4dc
  @F84B = 0xf53e
  @F84E = 0xf548
  @LHOUT = 0xf4fd
  @LHIN = 0xf4ea
endif

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

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

Ram ram1 = 0x8000
ram1.addrMask = 0x7fff

Ram ram2 = 0x8000
ram2.addrMask = 0x7fff

Rom rom1 = @ROM1, 0x2000
rom1.addrMask = 0x1fff

Rom rom2 = @ROM2, 0x2000
rom2.addrMask = 0x1fff

Rom mcpgRom = @MCPG_ROM, 0x800
mcpgRom.addrMask = 0x7ff

Rom fdcRom = @FDC_ROM, 0x800
fdcRom.addrMask = 0x7ff

Rom sdRom = @SD_ROM, 0x800
sdRom.addrMask = 0x7ff

Ram mcpgRam = 0x1000
mcpgRam.addrMask = 0xfff

Ppi8255 ppi

Dma8257 dma
dma.frequency = @CRT_FREQUENCY

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

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

PartnerMcpgRenderer mcpgCrtRenderer
mcpgCrtRenderer.crt = &crt
mcpgCrtRenderer.ram = &mcpgRam

crtRenderer.secondaryRenderer = &mcpgCrtRenderer

PartnerRamUpdater ramUpdater
ramUpdater.frequency = @CPU_FREQUENCY
ramUpdater.dma = &dma, 3

AddrSpaceMapper romWindow = 4
romWindow.page = 0, &sdRom
romWindow.page = 1, &fdcRom
romWindow.page = 2, &mcpgRom

AddrSpaceMapper ramWindow = 4
ramWindow.page = 2, &mcpgRam

PartnerMcpgSelector mcpgSelector

Pit8253 pit
pit.frequency = @CPU_FREQUENCY
Pit8253SoundSource sndSource
sndSource.polarity = negative
sndSource.pit = &pit

AddrSpaceShifter shiftedPit = &pit, 2

AddrSpace devMcpg
devMcpg.range = &mcpgSelector, 0, 0xFF
devMcpg.range = &shiftedPit, 0x100, 0x1FF

Fdc1793 fdc
fdc.dma = &dma, 0

PartnerFddControlRegister fddReg
fddReg.fdc = &fdc

AddrSpace devFdc
devFdc.range = &fdc, 0, 0xFF
devFdc.range = &fddReg, 0x100, 0x1FF

Ppi8255 sdPpi
RkSdController sdCard = @CFG_SD_DIR
sdPpi.circuit = &sdCard

AddrSpace devSd
devSd.range = &sdPpi, 0, 0xFF

AddrSpaceMapper devWindow = 4
devWindow.page = 0, &devSd
devWindow.page = 1, &devFdc
devWindow.page = 2, &devMcpg

PartnerModuleSelector moduleSelector
moduleSelector.mappers = &romWindow, &ramWindow, &devWindow

PartnerAddrSpace addrSpace = @D14

PartnerAddrSpaceSelector addrSpaceSelector
addrSpaceSelector.addrSpace = &addrSpace

AddrSpace slot
slot.range = &crt, 0x000, 0x0FF
slot.range = &ppi, 0x100, 0x1FF
slot.range = &addrSpaceSelector, 0x200, 0x2FF
slot.range = &dma, 0x300, 0x3FF
slot.range = &devWindow, 0x400, 0x5FF
#slot.range = &devMcpg, 0x400, 0x5FF
slot.range = &moduleSelector, 0x600, 0x7FF
slot.addrMask = 0x7FF

addrSpace.memBlock = 0, &romWindow
addrSpace.memBlock = 2, &ramWindow
addrSpace.memBlock = 3, &rom2
addrSpace.memBlock = 4, &rom1
addrSpace.memBlock = 5, &ram1
addrSpace.memBlock = 6, &ram2
addrSpace.memBlock = 7, &slot

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

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

RkKbdLayout kbdLayout
kbdLayout.layout = smart

RkKeyboard keyboard
keyboard.matrix = "partner"

GeneralSoundSource beepSoundSource
GeneralSoundSource tapeSoundSource
#tapeSoundSource.muted = yes

PartnerCore core
core.window = &window
core.cpu = &cpu
core.crtRenderer = &crtRenderer
core.mcpgCrtRenderer = &mcpgCrtRenderer
core.mcpgSelector = &mcpgSelector
core.beepSoundSource = &beepSoundSource

crt.core = &core
cpu.core = &core


PartnerPpi8255Circuit ppiCircuit
ppiCircuit.core = &core
ppiCircuit.rkKeyboard = &keyboard
ppiCircuit.tapeSoundSource = &tapeSoundSource

ppi.circuit = &ppiCircuit

AddrSpace loaderAddrSpace
loaderAddrSpace.range = &ram1, 0x0000, 0x7fff
loaderAddrSpace.range = &ram2, 0x8000, 0xffff

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


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

RkFileLoader loader
loader.addrSpace = &loaderAddrSpace
loader.filter = "Файлы Партнера (*.rkp)|*.rkp;*.RKP|Файлы RK-совместимых ПК (*.rk?)|*.rk;*.rk?;*.RK;*.RK?|Все файлы (*.*)|*"

TapeRedirector tapeInFile
tapeInFile.mode = "r"
tapeInFile.filter = "Файлы Партнера (*.rkp)|*.rkp;*.RKP|Файлы RK-совместимых ПК (*.rk?)|*.rk;*.rk?;*.RK;*.RK?|Файлы BSM (*.bsm)|*.bsm;*.BSM|Файлы EDM (*.edm)|*.edm;*.EDM|Все файлы (*.*)|*"
#tapeInFile.fileName = "example.rkp"

TapeRedirector tapeOutFile
tapeOutFile.mode = "w"
tapeOutFile.filter = "Файлы Партнера (*.rkp)|*.rkp|Файлы RK-совместимых ПК (*.rk)|*.rk|Файлы BSM (*.bsm)|*.bsm|Файлы EDM (*.edm)|*.edm|Все файлы (*.*)|*"


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

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


FdImage diskA = 80, 2, 5, 1024
diskA.label = A
diskA.filter = "Образы дисков Партнера (*.cpm)|*.cpm;*.CPM|Все файлы (*.*)|*"
diskA.readOnly = yes
#diskA.fileName = "partner/disk2.cpm"

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

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

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

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

ifdef MSX
  MsxTapeOutHook msxTapeOutHook = @F84E
  msxTapeOutHook.tapeRedirector = &msxTapeOutFile
  cpu.addHook = &msxTapeOutHook

  MsxTapeOutHeaderHook msxTapeOutShortHeaderHook = @F842
  msxTapeOutShortHeaderHook.tapeRedirector = &msxTapeOutFile
  cpu.addHook = &msxTapeOutShortHeaderHook

  MsxTapeOutHeaderHook msxTapeOutLongHeaderHook = @LHOUT
  msxTapeOutLongHeaderHook.tapeRedirector = &msxTapeOutFile
  cpu.addHook = &msxTapeOutLongHeaderHook

  MsxTapeInHook msxTapeInHook = @F84B
  msxTapeInHook.tapeRedirector = &msxTapeInFile
  cpu.addHook = &msxTapeInHook

  MsxTapeInHeaderHook msxTapeInShortHeaderHook = @F83F
  msxTapeInShortHeaderHook.tapeRedirector = &msxTapeInFile
  cpu.addHook = &msxTapeInShortHeaderHook

  MsxTapeInHeaderHook msxTapeInLongHeaderHook = @LHIN
  msxTapeInLongHeaderHook.tapeRedirector = &msxTapeInFile
  cpu.addHook = &msxTapeInLongHeaderHook

CloseFileHook closeFileHook = @F803
closeFileHook.addTapeRedirector = &tapeInFile
closeFileHook.addTapeRedirector = &tapeOutFile
ifdef MSX
  closeFileHook.addTapeRedirector = &msxTapeInFile
  closeFileHook.addTapeRedirector = &msxTapeOutFile
endif
cpu.addHook = &closeFileHook

EmuObjectGroup tapeGrp
tapeGrp.addItem = &tapeOutHook
tapeGrp.addItem = &tapeInHook
ifdef MSX
  tapeGrp.addItem = &msxTapeOutHook
  tapeGrp.addItem = &msxTapeOutShortHeaderHook
  tapeGrp.addItem = &msxTapeOutLongHeaderHook
  tapeGrp.addItem = &msxTapeInHook
  tapeGrp.addItem = &msxTapeInHook
  tapeGrp.addItem = &msxTapeInShortHeaderHook
  tapeGrp.addItem = &msxTapeInLongHeaderHook
endif
tapeGrp.addItem = &closeFileHook
#tapeGrp.enabled = no



######## 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 = mix, "Вкл."
mixSelector.addItem = average, "Усреднять (старый метод)"
mixSelector.addItem = interlace, "Чередование"
mixSelector.addItem = scanline, "Имитация линий растра"
configTab.addControl = 1, &mixSelector

#window.smoothing
ConfigRadioSelector smSelector = &window, smoothing, "Сглаживание"
smSelector.addItem = nearest, "Выкл."
smSelector.addItem = bilinear, "Билинейное"
smSelector.addItem = sharp, "Границы пикселей (рекомендуется)"
configTab.addControl = 2, &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 = 2, &cropSelector

#crtRenderer.altRenderer
ConfigRadioSelector rendSelector = &crtRenderer, altRenderer, "Шрифт ВГ8275"
rendSelector.addItem = no, "Оригинальный шрифт"
rendSelector.addItem = yes, "8×16 / 8×12 / 8×8"
configTab.addControl = 2, &rendSelector

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

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

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