all repos — mgba @ 89f9a0b8b105ba0a9f1f9dc9bf65bfb7f630aa6c

mGBA Game Boy Advance Emulator

SM83: Simplify register pair access on big endian
Vicki Pfau vi@endrift.com
Sun, 26 Jul 2020 18:12:20 -0700
commit

89f9a0b8b105ba0a9f1f9dc9bf65bfb7f630aa6c

parent

a786be5bdf8dcb9c63b2a96798e98fc47688cf7b

3 files changed, 46 insertions(+), 46 deletions(-)

jump to
M CHANGESCHANGES

@@ -49,6 +49,7 @@ - Qt: Fix a race condition in the frame inspector

- Qt: Fix Italian RTC translation (fixes mgba.io/i/1798) - Qt: Add missing option for Wisdom Tree in overrides list - Util: Fix crash if PNG header fails to write + - SM83: Simplify register pair access on big endian Misc: - Debugger: Keep track of global cycle count - FFmpeg: Add looping option for GIF/APNG
M include/mgba/internal/sm83/sm83.hinclude/mgba/internal/sm83/sm83.h

@@ -74,37 +74,42 @@

void (*hitIllegal)(struct SM83Core* cpu); }; +#ifdef __BIG_ENDIAN__ +#define SM83_REGISTER_PAIR(HIGH, LOW) union { \ + struct { \ + uint8_t HIGH; \ + uint8_t LOW; \ + }; \ + uint16_t HIGH ## LOW; \ + } +#else +#define SM83_REGISTER_PAIR(HIGH, LOW) union { \ + struct { \ + uint8_t LOW; \ + uint8_t HIGH; \ + }; \ + uint16_t HIGH ## LOW; \ + } +#endif + 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; }; #pragma pack(pop) - union { - struct { - uint8_t c; - uint8_t b; - }; - uint16_t bc; - }; - union { - struct { - uint8_t e; - uint8_t d; - }; - uint16_t de; - }; - union { - struct { - uint8_t l; - uint8_t h; - }; - uint16_t hl; - }; + SM83_REGISTER_PAIR(b, c); + SM83_REGISTER_PAIR(d, e); + SM83_REGISTER_PAIR(h, l); uint16_t sp; uint16_t pc;
M src/sm83/isa-sm83.csrc/sm83/isa-sm83.c

@@ -9,33 +9,27 @@ #include <mgba/internal/sm83/emitter-sm83.h>

#include <mgba/internal/sm83/sm83.h> static inline uint16_t SM83ReadHL(struct SM83Core* cpu) { - uint16_t hl; - LOAD_16LE(hl, 0, &cpu->hl); - return hl; + return cpu->hl; } static inline void SM83WriteHL(struct SM83Core* cpu, uint16_t hl) { - STORE_16LE(hl, 0, &cpu->hl); + cpu->hl = hl; } static inline uint16_t SM83ReadBC(struct SM83Core* cpu) { - uint16_t bc; - LOAD_16LE(bc, 0, &cpu->bc); - return bc; + return cpu->bc; } static inline void SM83WriteBC(struct SM83Core* cpu, uint16_t bc) { - STORE_16LE(bc, 0, &cpu->bc); + cpu->bc = bc; } static inline uint16_t SM83ReadDE(struct SM83Core* cpu) { - uint16_t de; - LOAD_16LE(de, 0, &cpu->de); - return de; + return cpu->de; } static inline void SM83WriteDE(struct SM83Core* cpu, uint16_t de) { - STORE_16LE(de, 0, &cpu->de); + cpu->de = de; } #define DEFINE_INSTRUCTION_SM83(NAME, BODY) \

@@ -77,7 +71,7 @@

DEFINE_CONDITIONAL_INSTRUCTION_SM83(JP); DEFINE_INSTRUCTION_SM83(JPHL, - cpu->pc = SM83ReadHL(cpu); + cpu->pc = cpu->hl; cpu->memory.setActiveRegion(cpu, cpu->pc);) DEFINE_INSTRUCTION_SM83(JRFinish,

@@ -226,7 +220,7 @@

#define DEFINE_LDHL__INSTRUCTION_SM83(NAME, OPERAND) \ DEFINE_INSTRUCTION_SM83(LDHL_ ## NAME, \ cpu->bus = OPERAND; \ - cpu->index = SM83ReadHL(cpu); \ + cpu->index = cpu->hl; \ cpu->executionState = SM83_CORE_MEMORY_STORE; \ cpu->instruction = _SM83InstructionNOP;)

@@ -244,7 +238,7 @@ DEFINE_ ## NAME ## _INSTRUCTION_SM83(H, cpu->h); \

DEFINE_ ## NAME ## _INSTRUCTION_SM83(L, cpu->l); DEFINE_INSTRUCTION_SM83(LDHL_Bus, \ - cpu->index = SM83ReadHL(cpu); \ + cpu->index = cpu->hl; \ cpu->executionState = SM83_CORE_MEMORY_STORE; \ cpu->instruction = _SM83InstructionNOP;)

@@ -267,7 +261,7 @@ cpu->executionState = SM83_CORE_READ_PC;

cpu->instruction = _SM83InstructionLDHL_SPDelay;) DEFINE_INSTRUCTION_SM83(LDSP_HL, - cpu->sp = SM83ReadHL(cpu); + cpu->sp = cpu->hl; cpu->executionState = SM83_CORE_STALL;) #define DEFINE_ALU_INSTRUCTION_SM83_MEM(NAME, REG) \

@@ -378,7 +372,7 @@ cpu->executionState = SM83_CORE_READ_PC; \

cpu->instruction = _SM83InstructionLDBCDelay;) DEFINE_INSTRUCTION_SM83(LDBC_A, \ - cpu->index = SM83ReadBC(cpu); \ + cpu->index = cpu->bc; \ cpu->bus = cpu->a; \ cpu->executionState = SM83_CORE_MEMORY_STORE; \ cpu->instruction = _SM83InstructionNOP;)

@@ -393,7 +387,7 @@ cpu->executionState = SM83_CORE_READ_PC; \

cpu->instruction = _SM83InstructionLDDEDelay;) DEFINE_INSTRUCTION_SM83(LDDE_A, \ - cpu->index = SM83ReadDE(cpu); \ + cpu->index = cpu->de; \ cpu->bus = cpu->a; \ cpu->executionState = SM83_CORE_MEMORY_STORE; \ cpu->instruction = _SM83InstructionNOP;)

@@ -419,27 +413,27 @@ cpu->executionState = SM83_CORE_READ_PC; \

cpu->instruction = _SM83InstructionLDSPDelay;) DEFINE_INSTRUCTION_SM83(LDIHLA, \ - cpu->index = SM83ReadHL(cpu); \ + cpu->index = cpu->hl; \ SM83WriteHL(cpu, cpu->index + 1); \ cpu->bus = cpu->a; \ cpu->executionState = SM83_CORE_MEMORY_STORE; \ cpu->instruction = _SM83InstructionNOP;) DEFINE_INSTRUCTION_SM83(LDDHLA, \ - cpu->index = SM83ReadHL(cpu); \ + cpu->index = cpu->hl; \ SM83WriteHL(cpu, cpu->index - 1); \ cpu->bus = cpu->a; \ cpu->executionState = SM83_CORE_MEMORY_STORE; \ cpu->instruction = _SM83InstructionNOP;) DEFINE_INSTRUCTION_SM83(LDA_IHL, \ - cpu->index = SM83ReadHL(cpu); \ + cpu->index = cpu->hl; \ SM83WriteHL(cpu, cpu->index + 1); \ cpu->executionState = SM83_CORE_MEMORY_LOAD; \ cpu->instruction = _SM83InstructionLDA_Bus;) DEFINE_INSTRUCTION_SM83(LDA_DHL, \ - cpu->index = SM83ReadHL(cpu); \ + cpu->index = cpu->hl; \ SM83WriteHL(cpu, cpu->index - 1); \ cpu->executionState = SM83_CORE_MEMORY_LOAD; \ cpu->instruction = _SM83InstructionLDA_Bus;)

@@ -587,7 +581,7 @@ cpu->instruction = _SM83InstructionNOP;

cpu->executionState = SM83_CORE_MEMORY_STORE;) DEFINE_INSTRUCTION_SM83(INC_HL, - cpu->index = SM83ReadHL(cpu); + cpu->index = cpu->hl; cpu->instruction = _SM83InstructionINC_HLDelay; cpu->executionState = SM83_CORE_MEMORY_LOAD;)

@@ -601,7 +595,7 @@ cpu->instruction = _SM83InstructionNOP;

cpu->executionState = SM83_CORE_MEMORY_STORE;) DEFINE_INSTRUCTION_SM83(DEC_HL, - cpu->index = SM83ReadHL(cpu); + cpu->index = cpu->hl; cpu->instruction = _SM83InstructionDEC_HLDelay; cpu->executionState = SM83_CORE_MEMORY_LOAD;)

@@ -699,7 +693,7 @@ cpu->bus = reg; \

cpu->executionState = WB; \ cpu->instruction = _SM83InstructionNOP;) \ DEFINE_INSTRUCTION_SM83(NAME ## HL, \ - cpu->index = SM83ReadHL(cpu); \ + cpu->index = cpu->hl; \ cpu->executionState = SM83_CORE_MEMORY_LOAD; \ cpu->instruction = _SM83Instruction ## NAME ## HLDelay;) \ DEFINE_INSTRUCTION_SM83(NAME ## A, uint8_t reg = cpu->a; BODY; cpu->a = reg)