diff --git a/include/mgba/internal/arm/arm.h b/include/mgba/internal/arm/arm.h index b3268910a..f7424bf01 100644 --- a/include/mgba/internal/arm/arm.h +++ b/include/mgba/internal/arm/arm.h @@ -147,10 +147,21 @@ struct ARMInterruptHandler { 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 @@ struct ARMCore { size_t numComponents; struct mCPUComponent** components; }; +#undef ARM_REGISTER_FILE void ARMInit(struct ARMCore* cpu); void ARMDeinit(struct ARMCore* cpu); diff --git a/include/mgba/internal/sm83/sm83.h b/include/mgba/internal/sm83/sm83.h index ae2a05e01..dfd3bedbc 100644 --- a/include/mgba/internal/sm83/sm83.h +++ b/include/mgba/internal/sm83/sm83.h @@ -74,7 +74,7 @@ struct SM83InterruptHandler { 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 @@ struct SM83InterruptHandler { }; \ 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 @@ struct SM83InterruptHandler { }; \ 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 @@ struct SM83Core { size_t numComponents; struct mCPUComponent** components; }; +#undef SM83_REGISTER_FILE void SM83Init(struct SM83Core* cpu); void SM83Deinit(struct SM83Core* cpu);