|
Post by jusalak on Jan 13, 2024 19:19:47 GMT
As a continuation to the raster interrupt program example I experimented with opening borders with Z80. The example program opens borders for a moment and then returns to the READY prompt.
Initial setup code:
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 $00 $02; ld bc,0200h .byte $11 $00 $38; ld de,3800h .byte $21; ld hl .byte <endcode .byte >endcode .byte $ED $B0; ldir .byte $C3 $00 $38; jp 3800h
endcode
The Z80 interrupt code:
.org 3800h
ld sp,37F0h
ld bc,0D012h ld a,0f9h out (c),a ld bc,0dc0eh in a,(c) ld (3101h),a ld a,0f9h out (c),a ld a,01h ld bc,0d019h out (c),a inc c out (c),a ld a,01bh ld bc,0d011h out (c),a
ld bc,3000h ld a,31h _loop1: ld (bc),a inc c jr nz, _loop1 inc b ld (bc),a ld a,0c3h ld (3131h),a ld bc,irq ld (3132h),bc
ld a,30h ld i,a im 2 ei ld bc,500
_loop3: halt dec bc ld a,b cp 0ffh jr nz, _loop3 ld bc,0dc0eh ld a,(3101h) out (c),a jp 0ffe0h irq: push af push bc ld bc,0d019h ld a,01h out (c),a ld bc,0d020h in a,(c) inc a out (c),a ld bc,0d011h in a,(c) and 0f7h out (c),a inc c _loop2: in a,(c) cp 00h jr nz, _loop2 dec c in a,(c) and 7fh or 08h out (c),a ld bc,0d020h in a,(c) dec a out (c),a pop bc pop af ei ret
.end The dump below
>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 00 02 11 >01c58 00 38 21 62 1c ed b0 c3 >01c60 00 38 31 f0 37 01 12 d0 >01c68 3e f9 ed 79 01 0e dc ed >01c70 78 32 01 31 3e f9 ed 79 >01c78 3e 01 01 19 d0 ed 79 0c >01c80 ed 79 3e 1b 01 11 d0 ed >01c88 79 01 00 30 3e 31 02 0c >01c90 20 fc 04 02 3e c3 32 31 >01c98 31 01 5a 38 ed 43 32 31 >01ca0 3e 30 ed 47 ed 5e fb 01 >01ca8 f4 01 76 0b 78 fe ff 20 >01cb0 f9 01 0e dc 3a 01 31 ed >01cb8 79 c3 e0 ff f5 c5 01 19 >01cc0 d0 3e 01 ed 79 01 20 d0 >01cc8 ed 78 3c ed 79 01 11 d0 >01cd0 ed 78 e6 f7 ed 79 0c ed >01cd8 78 fe 00 20 fa 0d ed 78 >01ce0 e6 7f f6 08 ed 79 01 20 >01ce8 d0 ed 78 3d ed 79 c1 f1 >01cf0 fb c9
can be copied and pasted the MONITOR of VICE or Z64K. The program can then be saved with the command
insert code hereS "Z80OPENBORDERS",8,1C01,1CF2
|
|
|
Post by bjonte on Jan 14, 2024 8:10:05 GMT
Very cool!
|
|
|
Post by c128old on Jan 14, 2024 17:29:48 GMT
Nice! Can’t easily see how you get a stable raster, I’ll have a more careful look.
|
|
|
Post by jusalak on Jan 14, 2024 17:39:39 GMT
When interrupts occur during Z80 HALT state, then timings are very stable. At the moment I am trying to figure out how to restore CIA interrupt when exiting.
|
|
|
Post by jusalak on Jan 14, 2024 19:50:31 GMT
And yes, I figured out that on C128, interrupts are by default generated by the VIC. So there is no need to disable the CIA #1 interrupt, since it is off by default. Only CIA #1 timer B is running, which is inconsequential.
So I polished the code
.org 3800h
ld sp,37F0h
ld bc,3000h ld a,31h _loop1: ld (bc),a inc c jr nz, _loop1 inc b ld (bc),a ld a,0c3h ld (3131h),a ld bc,irq ld (3132h),bc ld a,30h ld i,a im 2 ld bc,0d011h in a,(c) and 7fh out (c),a ld bc,0D012h ld a,0f9h out (c),a ld bc,0d019h ld a,01h out (c),a inc c out (c),a ei ld bc,500
_loop3: halt dec bc ld a,b cp 0ffh jr nz, _loop3 di ld bc,0D012h ld a,0ffh out (c),a ld bc,0d019h ld a,01h out (c),a jp 0ffe0h irq: push af push bc ld bc,0d019h ld a,01h out (c),a ld bc,0d020h in a,(c) inc a out (c),a ld bc,0d011h in a,(c) and 0f7h out (c),a inc c _loop2: in a,(c) cp 00h jr nz, _loop2 dec c in a,(c) and 7fh or 08h out (c),a ld bc,0d020h in a,(c) dec a out (c),a pop bc pop af ei ret
.end
And the dump 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 00 02 11 >01c58 00 38 21 62 1c ed b0 c3 >01c60 00 38 31 f0 37 01 00 30 >01c68 3e 31 02 0c 20 fc 04 02 >01c70 3e c3 32 31 31 01 57 38 >01c78 ed 43 32 31 3e 30 ed 47 >01c80 ed 5e 01 11 d0 ed 78 e6 >01c88 7f ed 79 01 12 d0 3e f9 >01c90 ed 79 01 19 d0 3e 01 ed >01c98 79 0c ed 79 fb 01 f4 01 >01ca0 76 0b 78 fe ff 20 f9 f3 >01ca8 01 12 d0 3e ff ed 79 01 >01cb0 19 d0 3e 01 ed 79 c3 e0 >01cb8 ff f5 c5 01 19 d0 3e 01 >01cc0 ed 79 01 20 d0 ed 78 3c >01cc8 ed 79 01 11 d0 ed 78 e6 >01cd0 f7 ed 79 0c ed 78 fe 00 >01cd8 20 fa 0d ed 78 e6 7f f6 >01ce0 08 ed 79 01 20 d0 ed 78 >01ce8 3d ed 79 c1 f1 fb c9
Save with
S "Z80OPENBORDERS2",8,1C01,1CEF
|
|
|
Post by jusalak on Jan 20, 2024 10:38:35 GMT
I added a safeguard to disable 2 MHz fast mode before entering the Z80 part. Z80 programs should be run only in VIC 1 Mhz SLOW mode, they will not benefit from the FAST mode (running speed is the same).
Z80 in VIC 2 Mhz FAST mode not only has interrupt instability, Z80 has also other weird behavior in that mode (separate post on that later).
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 $00 $02; ld bc,0200h .byte $11 $00 $38; ld de,3800h .byte $21; ld hl .byte <endcode .byte >endcode .byte $ED $B0; ldir .byte $C3 $00 $38; jp 3800h
endcode
.org 3800h
ld sp,37F0h
ld bc,3000h ld a,31h _loop1: ld (bc),a inc c jr nz, _loop1 inc b ld (bc),a ld a,0c3h ld (3131h),a ld bc,irq ld (3132h),bc ld a,30h ld i,a im 2 ld bc,0d011h in a,(c) and 7fh out (c),a inc c ld a,0f9h out (c),a ld bc,0d019h ld a,01h out (c),a inc c out (c),a ei ld bc,500
_loop3: halt dec bc ld a,b cp 0ffh jr nz, _loop3 di ld bc,0D012h ld a,0ffh out (c),a ld bc,0d019h ld a,01h out (c),a jp 0ffe0h irq: push af push bc ld bc,0d019h ld a,01h out (c),a ld bc,0d020h in a,(c) inc a out (c),a ld bc,0d011h in a,(c) and 0f7h out (c),a inc c _loop2: in a,(c) cp 00h jr nz, _loop2 dec c in a,(c) and 7fh or 08h out (c),a ld bc,0d020h in a,(c) dec a out (c),a pop bc pop af ei ret
.end
Updated dump and saving command:
>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 00 02 11 00 38 21 56 >01c50 1c ed b0 c3 00 38 31 f0 >01c58 37 01 00 30 3e 31 02 0c >01c60 20 fc 04 02 3e c3 32 31 >01c68 31 01 55 38 ed 43 32 31 >01c70 3e 30 ed 47 ed 5e 01 11 >01c78 d0 ed 78 e6 7f ed 79 0c >01c80 3e f9 ed 79 01 19 d0 3e >01c88 01 ed 79 0c ed 79 fb 01 >01c90 f4 01 76 0b 78 fe ff 20 >01c98 f9 f3 01 12 d0 3e ff ed >01ca0 79 01 19 d0 3e 01 ed 79 >01ca8 c3 e0 ff f5 c5 01 19 d0 >01cb0 3e 01 ed 79 01 20 d0 ed >01cb8 78 3c ed 79 01 11 d0 ed >01cc0 78 e6 f7 ed 79 0c ed 78 >01cc8 fe 00 20 fa 0d ed 78 e6 >01cd0 7f f6 08 ed 79 01 20 d0 >01cd8 ed 78 3d ed 79 c1 f1 fb >01ce0 c9
S "Z80OPENBORDER",8,1C01,1CE1
|
|
|
Post by jusalak on Jan 20, 2024 19:04:55 GMT
On one of my C128s (both flat PAL), the opened border is gray, the same as the background color, as do Z64K and VICE. But on the other, the opened border is black; this machine is of somewhat later production than the other.
|
|
|
Post by jusalak on Feb 9, 2024 16:43:25 GMT
An example to open the side border is listed below. It is this short!
main .org $1c01 .byte $0c,$08,$0a,$00,$9e,$37,$31,$38,$31,$00,$00,$00 lda #$be ; select RAM bank 2 with I/O for Z80 sta $ff00 ; to put Z80 BIOS out of the way sei ; disable interrupts lda #$00 ;disable 2 Mhz sta $d030 lda #$c3 sta $ffee ; store JP instruction for Z80 mode start lda #<z80code ; store lo-byte address sta $ffef lda #>z80code ; and hi-byte address sta $fff0 ;of Z80 code _main ;8502 main, no interrupt lda #$b0 ;give control to Z80 sta $d505 ;in order to wait for the next frame nop ldx #$07 nop nop nop nop bit $ff _loop: ldy #$00 sty $d016 ldy #$08 sty $d016 nop nop nop nop nop nop nop nop nop nop nop nop nop nop nop nop nop nop nop nop nop nop nop dex bne _loop jmp _main z80code
.org 1c5ch
di ld sp,2000h ;set up stack im 1 ;interrupt mode 1 ld a,0c3h ld (0038h),a ld bc,_irq ;set up JP interrupt addresses ld (0039h),bc ld bc,_return ld (0ffefh),bc ld bc,0d011h ;set up raster interrupt line ld a,1bh out (c),a inc c ld a,91 out (c),a call _irq ;call irq handled to acknowledge interrupt _return: nop halt jp 0ffe6h ;give control back to 8502
_irq: ;interrupt handler ld bc,0d019h ;acknowledge raster interrupt ld a,01h out (c),a ei ret ;this is all there is to do, then return
.end
>01c00 00 0b 1c 0a 00 9e 37 31 >01c08 38 31 00 00 00 a9 be 8d >01c10 00 ff 78 a9 00 8d 30 d0 >01c18 a9 c3 8d ee ff a9 5c 8d >01c20 ef ff a9 1c 8d f0 ff a9 >01c28 b0 8d 05 d5 ea a2 07 ea >01c30 ea ea ea 24 ff a0 00 8c >01c38 16 d0 a0 08 8c 16 d0 ea >01c40 ea ea ea ea ea ea ea ea >01c48 ea ea ea ea ea ea ea ea >01c50 ea ea ea ea ea ea ca d0 >01c58 dc 4c 27 1c f3 31 00 20 >01c60 ed 56 3e c3 32 38 00 01 >01c68 89 1c ed 43 39 00 01 84 >01c70 1c ed 43 ef ff 01 11 d0 >01c78 3e 1b ed 79 0c 3e 5b ed >01c80 79 cd 89 1c 00 76 c3 e6 >01c88 ff 01 19 d0 3e 01 ed 79 >01c90 fb c9
Paste dump to MONITOR using VICE or Z64K and save with command:
S "OPENBORDERTEST",8,1C01,1C92
|
|