Mercurial > repos > blastem
comparison blastem.c @ 682:7ed1dbb48f61
Merge
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Sun, 04 Jan 2015 23:35:55 -0800 |
parents | 4996369f1463 6b248602ab84 |
children | 70de0bdf8e97 |
comparison
equal
deleted
inserted
replaced
681:e26640daf1ae | 682:7ed1dbb48f61 |
---|---|
166 | 166 |
167 #define Z80_VINT_DURATION 128 | 167 #define Z80_VINT_DURATION 128 |
168 | 168 |
169 void z80_next_int_pulse(z80_context * z_context) | 169 void z80_next_int_pulse(z80_context * z_context) |
170 { | 170 { |
171 genesis_context * gen = z_context->system; | 171 genesis_context * gen = z_context->system; |
172 z_context->int_pulse_start = vdp_next_vint_z80(gen->vdp); | 172 z_context->int_pulse_start = vdp_next_vint_z80(gen->vdp); |
173 z_context->int_pulse_end = z_context->int_pulse_start + Z80_VINT_DURATION * MCLKS_PER_Z80; | 173 z_context->int_pulse_end = z_context->int_pulse_start + Z80_VINT_DURATION * MCLKS_PER_Z80; |
174 } | 174 } |
175 | 175 |
176 void sync_z80(z80_context * z_context, uint32_t mclks) | 176 void sync_z80(z80_context * z_context, uint32_t mclks) |
177 { | 177 { |
178 #ifndef NO_Z80 | 178 #ifndef NO_Z80 |
179 if (z80_enabled) { | 179 if (z80_enabled) { |
208 genesis_context * gen = context->system; | 208 genesis_context * gen = context->system; |
209 vdp_context * v_context = gen->vdp; | 209 vdp_context * v_context = gen->vdp; |
210 z80_context * z_context = gen->z80; | 210 z80_context * z_context = gen->z80; |
211 uint32_t mclks = context->current_cycle; | 211 uint32_t mclks = context->current_cycle; |
212 sync_z80(z_context, mclks); | 212 sync_z80(z_context, mclks); |
213 sync_sound(gen, mclks); | 213 sync_sound(gen, mclks); |
214 if (mclks >= mclk_target) { | 214 if (mclks >= mclk_target) { |
215 vdp_run_context(v_context, mclk_target); | 215 vdp_run_context(v_context, mclk_target); |
216 if (vdp_is_frame_over(v_context)) { | 216 if (vdp_is_frame_over(v_context)) { |
217 //printf("reached frame end | MCLK Cycles: %d, Target: %d, VDP cycles: %d\n", mclks, mclk_target, v_context->cycles); | 217 //printf("reached frame end | MCLK Cycles: %d, Target: %d, VDP cycles: %d\n", mclks, mclk_target, v_context->cycles); |
218 | 218 |
219 if (!headless) { | 219 if (!headless) { |
220 break_on_sync |= wait_render_frame(v_context, frame_limit); | 220 break_on_sync |= wait_render_frame(v_context, frame_limit); |
221 } else if(exit_after){ | 221 } else if(exit_after){ |
222 --exit_after; | 222 --exit_after; |
223 if (!exit_after) { | 223 if (!exit_after) { |
224 exit(0); | 224 exit(0); |
225 } | 225 } |
226 } | 226 } |
227 frame++; | 227 frame++; |
228 mclks -= mclk_target; | 228 mclks -= mclk_target; |
229 vdp_adjust_cycles(v_context, mclk_target); | 229 vdp_adjust_cycles(v_context, mclk_target); |
230 io_adjust_cycles(gen->ports, context->current_cycle, mclk_target); | 230 io_adjust_cycles(gen->ports, context->current_cycle, mclk_target); |
231 io_adjust_cycles(gen->ports+1, context->current_cycle, mclk_target); | 231 io_adjust_cycles(gen->ports+1, context->current_cycle, mclk_target); |
232 io_adjust_cycles(gen->ports+2, context->current_cycle, mclk_target); | 232 io_adjust_cycles(gen->ports+2, context->current_cycle, mclk_target); |
237 if (gen->ym->write_cycle != CYCLE_NEVER) { | 237 if (gen->ym->write_cycle != CYCLE_NEVER) { |
238 gen->ym->write_cycle = gen->ym->write_cycle >= mclk_target ? gen->ym->write_cycle - mclk_target : 0; | 238 gen->ym->write_cycle = gen->ym->write_cycle >= mclk_target ? gen->ym->write_cycle - mclk_target : 0; |
239 } | 239 } |
240 if (mclks) { | 240 if (mclks) { |
241 vdp_run_context(v_context, mclks); | 241 vdp_run_context(v_context, mclks); |
242 } | 242 } |
243 mclk_target = vdp_cycles_to_frame_end(v_context); | 243 mclk_target = vdp_cycles_to_frame_end(v_context); |
244 context->sync_cycle = mclk_target; | 244 context->sync_cycle = mclk_target; |
245 } else { | 245 } else { |
246 vdp_run_context(v_context, mclks); | 246 vdp_run_context(v_context, mclks); |
247 mclk_target = vdp_cycles_to_frame_end(v_context); | 247 mclk_target = vdp_cycles_to_frame_end(v_context); |
390 value = vdp_control_port_read(v_context); | 390 value = vdp_control_port_read(v_context); |
391 } else { | 391 } else { |
392 value = vdp_hv_counter_read(v_context); | 392 value = vdp_hv_counter_read(v_context); |
393 //printf("HV Counter: %X at cycle %d\n", value, v_context->cycles); | 393 //printf("HV Counter: %X at cycle %d\n", value, v_context->cycles); |
394 } | 394 } |
395 } else if (vdp_port < 0x18) { | 395 } else if (vdp_port < 0x18){ |
396 printf("Illegal read from PSG port %X\n", vdp_port); | 396 printf("Illegal read from PSG port %X\n", vdp_port); |
397 exit(1); | 397 exit(1); |
398 } else { | 398 } else { |
399 value = vdp_test_port_read(v_context); | 399 value = vdp_test_port_read(v_context); |
400 } | 400 } |
516 gen->z80->busack = 1; | 516 gen->z80->busack = 1; |
517 } | 517 } |
518 } else { | 518 } else { |
519 if (gen->z80->busreq) { | 519 if (gen->z80->busreq) { |
520 dputs("releasing z80 bus"); | 520 dputs("releasing z80 bus"); |
521 #ifdef DO_DEBUG_PRINT | 521 #ifdef DO_DEBUG_PRINT |
522 char fname[20]; | 522 char fname[20]; |
523 sprintf(fname, "zram-%d", zram_counter++); | 523 sprintf(fname, "zram-%d", zram_counter++); |
524 FILE * f = fopen(fname, "wb"); | 524 FILE * f = fopen(fname, "wb"); |
525 fwrite(z80_ram, 1, sizeof(z80_ram), f); | 525 fwrite(z80_ram, 1, sizeof(z80_ram), f); |
526 fclose(f); | 526 fclose(f); |
527 #endif | 527 #endif |
528 } | 528 } |
529 if (z80_enabled) { | 529 if (z80_enabled) { |
530 z80_clear_busreq(gen->z80, context->current_cycle); | 530 z80_clear_busreq(gen->z80, context->current_cycle); |
531 } else { | 531 } else { |
532 gen->z80->busack = 0; | 532 gen->z80->busack = 0; |