#2385 - darkcloud - Sun Feb 02, 2003 8:53 pm
In my game, I start out in Mode 4 to display images, stuff like that, then in my main game, i switch to Mode 2. Switching from Mode 4 to 2 works, but then later I try to switch from Mode 2, back to Mode 4. This is where I run into problems. I tested the Mode 4 code by itself, without switching from Mode 2, and that worked. But when I switch from Mode 2 to Mode 4 the screen is just black. Any reasons to why this is?
_________________
Maybe in order to understand mankind, we have to look at the word itself: "Mankind". Basically, it's made up of two separate words - "mank" and "ind". What do these words mean ? It's a mystery, and that's why so is mankind.
#2391 - Maddox - Sun Feb 02, 2003 10:23 pm
You are probably using some code that just writes the value of the mode into the register WITHOUT masking out the value that was there last time. This will cause you to set the mode to 6 because you will accumulate that bit in the dispcnt register. 2 OR 4 is 6. When the gba gets a mode > 5 it turns black.
_________________
You probably suck. I hope you're is not a game programmer.
#2393 - darkcloud - Sun Feb 02, 2003 11:15 pm
Could there be anything else that could cause the problem?
I don't think its the way I set REG_DISPCNT because I did some tests.
I tried setting the mode to Mode 2, then switching to Mode 4, and that worked. I also tried messing around with REG_DISPCNT and then setting the mode to Mode 4 and that worked. This leads me to believe that it has something to do with my game code.
Below is the code I use to change my modes:
Code: |
//define the bits that control the screen mode 0-5
#define MODE_0 0x0
#define MODE_1 0x1
#define MODE_2 0x2
#define MODE_3 0x3
#define MODE_4 0x4
#define MODE_5 0x5
//define the buffer which is used to set the active buffer
//when using double buffering
#define backbuffer 0x10
//This bit, when set allows OAM(Object Attribute Memory) to
//be updated during a horizontal blank
#define H_BLANK_OAM 0x20
//use these two defines to choose which mapping mode is used
//for sprite graphics 2D or 1D
#define OBJ_MAP_2D 0x0
#define OBJ_MAP_1D 0x40
//Causes the screen to go white by using a forced blank
#define FORCE_BLANK 0x80
//define the flags for enabling backgrounds and objects(sprites)
#define BG0_ENABLE 0x100
#define BG1_ENABLE 0x200
#define BG2_ENABLE 0x400
#define BG3_ENABLE 0x800
#define OBJ_ENABLE 0x1000
//allows window displays (dont worry about these)
#define WIN1_ENABLE 0x2000
#define WIN2_ENABLE 0x4000
#define WINOBJ_ENABLE 0x8000
//Set the mode that you want to use, logical AND them together as below:
//e.g. SetMode(MODE_2 | OBJ_ENABLE | OBJ_MAP_1D);
#define SetMode(mode) REG_DISPCNT = (mode)
|
Can you show me some code that guarentees REG_DISPCNT to be "reset"?
_________________
Maybe in order to understand mankind, we have to look at the word itself: "Mankind". Basically, it's made up of two separate words - "mank" and "ind". What do these words mean ? It's a mystery, and that's why so is mankind.
#2395 - Maddox - Mon Feb 03, 2003 12:56 am
Quote: |
Code: | //Set the mode that you want to use, logical AND them together as below:
//e.g. SetMode(MODE_2 | OBJ_ENABLE | OBJ_MAP_1D);
#define SetMode(mode) REG_DISPCNT = (mode)
|
|
This is silly but I will show patience. When you use that SetMode macro, do you use all those nice manifest constants like BG2_ENABLE. They need to be specified EVERY time you call that macro. Otherwise you will be resetting those bits to zero, shutting off your bg layers.
_________________
You probably suck. I hope you're is not a game programmer.
#2396 - darkcloud - Mon Feb 03, 2003 1:03 am
Yes, I know that.
So what else could cause the problem?
I can't seem to find any plausible cause in my code.
_________________
Maybe in order to understand mankind, we have to look at the word itself: "Mankind". Basically, it's made up of two separate words - "mank" and "ind". What do these words mean ? It's a mystery, and that's why so is mankind.
#2397 - Dev - Mon Feb 03, 2003 1:30 am
darkcloud wrote: |
I can't seem to find any plausible cause in my code. |
The compiler may be doing odd optimization things...
Try this:
Code: |
typedef volatile unsigned short int vu16;
#define SetMode(mode) *(vu16 *)REG_DISPCNT = (mode) |
My guess is that whatever startup code you're using has left things in a state that works correctly by sheer coincidence.
Also, what Maddox is saying is that you don't appear to be enabling the background anywhere (Mode 4 uses BG2), so unless your display is entirely sprites, I'd expect a black screen too.
If that change above doesn't work, you'll need to post the actual code you're using and not just a tiny snippet of it.
(I'm sure Maddox is rolling his eyes right now thinking "umm... yeah, he did post the actual code he's using!")
Then again, perhaps your GBA isn't working properly... ;-)
#2401 - darkcloud - Mon Feb 03, 2003 2:04 am
Sorry, I guess I didn't specify exactly what the code I posted was. That isn't the code I'm using to set up the display, thats just the definitions of the SetMode macro and the defines to go with it.
The change didn't work, actually it made the screen go black.
I would post more of my code, I'm just not sure which parts are relevant.
But I will explain the basic set up of my code.
Part 1-
First theres an intro to the game in Mode 4 (SetMode(MODE_4 | BG2_ENABLE)).
Part 2-
Then theres the game and I switch to mode 2 by doing SetMode(MODE_2 | BG2_ENABLE | BG3_ENABLE | OBJ_MAP_1D | OBJ_ENABLE)
Part 3-
Then I go back to mode 4, SetMode(MODE_4 | BG2_ENABLE) and load my images and this is where the problem is.
The way I tested to see if it was my SetMode macro causing the problem by only running the code in Part 3, but by adding a SetMode(MODE_2) before the SetMode(MODE_4 | BG2_ENABLE). This works. Its only when I run all the parts that I run into my problem.
I hope I explained it clearly, I think I'll search through my game code to find anything that might be related.
_________________
Maybe in order to understand mankind, we have to look at the word itself: "Mankind". Basically, it's made up of two separate words - "mank" and "ind". What do these words mean ? It's a mystery, and that's why so is mankind.
#2408 - Maddox - Mon Feb 03, 2003 7:19 am
Yeah, make sure it's declared as volatile unsigned short *REG_DISPCNT. Also, turn off ALL optimizations with -O0 (that's 'O' zero).
_________________
You probably suck. I hope you're is not a game programmer.
#2430 - MrMr[iCE] - Mon Feb 03, 2003 9:24 pm
Also make sure your enabling bg2 when you jump back to mode4. bitmap modes require that bg layer to be enabled.
_________________
Does the corpse have a familiar face?
#2433 - darkcloud - Mon Feb 03, 2003 9:53 pm
Ok well I found the problem, and it was stupidly obvious. It should have been one of the first things I should have checked for causing the problem. I forgot to reset the BG scrolling registers!!!!!!!
Well, anyway thanks for all your help.
_________________
Maybe in order to understand mankind, we have to look at the word itself: "Mankind". Basically, it's made up of two separate words - "mank" and "ind". What do these words mean ? It's a mystery, and that's why so is mankind.