-
Notifications
You must be signed in to change notification settings - Fork 225
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Registers should be defined as unions of bit-struct and u16 #529
Comments
Some of the code does use a bitfield, but other parts assign the values directly, and using a bitfield won't match. We already have a vBgCnt struct in types.h for this. |
Exactly, which is why they should be defined as unions. It's good to know these are already defined in types.h, so I don't need to redefine them. Additionally,
|
Isnt that just a DmaFill32 ? Please use the macros defined in gba/macros.h |
Turns out it is, thanks! |
Oh, I see what you mean about making it a union. I believe that would match at the cost of being slightly more verbose because of the extra member required. If there's a significant amount of code that accesses it as a bitfield, then the change is probably worth it. If the vast majority of code accesses it as a raw u16, then it might be good to leave it as it is. |
I'm working on decompiling
rock.c
and I've noticed that the C code fordo_boulder_dust
usedREG_BG1CNT
as a bit-struct instead of an integer.Specifically, this C statement
REG_BG1CNT.priority = 1;
(used bydo_boulder_dust
) translates to:While the equivalent yet more arithmetic version
REG_BG1CNT = (REG_BG1CNT & ~3) | 1;
(used bysub_809EC38
frompokemon_summary_screen.c
) translates to:To properly decompile that function, the
REG_BGXCNT
registers must be redefined as unions, so they can be used as both integers and bit structs. Meanwhile, in order to avoid refactoring pretty much everything else in order to decompile this function, I'm using((struct BGCNT *) ®_BG1CNT)
as a temporary hack.The text was updated successfully, but these errors were encountered: