Post by jusalak on Jan 20, 2024 19:11:52 GMT
Safeguard to disable FAST mode before entering Z80 code has been added (see thread c-128.freeforums.net/thread/1210/z80-instability-mhz-fast-mode).
main .org $1c01
.byte $0c,$08,$0a,$00,$9e,$37,$31,$38,$31,$00,$00,$00
lda $ff00 ;
pha ; store RAM config to stack
lda #$3e ;
sta $ff00 ; select RAM config for Z80
sei ; disable interrupts
lda $d030
pha
lda #$00 ;disable 2 Mhz
sta $d030
lda $ffee
pha
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 #$b0 ;
sta $d505 ; set Z80 mode - this instruction deactivates 8502 and jumps by Z80 PC to $ffee
nop
pla
sta $ffee
pla
sta $d030
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
; return from Z80 code (address 1c64h in this example)
.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 $e0ff ; give control back to 8502
_endofcode
.org 3800h
ld bc,0d020h
in a,(c)
inc a
out (c),a
jp 1c64h
.end
>01c00 00 0c 08 0a 00 9e 37 31
>01c08 38 31 00 00 00 ad 00 ff
>01c10 48 a9 3e 8d 00 ff 78 ad
>01c18 30 d0 48 a9 00 8d 30 d0
>01c20 ad ee ff 48 a9 c3 8d ee
>01c28 ff a9 47 8d ef ff a9 1c
>01c30 8d f0 ff a9 b0 8d 05 d5
>01c38 ea 68 8d ee ff 68 8d 30
>01c40 d0 68 8d 00 ff 58 60 f3
>01c48 01 06 d5 3e 06 ed 79 3e
>01c50 7e 01 00 d5 ed 79 01 00
>01c58 02 11 00 38 21 73 1c ed
>01c60 b0 c3 00 38 3e 3e 32 00
>01c68 ff 3e 06 01 06 d5 ed 79
>01c70 c3 e0 ff 01 20 d0 ed 78
>01c78 3c ed 79 c3 64 1c