# HG changeset patch # User Michael Pavone # Date 1582857495 28800 # Node ID 2d462aa78349c9d7a7fa7a062155bbafb47735b3 # Parent 1ec6931d0a495e3543efeb9e2f0f9f4e9e474b00 Make VDP VSRAM capacity respect model selection diff -r 1ec6931d0a49 -r 2d462aa78349 genesis.c --- a/genesis.c Wed Feb 26 22:41:10 2020 -0800 +++ b/genesis.c Thu Feb 27 18:38:15 2020 -0800 @@ -1409,7 +1409,8 @@ gen->version_reg |= 1; } - gen->vdp = init_vdp_context(gen->version_reg & 0x40); + uint8_t max_vsram = !strcmp(tern_find_ptr_default(model, "vsram", "40"), "64"); + gen->vdp = init_vdp_context(gen->version_reg & 0x40, max_vsram); gen->vdp->system = &gen->header; gen->frame_end = vdp_cycles_to_frame_end(gen->vdp); char * config_cycles = tern_find_path(config, "clocks\0max_cycles\0", TVAL_PTR).ptrval; @@ -1474,7 +1475,7 @@ { write_cram_internal(gen->vdp, i, rand()); } - for (int i = 0; i < VSRAM_SIZE; i++) + for (int i = 0; i < gen->vdp->vsram_size; i++) { gen->vdp->vsram[i] = rand(); } diff -r 1ec6931d0a49 -r 2d462aa78349 gst.c --- a/gst.c Wed Feb 26 22:41:10 2020 -0800 +++ b/gst.c Thu Feb 27 18:38:15 2020 -0800 @@ -244,11 +244,11 @@ uint16_t value; write_cram_internal(context, i, (tmp_buf[i*2+1] << 8) | tmp_buf[i*2]); } - if (fread(tmp_buf, 2, VSRAM_SIZE, state_file) != VSRAM_SIZE) { + if (fread(tmp_buf, 2, MIN_VSRAM_SIZE, state_file) != MIN_VSRAM_SIZE) { fputs("Failed to read VSRAM from savestate\n", stderr); return 0; } - for (int i = 0; i < VSRAM_SIZE; i++) { + for (int i = 0; i < MIN_VSRAM_SIZE; i++) { context->vsram[i] = (tmp_buf[i*2+1] << 8) | tmp_buf[i*2]; } fseek(state_file, GST_VDP_MEM, SEEK_SET); @@ -280,12 +280,12 @@ fputs("Error writing CRAM to savestate\n", stderr); return 0; } - for (int i = 0; i < VSRAM_SIZE; i++) + for (int i = 0; i < MIN_VSRAM_SIZE; i++) { tmp_buf[i*2] = context->vsram[i]; tmp_buf[i*2+1] = context->vsram[i] >> 8; } - if (fwrite(tmp_buf, 2, VSRAM_SIZE, outfile) != VSRAM_SIZE) { + if (fwrite(tmp_buf, 2, MIN_VSRAM_SIZE, outfile) != MIN_VSRAM_SIZE) { fputs("Error writing VSRAM to savestate\n", stderr); return 0; } diff -r 1ec6931d0a49 -r 2d462aa78349 sms.c --- a/sms.c Wed Feb 26 22:41:10 2020 -0800 +++ b/sms.c Thu Feb 27 18:38:15 2020 -0800 @@ -629,7 +629,7 @@ set_gain_config(sms); - sms->vdp = init_vdp_context(0); + sms->vdp = init_vdp_context(0, 0); sms->vdp->system = &sms->header; sms->header.info.save_type = SAVE_NONE; diff -r 1ec6931d0a49 -r 2d462aa78349 vdp.c --- a/vdp.c Wed Feb 26 22:41:10 2020 -0800 +++ b/vdp.c Thu Feb 27 18:38:15 2020 -0800 @@ -144,7 +144,7 @@ static uint8_t color_map_init_done; -vdp_context *init_vdp_context(uint8_t region_pal) +vdp_context *init_vdp_context(uint8_t region_pal, uint8_t has_max_vsram) { vdp_context *context = calloc(1, sizeof(vdp_context) + VRAM_SIZE); if (headless) { @@ -158,6 +158,7 @@ context->fifo_write = 0; context->fifo_read = -1; context->regs[REG_HINT] = context->hint_counter = 0xFF; + context->vsram_size = has_max_vsram ? MAX_VSRAM_SIZE : MIN_VSRAM_SIZE; if (!color_map_init_done) { uint8_t b,g,r; @@ -938,7 +939,7 @@ break; } case VSRAM_WRITE: - if (((start->address/2) & 63) < VSRAM_SIZE) { + if (((start->address/2) & 63) < context->vsram_size) { //printf("VSRAM Write: %X to %X @ frame: %d, vcounter: %d, hslot: %d, cycle: %d\n", start->value, start->address, context->frame, context->vcounter, context->hslot, context->cycles); if (start->partial == 3) { if (start->address & 1) { @@ -1012,7 +1013,7 @@ break; case VSRAM_READ: { uint16_t address = (context->address /2) & 63; - if (address >= VSRAM_SIZE) { + if (address >= context->vsram_size) { address = 0; } context->prefetch = context->vsram[address] & VSRAM_BITS; @@ -4232,14 +4233,14 @@ } } -#define VDP_STATE_VERSION 1 +#define VDP_STATE_VERSION 2 void vdp_serialize(vdp_context *context, serialize_buffer *buf) { save_int8(buf, VDP_STATE_VERSION); save_int8(buf, VRAM_SIZE / 1024);//VRAM size in KB, needed for future proofing save_buffer8(buf, context->vdpmem, VRAM_SIZE); save_buffer16(buf, context->cram, CRAM_SIZE); - save_buffer16(buf, context->vsram, VSRAM_SIZE); + save_buffer16(buf, context->vsram, MAX_VSRAM_SIZE); save_buffer8(buf, context->sat_cache, SAT_CACHE_SIZE); for (int i = 0; i <= REG_DMASRC_H; i++) { @@ -4337,7 +4338,7 @@ { update_color_map(context, i, context->cram[i]); } - load_buffer16(buf, context->vsram, VSRAM_SIZE); + load_buffer16(buf, context->vsram, version > 1 ? MAX_VSRAM_SIZE : MIN_VSRAM_SIZE); load_buffer8(buf, context->sat_cache, SAT_CACHE_SIZE); for (int i = 0; i <= REG_DMASRC_H; i++) { diff -r 1ec6931d0a49 -r 2d462aa78349 vdp.h --- a/vdp.h Wed Feb 26 22:41:10 2020 -0800 +++ b/vdp.h Thu Feb 27 18:38:15 2020 -0800 @@ -16,7 +16,8 @@ #define SHADOW_OFFSET CRAM_SIZE #define HIGHLIGHT_OFFSET (SHADOW_OFFSET+CRAM_SIZE) #define MODE4_OFFSET (HIGHLIGHT_OFFSET+CRAM_SIZE) -#define VSRAM_SIZE 40 +#define MIN_VSRAM_SIZE 40 +#define MAX_VSRAM_SIZE 64 #define VRAM_SIZE (64*1024) #define BORDER_LEFT 13 #define BORDER_RIGHT 14 @@ -178,6 +179,7 @@ uint32_t debugcolors[1 << (3 + 1 + 1 + 1)];//3 bits for source, 1 bit for priority, 1 bit for shadow, 1 bit for hilight uint16_t cram[CRAM_SIZE]; uint32_t frame; + uint32_t vsram_size; uint8_t cd; uint8_t flags; uint8_t regs[VDP_REGS]; @@ -186,7 +188,7 @@ uint32_t pending_vint_start; uint32_t pending_hint_start; uint32_t top_offset; - uint16_t vsram[VSRAM_SIZE]; + uint16_t vsram[MAX_VSRAM_SIZE]; uint16_t vscroll_latch[2]; uint16_t vcounter; uint16_t inactive_start; @@ -239,7 +241,7 @@ -vdp_context *init_vdp_context(uint8_t region_pal); +vdp_context *init_vdp_context(uint8_t region_pal, uint8_t has_max_vsram); void vdp_free(vdp_context *context); void vdp_run_context_full(vdp_context * context, uint32_t target_cycles); void vdp_run_context(vdp_context * context, uint32_t target_cycles);