more cleanup
authorJavier S. Pedro <maemo@javispedro.com>
Sun, 4 Oct 2009 21:04:09 +0000 (23:04 +0200)
committerJavier S. Pedro <maemo@javispedro.com>
Sun, 4 Oct 2009 21:04:09 +0000 (23:04 +0200)
Makefile
cheats.cpp
font.c [new file with mode: 0644]
font.h
loadzip.cpp
sounduxnew.cpp [deleted file]
sounduxnew.h [deleted file]
usbjoy.c [deleted file]
usbjoy.h [deleted file]

index a29066a..bf5d5a3 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -22,8 +22,8 @@ endif
 
 # SNES stuff
 OBJS = apu.o c4.o c4emu.o cheats.o cheats2.o clip.o cpu.o cpuexec.o data.o
-OBJS += dma.o dsp1.o fxemu.o fxinst.o gfx.o globals.o loadzip.o memmap.o netplay.o ppu.o
-OBJS += sa1.o sdd1.o sdd1emu.o snapshot.o soundux.o spc700.o srtc.o tile.o
+OBJS += dma.o dsp1.o font.o fxemu.o fxinst.o gfx.o globals.o loadzip.o memmap.o 
+OBJS += ppu.o sa1.o sdd1.o sdd1emu.o snapshot.o soundux.o spc700.o srtc.o tile.o
 
 ifeq ($(CONF_BUILD_ASM_CPU), 1)
        # ASM CPU Core from yoyofr's OpenSnes9X
index 3ea9d05..b055ed4 100644 (file)
@@ -98,7 +98,7 @@ const char *S9xGoldFingerToRaw (const char *code, uint32 &address, bool8 &sram,
 const char *S9xGameGenieToRaw (const char *code, uint32 &address, uint8 &byte)
 {
     char new_code [12];
-    
+
     if (strlen (code) != 9 || *(code + 4) != '-' || !S9xAllHex (code, 4) ||
         !S9xAllHex (code + 5, 4))
        return ("Invalid Game Genie(tm) code - should be 'xxxx-xxxx'.");
@@ -109,7 +109,7 @@ const char *S9xGameGenieToRaw (const char *code, uint32 &address, uint8 &byte)
 
     static const char *real_hex  = "0123456789ABCDEF";
     static const char *genie_hex = "DF4709156BC8A23E";
-    
+
     for (int i = 2; i < 10; i++)
     {
        if (islower (new_code [i]))
diff --git a/font.c b/font.c
new file mode 100644 (file)
index 0000000..365f9be
--- /dev/null
+++ b/font.c
@@ -0,0 +1,101 @@
+/*
+ * Snes9x - Portable Super Nintendo Entertainment System (TM) emulator.
+ *
+ * (c) Copyright 1996 - 2001 Gary Henderson (gary.henderson@ntlworld.com) and
+ *                           Jerremy Koot (jkoot@snes9x.com)
+ *
+ * Super FX C emulator code
+ * (c) Copyright 1997 - 1999 Ivar (ivar@snes9x.com) and
+ *                           Gary Henderson.
+ * Super FX assembler emulator code (c) Copyright 1998 zsKnight and _Demo_.
+ *
+ * DSP1 emulator code (c) Copyright 1998 Ivar, _Demo_ and Gary Henderson.
+ * C4 asm and some C emulation code (c) Copyright 2000 zsKnight and _Demo_.
+ * C4 C code (c) Copyright 2001 Gary Henderson (gary.henderson@ntlworld.com).
+ *
+ * DOS port code contains the works of other authors. See headers in
+ * individual files.
+ *
+ * Snes9x homepage: http://www.snes9x.com
+ *
+ * Permission to use, copy, modify and distribute Snes9x in both binary and
+ * source form, for non-commercial purposes, is hereby granted without fee,
+ * providing that this license information and copyright notice appear with
+ * all copies and any derived work.
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty. In no event shall the authors be held liable for any damages
+ * arising from the use of this software.
+ *
+ * Snes9x is freeware for PERSONAL USE only. Commercial users should
+ * seek permission of the copyright holders first. Commercial use includes
+ * charging money for Snes9x or software derived from Snes9x.
+ *
+ * The copyright holders request that bug fixes and improvements to the code
+ * should be forwarded to them so everyone can benefit from the modifications
+ * in future versions.
+ *
+ * Super NES and Super Nintendo Entertainment System are trademarks of
+ * Nintendo Co., Limited and its subsidiary companies.
+ */
+
+#include "port.h"
+#include "font.h"
+
+const char *font[] = {
+"           .      . .                    .                ..       .      .                                                     ",
+"          .#.    .#.#.    . .     ...   .#. .     .      .##.     .#.    .#.     . .       .                                .   ",
+"          .#.    .#.#.   .#.#.   .###.  .#..#.   .#.     .#.     .#.      .#.   .#.#.     .#.                              .#.  ",
+"          .#.    .#.#.  .#####. .#.#.    ..#.   .#.#.   .#.      .#.      .#.    .#.     ..#..           ....             .#.   ",
+"          .#.     . .    .#.#.   .###.   .#..    .#.     .       .#.      .#.   .###.   .#####.   ..    .####.    ..     .#.    ",
+"           .            .#####.   .#.#. .#..#.  .#.#.            .#.      .#.    .#.     ..#..   .##.    ....    .##.   .#.     ",
+"          .#.            .#.#.   .###.   . .#.   .#.#.            .#.    .#.    .#.#.     .#.    .#.             .##.    .      ",
+"           .              . .     ...       .     . .              .      .      . .       .    .#.               ..            ",
+"                                                                                                 .                              ",
+"  .       .       ..     ....      .     ....     ..     ....     ..      ..                                              .     ",
+" .#.     .#.     .##.   .####.    .#.   .####.   .##.   .####.   .##.    .##.     ..      ..       .             .       .#.    ",
+".#.#.   .##.    .#..#.   ...#.   .##.   .#...   .#..     ...#.  .#..#.  .#..#.   .##.    .##.     .#.    ....   .#.     .#.#.   ",
+".#.#.    .#.     . .#.   .##.   .#.#.   .###.   .###.     .#.    .##.   .#..#.   .##.    .##.    .#.    .####.   .#.     ..#.   ",
+".#.#.    .#.      .#.    ...#.  .####.   ...#.  .#..#.    .#.   .#..#.   .###.    ..      ..    .#.      ....     .#.    .#.    ",
+".#.#.    .#.     .#..   .#..#.   ..#.   .#..#.  .#..#.   .#.    .#..#.    ..#.   .##.    .##.    .#.    .####.   .#.      .     ",
+" .#.    .###.   .####.   .##.     .#.    .##.    .##.    .#.     .##.    .##.    .##.    .#.      .#.    ....   .#.      .#.    ",
+"  .      ...     ....     ..       .      ..      ..      .       ..      ..      ..    .#.        .             .        .     ",
+"                                                                                         .                                      ",
+"  ..      ..     ...      ..     ...     ....    ....     ..     .  .    ...        .    .  .    .       .   .   .   .    ..    ",
+" .##.    .##.   .###.    .##.   .###.   .####.  .####.   .##.   .#..#.  .###.      .#.  .#..#.  .#.     .#. .#. .#. .#.  .##.   ",
+".#..#.  .#..#.  .#..#.  .#..#.  .#..#.  .#...   .#...   .#..#.  .#..#.   .#.       .#.  .#.#.   .#.     .##.##. .##..#. .#..#.  ",
+".#.##.  .#..#.  .###.   .#. .   .#..#.  .###.   .###.   .#...   .####.   .#.       .#.  .##.    .#.     .#.#.#. .#.#.#. .#..#.  ",
+".#.##.  .####.  .#..#.  .#. .   .#..#.  .#..    .#..    .#.##.  .#..#.   .#.     . .#.  .##.    .#.     .#...#. .#.#.#. .#..#.  ",
+".#...   .#..#.  .#..#.  .#..#.  .#..#.  .#...   .#.     .#..#.  .#..#.   .#.    .#..#.  .#.#.   .#...   .#. .#. .#..##. .#..#.  ",
+" .##.   .#..#.  .###.    .##.   .###.   .####.  .#.      .###.  .#..#.  .###.    .##.   .#..#.  .####.  .#. .#. .#. .#.  .##.   ",
+"  ..     .  .    ...      ..     ...     ....    .        ...    .  .    ...      ..     .  .    ....    .   .   .   .    ..    ",
+"                                                                                                                                ",
+" ...      ..     ...      ..     ...     .   .   .   .   .   .   .  .    . .     ....    ...             ...      .             ",
+".###.    .##.   .###.    .##.   .###.   .#. .#. .#. .#. .#. .#. .#..#.  .#.#.   .####.  .###.    .      .###.    .#.            ",
+".#..#.  .#..#.  .#..#.  .#..#.   .#.    .#. .#. .#. .#. .#...#. .#..#.  .#.#.    ...#.  .#..    .#.      ..#.   .#.#.           ",
+".#..#.  .#..#.  .#..#.   .#..    .#.    .#. .#. .#. .#. .#.#.#.  .##.   .#.#.     .#.   .#.      .#.      .#.    . .            ",
+".###.   .#..#.  .###.    ..#.    .#.    .#. .#. .#. .#. .#.#.#. .#..#.   .#.     .#.    .#.       .#.     .#.                   ",
+".#..    .##.#.  .#.#.   .#..#.   .#.    .#...#.  .#.#.  .##.##. .#..#.   .#.    .#...   .#..       .#.   ..#.            ....   ",
+".#.      .##.   .#..#.   .##.    .#.     .###.    .#.   .#. .#. .#..#.   .#.    .####.  .###.       .   .###.           .####.  ",
+" .        ..#.   .  .     ..      .       ...      .     .   .   .  .     .      ....    ...             ...             ....   ",
+"            .                                                                                                                   ",
+" ..              .                  .              .             .        .        .     .       ..                             ",
+".##.            .#.                .#.            .#.           .#.      .#.      .#.   .#.     .##.                            ",
+" .#.      ...   .#..      ..      ..#.    ..     .#.#.    ...   .#..     ..        .    .#..     .#.     .. ..   ...      ..    ",
+"  .#.    .###.  .###.    .##.    .###.   .##.    .#..    .###.  .###.   .##.      .#.   .#.#.    .#.    .##.##. .###.    .##.   ",
+"   .    .#..#.  .#..#.  .#..    .#..#.  .#.##.  .###.   .#..#.  .#..#.   .#.      .#.   .##.     .#.    .#.#.#. .#..#.  .#..#.  ",
+"        .#.##.  .#..#.  .#..    .#..#.  .##..    .#.     .##.   .#..#.   .#.     ..#.   .#.#.    .#.    .#...#. .#..#.  .#..#.  ",
+"         .#.#.  .###.    .##.    .###.   .##.    .#.    .#...   .#..#.  .###.   .#.#.   .#..#.  .###.   .#. .#. .#..#.   .##.   ",
+"          . .    ...      ..      ...     ..      .      .###.   .  .    ...     .#.     .  .    ...     .   .   .  .     ..    ",
+"                                                          ...                     .                                             ",
+"                                  .                                                        .      .      .        . .           ",
+"                                 .#.                                                      .#.    .#.    .#.      .#.#.          ",
+" ...      ...    ...      ...    .#.     .  .    . .     .   .   .  .    .  .    ....    .#.     .#.     .#.    .#.#.           ",
+".###.    .###.  .###.    .###.  .###.   .#..#.  .#.#.   .#...#. .#..#.  .#..#.  .####.  .##.     .#.     .##.    . .            ",
+".#..#.  .#..#.  .#..#.  .##..    .#.    .#..#.  .#.#.   .#.#.#.  .##.   .#..#.   ..#.    .#.     .#.     .#.                    ",
+".#..#.  .#..#.  .#. .    ..##.   .#..   .#..#.  .#.#.   .#.#.#.  .##.    .#.#.   .#..    .#.     .#.     .#.                    ",
+".###.    .###.  .#.     .###.     .##.   .###.   .#.     .#.#.  .#..#.    .#.   .####.    .#.    .#.    .#.                     ",
+".#..      ..#.   .       ...       ..     ...     .       . .    .  .    .#.     ....      .      .      .                      ",
+" .          .                                                             .                                                     ",
+};
+
diff --git a/font.h b/font.h
index af19166..d85e942 100644 (file)
--- a/font.h
+++ b/font.h
  * Super NES and Super Nintendo Entertainment System are trademarks of
  * Nintendo Co., Limited and its subsidiary companies.
  */
-const char *font[] = {
-"           .      . .                    .                ..       .      .                                                     ",
-"          .#.    .#.#.    . .     ...   .#. .     .      .##.     .#.    .#.     . .       .                                .   ",
-"          .#.    .#.#.   .#.#.   .###.  .#..#.   .#.     .#.     .#.      .#.   .#.#.     .#.                              .#.  ",
-"          .#.    .#.#.  .#####. .#.#.    ..#.   .#.#.   .#.      .#.      .#.    .#.     ..#..           ....             .#.   ",
-"          .#.     . .    .#.#.   .###.   .#..    .#.     .       .#.      .#.   .###.   .#####.   ..    .####.    ..     .#.    ",
-"           .            .#####.   .#.#. .#..#.  .#.#.            .#.      .#.    .#.     ..#..   .##.    ....    .##.   .#.     ",
-"          .#.            .#.#.   .###.   . .#.   .#.#.            .#.    .#.    .#.#.     .#.    .#.             .##.    .      ",
-"           .              . .     ...       .     . .              .      .      . .       .    .#.               ..            ",
-"                                                                                                 .                              ",
-"  .       .       ..     ....      .     ....     ..     ....     ..      ..                                              .     ",
-" .#.     .#.     .##.   .####.    .#.   .####.   .##.   .####.   .##.    .##.     ..      ..       .             .       .#.    ",
-".#.#.   .##.    .#..#.   ...#.   .##.   .#...   .#..     ...#.  .#..#.  .#..#.   .##.    .##.     .#.    ....   .#.     .#.#.   ",
-".#.#.    .#.     . .#.   .##.   .#.#.   .###.   .###.     .#.    .##.   .#..#.   .##.    .##.    .#.    .####.   .#.     ..#.   ",
-".#.#.    .#.      .#.    ...#.  .####.   ...#.  .#..#.    .#.   .#..#.   .###.    ..      ..    .#.      ....     .#.    .#.    ",
-".#.#.    .#.     .#..   .#..#.   ..#.   .#..#.  .#..#.   .#.    .#..#.    ..#.   .##.    .##.    .#.    .####.   .#.      .     ",
-" .#.    .###.   .####.   .##.     .#.    .##.    .##.    .#.     .##.    .##.    .##.    .#.      .#.    ....   .#.      .#.    ",
-"  .      ...     ....     ..       .      ..      ..      .       ..      ..      ..    .#.        .             .        .     ",
-"                                                                                         .                                      ",
-"  ..      ..     ...      ..     ...     ....    ....     ..     .  .    ...        .    .  .    .       .   .   .   .    ..    ",
-" .##.    .##.   .###.    .##.   .###.   .####.  .####.   .##.   .#..#.  .###.      .#.  .#..#.  .#.     .#. .#. .#. .#.  .##.   ",
-".#..#.  .#..#.  .#..#.  .#..#.  .#..#.  .#...   .#...   .#..#.  .#..#.   .#.       .#.  .#.#.   .#.     .##.##. .##..#. .#..#.  ",
-".#.##.  .#..#.  .###.   .#. .   .#..#.  .###.   .###.   .#...   .####.   .#.       .#.  .##.    .#.     .#.#.#. .#.#.#. .#..#.  ",
-".#.##.  .####.  .#..#.  .#. .   .#..#.  .#..    .#..    .#.##.  .#..#.   .#.     . .#.  .##.    .#.     .#...#. .#.#.#. .#..#.  ",
-".#...   .#..#.  .#..#.  .#..#.  .#..#.  .#...   .#.     .#..#.  .#..#.   .#.    .#..#.  .#.#.   .#...   .#. .#. .#..##. .#..#.  ",
-" .##.   .#..#.  .###.    .##.   .###.   .####.  .#.      .###.  .#..#.  .###.    .##.   .#..#.  .####.  .#. .#. .#. .#.  .##.   ",
-"  ..     .  .    ...      ..     ...     ....    .        ...    .  .    ...      ..     .  .    ....    .   .   .   .    ..    ",
-"                                                                                                                                ",
-" ...      ..     ...      ..     ...     .   .   .   .   .   .   .  .    . .     ....    ...             ...      .             ",
-".###.    .##.   .###.    .##.   .###.   .#. .#. .#. .#. .#. .#. .#..#.  .#.#.   .####.  .###.    .      .###.    .#.            ",
-".#..#.  .#..#.  .#..#.  .#..#.   .#.    .#. .#. .#. .#. .#...#. .#..#.  .#.#.    ...#.  .#..    .#.      ..#.   .#.#.           ",
-".#..#.  .#..#.  .#..#.   .#..    .#.    .#. .#. .#. .#. .#.#.#.  .##.   .#.#.     .#.   .#.      .#.      .#.    . .            ",
-".###.   .#..#.  .###.    ..#.    .#.    .#. .#. .#. .#. .#.#.#. .#..#.   .#.     .#.    .#.       .#.     .#.                   ",
-".#..    .##.#.  .#.#.   .#..#.   .#.    .#...#.  .#.#.  .##.##. .#..#.   .#.    .#...   .#..       .#.   ..#.            ....   ",
-".#.      .##.   .#..#.   .##.    .#.     .###.    .#.   .#. .#. .#..#.   .#.    .####.  .###.       .   .###.           .####.  ",
-" .        ..#.   .  .     ..      .       ...      .     .   .   .  .     .      ....    ...             ...             ....   ",
-"            .                                                                                                                   ",
-" ..              .                  .              .             .        .        .     .       ..                             ",
-".##.            .#.                .#.            .#.           .#.      .#.      .#.   .#.     .##.                            ",
-" .#.      ...   .#..      ..      ..#.    ..     .#.#.    ...   .#..     ..        .    .#..     .#.     .. ..   ...      ..    ",
-"  .#.    .###.  .###.    .##.    .###.   .##.    .#..    .###.  .###.   .##.      .#.   .#.#.    .#.    .##.##. .###.    .##.   ",
-"   .    .#..#.  .#..#.  .#..    .#..#.  .#.##.  .###.   .#..#.  .#..#.   .#.      .#.   .##.     .#.    .#.#.#. .#..#.  .#..#.  ",
-"        .#.##.  .#..#.  .#..    .#..#.  .##..    .#.     .##.   .#..#.   .#.     ..#.   .#.#.    .#.    .#...#. .#..#.  .#..#.  ",
-"         .#.#.  .###.    .##.    .###.   .##.    .#.    .#...   .#..#.  .###.   .#.#.   .#..#.  .###.   .#. .#. .#..#.   .##.   ",
-"          . .    ...      ..      ...     ..      .      .###.   .  .    ...     .#.     .  .    ...     .   .   .  .     ..    ",
-"                                                          ...                     .                                             ",
-"                                  .                                                        .      .      .        . .           ",
-"                                 .#.                                                      .#.    .#.    .#.      .#.#.          ",
-" ...      ...    ...      ...    .#.     .  .    . .     .   .   .  .    .  .    ....    .#.     .#.     .#.    .#.#.           ",
-".###.    .###.  .###.    .###.  .###.   .#..#.  .#.#.   .#...#. .#..#.  .#..#.  .####.  .##.     .#.     .##.    . .            ",
-".#..#.  .#..#.  .#..#.  .##..    .#.    .#..#.  .#.#.   .#.#.#.  .##.   .#..#.   ..#.    .#.     .#.     .#.                    ",
-".#..#.  .#..#.  .#. .    ..##.   .#..   .#..#.  .#.#.   .#.#.#.  .##.    .#.#.   .#..    .#.     .#.     .#.                    ",
-".###.    .###.  .#.     .###.     .##.   .###.   .#.     .#.#.  .#..#.    .#.   .####.    .#.    .#.    .#.                     ",
-".#..      ..#.   .       ...       ..     ...     .       . .    .  .    .#.     ....      .      .      .                      ",
-" .          .                                                             .                                                     ",
-};
 
-const int font_width = 8;
-const int font_height = 9;
+#ifndef _FONT_H_
+#define _FONT_H_
+
+#include "port.h"
+
+START_EXTERN_C
+extern const char *font[];
+
+static const int font_width = 8;
+static const int font_height = 9;
+END_EXTERN_C
+
+#endif
+
index 4794a78..2f04768 100644 (file)
 /* This file contains a function for loading a SNES ROM image from a zip file                */
 /**********************************************************************************************/
 
+#include <stdio.h>
+#include <stdlib.h>
 #include <string.h>
 #include <ctype.h>
 
+#include "snes9x.h"
+
 #ifndef NO_INLINE_SET_GET
 #define NO_INLINE_SET_GET
 #endif
 
-#include "snes9x.h"
 #include "memmap.h"
-
 #include "unzip.h"
-//#include <assert.h>
-#include <stdio.h>
-#include <stdlib.h>
+#include "assert.h"
 
 bool8 LoadZip(const char* zipname,
              int32 *TotalFileSize,
@@ -71,7 +71,7 @@ bool8 LoadZip(const char* zipname,
     
     unzFile file = unzOpen(zipname);
     if(file == NULL)
-       return (FALSE);
+               return FALSE;
 
     // find largest file in zip file (under MAX_ROM_SIZE)
     // or a file with extension .1
@@ -79,142 +79,143 @@ bool8 LoadZip(const char* zipname,
     int filesize = 0;
     int port = unzGoToFirstFile(file);
     unz_file_info info;
-    while(port == UNZ_OK)
+    while (port == UNZ_OK)
     {
-       char name[132];
-       unzGetCurrentFileInfo(file, &info, name,128, NULL,0, NULL,0);
+               char name[132];
+               unzGetCurrentFileInfo(file, &info, name,128, NULL,0, NULL,0);
 
 #if 0
-       int calc_size = info.uncompressed_size / 0x2000;
-       calc_size *= 0x2000;
-       if(!(info.uncompressed_size - calc_size == 512 || info.uncompressed_size == calc_size))
-       {
-           port = unzGoToNextFile(file);
-           continue;
-       }
+               int calc_size = info.uncompressed_size / 0x2000;
+               calc_size *= 0x2000;
+               if(!(info.uncompressed_size - calc_size == 512 || info.uncompressed_size == calc_size))
+               {
+                       port = unzGoToNextFile(file);
+                       continue;
+               }
 #endif
 
-       if(info.uncompressed_size > (CMemory::MAX_ROM_SIZE + 512))
-       {
-           port = unzGoToNextFile(file);
-           continue;
-       }
-       
-       if ((int) info.uncompressed_size > filesize)
-       {
-           strcpy(filename,name);
-           filesize = info.uncompressed_size;
-       }
-       int len = strlen(name);
-       if(name[len-2] == '.' && name[len-1] == '1')
+               if(info.uncompressed_size > (CMemory::MAX_ROM_SIZE + 512))
+               {
+                       port = unzGoToNextFile(file);
+                       continue;
+               }
+
+               if ((int) info.uncompressed_size > filesize)
+               {
+                       strcpy(filename,name);
+                       filesize = info.uncompressed_size;
+               }
+
+               int len = strlen(name);
+               if(name[len-2] == '.' && name[len-1] == '1')
+               {
+                       strcpy(filename,name);
+                       filesize = info.uncompressed_size;
+                       break;
+               }
+
+               port = unzGoToNextFile(file);
+    }
+       if( !(port == UNZ_END_OF_LIST_OF_FILE || port == UNZ_OK) || filesize == 0)
        {
-           strcpy(filename,name);
-           filesize = info.uncompressed_size;
-           break;
+               unzClose(file);
+               return FALSE;
        }
-       port = unzGoToNextFile(file);
-    }
-    if( !(port == UNZ_END_OF_LIST_OF_FILE || port == UNZ_OK) || filesize == 0)
-    {
-       unzClose(file);
-       return (FALSE);
-    }
 
-    // Find extension
-    char tmp[2];
-    tmp[0] = tmp[1] = 0;
-    char *ext = strrchr(filename,'.');
-    if(ext) ext++;
-    else ext = tmp;
-    
+       // Find extension
+       char tmp[2] = { '\0', '\0' };
+       char *ext = strrchr(filename, '.');
+       if (ext) ext++;
+       else ext = tmp;
+
     uint8 *ptr = Memory.ROM;
     bool8 more = FALSE;
 
     unzLocateFile(file,filename,1);
     unzGetCurrentFileInfo(file, &info, filename,128, NULL,0, NULL,0);
-    
+
     if( unzOpenCurrentFile(file) != UNZ_OK )
     {
-       unzClose(file);
-       return (FALSE);
+               unzClose(file);
+               return FALSE;
     }
 
     do
     {
-//     assert(info.uncompressed_size <= CMemory::MAX_ROM_SIZE + 512);
-       int FileSize = info.uncompressed_size;
-       
-       int calc_size = FileSize / 0x2000;
-       calc_size *= 0x2000;
-       
-       int l = unzReadCurrentFile(file,ptr,FileSize);
-       if(unzCloseCurrentFile(file) == UNZ_CRCERROR)
-       {
-               unzClose(file);
-           return (FALSE);
-       }
-       
-       if(l <= 0 || l != FileSize)
-       {
-           unzClose(file);
-           switch(l)
-           {
-               case UNZ_ERRNO:
-                   break;
-               case UNZ_EOF:
-                   break;
-               case UNZ_PARAMERROR:
-                   break;
-               case UNZ_BADZIPFILE:
-                   break;
-               case UNZ_INTERNALERROR:
-                   break;
-               case UNZ_CRCERROR:
-                   break;
-           }
-           return (FALSE);
-       }
+               int FileSize = info.uncompressed_size;
+               assert(FileSize <= CMemory::MAX_ROM_SIZE + 512);
 
-       if ((FileSize - calc_size == 512 && !Settings.ForceNoHeader) ||
-           Settings.ForceHeader)
-       {
-           memmove (ptr, ptr + 512, calc_size);
-           (*headers)++;
-           FileSize -= 512;
-       }
-       ptr += FileSize;
-       (*TotalFileSize) += FileSize;
+               int calc_size = FileSize / 0x2000;
+               calc_size *= 0x2000;
 
-       int len;
-       if (ptr - Memory.ROM < CMemory::MAX_ROM_SIZE + 0x200 &&
-           (isdigit (ext [0]) && ext [1] == 0 && ext [0] < '9'))
-       {
-           more = TRUE;
-           ext [0]++;
-       }
-       else if (ptr - Memory.ROM < CMemory::MAX_ROM_SIZE + 0x200 &&
-                (((len = strlen (filename)) == 7 || len == 8) &&
-                 strncasecmp (filename, "sf", 2) == 0 &&
-                 isdigit (filename [2]) && isdigit (filename [3]) && isdigit (filename [4]) &&
-                 isdigit (filename [5]) && isalpha (filename [len - 1])))
-       {
-           more = TRUE;
-           filename [len - 1]++;
-       }
-       else
-           more = FALSE;
+               int l = unzReadCurrentFile(file,ptr,FileSize);
+               if(unzCloseCurrentFile(file) == UNZ_CRCERROR)
+               {
+                       unzClose(file);
+                       return FALSE;
+               }
+
+               if (l <= 0 || l != FileSize)
+               {
+                       unzClose(file);
+                       switch(l)
+                       {
+                       case UNZ_ERRNO:
+                               break;
+                       case UNZ_EOF:
+                               break;
+                       case UNZ_PARAMERROR:
+                               break;
+                       case UNZ_BADZIPFILE:
+                               break;
+                       case UNZ_INTERNALERROR:
+                               break;
+                       case UNZ_CRCERROR:
+                               break;
+                       }
+                       return FALSE;
+               }
+
+               if ((FileSize - calc_size == 512 && !Settings.ForceNoHeader) ||
+                       Settings.ForceHeader)
+               {
+                       memmove (ptr, ptr + 512, calc_size);
+                       (*headers)++;
+                       FileSize -= 512;
+               }
+               ptr += FileSize;
+               (*TotalFileSize) += FileSize;
+
+               int len;
+               if (ptr - Memory.ROM < CMemory::MAX_ROM_SIZE + 0x200 &&
+                       (isdigit (ext [0]) && ext [1] == 0 && ext [0] < '9'))
+               {
+                       more = TRUE;
+                       ext [0]++;
+               }
+               else if (ptr - Memory.ROM < CMemory::MAX_ROM_SIZE + 0x200 &&
+                        (((len = strlen (filename)) == 7 || len == 8) &&
+                         strncasecmp (filename, "sf", 2) == 0 &&
+                         isdigit (filename [2]) && isdigit (filename [3]) && isdigit (filename [4]) &&
+                         isdigit (filename [5]) && isalpha (filename [len - 1])))
+               {
+                       more = TRUE;
+                       filename [len - 1]++;
+               }
+               else
+                       more = FALSE;
        
-       if(more)
-       {
-           if( unzLocateFile(file,filename,1) != UNZ_OK ||
-               unzGetCurrentFileInfo(file, &info, filename,128, NULL,0, NULL,0) != UNZ_OK ||
-               unzOpenCurrentFile(file) != UNZ_OK)
-               break;
-       }
+               if(more)
+               {
+                       if (unzLocateFile(file,filename,1) != UNZ_OK ||
+                               unzGetCurrentFileInfo(file, &info, filename,128, NULL,0, NULL,0) != UNZ_OK ||
+                               unzOpenCurrentFile(file) != UNZ_OK)
+                                       break;
+               }
        
     } while(more);
     
     unzClose(file);
-    return (TRUE);
+       return TRUE;
 }
 #endif
diff --git a/sounduxnew.cpp b/sounduxnew.cpp
deleted file mode 100644 (file)
index e1a3175..0000000
+++ /dev/null
@@ -1,2105 +0,0 @@
-/*
- * Snes9x - Portable Super Nintendo Entertainment System (TM) emulator.
- *
- * (c) Copyright 1996 - 2001 Gary Henderson (gary.henderson@ntlworld.com) and
- *                           Jerremy Koot (jkoot@snes9x.com)
- *
- * Super FX C emulator code 
- * (c) Copyright 1997 - 1999 Ivar (ivar@snes9x.com) and
- *                           Gary Henderson.
- * Super FX assembler emulator code (c) Copyright 1998 zsKnight and _Demo_.
- *
- * DSP1 emulator code (c) Copyright 1998 Ivar, _Demo_ and Gary Henderson.
- * C4 asm and some C emulation code (c) Copyright 2000 zsKnight and _Demo_.
- * C4 C code (c) Copyright 2001 Gary Henderson (gary.henderson@ntlworld.com).
- *
- * DOS port code contains the works of other authors. See headers in
- * individual files.
- *
- * Snes9x homepage: http://www.snes9x.com
- *
- * Permission to use, copy, modify and distribute Snes9x in both binary and
- * source form, for non-commercial purposes, is hereby granted without fee,
- * providing that this license information and copyright notice appear with
- * all copies and any derived work.
- *
- * This software is provided 'as-is', without any express or implied
- * warranty. In no event shall the authors be held liable for any damages
- * arising from the use of this software.
- *
- * Snes9x is freeware for PERSONAL USE only. Commercial users should
- * seek permission of the copyright holders first. Commercial use includes
- * charging money for Snes9x or software derived from Snes9x.
- *
- * The copyright holders request that bug fixes and improvements to the code
- * should be forwarded to them so everyone can benefit from the modifications
- * in future versions.
- *
- * Super NES and Super Nintendo Entertainment System are trademarks of
- * Nintendo Co., Limited and its subsidiary companies.
- */
-#ifdef __DJGPP__
-//#include <allegro.h>
-#undef TRUE
-#endif
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#ifndef _SNESPPC
-#include <errno.h>
-#include <fcntl.h>
-#endif
-
-#define CLIP16(v) \
-if ((v) < -32768) \
-    (v) = -32768; \
-else \
-if ((v) > 32767) \
-    (v) = 32767
-
-#define CLIP16_latch(v,l) \
-if ((v) < -32768) \
-{ (v) = -32768; (l)++; }\
-else \
-if ((v) > 32767) \
-{ (v) = 32767; (l)++; }
-
-#define CLIP24(v) \
-if ((v) < -8388608) \
-    (v) = -8388608; \
-else \
-if ((v) > 8388607) \
-    (v) = 8388607
-
-#define CLIP8(v) \
-if ((v) < -128) \
-    (v) = -128; \
-else \
-if ((v) > 127) \
-    (v) = 127
-
-#include "snes9x.h"
-#include "soundux.h"
-#include "apu.h"
-#include "memmap.h"
-#include "cpuexec.h"
-
-
-extern int Echo [24000];
-extern int DummyEchoBuffer [SOUND_BUFFER_SIZE];
-extern int MixBuffer [SOUND_BUFFER_SIZE];
-extern int EchoBuffer [SOUND_BUFFER_SIZE];
-extern int FilterTaps [8];
-extern unsigned long Z;
-extern int Loop [16];
-
-extern long FilterValues[4][2];
-extern int NoiseFreq [32];
-
-#undef ABS
-#define ABS(a) ((a) < 0 ? -(a) : (a))
-
-#define FIXED_POINT 0x10000UL
-#define FIXED_POINT_REMAINDER 0xffffUL
-#define FIXED_POINT_SHIFT 16
-
-#define VOL_DIV8  0x8000
-#define VOL_DIV16 0x0080
-#define ENVX_SHIFT 24
-
-extern "C" void DecodeBlockAsm (int8 *, int16 *, int32 *, int32 *);
-extern "C" void DecodeBlockAsm2 (int8 *, int16 *, int32 *, int32 *);
-
-// F is channel's current frequency and M is the 16-bit modulation waveform
-// from the previous channel multiplied by the current envelope volume level.
-#define PITCH_MOD(F,M) ((F) * ((((unsigned long) (M)) + 0x800000) >> 16) >> 7)
-//#define PITCH_MOD(F,M) ((F) * ((((M) & 0x7fffff) >> 14) + 1) >> 8)
-
-#define LAST_SAMPLE 0xffffff
-#define JUST_PLAYED_LAST_SAMPLE(c) ((c)->sample_pointer >= LAST_SAMPLE)
-
-STATIC INLINE uint8 *S9xGetSampleAddress (int sample_number)
-{
-    uint32 addr = (((APU.DSP[APU_DIR] << 8) + (sample_number << 2)) & 0xffff);
-    return (IAPU.RAM + addr);
-}
-
-void S9xAPUSetEndOfSample (int i, Channel *ch)
-{
-    ch->state = SOUND_SILENT;
-    ch->mode = MODE_NONE;
-    APU.DSP [APU_ENDX] |= 1 << i;
-    APU.DSP [APU_KON] &= ~(1 << i);
-    APU.DSP [APU_KOFF] &= ~(1 << i);
-    APU.KeyedChannels &= ~(1 << i);
-}
-#ifdef __DJGPP
-END_OF_FUNCTION (S9xAPUSetEndOfSample)
-#endif
-
-void S9xAPUSetEndX (int ch)
-{
-    APU.DSP [APU_ENDX] |= 1 << ch;
-}
-#ifdef __DJGPP
-END_OF_FUNCTION (S9xAPUSetEndX)
-#endif
-
-void S9xSetEnvRate (Channel *ch, unsigned long rate, int direction, int target)
-{
-    ch->envx_target = target;
-
-    if (rate == ~0UL)
-    {
-       ch->direction = 0;
-       rate = 0;
-    }
-    else
-       ch->direction = direction;
-
-    static int steps [] =
-    {
-//     0, 64, 1238, 1238, 256, 1, 64, 109, 64, 1238
-       0, 64, 619, 619, 128, 1, 64, 55, 64, 619
-    };
-
-    if (rate == 0 || so.playback_rate == 0)
-       ch->erate = 0;
-    else
-    {
-       ch->erate = (unsigned long)
-                   (((int64) FIXED_POINT * 1000 * steps [ch->state]) /
-                     (rate * so.playback_rate));
-    }
-}
-
-#ifdef __DJGPP
-END_OF_FUNCTION(S9xSetEnvRate);
-#endif
-
-void S9xSetEnvelopeRate (int channel, unsigned long rate, int direction,
-                        int target)
-{
-    S9xSetEnvRate (&SoundData.channels [channel], rate, direction, target);
-}
-
-#ifdef __DJGPP
-END_OF_FUNCTION(S9xSetEnvelopeRate);
-#endif
-
-void S9xSetSoundVolume (int channel, short volume_left, short volume_right)
-{
-    Channel *ch = &SoundData.channels[channel];
-    if (!so.stereo)
-       volume_left = (ABS(volume_right) + ABS(volume_left)) / 2;
-
-    ch->volume_left = volume_left;
-    ch->volume_right = volume_right;
-    ch-> left_vol_level = (ch->envx * volume_left) / 128;
-    ch->right_vol_level = (ch->envx * volume_right) / 128;
-}
-
-void S9xSetMasterVolume (short volume_left, short volume_right)
-{
-    if (Settings.DisableMasterVolume)
-    {
-       SoundData.master_volume_left = 127;
-       SoundData.master_volume_right = 127;
-       SoundData.master_volume [0] = SoundData.master_volume [1] = 127;
-    }
-    else
-    {
-       if (!so.stereo)
-           volume_left = (ABS (volume_right) + ABS (volume_left)) / 2;
-       SoundData.master_volume_left = volume_left;
-       SoundData.master_volume_right = volume_right;
-       SoundData.master_volume [Settings.ReverseStereo] = volume_left;
-       SoundData.master_volume [1 ^ Settings.ReverseStereo] = volume_right;
-    }
-}
-
-void S9xSetEchoVolume (short volume_left, short volume_right)
-{
-    if (!so.stereo)
-       volume_left = (ABS (volume_right) + ABS (volume_left)) / 2;
-    SoundData.echo_volume_left = volume_left;
-    SoundData.echo_volume_right = volume_right;
-    SoundData.echo_volume [Settings.ReverseStereo] = volume_left;
-    SoundData.echo_volume [1 ^ Settings.ReverseStereo] = volume_right;
-}
-
-void S9xSetEchoEnable (uint8 byte)
-{
-    SoundData.echo_channel_enable = byte;
-    if (!SoundData.echo_write_enabled || Settings.DisableSoundEcho)
-       byte = 0;
-    if (byte && !SoundData.echo_enable)
-    {
-       memset (Echo, 0, sizeof (Echo));
-       memset (Loop, 0, sizeof (Loop));
-    }
-
-    SoundData.echo_enable = byte;
-    for (int i = 0; i < 8; i++)
-    {
-       if (byte & (1 << i))
-           SoundData.channels [i].echo_buf_ptr = EchoBuffer;
-       else
-           SoundData.channels [i].echo_buf_ptr = DummyEchoBuffer;
-    }
-}
-
-void S9xSetEchoFeedback (int feedback)
-{
-    CLIP8(feedback);
-    SoundData.echo_feedback = feedback;
-}
-
-void S9xSetEchoDelay (int delay)
-{
-    SoundData.echo_buffer_size = (512 * delay * so.playback_rate) / 32000;
-    if (so.stereo)
-       SoundData.echo_buffer_size <<= 1;
-    if (SoundData.echo_buffer_size)
-       SoundData.echo_ptr %= SoundData.echo_buffer_size;
-    else
-       SoundData.echo_ptr = 0;
-    S9xSetEchoEnable (APU.DSP [APU_EON]);
-}
-
-void S9xSetEchoWriteEnable (uint8 byte)
-{
-    SoundData.echo_write_enabled = byte;
-    S9xSetEchoDelay (APU.DSP [APU_EDL] & 15);
-}
-
-void S9xSetFrequencyModulationEnable (uint8 byte)
-{
-    SoundData.pitch_mod = byte & ~1;
-}
-
-void S9xSetSoundKeyOff (int channel)
-{
-    Channel *ch = &SoundData.channels[channel];
-
-    if (ch->state != SOUND_SILENT)
-    {
-       ch->state = SOUND_RELEASE;
-       ch->mode = MODE_RELEASE;
-       S9xSetEnvRate (ch, 8, -1, 0);
-    }
-}
-
-void S9xFixSoundAfterSnapshotLoad ()
-{
-    SoundData.echo_write_enabled = !(APU.DSP [APU_FLG] & 0x20);
-    SoundData.echo_channel_enable = APU.DSP [APU_EON];
-    S9xSetEchoDelay (APU.DSP [APU_EDL] & 0xf);
-    S9xSetEchoFeedback ((signed char) APU.DSP [APU_EFB]);
-
-    S9xSetFilterCoefficient (0, (signed char) APU.DSP [APU_C0]);
-    S9xSetFilterCoefficient (1, (signed char) APU.DSP [APU_C1]);
-    S9xSetFilterCoefficient (2, (signed char) APU.DSP [APU_C2]);
-    S9xSetFilterCoefficient (3, (signed char) APU.DSP [APU_C3]);
-    S9xSetFilterCoefficient (4, (signed char) APU.DSP [APU_C4]);
-    S9xSetFilterCoefficient (5, (signed char) APU.DSP [APU_C5]);
-    S9xSetFilterCoefficient (6, (signed char) APU.DSP [APU_C6]);
-    S9xSetFilterCoefficient (7, (signed char) APU.DSP [APU_C7]);
-    for (int i = 0; i < 8; i++)
-    {
-       SoundData.channels[i].needs_decode = TRUE;
-       S9xSetSoundFrequency (i, SoundData.channels[i].hertz);
-       SoundData.channels [i].envxx = SoundData.channels [i].envx << ENVX_SHIFT;
-       SoundData.channels [i].next_sample = 0;
-       SoundData.channels [i].interpolate = 0;
-       SoundData.channels [i].previous [0] = (int32) SoundData.channels [i].previous16 [0];
-       SoundData.channels [i].previous [1] = (int32) SoundData.channels [i].previous16 [1];
-    }
-    SoundData.master_volume [Settings.ReverseStereo] = SoundData.master_volume_left;
-    SoundData.master_volume [1 ^ Settings.ReverseStereo] = SoundData.master_volume_right;
-    SoundData.echo_volume [Settings.ReverseStereo] = SoundData.echo_volume_left;
-    SoundData.echo_volume [1 ^ Settings.ReverseStereo] = SoundData.echo_volume_right;
-    IAPU.Scanline = 0;
-}
-
-void S9xSetFilterCoefficient (int tap, int value)
-{
-    FilterTaps [tap & 7] = value;
-    SoundData.no_filter = (FilterTaps [0] == 127 || FilterTaps [0] == 0) && 
-                          FilterTaps [1] == 0   &&
-                          FilterTaps [2] == 0   &&
-                          FilterTaps [3] == 0   &&
-                          FilterTaps [4] == 0   &&
-                          FilterTaps [5] == 0   &&
-                          FilterTaps [6] == 0   &&
-                          FilterTaps [7] == 0;
-}
-
-void S9xSetSoundADSR (int channel, int attack_rate, int decay_rate,
-                     int sustain_rate, int sustain_level, int release_rate)
-{
-    SoundData.channels[channel].attack_rate = attack_rate;
-    SoundData.channels[channel].decay_rate = decay_rate;
-    SoundData.channels[channel].sustain_rate = sustain_rate;
-    SoundData.channels[channel].release_rate = release_rate;
-    SoundData.channels[channel].sustain_level = sustain_level + 1;
-
-    switch (SoundData.channels[channel].state)
-    {
-    case SOUND_ATTACK:
-       S9xSetEnvelopeRate (channel, attack_rate, 1, 127);
-       break;
-
-    case SOUND_DECAY:
-       S9xSetEnvelopeRate (channel, decay_rate, -1,
-                           (MAX_ENVELOPE_HEIGHT * (sustain_level + 1)) >> 3);
-       break;
-    case SOUND_SUSTAIN:
-       S9xSetEnvelopeRate (channel, sustain_rate, -1, 0);
-       break;
-    }
-}
-
-void S9xSetEnvelopeHeight (int channel, int level)
-{
-    Channel *ch = &SoundData.channels[channel];
-
-    ch->envx = level;
-    ch->envxx = level << ENVX_SHIFT;
-
-    ch->left_vol_level = (level * ch->volume_left) / 128;
-    ch->right_vol_level = (level * ch->volume_right) / 128;
-
-    if (ch->envx == 0 && ch->state != SOUND_SILENT && ch->state != SOUND_GAIN)
-    {
-       S9xAPUSetEndOfSample (channel, ch);
-    }
-}
-
-int S9xGetEnvelopeHeight (int channel)
-{
-    if ((Settings.SoundEnvelopeHeightReading ||
-        SNESGameFixes.SoundEnvelopeHeightReading2) &&
-        SoundData.channels[channel].state != SOUND_SILENT &&
-        SoundData.channels[channel].state != SOUND_GAIN)
-    {
-        return (SoundData.channels[channel].envx);
-    }
-
-    //siren fix from XPP
-    if (SNESGameFixes.SoundEnvelopeHeightReading2 &&
-        SoundData.channels[channel].state != SOUND_SILENT)
-    {
-        return (SoundData.channels[channel].envx);
-    }
-
-    return (0);
-}
-
-#if 1
-void S9xSetSoundSample (int, uint16) 
-{
-}
-#else
-void S9xSetSoundSample (int channel, uint16 sample_number)
-{
-    register Channel *ch = &SoundData.channels[channel];
-
-    if (ch->state != SOUND_SILENT && 
-       sample_number != ch->sample_number)
-    {
-       int keep = ch->state;
-       ch->state = SOUND_SILENT;
-       ch->sample_number = sample_number;
-       ch->loop = FALSE;
-       ch->needs_decode = TRUE;
-       ch->last_block = FALSE;
-       ch->previous [0] = ch->previous[1] = 0;
-       uint8 *dir = S9xGetSampleAddress (sample_number);
-       ch->block_pointer = READ_WORD (dir);
-       ch->sample_pointer = 0;
-       ch->state = keep;
-    }
-}
-#endif
-
-void S9xSetSoundFrequency (int channel, int hertz)
-{
-    if (so.playback_rate)
-    {
-       if (SoundData.channels[channel].type == SOUND_NOISE)
-           hertz = NoiseFreq [APU.DSP [APU_FLG] & 0x1f];
-       SoundData.channels[channel].frequency = (int)
-           (((int64) hertz * FIXED_POINT) / so.playback_rate);
-       if (Settings.FixFrequency)
-       {
-           SoundData.channels[channel].frequency = 
-               (unsigned long) ((double)  SoundData.channels[channel].frequency * 0.980);
-       }
-    }
-}
-
-void S9xSetSoundHertz (int channel, int hertz)
-{
-    SoundData.channels[channel].hertz = hertz;
-    S9xSetSoundFrequency (channel, hertz);
-}
-
-void S9xSetSoundType (int channel, int type_of_sound)
-{
-    SoundData.channels[channel].type = type_of_sound;
-}
-
-bool8_32 S9xSetSoundMute (bool8_32 mute)
-{
-    bool8_32 old = so.mute_sound;
-    so.mute_sound = mute;
-    return (old);
-}
-
-void AltDecodeBlock_PPC (Channel *ch, struct SIAPU * iapu)
-{
-    if (ch->block_pointer >= 0x10000 - 9)
-    {
-       ch->last_block = TRUE;
-       ch->loop = FALSE;
-       ch->block = ch->decoded;
-       memset ((void *) ch->decoded, 0, sizeof (int16) * 16);
-       return;
-    }
-    signed char *compressed = (signed char *) &iapu->RAM [ch->block_pointer];
-
-    unsigned char filter = *compressed;
-    if ((ch->last_block = filter & 1))
-       ch->loop = (filter & 2) != 0;
-
-#if (defined (__i386__) || defined (__i486__) ||\
-     defined (__i586__) || defined (__WIN32__) || defined (__DJGPP))
-    int16 *raw = ch->block = ch->decoded;
-
-    if (Settings.AltSampleDecode == 1)
-       DecodeBlockAsm (compressed, raw, &ch->previous [0], &ch->previous [1]);
-    else
-       DecodeBlockAsm2 (compressed, raw, &ch->previous [0], &ch->previous [1]);
-#else
-    int32 out;
-    unsigned char shift;
-    signed char sample1, sample2;
-    unsigned int i;
-
-    compressed++;
-    signed short *raw = ch->block = ch->decoded;
-    
-    int32 prev0 = ch->previous [0];
-    int32 prev1 = ch->previous [1];
-    shift = filter >> 4;
-
-    switch ((filter >> 2) & 3)
-    {
-    case 0:
-       for (i = 8; i != 0; i--)
-       {
-           sample1 = *compressed++;
-           sample2 = sample1 << 4;
-           sample2 >>= 4;
-           sample1 >>= 4;
-           *raw++ = ((int32) sample1 << shift);
-           *raw++ = ((int32) sample2 << shift);
-       }
-       prev1 = *(raw - 2);
-       prev0 = *(raw - 1);
-       break;
-    case 1:
-       for (i = 8; i != 0; i--)
-       {
-           sample1 = *compressed++;
-           sample2 = sample1 << 4;
-           sample2 >>= 4;
-           sample1 >>= 4;
-           prev0 = (int16) prev0;
-           *raw++ = prev1 = ((int32) sample1 << shift) + prev0 - (prev0 >> 4);
-           prev1 = (int16) prev1;
-           *raw++ = prev0 = ((int32) sample2 << shift) + prev1 - (prev1 >> 4);
-       }
-       break;
-    case 2:
-       for (i = 8; i != 0; i--)
-       {
-           sample1 = *compressed++;
-           sample2 = sample1 << 4;
-           sample2 >>= 4;
-           sample1 >>= 4;
-           
-           out = (sample1 << shift) - prev1 + (prev1 >> 4);
-           prev1 = (int16) prev0;
-           prev0 &= ~3;
-           *raw++ = prev0 = out + (prev0 << 1) - (prev0 >> 5) - 
-                            (prev0 >> 4);
-
-           out = (sample2 << shift) - prev1 + (prev1 >> 4);
-           prev1 = (int16) prev0;
-           prev0 &= ~3;
-           *raw++ = prev0 = out + (prev0 << 1) - (prev0 >> 5) -
-                            (prev0 >> 4);
-       }
-       break;
-    case 3:
-       for (i = 8; i != 0; i--)
-       {
-           sample1 = *compressed++;
-           sample2 = sample1 << 4;
-           sample2 >>= 4;
-           sample1 >>= 4;
-           out = (sample1 << shift);
-
-           out = out - prev1 + (prev1 >> 3) + (prev1 >> 4);
-           prev1 = (int16) prev0;
-           prev0 &= ~3;
-           *raw++ = prev0 = out + (prev0 << 1) - (prev0 >> 3) - 
-                            (prev0 >> 4) - (prev1 >> 6);
-
-           out = (sample2 << shift);
-           out = out - prev1 + (prev1 >> 3) + (prev1 >> 4);
-           prev1 = (int16) prev0;
-           prev0 &= ~3;
-           *raw++ = prev0 = out + (prev0 << 1) - (prev0 >> 3) - 
-                            (prev0 >> 4) - (prev1 >> 6);
-       }
-       break;
-    }
-    ch->previous [0] = prev0;
-    ch->previous [1] = prev1;
-#endif
-
-    ch->block_pointer += 9;
-}
-
-void AltDecodeBlock (Channel *ch, struct SIAPU * iapu)
-{
-    if (ch->block_pointer >= 0x10000 - 9)
-    {
-       ch->last_block = TRUE;
-       ch->loop = FALSE;
-       ch->block = ch->decoded;
-       memset ((void *) ch->decoded, 0, sizeof (int16) * 16);
-       return;
-    }
-    signed char *compressed = (signed char *) &iapu->RAM [ch->block_pointer];
-
-    unsigned char filter = *compressed;
-    if ((ch->last_block = filter & 1))
-       ch->loop = (filter & 2) != 0;
-
-#if (defined (__i386__) || defined (__i486__) ||\
-     defined (__i586__) || defined (__WIN32__) || defined (__DJGPP))
-    int16 *raw = ch->block = ch->decoded;
-
-    if (Settings.AltSampleDecode == 1)
-       DecodeBlockAsm (compressed, raw, &ch->previous [0], &ch->previous [1]);
-    else
-       DecodeBlockAsm2 (compressed, raw, &ch->previous [0], &ch->previous [1]);
-#else
-    int32 out;
-    unsigned char shift;
-    signed char sample1, sample2;
-    unsigned int i;
-
-    compressed++;
-    signed short *raw = ch->block = ch->decoded;
-    
-    int32 prev0 = ch->previous [0];
-    int32 prev1 = ch->previous [1];
-    shift = filter >> 4;
-
-    switch ((filter >> 2) & 3)
-    {
-    case 0:
-       for (i = 8; i != 0; i--)
-       {
-           sample1 = *compressed++;
-           sample2 = sample1 << 4;
-           sample2 >>= 4;
-           sample1 >>= 4;
-           *raw++ = ((int32) sample1 << shift);
-           *raw++ = ((int32) sample2 << shift);
-       }
-       prev1 = *(raw - 2);
-       prev0 = *(raw - 1);
-       break;
-    case 1:
-       for (i = 8; i != 0; i--)
-       {
-           sample1 = *compressed++;
-           sample2 = sample1 << 4;
-           sample2 >>= 4;
-           sample1 >>= 4;
-           prev0 = (int16) prev0;
-           *raw++ = prev1 = ((int32) sample1 << shift) + prev0 - (prev0 >> 4);
-           prev1 = (int16) prev1;
-           *raw++ = prev0 = ((int32) sample2 << shift) + prev1 - (prev1 >> 4);
-       }
-       break;
-    case 2:
-       for (i = 8; i != 0; i--)
-       {
-           sample1 = *compressed++;
-           sample2 = sample1 << 4;
-           sample2 >>= 4;
-           sample1 >>= 4;
-           
-           out = (sample1 << shift) - prev1 + (prev1 >> 4);
-           prev1 = (int16) prev0;
-           prev0 &= ~3;
-           *raw++ = prev0 = out + (prev0 << 1) - (prev0 >> 5) - 
-                            (prev0 >> 4);
-
-           out = (sample2 << shift) - prev1 + (prev1 >> 4);
-           prev1 = (int16) prev0;
-           prev0 &= ~3;
-           *raw++ = prev0 = out + (prev0 << 1) - (prev0 >> 5) -
-                            (prev0 >> 4);
-       }
-       break;
-    case 3:
-       for (i = 8; i != 0; i--)
-       {
-           sample1 = *compressed++;
-           sample2 = sample1 << 4;
-           sample2 >>= 4;
-           sample1 >>= 4;
-           out = (sample1 << shift);
-
-           out = out - prev1 + (prev1 >> 3) + (prev1 >> 4);
-           prev1 = (int16) prev0;
-           prev0 &= ~3;
-           *raw++ = prev0 = out + (prev0 << 1) - (prev0 >> 3) - 
-                            (prev0 >> 4) - (prev1 >> 6);
-
-           out = (sample2 << shift);
-           out = out - prev1 + (prev1 >> 3) + (prev1 >> 4);
-           prev1 = (int16) prev0;
-           prev0 &= ~3;
-           *raw++ = prev0 = out + (prev0 << 1) - (prev0 >> 3) - 
-                            (prev0 >> 4) - (prev1 >> 6);
-       }
-       break;
-    }
-    ch->previous [0] = prev0;
-    ch->previous [1] = prev1;
-#endif
-
-    ch->block_pointer += 9;
-}
-
-void AltDecodeBlock2 (Channel *ch)
-{
-    int32 out;
-    unsigned char filter;
-    unsigned char shift;
-    signed char sample1, sample2;
-    unsigned char i;
-
-    if (ch->block_pointer > 0x10000 - 9)
-    {
-       ch->last_block = TRUE;
-       ch->loop = FALSE;
-       ch->block = ch->decoded;
-       memset ((void *) ch->decoded, 0, sizeof (int16) * 16);
-       return;
-    }
-
-    signed char *compressed = (signed char *) &IAPU.RAM [ch->block_pointer];
-
-    filter = *compressed;
-    if ((ch->last_block = filter & 1))
-    ch->loop = (filter & 2) != 0;
-
-    compressed++;
-    signed short *raw = ch->block = ch->decoded;
-    
-    shift = filter >> 4;
-    int32 prev0 = ch->previous [0];
-    int32 prev1 = ch->previous [1];
-
-    if(shift > 12)
-       shift -= 4;
-
-    switch ((filter >> 2) & 3)
-    {
-    case 0:
-       for (i = 8; i != 0; i--)
-       {
-           sample1 = *compressed++;
-           sample2 = sample1 << 4;
-           //Sample 2 = Bottom Nibble, Sign Extended.
-           sample2 >>= 4;
-           //Sample 1 = Top Nibble, shifted down and Sign Extended.
-           sample1 >>= 4;
-
-           out = (int32)(sample1 << shift);
-
-           prev1 = prev0;
-           prev0 = out;
-           CLIP16(out);
-           *raw++ = (int16)out;
-
-           out = (int32)(sample2 << shift);
-
-           prev1 = prev0;
-           prev0 = out;
-           CLIP16(out);
-           *raw++ = (int16)out;
-       }
-       break;
-    case 1:
-       for (i = 8; i != 0; i--)
-       {
-           sample1 = *compressed++;
-           sample2 = sample1 << 4;
-           //Sample 2 = Bottom Nibble, Sign Extended.
-           sample2 >>= 4;
-           //Sample 1 = Top Nibble, shifted down and Sign Extended.
-           sample1 >>= 4;
-           out = (int32)(sample1 << shift);
-           out += (int32)((double)prev0 * 15/16);
-
-           prev1 = prev0;
-           prev0 = out;
-           CLIP16(out);
-           *raw++ = (int16)out;
-
-           out = (int32)(sample2 << shift);
-           out += (int32)((double)prev0 * 15/16);
-
-           prev1 = prev0;
-           prev0 = out;
-           CLIP16(out);
-           *raw++ = (int16)out;
-       }
-       break;
-    case 2:
-       for (i = 8; i != 0; i--)
-       {
-           sample1 = *compressed++;
-           sample2 = sample1 << 4;
-           //Sample 2 = Bottom Nibble, Sign Extended.
-           sample2 >>= 4;
-           //Sample 1 = Top Nibble, shifted down and Sign Extended.
-           sample1 >>= 4;
-
-           out = ((sample1 << shift) * 256 + (prev0 & ~0x2) * 488 - prev1 * 240) >> 8;
-
-           prev1 = prev0;
-           prev0 = (int16)out;
-           *raw++ = (int16)out;
-
-           out = ((sample2 << shift) * 256 + (prev0 & ~0x2) * 488 - prev1 * 240) >> 8;
-
-           prev1 = prev0;
-           prev0 = (int16)out;
-           *raw++ = (int16)out;
-       }
-       break;
-
-    case 3:
-       for (i = 8; i != 0; i--)
-       {
-           sample1 = *compressed++;
-           sample2 = sample1 << 4;
-           //Sample 2 = Bottom Nibble, Sign Extended.
-           sample2 >>= 4;
-           //Sample 1 = Top Nibble, shifted down and Sign Extended.
-           sample1 >>= 4;
-           out = (int32)(sample1 << shift);
-           out += (int32)((double)prev0 * 115/64 - (double)prev1 * 13/16);
-
-           prev1 = prev0;
-           prev0 = out;
-
-           CLIP16(out);
-           *raw++ = (int16)out;
-
-           out = (int32)(sample2 << shift);
-           out += (int32)((double)prev0 * 115/64 - (double)prev1 * 13/16);
-
-           prev1 = prev0;
-           prev0 = out;
-
-           CLIP16(out);
-           *raw++ = (int16)out;
-       }
-       break;
-    }
-    ch->previous [0] = prev0;
-    ch->previous [1] = prev1;
-    ch->block_pointer += 9;
-}
-
-void DecodeBlock (Channel *ch)
-{
-    int32 out;
-    unsigned char filter;
-    unsigned char shift;
-    signed char sample1, sample2;
-    unsigned char i;
-
-    if (Settings.AltSampleDecode)
-    {
-               if (Settings.AltSampleDecode < 3)
-                       AltDecodeBlock (ch, &IAPU);
-               else
-                       AltDecodeBlock2 (ch);
-                       return;
-    }
-    if (ch->block_pointer > 0x10000 - 9)
-    {
-       ch->last_block = TRUE;
-       ch->loop = FALSE;
-       ch->block = ch->decoded;
-       return;
-    }
-    signed char *compressed = (signed char *) &IAPU.RAM [ch->block_pointer];
-
-    filter = *compressed;
-    if ((ch->last_block = filter & 1))
-       ch->loop = (filter & 2) != 0;
-
-    // If enabled, results in 'tick' sound on some samples that repeat by
-    // re-using part of the original sample but generate a slightly different
-    // waveform.
-    if (!Settings.DisableSampleCaching &&
-       memcmp ((uint8 *) compressed, &IAPU.ShadowRAM [ch->block_pointer], 9) == 0)
-    {
-       ch->block = (signed short *) (IAPU.CachedSamples + (ch->block_pointer << 2));
-       ch->previous [0] = ch->block [15];
-       ch->previous [1] = ch->block [14];
-    }
-    else
-    {
-       if (!Settings.DisableSampleCaching)
-           memcpy (&IAPU.ShadowRAM [ch->block_pointer], (uint8 *) compressed, 9);
-       compressed++;
-       signed short *raw = ch->block = ch->decoded;
-
-       shift = filter >> 4;
-       filter = ((filter >> 2) & 3);
-       int32 prev0 = ch->previous [0];
-       int32 prev1 = ch->previous [1];
-       int32 f0 = FilterValues[filter][0];
-       int32 f1 = FilterValues[filter][1];
-
-       for (i = 8; i != 0; i--)
-       {
-           sample1 = *compressed++;
-           sample2 = sample1 << 4;
-           //Sample 2 = Bottom Nibble, Sign Extended.
-           sample2 >>= 4;
-           //Sample 1 = Top Nibble, shifted down and Sign Extended.
-           sample1 >>= 4;
-           out = (sample1 << shift);
-           out += (prev0 * f0 + prev1 * f1) / 256;
-
-           CLIP16 (out);
-           prev1 = prev0;
-           prev0 = out;
-           *raw++ = (signed short) out;
-
-           out = (sample2 << shift);
-           out += (prev0 * f0 + prev1 * f1) / 256;
-
-           CLIP16 (out);
-           prev1 = prev0;
-           prev0 = out;
-           *raw++ = (signed short) out;
-       }
-       ch->previous [0] = prev0;
-       ch->previous [1] = prev1;
-
-       if (!Settings.DisableSampleCaching)
-       {
-           memcpy (IAPU.CachedSamples + (ch->block_pointer << 2),
-                   (uint8 *) ch->decoded, 32);
-       }
-    }
-    ch->block_pointer += 9;
-}
-
-void MixStereo (int sample_count)
-{
-       struct SIAPU * iapu = &IAPU;
-#if defined(TARGET_OS_MAC) && TARGET_OS_MAC
-    static int wave[SOUND_BUFFER_SIZE];
-#else
-    int wave[SOUND_BUFFER_SIZE];
-#endif
-    int pitch_mod = SoundData.pitch_mod & ~APU.DSP[APU_NON];
-
-    for (uint32 J = 0; J < NUM_CHANNELS; J++) 
-    {
-       int32 VL, VR;
-       Channel *ch = &SoundData.channels[J];
-       unsigned long freq0 = ch->frequency;
-
-       if (ch->state == SOUND_SILENT || !(so.sound_switch & (1 << J)))
-           continue;
-
-//     freq0 = (unsigned long) ((double) freq0 * 0.985);
-
-       bool8_32 mod = pitch_mod & (1 << J);
-
-       if (ch->needs_decode) 
-       {
-               AltDecodeBlock(ch, iapu);
-           //DecodeBlock(ch);
-           ch->needs_decode = FALSE;
-           ch->sample = ch->block[0];
-           ch->sample_pointer = freq0 >> FIXED_POINT_SHIFT;
-           if (ch->sample_pointer == 0)
-               ch->sample_pointer = 1;
-           if (ch->sample_pointer > SOUND_DECODE_LENGTH)
-               ch->sample_pointer = SOUND_DECODE_LENGTH - 1;
-
-           ch->next_sample = ch->block[ch->sample_pointer];
-           ch->interpolate = 0;
-
-           if (Settings.InterpolatedSound && freq0 < FIXED_POINT && !mod)
-               ch->interpolate = ((ch->next_sample - ch->sample) * 
-                                  (long) freq0) / (long) FIXED_POINT;
-       }
-       VL = (ch->sample * ch-> left_vol_level) / 128;
-       VR = (ch->sample * ch->right_vol_level) / 128;
-
-       for (uint32 I = 0; I < (uint32) sample_count; I += 2)
-       {
-           unsigned long freq = freq0;
-
-           if (mod)
-               freq = PITCH_MOD(freq, wave [I / 2]);
-
-           ch->env_error += ch->erate;
-           if (ch->env_error >= FIXED_POINT) 
-           {
-               uint32 step = ch->env_error >> FIXED_POINT_SHIFT;
-
-               switch (ch->state)
-               {
-               case SOUND_ATTACK:
-                   ch->env_error &= FIXED_POINT_REMAINDER;
-                   ch->envx += step << 1;
-                   ch->envxx = ch->envx << ENVX_SHIFT;
-
-                   if (ch->envx >= 126)
-                   {
-                       ch->envx = 127;
-                       ch->envxx = 127 << ENVX_SHIFT;
-                       ch->state = SOUND_DECAY;
-                       if (ch->sustain_level != 8) 
-                       {
-                           S9xSetEnvRate (ch, ch->decay_rate, -1,
-                                               (MAX_ENVELOPE_HEIGHT * ch->sustain_level)
-                                               >> 3);
-                           break;
-                       }
-                       ch->state = SOUND_SUSTAIN;
-                       S9xSetEnvRate (ch, ch->sustain_rate, -1, 0);
-                   }
-                   break;
-               
-               case SOUND_DECAY:
-                   while (ch->env_error >= FIXED_POINT)
-                   {
-                       ch->envxx = (ch->envxx >> 8) * 255;
-                       ch->env_error -= FIXED_POINT;
-                   }
-                   ch->envx = ch->envxx >> ENVX_SHIFT;
-                   if (ch->envx <= ch->envx_target)
-                   {
-                       if (ch->envx <= 0)
-                       {
-                           S9xAPUSetEndOfSample (J, ch);
-                           goto stereo_exit;
-                       }
-                       ch->state = SOUND_SUSTAIN;
-                       S9xSetEnvRate (ch, ch->sustain_rate, -1, 0);
-                   }
-                   break;
-
-               case SOUND_SUSTAIN:
-                   while (ch->env_error >= FIXED_POINT)
-                   {
-                       ch->envxx = (ch->envxx >> 8) * 255;
-                       ch->env_error -= FIXED_POINT;
-                   }
-                   ch->envx = ch->envxx >> ENVX_SHIFT;
-                   if (ch->envx <= 0)
-                   {
-                       S9xAPUSetEndOfSample (J, ch);
-                       goto stereo_exit;
-                   }
-                   break;
-                   
-               case SOUND_RELEASE:
-                   while (ch->env_error >= FIXED_POINT)
-                   {
-                       ch->envxx -= (MAX_ENVELOPE_HEIGHT << ENVX_SHIFT) / 256;
-                       ch->env_error -= FIXED_POINT;
-                   }
-                   ch->envx = ch->envxx >> ENVX_SHIFT;
-                   if (ch->envx <= 0)
-                   {
-                       S9xAPUSetEndOfSample (J, ch);
-                       goto stereo_exit;
-                   }
-                   break;
-               
-               case SOUND_INCREASE_LINEAR:
-                   ch->env_error &= FIXED_POINT_REMAINDER;
-                   ch->envx += step << 1;
-                   ch->envxx = ch->envx << ENVX_SHIFT;
-
-                   if (ch->envx >= 126)
-                   {
-                       ch->envx = 127;
-                       ch->envxx = 127 << ENVX_SHIFT;
-                       ch->state = SOUND_GAIN;
-                       ch->mode = MODE_GAIN;
-                       S9xSetEnvRate (ch, 0, -1, 0);
-                   }
-                   break;
-
-               case SOUND_INCREASE_BENT_LINE:
-                   if (ch->envx >= (MAX_ENVELOPE_HEIGHT * 3) / 4)
-                   {
-                       while (ch->env_error >= FIXED_POINT)
-                       {
-                           ch->envxx += (MAX_ENVELOPE_HEIGHT << ENVX_SHIFT) / 256;
-                           ch->env_error -= FIXED_POINT;
-                       }
-                       ch->envx = ch->envxx >> ENVX_SHIFT;
-                   }
-                   else
-                   {
-                       ch->env_error &= FIXED_POINT_REMAINDER;
-                       ch->envx += step << 1;
-                       ch->envxx = ch->envx << ENVX_SHIFT;
-                   }
-
-                   if (ch->envx >= 126)
-                   {
-                       ch->envx = 127;
-                       ch->envxx = 127 << ENVX_SHIFT;
-                       ch->state = SOUND_GAIN;
-                       ch->mode = MODE_GAIN;
-                       S9xSetEnvRate (ch, 0, -1, 0);
-                   }
-                   break;
-
-               case SOUND_DECREASE_LINEAR:
-                   ch->env_error &= FIXED_POINT_REMAINDER;
-                   ch->envx -= step << 1;
-                   ch->envxx = ch->envx << ENVX_SHIFT;
-                   if (ch->envx <= 0)
-                   {
-                       S9xAPUSetEndOfSample (J, ch);
-                       goto stereo_exit;
-                   }
-                   break;
-
-               case SOUND_DECREASE_EXPONENTIAL:
-                   while (ch->env_error >= FIXED_POINT)
-                   {
-                       ch->envxx = (ch->envxx >> 8) * 255;
-                       ch->env_error -= FIXED_POINT;
-                   }
-                   ch->envx = ch->envxx >> ENVX_SHIFT;
-                   if (ch->envx <= 0)
-                   {
-                       S9xAPUSetEndOfSample (J, ch);
-                       goto stereo_exit;
-                   }
-                   break;
-               
-               case SOUND_GAIN:
-                   S9xSetEnvRate (ch, 0, -1, 0);
-                   break;
-               }
-               ch-> left_vol_level = (ch->envx * ch->volume_left) / 128;
-               ch->right_vol_level = (ch->envx * ch->volume_right) / 128;
-               VL = (ch->sample * ch-> left_vol_level) / 128;
-               VR = (ch->sample * ch->right_vol_level) / 128;
-           }
-
-           ch->count += freq;
-           if (ch->count >= FIXED_POINT)
-           {
-               VL = ch->count >> FIXED_POINT_SHIFT;
-               ch->sample_pointer += VL;
-               ch->count &= FIXED_POINT_REMAINDER;
-
-               ch->sample = ch->next_sample;
-               if (ch->sample_pointer >= SOUND_DECODE_LENGTH)
-               {
-                   if (JUST_PLAYED_LAST_SAMPLE(ch))
-                   {
-                       S9xAPUSetEndOfSample (J, ch);
-                       goto stereo_exit;
-                   }
-                   do
-                   {
-                       ch->sample_pointer -= SOUND_DECODE_LENGTH;
-                       if (ch->last_block)
-                       {
-                           if (!ch->loop)
-                           {
-                               ch->sample_pointer = LAST_SAMPLE;
-                               ch->next_sample = ch->sample;
-                               break;
-                           }
-                           else
-                           {
-                               S9xAPUSetEndX (J);
-                               ch->last_block = FALSE;
-                               uint8 *dir = S9xGetSampleAddress (ch->sample_number);
-                               ch->block_pointer = READ_WORD(dir + 2);
-                           }
-                       }
-                       AltDecodeBlock(ch, iapu);
-                       //DecodeBlock (ch);
-                   } while (ch->sample_pointer >= SOUND_DECODE_LENGTH);
-                   if (!JUST_PLAYED_LAST_SAMPLE (ch))
-                       ch->next_sample = ch->block [ch->sample_pointer];
-               }
-               else
-                   ch->next_sample = ch->block [ch->sample_pointer];
-
-               if (ch->type == SOUND_SAMPLE)
-               {
-                   if (Settings.InterpolatedSound && freq < FIXED_POINT && !mod)
-                   {
-                       ch->interpolate = ((ch->next_sample - ch->sample) * 
-                                          (long) freq) / (long) FIXED_POINT;
-                       ch->sample = (int16) (ch->sample + (((ch->next_sample - ch->sample) * 
-                                          (long) (ch->count)) / (long) FIXED_POINT));
-                   }             
-                   else
-                       ch->interpolate = 0;
-               }
-               else
-               {
-                   for (;VL > 0; VL--)
-                       if ((so.noise_gen <<= 1) & 0x80000000L)
-                           so.noise_gen ^= 0x0040001L;
-                   ch->sample = (so.noise_gen << 17) >> 17;
-                   ch->interpolate = 0;
-               }
-
-               VL = (ch->sample * ch-> left_vol_level) / 128;
-               VR = (ch->sample * ch->right_vol_level) / 128;
-            }
-           else
-           {
-               if (ch->interpolate)
-               {
-                   int32 s = (int32) ch->sample + ch->interpolate;
-                   
-                   CLIP16(s);
-                   ch->sample = (int16) s;
-                   VL = (ch->sample * ch-> left_vol_level) / 128;
-                   VR = (ch->sample * ch->right_vol_level) / 128;
-               }
-           }
-
-           if (pitch_mod & (1 << (J + 1)))
-               wave [I / 2] = ch->sample * ch->envx;
-
-           MixBuffer [I      ^ Settings.ReverseStereo] += VL;
-           MixBuffer [I + (1 ^ Settings.ReverseStereo)] += VR;
-           ch->echo_buf_ptr [I      ^ Settings.ReverseStereo] += VL;
-           ch->echo_buf_ptr [I + (1 ^ Settings.ReverseStereo)] += VR;
-        }
-stereo_exit: ;
-    }
-}
-
-#ifdef __DJGPP
-END_OF_FUNCTION(MixStereo);
-#endif
-
-void MixMono (int sample_count)
-{
-       struct SIAPU * iapu = &IAPU;
-#if defined(TARGET_OS_MAC) && TARGET_OS_MAC
-    static int wave[SOUND_BUFFER_SIZE];
-#else
-#ifdef _SNESPPC
-    static int wave[SOUND_BUFFER_SIZE];
-#else
-    int wave[SOUND_BUFFER_SIZE];
-#endif
-#endif
-    int pitch_mod = SoundData.pitch_mod & (~APU.DSP[APU_NON]);
-
-    for (uint32 J = 0; J < NUM_CHANNELS; J++) 
-    {
-       Channel *ch = &SoundData.channels[J];
-       unsigned long freq0 = ch->frequency;
-
-       if (ch->state == SOUND_SILENT || !(so.sound_switch & (1 << J)))
-           continue;
-
-//     freq0 = (unsigned long) ((double) freq0 * 0.985);
-
-       bool8_32 mod = pitch_mod & (1 << J);
-
-       if (ch->needs_decode) 
-       {
-               AltDecodeBlock(ch, iapu);
-           //DecodeBlock(ch);
-           ch->needs_decode = FALSE;
-           ch->sample = ch->block[0];
-           ch->sample_pointer = freq0 >> FIXED_POINT_SHIFT;
-           if (ch->sample_pointer == 0)
-               ch->sample_pointer = 1;
-           if (ch->sample_pointer > SOUND_DECODE_LENGTH)
-               ch->sample_pointer = SOUND_DECODE_LENGTH - 1;
-           ch->next_sample = ch->block[ch->sample_pointer];
-           ch->interpolate = 0;
-
-           if (Settings.InterpolatedSound && freq0 < FIXED_POINT && !mod)
-               ch->interpolate = ((ch->next_sample - ch->sample) * 
-                                  (long) freq0) / (long) FIXED_POINT;
-       }
-       int32 V = (ch->sample * ch->left_vol_level) / 128;
-
-       for (uint32 I = 0; I < (uint32) sample_count; I++)
-       {
-           unsigned long freq = freq0;
-
-           if (mod)
-               freq = PITCH_MOD(freq, wave [I]);
-
-           ch->env_error += ch->erate;
-           if (ch->env_error >= FIXED_POINT) 
-           {
-               uint32 step = ch->env_error >> FIXED_POINT_SHIFT;
-
-               switch (ch->state)
-               {
-               case SOUND_ATTACK:
-                   ch->env_error &= FIXED_POINT_REMAINDER;
-                   ch->envx += step << 1;
-                   ch->envxx = ch->envx << ENVX_SHIFT;
-
-                   if (ch->envx >= 126)
-                   {
-                       ch->envx = 127;
-                       ch->envxx = 127 << ENVX_SHIFT;
-                       ch->state = SOUND_DECAY;
-                       if (ch->sustain_level != 8) 
-                       {
-                           S9xSetEnvRate (ch, ch->decay_rate, -1,
-                                               (MAX_ENVELOPE_HEIGHT * ch->sustain_level)
-                                               >> 3);
-                           break;
-                       }
-                       ch->state = SOUND_SUSTAIN;
-                       S9xSetEnvRate (ch, ch->sustain_rate, -1, 0);
-                   }
-                   break;
-               
-               case SOUND_DECAY:
-                   while (ch->env_error >= FIXED_POINT)
-                   {
-                       ch->envxx = (ch->envxx >> 8) * 255;
-                       ch->env_error -= FIXED_POINT;
-                   }
-                   ch->envx = ch->envxx >> ENVX_SHIFT;
-                   if (ch->envx <= ch->envx_target)
-                   {
-                       if (ch->envx <= 0)
-                       {
-                           S9xAPUSetEndOfSample (J, ch);
-                           goto mono_exit;
-                       }
-                       ch->state = SOUND_SUSTAIN;
-                       S9xSetEnvRate (ch, ch->sustain_rate, -1, 0);
-                   }
-                   break;
-
-               case SOUND_SUSTAIN:
-                   while (ch->env_error >= FIXED_POINT)
-                   {
-                       ch->envxx = (ch->envxx >> 8) * 255;
-                       ch->env_error -= FIXED_POINT;
-                   }
-                   ch->envx = ch->envxx >> ENVX_SHIFT;
-                   if (ch->envx <= 0)
-                   {
-                       S9xAPUSetEndOfSample (J, ch);
-                       goto mono_exit;
-                   }
-                   break;
-                   
-               case SOUND_RELEASE:
-                   while (ch->env_error >= FIXED_POINT)
-                   {
-                       ch->envxx -= (MAX_ENVELOPE_HEIGHT << ENVX_SHIFT) / 256;
-                       ch->env_error -= FIXED_POINT;
-                   }
-                   ch->envx = ch->envxx >> ENVX_SHIFT;
-                   if (ch->envx <= 0)
-                   {
-                       S9xAPUSetEndOfSample (J, ch);
-                       goto mono_exit;
-                   }
-                   break;
-               
-               case SOUND_INCREASE_LINEAR:
-                   ch->env_error &= FIXED_POINT_REMAINDER;
-                   ch->envx += step << 1;
-                   ch->envxx = ch->envx << ENVX_SHIFT;
-
-                   if (ch->envx >= 126)
-                   {
-                       ch->envx = 127;
-                       ch->envxx = 127 << ENVX_SHIFT;
-                       ch->state = SOUND_GAIN;
-                       ch->mode = MODE_GAIN;
-                       S9xSetEnvRate (ch, 0, -1, 0);
-                   }
-                   break;
-
-               case SOUND_INCREASE_BENT_LINE:
-                   if (ch->envx >= (MAX_ENVELOPE_HEIGHT * 3) / 4)
-                   {
-                       while (ch->env_error >= FIXED_POINT)
-                       {
-                           ch->envxx += (MAX_ENVELOPE_HEIGHT << ENVX_SHIFT) / 256;
-                           ch->env_error -= FIXED_POINT;
-                       }
-                       ch->envx = ch->envxx >> ENVX_SHIFT;
-                   }
-                   else
-                   {
-                       ch->env_error &= FIXED_POINT_REMAINDER;
-                       ch->envx += step << 1;
-                       ch->envxx = ch->envx << ENVX_SHIFT;
-                   }
-
-                   if (ch->envx >= 126)
-                   {
-                       ch->envx = 127;
-                       ch->envxx = 127 << ENVX_SHIFT;
-                       ch->state = SOUND_GAIN;
-                       ch->mode = MODE_GAIN;
-                       S9xSetEnvRate (ch, 0, -1, 0);
-                   }
-                   break;
-
-               case SOUND_DECREASE_LINEAR:
-                   ch->env_error &= FIXED_POINT_REMAINDER;
-                   ch->envx -= step << 1;
-                   ch->envxx = ch->envx << ENVX_SHIFT;
-                   if (ch->envx <= 0)
-                   {
-                       S9xAPUSetEndOfSample (J, ch);
-                       goto mono_exit;
-                   }
-                   break;
-
-               case SOUND_DECREASE_EXPONENTIAL:
-                   while (ch->env_error >= FIXED_POINT)
-                   {
-                       ch->envxx = (ch->envxx >> 8) * 255;
-                       ch->env_error -= FIXED_POINT;
-                   }
-                   ch->envx = ch->envxx >> ENVX_SHIFT;
-                   if (ch->envx <= 0)
-                   {
-                       S9xAPUSetEndOfSample (J, ch);
-                       goto mono_exit;
-                   }
-                   break;
-               
-               case SOUND_GAIN:
-                   S9xSetEnvRate (ch, 0, -1, 0);
-                   break;
-               }
-               ch->left_vol_level = (ch->envx * ch->volume_left) / 128;
-               V = (ch->sample * ch->left_vol_level) / 128;
-           }
-
-           ch->count += freq;
-           if (ch->count >= FIXED_POINT)
-           {
-               V = ch->count >> FIXED_POINT_SHIFT;
-               ch->sample_pointer += V;
-               ch->count &= FIXED_POINT_REMAINDER;
-
-               ch->sample = ch->next_sample;
-               if (ch->sample_pointer >= SOUND_DECODE_LENGTH)
-               {
-                   if (JUST_PLAYED_LAST_SAMPLE(ch))
-                   {
-                       S9xAPUSetEndOfSample (J, ch);
-                       goto mono_exit;
-                   }
-                   do
-                   {
-                       ch->sample_pointer -= SOUND_DECODE_LENGTH;
-                       if (ch->last_block)
-                       {
-                           if (!ch->loop)
-                           {
-                               ch->sample_pointer = LAST_SAMPLE;
-                               ch->next_sample = ch->sample;
-                               break;
-                           }
-                           else
-                           {
-                               ch->last_block = FALSE;
-                               uint8 *dir = S9xGetSampleAddress (ch->sample_number);
-                               ch->block_pointer = READ_WORD(dir + 2);
-                               S9xAPUSetEndX (J);
-                           }
-                       }
-                       AltDecodeBlock(ch, iapu);
-                       //DecodeBlock (ch);
-                   } while (ch->sample_pointer >= SOUND_DECODE_LENGTH);
-                   if (!JUST_PLAYED_LAST_SAMPLE (ch))
-                       ch->next_sample = ch->block [ch->sample_pointer];
-               }
-               else
-                   ch->next_sample = ch->block [ch->sample_pointer];
-
-               if (ch->type == SOUND_SAMPLE)
-               {
-                   if (Settings.InterpolatedSound && freq < FIXED_POINT && !mod)
-                   {
-                       ch->interpolate = ((ch->next_sample - ch->sample) * 
-                                          (long) freq) / (long) FIXED_POINT;
-                       ch->sample = (int16) (ch->sample + (((ch->next_sample - ch->sample) * 
-                                          (long) (ch->count)) / (long) FIXED_POINT));
-                   }             
-                   else
-                       ch->interpolate = 0;
-               }
-               else
-               {
-                   for (;V > 0; V--)
-                       if ((so.noise_gen <<= 1) & 0x80000000L)
-                           so.noise_gen ^= 0x0040001L;
-                   ch->sample = (so.noise_gen << 17) >> 17;
-                   ch->interpolate = 0;
-               }
-               V = (ch->sample * ch-> left_vol_level) / 128;
-            }
-           else
-           {
-               if (ch->interpolate)
-               {
-                   int32 s = (int32) ch->sample + ch->interpolate;
-
-                   CLIP16(s);
-                   ch->sample = (int16) s;
-                   V = (ch->sample * ch-> left_vol_level) / 128;
-               }
-           }
-
-           MixBuffer [I] += V;
-           ch->echo_buf_ptr [I] += V;
-
-           if (pitch_mod & (1 << (J + 1)))
-               wave [I] = ch->sample * ch->envx;
-        }
-mono_exit: ;
-    }
-}
-#ifdef __DJGPP
-END_OF_FUNCTION(MixMono);
-#endif
-
-#ifdef __sun
-extern uint8 int2ulaw (int);
-#endif
-
-// For backwards compatibility with older port specific code
-void S9xMixSamples (uint8 *buffer, int sample_count)
-{
-    S9xMixSamplesO (buffer, sample_count, 0);
-}
-#ifdef __DJGPP
-END_OF_FUNCTION(S9xMixSamples);
-#endif
-
-void S9xMixSamplesO (uint8 *buffer, int sample_count, int byte_offset)
-{
-    int J;
-    int I;
-
-    if (!so.mute_sound)
-    {
-           memset (MixBuffer, 0, sample_count * sizeof (MixBuffer [0]));
-           if (SoundData.echo_enable)
-               memset (EchoBuffer, 0, sample_count * sizeof (EchoBuffer [0]));
-
-           if (so.stereo)
-               MixStereo (sample_count);
-           else
-               MixMono (sample_count);
-    }
-
-    /* Mix and convert waveforms */
-    if (so.sixteen_bit)
-    {
-           int byte_count = sample_count << 1;
-       
-           // 16-bit sound
-           if (so.mute_sound)
-           {
-                memset (buffer + byte_offset, 0, byte_count);
-           }
-           else
-           {
-               int O = byte_offset >> 1;
-               if (SoundData.echo_enable && SoundData.echo_buffer_size)
-               {
-                       if (so.stereo)
-                       {
-                           // 16-bit stereo sound with echo enabled ...
-                           if (SoundData.no_filter)
-                           {
-                                   // ... but no filter defined.
-                                   for (J = 0; J < sample_count; J++)
-                                   {
-                                       int E = Echo [SoundData.echo_ptr];
-
-                                       Echo [SoundData.echo_ptr] = (E * SoundData.echo_feedback) / 128 + EchoBuffer [J];
-
-                                       if ((SoundData.echo_ptr += 1) >= SoundData.echo_buffer_size)
-                                SoundData.echo_ptr = 0;
-
-                                       I = (MixBuffer [J] * SoundData.master_volume [J & 1] + E * SoundData.echo_volume [J & 1]) / VOL_DIV16;
-
-                                       CLIP16(I);
-                                       ((signed short *) buffer)[J + O] = I;
-                                   }
-                           }
-                           else
-                           {
-                                   // ... with filter defined.
-                                   for (J = 0; J < sample_count; J++)
-                                   {
-                                       int E = Echo [SoundData.echo_ptr];
-
-                                       Loop [(Z - 0) & 15] = E;
-                                       E =  E                    * FilterTaps [0];
-                                       E += Loop [(Z -  2) & 15] * FilterTaps [1];
-                                       E += Loop [(Z -  4) & 15] * FilterTaps [2];
-                                       E += Loop [(Z -  6) & 15] * FilterTaps [3];
-                                       E += Loop [(Z -  8) & 15] * FilterTaps [4];
-                                       E += Loop [(Z - 10) & 15] * FilterTaps [5];
-                                       E += Loop [(Z - 12) & 15] * FilterTaps [6];
-                                       E += Loop [(Z - 14) & 15] * FilterTaps [7];
-                                       E /= 128;
-                                       Z++;
-
-                                       Echo [SoundData.echo_ptr] = (E * SoundData.echo_feedback) / 128 +
-                                                                   EchoBuffer [J];
-
-                                       if ((SoundData.echo_ptr += 1) >= SoundData.echo_buffer_size)
-                                           SoundData.echo_ptr = 0;
-
-                                       I = (MixBuffer [J] * 
-                                            SoundData.master_volume [J & 1] +
-                                            E * SoundData.echo_volume [J & 1]) / VOL_DIV16;
-
-                                       CLIP16(I);
-                                       ((signed short *) buffer)[J + O] = I;
-                                   }
-                           }
-                       }
-                       else
-                       {
-                           // 16-bit mono sound with echo enabled...
-                           if (SoundData.no_filter)
-                           {
-                                   // ... no filter defined
-                                   for (J = 0; J < sample_count; J++)
-                                   {
-                                       int E = Echo [SoundData.echo_ptr];
-
-                                       Echo [SoundData.echo_ptr] = (E * SoundData.echo_feedback) / 128 +
-                                                                    EchoBuffer [J];
-
-                                       if ((SoundData.echo_ptr += 1) >= SoundData.echo_buffer_size)
-                                           SoundData.echo_ptr = 0;
-
-                                       I = (MixBuffer [J] *
-                                            SoundData.master_volume [0] +
-                                            E * SoundData.echo_volume [0]) / VOL_DIV16;
-                                       CLIP16(I);
-                                       ((signed short *) buffer)[J + O] = I;
-                                   }
-                           }
-                           else
-                           {
-                                   // ... with filter defined
-                                   for (J = 0; J < sample_count; J++)
-                                   {
-                                       int E = Echo [SoundData.echo_ptr];
-
-                                       Loop [(Z - 0) & 7] = E;
-                                       E =  E                  * FilterTaps [0];
-                                       E += Loop [(Z - 1) & 7] * FilterTaps [1];
-                                       E += Loop [(Z - 2) & 7] * FilterTaps [2];
-                                       E += Loop [(Z - 3) & 7] * FilterTaps [3];
-                                       E += Loop [(Z - 4) & 7] * FilterTaps [4];
-                                       E += Loop [(Z - 5) & 7] * FilterTaps [5];
-                                       E += Loop [(Z - 6) & 7] * FilterTaps [6];
-                                       E += Loop [(Z - 7) & 7] * FilterTaps [7];
-                                       E /= 128;
-                                       Z++;
-
-                                       Echo [SoundData.echo_ptr] = (E * SoundData.echo_feedback) / 128 +
-                                                                    EchoBuffer [J];
-
-                                       if ((SoundData.echo_ptr += 1) >= SoundData.echo_buffer_size)
-                                           SoundData.echo_ptr = 0;
-
-                                       I = (MixBuffer [J] * SoundData.master_volume [0] +
-                                            E * SoundData.echo_volume [0]) / VOL_DIV16;
-                                       CLIP16(I);
-                                       ((signed short *) buffer)[J + O] = I;
-                                   }
-                           }
-                       }
-               }
-               else
-               {
-                       // 16-bit mono or stereo sound, no echo
-                       for (J = 0; J < sample_count; J++)
-                       {
-                           I = (MixBuffer [J] * 
-                                SoundData.master_volume [J & 1]) / VOL_DIV16;
-
-                           CLIP16(I);
-                           ((signed short *) buffer)[J + O] = I;
-                       }
-               }
-           }
-    }
-    else
-    {
-           int O = byte_offset;
-
-           // 8-bit sound
-           if (so.mute_sound)
-           {
-             memset (buffer + O, 128, sample_count);
-           }
-           else
-#ifdef __sun
-               if (so.encoded)
-               {
-                   for (J = 0; J < sample_count; J++)
-                   {
-                       I = (MixBuffer [J] * SoundData.master_volume_left) / VOL_DIV16;
-                       CLIP16(I);
-                       buffer[J + O] = int2ulaw (I);
-                   }
-               }
-               else
-#endif
-           {
-               if (SoundData.echo_enable && SoundData.echo_buffer_size)
-               {
-                       if (so.stereo)
-                       {
-                           // 8-bit stereo sound with echo enabled...
-                           if (SoundData.no_filter)
-                           {
-                                   // ... but no filter
-                                   for (J = 0; J < sample_count; J++)
-                                   {
-                                       int E = Echo [SoundData.echo_ptr];
-
-                                       Echo [SoundData.echo_ptr] = (E * SoundData.echo_feedback) / 128 + 
-                                                                   EchoBuffer [J];
-
-                                       if ((SoundData.echo_ptr += 1) >= SoundData.echo_buffer_size)
-                                           SoundData.echo_ptr = 0;
-
-                                       I = (MixBuffer [J] * 
-                                            SoundData.master_volume [J & 1] +
-                                            E * SoundData.echo_volume [J & 1]) / VOL_DIV8;
-                                       CLIP8(I);
-                                       buffer [J + O] = I + 128;
-                                   }
-                           }
-                           else
-                           {
-                                   // ... with filter
-                                   for (J = 0; J < sample_count; J++)
-                                   {
-                                       int E = Echo [SoundData.echo_ptr];
-
-                                       Loop [(Z - 0) & 15] = E;
-                                       E =  E                    * FilterTaps [0];
-                                       E += Loop [(Z -  2) & 15] * FilterTaps [1];
-                                       E += Loop [(Z -  4) & 15] * FilterTaps [2];
-                                       E += Loop [(Z -  6) & 15] * FilterTaps [3];
-                                       E += Loop [(Z -  8) & 15] * FilterTaps [4];
-                                       E += Loop [(Z - 10) & 15] * FilterTaps [5];
-                                       E += Loop [(Z - 12) & 15] * FilterTaps [6];
-                                       E += Loop [(Z - 14) & 15] * FilterTaps [7];
-                                       E /= 128;
-                                       Z++;
-
-                                       Echo [SoundData.echo_ptr] = (E * SoundData.echo_feedback) / 128 + 
-                                                                   EchoBuffer [J];
-
-                                       if ((SoundData.echo_ptr += 1) >= SoundData.echo_buffer_size)
-                                           SoundData.echo_ptr = 0;
-
-                                       I = (MixBuffer [J] * 
-                                            SoundData.master_volume [J & 1] +
-                                            E * SoundData.echo_volume [J & 1]) / VOL_DIV8;
-                                       CLIP8(I);
-                                       buffer [J + O] = I + 128;
-                                   }
-                           }
-                       }
-                       else
-                       {
-                           // 8-bit mono sound with echo enabled...
-                           if (SoundData.no_filter)
-                           {
-                                   // ... but no filter.
-                                   for (J = 0; J < sample_count; J++)
-                                   {
-                                       int E = Echo [SoundData.echo_ptr];
-
-                                       Echo [SoundData.echo_ptr] = (E * SoundData.echo_feedback) / 128 + 
-                                                                   EchoBuffer [J];
-
-                                       if ((SoundData.echo_ptr += 1) >= SoundData.echo_buffer_size)
-                                           SoundData.echo_ptr = 0;
-
-                                       I = (MixBuffer [J] * SoundData.master_volume [0] +
-                                            E * SoundData.echo_volume [0]) / VOL_DIV8;
-                                       CLIP8(I);
-                                       buffer [J + O] = I + 128;
-                                   }
-                           }
-                           else
-                           {
-                                   // ... with filter.
-                                   for (J = 0; J < sample_count; J++)
-                                   {
-                                       int E = Echo [SoundData.echo_ptr];
-
-                                       Loop [(Z - 0) & 7] = E;
-                                       E =  E                  * FilterTaps [0];
-                                       E += Loop [(Z - 1) & 7] * FilterTaps [1];
-                                       E += Loop [(Z - 2) & 7] * FilterTaps [2];
-                                       E += Loop [(Z - 3) & 7] * FilterTaps [3];
-                                       E += Loop [(Z - 4) & 7] * FilterTaps [4];
-                                       E += Loop [(Z - 5) & 7] * FilterTaps [5];
-                                       E += Loop [(Z - 6) & 7] * FilterTaps [6];
-                                       E += Loop [(Z - 7) & 7] * FilterTaps [7];
-                                       E /= 128;
-                                       Z++;
-
-                                       Echo [SoundData.echo_ptr] = (E * SoundData.echo_feedback) / 128 + 
-                                                                   EchoBuffer [J];
-
-                                       if ((SoundData.echo_ptr += 1) >= SoundData.echo_buffer_size)
-                                           SoundData.echo_ptr = 0;
-
-                                       I = (MixBuffer [J] * SoundData.master_volume [0] +
-                                            E * SoundData.echo_volume [0]) / VOL_DIV8;
-                                       CLIP8(I);
-                                       buffer [J + O] = I + 128;
-                                   }
-                           }
-                       }
-               }
-               else
-               {
-                       // 8-bit mono or stereo sound, no echo
-                       for (J = 0; J < sample_count; J++)
-                       {
-                           I = (MixBuffer [J] * 
-                                SoundData.master_volume [J & 1]) / VOL_DIV8;
-                           CLIP8(I);
-                           buffer [J + O] = I + 128;
-                       }
-           }
-           }
-    }
-}
-
-#ifdef __DJGPP
-END_OF_FUNCTION(S9xMixSamplesO);
-#endif
-
-void S9xResetSound (bool8_32 full)
-{
-    for (int i = 0; i < 8; i++)
-    {
-       SoundData.channels[i].state = SOUND_SILENT;
-       SoundData.channels[i].mode = MODE_NONE;
-       SoundData.channels[i].type = SOUND_SAMPLE;
-       SoundData.channels[i].volume_left = 0;
-       SoundData.channels[i].volume_right = 0;
-       SoundData.channels[i].hertz = 0;
-       SoundData.channels[i].count = 0;
-       SoundData.channels[i].loop = FALSE;
-       SoundData.channels[i].envx_target = 0;
-       SoundData.channels[i].env_error = 0;
-       SoundData.channels[i].erate = 0;
-       SoundData.channels[i].envx = 0;
-       SoundData.channels[i].envxx = 0;
-       SoundData.channels[i].left_vol_level = 0;
-       SoundData.channels[i].right_vol_level = 0;
-       SoundData.channels[i].direction = 0;
-       SoundData.channels[i].attack_rate = 0;
-       SoundData.channels[i].decay_rate = 0;
-       SoundData.channels[i].sustain_rate = 0;
-       SoundData.channels[i].release_rate = 0;
-       SoundData.channels[i].sustain_level = 0;
-       SoundData.echo_ptr = 0;
-       SoundData.echo_feedback = 0;
-       SoundData.echo_buffer_size = 1;
-    }
-    FilterTaps [0] = 127;
-    FilterTaps [1] = 0;
-    FilterTaps [2] = 0;
-    FilterTaps [3] = 0;
-    FilterTaps [4] = 0;
-    FilterTaps [5] = 0;
-    FilterTaps [6] = 0;
-    FilterTaps [7] = 0;
-    so.mute_sound = TRUE;
-    so.noise_gen = 1;
-    so.sound_switch = 255;
-    so.samples_mixed_so_far = 0;
-    so.play_position = 0;
-    so.err_counter = 0;
-
-    if (full)
-    {
-       SoundData.master_volume_left = 0;
-       SoundData.master_volume_right = 0;
-       SoundData.echo_volume_left = 0;
-       SoundData.echo_volume_right = 0;
-       SoundData.echo_enable = 0;
-       SoundData.echo_write_enabled = 0;
-       SoundData.echo_channel_enable = 0;
-       SoundData.pitch_mod = 0;
-       SoundData.dummy[0] = 0;
-       SoundData.dummy[1] = 0;
-       SoundData.dummy[2] = 0;
-       SoundData.master_volume[0] = 0;
-       SoundData.master_volume[1] = 0;
-       SoundData.echo_volume[0] = 0;
-       SoundData.echo_volume[1] = 0;
-       SoundData.noise_hertz = 0;
-    }
-
-    SoundData.master_volume_left = 127;
-    SoundData.master_volume_right = 127;
-    SoundData.master_volume [0] = SoundData.master_volume [1] = 127;
-    if (so.playback_rate)
-       so.err_rate = (uint32) (FIXED_POINT * SNES_SCANLINE_TIME / (1.0 / so.playback_rate));
-    else
-       so.err_rate = 0;
-    SoundData.no_filter = TRUE;
-}
-
-void S9xSetPlaybackRate (uint32 playback_rate)
-{
-    so.playback_rate = playback_rate;
-    so.err_rate = (uint32) (SNES_SCANLINE_TIME * FIXED_POINT / (1.0 / (double) so.playback_rate));
-    S9xSetEchoDelay (APU.DSP [APU_EDL] & 0xf);
-    for (int i = 0; i < 8; i++)
-       S9xSetSoundFrequency (i, SoundData.channels [i].hertz);
-}
-
-bool8_32 S9xInitSound (int mode, bool8_32 stereo, int buffer_size)
-{
-    so.sound_fd = -1;
-    so.sound_switch = 255;
-
-    so.playback_rate = mode;
-    so.buffer_size = buffer_size;
-    so.stereo = false;//stereo;
-    so.sixteen_bit = Settings.SixteenBitSound;
-    so.encoded = FALSE;
-    
-    S9xResetSound (TRUE);
-
-    //if (!(mode & 7))
-       //return (1);
-
-    S9xSetSoundMute (TRUE);
-    if (!S9xOpenSoundDevice (mode, stereo, buffer_size))
-    {
-       S9xMessage (S9X_ERROR, S9X_SOUND_DEVICE_OPEN_FAILED,
-                   "Sound device open failed");
-       return (0);
-    }
-
-    return (1);
-}
-
-bool8_32 S9xSetSoundMode (int channel, int mode)
-{
-    Channel *ch = &SoundData.channels[channel];
-
-    switch (mode)
-    {
-    case MODE_RELEASE:
-       if (ch->mode != MODE_NONE)
-       {
-           ch->mode = MODE_RELEASE;
-           return (TRUE);
-       }
-       break;
-       
-    case MODE_DECREASE_LINEAR:
-    case MODE_DECREASE_EXPONENTIAL:
-    case MODE_GAIN:
-       if (ch->mode != MODE_RELEASE)
-       {
-           ch->mode = mode;
-           if (ch->state != SOUND_SILENT)
-               ch->state = mode;
-
-           return (TRUE);
-       }
-       break;
-
-    case MODE_INCREASE_LINEAR:
-    case MODE_INCREASE_BENT_LINE:
-       if (ch->mode != MODE_RELEASE)
-       {
-           ch->mode = mode;
-           if (ch->state != SOUND_SILENT)
-               ch->state = mode;
-
-           return (TRUE);
-       }
-       break;
-
-    case MODE_ADSR:
-       if (ch->mode == MODE_NONE || ch->mode == MODE_ADSR)
-       {
-           ch->mode = mode;
-           return (TRUE);
-       }
-    }
-
-    return (FALSE);
-}
-
-void S9xSetSoundControl (int sound_switch)
-{
-    so.sound_switch = sound_switch;
-}
-
-void S9xPlaySample (int channel)
-{
-    Channel *ch = &SoundData.channels[channel];
-    
-    ch->state = SOUND_SILENT;
-    ch->mode = MODE_NONE;
-    ch->envx = 0;
-    ch->envxx = 0;
-
-    S9xFixEnvelope (channel,
-                   APU.DSP [APU_GAIN  + (channel << 4)], 
-                   APU.DSP [APU_ADSR1 + (channel << 4)],
-                   APU.DSP [APU_ADSR2 + (channel << 4)]);
-
-    ch->sample_number = APU.DSP [APU_SRCN + channel * 0x10];
-    if (APU.DSP [APU_NON] & (1 << channel))
-       ch->type = SOUND_NOISE;
-    else
-       ch->type = SOUND_SAMPLE;
-
-    S9xSetSoundFrequency (channel, ch->hertz);
-    ch->loop = FALSE;
-    ch->needs_decode = TRUE;
-    ch->last_block = FALSE;
-    ch->previous [0] = ch->previous[1] = 0;
-    uint8 *dir = S9xGetSampleAddress (ch->sample_number);
-    ch->block_pointer = READ_WORD (dir);
-    ch->sample_pointer = 0;
-    ch->env_error = 0;
-    ch->next_sample = 0;
-    ch->interpolate = 0;
-
-    switch (ch->mode)
-    {
-    case MODE_ADSR:
-       if (ch->attack_rate == 0)
-       {
-           if (ch->decay_rate == 0 || ch->sustain_level == 8)
-           {
-               ch->state = SOUND_SUSTAIN;
-               ch->envx = (MAX_ENVELOPE_HEIGHT * ch->sustain_level) >> 3;
-               S9xSetEnvRate (ch, ch->sustain_rate, -1, 0);
-           }
-           else
-           {
-               ch->state = SOUND_DECAY;
-               ch->envx = MAX_ENVELOPE_HEIGHT;
-               S9xSetEnvRate (ch, ch->decay_rate, -1, 
-                                   (MAX_ENVELOPE_HEIGHT * ch->sustain_level) >> 3);
-           }
-           ch-> left_vol_level = (ch->envx * ch->volume_left) / 128;
-           ch->right_vol_level = (ch->envx * ch->volume_right) / 128;
-       }
-       else
-       {
-           ch->state = SOUND_ATTACK;
-           ch->envx = 0;
-           ch->left_vol_level = 0;
-           ch->right_vol_level = 0;
-           S9xSetEnvRate (ch, ch->attack_rate, 1, MAX_ENVELOPE_HEIGHT);
-       }
-       ch->envxx = ch->envx << ENVX_SHIFT;
-       break;
-
-    case MODE_GAIN:
-       ch->state = SOUND_GAIN;
-       break;
-
-    case MODE_INCREASE_LINEAR:
-       ch->state = SOUND_INCREASE_LINEAR;
-       break;
-
-    case MODE_INCREASE_BENT_LINE:
-       ch->state = SOUND_INCREASE_BENT_LINE;
-       break;
-
-    case MODE_DECREASE_LINEAR:
-       ch->state = SOUND_DECREASE_LINEAR;
-       break;
-
-    case MODE_DECREASE_EXPONENTIAL:
-       ch->state = SOUND_DECREASE_EXPONENTIAL;
-       break;
-
-    default:
-       break;
-    }
-
-    S9xFixEnvelope (channel,
-                   APU.DSP [APU_GAIN  + (channel << 4)], 
-                   APU.DSP [APU_ADSR1 + (channel << 4)],
-                   APU.DSP [APU_ADSR2 + (channel << 4)]);
-}
diff --git a/sounduxnew.h b/sounduxnew.h
deleted file mode 100644 (file)
index 3e92dba..0000000
+++ /dev/null
@@ -1,197 +0,0 @@
-/*
- * Snes9x - Portable Super Nintendo Entertainment System (TM) emulator.
- *
- * (c) Copyright 1996 - 2001 Gary Henderson (gary.henderson@ntlworld.com) and
- *                           Jerremy Koot (jkoot@snes9x.com)
- *
- * Super FX C emulator code 
- * (c) Copyright 1997 - 1999 Ivar (ivar@snes9x.com) and
- *                           Gary Henderson.
- * Super FX assembler emulator code (c) Copyright 1998 zsKnight and _Demo_.
- *
- * DSP1 emulator code (c) Copyright 1998 Ivar, _Demo_ and Gary Henderson.
- * C4 asm and some C emulation code (c) Copyright 2000 zsKnight and _Demo_.
- * C4 C code (c) Copyright 2001 Gary Henderson (gary.henderson@ntlworld.com).
- *
- * DOS port code contains the works of other authors. See headers in
- * individual files.
- *
- * Snes9x homepage: http://www.snes9x.com
- *
- * Permission to use, copy, modify and distribute Snes9x in both binary and
- * source form, for non-commercial purposes, is hereby granted without fee,
- * providing that this license information and copyright notice appear with
- * all copies and any derived work.
- *
- * This software is provided 'as-is', without any express or implied
- * warranty. In no event shall the authors be held liable for any damages
- * arising from the use of this software.
- *
- * Snes9x is freeware for PERSONAL USE only. Commercial users should
- * seek permission of the copyright holders first. Commercial use includes
- * charging money for Snes9x or software derived from Snes9x.
- *
- * The copyright holders request that bug fixes and improvements to the code
- * should be forwarded to them so everyone can benefit from the modifications
- * in future versions.
- *
- * Super NES and Super Nintendo Entertainment System are trademarks of
- * Nintendo Co., Limited and its subsidiary companies.
- */
-#ifndef _SOUND_H_
-#define _SOUND_H_
-
-enum { SOUND_SAMPLE = 0, SOUND_NOISE, SOUND_EXTRA_NOISE, SOUND_MUTE };
-enum { SOUND_SILENT, SOUND_ATTACK, SOUND_DECAY, SOUND_SUSTAIN,
-       SOUND_RELEASE, SOUND_GAIN, SOUND_INCREASE_LINEAR,
-       SOUND_INCREASE_BENT_LINE, SOUND_DECREASE_LINEAR,
-       SOUND_DECREASE_EXPONENTIAL};
-
-enum { MODE_NONE = SOUND_SILENT, MODE_ADSR, MODE_RELEASE = SOUND_RELEASE,
-       MODE_GAIN, MODE_INCREASE_LINEAR, MODE_INCREASE_BENT_LINE,
-       MODE_DECREASE_LINEAR, MODE_DECREASE_EXPONENTIAL};
-
-#define MAX_ENVELOPE_HEIGHT 127
-#define ENVELOPE_SHIFT 7
-#define MAX_VOLUME 127
-#define VOLUME_SHIFT 7
-#define VOL_DIV 128
-#define SOUND_DECODE_LENGTH 16
-
-#define NUM_CHANNELS    8
-#define SOUND_BUFFER_SIZE (1024 * 16)
-#define MAX_BUFFER_SIZE SOUND_BUFFER_SIZE
-#define SOUND_BUFFER_SIZE_MASK (SOUND_BUFFER_SIZE - 1)
-
-#define SOUND_BUFS      4
-
-#ifdef __sgi
-//#  include <audio.h>
-#endif /* __sgi */
-
-typedef struct {
-    int                        sound_fd;
-    int                        sound_switch;
-    int                        playback_rate;
-    int                        buffer_size;
-    int                        noise_gen;
-    bool8_32   mute_sound;
-    int                        stereo;
-    bool8_32   sixteen_bit;
-    bool8_32   encoded;
-#ifdef __sun
-    int                        last_eof;
-#endif
-#ifdef __sgi
-    ALport             al_port;
-#endif /* __sgi */
-    int32              samples_mixed_so_far;
-    int32              play_position;
-    uint32             err_counter;
-    uint32             err_rate;
-} SoundStatus;
-
-EXTERN_C volatile SoundStatus so;
-
-typedef struct {
-    int                                        state;
-    int                                        type;
-    short                              volume_left;
-    short                              volume_right;
-    uint32                             hertz;
-    uint32                             frequency;
-    uint32                             count;
-    bool8_32                   loop;
-    int                                        envx;
-    short                              left_vol_level;
-    short                              right_vol_level;
-    short                              envx_target;
-    unsigned long int  env_error;
-    unsigned long              erate;
-    int                                        direction;
-    unsigned long              attack_rate;
-    unsigned long              decay_rate;
-    unsigned long              sustain_rate;
-    unsigned long              release_rate;
-    unsigned long              sustain_level;
-    signed short               sample;
-    signed short               decoded [16];
-    signed short               previous16 [2];
-    signed short               *block;
-    uint16                             sample_number;
-    bool8_32                   last_block;
-    bool8_32                   needs_decode;
-    uint32                             block_pointer;
-    uint32                             sample_pointer;
-    int                                        *echo_buf_ptr;
-    int                                        mode;
-    int32                              envxx;
-    signed short               next_sample;
-    int32                              interpolate;
-    int32                              previous [2];
-    // Just incase they are needed in the future, for snapshot compatibility.
-    uint32                             dummy [8];
-} Channel;
-
-typedef struct
-{
-    short              master_volume_left;
-    short              master_volume_right;
-    short              echo_volume_left;
-    short              echo_volume_right;
-    int                        echo_enable;
-    int                        echo_feedback;
-    int                        echo_ptr;
-    int                        echo_buffer_size;
-    int                        echo_write_enabled;
-    int                        echo_channel_enable;
-    int                        pitch_mod;
-    // Just incase they are needed in the future, for snapshot compatibility.
-    uint32             dummy [3];
-    Channel            channels [NUM_CHANNELS];
-    bool8_32   no_filter;
-    int                        master_volume [2];
-    int                        echo_volume [2];
-    int                        noise_hertz;
-} SSoundData;
-
-EXTERN_C SSoundData SoundData;
-
-void S9xSetSoundVolume (int channel, short volume_left, short volume_right);
-void S9xSetSoundFrequency (int channel, int hertz);
-void S9xSetSoundHertz (int channel, int hertz);
-void S9xSetSoundType (int channel, int type_of_sound);
-void S9xSetMasterVolume (short master_volume_left, short master_volume_right);
-void S9xSetEchoVolume (short echo_volume_left, short echo_volume_right);
-void S9xSetSoundControl (int sound_switch);
-bool8_32 S9xSetSoundMute (bool8_32 mute);
-void S9xSetEnvelopeHeight (int channel, int height);
-void S9xSetSoundADSR (int channel, int attack, int decay, int sustain,
-                     int sustain_level, int release);
-void S9xSetSoundKeyOff (int channel);
-void S9xSetSoundDecayMode (int channel);
-void S9xSetSoundAttachMode (int channel);
-void S9xSoundStartEnvelope (Channel *);
-void S9xSetSoundSample (int channel, uint16 sample_number);
-void S9xSetEchoFeedback (int echo_feedback);
-void S9xSetEchoEnable (uint8 byte);
-void S9xSetEchoDelay (int byte);
-void S9xSetEchoWriteEnable (uint8 byte);
-void S9xSetFilterCoefficient (int tap, int value);
-void S9xSetFrequencyModulationEnable (uint8 byte);
-void S9xSetEnvelopeRate (int channel, unsigned long rate, int direction,
-                        int target);
-bool8_32 S9xSetSoundMode (int channel, int mode);
-int S9xGetEnvelopeHeight (int channel);
-void S9xResetSound (bool8_32 full);
-void S9xFixSoundAfterSnapshotLoad ();
-void S9xPlaybackSoundSetting (int channel);
-void S9xPlaySample (int channel);
-void S9xFixEnvelope (int channel, uint8 gain, uint8 adsr1, uint8 adsr2);
-void S9xStartSample (int channel);
-
-EXTERN_C void S9xMixSamples (uint8 *buffer, int sample_count);
-EXTERN_C void S9xMixSamplesO (uint8 *buffer, int sample_count, int byte_offset);
-bool8_32 S9xOpenSoundDevice (int, bool8_32, int);
-void S9xSetPlaybackRate (uint32 rate);
-#endif
diff --git a/usbjoy.c b/usbjoy.c
deleted file mode 100644 (file)
index 81d1be4..0000000
--- a/usbjoy.c
+++ /dev/null
@@ -1,297 +0,0 @@
-/* Title: USB Joystick library
-   Version 0.2
-   Written by Puck2099 (puck2099@gmail.com), (c) 2006.
-   <http://www.gp32wip.com>
-   
-   If you use this library or a part of it, please, let it know.
-
-   This library is free software; you can redistribute it and/or
-   modify it under the terms of the GNU Lesser General Public
-   License as published by the Free Software Foundation; either
-   version 2.1 of the License, or (at your option) any later version.
-   
-   This library is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   Lesser General Public License for more details.
-
-   You should have received a copy of the GNU Lesser General Public
-   License along with this library; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
-*/
-
-#include <stdlib.h>
-#include <stdio.h>             /* For the definition of NULL */
-#include <sys/types.h>         // For Device open
-#include <sys/stat.h>
-#include <sys/ioctl.h>
-#include <fcntl.h>
-#include <unistd.h>            // For Device read
-
-#include <string.h>
-#include <limits.h>            /* For the definition of PATH_MAX */
-#include <linux/joystick.h>
-
-#include "usbjoy.h"
-
-
-/*
-  Function: joy_open
-
-  Opens a USB joystick and fills its information.
-
-  Parameters:
-
-  joynumber - Joystick's identifier (0 reserved for GP2X's builtin Joystick).
-
-  Returns:
-
-  Filled usbjoy structure.
-
-*/
-struct usbjoy * joy_open (int joynumber) {
-  int fd, i;
-  char path [128];
-  struct usbjoy * joy = NULL;
-
-  system ("insmod joydev"); // Loads joydev module
-
-  if (joynumber == 0) {
-  }
-  else if (joynumber > 0) {
-    sprintf (path, "/dev/input/js%d", joynumber-1);
-    fd = open(path, O_RDONLY, 0);
-    if (fd > 0) {
-      joy = (struct usbjoy *) malloc(sizeof(struct usbjoy));
-
-      // Joystick's file descriptor
-      joy->fd = fd;
-
-      // Set the joystick to non-blocking read mode
-      fcntl(joy->fd, F_SETFL, O_NONBLOCK);
-
-      // Joystick's name
-      ioctl(joy->fd, JSIOCGNAME(128*sizeof(char)), joy->name);
-
-      // Joystick's device
-      sprintf (joy->device, path);
-
-      // Joystick's buttons
-      ioctl(joy->fd, JSIOCGBUTTONS, &joy->numbuttons);
-
-      // Joystick's axes
-      ioctl(joy->fd, JSIOCGAXES, &joy->numaxes);
-
-      // Clean buttons and axes
-      for (i=0; i<32; i++) joy->statebuttons[i] = 0;
-      for (i=0; i<4; i++) joy->stateaxes[i] = 0;
-    }
-    else {
-      printf ("ERROR: No Joystick found\n");
-    }
-  }
-  return joy;
-}
-
-/*
-  Function: joy_name
-
-  Returns Joystick's name.
-
-  Parameters:
-
-  joy - Selected joystick.
-
-  Returns:
-
-  Joystick's name or NULL if <usbjoy> struct is empty.
-*/
-char * joy_name (struct usbjoy * joy) {
-  if (joy != NULL)  return joy->name;
-  else return NULL;
-}
-
-
-/*
-  Function: joy_device
-
-  Returns Joystick's device.
-
-  Parameters:
-
-  joy - Selected joystick.
-
-  Returns:
-
-  Joystick's device or NULL if <usbjoy> struct is empty.
-*/
-char * joy_device (struct usbjoy * joy) {
-  if (joy != NULL)  return joy->device;
-  else return NULL;
-}
-
-
-/*
-  Function: joy_buttons
-
-  Returns Joystick's buttons number.
-
-  Parameters:
-
-  joy - Selected joystick.
-
-  Returns:
-
-  Joystick's buttons or 0 if <usbjoy> struct is empty.
-*/
-int joy_buttons (struct usbjoy * joy) {
-  if (joy != NULL) return joy->numbuttons;
-  else return 0;
-}
-
-
-/*
-  Function: joy_axes
-
-  Returns Joystick's axes number.
-
-  Parameters:
-
-  joy - Selected joystick.
-
-  Returns:
-
-  Joystick's axes or 0 if <usbjoy> struct is empty.
-*/
-int joy_axes (struct usbjoy * joy) {
-  if (joy != NULL) return joy->numaxes;
-  else return 0;
-}
-
-
-/*
-  Function: joy_update
-
-  Updates Joystick's internal information (<statebuttons> and <stateaxes> fields).
-
-  Parameters:
-
-  joy - Selected joystick.
-
-  Returns:
-
-  0 - No events registered (no need to update).
-  1 - Events registered (a button or axe has been pushed).
-  -1 - Error: <usbjoy> struct is empty.
-*/
-int joy_update (struct usbjoy * joy) {
-  struct js_event events[0xff];
-  int i, len;
-  int event = 0;
-  if (joy != NULL) {    
-    if ((len=read(joy->fd, events, (sizeof events))) >0) {
-      len /= sizeof(events[0]);
-      for ( i=0; i<len; ++i ) {
-       switch (events[i].type & ~JS_EVENT_INIT) {
-       case JS_EVENT_AXIS:
-         if (events[i].number == 0) {
-           joy->stateaxes[JOYLEFT] = joy->stateaxes[JOYRIGHT] = 0;
-           if (events[i].value < 0) joy->stateaxes[JOYLEFT] = 1;
-           else if (events[i].value > 0) joy->stateaxes[JOYRIGHT] = 1;
-         }
-         else if (events[i].number == 1) {
-           joy->stateaxes[JOYUP] = joy->stateaxes[JOYDOWN] = 0;
-           if (events[i].value < 0) joy->stateaxes[JOYUP] = 1;
-           else if (events[i].value > 0) joy->stateaxes[JOYDOWN] = 1;
-         }
-         event = 1;
-         break;
-       case JS_EVENT_BUTTON:
-         joy->statebuttons[events[i].number] = events[i].value;
-         event = 1;
-         break;
-       default:
-         break;
-       }
-      }
-    }
-  }
-  else {
-    event = -1;
-  }   
-  return event;
-}
-
-
-/*
-  Function: joy_getbutton
-
-  Returns Joystick's button information.
-
-  Parameters:
-
-  button - Button which value you want to know (from 0 to 31).
-  joy - Selected joystick.
-
-  Returns:
-
-  0 - Button NOT pushed.
-  1 - Button pushed.
-  -1 - Error: <usbjoy> struct is empty.
-*/
-int joy_getbutton (int button, struct usbjoy * joy) {
-  if (joy != NULL) {
-    if (button < joy_buttons(joy)) return joy->statebuttons[button];
-    else return 0;
-  }
-  else return -1;
-}
-
-
-/*
-  Function: joy_getaxe
-
-  Returns Joystick's axes information.
-
-  Parameters:
-
-  axe - Axe which value you want to know (see <Axes values>).
-  joy - Selected joystick.
-
-  Returns:
-
-  0 - Direction NOT pushed.
-  1 - Direction pushed.
-  -1 - Error: <usbjoy> struct is empty.
-*/
-int joy_getaxe (int axe, struct usbjoy * joy) {
-  if (joy != NULL) {
-    if (axe < 4) return joy->stateaxes[axe];
-    else return 0;
-  }
-  else return -1;
-}
-
-
-/*
-  Function: joy_close
-
-  Closes selected joystick's file descriptor and detroys it's fields.
-
-  Parameters:
-
-  joy - Selected joystick.
-
-  Returns:
-
-  0 - Joystick successfully closed.
-  -1 - Error: <usbjoy> struct is empty.
-*/
-int joy_close (struct usbjoy * joy) {
-  if (joy != NULL) {
-    close (joy->fd);
-    free (joy);
-    return 0;
-  }
-  else return -1;
-}
diff --git a/usbjoy.h b/usbjoy.h
deleted file mode 100644 (file)
index c324744..0000000
--- a/usbjoy.h
+++ /dev/null
@@ -1,221 +0,0 @@
-/* Title: USB Joystick library
-   Version 0.2
-   Written by Puck2099 (puck2099@gmail.com), (c) 2006.
-   <http://www.gp32wip.com>
-   
-   If you use this library or a part of it, please, let it know.
-
-   This library is free software; you can redistribute it and/or
-   modify it under the terms of the GNU Lesser General Public
-   License as published by the Free Software Foundation; either
-   version 2.1 of the License, or (at your option) any later version.
-   
-   This library is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   Lesser General Public License for more details.
-
-   You should have received a copy of the GNU Lesser General Public
-   License along with this library; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
-*/
-
-#ifndef USBJOY_H
-#define USBJOY_H
-
-/*
-  Enumeration: Axes values
-  This enumeration contains shortcuts to the values used on axes.
-  
-  Constants:
-  JOYUP    - Joystick Up
-  JOYDOWN  - Joystick Down
-  JOYLEFT  - Joystick Left
-  JOYRIGHT - Joystick Right
-
-  See also: 
-  <joy_getaxe>
-*/
-#define JOYUP    (0)
-#define JOYDOWN  (1)
-#define JOYLEFT  (2)
-#define JOYRIGHT (3)
-
-
-/*
-  Struct: usbjoy
-
-  Contains all Joystick needed information.
-
-  Fields:
-  fd - File descriptor used.
-  name - Joystick's name.
-  device - /dev/input/jsX device.
-  numbuttons - Joystick's buttons.
-  numaxes - Joystick's axes.
-  numhats - Joystick's hats.
-  statebuttons - Current state of each button.
-  stateaxes - Current state of each direction.
-*/
-struct usbjoy {
-  int fd;
-  char name [128];
-  char device [128];
-  int numbuttons;
-  int numaxes;
-  int numhats;
-  int statebuttons[32];
-  int stateaxes[4];
-};
-
-
-/*
-  Function: joy_open
-
-  Opens a USB joystick and fills its information.
-
-  Parameters:
-
-  joynumber - Joystick's identifier (0 reserved for GP2X's builtin Joystick).
-
-  Returns:
-
-  Filled usbjoy structure.
-*/
-struct usbjoy * joy_open (int joynumber);
-
-
-/*
-  Function: joy_name
-
-  Returns Joystick's name.
-
-  Parameters:
-
-  joy - Selected joystick.
-
-  Returns:
-
-  Joystick's name or NULL if <usbjoy> struct is empty.
-*/
-char * joy_name (struct usbjoy * joy);
-
-
-/*
-  Function: joy_device
-
-  Returns Joystick's device.
-
-  Parameters:
-
-  joy - Selected joystick.
-
-  Returns:
-
-  Joystick's device or NULL if <usbjoy> struct is empty.
-*/
-char * joy_device (struct usbjoy * joy);
-
-/*
-  Function: joy_buttons
-
-  Returns Joystick's buttons number.
-
-  Parameters:
-
-  joy - Selected joystick.
-
-  Returns:
-
-  Joystick's buttons or 0 if <usbjoy> struct is empty.
-*/
-int joy_buttons (struct usbjoy * joy);
-
-/*
-  Function: joy_axes
-
-  Returns Joystick's axes number.
-
-  Parameters:
-
-  joy - Selected joystick.
-
-  Returns:
-
-  Joystick's axes or 0 if <usbjoy> struct is empty.
-*/
-int joy_axes (struct usbjoy * joy);
-
-
-/*
-  Function: joy_update
-
-  Updates Joystick's internal information (<statebuttons> and <stateaxes> fields).
-
-  Parameters:
-
-  joy - Selected joystick.
-
-  Returns:
-
-  0 - No events registered (no need to update).
-  1 - Events registered (a button or axe has been pushed).
-  -1 - Error: <usbjoy> struct is empty.
-*/
-int joy_update (struct usbjoy * joy);
-
-
-/*
-  Function: joy_getbutton
-
-  Returns Joystick's button information.
-
-  Parameters:
-
-  button - Button which value you want to know (from 0 to 31).
-  joy - Selected joystick.
-
-  Returns:
-
-  0 - Button NOT pushed.
-  1 - Button pushed.
-  -1 - Error: <usbjoy> struct is empty.
-*/
-int joy_getbutton (int button, struct usbjoy * joy);
-
-
-/*
-  Function: joy_getaxe
-
-  Returns Joystick's axes information.
-
-  Parameters:
-
-  axe - Axe which value you want to know (see <Axes values>).
-  joy - Selected joystick.
-
-  Returns:
-
-  0 - Direction NOT pushed.
-  1 - Direction pushed.
-  -1 - Error: <usbjoy> struct is empty.
-*/
-int joy_getaxe (int axe, struct usbjoy * joy);
-
-/*
-  Function: joy_close
-
-  Closes selected joystick's file descriptor and detroys it's fields.
-
-  Parameters:
-
-  joy - Selected joystick.
-
-  Returns:
-
-  0 - Joystick successfully closed.
-  -1 - Error: <usbjoy> struct is empty.
-*/
-int joy_close (struct usbjoy * joy);
-
-#endif // USBJOY_H