ARM/SM83: Wrap register files in structs

This commit is contained in:
Adam Higerd 2020-07-26 16:55:33 -05:00
parent 588ca83855
commit d156e48da2
2 changed files with 50 additions and 19 deletions

View File

@ -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);

View File

@ -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);