summaryrefslogtreecommitdiff
path: root/apps/plugins/rockboy/cpu.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins/rockboy/cpu.c')
-rw-r--r--apps/plugins/rockboy/cpu.c62
1 files changed, 23 insertions, 39 deletions
diff --git a/apps/plugins/rockboy/cpu.c b/apps/plugins/rockboy/cpu.c
index 2bf9e90d2b..1aca06f337 100644
--- a/apps/plugins/rockboy/cpu.c
+++ b/apps/plugins/rockboy/cpu.c
@@ -37,14 +37,14 @@ F = (F & (FL|FC)) | decflag_table[(r)]; }
37#define DECW(r) ( (r)-- ) 37#define DECW(r) ( (r)-- )
38 38
39#define ADD(n) { \ 39#define ADD(n) { \
40W(acc) = (un16)A + (un16)(n); \ 40W(acc) = (un32)A + (un32)(n); \
41F = (ZFLAG(LB(acc))) \ 41F = (ZFLAG(LB(acc))) \
42| (FH & ((A ^ (n) ^ LB(acc)) << 1)) \ 42| (FH & ((A ^ (n) ^ LB(acc)) << 1)) \
43| (HB(acc) << 4); \ 43| (HB(acc) << 4); \
44A = LB(acc); } 44A = LB(acc); }
45 45
46#define ADC(n) { \ 46#define ADC(n) { \
47W(acc) = (un16)A + (un16)(n) + (un16)((F&FC)>>4); \ 47W(acc) = (un32)A + (un32)(n) + (un32)((F&FC)>>4); \
48F = (ZFLAG(LB(acc))) \ 48F = (ZFLAG(LB(acc))) \
49| (FH & ((A ^ (n) ^ LB(acc)) << 1)) \ 49| (FH & ((A ^ (n) ^ LB(acc)) << 1)) \
50| (HB(acc) << 4); \ 50| (HB(acc) << 4); \
@@ -70,7 +70,7 @@ F = (FH & (((SP>>8) ^ ((n)>>8) ^ HB(acc)) << 1)) \
70HL = W(acc); } 70HL = W(acc); }
71 71
72#define CP(n) { \ 72#define CP(n) { \
73W(acc) = (un16)A - (un16)(n); \ 73W(acc) = (un32)A - (un32)(n); \
74F = FN \ 74F = FN \
75| (ZFLAG(LB(acc))) \ 75| (ZFLAG(LB(acc))) \
76| (FH & ((A ^ (n) ^ LB(acc)) << 1)) \ 76| (FH & ((A ^ (n) ^ LB(acc)) << 1)) \
@@ -79,7 +79,7 @@ F = FN \
79#define SUB(n) { CP((n)); A = LB(acc); } 79#define SUB(n) { CP((n)); A = LB(acc); }
80 80
81#define SBC(n) { \ 81#define SBC(n) { \
82W(acc) = (un16)A - (un16)(n) - (un16)((F&FC)>>4); \ 82W(acc) = (un32)A - (un32)(n) - (un32)((F&FC)>>4); \
83F = FN \ 83F = FN \
84| (ZFLAG((n8)LB(acc))) \ 84| (ZFLAG((n8)LB(acc))) \
85| (FH & ((A ^ (n) ^ LB(acc)) << 1)) \ 85| (FH & ((A ^ (n) ^ LB(acc)) << 1)) \
@@ -273,18 +273,19 @@ void cpu_reset(void)
273#endif 273#endif
274} 274}
275 275
276 276static void div_advance(int cnt) ICODE_ATTR;
277void div_advance(int cnt) 277static void div_advance(int cnt)
278{ 278{
279 cpu.div += (cnt<<1); 279 cpu.div += (cnt<<1);
280 if (cpu.div >= 256) 280 if (cpu.div >> 8)
281 { 281 {
282 R_DIV += (cpu.div >> 8); 282 R_DIV += (cpu.div >> 8);
283 cpu.div &= 0xff; 283 cpu.div &= 0xff;
284 } 284 }
285} 285}
286 286
287void timer_advance(int cnt) 287static void timer_advance(int cnt) ICODE_ATTR;
288static void timer_advance(int cnt)
288{ 289{
289 int unit, tima; 290 int unit, tima;
290 291
@@ -293,28 +294,30 @@ void timer_advance(int cnt)
293 unit = ((-R_TAC) & 3) << 1; 294 unit = ((-R_TAC) & 3) << 1;
294 cpu.tim += (cnt<<unit); 295 cpu.tim += (cnt<<unit);
295 296
296 if (cpu.tim >= 512) 297 if (cpu.tim >> 9)
297 { 298 {
298 tima = R_TIMA + (cpu.tim >> 9); 299 tima = R_TIMA + (cpu.tim >> 9);
299 cpu.tim &= 0x1ff; 300 cpu.tim &= 0x1ff;
300 if (tima >= 256) 301 if (tima >> 8)
301 { 302 {
302 hw_interrupt(IF_TIMER, IF_TIMER); 303 hw_interrupt(IF_TIMER, IF_TIMER);
303 hw_interrupt(0, IF_TIMER); 304 hw_interrupt(0, IF_TIMER);
304 } 305 }
305 while (tima >= 256) 306 while (tima >> 8)
306 tima = tima - 256 + R_TMA; 307 tima = tima - 256 + R_TMA;
307 R_TIMA = tima; 308 R_TIMA = tima;
308 } 309 }
309} 310}
310 311
311void lcdc_advance(int cnt) 312static void lcdc_advance(int cnt) ICODE_ATTR;
313static void lcdc_advance(int cnt)
312{ 314{
313 cpu.lcdc -= cnt; 315 cpu.lcdc -= cnt;
314 if (cpu.lcdc <= 0) lcdc_trans(); 316 if (cpu.lcdc <= 0) lcdc_trans();
315} 317}
316 318
317void sound_advance(int cnt) 319static void sound_advance(int cnt) ICODE_ATTR;
320static void sound_advance(int cnt)
318{ 321{
319 cpu.snd += cnt; 322 cpu.snd += cnt;
320} 323}
@@ -328,11 +331,16 @@ void cpu_timers(int cnt)
328 sound_advance(cnt); 331 sound_advance(cnt);
329} 332}
330 333
331int cpu_idle(int max) 334static int cpu_idle(int max)
332{ 335{
333 int cnt, unit; 336 int cnt, unit;
334 337
335 if (!(cpu.halt && IME)) return 0; 338 if (!(cpu.halt && IME)) return 0;
339 if (R_IF & R_IE)
340 {
341 cpu.halt = 0;
342 return 0;
343 }
336 344
337 /* Make sure we don't miss lcdc status events! */ 345 /* Make sure we don't miss lcdc status events! */
338 if ((R_IE & (IF_VBLANK | IF_STAT)) && (max > cpu.lcdc)) 346 if ((R_IE & (IF_VBLANK | IF_STAT)) && (max > cpu.lcdc))
@@ -878,7 +886,7 @@ next:
878 PC++; 886 PC++;
879 if (R_KEY1 & 1) 887 if (R_KEY1 & 1)
880 { 888 {
881 cpu.speed = cpu.speed ^ 1; 889 cpu.speed ^= 1;
882 R_KEY1 = (R_KEY1 & 0x7E) | (cpu.speed << 7); 890 R_KEY1 = (R_KEY1 & 0x7E) | (cpu.speed << 7);
883 break; 891 break;
884 } 892 }
@@ -996,27 +1004,3 @@ next:
996} 1004}
997 1005
998#endif /* ASM_CPU_EMULATE */ 1006#endif /* ASM_CPU_EMULATE */
999
1000
1001#ifndef ASM_CPU_STEP
1002
1003inline int cpu_step(int max)
1004{
1005 register int cnt;
1006 if ((cnt = cpu_idle(max))) return cnt;
1007 return cpu_emulate(1);
1008}
1009
1010#endif /* ASM_CPU_STEP */
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022