SameBoy | Accurate GB/GBC emulator |
| download: https://git.y1.nz/archives/sameboy.tar.gz | |
| README | Files | Log | Refs | LICENSE |
commit e1be593a65ee39a5740a8b2a2d1a0f1290d6bea2 parent c0d6c3d6bb17236a42f06b59f0545773656146ca Author: Lior Halphon <LIJI32@gmail.com> Date: Sun, 5 Feb 2023 22:59:26 +0200 Expose and use the built-in accessory type enum Diffstat:
| M | Cocoa/Document.m | 14 | +++----------- |
| M | Core/gb.c | 5 | +++++ |
| M | Core/gb.h | 13 | ++++++++----- |
3 files changed, 16 insertions(+), 16 deletions(-)
diff --git a/Cocoa/Document.m b/Cocoa/Document.m @@ -90,7 +90,6 @@ enum model { GB_oam_info_t _oamInfo[40]; NSMutableData *currentPrinterImageData; - enum {GBAccessoryNone, GBAccessoryPrinter, GBAccessoryWorkboy, GBAccessoryLinkCable} accessory; bool rom_warning_issued; @@ -1213,13 +1212,13 @@ static bool is_path_writeable(const char *path) } } else if ([anItem action] == @selector(disconnectAllAccessories:)) { - [(NSMenuItem *)anItem setState:accessory == GBAccessoryNone]; + [(NSMenuItem *)anItem setState:GB_get_built_in_accessory(&gb) == GB_ACCESSORY_NONE && !self.partner]; } else if ([anItem action] == @selector(connectPrinter:)) { - [(NSMenuItem *)anItem setState:accessory == GBAccessoryPrinter]; + [(NSMenuItem *)anItem setState:GB_get_built_in_accessory(&gb) == GB_ACCESSORY_PRINTER]; } else if ([anItem action] == @selector(connectWorkboy:)) { - [(NSMenuItem *)anItem setState:accessory == GBAccessoryWorkboy]; + [(NSMenuItem *)anItem setState:GB_get_built_in_accessory(&gb) == GB_ACCESSORY_WORKBOY]; } else if ([anItem action] == @selector(connectLinkCable:)) { [(NSMenuItem *)anItem setState:[(NSMenuItem *)anItem representedObject] == master || @@ -2139,7 +2138,6 @@ static bool is_path_writeable(const char *path) { [self disconnectLinkCable]; [self performAtomicBlock:^{ - accessory = GBAccessoryNone; GB_disconnect_serial(&gb); }]; } @@ -2148,7 +2146,6 @@ static bool is_path_writeable(const char *path) { [self disconnectLinkCable]; [self performAtomicBlock:^{ - accessory = GBAccessoryPrinter; GB_connect_printer(&gb, printImage, printDone); }]; } @@ -2157,7 +2154,6 @@ static bool is_path_writeable(const char *path) { [self disconnectLinkCable]; [self performAtomicBlock:^{ - accessory = GBAccessoryWorkboy; GB_connect_workboy(&gb, setWorkboyTime, getWorkboyTime); }]; } @@ -2320,8 +2316,6 @@ static bool is_path_writeable(const char *path) } GB_set_turbo_mode(&gb, false, false); GB_set_turbo_mode(&partner->gb, false, false); - partner->accessory = GBAccessoryNone; - accessory = GBAccessoryNone; } } @@ -2338,8 +2332,6 @@ static bool is_path_writeable(const char *path) slave = partner; partner->master = self; linkOffset = 0; - partner->accessory = GBAccessoryLinkCable; - accessory = GBAccessoryLinkCable; GB_set_serial_transfer_bit_start_callback(&gb, linkCableBitStart); GB_set_serial_transfer_bit_start_callback(&partner->gb, linkCableBitStart); GB_set_serial_transfer_bit_end_callback(&gb, linkCableBitEnd); diff --git a/Core/gb.c b/Core/gb.c @@ -1387,6 +1387,11 @@ void GB_disconnect_serial(GB_gameboy_t *gb) memset(GB_GET_SECTION(gb, accessory), 0, GB_SECTION_SIZE(accessory)); } +GB_accessory_t GB_get_built_in_accessory(GB_gameboy_t *gb) +{ + return gb->accessory; +} + bool GB_is_inited(GB_gameboy_t *gb) { return gb->magic == state_magic(); diff --git a/Core/gb.h b/Core/gb.h @@ -336,6 +336,12 @@ typedef union { }; } GB_registers_t; +typedef GB_ENUM(uint8_t, { + GB_ACCESSORY_NONE, + GB_ACCESSORY_PRINTER, + GB_ACCESSORY_WORKBOY, +}) GB_accessory_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. @@ -637,11 +643,7 @@ struct GB_gameboy_internal_s { ) GB_SECTION(accessory, - GB_ENUM(uint8_t, { - GB_ACCESSORY_NONE, - GB_ACCESSORY_PRINTER, - GB_ACCESSORY_WORKBOY, - }) accessory; + GB_accessory_t accessory; union { GB_printer_t printer; GB_workboy_t workboy; @@ -951,6 +953,7 @@ bool GB_serial_get_data_bit(GB_gameboy_t *gb); void GB_serial_set_data_bit(GB_gameboy_t *gb, bool data); void GB_disconnect_serial(GB_gameboy_t *gb); +GB_accessory_t GB_get_built_in_accessory(GB_gameboy_t *gb); /* For cartridges with an alarm clock */ unsigned GB_time_to_alarm(GB_gameboy_t *gb); // 0 if no alarm
This webpage is intended to be an accessible preview of this repository. To get a fuller picture, clone it and use the git CLI.