Mercurial > repos > blastem
comparison blastem.c @ 628:041578693329
Fix Z80 interrupts
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Sat, 21 Jun 2014 09:36:15 -0700 |
parents | 6aa2a8ab9c70 |
children | d77c79cec800 |
comparison
equal
deleted
inserted
replaced
627:c5820734a5b6 | 628:041578693329 |
---|---|
188 if (z_context->current_cycle < z_context->sync_cycle) { | 188 if (z_context->current_cycle < z_context->sync_cycle) { |
189 if (need_reset) { | 189 if (need_reset) { |
190 z80_reset(z_context); | 190 z80_reset(z_context); |
191 need_reset = 0; | 191 need_reset = 0; |
192 } | 192 } |
193 uint32_t vint_cycle = vdp_next_vint_z80(gen->vdp) / MCLKS_PER_Z80; | 193 |
194 while (z_context->current_cycle < z_context->sync_cycle) { | 194 while (z_context->current_cycle < z_context->sync_cycle) { |
195 if (z_context->iff1 && z_context->int_cycle == CYCLE_NEVER && z_context->current_cycle < (vint_cycle + Z80_VINT_DURATION)) { | 195 if (z_context->int_pulse_end < z_context->current_cycle || z_context->int_pulse_end == CYCLE_NEVER) { |
196 z_context->int_cycle = vint_cycle < z_context->int_enable_cycle ? z_context->int_enable_cycle : vint_cycle; | 196 z_context->int_pulse_start = vdp_next_vint_z80(gen->vdp) / MCLKS_PER_Z80; |
197 z_context->int_pulse_end = z_context->int_pulse_start + Z80_VINT_DURATION; | |
198 } | |
199 if (z_context->iff1) { | |
200 z_context->int_cycle = z_context->int_pulse_start < z_context->int_enable_cycle ? z_context->int_enable_cycle : z_context->int_pulse_start; | |
197 } | 201 } |
198 z_context->target_cycle = z_context->sync_cycle < z_context->int_cycle ? z_context->sync_cycle : z_context->int_cycle; | 202 z_context->target_cycle = z_context->sync_cycle < z_context->int_cycle ? z_context->sync_cycle : z_context->int_cycle; |
199 dprintf("Running Z80 from cycle %d to cycle %d. Int cycle: %d\n", z_context->current_cycle, z_context->sync_cycle, z_context->int_cycle); | 203 dprintf("Running Z80 from cycle %d to cycle %d. Int cycle: %d\n", z_context->current_cycle, z_context->sync_cycle, z_context->int_cycle); |
200 z80_run(z_context); | 204 z80_run(z_context); |
201 dprintf("Z80 ran to cycle %d\n", z_context->current_cycle); | 205 dprintf("Z80 ran to cycle %d\n", z_context->current_cycle); |
266 context->current_cycle -= mclk_target/MCLKS_PER_68K; | 270 context->current_cycle -= mclk_target/MCLKS_PER_68K; |
267 if (z_context->current_cycle >= mclk_target/MCLKS_PER_Z80) { | 271 if (z_context->current_cycle >= mclk_target/MCLKS_PER_Z80) { |
268 z_context->current_cycle -= mclk_target/MCLKS_PER_Z80; | 272 z_context->current_cycle -= mclk_target/MCLKS_PER_Z80; |
269 } else { | 273 } else { |
270 z_context->current_cycle = 0; | 274 z_context->current_cycle = 0; |
275 } | |
276 if (z_context->int_cycle != CYCLE_NEVER) { | |
277 if (z_context->int_cycle >= mclk_target/MCLKS_PER_Z80) { | |
278 z_context->int_cycle -= mclk_target/MCLKS_PER_Z80; | |
279 } else { | |
280 z_context->int_cycle = 0; | |
281 } | |
282 } | |
283 if (z_context->int_pulse_start != CYCLE_NEVER) { | |
284 if (z_context->int_pulse_end >= mclk_target/MCLKS_PER_Z80) { | |
285 z_context->int_pulse_end -= mclk_target/MCLKS_PER_Z80; | |
286 if (z_context->int_pulse_start >= mclk_target/MCLKS_PER_Z80) { | |
287 z_context->int_pulse_start -= mclk_target/MCLKS_PER_Z80; | |
288 } else { | |
289 z_context->int_pulse_start = 0; | |
290 } | |
291 } | |
292 } else { | |
293 z_context->int_pulse_start = CYCLE_NEVER; | |
294 z_context->int_pulse_end = CYCLE_NEVER; | |
295 } | |
296 if (z_context->int_enable_cycle >= mclk_target/MCLKS_PER_Z80) { | |
297 z_context->int_enable_cycle -= mclk_target/MCLKS_PER_Z80; | |
298 } else { | |
299 z_context->int_enable_cycle = 0; | |
271 } | 300 } |
272 if (mclks) { | 301 if (mclks) { |
273 vdp_run_context(v_context, mclks); | 302 vdp_run_context(v_context, mclks); |
274 } | 303 } |
275 mclk_target = vdp_cycles_to_frame_end(v_context); | 304 mclk_target = vdp_cycles_to_frame_end(v_context); |