|
Post by mirkosoft on Jan 1, 2020 20:26:25 GMT
Hi!
My Q is bit naive - but need to be sure:
Is possible to access whole 128K RAM by Z80 in C128? I know that Z80 CPU address space is 65536 B or 64K. Q refers to MMU. Problem is that MMU config at $FF00 switches to Z80 CPU. But really each change of $FF00 affects active CPU? When we look at system at power-on C128 starts Z80 and by detection switches to 8502 - AFAIK it has nothing with $FF00. Even - no matter of MMU state - what is for Z80 visible? Always is visible physical 1st 64K block?
Even if Z80 is not aimed on 1st physical 64K RAM block, it is much more easy to do with Z80 in CP/M Cartridge...
Thank you for help, replies or comments. Miro
|
|
|
Post by bjonte on Jan 1, 2020 20:58:25 GMT
The MMU config doesn’t switch CPU.
I would guess the MMU would be functional on Z80 as well as 8502 but I don’t have any experience with Z80 programming on the C128 yet.
|
|
|
Post by mirkosoft on Jan 2, 2020 6:13:33 GMT
No, MCR what is $D505 is able to switch CPU, but it is visible only when IO is visible in memory. And it needs RAM config by:
lda #$3e sta $ff00 There is problem.
Miro
|
|
|
Post by bjonte on Jan 2, 2020 21:01:56 GMT
Oh, yes. You are correct, but what is the problem?
|
|
|
Post by mirkosoft on Jan 3, 2020 1:23:03 GMT
Main problem is that it looks that MMU affects only 8502 - I can test it but I have no time now and few weeks will not. If anyone has experience can solve my problem.
Miro
|
|
|
Post by jusalak on Jan 13, 2024 11:15:47 GMT
The MMU is fully configurable using Z80, both RAM banks, common memory settigs etc. work as expected. (Even C64 memory model can be switched to.) Even emulators Z64K and VICE should now fully support MMU configuration using Z80. The following program provides an example. It runs Z80 code in RAM bank 1 to cycle border color and then returns to normal C128 mode operation. The code to set up the Z80 operation is listed below. This is a stub, which needs the Z80 code appended to it. It can be done simply concatenating files. The beginning address for the appended Z80 code is 3800h in this example.
main .org $1c01 .byte $0c,$08,$0a,$00,$9e,$37,$31,$38,$31,$00,$00,$00 lda $ff00 ; pha ; store RAM config to stack sei ; disable interrupts lda $ffee pha lda $ffef pha lda $fff0 pha lda #$3e ; sta $ff00 ; select RAM config for Z80 lda #$c3 ; sta $ffee ; store JP instruction for Z80 mode start lda #<z80code ; sta $ffef ; store lo-byte address lda #>z80code; sta $fff0 ; store hi-byte address lda $d505 ; pha ; store mode to stack lda #$b0 ; sta $d505 ; set Z80 mode - this instruction deactivates 8502 and jumps by Z80 PC to $ffee nop nop pla sta $d505 pla sta $fff0 pla sta $ffef pla sta $ffee pla sta $ff00 cli rts z80code
.byte $F3; di .byte $01 $06 $D5; ld bc,0d506h .byte $3E $06; ld a,06h ;set 8kb common RAM bottom .byte $ED $79; out (c),a .byte $3E $7E; ld a,7eh ;set Bank 1 .byte $01 $00 $D5; ld bc,0d500h .byte $ED $79; out (c),a .byte $01 $00 $02; ld bc,200h ;number of copied bytes, change if needed .byte $11 $00 $38; ld de,3800h ;destination address .byte $21; ld hl ;load hl with .byte <_endofcode ; source address .byte >_endofcode .byte $ED $B0; ldir .byte $C3 $00 $38; jp 3800h
_endofcode The Z80 code appended to the stub in this example is
01c70: ld bc,0d020h ;cycle border color (this code is copied to RAM bank 1) in a,(c) inc a out (c),a jp 01c7bh ;return to bank 0 (common RAM area) 01c7b: ld a,3eh (this code is run from RAM bank 0) ld (0ff00h),a ld bc,0506h ld a,04h out (c),a jp 0ffe0h ;give control back to 8502
The dump for the code is listed below. It can be copied and pasted directly to the MONITOR, using emulator (Z64K or VICE).
>01c00 00 0b 1c 0a 00 9e 37 31 >01c08 38 31 00 00 00 ad 00 ff >01c10 48 78 ad ee ff 48 ad ef >01c18 ff 48 ad f0 ff 48 a9 3e >01c20 8d 00 ff a9 c3 8d ee ff >01c28 a9 53 8d ef ff a9 1c 8d >01c30 f0 ff ad 05 d5 48 a9 b0 >01c38 8d 05 d5 ea ea 68 8d 05 >01c40 d5 68 8d f0 ff 68 8d ef >01c48 ff 68 8d ee ff 68 8d 00 >01c50 ff 58 60 f3 01 06 d5 3e >01c58 06 ed 79 3e 7e 01 00 d5 >01c60 ed 79 01 00 02 11 00 38 >01c68 21 70 1c ed b0 c3 00 38 >01c70 01 20 d0 ed 78 3c ed 79 >01c78 c3 7b 1c 3e 3e 32 00 ff >01c80 01 06 05 3e 04 ed 79 c3 >01c88 e0 ff
The example code can then be saved with the command
S "Z80MMUDEMO",8,1c01,1c8a
To save only the stub, to which append Z80 code to, use command
S "Z80MMUSTUB",8,1c01,1c70
|
|
|
Post by jusalak on Jan 13, 2024 16:19:02 GMT
Even better, the code to give control back to 8502 can be included in the stub (assembled with Win2c64.)
main .org $1c01 .byte $0c,$08,$0a,$00,$9e,$37,$31,$38,$31,$00,$00,$00 lda $ff00 ; pha ; store RAM config to stack sei ; disable interrupts lda $ffee pha lda $ffef pha lda $fff0 pha lda #$3e ; sta $ff00 ; select RAM config for Z80 lda #$c3 ; sta $ffee ; store JP instruction for Z80 mode start lda #<z80code ; sta $ffef ; store lo-byte address lda #>z80code; sta $fff0 ; store hi-byte address lda $d505 ; pha ; store mode to stack lda #$b0 ; sta $d505 ; set Z80 mode - this instruction deactivates 8502 and jumps by Z80 PC to $ffee nop nop pla sta $d505 pla sta $fff0 pla sta $ffef pla sta $ffee pla sta $ff00 cli rts z80code
.byte $F3; di .byte $01 $06 $D5; ld bc,0d506h .byte $3E $06; ld a,06h ;set 8bk common RAM bottom .byte $ED $79; out (c),a .byte $3E $7E; ld a,7eh ;set Bank 1 .byte $01 $00 $D5; ld bc,0d500h .byte $ED $79; out (c),a .byte $01 $00 $02; ld bc,200h ;number of copied bytes .byte $11 $00 $38; ld de,3800h ;destination address .byte $21; ld hl ;load hl with .byte <_endofcode ; source address .byte >_endofcode .byte $ED $B0; ldir .byte $C3 $00 $38; jp 3800h
.byte $3E $3E; ld a,3eh ;set Bank 0 .byte $32 $00 $ff; ld (0ff00),a .byte $3E $06; ld a,06h ; set default 1kb .byte $01 $06 $D5; ld bc,0d506h ; common RAM .byte $ED $79; out (c),a .byte $c3 $e0 $ff; jp 0e0ffh ; give control back to 8502
_endofcode
In this case the return address to give control back is 1c70h. The dumb including color cycling code in Bank 1 is
>01c00 00 0b 1c 0a 00 9e 37 31 >01c08 38 31 00 00 00 ad 00 ff >01c10 48 78 ad ee ff 48 ad ef >01c18 ff 48 ad f0 ff 48 a9 3e >01c20 8d 00 ff a9 c3 8d ee ff >01c28 a9 53 8d ef ff a9 1c 8d >01c30 f0 ff ad 05 d5 48 a9 b0 >01c38 8d 05 d5 ea ea 68 8d 05 >01c40 d5 68 8d f0 ff 68 8d ef >01c48 ff 68 8d ee ff 68 8d 00 >01c50 ff 58 60 f3 01 06 d5 3e >01c58 06 ed 79 3e 7e 01 00 d5 >01c60 ed 79 01 00 02 11 00 38 >01c68 21 7f 1c ed b0 c3 00 38 >01c70 3e 3e 32 00 ff 3e 06 01 >01c78 06 d5 ed 79 c3 e0 ff 01 >01c80 20 d0 ed 78 3c ed 79 c3 >01c88 70 1c
Save with command
S "Z80MMUDEMO",8,1C01,1C8A
And the command to save only the stub is
S "Z80MMUSTUB",8,1C01,1C7F
|
|
|
Post by c128old on Jan 13, 2024 17:09:52 GMT
The following thing is not accessible by z80: Cpu port 0 and 1, ie the caps lock key, datasette things.
Warning with REU: I believe this does not stop the z80, which will read bytes from the bus leading ultimately to bus-contention In short: do REU with 8502
Also tricky: 2mhz mode. This has no effect because ‘go go stop stop’ is believed to become ‘go stop go stop’ (still 2mhz) In 2mhz mode the vic sees the z80 bytes from the bus like it does for 8502.
|
|
|
Post by bjonte on Jan 14, 2024 8:14:33 GMT
Warning with REU: I believe this does not stop the z80, which will read bytes from the bus leading ultimately to bus-contention In short: do REU with 8502 I started thinking it would be possible to fill REU memory in parallel with CPU work then. But I realized that’s done by a copy from main memory but with a memory address that doesn’t increment.
|
|
|
Post by c128old on Jan 14, 2024 17:27:31 GMT
bjonte: consider what VIC sees in 2mhz, the bytes ‘left on the bus by processor’ In theory, z80 would see what the reu ‘left on the bus’ So, I tried start memtransfer on REU while z80 is active and this sometimes works for short transfers where you set z80 to wait (halt) I don’t know if ‘halt’ means get byte and do not inc pc, meaning even halt still loads from mem every 3rd z80 cycle (so every other 1mhz vic cycle) I would need to set a decent scope on the lines. Consider the reu might overpower (more V or so) the z80 attempt to set the bus. Anyway, as far as I can see this wasn’t figured out yet…
|
|