Skip to main content
GameDev.net gamedev.net
🔒 Locked

I MUST be missing something....

Started by Arek the Absolute Aug 12, 2002 at 7:35 PM 1 replies 600+ views
Original Post
Arek the Absolute
Arek the Absolute

    
void Text(char* text, int x = 10, int y = 10){

	u8 line = 0; u8 col = 0; u8 write = 0;
	int length = strlen(text);
	u16* image = &OAMData[8192];
	for (int loop = 0; loop < length; loop++){

		int letter = 0;

		if ((text[loop] >= 65) && (text[loop] <= 90)){letter = text[loop]-39;} // caps

		else if ((text[loop] >= 97) && (text[loop] <= 122)){letter = text[loop]-97;} // lower

		else if (text[loop] == 32){letter = 77;} // space

		else if ((text[loop] >= 48) && (text[loop] <= 57)){letter = text[loop]+4;} // nums

		else if (text[loop] == '.'){letter = 62;} // .

		else if (text[loop] == ','){letter = 63;}
		else if (text[loop] == '?'){letter = 64;}
		else if (text[loop] == '!'){letter = 65;}
		else if (text[loop] == '"'){letter = 66;}
		else if (text[loop] == ':'){letter = 67;}
		else if (text[loop] == ';'){letter = 68;}
		else if (text[loop] == '-'){letter = 69;}
		else if (text[loop] == '_'){letter = 70;}
		else if (text[loop] == '+'){letter = 71;}
		else if (text[loop] == '='){letter = 72;}
		else if (text[loop] == '<'){letter = 73;}
		else if (text[loop] == '>'){letter = 74;}
		else if (text[loop] == '\''){letter = 75;} // apostrophe

		else if (text[loop] == '\n'){line++; col = 0; continue;}

		for (int pix = 0; pix < 64; pix++)
			image[pix] = 0x0202;

		MoveSprite(&sprites[write],x+(col<<3),y+(line<<4));

		write++;
		col++;
		image = ?[64];

	}

}
    
This code is a function to make text appear using sprites on the GBA. However, that knowledge probably isn't important to my problem. What's the problem? I'm working in mode 5. Whenever I call that function, the text sprites are, predictably, filled in with palette color 2, whatever that may be. However, then nothing else is drawn to the screen, and it seems to stop accepting button input. Yes, I know that doesn't sound like a problem in this segment of code. However, take out these lines of code: for (int pix = 0; pix < 64; pix++) image[pix] = 0x0202; and replace it with this: image[0] = 0x0202; and explain to me why exactly the first two pixels in the sprite are palette color two, and EVERYTHING works fine. How the heck is a simple for loop screwing up everything in my code? Am I running into some problem with GCC (G++, technically) Any help with this would be GREATLY appreciated. **Edit: BTW: I am fully aware a significant chunk of that code is irrelevant to the end result. I've castrated it to figure out what the heck is going on. Just assume that I'm parsing the string and changing its values to get the appropriate segment in an array that holds the image data. *** -Arek the Absolute [edited by - Arek the Absolute on August 12, 2002 8:38:24 PM]
-Arek the Absolute"The full quartet is pirates, ninjas, zombies, and robots. Create a game which involves all four, and you risk being blinded by the sheer level of coolness involved." - Superpig
outRider
outRider
If your *image points to the actual OAM memory in VRAM then you can only update that at certain times, i.e. on either the vblank/hblank, or a the forced blank, so it might screw things up if you try to do it at any other time. If you are updating during a blank you might be missing the blank. If you aren''t, or if that OAMData is in system memory then I don''t know what the problem is, I haven''t worked with the GBA in too much depth.

------------
- outRider -
heronmark
heronmark
The last line of your for loop is:
image = ?[64];
which is probably a cut and paste issue, but you might want to check that you''re incrementing the image pointer correctly.
The other thing which might be problem is that you''re not checking the length of the string that you''re printing (at least not in this code) which could cause you to overwrite the memory following the OAMData memory area.

Hope that helps
Pete

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.