diff options
-rw-r--r-- | genesis.c | 5 | ||||
-rw-r--r-- | gst.c | 8 | ||||
-rw-r--r-- | sms.c | 2 | ||||
-rw-r--r-- | vdp.c | 13 | ||||
-rw-r--r-- | vdp.h | 8 |
5 files changed, 20 insertions, 16 deletions
@@ -1409,7 +1409,8 @@ genesis_context *alloc_init_genesis(rom_info *rom, void *main_rom, void *lock_on 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 @@ genesis_context *alloc_init_genesis(rom_info *rom, void *main_rom, void *lock_on { 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(); } @@ -244,11 +244,11 @@ uint8_t vdp_load_gst(vdp_context * context, FILE * state_file) 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 @@ uint8_t vdp_save_gst(vdp_context * context, FILE * outfile) 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; } @@ -629,7 +629,7 @@ sms_context *alloc_configure_sms(system_media *media, uint32_t opts, uint8_t for 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; @@ -144,7 +144,7 @@ static void update_video_params(vdp_context *context) 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 @@ vdp_context *init_vdp_context(uint8_t region_pal) 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 @@ static void external_slot(vdp_context * context) 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 @@ static void external_slot(vdp_context * context) 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 @@ void vdp_int_ack(vdp_context * context) } } -#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 @@ void vdp_deserialize(deserialize_buffer *buf, void *vcontext) { 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++) { @@ -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 @@ typedef struct { 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 @@ typedef struct { 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 @@ typedef struct { -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); |