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 > REG_DISPCNT 16bit or 32bit?

#82504 - E-Coder - Sat May 06, 2006 11:31 pm

Hi,

I'm new on this forum, i'm fluence in Dutch so i'll make a lot of spelling mistakes. I'm sorry for that.

I'm reading a tutorial about GBA programming (GbaJunkies tutorial). Here's a quote:

Quote:

REG_DISPCNT
REG_DISPCNT is probably the most important register in GBA programming because it allows
you to do the following:
- Set the screen mode
- Enable backgrounds
- Set the layout of sprites in memory
- Gives you control over video hardware

It is a 16-bit register which is split up to control different areas as outlined above. Below is
a description of what each bit or set of bits does within the register.


But when I look up in gba.h i'll find this:
Code:

#define REG_DISPCNT    *(u32*)0x4000000      //Display Control (Mode)


This is a 32bit register? Right? Or do we only use the lower-part of the register? Or is GbaJunkie using an old header.

I'm a little bit confused.

E-Coder.
_________________
Newbie in GbaDev.

#82519 - poslundc - Sun May 07, 2006 1:18 am

It's technically a 32-bit register, although only the bottom 16 bits have any purpose as far as I am aware.

The IO memory region (addresses beginning with 0x04000000) has a 32-bit bus width (this means it takes the same amount of time to read or write 32 bits as it does 8 or 16) and the ARM computer is natively a 32-bit machine, so it doesn't hurt to access it 32 bits at a time if you don't have a reason to be dealing with it in 16 bit chunks.

So, in this case you can access it as a 32-bit register (u32 *) or a 16-bit register (u16 *) and it makes no difference, since there is nothing of consequence in the top two bytes of the 32 bits. This is not always the case with every register, though, so you should probably use the correct field-width when you can to be safe.

Check out the Cowbite Virtual Hardware Spec as a reference sheet for more detailed specifications of each register and their behaviour.

Also, check out Cearn's Tonc tutorial for more up-to-date and thorough content than other tutorials currently available.

Dan.

#82526 - Lord Graga - Sun May 07, 2006 2:06 am

Actually, the first of the high bits swap the green components in every other pixel.

#82558 - E-Coder - Sun May 07, 2006 7:44 am

Thanks :). Very fast response!
_________________
Newbie in GbaDev.

#82559 - poslundc - Sun May 07, 2006 7:48 am

Lord Graga wrote:
Actually, the first of the high bits swap the green components in every other pixel.


Really?! Huh! Is that useful for anything...?

Dan.

#82584 - Lord Graga - Sun May 07, 2006 2:39 pm

poslundc wrote:
Lord Graga wrote:
Actually, the first of the high bits swap the green components in every other pixel.


Really?! Huh! Is that useful for anything...?

Dan.


Not really. Something about screens with different pixel formations.