Mercurial > repos > blastem
comparison genesis.c @ 1946:c3c62dbf1ceb
WIP netplay support
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Wed, 29 Apr 2020 01:00:57 -0700 |
parents | b387f1c5a1d0 |
children | 2fd0a8cb1c80 |
comparison
equal
deleted
inserted
replaced
1945:ba7231d2411c | 1946:c3c62dbf1ceb |
---|---|
17 #include "gdb_remote.h" | 17 #include "gdb_remote.h" |
18 #include "saves.h" | 18 #include "saves.h" |
19 #include "bindings.h" | 19 #include "bindings.h" |
20 #include "jcart.h" | 20 #include "jcart.h" |
21 #include "config.h" | 21 #include "config.h" |
22 #include "event_log.h" | |
22 #define MCLKS_NTSC 53693175 | 23 #define MCLKS_NTSC 53693175 |
23 #define MCLKS_PAL 53203395 | 24 #define MCLKS_PAL 53203395 |
24 | 25 |
25 uint32_t MCLKS_PER_68K; | 26 uint32_t MCLKS_PER_68K; |
26 #define MCLKS_PER_YM 7 | 27 #define MCLKS_PER_YM 7 |
47 #else | 48 #else |
48 #define Z80_CYCLE current_cycle | 49 #define Z80_CYCLE current_cycle |
49 #define Z80_OPTS options | 50 #define Z80_OPTS options |
50 #endif | 51 #endif |
51 | 52 |
52 void genesis_serialize(genesis_context *gen, serialize_buffer *buf, uint32_t m68k_pc) | 53 void genesis_serialize(genesis_context *gen, serialize_buffer *buf, uint32_t m68k_pc, uint8_t all) |
53 { | 54 { |
54 start_section(buf, SECTION_68000); | 55 if (all) { |
55 m68k_serialize(gen->m68k, m68k_pc, buf); | 56 start_section(buf, SECTION_68000); |
56 end_section(buf); | 57 m68k_serialize(gen->m68k, m68k_pc, buf); |
57 | 58 end_section(buf); |
58 start_section(buf, SECTION_Z80); | 59 |
59 z80_serialize(gen->z80, buf); | 60 start_section(buf, SECTION_Z80); |
60 end_section(buf); | 61 z80_serialize(gen->z80, buf); |
62 end_section(buf); | |
63 } | |
61 | 64 |
62 start_section(buf, SECTION_VDP); | 65 start_section(buf, SECTION_VDP); |
63 vdp_serialize(gen->vdp, buf); | 66 vdp_serialize(gen->vdp, buf); |
64 end_section(buf); | 67 end_section(buf); |
65 | 68 |
69 | 72 |
70 start_section(buf, SECTION_PSG); | 73 start_section(buf, SECTION_PSG); |
71 psg_serialize(gen->psg, buf); | 74 psg_serialize(gen->psg, buf); |
72 end_section(buf); | 75 end_section(buf); |
73 | 76 |
74 start_section(buf, SECTION_GEN_BUS_ARBITER); | 77 if (all) { |
75 save_int8(buf, gen->z80->reset); | 78 start_section(buf, SECTION_GEN_BUS_ARBITER); |
76 save_int8(buf, gen->z80->busreq); | 79 save_int8(buf, gen->z80->reset); |
77 save_int16(buf, gen->z80_bank_reg); | 80 save_int8(buf, gen->z80->busreq); |
78 end_section(buf); | 81 save_int16(buf, gen->z80_bank_reg); |
79 | 82 end_section(buf); |
80 start_section(buf, SECTION_SEGA_IO_1); | 83 |
81 io_serialize(gen->io.ports, buf); | 84 start_section(buf, SECTION_SEGA_IO_1); |
82 end_section(buf); | 85 io_serialize(gen->io.ports, buf); |
83 | 86 end_section(buf); |
84 start_section(buf, SECTION_SEGA_IO_2); | 87 |
85 io_serialize(gen->io.ports + 1, buf); | 88 start_section(buf, SECTION_SEGA_IO_2); |
86 end_section(buf); | 89 io_serialize(gen->io.ports + 1, buf); |
87 | 90 end_section(buf); |
88 start_section(buf, SECTION_SEGA_IO_EXT); | 91 |
89 io_serialize(gen->io.ports + 2, buf); | 92 start_section(buf, SECTION_SEGA_IO_EXT); |
90 end_section(buf); | 93 io_serialize(gen->io.ports + 2, buf); |
91 | 94 end_section(buf); |
92 start_section(buf, SECTION_MAIN_RAM); | 95 |
93 save_int8(buf, RAM_WORDS * 2 / 1024); | 96 start_section(buf, SECTION_MAIN_RAM); |
94 save_buffer16(buf, gen->work_ram, RAM_WORDS); | 97 save_int8(buf, RAM_WORDS * 2 / 1024); |
95 end_section(buf); | 98 save_buffer16(buf, gen->work_ram, RAM_WORDS); |
96 | 99 end_section(buf); |
97 start_section(buf, SECTION_SOUND_RAM); | 100 |
98 save_int8(buf, Z80_RAM_BYTES / 1024); | 101 start_section(buf, SECTION_SOUND_RAM); |
99 save_buffer8(buf, gen->zram, Z80_RAM_BYTES); | 102 save_int8(buf, Z80_RAM_BYTES / 1024); |
100 end_section(buf); | 103 save_buffer8(buf, gen->zram, Z80_RAM_BYTES); |
101 | 104 end_section(buf); |
102 cart_serialize(&gen->header, buf); | 105 |
106 cart_serialize(&gen->header, buf); | |
107 } | |
103 } | 108 } |
104 | 109 |
105 static uint8_t *serialize(system_header *sys, size_t *size_out) | 110 static uint8_t *serialize(system_header *sys, size_t *size_out) |
106 { | 111 { |
107 genesis_context *gen = (genesis_context *)sys; | 112 genesis_context *gen = (genesis_context *)sys; |
117 } else { | 122 } else { |
118 serialize_buffer state; | 123 serialize_buffer state; |
119 init_serialize(&state); | 124 init_serialize(&state); |
120 uint32_t address = read_word(4, (void **)gen->m68k->mem_pointers, &gen->m68k->options->gen, gen->m68k) << 16; | 125 uint32_t address = read_word(4, (void **)gen->m68k->mem_pointers, &gen->m68k->options->gen, gen->m68k) << 16; |
121 address |= read_word(6, (void **)gen->m68k->mem_pointers, &gen->m68k->options->gen, gen->m68k); | 126 address |= read_word(6, (void **)gen->m68k->mem_pointers, &gen->m68k->options->gen, gen->m68k); |
122 genesis_serialize(gen, &state, address); | 127 genesis_serialize(gen, &state, address, 1); |
123 if (size_out) { | 128 if (size_out) { |
124 *size_out = state.size; | 129 *size_out = state.size; |
125 } | 130 } |
126 return state.data; | 131 return state.data; |
127 } | 132 } |
409 } | 414 } |
410 gen->psg->cycles -= deduction; | 415 gen->psg->cycles -= deduction; |
411 if (gen->reset_cycle != CYCLE_NEVER) { | 416 if (gen->reset_cycle != CYCLE_NEVER) { |
412 gen->reset_cycle -= deduction; | 417 gen->reset_cycle -= deduction; |
413 } | 418 } |
419 event_cycle_adjust(mclks, deduction); | |
414 } | 420 } |
415 } | 421 } |
416 gen->frame_end = vdp_cycles_to_frame_end(v_context); | 422 gen->frame_end = vdp_cycles_to_frame_end(v_context); |
417 context->sync_cycle = gen->frame_end; | 423 context->sync_cycle = gen->frame_end; |
418 //printf("Set sync cycle to: %d @ %d, vcounter: %d, hslot: %d\n", context->sync_cycle, context->current_cycle, v_context->vcounter, v_context->hslot); | 424 //printf("Set sync cycle to: %d @ %d, vcounter: %d, hslot: %d\n", context->sync_cycle, context->current_cycle, v_context->vcounter, v_context->hslot); |
447 { | 453 { |
448 sync_z80(z_context, z_context->current_cycle + MCLKS_PER_Z80); | 454 sync_z80(z_context, z_context->current_cycle + MCLKS_PER_Z80); |
449 } | 455 } |
450 } | 456 } |
451 #endif | 457 #endif |
452 char *save_path = slot == SERIALIZE_SLOT ? NULL : get_slot_name(&gen->header, slot, use_native_states ? "state" : "gst"); | 458 char *save_path = slot >= SERIALIZE_SLOT ? NULL : get_slot_name(&gen->header, slot, use_native_states ? "state" : "gst"); |
453 if (use_native_states || slot == SERIALIZE_SLOT) { | 459 if (use_native_states || slot >= SERIALIZE_SLOT) { |
454 serialize_buffer state; | 460 serialize_buffer state; |
455 init_serialize(&state); | 461 init_serialize(&state); |
456 genesis_serialize(gen, &state, address); | 462 genesis_serialize(gen, &state, address, slot != EVENTLOG_SLOT); |
457 if (slot == SERIALIZE_SLOT) { | 463 if (slot == SERIALIZE_SLOT) { |
458 gen->serialize_tmp = state.data; | 464 gen->serialize_tmp = state.data; |
459 gen->serialize_size = state.size; | 465 gen->serialize_size = state.size; |
460 context->sync_cycle = context->current_cycle; | 466 context->sync_cycle = context->current_cycle; |
461 context->should_return = 1; | 467 context->should_return = 1; |
468 } else if (slot == EVENTLOG_SLOT) { | |
469 event_state(context->current_cycle, &state); | |
462 } else { | 470 } else { |
463 save_to_file(&state, save_path); | 471 save_to_file(&state, save_path); |
464 free(state.data); | 472 free(state.data); |
465 } | 473 } |
466 } else { | 474 } else { |
1531 gen->max_cycles = config_cycles ? atoi(config_cycles) : DEFAULT_SYNC_INTERVAL; | 1539 gen->max_cycles = config_cycles ? atoi(config_cycles) : DEFAULT_SYNC_INTERVAL; |
1532 gen->int_latency_prev1 = MCLKS_PER_68K * 32; | 1540 gen->int_latency_prev1 = MCLKS_PER_68K * 32; |
1533 gen->int_latency_prev2 = MCLKS_PER_68K * 16; | 1541 gen->int_latency_prev2 = MCLKS_PER_68K * 16; |
1534 | 1542 |
1535 render_set_video_standard((gen->version_reg & HZ50) ? VID_PAL : VID_NTSC); | 1543 render_set_video_standard((gen->version_reg & HZ50) ? VID_PAL : VID_NTSC); |
1544 event_system_start(SYSTEM_GENESIS, (gen->version_reg & HZ50) ? VID_PAL : VID_NTSC, rom->name); | |
1536 | 1545 |
1537 gen->ym = malloc(sizeof(ym2612_context)); | 1546 gen->ym = malloc(sizeof(ym2612_context)); |
1538 char *fm = tern_find_ptr_default(model, "fm", "discrete 2612"); | 1547 char *fm = tern_find_ptr_default(model, "fm", "discrete 2612"); |
1539 if (!strcmp(fm + strlen(fm) -4, "3834")) { | 1548 if (!strcmp(fm + strlen(fm) -4, "3834")) { |
1540 system_opts |= YM_OPT_3834; | 1549 system_opts |= YM_OPT_3834; |