Skip to content

Commit

Permalink
Fixed delaychain max fifo depth
Browse files Browse the repository at this point in the history
  • Loading branch information
ogamespec committed May 12, 2024
1 parent 297f1a6 commit 62a7298
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 89 deletions.
10 changes: 4 additions & 6 deletions common.h
Original file line number Diff line number Diff line change
Expand Up @@ -272,28 +272,26 @@ 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;
}

static inline void DELAY_Free(delaychain_t *delay)
{
free(delay->fifo);
}

static inline int DELAY_Update(delaychain_t *delay, uint64_t cycles, int pushval)
Expand Down
83 changes: 0 additions & 83 deletions savestate.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 62a7298

Please sign in to comment.