Skip to content

Instantly share code, notes, and snippets.

@BalorPrice
Last active March 13, 2023 22:55
Show Gist options
  • Save BalorPrice/799f815267cd9b8ae16d1efa2e6d57ce to your computer and use it in GitHub Desktop.
Save BalorPrice/799f815267cd9b8ae16d1efa2e6d57ce to your computer and use it in GitHub Desktop.
Simple ZX Spectrum scroller - amended from John Metcalf's 69-byte scroller
org 32768
init_scroll:
ld hl,message-1 ; set to refresh char on first call
ld (scroll_pos),hl
ld hl,pix_count ; variable to check if new character needed
ld (hl),1
ret
update_scroll:
ld hl,pix_count ; update pixel count
dec (hl)
jr nz,scroll
new_char:
ld (hl),8 ; reset pixel count
ld hl,(scroll_pos) ; update current character
inc hl
ld (scroll_pos),hl
ld a,(hl) ; check for loop token
or a
jr nz,get_glyph
loop_msg:
ld hl,message ; loop if necessary
ld (scroll_pos),hl
get_glyph:
ld l,(hl) ; collect letter to print in ascii
ld h,0 ; convert to offset within font data
add hl,hl
add hl,hl
add hl,hl
ld de,(23606) ; base address for font within ROM
add hl,de ; hl=> this letter's font data
ld de,tempchar ; move font data to tempchar space
ld bc,8
ldir
scroll:
ld hl,050FFh ; top-right of print area
ld de,tempchar
ld c,8 ; loop to scroll 8 rows
nextrow:
ex de,hl ; scroll tempchar area left one pix, keep leftmost bit in carry
rl (hl)
ex de,hl
push hl
ld b,32
scrollrow:
rl (hl) ; scroll each byte left, from right to left of screen.
dec l ; NB rightmost byte scrolls tempchar carry data onto screen first time through
djnz scrollrow
pop hl ; next raster line down
inc h
inc de ; find next tempchar data position
dec c
jr nz,nextrow
ret
message:
db "Z80 Assembly for the ZX Spectrum... ",0
tempchar:
db 0,0,0,0,0,0,0,0
scroll_pos: dw 0
pix_count: db 0
@BalorPrice
Copy link
Author

NB Not tested yet.

@BalorPrice
Copy link
Author

Now tested. Edited to tidy up coding style

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment