Minor refactor of GBTimers lifecycles functions

This commit is contained in:
condret 2024-11-05 18:53:42 +01:00
parent cc18c20435
commit d32386b621
2 changed files with 9 additions and 14 deletions

View File

@ -24,9 +24,9 @@ typedef struct gb_timers_t {
bool check_fedge; bool check_fedge;
} GBTimers; } GBTimers;
GBTimers *gb_timers_open(RIO *io); bool gb_timers_init(GBTimers *timers, RIO *io);
void gb_timers_continue(GBTimers *timers, ut32 cycles); void gb_timers_continue(GBTimers *timers, ut32 cycles);
void gb_timers_close(GBTimers *timers, RIO *io); void gb_timers_fini(GBTimers *timers, RIO *io);
typedef struct gb_joypad_t { typedef struct gb_joypad_t {
ut8 *keys; ut8 *keys;
@ -172,7 +172,7 @@ typedef struct gb_dmg_ppu_t {
typedef struct gameboy_t { typedef struct gameboy_t {
RIO *io; RIO *io;
RArch *arch; RArch *arch;
GBTimers *timers; GBTimers timers;
GBJoypad joypad; GBJoypad joypad;
GBDMA *dma; GBDMA *dma;
GBPPU *ppu; GBPPU *ppu;

View File

@ -101,33 +101,28 @@ RIOPlugin r_io_plugin_gb_timers = {
.write = __write, .write = __write,
}; };
GBTimers *gb_timers_open (RIO *io) { bool gb_timers_init (GBTimers *timers, RIO *io) {
if (!io) { if (!timers || !io) {
return NULL; return false;
}
GBTimers *timers = R_NEW0 (GBTimers);
if (!timers) {
return NULL;
} }
timers[0] = (const GBTimers){0};
char uri[64]; char uri[64];
memset (uri, 0x00, sizeof (char) * 64); memset (uri, 0x00, sizeof (char) * 64);
sprintf (uri, "gb_timers://%p", timers); sprintf (uri, "gb_timers://%p", timers);
RIODesc *desc = r_io_desc_open_plugin (io, &r_io_plugin_gb_timers, RIODesc *desc = r_io_desc_open_plugin (io, &r_io_plugin_gb_timers,
uri, R_PERM_RWX, 0); uri, R_PERM_RWX, 0);
if (!desc) { if (!desc) {
free (timers);
return NULL; return NULL;
} }
timers->fd = desc->fd; timers->fd = desc->fd;
return timers; return true;
} }
void gb_timers_close (GBTimers *timers, RIO *io) { void gb_timers_fini (GBTimers *timers, RIO *io) {
if (!timers || !io) { if (!timers || !io) {
return; return;
} }
r_io_fd_close (io, timers->fd); r_io_fd_close (io, timers->fd);
free (timers);
} }
void gb_timers_continue (GBTimers *timers, ut32 cycles) { void gb_timers_continue (GBTimers *timers, ut32 cycles) {