LIST

killsnd equ &093A            ;useful rom routine
SCRN5 EQU &FFA8              ;memory table for rom's VDU handler

ORG &2000
; Non standard MTX autorun ROM header
DB 8,7,6,5,4,3,2,1
DW romID
NOP
NOP
;ROM 4 calls here (&200c)
RET
NOP
NOP
NOP
; Auto entry point
;6845 setup code replaced with TMS9928 setup code
.zmon
LD      A,&7F
OUT     (5),A
IN      A,(5)
AND     &8
RET     Z                       ;if "M" pressed, return to BASIC

; turn ctc off  
ld b,2
.ctc_loop
ld a,3
out (&8),a
out (&9),a
out (&a),a
out (&b),a
djnz ctc_loop

; turn the sound generator off OS doesn't call this until after the autorun rom is detected
call killsnd

; reset the VDP, agian only called after the autorun check
RST &28
DB &42
XOR  A
LD   (SCRN5+3),A
LD   A,&28
LD   (SCRN5+5),A
RST  &10       ; output routine
DB   &4D      ; select VS5 and clear

;all VDU handling after this is in the CPM rom.
;copy the code from the rom into high memory 
ld   SP,&E000
LD   HL,&2000
LD   DE,&E000
LD   BC,&2000
LDIR

;VDU setup step 1, move the name table (register 2) to offset 0000
ld a,0
out (2),A
ld a,&82
out (2),a
;step 2 extend the patern table from 1900-1BFF to 1FFF 
;because the rom is copied we can call high memory routines
ld hl,&1900
call set_read
ld hl,&c000
ld e,3
ld BC,1          ; b=0  c=1
.read_loop
in a,(c)
cpl              ;invert the data, top bit characters are inverted - used for the cursor 
ld (hl),A
inc hl
djnz read_loop
dec E
jr nz,read_loop

ld hl,&1D00
call set_write
ld hl,&c000
ld e,3
ld BC,1          ; b=0  c=1
.write_loop
ld a,(hl)
nop
out (c),A
inc hl
djnz write_loop
dec E
jr nz,write_loop

;step 3 change the colours by updating register 7 - CPM looks reaaly odd white on blue
ld a,&A1
out (2),A
ld a,&87
out (2),a

JP   setup

.romID
DS "B820"
RST &10
DB &84
DS "B820"
RET


END