main.CPUClock=3500KHz
main.Caption="ZX Spectrum 128 + TR-DOS"
main.ff.speed=20
main.ff.keymask[9]=1

cpu : z80 {
  debug=cas
  debug=trap3Dxx
  mem=mm
  int[FF]=vid.irq
  port[00-FF]=portmap
}

portmap : MemMap {
  map[0][00-FF]=normalports
  map[1][00-FF]=trdosports
  page=trap3Dxx.output
}

normalports : MemMap2 {
  map[FE]=sys.data[0]
  map[FD]=portFD
}

trdosports : MemMap2 {
  map[1F]=dsk.data[0]
  map[3F]=dsk.data[1]
  map[5F]=dsk.data[2]
  map[7F]=dsk.data[3]
  map[FF]=sys.data[2]
}

portFD : MemMap2 {
  offset=cpu.port.msb
  map[7E-7F]=sys.data[1]
  map[BE-BF].wo=AYdata
  map[FE-FF].ro=AYdata
  map[FE-FF].wo=TSreg
  map[BE-BF].offset=0
  map[FE-FF].offset=0
}

TSreg : Register {
  write=TSmx.offset
  write[0-3]=TSmx
}

TSmx : MemMap2 {
  map[00-FB].offset=0
  map[00-FB]=AYreg
  map[FC-FF]=TSbit
}

TSbit : Register {
  write[0]=AYreg.offset
  write[0]=AYdata.offset
}

AYreg : MemMap2 {
  map[0]=AY.regno
  map[1]=AY2.regno
}

AYdata : MemMap2 {
  map[0]=AY.data
  map[1]=AY2.data
}

r128 : Memory {
  rom="ZX\qc_3_05.rom"
}

rsos : Memory {
  rom="ZX\2006.rom"
}

rsys : Memory {
  rom="ZX\glukpen.rom"
}

rdos : Memory {
  rom="ZX\dos6_10e.rom"
}

mem1 : Memory {
  size=20000
  frame[0].size=4000
  frame[0].page=sys.portB[0-2]
}

mm : MemMap {
  page[0]=sys.portB[4]
  page[1]=trap3Dxx.output
  map[0][0000-3FFF]=r128
  map[0][4000-7FFF]=mem1[14000]
  map[0][8000-BFFF]=mem1[08000]
  map[0][C000-FFFF]=mem1.frame[0]
  map[1][0000-3FFF]=rsos
  map[1][4000-7FFF]=mem1[14000]
  map[1][8000-BFFF]=mem1[08000]
  map[1][C000-FFFF]=mem1.frame[0]
  map[2][0000-3FFF]=rsys
  map[2][4000-7FFF]=mem1[14000]
  map[2][8000-BFFF]=mem1[08000]
  map[2][C000-FFFF]=mem1.frame[0]
  map[3][0000-3FFF]=rdos
  map[3][4000-7FFF]=mem1[14000]
  map[3][8000-BFFF]=mem1[08000]
  map[3][C000-FFFF]=mem1.frame[0]
  initpage=2
}

sys : K580ww55 {
}

kbd : Keyboard {
  layout="ZX\layout.kbd"
  ~mask=cpu.port.msb
  ~data=sys.portA
  irqkey=49
  irq=cpu.nmi
}

vid : zxspec-video {
  mem[0]=mem1[14000]
  mem[1]=mem1[1C000]
  border=sys.portA[0-2]
  page=sys.portB[3]
}

cas : tape-recorder {
  playback=sys.portA[6]
  record=sys.portA[3]
  filter="ZX Spectrum files (*.tzx;*.tap)|*.tzx;*.tap"
  ext="tzx"
  iproc[0562-05E0]=zx
  oproc[04C2-053E]=zx
}

AY : AY-3-8910 {
  freq=1773400
  input=sys.portA[4]
  mono=7,12,7
  left=11,12,3
  right=3,12,11
}

AY2 : AY-3-8910 {
  freq=1773400
  mono=7,12,7
  left=11,12,3
  right=3,12,11
}

trap3Dxx : exec-sensor {
  range[3D01-3DFC]=1
  range[4000-FFFF]=0
}

dsk : KR1818wg93 {
  drive=sys.portC[0-1]
  side[0]=sys.portC[4]
  drq=sys.portC[6]
  irq=sys.portC[7]
  drive.count=4
  drive[0].tooltip="A:"
  drive[1].tooltip="B:"
  drive[2].tooltip="C:"
  drive[3].tooltip="D:"
  ext="trd;*.scl"
}
