With real C128 hardware Z80 cannot access Char ROM
Versatile Commodore Emulator
Brought to you by:
blackystardust,
gpz
Apparently with Z80 the character ROM at addresses $d000-$dfff is not accessible. With real hardware, what is seen by the Z80 CPU, is RAM at these addresses, even if MMU is configured to ROM $d000-$dfff (CR bit 0). Using Bank 2 made no difference - the Z80 again saw RAM at $d000-$dfff.
This is not currently emulated accurately - x128 and Z64K both see ROM at these addresses.
The following test programs copy from MMU bank 0/2 ROM configuration the $d000-$dfff addresses to $3000-$3fff. The emulators copy the Char ROM. But as said, it does not work on real hardware.
main .org $1c01
.byte $0c,$08,$0a,$00,$9e,$37,$31,$38,$31,$00,$00,$00
lda #$3e
sta $ff00 ;select RAM config
sei ;disable interrupts
lda #$00 ;disable 2 Mhz
sta $d030
lda #$c3
sta $ffee ;store JP instruction for Z80 mode start
lda #<z80code
sta $ffef ;store lo-byte address of Z80 code
lda #>z80code
sta $fff0 ;store hi-byte address of Z80 code
lda #$b0
sta $d505 ;activate Z80
nop
lda #$cf ;restore Z80 RST
sta $ffee
lda #$00
sta $ff00
cli
rts
z80code
.byte $f3 ;di
.byte $3e $01 ;ld a,01h - bank configuration with char ROM, change to 'ld a,81h' to use Bank 2
.byte $32 $00 $ff ;ld (ff00h),a
.byte $01 $00 $10 ;ld bc,1000h
.byte $11 $00 $30 ;ld de,3000h
.byte $21 $00 $d0 ;ld hl,d000h
.byte $ed $b0 ;ldir
.byte $3e $3e ;ld a,3eh - bank to RAM
.byte $32 $00 $ff ;ld (ff00h),a
.byte $c3 $e0 $ff ;JP ffe6h - give control back to 8502
endcode
A test indicated that Char-ROM is accessible to Z80 in C64 mode, but memory management is very different in C64 mode. The inaccessibility of Char-ROM in C128 mode seems to be related to the Z80 BIOS relocation $d000-$dfff >$0000-$0fff. And since the Z80 BIOS is not present in C64 mode, the accessibility of Char-ROM in C64 mode seems understandable.
It is no solution of course, since C64 mode cannot be returned from by program means.
I have a test program for this case.
2024-02-22: changed flag initial value.
Last edit: Jussi Ala-Könni 2024-02-21
Okay fixed this, but before I commit, can you do a test for c64 mode? The only difference is you can't go back to c128 mode, but you can write something to the screen ram to say if it passed or not. We won't be able to use the debug cart, but it will be something anyways.
I already had one at hand, attached.
Fixed in r45099. Also, please incorporate this into your testing suite. I think we can do some automation with the c64 one by comparing screen captures.
r45099 is delayed.
This now works as real hardware. Attached is a small test program, which copies $d000-$dfff to $4000-$4fff. Incorrectly it came from Char ROM, but on real hardware it comes from Bank 0 RAM.
By altering bytes at $1c42-$1c43 the starting address ($dfff, downwards) can be changed, and easily verified that z80 sees other ROM banks, but not Char ROM at $d000-$dfff.
Please add this to your suite of tests. Ideally they should have the debugcart functionality. At some point, we will combine them into a single test suite.
The test I wrote (listed above) already has the debugcart functionality.