diff blastem.c @ 447:e730fc040169

Fix performance regression from stop instruction work
author Mike Pavone <pavone@retrodev.com>
date Sat, 20 Jul 2013 23:40:28 -0700
parents 1e828ed04a7c
children 3758bcdae5de b7c3b2d22858
line wrap: on
line diff
--- a/blastem.c	Fri Jul 19 22:44:00 2013 -0700
+++ b/blastem.c	Sat Jul 20 23:40:28 2013 -0700
@@ -52,7 +52,7 @@
 	uint8_t block[SMD_BLOCK_SIZE];
 	filesize -= SMD_HEADER_SIZE;
 	fseek(f, SMD_HEADER_SIZE, SEEK_SET);
-	
+
 	uint16_t * dst = cart;
 	while (filesize > 0) {
 		fread(block, 1, SMD_BLOCK_SIZE, f);
@@ -139,15 +139,15 @@
 				if (next_hint < context->int_cycle) {
 					context->int_cycle = next_hint;
 					context->int_num = 4;
-			
+
 				}
 			}
 		}
 	}
 
 	context->target_cycle = context->int_cycle < context->sync_cycle ? context->int_cycle : context->sync_cycle;
-	/*printf("Cyc: %d, Trgt: %d, Int Cyc: %d, Int: %d, Mask: %X, V: %d, H: %d, HICount: %d, HReg: %d, Line: %d\n", 
-		context->current_cycle, context->target_cycle, context->int_cycle, context->int_num, (context->status & 0x7), 
+	/*printf("Cyc: %d, Trgt: %d, Int Cyc: %d, Int: %d, Mask: %X, V: %d, H: %d, HICount: %d, HReg: %d, Line: %d\n",
+		context->current_cycle, context->target_cycle, context->int_cycle, context->int_num, (context->status & 0x7),
 		v_context->regs[REG_MODE_2] & 0x20, v_context->regs[REG_MODE_1] & 0x10, v_context->hint_counter, v_context->regs[REG_HINT], v_context->cycles / MCLKS_LINE);*/
 }
 
@@ -199,7 +199,7 @@
 	//printf("YM | Cycle: %d, bpos: %d, PSG | Cycle: %d, bpos: %d\n", gen->ym->current_cycle, gen->ym->buffer_pos, gen->psg->cycles, gen->psg->buffer_pos * 2);
 	psg_run(gen->psg, target);
 	ym_run(gen->ym, target);
-	
+
 	//printf("Target: %d, YM bufferpos: %d, PSG bufferpos: %d\n", target, gen->ym->buffer_pos, gen->psg->buffer_pos * 2);
 }
 
@@ -221,7 +221,7 @@
 		}
 		//printf("reached frame end | 68K Cycles: %d, MCLK Cycles: %d\n", context->current_cycle, mclks);
 		vdp_run_context(v_context, mclks_per_frame);
-		
+
 		if (!headless) {
 			break_on_sync |= wait_render_frame(v_context, frame_limit);
 		}
@@ -258,12 +258,6 @@
 		context->int_ack = 0;
 	}
 	adjust_int_cycle(context, v_context);
-	if (context->current_cycle <= context->sync_cycle) {
-		context->sync_cycle = context->current_cycle + 4;
-		if (context->sync_cycle < context->int_cycle) {
-			context->target_cycle = context->sync_cycle;
-		}
-	}
 	if (break_on_sync && address) {
 		break_on_sync = 0;
 		debugger(context, address);
@@ -504,7 +498,7 @@
 				}
 				if (value & 1) {
 					dputs("bus requesting Z80");
-					
+
 					if(!reset && !busreq) {
 						busack_cycle = ((gen->z80->current_cycle + Z80_ACK_DELAY) * MCLKS_PER_Z80) / MCLKS_PER_68K;//context->current_cycle + Z80_ACK_DELAY;
 						new_busack = Z80_REQ_ACK;
@@ -526,7 +520,7 @@
 					}
 					//busack_cycle = CYCLE_NEVER;
 					//busack = Z80_REQ_BUSY;
-					
+
 				}
 			} else if (location == 0x1200) {
 				sync_z80(gen->z80, context->current_cycle * MCLKS_PER_68K);
@@ -1441,7 +1435,7 @@
 				//Z80 debug commands
 				switch(input_buf[1])
 				{
-				case 'b': 
+				case 'b':
 					param = find_param(input_buf);
 					if (!param) {
 						fputs("zb command requires a parameter\n", stderr);
@@ -1560,7 +1554,7 @@
 	context->flags[ZF_Z] = f & 1;
 	f >>= 1;
 	context->flags[ZF_S] = f;
-	
+
 	context->regs[Z80_A] = *curpos;
 	curpos += 3;
 	for (int reg = Z80_C; reg <= Z80_IYH; reg++) {
@@ -1648,7 +1642,7 @@
 	adjust_int_cycle(gen->m68k, gen->vdp);
 	fclose(gstfile);
 	return pc;
-	
+
 error_close:
 	fclose(gstfile);
 error:
@@ -1666,7 +1660,7 @@
 const memmap_chunk static_map[] = {
 		{0,        0x400000,  0xFFFFFF, 0, MMAP_READ,                          cart,
 		           NULL,          NULL,         NULL,            NULL},
-		{0xE00000, 0x1000000, 0xFFFF,   0, MMAP_READ | MMAP_WRITE | MMAP_CODE, ram, 
+		{0xE00000, 0x1000000, 0xFFFF,   0, MMAP_READ | MMAP_WRITE | MMAP_CODE, ram,
 		           NULL,          NULL,         NULL,            NULL},
 		{0xC00000, 0xE00000,  0x1FFFFF, 0, 0,                                  NULL,
 		           (read_16_fun)vdp_port_read,  (write_16_fun)vdp_port_write,
@@ -1719,7 +1713,7 @@
 			memmap[0].mask = 0xFFFFFF;
 			memmap[0].flags = MMAP_READ;
 			memmap[0].buffer = cart;
-			
+
 			ram_start &= 0xFFFFFE;
 			ram_end |= 1;
 			memmap[1].start = ram_start;
@@ -1736,7 +1730,7 @@
 				size /= 2;
 			}
 			memmap[1].buffer = gen->save_ram = malloc(size);
-			
+
 			memcpy(memmap+2, static_map+1, sizeof(static_map)-sizeof(static_map[0]));
 			num_chunks = sizeof(static_map)/sizeof(memmap_chunk)+1;
 		} else {
@@ -1745,7 +1739,7 @@
 			memmap[0].mask = 0xFFFFFF;
 			memmap[0].flags = MMAP_READ;
 			memmap[0].buffer = cart;
-			
+
 			memmap[1].start = 0x200000;
 			memmap[1].end = 0x400000;
 			memmap[1].mask = 0x1FFFFF;
@@ -1765,7 +1759,7 @@
 			memmap[num_chunks].end = 0xA13100;
 			memmap[num_chunks].mask = 0xFF;
 			memmap[num_chunks].write_16 = (write_16_fun)write_bank_reg_w;
-			memmap[num_chunks].write_8 = (write_8_fun)write_bank_reg_b; 
+			memmap[num_chunks].write_8 = (write_8_fun)write_bank_reg_b;
 			num_chunks++;
 			ram_end++;
 			size = ram_end-ram_start;
@@ -1794,7 +1788,7 @@
 	init_x86_68k_opts(&opts, memmap, num_chunks);
 	opts.address_log = address_log;
 	init_68k_context(&context, opts.native_code_map, &opts);
-	
+
 	context.video_context = gen->vdp;
 	context.system = gen;
 	//cartridge ROM
@@ -1998,15 +1992,15 @@
 		render_init(width, height, title, fps, fullscreen);
 	}
 	vdp_context v_context;
-	
+
 	init_vdp_context(&v_context);
-	
+
 	ym2612_context y_context;
 	ym_init(&y_context, render_sample_rate(), fps == 60 ? MCLKS_NTSC : MCLKS_PAL, MCLKS_PER_YM, render_audio_buffer(), ym_log ? YM_OPT_WAVE_LOG : 0);
-	
+
 	psg_context p_context;
 	psg_init(&p_context, render_sample_rate(), fps == 60 ? MCLKS_NTSC : MCLKS_PAL, MCLKS_PER_PSG, render_audio_buffer());
-	
+
 	z80_context z_context;
 	x86_z80_options z_opts;
 	init_x86_z80_opts(&z_opts);
@@ -2020,13 +2014,13 @@
 	z_context.sync_cycle = z_context.target_cycle = mclks_per_frame/MCLKS_PER_Z80;
 	z_context.int_cycle = CYCLE_NEVER;
 	z_context.mem_pointers[1] = z_context.mem_pointers[2] = (uint8_t *)cart;
-	
+
 	gen.z80 = &z_context;
 	gen.vdp = &v_context;
 	gen.ym = &y_context;
 	gen.psg = &p_context;
 	genesis = &gen;
-	
+
 	int fname_size = strlen(argv[1]);
 	sram_filename = malloc(fname_size+6);
 	memcpy(sram_filename, argv[1], fname_size);
@@ -2041,7 +2035,7 @@
 		strcpy(sram_filename + fname_size, ".sram");
 	}
 	set_keybindings();
-	
+
 	init_run_cpu(&gen, debug, address_log, statefile);
 	return 0;
 }