comparison blastem.c @ 317:e5e8b48ad157

Initial stab at horizontal interrupts and improving accuracy of vertical interrupts. Also added the VINT pending flag to status port.
author Mike Pavone <pavone@retrodev.com>
date Fri, 10 May 2013 22:57:56 -0700
parents 171f97e70d85
children 146c87616b05
comparison
equal deleted inserted replaced
316:fd7c24b97ebf 317:e5e8b48ad157
105 } 105 }
106 //TODO: Figure out what happens when you try to DMA from weird adresses like IO or banked Z80 area 106 //TODO: Figure out what happens when you try to DMA from weird adresses like IO or banked Z80 area
107 return 0; 107 return 0;
108 } 108 }
109 109
110 #define VINT_CYCLE ((MCLKS_LINE * 226)/MCLKS_PER_68K) 110 //TODO: Make these dependent on the video mode
111 #define ZVINT_CYCLE ((MCLKS_LINE * 226)/MCLKS_PER_Z80) 111 //#define VINT_CYCLE ((MCLKS_LINE * 225 + (148 + 40) * 4)/MCLKS_PER_68K)
112 #define ZVINT_CYCLE ((MCLKS_LINE * 225 + (148 + 40) * 4)/MCLKS_PER_Z80)
113 //#define VINT_CYCLE ((MCLKS_LINE * 226)/MCLKS_PER_68K)
114 //#define ZVINT_CYCLE ((MCLKS_LINE * 226)/MCLKS_PER_Z80)
112 115
113 void adjust_int_cycle(m68k_context * context, vdp_context * v_context) 116 void adjust_int_cycle(m68k_context * context, vdp_context * v_context)
114 { 117 {
115 if (!(v_context->regs[REG_MODE_2] & 0x20 && ((context->status & 0x7) < 6)) || context->current_cycle >= VINT_CYCLE) { 118 context->int_cycle = CYCLE_NEVER;
116 context->int_cycle = CYCLE_NEVER; 119 if ((context->status & 0x7) < 6) {
117 context->target_cycle = context->sync_cycle; 120 uint32_t next_vint = vdp_next_vint(v_context);
118 } else if (context->int_cycle > VINT_CYCLE) { 121 if (next_vint != CYCLE_NEVER) {
119 context->int_cycle = VINT_CYCLE; 122 next_vint /= MCLKS_PER_68K;
120 context->int_num = 6; 123 context->int_cycle = next_vint;
121 if (context->int_cycle < context->sync_cycle) { 124 context->int_num = 6;
122 context->target_cycle = context->int_cycle; 125 }
123 } 126 if ((context->status & 0x7) < 4) {
124 } 127 uint32_t next_hint = vdp_next_hint(v_context);
128 if (next_hint != CYCLE_NEVER) {
129 next_hint /= MCLKS_PER_68K;
130 if (next_hint < context->int_cycle) {
131 context->int_cycle = next_hint;
132 context->int_num = 4;
133
134 }
135 }
136 }
137 }
138
139 context->target_cycle = context->int_cycle < context->sync_cycle ? context->int_cycle : context->sync_cycle;
140 /*printf("Cyc: %d, Trgt: %d, Int Cyc: %d, Int: %d, Mask: %X, V: %d, H: %d, HICount: %d, HReg: %d, Line: %d\n",
141 context->current_cycle, context->target_cycle, context->int_cycle, context->int_num, (context->status & 0x7),
142 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);*/
125 } 143 }
126 144
127 int break_on_sync = 0; 145 int break_on_sync = 0;
128 146
129 uint8_t reset = 1; 147 uint8_t reset = 1;
193 vdp_run_context(v_context, mclks); 211 vdp_run_context(v_context, mclks);
194 } 212 }
195 } else { 213 } else {
196 //printf("running VDP for %d cycles\n", mclks - v_context->cycles); 214 //printf("running VDP for %d cycles\n", mclks - v_context->cycles);
197 vdp_run_context(v_context, mclks); 215 vdp_run_context(v_context, mclks);
216 }
217 if (context->int_ack) {
218 vdp_int_ack(v_context, context->int_ack);
219 context->int_ack = 0;
198 } 220 }
199 adjust_int_cycle(context, v_context); 221 adjust_int_cycle(context, v_context);
200 if (break_on_sync && address) { 222 if (break_on_sync && address) {
201 break_on_sync = 0; 223 break_on_sync = 0;
202 debugger(context, address); 224 debugger(context, address);