#18510 - Shadow - Sun Mar 28, 2004 4:14 am
I've got a tedious problem here. As I was trying out some code, at one point it looked like there was a bug because nothing was happening (I had code to load values into the sprite palette memory and nothing happened at all). After some time, I found where the problem was and I created a small program that would reproduce it. Here is the code :
(Originally, I had the data array in a structure that represented OAM Data, and I was trying to clear it).
The program initializes an array of 16384 16-bit values to 0x6666 and then loads into the sprite palette memory the palette data declared at the top, which consists of 256 times the value 0x1111. At least this is what should happen. What happens is that the values loaded into the palette are not 0x1111 but 0x6666, which makes no sense at all. Now, I found that if I only initialized the first 164 values of the data array, then everything worked correctly. From the 165th value on, palette values started to be corrupted.
I decided to look into the memory using VisualBoy Advance, and I found the 16384 items of data starting somewhere in EWRAM, and "spilling" into IWRAM, completely overwriting the palette data, which was stored there.
The thing is I have no idea what to do. I'm still only learning how the GBA works and how to program it, and I'm afraid I've accidentally bumped into a really difficult problem that is way beyond my level. I would imagine it has something to do with the linkscript and/or gcc. I'm using DevKitAdvance, with the default CRT0.S and lnkscript, and I've never had any problems with it before. I've tried other things such as GNUARM, but I could never get them to work (too many confusing command-line options and things I don't understand...). I don't know how the gcc linkscript commands work, but if I must I will get my hands dirty and learn them.
Any suggestions would be very appreciated. I'm completely blocked by this problem and I'm determined to find a solution.
Thank you very much for your help.
Code: |
static unsigned short palette[ 256 ] = { 0x1111,0x1111,0x1111,0x1111,0x1111,0x1111,0x1111,0x1111, 0x1111,0x1111,0x1111,0x1111,0x1111,0x1111,0x1111,0x1111, 0x1111,0x1111,0x1111,0x1111,0x1111,0x1111,0x1111,0x1111, 0x1111,0x1111,0x1111,0x1111,0x1111,0x1111,0x1111,0x1111, 0x1111,0x1111,0x1111,0x1111,0x1111,0x1111,0x1111,0x1111, 0x1111,0x1111,0x1111,0x1111,0x1111,0x1111,0x1111,0x1111, 0x1111,0x1111,0x1111,0x1111,0x1111,0x1111,0x1111,0x1111, 0x1111,0x1111,0x1111,0x1111,0x1111,0x1111,0x1111,0x1111, 0x1111,0x1111,0x1111,0x1111,0x1111,0x1111,0x1111,0x1111, 0x1111,0x1111,0x1111,0x1111,0x1111,0x1111,0x1111,0x1111, 0x1111,0x1111,0x1111,0x1111,0x1111,0x1111,0x1111,0x1111, 0x1111,0x1111,0x1111,0x1111,0x1111,0x1111,0x1111,0x1111, 0x1111,0x1111,0x1111,0x1111,0x1111,0x1111,0x1111,0x1111, 0x1111,0x1111,0x1111,0x1111,0x1111,0x1111,0x1111,0x1111, 0x1111,0x1111,0x1111,0x1111,0x1111,0x1111,0x1111,0x1111, 0x1111,0x1111,0x1111,0x1111,0x1111,0x1111,0x1111,0x1111, 0x1111,0x1111,0x1111,0x1111,0x1111,0x1111,0x1111,0x1111, 0x1111,0x1111,0x1111,0x1111,0x1111,0x1111,0x1111,0x1111, 0x1111,0x1111,0x1111,0x1111,0x1111,0x1111,0x1111,0x1111, 0x1111,0x1111,0x1111,0x1111,0x1111,0x1111,0x1111,0x1111, 0x1111,0x1111,0x1111,0x1111,0x1111,0x1111,0x1111,0x1111, 0x1111,0x1111,0x1111,0x1111,0x1111,0x1111,0x1111,0x1111, 0x1111,0x1111,0x1111,0x1111,0x1111,0x1111,0x1111,0x1111, 0x1111,0x1111,0x1111,0x1111,0x1111,0x1111,0x1111,0x1111, 0x1111,0x1111,0x1111,0x1111,0x1111,0x1111,0x1111,0x1111, 0x1111,0x1111,0x1111,0x1111,0x1111,0x1111,0x1111,0x1111, 0x1111,0x1111,0x1111,0x1111,0x1111,0x1111,0x1111,0x1111, 0x1111,0x1111,0x1111,0x1111,0x1111,0x1111,0x1111,0x1111, 0x1111,0x1111,0x1111,0x1111,0x1111,0x1111,0x1111,0x1111, 0x1111,0x1111,0x1111,0x1111,0x1111,0x1111,0x1111,0x1111, 0x1111,0x1111,0x1111,0x1111,0x1111,0x1111,0x1111,0x1111, 0x1111,0x1111,0x1111,0x1111,0x1111,0x1111,0x1111,0x1111 }; int main( void ) { unsigned short index = 0; unsigned short data[ 16384 ]; unsigned short * gba_sprite_palette = ( unsigned short * ) 0x5000200; for ( index = 0; index < 16384; ++ index ) { data[ index ] = 0x6666; } for ( index = 0; index < 256; ++ index ) { gba_sprite_palette[ index ] = palette[ index ]; } while ( 1 ) { } return 0; } |
(Originally, I had the data array in a structure that represented OAM Data, and I was trying to clear it).
The program initializes an array of 16384 16-bit values to 0x6666 and then loads into the sprite palette memory the palette data declared at the top, which consists of 256 times the value 0x1111. At least this is what should happen. What happens is that the values loaded into the palette are not 0x1111 but 0x6666, which makes no sense at all. Now, I found that if I only initialized the first 164 values of the data array, then everything worked correctly. From the 165th value on, palette values started to be corrupted.
I decided to look into the memory using VisualBoy Advance, and I found the 16384 items of data starting somewhere in EWRAM, and "spilling" into IWRAM, completely overwriting the palette data, which was stored there.
The thing is I have no idea what to do. I'm still only learning how the GBA works and how to program it, and I'm afraid I've accidentally bumped into a really difficult problem that is way beyond my level. I would imagine it has something to do with the linkscript and/or gcc. I'm using DevKitAdvance, with the default CRT0.S and lnkscript, and I've never had any problems with it before. I've tried other things such as GNUARM, but I could never get them to work (too many confusing command-line options and things I don't understand...). I don't know how the gcc linkscript commands work, but if I must I will get my hands dirty and learn them.
Any suggestions would be very appreciated. I'm completely blocked by this problem and I'm determined to find a solution.
Thank you very much for your help.