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.

Coding > Setting display modes (REG_DISPCNT (0x4000000))

#9237 - abilyk - Thu Jul 31, 2003 5:53 am

Quick question:

My current macro for setting the display mode is as follows:
Code:
#define SetMode(mode) (REG_DISPCNT = (mode))

Through this method, I have to set every option I want each time I call the macro. If I call
Code:
SetMode(MODE_0 | BG0_ENABLE);
and then
Code:
SetMode(BG1_ENABLE);

The MODE_0 option from the first call is overwritten, obviously.



Now, in my mind,
Code:
#define SetMode(mode) (REG_DISPCNT = (REG_DISPCNT | (mode)))
should do what I want and allow me to add options as shown above. However, this just gives me a blank screen.

I could have my SetMode macro update a 16-bit variable and just set REG_DISPCNT to that variable each time, but is there a more efficient way to do it? Why won't the above macro work?



Also, tepples, from some of your code....
Code:
LCDMODE = 0 | LCDMODE_BG0 | LCDMODE_SPR;


Why are you ORing with 0? Is this just a stylistic habit of yours, or is there a specific reason you're doing that?

Thanks,
Andrew

#9247 - tepples - Thu Jul 31, 2003 8:24 am

abilyk wrote:
Now, in my mind,
Code:
#define SetMode(mode) (REG_DISPCNT = (REG_DISPCNT | (mode)))
should do what I want and allow me to add options as shown above. However, this just gives me a blank screen.

I could have my SetMode macro update a 16-bit variable and just set REG_DISPCNT to that variable each time, but is there a more efficient way to do it? Why won't the above macro work?

Easy: the force-blank bit is set before the GBA jumps to your code. You'll need to add a ClearMode() macro that zeroes out REG_DISPCNT so that you can SetMode() more bits in.
Code:
#define ClearMode() (REG_DISPCNT = 0)


Quote:
Also, tepples, from some of your code....
Code:
LCDMODE = 0 | LCDMODE_BG0 | LCDMODE_SPR;

Why are you ORing with 0? Is this just a stylistic habit of yours, or is there a specific reason you're doing that?

(To folks at home: I use different register names that make sense to me. LCDMODE in my header corresponds to REG_DISPCNT in the purported official register list.)

The 0 represents mode 0. If I were using mode 3 (240x160 pixel high color), it would look like (with my header)
Code:
LCDMODE = 3 | LCDMODE_BG2 | LCDMODE_SPR;

Notice where the 3 goes.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.