Palettes from BASIC
Andy S (2979) 504 posts |
I’m trying to write some BASIC to make a 256-colour sprite and then add a full, 256-entry palette to it. Unfortunately, depending on what I pass in R3 to OS_SpriteOp 37, I seem to either get back 64 bytes or 256 bytes of palette data (according to the value returned in R3). The PRM says the sprite palettes contain 8 bytes per palette entry, which would mean I’m only getting back 8 or 32 palette entries instead of the 16, 64, or 256 I’m expecting! This odd behaviour seems to be confirmed by the fact that even though my FOR loop is setting all the palette entries to white, when I plot the sprite the palette entries only apply a slight tint to the pixel colours, as is the normal for a 16 or 64-entry palette, not the 256-entry palette I want. My BASIC is pretty rusty, so what am I doing wrong here?
|
Andy S (2979) 504 posts |
It’s very odd. If I change the statement assigning the palette entries to If I change it to |
Andy S (2979) 504 posts |
Never mind. I’ve figured most of it out. My rusty BASIC knowledge had me thinking the ‘!’ indirection operator would step the specified number of words on from the memory address but of course all the offsets actually have to be in bytes! It’s not like an int * in C. It’s still odd that I get the value 256 back from OS_SpriteOp 37 for the palette size, because when I peek inside the sprite header the palette I made is really the 2048 bytes that I expected! |
Rick Murray (539) 13840 posts |
Yeah, I fall into that one too, but usually the other way, of addressing something far beyond the array limits because, no, it’s words not bytes! ;-) |
Andy S (2979) 504 posts |
I thought the palette size returned by OS_SpriteOP 37 was the number of entries in the palette, not the bytesize? Yes I’m pretty sure it is returning the number of palette entries when I run it. The PRM is probably wrong. |
Andy S (2979) 504 posts |
Yeah, I fall into that one too, but usually the other way, of addressing something far beyond the array limits because, no, it’s words not bytes! ;-) Hey at least your mistake’s more likely to go bang quicker, giving a clear signal something’s very wrong. Mine only went bang when I tried to use my erroneous technique to read the offsets of values in the sprite header and then try to actually access memory at those offsets! 8-S |