comparison blastem.c @ 505:b7b7a1cab44a

The local clone on my laptop got messed up and some changes had not been pushed. This commit represents the status of the working copy from that clone. It unfortunately contains some changes that I did not intend to commit yet, but this seems like the best option at the moment.
author Michael Pavone <pavone@retrodev.com>
date Mon, 06 Jan 2014 22:54:05 -0800
parents e1355aa80f4d
children b976c6d6e5fb
comparison
equal deleted inserted replaced
504:7b0df1aaf384 505:b7b7a1cab44a
41 uint16_t cart[CARTRIDGE_WORDS]; 41 uint16_t cart[CARTRIDGE_WORDS];
42 uint16_t ram[RAM_WORDS]; 42 uint16_t ram[RAM_WORDS];
43 uint8_t z80_ram[Z80_RAM_BYTES]; 43 uint8_t z80_ram[Z80_RAM_BYTES];
44 44
45 int headless = 0; 45 int headless = 0;
46 int exit_after = 0;
46 int z80_enabled = 1; 47 int z80_enabled = 1;
47 int frame_limit = 0; 48 int frame_limit = 0;
48 49
49 tern_node * config; 50 tern_node * config;
50 51
184 185
185 void sync_z80(z80_context * z_context, uint32_t mclks) 186 void sync_z80(z80_context * z_context, uint32_t mclks)
186 { 187 {
187 if (z80_enabled && !reset && !busreq) { 188 if (z80_enabled && !reset && !busreq) {
188 genesis_context * gen = z_context->system; 189 genesis_context * gen = z_context->system;
189 if (need_reset) {
190 z80_reset(z_context);
191 need_reset = 0;
192 }
193 z_context->sync_cycle = mclks / MCLKS_PER_Z80; 190 z_context->sync_cycle = mclks / MCLKS_PER_Z80;
194 uint32_t vint_cycle = vdp_next_vint_z80(gen->vdp) / MCLKS_PER_Z80; 191 if (z_context->current_cycle < z_context->sync_cycle) {
195 while (z_context->current_cycle < z_context->sync_cycle) { 192 if (need_reset) {
196 if (z_context->iff1 && z_context->current_cycle < (vint_cycle + Z80_VINT_DURATION)) { 193 z80_reset(z_context);
197 z_context->int_cycle = vint_cycle < z_context->int_enable_cycle ? z_context->int_enable_cycle : vint_cycle; 194 need_reset = 0;
198 } 195 }
199 z_context->target_cycle = z_context->sync_cycle < z_context->int_cycle ? z_context->sync_cycle : z_context->int_cycle; 196 uint32_t vint_cycle = vdp_next_vint_z80(gen->vdp) / MCLKS_PER_Z80;
200 dprintf("Running Z80 from cycle %d to cycle %d. Native PC: %p\n", z_context->current_cycle, z_context->sync_cycle, z_context->native_pc); 197 while (z_context->current_cycle < z_context->sync_cycle) {
201 z80_run(z_context); 198 if (z_context->iff1 && z_context->current_cycle < (vint_cycle + Z80_VINT_DURATION)) {
202 dprintf("Z80 ran to cycle %d\n", z_context->current_cycle); 199 z_context->int_cycle = vint_cycle < z_context->int_enable_cycle ? z_context->int_enable_cycle : vint_cycle;
200 }
201 z_context->target_cycle = z_context->sync_cycle < z_context->int_cycle ? z_context->sync_cycle : z_context->int_cycle;
202 dprintf("Running Z80 from cycle %d to cycle %d. Native PC: %p\n", z_context->current_cycle, z_context->sync_cycle, z_context->native_pc);
203 z80_run(z_context);
204 dprintf("Z80 ran to cycle %d\n", z_context->current_cycle);
205 }
203 } 206 }
204 } else { 207 } else {
205 z_context->current_cycle = mclks / MCLKS_PER_Z80; 208 z_context->current_cycle = mclks / MCLKS_PER_Z80;
206 } 209 }
207 } 210 }
241 //printf("reached frame end | 68K Cycles: %d, MCLK Cycles: %d\n", context->current_cycle, mclks); 244 //printf("reached frame end | 68K Cycles: %d, MCLK Cycles: %d\n", context->current_cycle, mclks);
242 vdp_run_context(v_context, mclks_per_frame); 245 vdp_run_context(v_context, mclks_per_frame);
243 246
244 if (!headless) { 247 if (!headless) {
245 break_on_sync |= wait_render_frame(v_context, frame_limit); 248 break_on_sync |= wait_render_frame(v_context, frame_limit);
249 } else if(exit_after){
250 --exit_after;
251 if (!exit_after) {
252 exit(0);
253 }
246 } 254 }
247 frame++; 255 frame++;
248 mclks -= mclks_per_frame; 256 mclks -= mclks_per_frame;
249 vdp_adjust_cycles(v_context, mclks_per_frame); 257 vdp_adjust_cycles(v_context, mclks_per_frame);
250 io_adjust_cycles(gen->ports, context->current_cycle, mclks_per_frame/MCLKS_PER_68K); 258 io_adjust_cycles(gen->ports, context->current_cycle, mclks_per_frame/MCLKS_PER_68K);
313 vdp_run_dma_done(v_context, mclks_per_frame); 321 vdp_run_dma_done(v_context, mclks_per_frame);
314 if (v_context->cycles >= mclks_per_frame) { 322 if (v_context->cycles >= mclks_per_frame) {
315 if (!headless) { 323 if (!headless) {
316 //printf("reached frame end | 68K Cycles: %d, MCLK Cycles: %d\n", context->current_cycle, v_context->cycles); 324 //printf("reached frame end | 68K Cycles: %d, MCLK Cycles: %d\n", context->current_cycle, v_context->cycles);
317 wait_render_frame(v_context, frame_limit); 325 wait_render_frame(v_context, frame_limit);
326 } else if(exit_after){
327 --exit_after;
328 if (!exit_after) {
329 exit(0);
330 }
318 } 331 }
319 vdp_adjust_cycles(v_context, mclks_per_frame); 332 vdp_adjust_cycles(v_context, mclks_per_frame);
320 genesis_context * gen = context->system; 333 genesis_context * gen = context->system;
321 io_adjust_cycles(gen->ports, v_context->cycles/MCLKS_PER_68K, mclks_per_frame/MCLKS_PER_68K); 334 io_adjust_cycles(gen->ports, v_context->cycles/MCLKS_PER_68K, mclks_per_frame/MCLKS_PER_68K);
322 io_adjust_cycles(gen->ports+1, v_context->cycles/MCLKS_PER_68K, mclks_per_frame/MCLKS_PER_68K); 335 io_adjust_cycles(gen->ports+1, v_context->cycles/MCLKS_PER_68K, mclks_per_frame/MCLKS_PER_68K);
340 while(v_context->flags & FLAG_DMA_RUN) { 353 while(v_context->flags & FLAG_DMA_RUN) {
341 vdp_run_dma_done(v_context, mclks_per_frame); 354 vdp_run_dma_done(v_context, mclks_per_frame);
342 if (v_context->cycles >= mclks_per_frame) { 355 if (v_context->cycles >= mclks_per_frame) {
343 if (!headless) { 356 if (!headless) {
344 wait_render_frame(v_context, frame_limit); 357 wait_render_frame(v_context, frame_limit);
358 } else if(exit_after){
359 --exit_after;
360 if (!exit_after) {
361 exit(0);
362 }
345 } 363 }
346 vdp_adjust_cycles(v_context, mclks_per_frame); 364 vdp_adjust_cycles(v_context, mclks_per_frame);
347 genesis_context * gen = context->system; 365 genesis_context * gen = context->system;
348 io_adjust_cycles(gen->ports, v_context->cycles/MCLKS_PER_68K, mclks_per_frame/MCLKS_PER_68K); 366 io_adjust_cycles(gen->ports, v_context->cycles/MCLKS_PER_68K, mclks_per_frame/MCLKS_PER_68K);
349 io_adjust_cycles(gen->ports+1, v_context->cycles/MCLKS_PER_68K, mclks_per_frame/MCLKS_PER_68K); 367 io_adjust_cycles(gen->ports+1, v_context->cycles/MCLKS_PER_68K, mclks_per_frame/MCLKS_PER_68K);
568 } 586 }
569 //TODO: Deal with the scenario in which reset is not asserted long enough 587 //TODO: Deal with the scenario in which reset is not asserted long enough
570 if (reset) { 588 if (reset) {
571 need_reset = 1; 589 need_reset = 1;
572 //TODO: Add necessary delay between release of reset and start of execution 590 //TODO: Add necessary delay between release of reset and start of execution
573 gen->z80->current_cycle = (context->current_cycle * MCLKS_PER_68K) / MCLKS_PER_Z80; 591 gen->z80->current_cycle = (context->current_cycle * MCLKS_PER_68K) / MCLKS_PER_Z80 + 16;
574 } 592 }
575 reset = 0; 593 reset = 0;
576 } else { 594 } else {
577 reset = 1; 595 reset = 1;
578 } 596 }
1777 char * statefile = NULL; 1795 char * statefile = NULL;
1778 uint8_t fullscreen = 0, use_gl = 1; 1796 uint8_t fullscreen = 0, use_gl = 1;
1779 for (int i = 1; i < argc; i++) { 1797 for (int i = 1; i < argc; i++) {
1780 if (argv[i][0] == '-') { 1798 if (argv[i][0] == '-') {
1781 switch(argv[i][1]) { 1799 switch(argv[i][1]) {
1800 case 'b':
1801 i++;
1802 if (i >= argc) {
1803 fputs("-b must be followed by a frame count\n", stderr);
1804 return 1;
1805 }
1806 headless = 1;
1807 exit_after = atoi(argv[i]);
1808 break;
1782 case 'd': 1809 case 'd':
1783 debug = 1; 1810 debug = 1;
1784 break; 1811 break;
1785 case 'f': 1812 case 'f':
1786 fullscreen = 1; 1813 fullscreen = 1;