ARM/SM83: Wrap register files in structs
Adam Higerd chighland@gmail.com
Sun, 26 Jul 2020 16:55:33 -0500
2 files changed,
50 insertions(+),
19 deletions(-)
M
include/mgba/internal/arm/arm.h
→
include/mgba/internal/arm/arm.h
@@ -147,10 +147,21 @@
void (*hitStub)(struct ARMCore* cpu, uint32_t opcode); }; +#define ARM_REGISTER_FILE struct { \ + int32_t gprs[16]; \ + union PSR cpsr; \ + union PSR spsr; \ +} + +struct ARMRegisterFile { + ARM_REGISTER_FILE; +}; + struct ARMCore { - int32_t gprs[16]; - union PSR cpsr; - union PSR spsr; + union { + struct ARMRegisterFile regs; + ARM_REGISTER_FILE; + }; int32_t cycles; int32_t nextEvent;@@ -174,6 +185,7 @@
size_t numComponents; struct mCPUComponent** components; }; +#undef ARM_REGISTER_FILE void ARMInit(struct ARMCore* cpu); void ARMDeinit(struct ARMCore* cpu);
M
include/mgba/internal/sm83/sm83.h
→
include/mgba/internal/sm83/sm83.h
@@ -74,7 +74,7 @@
void (*hitIllegal)(struct SM83Core* cpu); }; -#ifdef __BIG_ENDIAN__ +#if defined(__BIG_ENDIAN__) #define SM83_REGISTER_PAIR(HIGH, LOW) union { \ struct { \ uint8_t HIGH; \@@ -82,6 +82,14 @@ uint8_t LOW; \
}; \ uint16_t HIGH ## LOW; \ } + +#define SM83_AF_REGISTER union { \ + struct { \ + uint8_t a; \ + union FlagRegister f; \ + }; \ + uint16_t af; \ + } #else #define SM83_REGISTER_PAIR(HIGH, LOW) union { \ struct { \@@ -90,28 +98,38 @@ uint8_t HIGH; \
}; \ uint16_t HIGH ## LOW; \ } + +#define SM83_AF_REGISTER union { \ + struct { \ + union FlagRegister f; \ + uint8_t a; \ + }; \ + uint16_t af; \ + } #endif +#define SM83_REGISTER_FILE struct { \ + SM83_AF_REGISTER; \ + SM83_REGISTER_PAIR(b, c); \ + SM83_REGISTER_PAIR(d, e); \ + SM83_REGISTER_PAIR(h, l); \ + uint16_t sp; \ + uint16_t pc; \ +} + +struct SM83RegisterFile { +#pragma pack(push, 1) + SM83_REGISTER_FILE; +#pragma pack(pop) +}; + struct SM83Core { #pragma pack(push, 1) union { - struct { -#ifdef __BIG_ENDIAN__ - uint8_t a; - union FlagRegister f; -#else - union FlagRegister f; - uint8_t a; -#endif - }; - uint16_t af; + struct SM83RegisterFile regs; + SM83_REGISTER_FILE; }; #pragma pack(pop) - SM83_REGISTER_PAIR(b, c); - SM83_REGISTER_PAIR(d, e); - SM83_REGISTER_PAIR(h, l); - uint16_t sp; - uint16_t pc; uint16_t index;@@ -134,6 +152,7 @@
size_t numComponents; struct mCPUComponent** components; }; +#undef SM83_REGISTER_FILE void SM83Init(struct SM83Core* cpu); void SM83Deinit(struct SM83Core* cpu);