SameBoy | Accurate GB/GBC emulator |
| download: https://git.y1.nz/archives/sameboy.tar.gz | |
| README | Files | Log | Refs | LICENSE |
commit 5127cb00221e41c8f1abda77f8ecc040856a4b91 parent c63ddbe771d28462af1c96c4e75015ed4b54a45d Author: Lior Halphon <LIJI32@gmail.com> Date: Sat, 18 Dec 2021 14:51:14 +0200 Direct access to registers (#422) Diffstat:
| M | Core/gb.c | 5 | +++++ |
| M | Core/gb.h | 67 | ++++++++++++++++++++++++++++++++++++++++++++++--------------------- |
2 files changed, 51 insertions(+), 21 deletions(-)
diff --git a/Core/gb.c b/Core/gb.c @@ -1750,6 +1750,11 @@ void *GB_get_direct_access(GB_gameboy_t *gb, GB_direct_access_t access, size_t * } } +GB_registers_t *GB_get_registers(GB_gameboy_t *gb) +{ + return (GB_registers_t *)&gb->registers; +} + void GB_set_clock_multiplier(GB_gameboy_t *gb, double multiplier) { gb->clock_multiplier = multiplier; diff --git a/Core/gb.h b/Core/gb.h @@ -321,6 +321,31 @@ typedef struct { char copyright[33]; } GB_gbs_info_t; +/* Duplicated so it can remain anonymous in GB_gameboy_t */ +typedef union { + uint16_t registers[GB_REGISTERS_16_BIT]; + struct { + uint16_t af, + bc, + de, + hl, + sp; + }; + struct { +#ifdef GB_BIG_ENDIAN + uint8_t a, f, + b, c, + d, e, + h, l; +#else + uint8_t f, a, + c, b, + e, d, + l, h; +#endif + }; +} GB_registers_t; + /* When state saving, each section is dumped independently of other sections. This allows adding data to the end of the section without worrying about future compatibility. Some other changes might be "safe" as well. @@ -345,30 +370,29 @@ struct GB_gameboy_internal_s { GB_SECTION(core_state, /* Registers */ uint16_t pc; - union { - uint16_t registers[GB_REGISTERS_16_BIT]; - struct { - uint16_t af, - bc, - de, - hl, - sp; - }; - struct { + union { + uint16_t registers[GB_REGISTERS_16_BIT]; + struct { + uint16_t af, + bc, + de, + hl, + sp; + }; + struct { #ifdef GB_BIG_ENDIAN - uint8_t a, f, - b, c, - d, e, - h, l; + uint8_t a, f, + b, c, + d, e, + h, l; #else - uint8_t f, a, - c, b, - e, d, - l, h; + uint8_t f, a, + c, b, + e, d, + l, h; #endif - }; - - }; + }; + }; uint8_t ime; uint8_t interrupt_enable; uint8_t cgb_ram_bank; @@ -801,6 +825,7 @@ typedef enum { /* Returns a mutable pointer to various hardware memories. If that memory is banked, the current bank is returned at *bank, even if only a portion of the memory is banked. */ void *GB_get_direct_access(GB_gameboy_t *gb, GB_direct_access_t access, size_t *size, uint16_t *bank); +GB_registers_t *GB_get_registers(GB_gameboy_t *gb); void *GB_get_user_data(GB_gameboy_t *gb); void GB_set_user_data(GB_gameboy_t *gb, void *data);
This webpage is intended to be an accessible preview of this repository. To get a fuller picture, clone it and use the git CLI.