gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

C/C++ > Passing a string as a function argument screws up my palette

#30100 - JonahB - Sun Nov 28, 2004 6:17 am

I'm working in mode 4 and I'm trying to build a text system for my GBA game. It uses bitmaps to plot the text characters to the background. The function works like this...

Code:

void draw_text(u16 x, u16 y, const char *str)

....

draw_text(30,30,"TEXT");


Whenever I call draw_text it messes up my sprite data, my sprite palette, and my bg palette. I have done some testing and tracked the bug to the str parameter. Even when I commented out all of the code inside draw_text, it still happened.

As for the function code itself, it doesnt associate str with the video memory at all. It just reads the string then draws the correct bitmap to the screen.

Here are some screenshots of whats happening (the "A" is an early test of my text system)

Good: http://img34.exs.cx/img34/1466/np_good.jpg

Bad: http://img34.exs.cx/img34/8928/np_bad.jpg

This has been driving me nuts for the past three hours. If someone could please help me out, I would be really greatfull.

#30102 - tepples - Sun Nov 28, 2004 7:04 am

Two words: Unaligned Data.

How are you declaring the constant data arrays that your program copies into VRAM? Are they aligned to a 4-byte boundary?
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#30104 - JonahB - Sun Nov 28, 2004 7:48 am

I'm using dovoto's pcx->gba program to convert my image data. Its declared like this:

Code:

const u16 bg_titleData[] = {
0x0707, 0x0707, 0x0707, 0x0307, 0x0303, 0x0703, 0x0303, 0x0101, 0x0101, 0x0101, 0x0101, 0x0101, 0x0101, 0x0101, 0x0101, 0x0101, 0x0101, 0x0101, 0x0101, 0x0101, ect...


Everything works just fine when I dont call the draw_text function. The only thing I can trace it to is the str parameter.

#30118 - tepples - Sun Nov 28, 2004 4:14 pm

const u16? If you use a 32-bit DMA or BIOS CpuFastSet, it'll get screwed up when you copy it to VRAM. Try either using a 16-bit DMA or changing the first line to the following:
Code:
const u16 bg_titleData[] __attribute__ ((aligned (16))) = {

and tell us if it clears up your problem.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#30121 - JonahB - Sun Nov 28, 2004 5:14 pm

WOOHOO!! I was using 32-bit DMA copies to get the data into VRAM. I switched to 16-bit and it works! Thanks!

#30129 - identitycrisisuk - Sun Nov 28, 2004 7:04 pm

tepples wrote:
const u16? If you use a 32-bit DMA or BIOS CpuFastSet, it'll get screwed up when you copy it to VRAM. Try either using a 16-bit DMA or changing the first line to the following:
Code:
const u16 bg_titleData[] __attribute__ ((aligned (16))) = {

and tell us if it clears up your problem.


Sorry to chip in here but when I try and compile things in Visual Studio with the __attribute__ thing in, it flags it as a syntax error - is there something I can do to stop this? I don't use VS to compile my stuff properly, I still use a make.bat file for DevKitAdvance but it's nice to use VS to write the code and compiling the project will save the changes, even if it produces a useless exe. Also, what's the difference between the aligned(16) thing up there and the aligned(4) that you find outputted by graphics programs, should I use one or the other/both/in what situations?
_________________
Code:
CanIKickIt(YES_YOU_CAN);

#30130 - sajiimori - Sun Nov 28, 2004 7:21 pm

__attribute__ is a GCC extension. The GCC docs describe the various attributes and their meanings.

Did you say you want to compile your GBA ROM using VC++ just because compiling does a "save all"? Why don't you just "save all"? Better yet, set up a custom build rule to use your batch file and mark all your .c files to never build.

#30131 - identitycrisisuk - Sun Nov 28, 2004 7:25 pm

sajiimori wrote:
__attribute__ is a GCC extension. The GCC docs describe the various attributes and their meanings.

Did you say you want to compile your GBA ROM using VC++ just because compiling does a "save all"? Why don't you just "save all"? Better yet, set up a custom build rule to use your batch file and mark all your .c files to never build.


Well it tells me if I have any errors as well as just saving everything. I'd much rather use VC++ to go straight to them than run a makefile and have to figure out what lines it's talking about.
_________________
Code:
CanIKickIt(YES_YOU_CAN);