bugfixes, state load for new mode
[picodrive.git] / Pico / sound / sound.c
index 6c7c6d8..ab6b7e1 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; // in z80 cycles\r
-//int\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
 \r
 // sn76496\r
 extern int *sn76496_regs;\r
@@ -46,13 +46,15 @@ static void dac_recalculate(void)
 {\r
   int i, dac_cnt, pos, len, lines = Pico.m.pal ? 312 : 262, mid = Pico.m.pal ? 68 : 93;\r
 \r
-  if(PsndLen <= lines) {\r
+  if (PsndLen <= lines)\r
+  {\r
     // shrinking algo\r
     dac_cnt = -PsndLen;\r
     len=1; pos=0;\r
     dac_info[225] = 1;\r
 \r
-    for(i=226; i != 225; i++) {\r
+    for(i=226; i != 225; i++)\r
+    {\r
       if (i >= lines) i = 0;\r
       len = 0;\r
       if(dac_cnt < 0) {\r
@@ -63,11 +65,14 @@ static void dac_recalculate(void)
       dac_cnt -= PsndLen;\r
       dac_info[i] = (pos<<4)|len;\r
     }\r
-  } else {\r
+  }\r
+  else\r
+  {\r
     // stretching\r
     dac_cnt = PsndLen;\r
     pos=0;\r
-    for(i = 225; i != 224; i++) {\r
+    for(i = 225; i != 224; i++)\r
+    {\r
       if (i >= lines) i = 0;\r
       len=0;\r
       while(dac_cnt >= 0) {\r
@@ -88,8 +93,9 @@ static void dac_recalculate(void)
     if (PsndLen_exc_add) len++;\r
     dac_info[224] = (pos<<4)|len;\r
   }\r
+  mid = (dac_info[lines-1] & 0xfff0) + ((dac_info[lines-1] & 0xf) << 4);\r
   for (i = lines; i < sizeof(dac_info) / sizeof(dac_info[0]); i++)\r
-    dac_info[i] = 0;\r
+    dac_info[i] = mid;\r
   //for(i=len=0; i < lines; i++) {\r
   //  printf("%03i : %03i : %i\n", i, dac_info[i]>>4, dac_info[i]&0xf);\r
   //  len+=dac_info[i]&0xf;\r
@@ -134,7 +140,7 @@ void PsndRerate(int preserve_state)
   if (preserve_state) {\r
     // feed it back it's own registers, just like after loading state\r
     memcpy(YM2612GetRegs(), state, 0x200);\r
-    YM2612PicoStateLoad();\r
+    ym2612_unpack_state();\r
     if ((PicoAHW & PAHW_MCD) && !(Pico_mcd->s68k_regs[0x36] & 1) && (Pico_mcd->scd.Status_CDC & 1))\r
       cdda_start_play();\r
   }\r