Last active
February 3, 2021 20:40
-
-
Save ped7g/80fd30f8c731b9f52b3952033a6a8564 to your computer and use it in GitHub Desktop.
ZX Spectrum Next - ULA double buffering example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DEVICE ZXSPECTRUMNEXT | |
ORG $8000 ; this example does map Bank5/Bank7 ULA to $4000 (to use "pixelad" easily) | |
mainLoop: | |
call FlipULABuffers ; flip the buffer screen to visible screen and flip buffer | |
call drawDot | |
jr mainLoop | |
FlipULABuffers: ; Flip ULA/Alt ULA screen (double buffer ULA screen) | |
; ret ; uncomment to see effect of non-double-buffered running (blinking dots) | |
ld a,(ULABank) ; Get screen to display this frame | |
; if A==14, then do NR_69=64 (display Bank7), if A==10: NR_69=0 (display Bank5) | |
; its %0000'1110 vs %0000'1010 in binary, so extract bit2 and move it to bit6 | |
and %0000'0100 ; $04 from A=14, $00 from A=10 | |
swapnib ; bit6 set from bit2 | |
nextreg $69,a ; Select Timex/ULA screen to show | |
; flip the drawing buffer mapped at $4000 | |
ld a,(ULABank) | |
xor 10^14 ; alternate between 10 and 14 | |
ld (ULABank),a | |
nextreg $52,a ; map the new "backbuffer" to $4000 (for next drawing) | |
ret | |
ClearUlaBuffer: | |
ld hl,$4000 | |
ld de,$4001 | |
ld bc,$1800 | |
ld (hl),l | |
ldir | |
ld (hl),$05 ; black paper, cyan ink | |
ld bc,$02FF | |
ldir | |
ret | |
drawDot: | |
; clear full ULA to make it blink in case of wrong double-buffering | |
call ClearUlaBuffer | |
; adjust position for next frame | |
ld de,(DotPos) | |
inc e ; ++X | |
ld (DotPos),de | |
; draw dot on every char-row | |
ld b,24 | |
dotLoop: | |
pixelad | |
setae | |
ld (hl),a | |
add de,$0800 ; lazy slow way to do Y+=8 | |
djnz dotLoop | |
ret | |
ULABank defb 10 ;holds current ULA screen in use | |
DotPos defb 0, 4 ; X=0, Y=4 | |
SAVENEX OPEN "flipULA.nex", mainLoop, $BF00 : SAVENEX AUTO : SAVENEX CLOSE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment