Post by hydrophilic on Jun 2, 2014 1:25:08 GMT
Unfortunately the KERNAL doesn't initialize the VDC to use 64K RAM so we need to do it ourselves, otherwise any memory access past $4000 will be messed up.
There was a thread in old C128 Forum about this. Since it is not available now, I was wondering if somebody has working code?
I'm working on my 3rd attempt now (untested yet). I'll show each of the 3 versions in a moment, but first here is some stuff that is common to all of them:
Here is the first version. It runs fine in VICE and from a report by Miro it seems to work on 64K machine. But on my 16K machine it did not work...
Here is the second version. It runs fine in VICE and on my 16K VRAM system, but from a report by Miro it fails on on 64K machine....
And finally my third attempt. It just mixes the two methods. Again it works in VICE. I haven't tested it on real hardware yet.
I'll report back after I test on real hardware, but if somebody has a link or can post known good code, that would be nice!
There was a thread in old C128 Forum about this. Since it is not available now, I was wondering if somebody has working code?
I'm working on my 3rd attempt now (untested yet). I'll show each of the 3 versions in a moment, but first here is some stuff that is common to all of them:
vdcFont = $1c ; VDC register for Font address and RAM size
ReadReg = $cdda ; Editor ROM routine to read VDC register
ReadVram = $cdd8 ; Editor ROM routine to read register $1f (read video RAM)
WriteReg = $cdcc ; Editor ROM routine to write VDC register
WriteVram = $cdca ; Editor ROM routine to write register $1f (write video RAM)
vdcUAH = $12 ; VDC register (high byte) for RAM pointer
vdcRAM = $1f ; VDC register to read/write RAM
VadrSet:
ldx #vdcUAH ;register for V-RAM address
jsr WriteReg ;set address high
inx
lda #0
jmp WriteReg ;set address low
Here is the first version. It runs fine in VICE and from a report by Miro it seems to work on 64K machine. But on my 16K machine it did not work...
;set VDC to use 64K RAM chips
ldx #vdcFont
jsr ReadReg
ora #16 ;bit 4 set to enable 4464 RAM chip
jsr WriteReg
;test RAM size and set flag
lda #$00 ;point to $0000
jsr VadrSet
jsr ReadVram
tay ;save original
lda #$40 ;point to $4000
jsr VadrSet
tya
eor #$ff ;toggle all bits
jsr WriteVram ;we just wrote to $4000, but $0000 should be unchanged...
lda #$00 ;point to $0000
jsr VadrSet
jsr ReadVram
sta index2 ;save value read
lda #$00 ;point to $0000 again because of auto-increment
jsr VadrSet
tya ;original value
jsr WriteVram ;restore original (if it was changed)
eor index2 ;test original (.A) with value read back from $0000
sta only16k ;save result as flag (0=64k, not 0[$ff]=16k)
jsr $c027 ;call Editor ROM to (re)write font into video RAM
Here is the second version. It runs fine in VICE and on my 16K VRAM system, but from a report by Miro it fails on on 64K machine....
;test RAM size and set flag
lda #$00 ;point to $0000
jsr VadrSet
jsr ReadVram
tay ;save original
lda #$40 ;point to $4000
jsr VadrSet
tya
eor #$ff ;toggle all bits
jsr WriteVram ;we just wrote to $4000, but $0000 should be unchanged...
lda #$00 ;point to $0000
jsr VadrSet
jsr ReadVram
sta index2 ;save value read
lda #$00 ;point to $0000 again because of auto-increment
jsr VadrSet
tya ;original value
jsr WriteVram ;restore original (if it was changed)
eor index2 ;test original (.A) with value read back from $0000
sta only16k ;save result as flag (0=64k, not 0[$ff]=16k)
bne Done ;user has 16K
;set VDC to use 64K RAM chips
ldx #vdcFont
jsr ReadReg
ora #16 ;bit 4 set to enable 4464 RAM chip
jsr WriteReg
jsr $c027 ;call Editor ROM to (re)write font into video RAM
Done:
And finally my third attempt. It just mixes the two methods. Again it works in VICE. I haven't tested it on real hardware yet.
;set VDC to use 64K RAM chips
ldx #vdcFont
jsr ReadReg
ora #16 ;bit 4 set to enable 4464 RAM chip
jsr WriteReg
;test RAM size and set flag
lda #$00 ;point to $0000
jsr VadrSet
jsr ReadVram
tay ;save original
lda #$40 ;point to $4000
jsr VadrSet
tya
eor #$ff ;toggle all bits
jsr WriteVram ;we just wrote to $4000, but $0000 should be unchanged...
lda #$00 ;point to $0000
jsr VadrSet
jsr ReadVram
sta index2 ;save value read
lda #$00 ;point to $0000 again because of auto-increment
jsr VadrSet
tya ;original value
jsr WriteVram ;restore original (if it was changed)
eor index2 ;test original (.A) with value read back from $0000
sta only16k ;save result as flag (0=64k, not 0[$ff]=16k)
beq DoFont ;user has 64K
;user has 16K, reset VDC RAM size
ldx #vdcFont
jsr ReadReg
and #255-16 ;bit 4 clear to enable 4416 RAM chip
jsr WriteReg
bmi Done ;always
DoFont: ;user has 64K V-RAM
jsr $c027 ;call Editor ROM to (re)write font into video RAM
Done:
I'll report back after I test on real hardware, but if somebody has a link or can post known good code, that would be nice!