timer adjustments based on Nem's new info
authornotaz <notasas@gmail.com>
Wed, 2 Jul 2008 11:40:19 +0000 (11:40 +0000)
committernotaz <notasas@gmail.com>
Wed, 2 Jul 2008 11:40:19 +0000 (11:40 +0000)
git-svn-id: file:///home/notaz/opt/svn/PicoDrive@513 be3aeb3a-fb24-0410-a615-afba39da0efa

Pico/Memory.c
Pico/PicoInt.h
Pico/sound/sound.c

index 290dba4..004d3af 100644 (file)
@@ -700,7 +700,7 @@ static int get_scanline(int is_from_z80)
   return Pico.m.scanline;\r
 }\r
 \r
-/* probably not should be in this file, but it's near related code here */\r
+/* probably should not be in this file, but it's near related code here */\r
 void ym2612_sync_timers(int z80_cycles, int mode_old, int mode_new)\r
 {\r
   int xcycles = z80_cycles << 8;\r
@@ -719,12 +719,10 @@ void ym2612_sync_timers(int z80_cycles, int mode_old, int mode_new)
 \r
   if ((mode_old ^ mode_new) & 1) // turning on/off\r
   {\r
-    if (mode_old & 1) {\r
-      timer_a_offset = timer_a_next_oflow - xcycles;\r
+    if (mode_old & 1)\r
       timer_a_next_oflow = TIMER_NO_OFLOW;\r
-    }\r
     else\r
-      timer_a_next_oflow = xcycles + timer_a_offset;\r
+      timer_a_next_oflow = xcycles + timer_a_step;\r
   }\r
   if (mode_new & 1)\r
     elprintf(EL_YMTIMER, "timer a upd to %i @ %i", timer_a_next_oflow>>8, z80_cycles);\r
@@ -736,12 +734,10 @@ void ym2612_sync_timers(int z80_cycles, int mode_old, int mode_new)
 \r
   if ((mode_old ^ mode_new) & 2)\r
   {\r
-    if (mode_old & 2) {\r
-      timer_b_offset = timer_b_next_oflow - xcycles;\r
+    if (mode_old & 2)\r
       timer_b_next_oflow = TIMER_NO_OFLOW;\r
-    }\r
     else\r
-      timer_b_next_oflow = xcycles + timer_b_offset;\r
+      timer_b_next_oflow = xcycles + timer_b_step;\r
   }\r
   if (mode_new & 2)\r
     elprintf(EL_YMTIMER, "timer b upd to %i @ %i", timer_b_next_oflow>>8, z80_cycles);\r
@@ -792,8 +788,9 @@ int ym2612_write_local(u32 a, u32 d, int is_from_z80)
             ym2612.OPN.ST.TA = TAnew;\r
             //ym2612.OPN.ST.TAC = (1024-TAnew)*18;\r
             //ym2612.OPN.ST.TAT = 0;\r
-            timer_a_step = timer_a_offset = TIMER_A_TICK_ZCYCLES * (1024 - TAnew);\r
+            timer_a_step = TIMER_A_TICK_ZCYCLES * (1024 - TAnew);\r
             if (ym2612.OPN.ST.mode & 1) {\r
+              // this is not right, should really be done on overflow only\r
               int cycles = is_from_z80 ? z80_cyclesDone() : cycles_68k_to_z80(SekCyclesDone());\r
               timer_a_next_oflow = (cycles << 8) + timer_a_step;\r
             }\r
@@ -807,7 +804,7 @@ int ym2612_write_local(u32 a, u32 d, int is_from_z80)
             ym2612.OPN.ST.TB = d;\r
             //ym2612.OPN.ST.TBC = (256-d) * 288;\r
             //ym2612.OPN.ST.TBT  = 0;\r
-            timer_b_step = timer_b_offset = TIMER_B_TICK_ZCYCLES * (256 - d); // 262800\r
+            timer_b_step = TIMER_B_TICK_ZCYCLES * (256 - d); // 262800\r
             if (ym2612.OPN.ST.mode & 2) {\r
               int cycles = is_from_z80 ? z80_cyclesDone() : cycles_68k_to_z80(SekCyclesDone());\r
               timer_b_next_oflow = (cycles << 8) + timer_b_step;\r
@@ -966,11 +963,11 @@ void ym2612_unpack_state(void)
   tac = (1024 - ym2612.OPN.ST.TA) << 16;\r
   tbc = (256  - ym2612.OPN.ST.TB) << 16;\r
   if (ym2612.OPN.ST.mode & 1)\r
-    timer_a_next_oflow = (double)(tac - tat) / (double)tac * timer_a_step;\r
+    timer_a_next_oflow = (int)((double)(tac - tat) / (double)tac * timer_a_step);\r
   else\r
     timer_a_next_oflow = TIMER_NO_OFLOW;\r
   if (ym2612.OPN.ST.mode & 2)\r
-    timer_b_next_oflow = (double)(tbc - tbt) / (double)tbc * timer_b_step;\r
+    timer_b_next_oflow = (int)((double)(tbc - tbt) / (double)tbc * timer_b_step);\r
   else\r
     timer_b_next_oflow = TIMER_NO_OFLOW;\r
   elprintf(EL_YMTIMER, "load: %i/%i, timer_a_next_oflow %i", tat>>16, tac>>16, timer_a_next_oflow >> 8);\r
index 4994ffc..c9aa1aa 100644 (file)
@@ -476,8 +476,8 @@ PICO_INTERNAL void cdda_start_play();
 extern short cdda_out_buffer[2*1152];\r
 extern int PsndLen_exc_cnt;\r
 extern int PsndLen_exc_add;\r
-extern int timer_a_next_oflow, timer_a_step, timer_a_offset; // in z80 cycles\r
-extern int timer_b_next_oflow, timer_b_step, timer_b_offset;\r
+extern int timer_a_next_oflow, timer_a_step; // in z80 cycles\r
+extern int timer_b_next_oflow, timer_b_step;\r
 \r
 void ym2612_sync_timers(int z80_cycles, int mode_old, int mode_new);\r
 void ym2612_pack_state(void);\r
@@ -498,8 +498,8 @@ void ym2612_unpack_state(void);
 \r
 #define timers_reset() \\r
   timer_a_next_oflow = timer_b_next_oflow = TIMER_NO_OFLOW; \\r
-  timer_a_step = timer_a_offset = TIMER_A_TICK_ZCYCLES * 1024; \\r
-  timer_b_step = timer_b_offset = TIMER_B_TICK_ZCYCLES * 256;\r
+  timer_a_step = TIMER_A_TICK_ZCYCLES * 1024; \\r
+  timer_b_step = TIMER_B_TICK_ZCYCLES * 256;\r
 \r
 \r
 // VideoPort.c\r
index e296742..cfa21a4 100644 (file)
@@ -35,8 +35,8 @@ int PsndDacLine=0;
 short *PsndOut=NULL; // PCM data buffer\r
 \r
 // timers\r
-int timer_a_next_oflow, timer_a_step, timer_a_offset; // in z80 cycles\r
-int timer_b_next_oflow, timer_b_step, timer_b_offset;\r
+int timer_a_next_oflow, timer_a_step; // in z80 cycles\r
+int timer_b_next_oflow, timer_b_step;\r
 \r
 // sn76496\r
 extern int *sn76496_regs;\r