Skip to content

Commit

Permalink
added sprites.reset() to remove sprites from the screen
Browse files Browse the repository at this point in the history
  • Loading branch information
irmen committed Nov 13, 2024
1 parent 1d38c35 commit d70b830
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 4 deletions.
16 changes: 16 additions & 0 deletions compiler/res/prog8lib/cx16/sprites.p8
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,22 @@ sprites {
cx16.vpoke(1, sprite_reg+7, height_flag<<6 | width_flag<<4 | palette_offset&15) ; 64x64 pixels, palette offset
}

sub reset(ubyte spritenum_start, ubyte count) {
; resets all sprite attributes for the given sprite range
; this removes these sprites from the screen completely
; (without disabling sprites globally so the mouse cursor remains visible)
if spritenum_start > 127
return
if count + spritenum_start > 128
return
cx16.VERA_CTRL = $00
cx16.VERA_ADDR_H = $11
cx16.VERA_ADDR = VERA_SPRITEREGS + spritenum_start * $0008
repeat count {
unroll 8 cx16.VERA_DATA0 = $00
}
}

sub data(ubyte spritenum, ubyte bank, uword addr) {
addr >>= 5
addr |= (bank as uword)<<11
Expand Down
2 changes: 2 additions & 0 deletions docs/source/todo.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ TODO
====


- make "block address must be at least program load address + 20 (to allow for startup logic)" more flexible; the 20 should be a constant in the compilation target

...


Expand Down
15 changes: 11 additions & 4 deletions examples/test.p8
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
%import sprites
%import textio
%option no_sysinit
%zeropage basicsafe

main {
sub start() {
txt.print_uwhex(sys.progstart(), true)
txt.spc()
txt.print_uwhex(sys.progend(), true)
txt.nl()
ubyte sprite

for sprite in 1 to 99 {
sys.wait(1)
sprites.init(sprite, 0, 0, sprites.SIZE_8, sprites.SIZE_8, sprites.COLORS_256, 0)
sprites.pos(sprite, 10 + sprite*10, 10+sprite*4)
}

sprites.reset(1, 100)

}
}

0 comments on commit d70b830

Please sign in to comment.