Skip to content

Instantly share code, notes, and snippets.

@ped7g
Last active April 18, 2022 13:46
Show Gist options
  • Save ped7g/7212217fc034e643f6ffe831ff2f49ac to your computer and use it in GitHub Desktop.
Save ped7g/7212217fc034e643f6ffe831ff2f49ac to your computer and use it in GitHub Desktop.
ZX Spectrum Z80 assembly - set "box" on screen to particular attribute value
; Variations on Andrew's question from FB group, two possible entry points
; clear_box with HL as char-coordinates or clear_box_adr with HL as attribute address
clear_box:
; h = valid character y coordinate
; l = valid character x coordinate
; b = width
; c = height
; a = attribute to fill
push af
ld a,h
rrca
rrca
rrca
ld h,a
and $e0
or l
ld l,a
ld a,h
and $03
or $58
ld h,a
pop af
; |
; fallthrough into clear_box_adr
; |
; v
clear_box_adr:
; hl = left-top attr address
; b = width
; c = height
; a = attribute to fill
push bc
push hl
attr_line:
ld (hl),a
inc hl ; inc l is enough for boxes which don't cross border edge
djnz attr_line
pop hl
ld c,32 ; b is zero from djnz
add hl,bc
pop bc
dec c
jp nz,clear_box_adr
ret
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment