3gengames wrote:
Sprites is always in a constant area, it is assembled and assigned a value.
Yes, the actual sprites are in a constant area. I'm talking about my read only data that simply gives the information which sprites are to be loaded next. Imagine this:
Code:
SpritesLevel1:
.byte $03
.byte $01
.byte $05
.byte $02
.byte $FF
This code tells you that level 1 will contain three Goombas (ID 1) and 5 Koopa Troopas (ID 2). And that's it. ($FF is the constant for end of data.) Another function that contains some logic would then build the actual on-screen sprites from that abstract data.
Level 4 would then maybe look like this:
Code:
SpritesLevel4:
.byte $01
.byte $01 ; Goomba
.byte $10
.byte $02 ; Koopa Troopa
.byte $02
.byte $05 ; Lakitu
.byte $04
.byte $06 ; Hammer brother
.byte $01
.byte $0F ; Bowser
.byte $FF
3gengames wrote:
To dynamically load sprites, levels, or basically any data based on a number, you either 1. Need to build a pointer table.
Sounds good. How do I do this in 6502 Assembly, specifically for my example loop?
3gengames wrote:
2. Use math based on the number and multiply based on the base value.
Doesn't sound so good. As you see above, there's no guarantee that data will have a fixed length. Besides, the same function shall be used for various unrelated data sections. So, any solution based on a fixed memory location of the data won't work in the long run.
blargg wrote:
The routine is so short it can be made a macro. If it were a parameterized subroutine, it'd take 7-9 bytes to call, whereas the loop itself can be an inline macro and only need 11 bytes:
Yeah, but if I want to call it various times (four times alone for background, sprites, palettes and attributes which would already make 44 bytes), it can get relatively very big.
blargg wrote:
<addr gives the low 8 bits of addr, >addr gives the next higher 8 bits. If you code in C, <addr is the equivalent of addr&0xFF, and >addr is addr>>8&0xFF.
If there's a way to take 8 bits from a 16 bit address, isn't there also a way to store two eight bit values next to each other and let the program treat it as a 16 bit address value?