gbadev
Game Boy Advance homebrew development forum
Member
Joined:
Posts: 1

I was following Tonc and noticed it defines the display register like this:
#define REG_DISPCNT *((volatile u32*)(MEM_IO+0x0000))

But the documentation I've seen online describes it as a 16-bit register.
Can anyone explain the discrepancy and recommend how I should handle it in my own projects?

Administrator
avatar
Joined:
Posts: 54

I'd probably recommend to treat DISPCNT as 16-bit in your own projects.

As far as I know, Tonc treats DISPCNT as 32-bit under the belief that the space next to it is unused. This isn't correct, those 16-bits are actually the green-swap register. However, green-swap isn't all that useful and writing zeroes to it is harmless, so there's nothing really wrong with what Tonc's doing. If you did want to toggle green-swap for any reason you could just treat it as an extra field of DISPCNT.

I did once wonder if having DISPCNT as 32-bit could be performance-related but my current understanding is that it wouldn't be any faster... So I don't really know why Tonc does this. Maybe cearn thought it would throw people off if there was an unexplained gap?

Member
Joined:
Posts: 1

I definitely recommend it as 16bit.

Retail games use 32bit writes from the few that I have inspected, I assume it's actually defined as that in the SDK.

As exelotl said, the only bit above the low 16bit is "green swap" stereoscopic mode enable, which is useless to change (especially if you want it enabled 😉).

And yes, the IO bus has no wait (except HALTCNT, hehe), so accessing it as 8/16/32 is the same speed, so performance doesn't matter.
Although, regs like DMACNT and TMCNT can be written as 32bit, so we are losing some performance by splitting them up as 2x 16bit writes, but I digress.


If we want to be extra pedantic... technically all IO regs are 32bit (due to the size of the APB... this is evident, as registers with a few readable bits have the unreadable bits read as 0, extended to 32 bits, as opposed to write-only registers with no readable bits reading as open bus), but clearly, there are some where it makes no sense to treat it as 32bits (for example, audio regs, serial regs, etc.).

Especially so, that most are not size-sensitive (except like PCM FIFO and DMACNT_H or so that I can remember without looking it up), it is more convenient sometimes to manipulate regs in the smallest allowed quantity.