Browse Source

Wii backport(rebased). Saving works( previous is really a stupid error ).

Pal Lockheart 6 years ago
parent
commit
065a35cec7
27 changed files with 839 additions and 144 deletions
  1. 30 0
      .travis.yml
  2. 1 1
      adplug/dosbox_opl.cpp
  3. 1 0
      adplug/fprovide.cpp
  4. 78 62
      adplug/rix.cpp
  5. 34 33
      adplug/rix.h
  6. 1 5
      audio.c
  7. 1 1
      common.h
  8. 1 1
      emscripten/Makefile
  9. 26 19
      global.c
  10. 1 1
      input.c
  11. 1 1
      liboggvorbis/include/ogg/config_types.h
  12. 1 0
      macos/pal_config.h
  13. 19 0
      macos/util.mm
  14. 2 10
      main.c
  15. 1 1
      rixplay.cpp
  16. 0 4
      sound.c
  17. 6 0
      util.h
  18. 1 1
      video.c
  19. 1 0
      wii/.gdbinit
  20. 67 0
      wii/Makefile
  21. 3 0
      wii/README.txt
  22. BIN
      wii/icon.png
  23. 379 0
      wii/libc.c
  24. 9 0
      wii/meta.xml
  25. 35 0
      wii/pal_config.h
  26. 136 0
      wii/pal_utils.cpp
  27. 4 4
      winrt/SDLPal.WindowsPhone/SDLPal.Core.vcxproj

+ 30 - 0
.travis.yml

@@ -51,6 +51,36 @@ matrix:
           - mv sdlpal-mingw32.zip ../deploy/
           - cd ..
 
+      - os: linux
+        env: TARGET=wii
+        language: c
+        before_install:
+          - export DEVKITPRO=/home/travis/devkitPro
+          - export DEVKITPPC=${DEVKITPRO}/devkitPPC
+          - export PATH=$DEVKITPPC/bin:$PATH
+        install:
+          - export PUSHD="$(pwd)"
+          - mkdir $DEVKITPRO
+          - cd $DEVKITPRO
+          - wget https://sourceforge.net/projects/devkitpro/files/devkitPPC/devkitPPC_r27-x86_64-linux.tar.bz2
+          - tar xvf devkitPPC_r27-x86_64-linux.tar.bz2
+          - mkdir libogc
+          - cd libogc
+          - wget https://sourceforge.net/projects/devkitpro/files/libogc/libogc-1.8.12.tar.bz2
+          - tar xvf libogc-1.8.12.tar.bz2
+          - wget https://sourceforge.net/projects/devkitpro/files/libfat/libfat-ogc-1.0.13.tar.bz2
+          - tar xvf libfat-ogc-1.0.13.tar.bz2
+          - cd ..
+          - wget https://github.com/dborth/sdl-wii/releases/download/2013-10-28/SDL.Wii.10-28-2013.zip
+          - unzip SDL.Wii.10-28-2013.zip
+          - cd "${PUSHD}"
+        script:
+          - cd wii
+          - make
+          - tar cvjf ../deploy/sdlpal-wii.tar.bz2 icon.png meta.xml boot.dol
+          - make clean
+          - cd ..
+          
       - os: linux
         env: TARGET=Android NDK_VERSION=r13b TERM=dumb
         android:

+ 1 - 1
adplug/dosbox_opl.cpp

@@ -26,7 +26,7 @@
 
 #include "dosbox_opl.h"
 #include <stdlib.h>
-#include <memory.h>
+#include <string.h>
 #include <math.h>
 
 struct opl_chip_struct {

+ 1 - 0
adplug/fprovide.cpp

@@ -18,6 +18,7 @@
  *
  * fprovide.cpp - File provider class framework, by Simon Peter <dn.tlp@gmx.net>
  */
+#include "common.h"
 
 #include <string.h>
 #include "binio.h"

+ 78 - 62
adplug/rix.cpp

@@ -19,8 +19,10 @@
  * rix.cpp - Softstar RIX OPL Format Player by palxex <palxex.ys168.com>
  *                                             BSPAL <BSPAL.ys168.com>
  */
+#include "common.h"
 
 #include <cstring>
+#include <cstdio>
 #include <cstdlib>
 #include "rix.h"
 
@@ -37,9 +39,17 @@ using namespace std;
    defined(__sparc__)
    // big endian
    #define RIX_SWAP32(a) (((a) << 24) | (((a) << 8) & 0x00FF0000) | (((a) >> 8) & 0x0000FF00) | ((a) >> 24))
+   #define RIX_SWAP16(a) ((((a) << 8) & 0xFF00)  | ((a) >> 8))
 #else
    // little endian
    #define RIX_SWAP32(a) (a)
+   #define RIX_SWAP16(a) (a)
+#endif
+
+#ifdef DEBUG
+#define RELEASE_INLINE
+#else
+#define RELEASE_INLINE inline
 #endif
 
 const uint8_t CrixPlayer::adflag[] = {0,0,0,1,1,1,0,0,0,1,1,1,0,0,0,1,1,1};
@@ -73,7 +83,7 @@ CPlayer *CrixPlayer::factory(Copl *newopl)
 }
 
 CrixPlayer::CrixPlayer(Copl *newopl)
-  : CPlayer(newopl), flag_mkf(0), file_buffer(0), rix_buf(0)
+  : CPlayer(newopl), flag_mkf(0), fp(NULL)
 #if USE_RIX_EXTRA_INIT
 	, extra_regs(NULL), extra_vals(NULL), extra_length(0)
 #endif
@@ -82,8 +92,7 @@ CrixPlayer::CrixPlayer(Copl *newopl)
 
 CrixPlayer::~CrixPlayer()
 {
-  if(file_buffer)
-    delete [] file_buffer;
+  fclose(fp);
 #if USE_RIX_EXTRA_INIT
   if (extra_regs) delete[] extra_regs;
   if (extra_vals) delete[] extra_vals;
@@ -112,27 +121,36 @@ void CrixPlayer::set_extra_init(uint32_t* regs, uint8_t* datas, int n)
 }
 #endif
 
-bool CrixPlayer::load(const std::string &filename, const CFileProvider &fp)
+bool CrixPlayer::load(const std::string &filename, const CFileProvider &cfp)
 {
-  binistream *f = fp.open(filename); if(!f) return false;
-  uint32_t i=0;
+  fp = fopen(filename.c_str(),"rb"); if(!fp) return false;
 
   if(stricmp(filename.substr(filename.length()-4,4).c_str(),".mkf")==0)
   {
 	  flag_mkf=1;
-	  f->seek(0);
-	  int offset=f->readInt(4);
-	  f->seek(offset);
+	  fseek(fp,0,SEEK_SET);
+      int offset;
+      fread(&offset,4,1,fp);
+	  fseek(fp,RIX_SWAP32(offset),SEEK_SET);
   }
-  if(f->readInt(2)!=0x55aa){ fp.close(f);return false; }
-  file_buffer = new uint8_t [fp.filesize(f) + 1];
-  f->seek(0);
-  while(!f->eof())
-	file_buffer[i++]=f->readInt(1);
-  length=i;
-  fp.close(f);
-  if(!flag_mkf)
-	  rix_buf=file_buffer;
+  uint16_t signature;
+  fread(&signature,2,1,fp);
+  if(RIX_SWAP16(signature)!=0x55aa){ fclose(fp);return false; }
+    if(!flag_mkf)
+    {
+        fseek(fp,0,SEEK_END);
+        length = (uint32_t)ftell(fp);
+        fseek(fp,0,SEEK_SET);
+        fread(rix_buf,length,1,fp);
+        subsongs = 1;
+    }
+    else
+    {
+        fseek(fp,0,SEEK_SET);
+        fread(&subsongs,4,1,fp);
+        subsongs = RIX_SWAP32(subsongs);
+        subsongs/=4;
+    }
   rewind(0);
   return true;
 }
@@ -142,8 +160,11 @@ bool CrixPlayer::update()
 	int_08h_entry();
 	return !play_end;
 }
-
-void CrixPlayer::rewind(int subsong, bool reinit)
+void CrixPlayer::rewind(int subsong)
+{
+    rewindReInit(subsong, true);
+}
+void CrixPlayer::rewindReInit(int subsong, bool reinit)
 {
 	play_end = 0;
 	pos = 0;
@@ -176,11 +197,16 @@ void CrixPlayer::rewind(int subsong, bool reinit)
 
 	if (flag_mkf)
 	{
-		uint32_t *buf_index = (uint32_t *)file_buffer;
-		int offset1 = RIX_SWAP32(buf_index[subsong]), offset2;
-		while ((offset2 = RIX_SWAP32(buf_index[++subsong])) == offset1);
-		length = offset2 - offset1 + 1;
-		rix_buf = file_buffer + offset1;
+        int index,index2;
+        fseek(fp,subsong*4,SEEK_SET);
+        fread(&index,4,1,fp);
+        fread(&index2,4,1,fp);
+        index = RIX_SWAP32(index);
+        index2 = RIX_SWAP32(index2);
+        length = index2 - index;
+        fseek(fp,index,SEEK_SET);
+        memset(rix_buf, 0, sizeof(rix_buf));
+        fread(rix_buf,length,1,fp);
 	}
 
 	if (reinit)
@@ -194,17 +220,7 @@ void CrixPlayer::rewind(int subsong, bool reinit)
 
 unsigned int CrixPlayer::getsubsongs()
 {
-	if(flag_mkf)
-	{
-		uint32_t *buf_index=(uint32_t *)file_buffer;
-		int songs=RIX_SWAP32(buf_index[0])/4,i=0;
-		for(i=0;i<songs;i++)
-			if(buf_index[i+1]==buf_index[i])
-				songs--;
-		return songs;
-	}
-	else
-		return 1;
+    return subsongs;
 }
 
 float CrixPlayer::getrefresh()
@@ -213,13 +229,13 @@ float CrixPlayer::getrefresh()
 }
 
 /*------------------Implemention----------------------------*/
-inline void CrixPlayer::set_new_int()
+RELEASE_INLINE void CrixPlayer::set_new_int()
 {
 //   if(!ad_initial()) exit(1);
   ad_initial();
 }
 /*----------------------------------------------------------*/
-inline void CrixPlayer::Pause()
+RELEASE_INLINE void CrixPlayer::Pause()
 {
   uint16_t i;
   pause_flag = 1;
@@ -227,13 +243,13 @@ inline void CrixPlayer::Pause()
     switch_ad_bd(i);
 }
 /*----------------------------------------------------------*/
-inline void CrixPlayer::ad_a0b0l_reg_(uint16_t index,uint16_t p2,uint16_t p3)
+RELEASE_INLINE void CrixPlayer::ad_a0b0l_reg_(uint16_t index,uint16_t p2,uint16_t p3)
 {
 //   uint16_t i = p2+a0b0_data2[index];
   a0b0_data4[index] = p3;
   a0b0_data3[index] = p2;
 }
-inline void CrixPlayer::data_initial()
+RELEASE_INLINE void CrixPlayer::data_initial()
 {
   rhythm = rix_buf[2];
   mus_block = (rix_buf[0x0D]<<8)+rix_buf[0x0C];
@@ -266,7 +282,7 @@ inline void CrixPlayer::data_initial()
   band = 0; music_on = 1;
 }
 /*----------------------------------------------------------*/
-inline uint16_t CrixPlayer::ad_initial()
+RELEASE_INLINE uint16_t CrixPlayer::ad_initial()
 {
   uint16_t i,j,k = 0;
   for(i=0;i<25;i++) 
@@ -295,14 +311,14 @@ inline uint16_t CrixPlayer::ad_initial()
   return 1;//ad_test();
 }
 /*----------------------------------------------------------*/
-inline void CrixPlayer::ad_bop(uint16_t reg,uint16_t value)
+RELEASE_INLINE void CrixPlayer::ad_bop(uint16_t reg,uint16_t value)
 {
   //if(reg == 2 || reg == 3)
   //  AdPlug_LogWrite("switch OPL2/3 mode!\n");
   opl->write(reg & 0xff, value & 0xff);
 }
 /*--------------------------------------------------------------*/
-inline void CrixPlayer::int_08h_entry()   
+RELEASE_INLINE void CrixPlayer::int_08h_entry()
   {   
     uint16_t band_sus = 1;   
     while(band_sus)   
@@ -325,7 +341,7 @@ inline void CrixPlayer::int_08h_entry()
       }   
   }   
 /*--------------------------------------------------------------*/ 
-inline uint16_t CrixPlayer::rix_proc()
+RELEASE_INLINE uint16_t CrixPlayer::rix_proc()
 {
   uint8_t ctrl = 0;
   if(music_on == 0||pause_flag == 1) return 0;
@@ -352,7 +368,7 @@ inline uint16_t CrixPlayer::rix_proc()
   return 0;
 }
 /*--------------------------------------------------------------*/
-inline void CrixPlayer::rix_get_ins()
+RELEASE_INLINE void CrixPlayer::rix_get_ins()
 {
   int		i;
   uint8_t	*baddr = (&rix_buf[ins_block])+(band_low<<6);
@@ -361,7 +377,7 @@ inline void CrixPlayer::rix_get_ins()
     insbuf[i] = (baddr[i * 2 + 1] << 8) + baddr[i * 2];
 }
 /*--------------------------------------------------------------*/
-inline void CrixPlayer::rix_90_pro(uint16_t ctrl_l)
+RELEASE_INLINE void CrixPlayer::rix_90_pro(uint16_t ctrl_l)
 {
   if(rhythm == 0 || ctrl_l < 6)
     {
@@ -382,7 +398,7 @@ inline void CrixPlayer::rix_90_pro(uint16_t ctrl_l)
 		}
 }
 /*--------------------------------------------------------------*/
-inline void CrixPlayer::rix_A0_pro(uint16_t ctrl_l,uint16_t index)
+RELEASE_INLINE void CrixPlayer::rix_A0_pro(uint16_t ctrl_l,uint16_t index)
 {
   if(rhythm == 0 || ctrl_l <= 6)
     {
@@ -392,7 +408,7 @@ inline void CrixPlayer::rix_A0_pro(uint16_t ctrl_l,uint16_t index)
   else return;
 }
 /*--------------------------------------------------------------*/
-inline void CrixPlayer::prepare_a0b0(uint16_t index,uint16_t v)  /* important !*/
+RELEASE_INLINE void CrixPlayer::prepare_a0b0(uint16_t index,uint16_t v)  /* important !*/
 {
   short high = 0,low = 0; uint32_t res;
   int res1 = (v-0x2000)*0x19;
@@ -422,7 +438,7 @@ inline void CrixPlayer::prepare_a0b0(uint16_t index,uint16_t v)  /* important !*
   displace[index] = low;
 }
 /*--------------------------------------------------------------*/
-inline void CrixPlayer::ad_a0b0l_reg(uint16_t index,uint16_t p2,uint16_t p3)
+RELEASE_INLINE void CrixPlayer::ad_a0b0l_reg(uint16_t index,uint16_t p2,uint16_t p3)
 {
   uint16_t data; uint16_t i = p2+a0b0_data2[index];
   a0b0_data4[index] = p3;
@@ -435,7 +451,7 @@ inline void CrixPlayer::ad_a0b0l_reg(uint16_t index,uint16_t p2,uint16_t p3)
   ad_bop(0xB0+index,data);
 }
 /*--------------------------------------------------------------*/
-inline void CrixPlayer::rix_B0_pro(uint16_t ctrl_l,uint16_t index)
+RELEASE_INLINE void CrixPlayer::rix_B0_pro(uint16_t ctrl_l,uint16_t index)
 {
   int temp = 0;
   if(rhythm == 0 || ctrl_l < 6) temp = modify[ctrl_l*2+1];
@@ -448,7 +464,7 @@ inline void CrixPlayer::rix_B0_pro(uint16_t ctrl_l,uint16_t index)
   ad_40_reg(temp);
 }
 /*--------------------------------------------------------------*/
-inline void CrixPlayer::rix_C0_pro(uint16_t ctrl_l,uint16_t index)
+RELEASE_INLINE void CrixPlayer::rix_C0_pro(uint16_t ctrl_l,uint16_t index)
 {
   uint16_t i = index>=12?index-12:0;
   if(ctrl_l < 6 || rhythm == 0)
@@ -473,7 +489,7 @@ inline void CrixPlayer::rix_C0_pro(uint16_t ctrl_l,uint16_t index)
     }
 }
 /*--------------------------------------------------------------*/
-inline void CrixPlayer::switch_ad_bd(uint16_t index)
+RELEASE_INLINE void CrixPlayer::switch_ad_bd(uint16_t index)
 {
 
   if(rhythm == 0 || index < 6) ad_a0b0l_reg(index,a0b0_data3[index],0);
@@ -484,7 +500,7 @@ inline void CrixPlayer::switch_ad_bd(uint16_t index)
     }
 }
 /*--------------------------------------------------------------*/
-inline void CrixPlayer::ins_to_reg(uint16_t index,uint16_t* insb,uint16_t value)
+RELEASE_INLINE void CrixPlayer::ins_to_reg(uint16_t index,uint16_t* insb,uint16_t value)
 {
   uint16_t i;
   for(i=0;i<13;i++) reg_bufs[index].v[i] = insb[i];
@@ -494,13 +510,13 @@ inline void CrixPlayer::ins_to_reg(uint16_t index,uint16_t* insb,uint16_t value)
     ad_80_reg(index),ad_20_reg(index),ad_E0_reg(index);
 }
 /*--------------------------------------------------------------*/
-inline void CrixPlayer::ad_E0_reg(uint16_t index)
+RELEASE_INLINE void CrixPlayer::ad_E0_reg(uint16_t index)
 {
   uint16_t data = e0_reg_flag == 0?0:(reg_bufs[index].v[13]&3);
   ad_bop(0xE0+reg_data[index],data);
 }
 /*--------------------------------------------------------------*/
-inline void CrixPlayer::ad_20_reg(uint16_t index)
+RELEASE_INLINE void CrixPlayer::ad_20_reg(uint16_t index)
 {
   uint16_t data = (reg_bufs[index].v[9] < 1?0:0x80);
   data += (reg_bufs[index].v[10] < 1?0:0x40);
@@ -510,21 +526,21 @@ inline void CrixPlayer::ad_20_reg(uint16_t index)
   ad_bop(0x20+reg_data[index],data);
 }
 /*--------------------------------------------------------------*/
-inline void CrixPlayer::ad_80_reg(uint16_t index)
+RELEASE_INLINE void CrixPlayer::ad_80_reg(uint16_t index)
 {
   uint16_t data = (reg_bufs[index].v[7]&0x0F),temp = reg_bufs[index].v[4];
   data |= (temp << 4);
   ad_bop(0x80+reg_data[index],data);
 }
 /*--------------------------------------------------------------*/
-inline void CrixPlayer::ad_60_reg(uint16_t index)
+void CrixPlayer::ad_60_reg(uint16_t index)
 {
   uint16_t data = reg_bufs[index].v[6]&0x0F,temp = reg_bufs[index].v[3];
   data |= (temp << 4);
   ad_bop(0x60+reg_data[index],data);
 }
 /*--------------------------------------------------------------*/
-inline void CrixPlayer::ad_C0_reg(uint16_t index)
+RELEASE_INLINE void CrixPlayer::ad_C0_reg(uint16_t index)
 {
   uint16_t data = reg_bufs[index].v[2];
   if(adflag[index] == 1) return;
@@ -533,7 +549,7 @@ inline void CrixPlayer::ad_C0_reg(uint16_t index)
   ad_bop(0xC0+ad_C0_offs[index],data);
 }
 /*--------------------------------------------------------------*/
-inline void CrixPlayer::ad_40_reg(uint16_t index)
+RELEASE_INLINE void CrixPlayer::ad_40_reg(uint16_t index)
 {
   uint32_t res = 0;
   uint16_t data = 0,temp = reg_bufs[index].v[0];
@@ -549,20 +565,20 @@ inline void CrixPlayer::ad_40_reg(uint16_t index)
   ad_bop(0x40+reg_data[index],data);
 }
 /*--------------------------------------------------------------*/
-inline void CrixPlayer::ad_bd_reg()
+RELEASE_INLINE void CrixPlayer::ad_bd_reg()
 {
   uint16_t data = rhythm < 1? 0:0x20;
   data |= bd_modify;
   ad_bop(0xBD,data);
 }
 /*--------------------------------------------------------------*/
-inline void CrixPlayer::ad_a0b0_reg(uint16_t index)
+RELEASE_INLINE void CrixPlayer::ad_a0b0_reg(uint16_t index)
 {
   ad_bop(0xA0+index,0);
   ad_bop(0xB0+index,0);
 }
 /*--------------------------------------------------------------*/
-inline void CrixPlayer::music_ctrl()
+RELEASE_INLINE void CrixPlayer::music_ctrl()
 {
   int i;
   for(i=0;i<11;i++)

+ 34 - 33
adplug/rix.h

@@ -41,8 +41,8 @@ class CrixPlayer: public CPlayer
 
   bool load(const std::string &filename, const CFileProvider &fp);
   bool update();
-  void rewind(int subsong) { rewind(subsong, true); }
-  void rewind(int subsong, bool reinit); /* For seamless continous */
+  void rewind(int subsong);
+  void rewindReInit(int subsong, bool reinit); /* For seamless continous */
   float getrefresh();
   unsigned int getsubsongs();
 
@@ -63,8 +63,9 @@ class CrixPlayer: public CPlayer
   uint32_t *extra_regs;
   uint8_t *extra_vals;
 #endif
-  uint8_t *file_buffer;
-  uint8_t *rix_buf;  /* rix files' f_buffer */
+  FILE *fp;
+  int subsongs;
+  uint8_t rix_buf[16384];  /* rix files' f_buffer */
   uint16_t f_buffer[300];//9C0h-C18h
   uint16_t a0b0_data2[11];
   uint8_t a0b0_data3[18];
@@ -100,33 +101,33 @@ class CrixPlayer: public CPlayer
   int play_end;
 
 #define ad_08_reg() ad_bop(8,0)    /**/
-  inline void ad_20_reg(uint16_t);              /**/
-  inline void ad_40_reg(uint16_t);              /**/
-  inline void ad_60_reg(uint16_t);              /**/
-  inline void ad_80_reg(uint16_t);              /**/
-  inline void ad_a0b0_reg(uint16_t);            /**/
-  inline void ad_a0b0l_reg(uint16_t,uint16_t,uint16_t); /**/
-  inline void ad_a0b0l_reg_(uint16_t,uint16_t,uint16_t); /**/
-  inline void ad_bd_reg();                  /**/
-  inline void ad_bop(uint16_t,uint16_t);                     /**/
-  inline void ad_C0_reg(uint16_t);              /**/
-  inline void ad_E0_reg(uint16_t);              /**/
-  inline uint16_t ad_initial();                 /**/
-  inline uint16_t ad_test();                    /**/
-  inline void crc_trans(uint16_t,uint16_t);         /**/
-  inline void data_initial();               /* done */
-  inline void init();                       /**/
-  inline void ins_to_reg(uint16_t,uint16_t*,uint16_t);  /**/
-  inline void int_08h_entry();    /**/
-  inline void music_ctrl();                 /**/
-  inline void Pause();                      /**/
-  inline void prepare_a0b0(uint16_t,uint16_t);      /**/
-  inline void rix_90_pro(uint16_t);             /**/
-  inline void rix_A0_pro(uint16_t,uint16_t);        /**/
-  inline void rix_B0_pro(uint16_t,uint16_t);        /**/
-  inline void rix_C0_pro(uint16_t,uint16_t);        /**/
-  inline void rix_get_ins();                /**/
-  inline uint16_t rix_proc();                   /**/
-  inline void set_new_int();
-  inline void switch_ad_bd(uint16_t);           /**/
+  void ad_20_reg(uint16_t);              /**/
+  void ad_40_reg(uint16_t);              /**/
+  void ad_60_reg(uint16_t);              /**/
+  void ad_80_reg(uint16_t);              /**/
+  void ad_a0b0_reg(uint16_t);            /**/
+  void ad_a0b0l_reg(uint16_t,uint16_t,uint16_t); /**/
+  void ad_a0b0l_reg_(uint16_t,uint16_t,uint16_t); /**/
+  void ad_bd_reg();                  /**/
+  void ad_bop(uint16_t,uint16_t);                     /**/
+  void ad_C0_reg(uint16_t);              /**/
+  void ad_E0_reg(uint16_t);              /**/
+  uint16_t ad_initial();                 /**/
+  uint16_t ad_test();                    /**/
+  void crc_trans(uint16_t,uint16_t);         /**/
+  void data_initial();               /* done */
+  void init();                       /**/
+  void ins_to_reg(uint16_t,uint16_t*,uint16_t);  /**/
+  void int_08h_entry();    /**/
+  void music_ctrl();                 /**/
+  void Pause();                      /**/
+  void prepare_a0b0(uint16_t,uint16_t);      /**/
+  void rix_90_pro(uint16_t);             /**/
+  void rix_A0_pro(uint16_t,uint16_t);        /**/
+  void rix_B0_pro(uint16_t,uint16_t);        /**/
+  void rix_C0_pro(uint16_t,uint16_t);        /**/
+  void rix_get_ins();                /**/
+  uint16_t rix_proc();                   /**/
+  void set_new_int();
+  void switch_ad_bd(uint16_t);           /**/
 };

+ 1 - 5
audio.c

@@ -31,10 +31,6 @@
 #include "aviplay.h"
 #include <math.h>
 
-#if PAL_HAS_OGG
-#include <vorbis/codec.h>
-#endif
-
 #define PAL_CDTRACK_BASE    10000
 
 typedef void(*ResampleMixFunction)(void *, const void *, int, void *, int, int, uint8_t);
@@ -207,7 +203,7 @@ AUDIO_OpenDevice(
       //
       return -1;
    }
-#ifdef __EMSCRIPTEN__ // Now either music/sound enabled will makes whole app crash in emscripten. Disabled until a solution is found.
+#if defined( __EMSCRIPTEN__ ) // Now either music/sound enabled will makes whole app crash in emscripten. Disabled until a solution is found.
    return -1;
 #endif
 

+ 1 - 1
common.h

@@ -138,7 +138,7 @@ typedef unsigned char       UCHAR, *PUCHAR;
 typedef unsigned short      WORD, *LPWORD;
 typedef unsigned int        DWORD, *LPDWORD;
 typedef int                 INT, *LPINT;
-# ifndef __APPLE__
+# if !defined( __APPLE__ ) && !defined( GEKKO )
 typedef int                 BOOL, *LPBOOL;
 # endif
 typedef unsigned int        UINT, *PUINT, UINT32, *PUINT32;

+ 1 - 1
emscripten/Makefile

@@ -17,7 +17,7 @@ DEPFILES = $(OBJFILES:.o=.d)
 
 CFLAGS = -I${EMSCRIPTEN_TOOLCHAIN}/include/SDL2 -g -Wall -Oz -fno-strict-aliasing -I. -I../ -I../liboggvorbis/include -I../liboggvorbis/src -DPAL_HAS_PLATFORM_SPECIFIC_UTILS $(DEPFLAGS) 
 CPPFLAGS = $(CFLAGS)
-override LDFLAGS += -Oz -L${EMSCRIPTEN_TOOLCHAIN}/lib -lSDL2 -lm -lstdc++ --preload-file data -s TOTAL_MEMORY=134217728 -s TOTAL_STACK=5242880 --emrun -s DEMANGLE_SUPPORT=1 -s EMTERPRETIFY=1 -s EMTERPRETIFY_ASYNC=1 -s 'EMTERPRETIFY_FILE="sdlpal.bc"' -s WASM=1
+override LDFLAGS += -Oz -L${EMSCRIPTEN_TOOLCHAIN}/lib -lSDL2 -lm -lstdc++ --preload-file data -s TOTAL_MEMORY=134217728 -s TOTAL_STACK=5242880 --emrun -s DEMANGLE_SUPPORT=1 -s EMTERPRETIFY=1 -s EMTERPRETIFY_ASYNC=1 -s 'EMTERPRETIFY_FILE="sdlpal.bc"' -s WASM=1 -s NO_EXIT_RUNTIME=1
 
 POSTCOMPILE = @mv -f $*$(INTER).Td $*$(INTER).d && touch $@
 

+ 26 - 19
global.c

@@ -587,7 +587,7 @@ PAL_LoadGame_Common(
 	//
 	// Adjust endianness
 	//
-	DO_BYTESWAP(&s, size);
+	DO_BYTESWAP(s, size);
 
 	//
 	// Cash amount is in DWORD, so do a wordswap in Big-Endian.
@@ -657,13 +657,13 @@ PAL_LoadGame_DOS(
 
 --*/
 {
-   PAL_LARGE SAVEDGAME_DOS   s;
+   SAVEDGAME_DOS   *s = (SAVEDGAME_DOS*)malloc(sizeof(SAVEDGAME_DOS));
    int                       i;
 
    //
    // Get all the data from the saved game struct.
    //
-   if (!PAL_LoadGame_Common(iSaveSlot, (LPSAVEDGAME_COMMON)&s, sizeof(SAVEDGAME_DOS)))
+   if (!PAL_LoadGame_Common(iSaveSlot, (LPSAVEDGAME_COMMON)s, sizeof(SAVEDGAME_DOS)))
 	   return -1;
 
    //
@@ -671,11 +671,13 @@ PAL_LoadGame_DOS(
    //
    for (i = 0; i < MAX_OBJECTS; i++)
    {
-      memcpy(&gpGlobals->g.rgObject[i], &s.rgObject[i], sizeof(OBJECT_DOS));
-      gpGlobals->g.rgObject[i].rgwData[6] = s.rgObject[i].rgwData[5];     // wFlags
+      memcpy(&gpGlobals->g.rgObject[i], &s->rgObject[i], sizeof(OBJECT_DOS));
+      gpGlobals->g.rgObject[i].rgwData[6] = s->rgObject[i].rgwData[5];     // wFlags
       gpGlobals->g.rgObject[i].rgwData[5] = 0;                            // wScriptDesc or wReserved2
    }
-   memcpy(gpGlobals->g.lprgEventObject, s.rgEventObject, sizeof(EVENTOBJECT) * gpGlobals->g.nEventObject);
+   memcpy(gpGlobals->g.lprgEventObject, s->rgEventObject, sizeof(EVENTOBJECT) * gpGlobals->g.nEventObject);
+
+   free(s);
 
    //
    // Success
@@ -702,16 +704,18 @@ PAL_LoadGame_WIN(
 
 --*/
 {
-   PAL_LARGE SAVEDGAME_WIN   s;
+   SAVEDGAME_WIN   *s = (SAVEDGAME_WIN*)malloc(sizeof(SAVEDGAME_WIN));
 
    //
    // Get all the data from the saved game struct.
    //
-   if (!PAL_LoadGame_Common(iSaveSlot, (LPSAVEDGAME_COMMON)&s, sizeof(SAVEDGAME_WIN)))
+   if (!PAL_LoadGame_Common(iSaveSlot, (LPSAVEDGAME_COMMON)s, sizeof(SAVEDGAME_WIN)))
 	   return -1;
 
-   memcpy(gpGlobals->g.rgObject, s.rgObject, sizeof(gpGlobals->g.rgObject));
-   memcpy(gpGlobals->g.lprgEventObject, s.rgEventObject, sizeof(EVENTOBJECT) * gpGlobals->g.nEventObject);
+   memcpy(gpGlobals->g.rgObject, s->rgObject, sizeof(gpGlobals->g.rgObject));
+   memcpy(gpGlobals->g.lprgEventObject, s->rgEventObject, sizeof(EVENTOBJECT) * gpGlobals->g.nEventObject);
+    
+   free(s);
 
    //
    // Success
@@ -772,7 +776,7 @@ PAL_SaveGame_Common(
 	//
 	// Adjust endianness
 	//
-	DO_BYTESWAP(&s, size);
+	DO_BYTESWAP(s, size);
 
 	//
 	// Cash amount is in DWORD, so do a wordswap in Big-Endian.
@@ -816,7 +820,7 @@ PAL_SaveGame_DOS(
 
 --*/
 {
-   PAL_LARGE SAVEDGAME_DOS   s;
+   SAVEDGAME_DOS   *s = (SAVEDGAME_DOS*)malloc(sizeof(SAVEDGAME_DOS));
    UINT32                    i;
 
    //
@@ -824,15 +828,16 @@ PAL_SaveGame_DOS(
    //
    for (i = 0; i < MAX_OBJECTS; i++)
    {
-      memcpy(&s.rgObject[i], &gpGlobals->g.rgObject[i], sizeof(OBJECT_DOS));
-      s.rgObject[i].rgwData[5] = gpGlobals->g.rgObject[i].rgwData[6];     // wFlags
+      memcpy(&s->rgObject[i], &gpGlobals->g.rgObject[i], sizeof(OBJECT_DOS));
+      s->rgObject[i].rgwData[5] = gpGlobals->g.rgObject[i].rgwData[6];     // wFlags
    }
-   memcpy(s.rgEventObject, gpGlobals->g.lprgEventObject, sizeof(EVENTOBJECT) * gpGlobals->g.nEventObject);
+   memcpy(s->rgEventObject, gpGlobals->g.lprgEventObject, sizeof(EVENTOBJECT) * gpGlobals->g.nEventObject);
 
    //
    // Put all the data to the saved game struct.
    //
-   PAL_SaveGame_Common(iSaveSlot, wSavedTimes, (LPSAVEDGAME_COMMON)&s, sizeof(SAVEDGAME_DOS));
+   PAL_SaveGame_Common(iSaveSlot, wSavedTimes, (LPSAVEDGAME_COMMON)s, sizeof(SAVEDGAME_DOS));
+   free(s);
 }
 
 static VOID
@@ -855,15 +860,17 @@ PAL_SaveGame_WIN(
 
 --*/
 {
-   PAL_LARGE SAVEDGAME_WIN   s;
+   SAVEDGAME_WIN   *s = (SAVEDGAME_WIN*)malloc(sizeof(SAVEDGAME_WIN));
 
    //
    // Put all the data to the saved game struct.
    //
-   memcpy(s.rgObject, gpGlobals->g.rgObject, sizeof(gpGlobals->g.rgObject));
-   memcpy(s.rgEventObject, gpGlobals->g.lprgEventObject, sizeof(EVENTOBJECT) * gpGlobals->g.nEventObject);
+   memcpy(&s->rgObject, gpGlobals->g.rgObject, sizeof(gpGlobals->g.rgObject));
+   memcpy(&s->rgEventObject, gpGlobals->g.lprgEventObject, sizeof(EVENTOBJECT) * gpGlobals->g.nEventObject);
 
    PAL_SaveGame_Common(iSaveSlot, wSavedTimes, (LPSAVEDGAME_COMMON)&s, sizeof(SAVEDGAME_WIN));
+
+   free(s);
 }
 
 VOID

+ 1 - 1
input.c

@@ -1115,7 +1115,7 @@ PAL_ProcessEvent(
    while (PAL_PollEvent(NULL));
 
    PAL_UpdateKeyboardState();
-#ifdef PAL_HAS_TOUCH
+#if PAL_HAS_TOUCH
    PAL_TouchRepeatCheck();
 #endif
 }

+ 1 - 1
liboggvorbis/include/ogg/config_types.h

@@ -2,7 +2,7 @@
 #ifndef _CONFIG_TYPES_H
 #define _CONFIG_TYPES_H
 
-#if defined(__ANDROID__) || defined(__IOS__) || defined(__linux__) || defined(__EMSCRIPTEN__)
+#if defined(__ANDROID__) || defined(__IOS__) || defined(__linux__) || defined(__EMSCRIPTEN__) || defined(GEKKO)
 
 /* Android or iOS compiler */
 #	include <stdint.h>

+ 1 - 0
macos/pal_config.h

@@ -62,5 +62,6 @@
 #define PAL_FILESYSTEM_IGNORE_CASE 1
 
 #define PAL_HAS_PLATFORM_SPECIFIC_UTILS 1
+#define PAL_HAS_PLATFORM_STARTUP        1
 
 #endif

+ 19 - 0
macos/util.mm

@@ -24,6 +24,25 @@ static void LogCallBack(LOGLEVEL, const char* str, const char*)
     NSLog(@"%s",str);
 }
 
+INT UTIL_Platform_Startup(
+	int argc,
+	char* argv[]
+)
+{
+#if !defined(DEBUG) //for ease of debugging(specify resource dir in xcode scheme)
+    char *p = strstr(argv[0], "/Pal.app/");
+    
+    if (p != NULL)
+    {
+        char buf[4096];
+        strcpy(buf, argv[0]);
+        buf[p - argv[0]] = '\0';
+        chdir(buf);
+    }
+#endif
+    return 0;
+}
+
 INT
 UTIL_Platform_Init(
                    int argc,

+ 2 - 10
main.c

@@ -455,16 +455,8 @@ main(
 
 --*/
 {
-#if defined(__APPLE__) && !defined(__IOS__) && !defined(DEBUG) //for ease of debugging(specify resource dir in xcode scheme)
-   char *p = strstr(argv[0], "/Pal.app/");
-
-   if (p != NULL)
-   {
-      char buf[4096];
-      strcpy(buf, argv[0]);
-      buf[p - argv[0]] = '\0';
-      chdir(buf);
-   }
+#if PAL_HAS_PLATFORM_STARTUP
+   UTIL_Platform_Startup(argc,argv);
 #endif
 
    if (setjmp(g_exit_jmp_buf) != 0)

+ 1 - 1
rixplay.cpp

@@ -190,7 +190,7 @@ RIX_FillBuffer(
 						}
 						return;
 					}
-					pRixPlayer->rix->rewind(pRixPlayer->iCurrentMusic, false);
+					pRixPlayer->rix->rewindReInit(pRixPlayer->iCurrentMusic, false);
 					if (!pRixPlayer->rix->update())
 					{
 						//

+ 0 - 4
sound.c

@@ -31,10 +31,6 @@
 #include "riff.h"
 #include <math.h>
 
-#if PAL_HAS_OGG
-#include <vorbis/codec.h>
-#endif
-
 #define PAL_CDTRACK_BASE    10000
 
 typedef struct tagWAVESPEC

+ 6 - 0
util.h

@@ -223,6 +223,12 @@ UTIL_IsAbsolutePath(
 	const char *lpszFileName
 );
 
+int
+UTIL_Platform_Startup(
+	int   argc,
+	char *argv[]
+);
+
 int
 UTIL_Platform_Init(
 	int   argc,

+ 1 - 1
video.c

@@ -794,7 +794,7 @@ VIDEO_SaveScreenshot(
 	SYSTEMTIME st;
 	GetLocalTime(&st);
 	sprintf(filename, "%04d%02d%02d%02d%02d%02d%03d.bmp", st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond, st.wMilliseconds);
-#else
+#elif !defined( GEKKO )
 	struct timeval tv;
 	struct tm *ptm;
 	gettimeofday(&tv, NULL);

+ 1 - 0
wii/.gdbinit

@@ -0,0 +1 @@
+target remote wii.home.net:5656

+ 67 - 0
wii/Makefile

@@ -0,0 +1,67 @@
+TARGET = boot.dol
+
+INTER=.wii
+
+HOST = powerpc-eabi-
+
+DEPFLAGS = -MT $@ -MMD -MP -MF $*$(INTER).Td
+
+SOURCES = . .. ../adplug ../liboggvorbis/src ../libmad
+CFILES = $(foreach dir, $(SOURCES), $(wildcard $(dir)/*.c)) 
+CPPFILES = $(foreach dir, $(SOURCES), $(wildcard $(dir)/*.cpp))
+OFILES = $(CFILES:.c=$(INTER).o) $(CPPFILES:.cpp=$(INTER).o)
+DEPFILES = $(OFILES:.o=.d) 
+
+CCFLAGS = $(DFALG) -g -Wall -O2 -DGEKKO -D__POWERPC__ -D__ppc__ -DPAL_HAS_PLATFORM_SPECIFIC_UTILS -I. -I../ -I../liboggvorbis/include -I../liboggvorbis/src $(DEPFLAGS) -I$(DEVKITPRO)/libogc/include -I$(DEVKITPRO)/libogc/include/ogc -I$(DEVKITPRO)/libogc/include/SDL 
+CXXFLAGS = $(CCFLAGS) -std=c++11
+CFLAGS = $(CCFLAGS) -std=gnu99
+LDFLAGS = -L$(DEVKITPRO)/libogc/lib/wii -lSDL -lfat -lwiiuse -lbte -logc -lm -lwiikeyboard -lg -mrvl
+
+ifeq ($(DEBUG),1)
+	CCFLAGS += -DDEBUG -I$(DEVKITPRO)/wii_dev_debug/net_print/sockettest/source
+	LDFLAGS += -ldb
+	OFILES += $(DEVKITPRO)/wii_dev_debug/net_print/sockettest/build/net_print.o
+endif
+
+POSTCOMPILE = @mv -f $*$(INTER).Td $*$(INTER).d && touch $@
+
+.PHONY : all clean check
+
+all: $(TARGET)
+
+debug:
+	$(MAKE) debug-clean
+	$(MAKE) "DEBUG=1" -C .
+
+debug-clean:
+	-@rm pal_utils.wii.*
+
+test: $(TARGET).elf
+	wiiload $<
+
+$(TARGET).elf: $(OFILES)
+	@echo [LD] $@
+	@$(HOST)g++ $(OFILES) -o $@ $(LDFLAGS)
+
+$(TARGET): $(TARGET).elf
+	@echo [elf2dol] $@
+	@elf2dol $< $(TARGET)
+
+%$(INTER).o: %.c %$(INTER).d
+	@echo [CC] $<
+	@$(HOST)gcc $(CFLAGS) -c $< -o $@
+	$(POSTCOMPILE)
+
+%$(INTER).o: %.cpp %$(INTER).d
+	@echo [CC] $<
+	@$(HOST)g++ $(CXXFLAGS) -c $< -o $@
+	$(POSTCOMPILE)
+
+clean:
+	-rm -f $(TARGET).elf $(TARGET) $(OFILES) $(DEPFILES)
+
+%.d: ;
+.PRECIOUS: %.d
+
+-include $(DEPFILES)
+

+ 3 - 0
wii/README.txt

@@ -0,0 +1,3 @@
+Wii port uses SDL-wii, which has only 1.2 version.
+Build environment: DevKitPPC
+Debug requirement: wii_dev_debug

BIN
wii/icon.png


+ 379 - 0
wii/libc.c

@@ -0,0 +1,379 @@
+/*
+
+  This file is distributed under the GNU Public License, version 2 or at
+  your option any later version. Read the file gpl.txt for details.
+
+  scandir/access function for wii.
+*/
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+
+#ifdef GEKKO
+#include <errno.h>
+#include <dirent.h>
+
+int access(const char *pathname, int mode) {
+	struct stat sb;
+
+	if (stat(pathname, &sb) == -1) {
+		return -1;
+	}
+
+	return 0;
+}
+
+int alphasort(const void *d1, const void *d2)
+{
+	return strcmp((*(struct dirent * const *)d1)->d_name,
+		      (*(struct dirent * const *)d2)->d_name);
+}
+
+int scandir(const char *dirp, struct dirent ***namelist,
+            int (*filter)(struct dirent *),
+            int (*compar)(const void *, const void *))
+{
+
+    DIR *dp = opendir (dirp);
+    struct dirent *current;
+    struct dirent **names = NULL;
+    size_t names_size = 0, pos;
+
+    if (dp == NULL)
+        return -1;
+
+    errno = 0;
+
+    pos = 0;
+    while ((current = readdir (dp)) != NULL)
+        if (filter == NULL || (*filter) (current))
+        {
+            struct dirent *vnew;
+            size_t dsize;
+
+            if (pos == names_size)
+            {
+                struct dirent **new;
+                if (names_size == 0)
+                    names_size = 10;
+                else
+                    names_size *= 2;
+                new = (struct dirent **) realloc (names, names_size * sizeof (struct dirent *));
+                if (new == NULL)
+                    break;
+                names = new;
+            }
+
+            dsize = &current->d_name[strlen(current->d_name)+1] - (char *) current;
+            vnew = (struct dirent *) malloc (dsize);
+            if (vnew == NULL)
+                break;
+
+            names[pos++] = (struct dirent *) memcpy (vnew, current, dsize);
+        }
+
+    if (errno != 0)
+    {
+        closedir (dp);
+        while (pos > 0)
+            free (names[--pos]);
+        free (names);
+
+        return -1;
+    }
+
+    closedir (dp);
+
+
+    /* Sort the list if we have a comparison function to sort with.  */
+    if (compar != NULL)
+        qsort (names, pos, sizeof (struct dirent *), compar);
+    *namelist = names;
+    return pos;
+}
+
+
+#endif
+
+/*-----------------------------------------------------------------------
+ * Here come alphasort and scandir for BeOS and SunOS
+ *-----------------------------------------------------------------------*/
+#if defined(__BEOS__) || (defined(__sun) && defined(__SVR4))
+
+#undef DIRSIZ
+
+#define DIRSIZ(dp)                                          \
+		((sizeof(struct dirent) - sizeof(dp)->d_name) +     \
+		(((dp)->d_reclen + 1 + 3) &~ 3))
+
+#if (defined(__sun) && defined(__SVR4)) || defined(__CEGCC__)
+# define dirfd(d) ((d)->dd_fd)
+#elif defined(__BEOS__)
+# define dirfd(d) ((d)->fd)
+#endif
+
+
+/*-----------------------------------------------------------------------*/
+/**
+ * Alphabetic order comparison routine.
+ */
+int alphasort(const void *d1, const void *d2)
+{
+	return strcmp((*(struct dirent * const *)d1)->d_name, (*(struct dirent * const *)d2)->d_name);
+}
+
+
+/*-----------------------------------------------------------------------*/
+/**
+ * Scan a directory for all its entries
+ * Return -1 on error, number of entries on success
+ */
+int scandir(const char *dirname, struct dirent ***namelist, int (*sdfilter)(struct dirent *), int (*dcomp)(const void *, const void *))
+{
+	struct dirent *d, *p = NULL, **names = NULL;
+	struct stat stb;
+	size_t nitems = 0;
+	size_t arraysz;
+	DIR *dirp;
+
+	if ((dirp = opendir(dirname)) == NULL)
+		goto error_out;
+
+	if (fstat(dirfd(dirp), &stb) < 0)
+		goto error_out;
+
+	/*
+	 * estimate the array size by taking the size of the directory file
+	 * and dividing it by a multiple of the minimum size entry.
+	 */
+	arraysz = (stb.st_size / 24);
+
+	names = (struct dirent **)malloc(arraysz * sizeof(struct dirent *));
+	if (names == NULL)
+		goto error_out;
+
+	while ((d = readdir(dirp)) != NULL)
+	{
+
+		if (sdfilter != NULL && !(*sdfilter)(d))
+			continue;       /* just selected names */
+
+		/*
+		 * Make a minimum size copy of the data
+		 */
+
+		p = (struct dirent *)malloc(DIRSIZ(d));
+		if (p == NULL)
+			goto error_out;
+
+		p->d_ino = d->d_ino;
+		p->d_reclen = d->d_reclen;
+		/*p->d_namlen = d->d_namlen;*/
+		memcpy(p->d_name, d->d_name, p->d_reclen + 1);
+
+		/*
+		 * Check to make sure the array has space left and
+		 * realloc the maximum size.
+		 */
+
+		if ((nitems+1) >= arraysz)
+		{
+			struct dirent **tmp;
+			
+			if (fstat(dirfd(dirp), &stb) < 0)
+				goto error_out;   /* just might have grown */
+
+			arraysz = stb.st_size / 12;
+
+			tmp = (struct dirent **)realloc((char *)names, arraysz * sizeof(struct dirent *));
+			if (tmp == NULL)
+				goto error_out;
+			names = tmp;
+		}
+
+		names[nitems++] = p;
+		p = NULL;
+	}
+
+	closedir(dirp);
+
+	if (nitems && dcomp != NULL)
+		qsort(names, nitems, sizeof(struct dirent *), dcomp);
+
+	*namelist = names;
+
+	return nitems;
+
+error_out:
+	if (names)
+	{
+		int i;
+		for (i = 0; i < nitems; i++)
+			free(names[i]);
+		free(names);
+	}
+	if (dirp)
+		closedir(dirp);
+	return -1;
+}
+
+
+#endif /* __BEOS__ || __sun */
+
+
+/*-----------------------------------------------------------------------
+ * Here come alphasort and scandir for Windows
+ *-----------------------------------------------------------------------*/
+#if defined(WIN32) || defined(__CEGCC__)
+
+#include <windows.h>
+#include <wchar.h>
+
+/*-----------------------------------------------------------------------*/
+/**
+ * Alphabetic order comparison routine.
+ */
+int alphasort(const void *d1, const void *d2)
+{
+	return stricmp((*(struct dirent * const *)d1)->d_name, (*(struct dirent * const *)d2)->d_name);
+}
+
+/*-----------------------------------------------------------------------*/
+/**
+ * Scan a directory for all its entries
+ */
+int scandir(const char *dirname, struct dirent ***namelist, int (*sdfilter)(struct dirent *), int (*dcomp)(const void *, const void *))
+{
+	int len;
+	char *findIn, *d;
+	WIN32_FIND_DATA find;
+	HANDLE h;
+	int nDir = 0, NDir = 0;
+	struct dirent **dir = 0, *selectDir;
+	unsigned long ret;
+
+	len    = strlen(dirname);
+	findIn = (char *)malloc(len+5);
+	if (!findIn)
+		return -1;
+
+	strcpy(findIn, dirname);
+	Log_Printf(LOG_DEBUG, "scandir : findIn orign='%s'\n", findIn);
+
+	for (d = findIn; *d; d++)
+		if (*d=='/')
+			*d='\\';
+	if ((len==0))
+	{
+		strcpy(findIn, ".\\*");
+	}
+	if ((len==1)&& (d[-1]=='.'))
+	{
+		strcpy(findIn, ".\\*");
+	}
+	if ((len>0) && (d[-1]=='\\'))
+	{
+		*d++ = '*';
+		*d = 0;
+	}
+	if ((len>1) && (d[-1]=='.') && (d[-2]=='\\'))
+	{
+		d[-1] = '*';
+	}
+	if ((len>1) && !(d[-2]=='\\' && d[-1]=='*') )
+	{
+		*d++ = '\\';
+		*d++ = '*';
+		*d = 0;
+	}
+
+	Log_Printf(LOG_DEBUG, "scandir : findIn processed='%s'\n", findIn);
+
+#if defined(__CEGCC__)
+	void *findInW = NULL;
+	findInW = malloc((len+6)*2);
+	if (!findInW)
+		return -1;
+	mbstowcs(findInW, findIn, len+6);
+	h = FindFirstFileW(findInW, &find);
+#else
+	h = FindFirstFile(findIn, &find);
+#endif
+
+	if (h == INVALID_HANDLE_VALUE)
+	{
+		Log_Printf(LOG_DEBUG, "scandir : FindFirstFile error\n");
+		ret = GetLastError();
+		if (ret != ERROR_NO_MORE_FILES)
+		{
+			// TODO: return some error code
+		}
+		*namelist = dir;
+		return nDir;
+	}
+
+	do
+	{
+		selectDir=(struct dirent*)malloc(sizeof(struct dirent)+lstrlen(find.cFileName)+1);
+#if defined(__CEGCC__)
+		wcstombs(selectDir->d_name, find.cFileName, lstrlen(find.cFileName)+1);
+#else
+		strcpy(selectDir->d_name, find.cFileName);
+#endif
+		//Log_Printf(LOG_DEBUG, "scandir : findFile='%s'\n", selectDir->d_name);
+		if (!sdfilter || (*sdfilter)(selectDir))
+		{
+			if (nDir==NDir)
+			{
+				struct dirent **tempDir = (struct dirent **)calloc(sizeof(struct dirent*), NDir+33);
+				if (NDir)
+					memcpy(tempDir, dir, sizeof(struct dirent*)*NDir);
+				if (dir)
+					free(dir);
+				dir = tempDir;
+				NDir += 32;
+			}
+			dir[nDir] = selectDir;
+			nDir++;
+			dir[nDir] = 0;
+		}
+		else
+		{
+			free(selectDir);
+		}
+
+#if defined(__CEGCC__)
+		ret = FindNextFileW(h, &find);
+#else
+		ret = FindNextFile(h, &find);
+#endif
+	}
+	while (ret);
+
+	ret = GetLastError();
+	if (ret != ERROR_NO_MORE_FILES)
+	{
+		// TODO: return some error code
+		Log_Printf(LOG_DEBUG, "scandir: last error = %ld\n", ret);
+	}
+
+	FindClose(h);
+
+	free(findIn);
+
+#if defined(__CEGCC__)
+	free(findInW);
+#endif
+
+	if (dcomp)
+		qsort (dir, nDir, sizeof(*dir),dcomp);
+
+	*namelist = dir;
+	return nDir;
+}
+
+#endif /* WIN32 */

+ 9 - 0
wii/meta.xml

@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<app version="1">
+<name>sdlpal</name>
+<coder>palxex</coder>
+<version>2.0</version>
+<release_date>2017.07.27</release_date>
+<short_description>Chinese Paladin</short_description>
+<long_description>SDL-based reimplementation of the classic Chinese-language RPG "Xiān jiàn Qí Xiá Zhuàn" (also known as PAL).</long_description>
+</app>

+ 35 - 0
wii/pal_config.h

@@ -0,0 +1,35 @@
+#ifndef PAL_CONFIG_H
+# define PAL_CONFIG_H
+
+# define PAL_HAS_JOYSTICKS     1
+# define PAL_HAS_MOUSE         0
+# define PAL_PREFIX            "sd:/sdlpal/"
+# define PAL_SAVE_PREFIX       "sd:/sdlpal/"
+
+# define PAL_DEFAULT_WINDOW_WIDTH   640
+# define PAL_DEFAULT_WINDOW_HEIGHT  480
+
+# if SDL_VERSION_ATLEAST(2,0,0)
+#  define PAL_VIDEO_INIT_FLAGS  (SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE)
+# else
+#  define PAL_VIDEO_INIT_FLAGS  (SDL_SWSURFACE | (gConfig.fFullScreen ? SDL_FULLSCREEN : 0))
+# endif
+
+# define PAL_SDL_INIT_FLAGS	(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_CDROM | SDL_INIT_NOPARACHUTE | SDL_INIT_JOYSTICK)
+# define PAL_SCALE_SCREEN   FALSE
+
+# define PAL_PLATFORM         "Nintendo WII"
+# define PAL_CREDIT           "Rikku2000,palxex"
+# define PAL_PORTYEAR         "2017"
+
+# define PAL_FILESYSTEM_IGNORE_CASE         1
+# define PAL_HAS_PLATFORM_SPECIFIC_UTILS    1
+# define PAL_HAS_PLATFORM_STARTUP           1
+
+# include <gctypes.h>
+# include <dirent.h>
+# include <strings.h>
+
+extern int alphasort(const struct dirent **d1, const struct dirent **d2);
+
+#endif

+ 136 - 0
wii/pal_utils.cpp

@@ -0,0 +1,136 @@
+
+#include "main.h"
+#include <fat.h>
+#include <ogcsys.h>
+#include <gccore.h>
+#include <fcntl.h>
+#include <network.h>
+#include <debug.h>
+#include <errno.h>
+#include <unistd.h>
+#ifdef DEBUG
+extern "C"{
+# include <net_print.h>
+}
+#endif
+
+static int input_event_filter(const SDL_Event *lpEvent, volatile PALINPUTSTATE *state)
+{
+	switch (lpEvent->type)
+	{
+	case SDL_JOYHATMOTION:
+		switch (lpEvent->jhat.value)
+		{
+		case SDL_HAT_LEFT:
+			state->prevdir = (gpGlobals->fInBattle ? kDirUnknown : state->dir);
+			state->dir = kDirWest;
+			state->dwKeyPress = kKeyLeft;
+			break;
+
+		case SDL_HAT_RIGHT:
+			state->prevdir = (gpGlobals->fInBattle ? kDirUnknown : state->dir);
+			state->dir = kDirEast;
+			state->dwKeyPress = kKeyRight;
+			break;
+
+		case SDL_HAT_UP:
+			state->prevdir = (gpGlobals->fInBattle ? kDirUnknown : state->dir);
+			state->dir = kDirNorth;
+			state->dwKeyPress = kKeyUp;
+			break;
+
+		case SDL_HAT_DOWN:
+			state->prevdir = (gpGlobals->fInBattle ? kDirUnknown : state->dir);
+			state->dir = kDirSouth;
+			state->dwKeyPress = kKeyDown;
+			break;
+		}
+		return 1;
+
+	case SDL_JOYBUTTONDOWN:
+		switch (lpEvent->jbutton.button)
+		{
+		case 2:
+			state->dwKeyPress |= kKeyMenu;
+			return 1;
+
+		case 3:
+			state->dwKeyPress |= kKeySearch;
+			return 1;
+		}
+	}
+	return 0;
+}
+
+BOOL
+UTIL_GetScreenSize(
+	DWORD *pdwScreenWidth,
+	DWORD *pdwScreenHeight
+)
+{
+    return (pdwScreenWidth && pdwScreenHeight && *pdwScreenWidth && *pdwScreenHeight);
+}
+
+BOOL
+UTIL_IsAbsolutePath(
+	LPCSTR  lpszFileName
+)
+{
+	return FALSE;
+}
+
+int UTIL_Platform_Startup(
+	int argc,
+	char* argv[]
+)
+{
+#if defined(DEBUG)
+   VIDEO_SetBlack(FALSE);
+   VIDEO_Flush();
+   VIDEO_WaitVSync();
+   char localip[16] = {0};
+   char gateway[16] = {0};
+   char netmask[16] = {0};
+   int ret = if_config ( localip, netmask, gateway, TRUE);
+   if (ret>=0) {
+      printf ("\n network configured, ip: %s, gw: %s, mask %s\n", localip, gateway, netmask);
+      net_print_init(NULL,0);
+      
+      printf("net_print_init() called.\n");
+      net_print_string(__FILE__,__LINE__, "initial net_print from %s...\n",localip);
+
+      DEBUG_Init(100,5656);
+      printf("after DEBUG_Init()...\n");
+      
+      printf("Before _break() is called.\n");
+      _break();
+      printf("After _break() is called.\n");
+   }
+#endif
+	fatInitDefault();
+	return 0;
+}
+
+INT
+UTIL_Platform_Init(
+	int argc,
+	char* argv[]
+)
+{
+#ifdef DEBUG
+	UTIL_LogAddOutputCallback([](LOGLEVEL, const char* str, const char*)->void {
+      net_print_string(__FILE__,__LINE__, "%s\n",str);
+	}, PAL_DEFAULT_LOGLEVEL);
+#endif
+	UTIL_LogOutput(LOGLEVEL_WARNING, "try net_print logout");
+	PAL_RegisterInputFilter(NULL, input_event_filter, NULL);
+	gConfig.fLaunchSetting = FALSE;
+	return 0;
+}
+
+VOID
+UTIL_Platform_Quit(
+	VOID
+)
+{
+}

+ 4 - 4
winrt/SDLPal.WindowsPhone/SDLPal.Core.vcxproj

@@ -84,7 +84,7 @@
   <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
     <ClCompile>
       <PrecompiledHeader>NotUsing</PrecompiledHeader>
-      <AdditionalIncludeDirectories>..\;..\..\liboggvorbis\include;$(IntermediateOutputPath);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+      <AdditionalIncludeDirectories>..\;..\..\;..\..\liboggvorbis\include;$(IntermediateOutputPath);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
       <CompileAsWinRT>false</CompileAsWinRT>
       <PreprocessorDefinitions>PAL_HAS_GIT_REVISION;PAL_HAS_PLATFORM_SPECIFIC_UTILS;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
       <DisableSpecificWarnings>4244</DisableSpecificWarnings>
@@ -96,7 +96,7 @@
   <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
     <ClCompile>
       <PrecompiledHeader>NotUsing</PrecompiledHeader>
-      <AdditionalIncludeDirectories>..\;..\..\liboggvorbis\include;$(IntermediateOutputPath);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+      <AdditionalIncludeDirectories>..\;..\..\;..\..\liboggvorbis\include;$(IntermediateOutputPath);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
       <CompileAsWinRT>false</CompileAsWinRT>
       <PreprocessorDefinitions>PAL_HAS_GIT_REVISION;PAL_HAS_PLATFORM_SPECIFIC_UTILS;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
       <DisableSpecificWarnings>4244</DisableSpecificWarnings>
@@ -108,7 +108,7 @@
   <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">
     <ClCompile>
       <PrecompiledHeader>NotUsing</PrecompiledHeader>
-      <AdditionalIncludeDirectories>..\;..\..\liboggvorbis\include;$(IntermediateOutputPath);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+      <AdditionalIncludeDirectories>..\;..\..\;..\..\liboggvorbis\include;$(IntermediateOutputPath);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
       <CompileAsWinRT>false</CompileAsWinRT>
       <PreprocessorDefinitions>PAL_HAS_GIT_REVISION;PAL_HAS_PLATFORM_SPECIFIC_UTILS;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
       <DisableSpecificWarnings>4244</DisableSpecificWarnings>
@@ -120,7 +120,7 @@
   <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">
     <ClCompile>
       <PrecompiledHeader>NotUsing</PrecompiledHeader>
-      <AdditionalIncludeDirectories>..\;..\..\liboggvorbis\include;$(IntermediateOutputPath);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+      <AdditionalIncludeDirectories>..\;..\..\;..\..\liboggvorbis\include;$(IntermediateOutputPath);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
       <CompileAsWinRT>false</CompileAsWinRT>
       <PreprocessorDefinitions>PAL_HAS_GIT_REVISION;PAL_HAS_PLATFORM_SPECIFIC_UTILS;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
       <DisableSpecificWarnings>4244</DisableSpecificWarnings>