diff --git a/common.h b/common.h index 7480152..6dd5df0 100644 --- a/common.h +++ b/common.h @@ -272,20 +272,19 @@ static inline void SDFFSR_Update(sdffsr_t *dff, int clk, int val, int set, int r } } -// Does not require packing or other alignment as it is serialized by special processing. +#pragma pack(push, 1) +#define MAX_DELAYCHAIN_DEPTH 10 typedef struct { uint64_t lastcycle; int items; int pos; int lastval; - int *fifo; + int fifo[MAX_DELAYCHAIN_DEPTH]; } delaychain_t; +#pragma pack(pop) static inline void DELAY_Init(delaychain_t *delay, int delaycycles) { - delay->fifo = (int*)malloc((delaycycles + 1) * sizeof(int)); - if (!delay->fifo) - return; delay->lastcycle = 0; delay->items = delaycycles + 1; delay->pos = 0; @@ -293,7 +292,6 @@ static inline void DELAY_Init(delaychain_t *delay, int delaycycles) static inline void DELAY_Free(delaychain_t *delay) { - free(delay->fifo); } static inline int DELAY_Update(delaychain_t *delay, uint64_t cycles, int pushval) diff --git a/savestate.c b/savestate.c index 86887d2..8108d31 100644 --- a/savestate.c +++ b/savestate.c @@ -22,55 +22,6 @@ int load_blob(void* ptr, size_t size, FILE* f) return 0; } -static int save_delay(delaychain_t* delay_ptr, FILE* f) -{ - size_t n; - - if (save_blob(&delay_ptr->lastcycle, sizeof(delay_ptr->lastcycle), f)) - return -1; - if (save_blob(&delay_ptr->items, sizeof(delay_ptr->items), f)) - return -1; - if (save_blob(&delay_ptr->pos, sizeof(delay_ptr->pos), f)) - return -1; - if (save_blob(&delay_ptr->lastval, sizeof(delay_ptr->lastval), f)) - return -1; - - for (n = 0; n < delay_ptr->items; n++) { - if (save_blob(&delay_ptr->fifo[n], sizeof(delay_ptr->fifo[n]), f)) - return -1; - } - return 0; -} - -static int load_delay(delaychain_t* delay_ptr, FILE* f) -{ - size_t n; - - if (load_blob(&delay_ptr->lastcycle, sizeof(delay_ptr->lastcycle), f)) - return -1; - if (load_blob(&delay_ptr->items, sizeof(delay_ptr->items), f)) - return -1; - if (load_blob(&delay_ptr->pos, sizeof(delay_ptr->pos), f)) - return -1; - if (load_blob(&delay_ptr->lastval, sizeof(delay_ptr->lastval), f)) - return -1; - - if (delay_ptr->fifo) { - free(delay_ptr->fifo); - delay_ptr->fifo = 0; - } - - delay_ptr->fifo = (int*)malloc(delay_ptr->items * sizeof(int)); - if (!delay_ptr->fifo) - return -1; - - for (n = 0; n < delay_ptr->items; n++) { - if (load_blob(&delay_ptr->fifo[n], sizeof(delay_ptr->fifo[n]), f)) - return -1; - } - return 0; -} - int save_state(const char* filename) { FILE* f; @@ -117,23 +68,6 @@ int save_state(const char* filename) if (save_blob(&ym, sizeof(ym), f)) return -1; - // Arbiter Delays - if (save_delay(&ym.arb.d1, f)) - return -1; - if (save_delay(&ym.arb.d2, f)) - return -1; - if (save_delay(&ym.arb.d3, f)) - return -1; - if (save_delay(&ym.arb.d4, f)) - return -1; - if (save_delay(&ym.arb.d5, f)) - return -1; - if (save_delay(&ym.arb.d6, f)) - return -1; - if (save_delay(&ym.arb.d7, f)) - return -1; - if (save_delay(&ym.arb.d8, f)) - return -1; // Cart @@ -192,23 +126,6 @@ int load_state(const char* filename) if (load_blob(&ym, sizeof(ym), f)) return -1; - // Arbiter Delays - if (load_delay(&ym.arb.d1, f)) - return -1; - if (load_delay(&ym.arb.d2, f)) - return -1; - if (load_delay(&ym.arb.d3, f)) - return -1; - if (load_delay(&ym.arb.d4, f)) - return -1; - if (load_delay(&ym.arb.d5, f)) - return -1; - if (load_delay(&ym.arb.d6, f)) - return -1; - if (load_delay(&ym.arb.d7, f)) - return -1; - if (load_delay(&ym.arb.d8, f)) - return -1; // Cart