diff --git a/include/gb.h b/include/gb.h index c89eb41..60bc6d6 100644 --- a/include/gb.h +++ b/include/gb.h @@ -24,9 +24,9 @@ typedef struct gb_timers_t { bool check_fedge; } 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_close(GBTimers *timers, RIO *io); +void gb_timers_fini(GBTimers *timers, RIO *io); typedef struct gb_joypad_t { ut8 *keys; @@ -172,7 +172,7 @@ typedef struct gb_dmg_ppu_t { typedef struct gameboy_t { RIO *io; RArch *arch; - GBTimers *timers; + GBTimers timers; GBJoypad joypad; GBDMA *dma; GBPPU *ppu; diff --git a/io/timers.c b/io/timers.c index d8a04a6..36b78a9 100644 --- a/io/timers.c +++ b/io/timers.c @@ -101,33 +101,28 @@ RIOPlugin r_io_plugin_gb_timers = { .write = __write, }; -GBTimers *gb_timers_open (RIO *io) { - if (!io) { - return NULL; - } - GBTimers *timers = R_NEW0 (GBTimers); - if (!timers) { - return NULL; +bool gb_timers_init (GBTimers *timers, RIO *io) { + if (!timers || !io) { + return false; } + timers[0] = (const GBTimers){0}; char uri[64]; memset (uri, 0x00, sizeof (char) * 64); sprintf (uri, "gb_timers://%p", timers); RIODesc *desc = r_io_desc_open_plugin (io, &r_io_plugin_gb_timers, uri, R_PERM_RWX, 0); if (!desc) { - free (timers); return NULL; } 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) { return; } r_io_fd_close (io, timers->fd); - free (timers); } void gb_timers_continue (GBTimers *timers, ut32 cycles) {