User`s guide
Page 26
www.commodorefree.com
display eight sprites on a single screen regardless of which
screen mode you've set. To be more precise, the VIC-II is able
to handle eight sprites per scan-line (sometimes referred to as
a raster-line or raster-beam), but we needn't concern
ourselves with this at the moment.
As with bit-mapping or the default screen mode, everything
has its' place, so each sprite must start at specific locations in
the memory bank that the VIC-II is pointing to.
Each sprite is made up of 24 pixels by 21 pixels in mono-colour
(high-resolution) mode, with multi-colour mode halving the
vertical resolution, meaning 12 by 21 pixels. There is quite ver-
satile handling too, as each [sprite] may be expanded horizon-
tally, vertically or both, and is automatically layered based on a
pre-set of zero through to seven. And regardless of how
chunky you have set your MOBs, you are still able to move
them horizontally or vertically one single pixel at a time based
on the default visible area of 320 by 200 pixels, which is quite
good as it always ensures smooth movements even if the
graphics have that 'blocky' look about them. You may also set
the priority of each sprite to say whether or not it is in front of
or behind the characters on the screen or the bit-mapped, but
you are not able to change the way one sprite may over or un-
der lap another as this is set by the hardware. I have a brief
sprite demonstration next time as unfortunately we've ran out
of space for a coding example.
A C64 sprite editor
More on sprites – Part 11
Last week, I briefly introduced hardware sprites on the
Commodore 64, so as there wasn't much time or space for a
piece of example code, I thought that I'll throw one straight at
you, with some explanations on the forums at
tinyurl.com/C64-Coding. Here's this week’s routine:
*=$1000
lda #$0d ; Using block 13 for sprite zero
sta $07f8
lda #%00000001 ; Enable sprite zero
sta $d015
lda #$05 ; We'll colour it green
sta $d027
lda #%11100111 ; Our bit pattern for the sprite (repeated)
ldx #$40 ; X is used as a counter
SETUP
dex
sta $0340,x
bne SETUP ; Builds the sprite
lda #%00000000
sta $d010 ; This clears the MSB setting for all sprites
ldx #$64
ldy #$70
stx $d000 ; X position set
sty $d001 ; Y position set
SCAN
jsr $ff9f ; Scans keyboards
jsr $ffe4 ; Put relevant value into A
START
cmp #$57 ; W is up
beq MOVEUP ; If true, move sprite up...
cmp #$53 ; S is down
beq MOVEDOWN ; etc...
cmp #$41 ; A is left
beq MOVELEFT
cmp #$44 ; D is right
beq MOVERIGHT
cmp #$0d ; Checks is the RETURN key is pressed
beq EXIT ; If so, we'll exit
jmp SCAN ; Back to loop marker
MOVEUP
ldy $d001 ; Gets previous Y position
dey ; Decreases by one
sty $d001 ; Stores new value
jmp SCAN
MOVEDOWN
ldy $d001
iny
sty $d001
jmp SCAN
MOVELEFT
ldx $d000
dex
stx $d000
cpx #$ff ; Checks for horizontal position moving left
bne SCAN
lda #%00000000
sta $d010 ; Clears MSB for horizontal position
jmp SCAN
MOVERIGHT
ldx $d000
inx
stx $d000
cpx #$00 ; Checks for horizontal position moving right
bne SCAN
lda #%00000001
sta $d010 ; Sets MSB for horizontal position
jmp SCAN
EXIT
jsr $e544
lda #$00
sta $d015 ; Switches off sprites
rts ; Back to BASIC