Mercurial > repos > blastem
comparison genesis.c @ 1170:9170fc4d9835
Don't adjust cycles every frame. Only when we start getting close to UINT_MAX. Don't adjust all the way down to zero when we do adjust. Shouldn't fix anything, but may make debugging current issues easier.
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Sun, 15 Jan 2017 22:54:01 -0800 |
parents | 9fc680b35dbb |
children | b1147418254a |
comparison
equal
deleted
inserted
replaced
1169:82d8b9324b10 | 1170:9170fc4d9835 |
---|---|
146 #define REFRESH_DELAY 2 | 146 #define REFRESH_DELAY 2 |
147 uint32_t last_sync_cycle; | 147 uint32_t last_sync_cycle; |
148 uint32_t refresh_counter; | 148 uint32_t refresh_counter; |
149 #endif | 149 #endif |
150 | 150 |
151 #include <limits.h> | |
152 #define ADJUST_BUFFER (8*MCLKS_LINE*313) | |
153 #define MAX_NO_ADJUST (UINT_MAX-ADJUST_BUFFER) | |
154 | |
151 m68k_context * sync_components(m68k_context * context, uint32_t address) | 155 m68k_context * sync_components(m68k_context * context, uint32_t address) |
152 { | 156 { |
153 genesis_context * gen = context->system; | 157 genesis_context * gen = context->system; |
154 vdp_context * v_context = gen->vdp; | 158 vdp_context * v_context = gen->vdp; |
155 z80_context * z_context = gen->z80; | 159 z80_context * z_context = gen->z80; |
174 --exit_after; | 178 --exit_after; |
175 if (!exit_after) { | 179 if (!exit_after) { |
176 exit(0); | 180 exit(0); |
177 } | 181 } |
178 } | 182 } |
179 | 183 if (context->current_cycle > MAX_NO_ADJUST) { |
180 vdp_adjust_cycles(v_context, mclks); | 184 uint32_t deduction = mclks - ADJUST_BUFFER; |
181 io_adjust_cycles(gen->io.ports, context->current_cycle, mclks); | 185 vdp_adjust_cycles(v_context, deduction); |
182 io_adjust_cycles(gen->io.ports+1, context->current_cycle, mclks); | 186 io_adjust_cycles(gen->io.ports, context->current_cycle, deduction); |
183 io_adjust_cycles(gen->io.ports+2, context->current_cycle, mclks); | 187 io_adjust_cycles(gen->io.ports+1, context->current_cycle, deduction); |
184 context->current_cycle -= mclks; | 188 io_adjust_cycles(gen->io.ports+2, context->current_cycle, deduction); |
185 z80_adjust_cycles(z_context, mclks); | 189 context->current_cycle -= deduction; |
186 gen->ym->current_cycle -= mclks; | 190 z80_adjust_cycles(z_context, deduction); |
187 gen->psg->cycles -= mclks; | 191 gen->ym->current_cycle -= deduction; |
188 if (gen->ym->write_cycle != CYCLE_NEVER) { | 192 gen->psg->cycles -= deduction; |
189 gen->ym->write_cycle = gen->ym->write_cycle >= mclks ? gen->ym->write_cycle - mclks : 0; | 193 if (gen->ym->write_cycle != CYCLE_NEVER) { |
194 gen->ym->write_cycle = gen->ym->write_cycle >= deduction ? gen->ym->write_cycle - deduction : 0; | |
195 } | |
190 } | 196 } |
191 } | 197 } |
192 gen->frame_end = vdp_cycles_to_frame_end(v_context); | 198 gen->frame_end = vdp_cycles_to_frame_end(v_context); |
193 context->sync_cycle = gen->frame_end; | 199 context->sync_cycle = gen->frame_end; |
194 //printf("Set sync cycle to: %d @ %d, vcounter: %d, hslot: %d\n", context->sync_cycle, context->current_cycle, v_context->vcounter, v_context->hslot); | 200 //printf("Set sync cycle to: %d @ %d, vcounter: %d, hslot: %d\n", context->sync_cycle, context->current_cycle, v_context->vcounter, v_context->hslot); |