I have a routine for one of my Atari 2600 projects. The basic concept of what I am doing is drawing a gamesprite one line at a time.
Sprites' for the Atari are 8 bits wide and as many scanlines tall as you want. For brevity, I'm going to share as little code as possible.
I have decided to use a table pointer because I will store the multiple sprite frames in different tables for animation. Before I decided to animate my sprite, I used the Absolute Indexed mode:
Code:
ldy SpriteLine ; counter for which line we are drawing
beq .finish
lda Sprite-1, y ; <-- this is what I don't like. Since we beq on zero, I have to reduce this by 1
sta GRP0 ; player 0 graphics register
dec SpriteLine
.finish
; elsewhere
Sprite:
.byte #%00011000
.byte #%00111100
.byte #%00011000
In the above code, I am trying to draw a simple diamond shape, 3 scanlines tall. If I don't use the -1 on the Sprite table, it will draw the byte before the table and cut off the bottom.
I've seen this convention used to offset tables, but how would I do that when the table is defined in a pointer? For instance:
Code:
ldy SpriteLine ; counter for which line we are drawing
beq .finish
lda (SpritePtr), y
sta GRP0 ; player 0 graphics register
dec SpriteLine
.finish
; elsewhere
Sprite:
.byte #%00011000
.byte #%00111100
.byte #%00011000
That is fine, but I cannot use -1 on the SpritePtr because it would change the pointer itself. Using -1 on Y doesn't work either.
I personally don't like having to use a -1 to begin with. What solutions would make this more sound?