Sfoglia il codice sorgente

move more globals to PicoInterface

similar reasons as before
notaz 6 anni fa
parent
commit
6311a3baf5

+ 2 - 2
pico/cart.c

@@ -391,8 +391,8 @@ int pm_seek(pm_file *stream, long offset, int whence)
       offset = pos;
     }
 
-    if (PicoMessage != NULL && offset > 4 * 1024 * 1024)
-      PicoMessage("Decompressing data...");
+    if (PicoIn.osdMessage != NULL && offset > 4 * 1024 * 1024)
+      PicoIn.osdMessage("Decompressing data...");
 
     while (offset > 0) {
       char buf[16 * 1024];

+ 4 - 4
pico/cd/cdd.c

@@ -1297,8 +1297,8 @@ void cdd_process(void)
       set_reg16(0x3e, 0x0000);
       set_reg16(0x40, 0x000f);
 
-      if (PicoMCDcloseTray)
-        PicoMCDcloseTray();
+      if (PicoIn.mcdTrayClose)
+        PicoIn.mcdTrayClose();
 
       return;
     }
@@ -1316,8 +1316,8 @@ void cdd_process(void)
       set_reg16(0x3e, 0x0000);
       set_reg16(0x40, ~CD_OPEN & 0x0f);
 
-      if (PicoMCDopenTray)
-        PicoMCDopenTray();
+      if (PicoIn.mcdTrayOpen)
+        PicoIn.mcdTrayOpen();
       return;
     }
 

+ 0 - 3
pico/cd/mcd.c

@@ -15,9 +15,6 @@ static unsigned int mcd_m68k_cycle_mult;
 static unsigned int mcd_m68k_cycle_base;
 static unsigned int mcd_s68k_cycle_base;
 
-void (*PicoMCDopenTray)(void) = NULL;
-void (*PicoMCDcloseTray)(void) = NULL;
-
 
 PICO_INTERNAL void PicoInitMCD(void)
 {

+ 3 - 3
pico/debug.c

@@ -387,14 +387,14 @@ void PDebugZ80Frame(void)
 
   if (/*Pico.m.z80Run &&*/ !Pico.m.z80_reset && (PicoIn.opt&POPT_EN_Z80))
     PicoSyncZ80(Pico.t.m68c_cnt + line_sample * 488);
-  if (PsndOut)
+  if (PicoIn.sndOut)
     PsndGetSamples(line_sample);
 
   if (/*Pico.m.z80Run &&*/ !Pico.m.z80_reset && (PicoIn.opt&POPT_EN_Z80)) {
     PicoSyncZ80(Pico.t.m68c_cnt + 224 * 488);
     z80_int();
   }
-  if (PsndOut)
+  if (PicoIn.sndOut)
     PsndGetSamples(224);
 
   // sync z80
@@ -402,7 +402,7 @@ void PDebugZ80Frame(void)
     Pico.t.m68c_cnt += Pico.m.pal ? 151809 : 127671; // cycles adjusted for converter
     PicoSyncZ80(Pico.t.m68c_cnt);
   }
-  if (PsndOut && ym2612.dacen && PsndDacLine < lines)
+  if (PicoIn.sndOut && ym2612.dacen && Pico.snd.dac_line < lines)
     PsndDoDAC(lines - 1);
   PsndDoPSG(lines - 1);
 

+ 42 - 38
pico/memory.c

@@ -389,7 +389,7 @@ static int get_scanline(int is_from_z80);
 static void psg_write_68k(u32 d)
 {
   // look for volume write and update if needed
-  if ((d & 0x90) == 0x90 && PsndPsgLine < Pico.m.scanline)
+  if ((d & 0x90) == 0x90 && Pico.snd.psg_line < Pico.m.scanline)
     PsndDoPSG(Pico.m.scanline);
 
   SN76496Write(d);
@@ -399,7 +399,7 @@ static void psg_write_z80(u32 d)
 {
   if ((d & 0x90) == 0x90) {
     int scanline = get_scanline(1);
-    if (PsndPsgLine < scanline)
+    if (Pico.snd.psg_line < scanline)
       PsndDoPSG(scanline);
   }
 
@@ -895,41 +895,41 @@ void ym2612_sync_timers(int z80_cycles, int mode_old, int mode_new)
   int xcycles = z80_cycles << 8;
 
   /* check for overflows */
-  if ((mode_old & 4) && xcycles > timer_a_next_oflow)
+  if ((mode_old & 4) && xcycles > Pico.t.timer_a_next_oflow)
     ym2612.OPN.ST.status |= 1;
 
-  if ((mode_old & 8) && xcycles > timer_b_next_oflow)
+  if ((mode_old & 8) && xcycles > Pico.t.timer_b_next_oflow)
     ym2612.OPN.ST.status |= 2;
 
   /* update timer a */
   if (mode_old & 1)
-    while (xcycles > timer_a_next_oflow)
-      timer_a_next_oflow += timer_a_step;
+    while (xcycles > Pico.t.timer_a_next_oflow)
+      Pico.t.timer_a_next_oflow += Pico.t.timer_a_step;
 
   if ((mode_old ^ mode_new) & 1) // turning on/off
   {
     if (mode_old & 1)
-      timer_a_next_oflow = TIMER_NO_OFLOW;
+      Pico.t.timer_a_next_oflow = TIMER_NO_OFLOW;
     else
-      timer_a_next_oflow = xcycles + timer_a_step;
+      Pico.t.timer_a_next_oflow = xcycles + Pico.t.timer_a_step;
   }
   if (mode_new & 1)
-    elprintf(EL_YMTIMER, "timer a upd to %i @ %i", timer_a_next_oflow>>8, z80_cycles);
+    elprintf(EL_YMTIMER, "timer a upd to %i @ %i", Pico.t.timer_a_next_oflow>>8, z80_cycles);
 
   /* update timer b */
   if (mode_old & 2)
-    while (xcycles > timer_b_next_oflow)
-      timer_b_next_oflow += timer_b_step;
+    while (xcycles > Pico.t.timer_b_next_oflow)
+      Pico.t.timer_b_next_oflow += Pico.t.timer_b_step;
 
   if ((mode_old ^ mode_new) & 2)
   {
     if (mode_old & 2)
-      timer_b_next_oflow = TIMER_NO_OFLOW;
+      Pico.t.timer_b_next_oflow = TIMER_NO_OFLOW;
     else
-      timer_b_next_oflow = xcycles + timer_b_step;
+      Pico.t.timer_b_next_oflow = xcycles + Pico.t.timer_b_step;
   }
   if (mode_new & 2)
-    elprintf(EL_YMTIMER, "timer b upd to %i @ %i", timer_b_next_oflow>>8, z80_cycles);
+    elprintf(EL_YMTIMER, "timer b upd to %i @ %i", Pico.t.timer_b_next_oflow>>8, z80_cycles);
 }
 
 // ym2612 DAC and timer I/O handlers for z80
@@ -941,7 +941,7 @@ static int ym2612_write_local(u32 a, u32 d, int is_from_z80)
   if (a == 1 && ym2612.OPN.ST.address == 0x2a) /* DAC data */
   {
     int scanline = get_scanline(is_from_z80);
-    //elprintf(EL_STATUS, "%03i -> %03i dac w %08x z80 %i", PsndDacLine, scanline, d, is_from_z80);
+    //elprintf(EL_STATUS, "%03i -> %03i dac w %08x z80 %i", Pico.snd.dac_line, scanline, d, is_from_z80);
     ym2612.dacout = ((int)d - 0x80) << 6;
     if (ym2612.dacen)
       PsndDoDAC(scanline);
@@ -977,13 +977,13 @@ static int ym2612_write_local(u32 a, u32 d, int is_from_z80)
             ym2612.OPN.ST.TA = TAnew;
             //ym2612.OPN.ST.TAC = (1024-TAnew)*18;
             //ym2612.OPN.ST.TAT = 0;
-            timer_a_step = TIMER_A_TICK_ZCYCLES * (1024 - TAnew);
+            Pico.t.timer_a_step = TIMER_A_TICK_ZCYCLES * (1024 - TAnew);
             if (ym2612.OPN.ST.mode & 1) {
               // this is not right, should really be done on overflow only
               int cycles = is_from_z80 ? z80_cyclesDone() : z80_cycles_from_68k();
-              timer_a_next_oflow = (cycles << 8) + timer_a_step;
+              Pico.t.timer_a_next_oflow = (cycles << 8) + Pico.t.timer_a_step;
             }
-            elprintf(EL_YMTIMER, "timer a set to %i, %i", 1024 - TAnew, timer_a_next_oflow>>8);
+            elprintf(EL_YMTIMER, "timer a set to %i, %i", 1024 - TAnew, Pico.t.timer_a_next_oflow>>8);
           }
           return 0;
         }
@@ -993,12 +993,12 @@ static int ym2612_write_local(u32 a, u32 d, int is_from_z80)
             ym2612.OPN.ST.TB = d;
             //ym2612.OPN.ST.TBC = (256-d) * 288;
             //ym2612.OPN.ST.TBT  = 0;
-            timer_b_step = TIMER_B_TICK_ZCYCLES * (256 - d); // 262800
+            Pico.t.timer_b_step = TIMER_B_TICK_ZCYCLES * (256 - d); // 262800
             if (ym2612.OPN.ST.mode & 2) {
               int cycles = is_from_z80 ? z80_cyclesDone() : z80_cycles_from_68k();
-              timer_b_next_oflow = (cycles << 8) + timer_b_step;
+              Pico.t.timer_b_next_oflow = (cycles << 8) + Pico.t.timer_b_step;
             }
-            elprintf(EL_YMTIMER, "timer b set to %i, %i", 256 - d, timer_b_next_oflow>>8);
+            elprintf(EL_YMTIMER, "timer b set to %i, %i", 256 - d, Pico.t.timer_b_next_oflow>>8);
           }
           return 0;
         case 0x27: { /* mode, timer control */
@@ -1029,7 +1029,7 @@ static int ym2612_write_local(u32 a, u32 d, int is_from_z80)
           int scanline = get_scanline(is_from_z80);
           if (ym2612.dacen != (d & 0x80)) {
             ym2612.dacen = d & 0x80;
-            PsndDacLine = scanline;
+            Pico.snd.dac_line = scanline;
           }
 #ifdef __GP2X__
           if (PicoIn.opt & POPT_EXT_FM) YM2612Write_940(a, d, scanline);
@@ -1065,9 +1065,9 @@ static int ym2612_write_local(u32 a, u32 d, int is_from_z80)
 
 
 #define ym2612_read_local() \
-  if (xcycles >= timer_a_next_oflow) \
+  if (xcycles >= Pico.t.timer_a_next_oflow) \
     ym2612.OPN.ST.status |= (ym2612.OPN.ST.mode >> 2) & 1; \
-  if (xcycles >= timer_b_next_oflow) \
+  if (xcycles >= Pico.t.timer_b_next_oflow) \
     ym2612.OPN.ST.status |= (ym2612.OPN.ST.mode >> 2) & 2
 
 static u32 ym2612_read_local_z80(void)
@@ -1076,8 +1076,9 @@ static u32 ym2612_read_local_z80(void)
 
   ym2612_read_local();
 
-  elprintf(EL_YMTIMER, "timer z80 read %i, sched %i, %i @ %i|%i", ym2612.OPN.ST.status,
-      timer_a_next_oflow>>8, timer_b_next_oflow>>8, xcycles >> 8, (xcycles >> 8) / 228);
+  elprintf(EL_YMTIMER, "timer z80 read %i, sched %i, %i @ %i|%i",
+    ym2612.OPN.ST.status, Pico.t.timer_a_next_oflow >> 8,
+    Pico.t.timer_b_next_oflow >> 8, xcycles >> 8, (xcycles >> 8) / 228);
   return ym2612.OPN.ST.status;
 }
 
@@ -1087,8 +1088,9 @@ static u32 ym2612_read_local_68k(void)
 
   ym2612_read_local();
 
-  elprintf(EL_YMTIMER, "timer 68k read %i, sched %i, %i @ %i|%i", ym2612.OPN.ST.status,
-      timer_a_next_oflow>>8, timer_b_next_oflow>>8, xcycles >> 8, (xcycles >> 8) / 228);
+  elprintf(EL_YMTIMER, "timer 68k read %i, sched %i, %i @ %i|%i",
+    ym2612.OPN.ST.status, Pico.t.timer_a_next_oflow >> 8,
+    Pico.t.timer_b_next_oflow >> 8, xcycles >> 8, (xcycles >> 8) / 228);
   return ym2612.OPN.ST.status;
 }
 
@@ -1098,10 +1100,12 @@ void ym2612_pack_state(void)
   int tac, tat = 0, tbc, tbt = 0;
   tac = 1024 - ym2612.OPN.ST.TA;
   tbc = 256  - ym2612.OPN.ST.TB;
-  if (timer_a_next_oflow != TIMER_NO_OFLOW)
-    tat = (int)((double)(timer_a_step - timer_a_next_oflow) / (double)timer_a_step * tac * 65536);
-  if (timer_b_next_oflow != TIMER_NO_OFLOW)
-    tbt = (int)((double)(timer_b_step - timer_b_next_oflow) / (double)timer_b_step * tbc * 65536);
+  if (Pico.t.timer_a_next_oflow != TIMER_NO_OFLOW)
+    tat = (int)((double)(Pico.t.timer_a_step - Pico.t.timer_a_next_oflow)
+          / (double)Pico.t.timer_a_step * tac * 65536);
+  if (Pico.t.timer_b_next_oflow != TIMER_NO_OFLOW)
+    tbt = (int)((double)(Pico.t.timer_b_step - Pico.t.timer_b_next_oflow)
+          / (double)Pico.t.timer_b_step * tbc * 65536);
   elprintf(EL_YMTIMER, "save: timer a %i/%i", tat >> 16, tac);
   elprintf(EL_YMTIMER, "save: timer b %i/%i", tbt >> 16, tbc);
 
@@ -1154,15 +1158,15 @@ void ym2612_unpack_state(void)
   tac = (1024 - ym2612.OPN.ST.TA) << 16;
   tbc = (256  - ym2612.OPN.ST.TB) << 16;
   if (ym2612.OPN.ST.mode & 1)
-    timer_a_next_oflow = (int)((double)(tac - tat) / (double)tac * timer_a_step);
+    Pico.t.timer_a_next_oflow = (int)((double)(tac - tat) / (double)tac * Pico.t.timer_a_step);
   else
-    timer_a_next_oflow = TIMER_NO_OFLOW;
+    Pico.t.timer_a_next_oflow = TIMER_NO_OFLOW;
   if (ym2612.OPN.ST.mode & 2)
-    timer_b_next_oflow = (int)((double)(tbc - tbt) / (double)tbc * timer_b_step);
+    Pico.t.timer_b_next_oflow = (int)((double)(tbc - tbt) / (double)tbc * Pico.t.timer_b_step);
   else
-    timer_b_next_oflow = TIMER_NO_OFLOW;
-  elprintf(EL_YMTIMER, "load: %i/%i, timer_a_next_oflow %i", tat>>16, tac>>16, timer_a_next_oflow >> 8);
-  elprintf(EL_YMTIMER, "load: %i/%i, timer_b_next_oflow %i", tbt>>16, tbc>>16, timer_b_next_oflow >> 8);
+    Pico.t.timer_b_next_oflow = TIMER_NO_OFLOW;
+  elprintf(EL_YMTIMER, "load: %i/%i, timer_a_next_oflow %i", tat>>16, tac>>16, Pico.t.timer_a_next_oflow >> 8);
+  elprintf(EL_YMTIMER, "load: %i/%i, timer_b_next_oflow %i", tbt>>16, tbc>>16, Pico.t.timer_b_next_oflow >> 8);
 }
 
 #if defined(NO_32X) && defined(_ASM_MEMORY_C)

+ 1 - 4
pico/pico.c

@@ -14,7 +14,6 @@ struct Pico Pico;
 struct PicoMem PicoMem;
 PicoInterface PicoIn;
 
-void (*PicoWriteSound)(int len) = NULL; // called at the best time to send sound buffer (PsndOut) to hardware
 void (*PicoResetHook)(void) = NULL;
 void (*PicoLineHook)(void) = NULL;
 
@@ -344,6 +343,4 @@ void PicoGetInternal(pint_t which, pint_ret_t *r)
   }
 }
 
-// callback to output message from emu
-void (*PicoMessage)(const char *msg)=NULL;
-
+// vim:ts=2:sw=2:expandtab

+ 9 - 8
pico/pico.h

@@ -97,6 +97,15 @@ typedef struct
 
 	unsigned short quirks;         // game-specific quirks: PQUIRK_*
 	unsigned short overclockM68k;  // overclock the emulated 68k, in %
+
+	int sndRate;                   // rate in Hz
+	short *sndOut;                 // PCM output buffer
+	void (*writeSound)(int len);   // write .sndOut callback, called once per frame
+
+	void (*osdMessage)(const char *msg); // output OSD message from emu, optional
+
+	void (*mcdTrayOpen)(void);
+	void (*mcdTrayClose)(void);
 } PicoInterface;
 
 extern PicoInterface PicoIn;
@@ -108,18 +117,12 @@ int  PicoReset(void);
 void PicoLoopPrepare(void);
 void PicoFrame(void);
 void PicoFrameDrawOnly(void);
-extern void (*PicoWriteSound)(int bytes); // called once per frame at the best time to send sound buffer (PsndOut) to hardware
-extern void (*PicoMessage)(const char *msg); // callback to output text message from emu
 typedef enum { PI_ROM, PI_ISPAL, PI_IS40_CELL, PI_IS240_LINES } pint_t;
 typedef union { int vint; void *vptr; } pint_ret_t;
 void PicoGetInternal(pint_t which, pint_ret_t *ret);
 
 struct PicoEState;
 
-// cd/mcd.c
-extern void (*PicoMCDopenTray)(void);
-extern void (*PicoMCDcloseTray)(void);
-
 // pico.c
 #define XPCM_BUFFER_SIZE (320+160)
 typedef struct
@@ -230,8 +233,6 @@ void Pico32xSetClocks(int msh2_hz, int ssh2_hz);
 #define PICO_SSH2_HZ ((int)(7670442.0 * 2.4))
 
 // sound.c
-extern int PsndRate,PsndLen;
-extern short *PsndOut;
 extern void (*PsndMix_32_to_16l)(short *dest, int *src, int count);
 void PsndRerate(int preserve_state);
 

+ 1 - 1
pico/pico/xpcm.c

@@ -50,7 +50,7 @@ PICO_INTERNAL void PicoPicoPCMReset(void)
 
 PICO_INTERNAL void PicoPicoPCMRerate(int xpcm_rate)
 {
-  stepsamples = (PsndRate<<10)/xpcm_rate;
+  stepsamples = (PicoIn.sndRate<<10)/xpcm_rate;
 }
 
 #define XSHIFT 6

+ 4 - 4
pico/pico_cmn.c

@@ -153,7 +153,7 @@ static int PicoFrameHints(void)
     }
 
     // get samples from sound chips
-    if ((y == 224 || y == line_sample) && PsndOut)
+    if ((y == 224 || y == line_sample) && PicoIn.sndOut)
     {
       cycles = SekCyclesDone();
 
@@ -241,7 +241,7 @@ static int PicoFrameHints(void)
 #endif
 
   // get samples from sound chips
-  if (y == 224 && PsndOut)
+  if (y == 224 && PicoIn.sndOut)
     PsndGetSamples(y);
 
   // Run scanline:
@@ -324,9 +324,9 @@ static int PicoFrameHints(void)
   cycles = SekCyclesDone();
   if (Pico.m.z80Run && !Pico.m.z80_reset && (PicoIn.opt&POPT_EN_Z80))
     PicoSyncZ80(cycles);
-  if (PsndOut && ym2612.dacen && PsndDacLine < lines)
+  if (PicoIn.sndOut && ym2612.dacen && Pico.snd.dac_line < lines)
     PsndDoDAC(lines - 1);
-  if (PsndOut && PsndPsgLine < lines)
+  if (PicoIn.sndOut && Pico.snd.psg_line < lines)
     PsndDoPSG(lines - 1);
 
 #ifdef PICO_CD

+ 21 - 12
pico/pico_int.h

@@ -409,6 +409,19 @@ struct PicoTiming
   unsigned int z80c_cnt;                // z80 cycles done (this frame)
   unsigned int z80c_aim;
   int z80_scanline;
+
+  int timer_a_next_oflow, timer_a_step; // in z80 cycles
+  int timer_b_next_oflow, timer_b_step;
+};
+
+struct PicoSound
+{
+  short len;                            // number of mono samples
+  short len_use;                        // adjusted
+  int len_e_add;                        // for non-int samples/frame
+  int len_e_cnt;
+  short dac_line;
+  short psg_line;
 };
 
 // run tools/mkoffsets pico/pico_int_o32.h if you change these
@@ -419,6 +432,7 @@ struct Pico
   struct PicoMisc m;
   struct PicoTiming t;
   struct PicoCartSave sv;
+  struct PicoSound snd;
   struct PicoEState est;
   struct PicoMS ms;
 
@@ -781,10 +795,6 @@ void SekInterruptClearS68k(int irq);
 
 // sound/sound.c
 extern short cdda_out_buffer[2*1152];
-extern int PsndLen_exc_cnt;
-extern int PsndLen_exc_add;
-extern int timer_a_next_oflow, timer_a_step; // in z80 cycles
-extern int timer_b_next_oflow, timer_b_step;
 
 void cdda_start_play(int lba_base, int lba_offset, int lb_len);
 
@@ -799,16 +809,16 @@ void ym2612_unpack_state(void);
 #define TIMER_B_TICK_ZCYCLES 262800 // 275251 broken, see Dai Makaimura
 
 #define timers_cycle() \
-  if (timer_a_next_oflow > 0 && timer_a_next_oflow < TIMER_NO_OFLOW) \
-    timer_a_next_oflow -= Pico.m.pal ? 70938*256 : 59659*256; \
-  if (timer_b_next_oflow > 0 && timer_b_next_oflow < TIMER_NO_OFLOW) \
-    timer_b_next_oflow -= Pico.m.pal ? 70938*256 : 59659*256; \
+  if (Pico.t.timer_a_next_oflow > 0 && Pico.t.timer_a_next_oflow < TIMER_NO_OFLOW) \
+    Pico.t.timer_a_next_oflow -= Pico.m.pal ? 70938*256 : 59659*256; \
+  if (Pico.t.timer_b_next_oflow > 0 && Pico.t.timer_b_next_oflow < TIMER_NO_OFLOW) \
+    Pico.t.timer_b_next_oflow -= Pico.m.pal ? 70938*256 : 59659*256; \
   ym2612_sync_timers(0, ym2612.OPN.ST.mode, ym2612.OPN.ST.mode);
 
 #define timers_reset() \
-  timer_a_next_oflow = timer_b_next_oflow = TIMER_NO_OFLOW; \
-  timer_a_step = TIMER_A_TICK_ZCYCLES * 1024; \
-  timer_b_step = TIMER_B_TICK_ZCYCLES * 256;
+  Pico.t.timer_a_next_oflow = Pico.t.timer_b_next_oflow = TIMER_NO_OFLOW; \
+  Pico.t.timer_a_step = TIMER_A_TICK_ZCYCLES * 1024; \
+  Pico.t.timer_b_step = TIMER_B_TICK_ZCYCLES * 256;
 
 
 // videoport.c
@@ -850,7 +860,6 @@ PICO_INTERNAL void PsndDoPSG(int line_to);
 PICO_INTERNAL void PsndClear(void);
 PICO_INTERNAL void PsndGetSamples(int y);
 PICO_INTERNAL void PsndGetSamplesMS(void);
-extern int PsndDacLine, PsndPsgLine;
 
 // sms.c
 #ifndef NO_SMS

+ 7 - 7
pico/pico_int_o32.h

@@ -6,13 +6,13 @@
 #define OFS_Pico_m_hardware  0x0047
 #define OFS_Pico_m_z80_reset 0x004f
 #define OFS_Pico_m_sram_reg  0x0049
-#define OFS_Pico_sv          0x007c
-#define OFS_Pico_sv_data     0x007c
-#define OFS_Pico_sv_start    0x0080
-#define OFS_Pico_sv_end      0x0084
-#define OFS_Pico_sv_flags    0x0088
-#define OFS_Pico_rom         0x031c
-#define OFS_Pico_romsize     0x0320
+#define OFS_Pico_sv          0x008c
+#define OFS_Pico_sv_data     0x008c
+#define OFS_Pico_sv_start    0x0090
+#define OFS_Pico_sv_end      0x0094
+#define OFS_Pico_sv_flags    0x0098
+#define OFS_Pico_rom         0x033c
+#define OFS_Pico_romsize     0x0340
 #define OFS_EST_DrawScanline 0x00
 #define OFS_EST_rendstatus   0x04
 #define OFS_EST_DrawLineDest 0x08

+ 3 - 3
pico/sms.c

@@ -131,7 +131,7 @@ static void z80_sms_out(unsigned short a, unsigned char d)
 
     case 0x40:
     case 0x41:
-      if ((d & 0x90) == 0x90 && PsndPsgLine < Pico.m.scanline)
+      if ((d & 0x90) == 0x90 && Pico.snd.psg_line < Pico.m.scanline)
         PsndDoPSG(Pico.m.scanline);
       SN76496Write(d);
       break;
@@ -300,14 +300,14 @@ void PicoFrameMS(void)
     }
 
     // 224 because of how it's done for MD...
-    if (y == 224 && PsndOut)
+    if (y == 224 && PicoIn.sndOut)
       PsndGetSamplesMS();
 
     cycles_aim += cycles_line;
     cycles_done += z80_run((cycles_aim - cycles_done) >> 8) << 8;
   }
 
-  if (PsndOut && PsndPsgLine < lines)
+  if (PicoIn.sndOut && Pico.snd.psg_line < lines)
     PsndDoPSG(lines - 1);
 }
 

+ 52 - 63
pico/sound/sound.c

@@ -25,31 +25,20 @@ static unsigned short dac_info[312+4]; // pos in sample buffer
 // cdda output buffer
 short cdda_out_buffer[2*1152];
 
-// for Pico
-int PsndRate=0;
-int PsndLen=0; // number of mono samples, multiply by 2 for stereo
-int PsndLen_exc_add=0; // this is for non-integer sample counts per line, eg. 22050/60
-int PsndLen_exc_cnt=0;
-int PsndDacLine, PsndPsgLine;
-short *PsndOut=NULL; // PCM data buffer
-static int PsndLen_use;
-
-// timers
-int timer_a_next_oflow, timer_a_step; // in z80 cycles
-int timer_b_next_oflow, timer_b_step;
-
 // sn76496
 extern int *sn76496_regs;
 
 
 static void dac_recalculate(void)
 {
-  int i, dac_cnt, pos, len, lines = Pico.m.pal ? 313 : 262, mid = Pico.m.pal ? 68 : 93;
+  int lines = Pico.m.pal ? 313 : 262;
+  int mid = Pico.m.pal ? 68 : 93;
+  int i, dac_cnt, pos, len;
 
-  if (PsndLen <= lines)
+  if (Pico.snd.len <= lines)
   {
     // shrinking algo
-    dac_cnt = -PsndLen;
+    dac_cnt = -Pico.snd.len;
     len=1; pos=0;
     dac_info[225] = 1;
 
@@ -60,14 +49,14 @@ static void dac_recalculate(void)
         pos++;
         dac_cnt += lines;
       }
-      dac_cnt -= PsndLen;
+      dac_cnt -= Pico.snd.len;
       dac_info[i] = pos;
     }
   }
   else
   {
     // stretching
-    dac_cnt = PsndLen;
+    dac_cnt = Pico.snd.len;
     pos=0;
     for(i = 225; i != 224; i++)
     {
@@ -78,11 +67,11 @@ static void dac_recalculate(void)
         len++;
       }
       if (i == mid) // midpoint
-        while(pos+len < PsndLen/2) {
+        while(pos+len < Pico.snd.len/2) {
           dac_cnt -= lines;
           len++;
         }
-      dac_cnt += PsndLen;
+      dac_cnt += Pico.snd.len;
       pos += len;
       dac_info[i] = pos;
     }
@@ -112,7 +101,7 @@ void PsndRerate(int preserve_state)
     ym2612_pack_state();
     memcpy(state, YM2612GetRegs(), 0x204);
   }
-  YM2612Init(Pico.m.pal ? OSC_PAL/7 : OSC_NTSC/7, PsndRate);
+  YM2612Init(Pico.m.pal ? OSC_PAL/7 : OSC_NTSC/7, PicoIn.sndRate);
   if (preserve_state) {
     // feed it back it's own registers, just like after loading state
     memcpy(YM2612GetRegs(), state, 0x204);
@@ -120,16 +109,16 @@ void PsndRerate(int preserve_state)
   }
 
   if (preserve_state) memcpy(state, sn76496_regs, 28*4); // remember old state
-  SN76496_init(Pico.m.pal ? OSC_PAL/15 : OSC_NTSC/15, PsndRate);
+  SN76496_init(Pico.m.pal ? OSC_PAL/15 : OSC_NTSC/15, PicoIn.sndRate);
   if (preserve_state) memcpy(sn76496_regs, state, 28*4); // restore old state
 
   if (state)
     free(state);
 
-  // calculate PsndLen
-  PsndLen=PsndRate / target_fps;
-  PsndLen_exc_add=((PsndRate - PsndLen*target_fps)<<16) / target_fps;
-  PsndLen_exc_cnt=0;
+  // calculate Pico.snd.len
+  Pico.snd.len = PicoIn.sndRate / target_fps;
+  Pico.snd.len_e_add = ((PicoIn.sndRate - Pico.snd.len * target_fps) << 16) / target_fps;
+  Pico.snd.len_e_cnt = 0;
 
   // recalculate dac info
   dac_recalculate();
@@ -137,7 +126,7 @@ void PsndRerate(int preserve_state)
   // clear all buffers
   memset32(PsndBuffer, 0, sizeof(PsndBuffer)/4);
   memset(cdda_out_buffer, 0, sizeof(cdda_out_buffer));
-  if (PsndOut)
+  if (PicoIn.sndOut)
     PsndClear();
 
   // set mixer
@@ -150,24 +139,24 @@ void PsndRerate(int preserve_state)
 
 PICO_INTERNAL void PsndStartFrame(void)
 {
-  // compensate for float part of PsndLen
-  PsndLen_use = PsndLen;
-  PsndLen_exc_cnt += PsndLen_exc_add;
-  if (PsndLen_exc_cnt >= 0x10000) {
-    PsndLen_exc_cnt -= 0x10000;
-    PsndLen_use++;
+  // compensate for float part of Pico.snd.len
+  Pico.snd.len_use = Pico.snd.len;
+  Pico.snd.len_e_cnt += Pico.snd.len_e_add;
+  if (Pico.snd.len_e_cnt >= 0x10000) {
+    Pico.snd.len_e_cnt -= 0x10000;
+    Pico.snd.len_use++;
   }
 
-  PsndDacLine = PsndPsgLine = 0;
+  Pico.snd.dac_line = Pico.snd.psg_line = 0;
   Pico.m.status &= ~1;
-  dac_info[224] = PsndLen_use;
+  dac_info[224] = Pico.snd.len_use;
 }
 
 PICO_INTERNAL void PsndDoDAC(int line_to)
 {
   int pos, pos1, len;
   int dout = ym2612.dacout;
-  int line_from = PsndDacLine;
+  int line_from = Pico.snd.dac_line;
 
   if (line_to >= 313)
     line_to = 312;
@@ -178,23 +167,23 @@ PICO_INTERNAL void PsndDoDAC(int line_to)
   if (len <= 0)
     return;
 
-  PsndDacLine = line_to + 1;
+  Pico.snd.dac_line = line_to + 1;
 
-  if (!PsndOut)
+  if (!PicoIn.sndOut)
     return;
 
   if (PicoIn.opt & POPT_EN_STEREO) {
-    short *d = PsndOut + pos*2;
+    short *d = PicoIn.sndOut + pos*2;
     for (; len > 0; len--, d+=2) *d += dout;
   } else {
-    short *d = PsndOut + pos;
+    short *d = PicoIn.sndOut + pos;
     for (; len > 0; len--, d++)  *d += dout;
   }
 }
 
 PICO_INTERNAL void PsndDoPSG(int line_to)
 {
-  int line_from = PsndPsgLine;
+  int line_from = Pico.snd.psg_line;
   int pos, pos1, len;
   int stereo = 0;
 
@@ -209,16 +198,16 @@ PICO_INTERNAL void PsndDoPSG(int line_to)
   if (len <= 0)
     return;
 
-  PsndPsgLine = line_to + 1;
+  Pico.snd.psg_line = line_to + 1;
 
-  if (!PsndOut || !(PicoIn.opt & POPT_EN_PSG))
+  if (!PicoIn.sndOut || !(PicoIn.opt & POPT_EN_PSG))
     return;
 
   if (PicoIn.opt & POPT_EN_STEREO) {
     stereo = 1;
     pos <<= 1;
   }
-  SN76496Update(PsndOut + pos, len, stereo);
+  SN76496Update(PicoIn.sndOut + pos, len, stereo);
 }
 
 // cdda
@@ -227,8 +216,8 @@ static void cdda_raw_update(int *buffer, int length)
   int ret, cdda_bytes, mult = 1;
 
   cdda_bytes = length*4;
-  if (PsndRate <= 22050 + 100) mult = 2;
-  if (PsndRate <  22050 - 100) mult = 4;
+  if (PicoIn.sndRate <= 22050 + 100) mult = 2;
+  if (PicoIn.sndRate <  22050 - 100) mult = 4;
   cdda_bytes *= mult;
 
   ret = pm_read(cdda_out_buffer, cdda_bytes, Pico_mcd->cdda_stream);
@@ -270,12 +259,12 @@ void cdda_start_play(int lba_base, int lba_offset, int lb_len)
 
 PICO_INTERNAL void PsndClear(void)
 {
-  int len = PsndLen;
-  if (PsndLen_exc_add) len++;
+  int len = Pico.snd.len;
+  if (Pico.snd.len_e_add) len++;
   if (PicoIn.opt & POPT_EN_STEREO)
-    memset32((int *) PsndOut, 0, len); // assume PsndOut to be aligned
+    memset32((int *) PicoIn.sndOut, 0, len); // assume PicoIn.sndOut to be aligned
   else {
-    short *out = PsndOut;
+    short *out = PicoIn.sndOut;
     if ((long)out & 2) { *out++ = 0; len--; }
     memset32((int *) out, 0, len/2);
     if (len & 1) out[len-1] = 0;
@@ -294,7 +283,7 @@ static int PsndRender(int offset, int length)
   pprof_start(sound);
 
   if (PicoIn.AHW & PAHW_PICO) {
-    PicoPicoPCMUpdate(PsndOut+offset, length, stereo);
+    PicoPicoPCMUpdate(PicoIn.sndOut+offset, length, stereo);
     return length;
   }
 
@@ -330,7 +319,7 @@ static int PsndRender(int offset, int length)
     p32x_pwm_update(buf32, length, stereo);
 
   // convert + limit to normal 16bit output
-  PsndMix_32_to_16l(PsndOut+offset, buf32, length);
+  PsndMix_32_to_16l(PicoIn.sndOut+offset, buf32, length);
 
   pprof_end(sound);
 
@@ -342,47 +331,47 @@ PICO_INTERNAL void PsndGetSamples(int y)
 {
   static int curr_pos = 0;
 
-  if (ym2612.dacen && PsndDacLine < y)
+  if (ym2612.dacen && Pico.snd.dac_line < y)
     PsndDoDAC(y - 1);
   PsndDoPSG(y - 1);
 
   if (y == 224)
   {
     if (Pico.m.status & 2)
-         curr_pos += PsndRender(curr_pos, PsndLen-PsndLen/2);
-    else curr_pos  = PsndRender(0, PsndLen_use);
+         curr_pos += PsndRender(curr_pos, Pico.snd.len-Pico.snd.len/2);
+    else curr_pos  = PsndRender(0, Pico.snd.len_use);
     if (Pico.m.status & 1)
          Pico.m.status |=  2;
     else Pico.m.status &= ~2;
-    if (PicoWriteSound)
-      PicoWriteSound(curr_pos * ((PicoIn.opt & POPT_EN_STEREO) ? 4 : 2));
+    if (PicoIn.writeSound)
+      PicoIn.writeSound(curr_pos * ((PicoIn.opt & POPT_EN_STEREO) ? 4 : 2));
     // clear sound buffer
     PsndClear();
-    PsndDacLine = 224;
+    Pico.snd.dac_line = 224;
     dac_info[224] = 0;
   }
   else if (Pico.m.status & 3) {
     Pico.m.status |=  2;
     Pico.m.status &= ~1;
-    curr_pos = PsndRender(0, PsndLen/2);
+    curr_pos = PsndRender(0, Pico.snd.len/2);
   }
 }
 
 PICO_INTERNAL void PsndGetSamplesMS(void)
 {
-  int length = PsndLen_use;
+  int length = Pico.snd.len_use;
 
   PsndDoPSG(223);
 
   // upmix to "stereo" if needed
   if (PicoIn.opt & POPT_EN_STEREO) {
     int i, *p;
-    for (i = length, p = (void *)PsndOut; i > 0; i--, p++)
+    for (i = length, p = (void *)PicoIn.sndOut; i > 0; i--, p++)
       *p |= *p << 16;
   }
 
-  if (PicoWriteSound != NULL)
-    PicoWriteSound(length * ((PicoIn.opt & POPT_EN_STEREO) ? 4 : 2));
+  if (PicoIn.writeSound != NULL)
+    PicoIn.writeSound(length * ((PicoIn.opt & POPT_EN_STEREO) ? 4 : 2));
   PsndClear();
 
   dac_info[224] = 0;

+ 3 - 3
platform/common/config_file.c

@@ -259,9 +259,9 @@ static int custom_read(menu_entry *me, const char *var, const char *val)
 
 		case MA_OPT_SOUND_QUALITY:
 			if (strcasecmp(var, "Sound Quality") != 0) return 0;
-			PsndRate = strtoul(val, &tmp, 10);
-			if (PsndRate < 8000 || PsndRate > 44100)
-				PsndRate = 22050;
+			PicoIn.sndRate = strtoul(val, &tmp, 10);
+			if (PicoIn.sndRate < 8000 || PicoIn.sndRate > 44100)
+				PicoIn.sndRate = 22050;
 			if (*tmp == 'H' || *tmp == 'h') tmp++;
 			if (*tmp == 'Z' || *tmp == 'z') tmp++;
 			while (*tmp == ' ') tmp++;

+ 13 - 13
platform/common/emu.c

@@ -604,7 +604,7 @@ void emu_set_defconfig(void)
 {
 	memcpy(&currentConfig, &defaultConfig, sizeof(currentConfig));
 	PicoIn.opt = currentConfig.s_PicoOpt;
-	PsndRate = currentConfig.s_PsndRate;
+	PicoIn.sndRate = currentConfig.s_PsndRate;
 	PicoIn.regionOverride = currentConfig.s_PicoRegion;
 	PicoIn.autoRgnOrder = currentConfig.s_PicoAutoRgnOrder;
 }
@@ -958,10 +958,10 @@ void emu_set_fastforward(int set_on)
 	static int set_Frameskip, set_EmuOpt, is_on = 0;
 
 	if (set_on && !is_on) {
-		set_PsndOut = PsndOut;
+		set_PsndOut = PicoIn.sndOut;
 		set_Frameskip = currentConfig.Frameskip;
 		set_EmuOpt = currentConfig.EmuOpt;
-		PsndOut = NULL;
+		PicoIn.sndOut = NULL;
 		currentConfig.Frameskip = 8;
 		currentConfig.EmuOpt &= ~4;
 		currentConfig.EmuOpt |= 0x40000;
@@ -969,7 +969,7 @@ void emu_set_fastforward(int set_on)
 		emu_status_msg("FAST FORWARD");
 	}
 	else if (!set_on && is_on) {
-		PsndOut = set_PsndOut;
+		PicoIn.sndOut = set_PsndOut;
 		currentConfig.Frameskip = set_Frameskip;
 		currentConfig.EmuOpt = set_EmuOpt;
 		PsndRerate(1);
@@ -1253,9 +1253,9 @@ void emu_init(void)
 	config_readlrom(path);
 
 	PicoInit();
-	PicoMessage = plat_status_msg_busy_next;
-	PicoMCDopenTray = emu_tray_open;
-	PicoMCDcloseTray = emu_tray_close;
+	PicoIn.osdMessage = plat_status_msg_busy_next;
+	PicoIn.mcdTrayOpen = emu_tray_open;
+	PicoIn.mcdTrayClose = emu_tray_close;
 
 	sndout_init();
 }
@@ -1285,12 +1285,12 @@ void emu_finish(void)
 
 static void snd_write_nonblocking(int len)
 {
-	sndout_write_nb(PsndOut, len);
+	sndout_write_nb(PicoIn.sndOut, len);
 }
 
 void emu_sound_start(void)
 {
-	PsndOut = NULL;
+	PicoIn.sndOut = NULL;
 
 	if (currentConfig.EmuOpt & EOPT_EN_SOUND)
 	{
@@ -1299,12 +1299,12 @@ void emu_sound_start(void)
 		PsndRerate(Pico.m.frame_count ? 1 : 0);
 
 		printf("starting audio: %i len: %i stereo: %i, pal: %i\n",
-			PsndRate, PsndLen, is_stereo, Pico.m.pal);
-		sndout_start(PsndRate, is_stereo);
-		PicoWriteSound = snd_write_nonblocking;
+			PicoIn.sndRate, Pico.snd.len, is_stereo, Pico.m.pal);
+		sndout_start(PicoIn.sndRate, is_stereo);
+		PicoIn.writeSound = snd_write_nonblocking;
 		plat_update_volume(0, 0);
 		memset(sndBuffer, 0, sizeof(sndBuffer));
-		PsndOut = sndBuffer;
+		PicoIn.sndOut = sndBuffer;
 	}
 }
 

+ 3 - 3
platform/common/menu_pico.c

@@ -610,7 +610,7 @@ static int mh_opt_misc(int id, int keys)
 {
 	switch (id) {
 	case MA_OPT_SOUND_QUALITY:
-		PsndRate = sndrate_prevnext(PsndRate, keys & PBTN_RIGHT);
+		PicoIn.sndRate = sndrate_prevnext(PicoIn.sndRate, keys & PBTN_RIGHT);
 		break;
 	case MA_OPT_REGION:
 		region_prevnext(keys & PBTN_RIGHT);
@@ -674,7 +674,7 @@ static const char *mgn_opt_sound(int id, int *offs)
 	const char *str2;
 	*offs = -8;
 	str2 = (PicoIn.opt & POPT_EN_STEREO) ? "stereo" : "mono";
-	sprintf(static_buff, "%5iHz %s", PsndRate, str2);
+	sprintf(static_buff, "%5iHz %s", PicoIn.sndRate, str2);
 	return static_buff;
 }
 
@@ -892,7 +892,7 @@ static void debug_menu_loop(void)
 				if (inp & PBTN_UP)    pv->debug_p ^= PVD_KILL_S_HI;
 				if (inp & PBTN_MA2)   pv->debug_p ^= PVD_KILL_32X;
 				if (inp & PBTN_MOK) {
-					PsndOut = NULL; // just in case
+					PicoIn.sndOut = NULL; // just in case
 					PicoIn.skipFrame = 1;
 					PicoFrame();
 					PicoIn.skipFrame = 0;

+ 2 - 2
platform/common/mp3.c

@@ -167,11 +167,11 @@ void mp3_update(int *buffer, int length, int stereo)
 		return;
 
 	length_mp3 = length;
-	if (PsndRate <= 11025 + 100) {
+	if (PicoIn.sndRate <= 11025 + 100) {
 		mix_samples = mix_16h_to_32_s2;
 		length_mp3 <<= 2; shr = 2;
 	}
-	else if (PsndRate <= 22050 + 100) {
+	else if (PicoIn.sndRate <= 22050 + 100) {
 		mix_samples = mix_16h_to_32_s1;
 		length_mp3 <<= 1; shr = 1;
 	}

+ 24 - 24
platform/gizmondo/emu.c

@@ -266,12 +266,12 @@ static void stdbg(const char *fmt, ...)
 static void updateSound(int len)
 {
 	snd_all_samples += len / 2;
-	PsndOut += len / 2;
-	if (PsndOut - snd_cbuff >= snd_cbuf_samples)
+	PicoIn.sndOut += len / 2;
+	if (PicoIn.sndOut - snd_cbuff >= snd_cbuf_samples)
 	{
-		//if (PsndOut - snd_cbuff != snd_cbuf_samples)
-		//	stdbg("snd diff is %i, not %i", PsndOut - snd_cbuff, snd_cbuf_samples);
-		PsndOut = snd_cbuff;
+		//if (PicoIn.sndOut - snd_cbuff != snd_cbuf_samples)
+		//	stdbg("snd diff is %i, not %i", PicoIn.sndOut - snd_cbuff, snd_cbuf_samples);
+		PicoIn.sndOut = snd_cbuff;
 	}
 }
 
@@ -317,7 +317,7 @@ static void RunEvents(unsigned int which)
 	{
 		int do_it = 1;
 
-		if (PsndOut != NULL)
+		if (PicoIn.sndOut != NULL)
 			FrameworkAudio_SetPause(1);
 		if (giz_screen == NULL)
 			giz_screen = fb_lock(1);
@@ -344,7 +344,7 @@ static void RunEvents(unsigned int which)
 			Sleep(0);
 		}
 
-		if (PsndOut != NULL)
+		if (PicoIn.sndOut != NULL)
 			FrameworkAudio_SetPause(0);
 		reset_timing = 1;
 	}
@@ -401,7 +401,7 @@ static void updateKeys(void)
 	events = (allActions[0] | allActions[1]) >> 16;
 
 	// volume is treated in special way and triggered every frame
-	if ((events & 0x6000) && PsndOut != NULL)
+	if ((events & 0x6000) && PicoIn.sndOut != NULL)
 	{
 		int vol = currentConfig.volume;
 		if (events & 0x2000) {
@@ -469,19 +469,19 @@ void pemu_loop(void)
 	if (PicoIn.AHW & PAHW_MCD) PicoCDBufferInit();
 
 	// prepare sound stuff
-	PsndOut = NULL;
+	PicoIn.sndOut = NULL;
 	if (currentConfig.EmuOpt & 4)
 	{
 		int ret, snd_excess_add, stereo;
-		if (PsndRate != PsndRate_old || (PicoIn.opt&0x0b) != (PicoOpt_old&0x0b) || Pico.m.pal != pal_old) {
+		if (PicoIn.sndRate != PsndRate_old || (PicoIn.opt&0x0b) != (PicoOpt_old&0x0b) || Pico.m.pal != pal_old) {
 			PsndRerate(Pico.m.frame_count ? 1 : 0);
 		}
 		stereo=(PicoIn.opt&8)>>3;
-		snd_excess_add = ((PsndRate - PsndLen*target_fps)<<16) / target_fps;
-		snd_cbuf_samples = (PsndRate<<stereo) * 16 / target_fps;
+		snd_excess_add = ((PicoIn.sndRate - Pico.snd.len*target_fps)<<16) / target_fps;
+		snd_cbuf_samples = (PicoIn.sndRate<<stereo) * 16 / target_fps;
 		lprintf("starting audio: %i len: %i (ex: %04x) stereo: %i, pal: %i\n",
-			PsndRate, PsndLen, snd_excess_add, stereo, Pico.m.pal);
-		ret = FrameworkAudio_Init(PsndRate, snd_cbuf_samples, stereo);
+			PicoIn.sndRate, Pico.snd.len, snd_excess_add, stereo, Pico.m.pal);
+		ret = FrameworkAudio_Init(PicoIn.sndRate, snd_cbuf_samples, stereo);
 		if (ret != 0) {
 			lprintf("FrameworkAudio_Init() failed: %i\n", ret);
 			sprintf(noticeMsg, "sound init failed (%i), snd disabled", ret);
@@ -489,11 +489,11 @@ void pemu_loop(void)
 			currentConfig.EmuOpt &= ~4;
 		} else {
 			FrameworkAudio_SetVolume(currentConfig.volume, currentConfig.volume);
-			PicoWriteSound = updateSound;
+			PicoIn.writeSound = updateSound;
 			snd_cbuff = FrameworkAudio_56448Buffer();
-			PsndOut = snd_cbuff + snd_cbuf_samples / 2; // start writing at the middle
+			PicoIn.sndOut = snd_cbuff + snd_cbuf_samples / 2; // start writing at the middle
 			snd_all_samples = 0;
-			PsndRate_old = PsndRate;
+			PsndRate_old = PicoIn.sndRate;
 			PicoOpt_old  = PicoIn.opt;
 			pal_old = Pico.m.pal;
 		}
@@ -553,14 +553,14 @@ void pemu_loop(void)
 			//tval_thissec += 1000;
 			tval_thissec += sec_ms;
 
-			if (PsndOut != NULL)
+			if (PicoIn.sndOut != NULL)
 			{
 				/* some code which tries to sync things to audio clock, the dirty way */
 				static int audio_skew_prev = 0;
 				int audio_skew, adj, co = 9, shift = 7;
 				audio_skew = snd_all_samples*2 - FrameworkAudio_BufferPos();
-				if (PsndRate == 22050) co = 10;
-				if (PsndRate  > 22050) co = 11;
+				if (PicoIn.sndRate == 22050) co = 10;
+				if (PicoIn.sndRate  > 22050) co = 11;
 				if (PicoIn.opt&8) shift++;
 				if (audio_skew < 0) {
 					adj = -((-audio_skew) >> shift);
@@ -600,7 +600,7 @@ void pemu_loop(void)
 			for (i = 0; i < currentConfig.Frameskip; i++) {
 				updateKeys();
 				SkipFrame(); frames_done++;
-				if (PsndOut) { // do framelimitting if sound is enabled
+				if (PicoIn.sndOut) { // do framelimitting if sound is enabled
 					int tval_diff;
 					tval = GetTickCount();
 					tval_diff = (int)(tval - tval_thissec) << 8;
@@ -660,7 +660,7 @@ void pemu_loop(void)
 
 		if (currentConfig.Frameskip < 0 && tval_diff - lim_time >= (300<<8)) // slowdown detection
 			reset_timing = 1;
-		else if (PsndOut != NULL || currentConfig.Frameskip < 0)
+		else if (PicoIn.sndOut != NULL || currentConfig.Frameskip < 0)
 		{
 			// sleep if we are still too fast
 			if (tval_diff < lim_time)
@@ -676,8 +676,8 @@ void pemu_loop(void)
 
 	if (PicoIn.AHW & PAHW_MCD) PicoCDBufferFree();
 
-	if (PsndOut != NULL) {
-		PsndOut = snd_cbuff = NULL;
+	if (PicoIn.sndOut != NULL) {
+		PicoIn.sndOut = snd_cbuff = NULL;
 		FrameworkAudio_Close();
 	}
 

+ 6 - 6
platform/gizmondo/menu.c

@@ -1046,7 +1046,7 @@ static void menu_opt_cust_draw(const menu_entry *entry, int x, int y, void *para
 			break;
 		case MA_OPT_SOUND_QUALITY:
 			str = (PicoIn.opt&0x08)?"stereo":"mono";
-			text_out16(x, y, "Sound Quality:     %5iHz %s", PsndRate, str);
+			text_out16(x, y, "Sound Quality:     %5iHz %s", PicoIn.sndRate, str);
 			break;
 		case MA_OPT_REGION:
 			text_out16(x, y, "Region:              %s", me_region_name(PicoIn.regionOverride, PicoIn.autoRgnOrder));
@@ -1174,18 +1174,18 @@ static int menu_loop_options(void)
 						}
 						break;
 					case MA_OPT_SOUND_QUALITY:
-						if ((inp & PBTN_RIGHT) && PsndRate == 44100 &&
+						if ((inp & PBTN_RIGHT) && PicoIn.sndRate == 44100 &&
 								!(PicoIn.opt&0x08))
 						{
-							PsndRate =  11025;
+							PicoIn.sndRate =  11025;
 							PicoIn.opt |=  8;
-						} else if ((inp & PBTN_LEFT) && PsndRate == 11025 &&
+						} else if ((inp & PBTN_LEFT) && PicoIn.sndRate == 11025 &&
 								(PicoIn.opt&0x08) && !(PicoIn.AHW&1))
 						{
-							PsndRate =  44100;
+							PicoIn.sndRate =  44100;
 							PicoIn.opt &= ~8;
 						} else
-							PsndRate = sndrate_prevnext(PsndRate, inp & PBTN_RIGHT);
+							PicoIn.sndRate = sndrate_prevnext(PicoIn.sndRate, inp & PBTN_RIGHT);
 						break;
 					case MA_OPT_REGION:
 						region_prevnext(inp & PBTN_RIGHT);

+ 5 - 5
platform/gp2x/940ctl.c

@@ -402,9 +402,9 @@ int YM2612UpdateOne_940(int *buffer, int length, int stereo, int is_buf_empty)
 	writebuff_ptr = 0;
 
 	/* predict sample counter for next frame */
-	if (PsndLen_exc_add) {
-		length = PsndLen;
-		if (PsndLen_exc_cnt + PsndLen_exc_add >= 0x10000) length++;
+	if (Pico.snd.len_e_add) {
+		length = Pico.snd.len;
+		if (Pico.snd.len_e_cnt + Pico.snd.len_e_add >= 0x10000) length++;
 	}
 
 	/* give 940 ym job */
@@ -463,11 +463,11 @@ int mp3dec_start(FILE *f, int fpos_start)
 
 	if (loaded_mp3 != f)
 	{
-		if (PicoMessage != NULL)
+		if (PicoIn.osdMessage != NULL)
 		{
 			fseek(f, 0, SEEK_END);
 			if (ftell(f) > 2*1024*1024)
-				PicoMessage("Loading MP3...");
+				PicoIn.osdMessage("Loading MP3...");
 		}
 		fseek(f, 0, SEEK_SET);
 		fread(mp3_mem, 1, MP3_SIZE_MAX, f);

+ 4 - 4
platform/gp2x/emu.c

@@ -692,7 +692,7 @@ void pemu_sound_start(void)
 	{
 		soc = soc_detect();
 		if (soc == SOCID_POLLUX) {
-			PsndRate = pollux_get_real_snd_rate(PsndRate);
+			PicoIn.sndRate = pollux_get_real_snd_rate(PicoIn.sndRate);
 			PsndRerate(Pico.m.frame_count ? 1 : 0);
 		}
 
@@ -707,10 +707,10 @@ void pemu_sound_stop(void)
 	int i;
 
 	/* get back from Pollux pain */
-	PsndRate += 1000;
+	PicoIn.sndRate += 1000;
 	for (i = 0; i < ARRAY_SIZE(sound_rates); i++) {
-		if (PsndRate >= sound_rates[i]) {
-			PsndRate = sound_rates[i];
+		if (PicoIn.sndRate >= sound_rates[i]) {
+			PicoIn.sndRate = sound_rates[i];
 			break;
 		}
 	}

+ 7 - 7
platform/libretro/libretro.c

@@ -1088,9 +1088,9 @@ bool retro_load_game(const struct retro_game_info *info)
 
    PicoLoopPrepare();
 
-   PicoWriteSound = snd_write;
+   PicoIn.writeSound = snd_write;
    memset(sndBuffer, 0, sizeof(sndBuffer));
-   PsndOut = sndBuffer;
+   PicoIn.sndOut = sndBuffer;
    PsndRerate(0);
 
    return true;
@@ -1193,7 +1193,7 @@ static const unsigned short retro_pico_map[] = {
 
 static void snd_write(int len)
 {
-   audio_batch_cb(PsndOut, len / 4);
+   audio_batch_cb(PicoIn.sndOut, len / 4);
 }
 
 static enum input_device input_name_to_val(const char *name)
@@ -1375,7 +1375,7 @@ void retro_init(void)
 #endif
       PicoIn.opt |= POPT_EN_DRC;
 #endif
-   PsndRate = 44100;
+   PicoIn.sndRate = 44100;
    PicoIn.autoRgnOrder = 0x184; // US, EU, JP
 
    vout_width = 320;
@@ -1390,9 +1390,9 @@ void retro_init(void)
    PicoDrawSetOutFormat(PDF_RGB555, 0);
    PicoDrawSetOutBuf(vout_buf, vout_width * 2);
 
-   //PicoMessage = plat_status_msg_busy_next;
-   PicoMCDopenTray = disk_tray_open;
-   PicoMCDcloseTray = disk_tray_close;
+   //PicoIn.osdMessage = plat_status_msg_busy_next;
+   PicoIn.mcdTrayOpen = disk_tray_open;
+   PicoIn.mcdTrayClose = disk_tray_close;
 
    update_variables();
 }

+ 17 - 17
platform/psp/emu.c

@@ -571,32 +571,32 @@ void pemu_sound_start(void)
 
 	samples_made = samples_done = 0;
 
-	if (PsndRate != PsndRate_old || (PicoIn.opt&0x0b) != (PicoOpt_old&0x0b) || Pico.m.pal != pal_old) {
+	if (PicoIn.sndRate != PsndRate_old || (PicoIn.opt&0x0b) != (PicoOpt_old&0x0b) || Pico.m.pal != pal_old) {
 		PsndRerate(Pico.m.frame_count ? 1 : 0);
 	}
 	stereo=(PicoIn.opt&8)>>3;
 
 	samples_block = Pico.m.pal ? SOUND_BLOCK_SIZE_PAL : SOUND_BLOCK_SIZE_NTSC;
-	if (PsndRate <= 22050) samples_block /= 2;
+	if (PicoIn.sndRate <= 22050) samples_block /= 2;
 	sndBuffer_endptr = &sndBuffer[samples_block*SOUND_BLOCK_COUNT];
 
 	lprintf("starting audio: %i, len: %i, stereo: %i, pal: %i, block samples: %i\n",
-			PsndRate, PsndLen, stereo, Pico.m.pal, samples_block);
+			PicoIn.sndRate, Pico.snd.len, stereo, Pico.m.pal, samples_block);
 
 	// while (sceAudioOutput2GetRestSample() > 0) psp_msleep(100);
 	// sceAudio_5C37C0AE();
-	ret = sceAudio_38553111(samples_block/2, PsndRate, 2); // seems to not need that stupid 64byte alignment
+	ret = sceAudio_38553111(samples_block/2, PicoIn.sndRate, 2); // seems to not need that stupid 64byte alignment
 	if (ret < 0) {
 		lprintf("sceAudio_38553111() failed: %i\n", ret);
 		emu_status_msg("sound init failed (%i), snd disabled", ret);
 		currentConfig.EmuOpt &= ~EOPT_EN_SOUND;
 	} else {
-		PicoWriteSound = writeSound;
+		PicoIn.writeSound = writeSound;
 		memset32((int *)(void *)sndBuffer, 0, sizeof(sndBuffer)/4);
 		snd_playptr = sndBuffer_endptr - samples_block;
 		samples_made = samples_block; // send 1 empty block first..
-		PsndOut = sndBuffer;
-		PsndRate_old = PsndRate;
+		PicoIn.sndOut = sndBuffer;
+		PsndRate_old = PicoIn.sndRate;
 		PicoOpt_old  = PicoIn.opt;
 		pal_old = Pico.m.pal;
 	}
@@ -641,16 +641,16 @@ static void writeSound(int len)
 {
 	int ret;
 
-	PsndOut += len / 2;
-	/*if (PsndOut > sndBuffer_endptr) {
-		memcpy32((int *)(void *)sndBuffer, (int *)endptr, (PsndOut - endptr + 1) / 2);
-		PsndOut = &sndBuffer[PsndOut - endptr];
+	PicoIn.sndOut += len / 2;
+	/*if (PicoIn.sndOut > sndBuffer_endptr) {
+		memcpy32((int *)(void *)sndBuffer, (int *)endptr, (PicoIn.sndOut - endptr + 1) / 2);
+		PicoIn.sndOut = &sndBuffer[PicoIn.sndOut - endptr];
 		lprintf("mov\n");
 	}
 	else*/
-	if (PsndOut > sndBuffer_endptr) lprintf("snd oflow %i!\n", PsndOut - sndBuffer_endptr);
-	if (PsndOut >= sndBuffer_endptr)
-		PsndOut = sndBuffer;
+	if (PicoIn.sndOut > sndBuffer_endptr) lprintf("snd oflow %i!\n", PicoIn.sndOut - sndBuffer_endptr);
+	if (PicoIn.sndOut >= sndBuffer_endptr)
+		PicoIn.sndOut = sndBuffer;
 
 	// signal the snd thread
 	samples_made += len / 2;
@@ -873,7 +873,7 @@ void pemu_loop(void)
 	}
 
 	// prepare sound stuff
-	PsndOut = NULL;
+	PicoIn.sndOut = NULL;
 	if (currentConfig.EmuOpt & EOPT_EN_SOUND)
 	{
 		pemu_sound_start();
@@ -1021,9 +1021,9 @@ void pemu_loop(void)
 
 	if (PicoIn.AHW & PAHW_MCD) PicoCDBufferFree();
 
-	if (PsndOut != NULL) {
+	if (PicoIn.sndOut != NULL) {
 		pemu_sound_stop();
-		PsndOut = NULL;
+		PicoIn.sndOut = NULL;
 	}
 
 	// save SRAM

+ 2 - 2
platform/psp/menu.c

@@ -1227,7 +1227,7 @@ static void menu_opt_cust_draw(const menu_entry *entry, int x, int y, void *para
 			break;
 		case MA_OPT_SOUND_QUALITY:
 			str = (PicoIn.opt&0x08)?"stereo":"mono";
-			text_out16(x, y, "Sound Quality:     %5iHz %s", PsndRate, str);
+			text_out16(x, y, "Sound Quality:     %5iHz %s", PicoIn.sndRate, str);
 			break;
 		case MA_OPT_REGION:
 			text_out16(x, y, "Region:              %s", me_region_name(PicoIn.regionOverride, PicoIn.autoRgnOrder));
@@ -1353,7 +1353,7 @@ static int menu_loop_options(void)
 						}
 						break;
 					case MA_OPT_SOUND_QUALITY:
-						PsndRate = sndrate_prevnext(PsndRate, inp & PBTN_RIGHT);
+						PicoIn.sndRate = sndrate_prevnext(PicoIn.sndRate, inp & PBTN_RIGHT);
 						break;
 					case MA_OPT_REGION:
 						region_prevnext(inp & PBTN_RIGHT);

+ 4 - 4
platform/psp/mp3.c

@@ -403,8 +403,8 @@ void mp3_update(int *buffer, int length, int stereo)
 	if (mp3_handle < 0 || mp3_src_pos >= mp3_src_size) return;
 
 	length_mp3 = length;
-	if (PsndRate == 22050) length_mp3 <<= 1;	// mp3s are locked to 44100Hz stereo
-	else if (PsndRate == 11025) length_mp3 <<= 2;	// so make length 44100ish
+	if (PicoIn.sndRate == 22050) length_mp3 <<= 1;	// mp3s are locked to 44100Hz stereo
+	else if (PicoIn.sndRate == 11025) length_mp3 <<= 2;	// so make length 44100ish
 
 	/* do we have to wait? */
 	if (mp3_job_started && mp3_samples_ready < length_mp3)
@@ -420,8 +420,8 @@ void mp3_update(int *buffer, int length, int stereo)
 	{
 		int shr = 0;
 		void (*mix_samples)(int *dest_buf, short *mp3_buf, int count) = mix_16h_to_32;
-		if (PsndRate == 22050) { mix_samples = mix_16h_to_32_s1; shr = 1; }
-		else if (PsndRate == 11025) { mix_samples = mix_16h_to_32_s2; shr = 2; }
+		if (PicoIn.sndRate == 22050) { mix_samples = mix_16h_to_32_s1; shr = 1; }
+		else if (PicoIn.sndRate == 11025) { mix_samples = mix_16h_to_32_s2; shr = 2; }
 
 		if (1152 - mp3_buffer_offs >= length_mp3) {
 			mix_samples(buffer, mp3_mix_buffer[mp3_play_bufsel] + mp3_buffer_offs*2, length<<1);

+ 4 - 4
platform/win32/plat.c

@@ -131,7 +131,7 @@ void pemu_sound_start(void)
 {
 	int ret;
 
-	PsndOut = NULL;
+	PicoIn.sndOut = NULL;
 	currentConfig.EmuOpt &= ~EOPT_EXT_FRMLIMIT;
 
 	// prepare sound stuff
@@ -139,14 +139,14 @@ void pemu_sound_start(void)
 	{
 		PsndRerate(0);
 
-		ret = DSoundInit(FrameWnd, PsndRate, (PicoIn.opt & POPT_EN_STEREO) ? 1 : 0, PsndLen);
+		ret = DSoundInit(FrameWnd, PicoIn.sndRate, (PicoIn.opt & POPT_EN_STEREO) ? 1 : 0, Pico.snd.len);
 		if (ret != 0) {
 			lprintf("dsound init failed\n");
 			return;
 		}
 
-		PsndOut = (void *)sndbuff;
-		PicoWriteSound = update_sound;
+		PicoIn.sndOut = (void *)sndbuff;
+		PicoIn.writeSound = update_sound;
 		currentConfig.EmuOpt |= EOPT_EXT_FRMLIMIT;
 	}
 }

+ 1 - 1
tools/mkoffsets.c

@@ -58,7 +58,7 @@ int main(int argc, char *argv[])
   DUMP_EST(f, Pico);
   DUMP_EST(f, PicoMem_vram);
   DUMP_EST(f, PicoMem_cram);
-  DUMP_EST(f, PicoIn.opt);
+  DUMP_EST(f, PicoOpt);
   DUMP_EST(f, Draw2FB);
   DUMP_EST(f, HighPal);
   DUMP_PMEM(f, vram);