From 7a84a2492eb065d8115c3174eafb4eb132e61738 Mon Sep 17 00:00:00 2001 From: dborth Date: Sun, 25 Jan 2009 06:53:21 +0000 Subject: [PATCH] switch from C to C++, fix a few small bugs --- source/ngc/{dvd.c => dvd.cpp} | 2 ++ source/ngc/{fceuconfig.c => fceuconfig.cpp} | 0 source/ngc/{fceugx.c => fceugx.cpp} | 21 ++++++++++-------- source/ngc/fceugx.h | 1 + source/ngc/{fceuload.c => fceuload.cpp} | 17 +++++++------- source/ngc/{fceuram.c => fceuram.cpp} | 22 +++++++++---------- source/ngc/{fceustate.c => fceustate.cpp} | 6 +++-- source/ngc/{fileop.c => fileop.cpp} | 0 source/ngc/{filesel.c => filesel.cpp} | 0 source/ngc/{gcaudio.c => gcaudio.cpp} | 0 source/ngc/{gcunzip.c => gcunzip.cpp} | 2 ++ source/ngc/{gcvideo.c => gcvideo.cpp} | 12 +++++++--- source/ngc/gcvideo.h | 2 +- source/ngc/{http.c => http.cpp} | 0 source/ngc/{memcardop.c => memcardop.cpp} | 0 source/ngc/{menu.c => menu.cpp} | 2 ++ source/ngc/{menudraw.c => menudraw.cpp} | 0 source/ngc/{networkop.c => networkop.cpp} | 0 source/ngc/{pad.c => pad.cpp} | 12 +++++----- source/ngc/{preferences.c => preferences.cpp} | 3 +-- 20 files changed, 60 insertions(+), 42 deletions(-) rename source/ngc/{dvd.c => dvd.cpp} (99%) rename source/ngc/{fceuconfig.c => fceuconfig.cpp} (100%) rename source/ngc/{fceugx.c => fceugx.cpp} (99%) rename source/ngc/{fceuload.c => fceuload.cpp} (98%) rename source/ngc/{fceuram.c => fceuram.cpp} (94%) rename source/ngc/{fceustate.c => fceustate.cpp} (99%) rename source/ngc/{fileop.c => fileop.cpp} (100%) rename source/ngc/{filesel.c => filesel.cpp} (100%) rename source/ngc/{gcaudio.c => gcaudio.cpp} (100%) rename source/ngc/{gcunzip.c => gcunzip.cpp} (99%) rename source/ngc/{gcvideo.c => gcvideo.cpp} (99%) rename source/ngc/{http.c => http.cpp} (100%) rename source/ngc/{memcardop.c => memcardop.cpp} (100%) rename source/ngc/{menu.c => menu.cpp} (99%) rename source/ngc/{menudraw.c => menudraw.cpp} (100%) rename source/ngc/{networkop.c => networkop.cpp} (100%) rename source/ngc/{pad.c => pad.cpp} (99%) rename source/ngc/{preferences.c => preferences.cpp} (99%) diff --git a/source/ngc/dvd.c b/source/ngc/dvd.cpp similarity index 99% rename from source/ngc/dvd.c rename to source/ngc/dvd.cpp index eb003ab..1b6de39 100644 --- a/source/ngc/dvd.c +++ b/source/ngc/dvd.cpp @@ -17,7 +17,9 @@ #include #ifdef HW_RVL +extern "C" { #include +} #endif #include "menudraw.h" diff --git a/source/ngc/fceuconfig.c b/source/ngc/fceuconfig.cpp similarity index 100% rename from source/ngc/fceuconfig.c rename to source/ngc/fceuconfig.cpp diff --git a/source/ngc/fceugx.c b/source/ngc/fceugx.cpp similarity index 99% rename from source/ngc/fceugx.c rename to source/ngc/fceugx.cpp index f80d7d4..81ba11c 100644 --- a/source/ngc/fceugx.c +++ b/source/ngc/fceugx.cpp @@ -18,8 +18,6 @@ #include #include -#include "types.h" - #include "fceugx.h" #include "fceuconfig.h" #include "fceuload.h" @@ -35,10 +33,21 @@ #include "gcvideo.h" #include "pad.h" -#ifdef WII_DVD +#ifdef HW_RVL +extern "C" { #include +} #endif +extern "C" { +#include "types.h" +extern int cleanSFMDATA(); +extern void PowerNES(void); +extern uint8 FDSBIOS[8192]; + +void FCEUD_Update(uint8 *XBuf, int32 *Buffer, int Count); +} + unsigned char * nesrom = NULL; int ConfigRequested = 0; int ShutdownRequested = 0; @@ -49,12 +58,6 @@ int frameskip = 0; extern bool romLoaded; -extern int cleanSFMDATA(); -extern void PowerNES(void); -extern uint8 FDSBIOS[8192]; - -void FCEUD_Update(uint8 *XBuf, int32 *Buffer, int Count); - /**************************************************************************** * Shutdown / Reboot / Exit ***************************************************************************/ diff --git a/source/ngc/fceugx.h b/source/ngc/fceugx.h index 6cc2ba8..19fff23 100644 --- a/source/ngc/fceugx.h +++ b/source/ngc/fceugx.h @@ -75,5 +75,6 @@ extern int ConfigRequested; extern int ShutdownRequested; extern char appPath[]; extern int frameskip; +extern unsigned char * nesrom; #endif diff --git a/source/ngc/fceuload.c b/source/ngc/fceuload.cpp similarity index 98% rename from source/ngc/fceuload.c rename to source/ngc/fceuload.cpp index 9d1e340..f1d7352 100644 --- a/source/ngc/fceuload.c +++ b/source/ngc/fceuload.cpp @@ -16,6 +16,7 @@ #include #include +extern "C" { #include "types.h" #include "git.h" #include "driver.h" @@ -24,6 +25,13 @@ #include "sound.h" #include "file.h" +extern int FDSLoad(const char *name, FCEUFILE *fp); +extern int iNESLoad(const char *name, FCEUFILE *fp); +extern int UNIFLoad(const char *name, FCEUFILE *fp); +extern int NSFLoad(FCEUFILE *fp); +extern uint8 FDSBIOS[8192]; +} + #include "fceugx.h" #include "gcaudio.h" #include "common.h" @@ -32,7 +40,6 @@ #include "fileop.h" #include "filesel.h" -unsigned char *nesrom; bool romLoaded = false; extern FCEUGI *FCEUGameInfo; @@ -66,19 +73,13 @@ static void MakeFCEUFile(char * membuffer, int length) fceufp->fp = fceumem; } -extern int FDSLoad(const char *name, FCEUFILE *fp); -extern int iNESLoad(const char *name, FCEUFILE *fp); -extern int UNIFLoad(const char *name, FCEUFILE *fp); -extern int NSFLoad(FCEUFILE *fp); -extern uint8 FDSBIOS[8192]; - int GCMemROM(int method, int size) { ResetGameLoaded(); /*** Allocate and clear GameInfo ***/ - FCEUGameInfo = malloc(sizeof(FCEUGI)); + FCEUGameInfo = (FCEUGI *)malloc(sizeof(FCEUGI)); memset(FCEUGameInfo, 0, sizeof(FCEUGI)); /*** Set some default values ***/ diff --git a/source/ngc/fceuram.c b/source/ngc/fceuram.cpp similarity index 94% rename from source/ngc/fceuram.c rename to source/ngc/fceuram.cpp index 4b5e095..a55ca2b 100644 --- a/source/ngc/fceuram.c +++ b/source/ngc/fceuram.cpp @@ -20,17 +20,7 @@ #include #include -#include "types.h" - -#include "fceu.h" -#include "ppu.h" - -#include "cart.h" -#include "memory.h" -#include "x6502.h" - -#include "general.h" - +#include "images/saveicon.h" #include "fceugx.h" #include "intl.h" #include "menudraw.h" @@ -38,10 +28,18 @@ #include "memcardop.h" #include "fileop.h" -extern const unsigned short saveicon[1024]; +extern "C" { +#include "types.h" +#include "fceu.h" +#include "ppu.h" +#include "cart.h" +#include "memory.h" +#include "x6502.h" +#include "general.h" extern u32 iNESGameCRC32; extern CartInfo iNESCart; extern CartInfo UNIFCart; +} static u32 NGCFCEU_GameSave(CartInfo *LocalHWInfo, int operation, int method) { diff --git a/source/ngc/fceustate.c b/source/ngc/fceustate.cpp similarity index 99% rename from source/ngc/fceustate.c rename to source/ngc/fceustate.cpp index ee3fcea..094d5a5 100644 --- a/source/ngc/fceustate.c +++ b/source/ngc/fceustate.cpp @@ -29,6 +29,7 @@ #include "memcardop.h" #include "fileop.h" +extern "C" { /*** External functions ***/ extern void FCEUPPU_SaveState(void); extern void FCEUSND_SaveState(void); @@ -45,6 +46,7 @@ extern SFORMAT FCEUCTRL_STATEINFO[]; extern SFORMAT FCEUSND_STATEINFO[]; extern SFORMAT SFMDATA[64]; extern u32 iNESGameCRC32; +} #define RLSB 0x80000000 @@ -92,7 +94,7 @@ static void memfread(void *buffer, int len) ****************************************************************************/ static int GCReadChunk(int chunkid, SFORMAT *sf) { - int csize; + uint32 csize; static char chunk[6]; int chunklength; int thischunk; @@ -268,7 +270,7 @@ static int GCFCEUSS_Save(int method) if(method == METHOD_MC_SLOTA || method == METHOD_MC_SLOTB) { // Copy in save icon - memfwrite(&saveicon, sizeof(saveicon)); + memfwrite((void *)&saveicon, sizeof(saveicon)); totalsize += sizeof(saveicon); // And the comments diff --git a/source/ngc/fileop.c b/source/ngc/fileop.cpp similarity index 100% rename from source/ngc/fileop.c rename to source/ngc/fileop.cpp diff --git a/source/ngc/filesel.c b/source/ngc/filesel.cpp similarity index 100% rename from source/ngc/filesel.c rename to source/ngc/filesel.cpp diff --git a/source/ngc/gcaudio.c b/source/ngc/gcaudio.cpp similarity index 100% rename from source/ngc/gcaudio.c rename to source/ngc/gcaudio.cpp diff --git a/source/ngc/gcunzip.c b/source/ngc/gcunzip.cpp similarity index 99% rename from source/ngc/gcunzip.c rename to source/ngc/gcunzip.cpp index 4ca64d7..ef1eb76 100644 --- a/source/ngc/gcunzip.c +++ b/source/ngc/gcunzip.cpp @@ -15,9 +15,11 @@ #include #include +extern "C" { #include "../sz/7zCrc.h" #include "../sz/7zIn.h" #include "../sz/7zExtract.h" +} #include "fceugx.h" #include "dvd.h" diff --git a/source/ngc/gcvideo.c b/source/ngc/gcvideo.cpp similarity index 99% rename from source/ngc/gcvideo.c rename to source/ngc/gcvideo.cpp index 2778f14..27238e4 100644 --- a/source/ngc/gcvideo.c +++ b/source/ngc/gcvideo.cpp @@ -23,7 +23,9 @@ #include "menudraw.h" #include "images/nesback.h" +extern "C" { extern void FCEU_ResetPalette(void); +} int FDSTimer = 0; u32 FrameTimer = 0; @@ -68,8 +70,11 @@ static unsigned short rgb565[256]; // Texture map palette static long long prev; static long long now; +extern "C" +{ long long gettime(); u32 diff_usec(long long start,long long end); +} /* New texture based scaler */ typedef struct tagcamera @@ -190,7 +195,7 @@ static GXRModeObj *tvmodes[2] = { * change frame timings depending on whether ROM is NTSC or PAL ***************************************************************************/ -static int normaldiff; +static long long normaldiff; void setFrameTimer() { @@ -205,7 +210,8 @@ void setFrameTimer() static void SyncSpeed() { now = gettime(); - while (diff_usec(prev, now) < normaldiff) now = gettime(); + while (diff_usec(prev, now) < normaldiff) + now = gettime(); prev = now; } @@ -999,7 +1005,7 @@ struct st_palettes palettes[] = { 0xe0e01e, 0xd8f878, 0xc0e890, 0x95f7c8, 0x98e0e8, 0xf8d8f8, 0x000000, 0x000000 } }, - { "mess", "palette from the MESS NES driver", + { "mess", "palette from MESS NES driver", { 0x747474, 0x24188c, 0x0000a8, 0x44009c, 0x8c0074, 0xa80010, 0xa40000, 0x7c0800, 0x402c00, 0x004400, 0x005000, 0x003c14, diff --git a/source/ngc/gcvideo.h b/source/ngc/gcvideo.h index 342dac5..20830a8 100644 --- a/source/ngc/gcvideo.h +++ b/source/ngc/gcvideo.h @@ -34,6 +34,6 @@ struct st_palettes { extern struct st_palettes palettes[]; extern int FDSSwitchRequested; extern bool progressive; -u32 FrameTimer; +extern u32 FrameTimer; #endif diff --git a/source/ngc/http.c b/source/ngc/http.cpp similarity index 100% rename from source/ngc/http.c rename to source/ngc/http.cpp diff --git a/source/ngc/memcardop.c b/source/ngc/memcardop.cpp similarity index 100% rename from source/ngc/memcardop.c rename to source/ngc/memcardop.cpp diff --git a/source/ngc/menu.c b/source/ngc/menu.cpp similarity index 99% rename from source/ngc/menu.c rename to source/ngc/menu.cpp index 61e9be3..993cf08 100644 --- a/source/ngc/menu.c +++ b/source/ngc/menu.cpp @@ -38,8 +38,10 @@ #include "fceuram.h" #include "fceuload.h" +extern "C" { extern void ResetNES(void); extern void PowerNES(void); +} extern int menu; extern bool romLoaded; diff --git a/source/ngc/menudraw.c b/source/ngc/menudraw.cpp similarity index 100% rename from source/ngc/menudraw.c rename to source/ngc/menudraw.cpp diff --git a/source/ngc/networkop.c b/source/ngc/networkop.cpp similarity index 100% rename from source/ngc/networkop.c rename to source/ngc/networkop.cpp diff --git a/source/ngc/pad.c b/source/ngc/pad.cpp similarity index 99% rename from source/ngc/pad.c rename to source/ngc/pad.cpp index 39e7080..9d6c432 100644 --- a/source/ngc/pad.c +++ b/source/ngc/pad.cpp @@ -12,9 +12,6 @@ #include #include #include -#include "driver.h" -#include "fceu.h" -#include "input.h" #include "fceugx.h" #include "pad.h" @@ -23,6 +20,13 @@ #include "gcvideo.h" #include "filesel.h" +extern "C" { +#include "driver.h" +#include "fceu.h" +#include "input.h" +extern INPUTC *FCEU_InitZapper(int w); +} + extern bool romLoaded; static uint32 JSReturn = 0; @@ -31,8 +35,6 @@ void *InputDPR; static INPUTC *zapperdata[2]; static unsigned int myzappers[2][3]; -extern INPUTC *FCEU_InitZapper(int w); - unsigned int nespadmap[11]; // Original NES controller buttons unsigned int gcpadmap[11]; // Gamecube controller Padmap unsigned int wmpadmap[11]; // Wiimote Padmap diff --git a/source/ngc/preferences.c b/source/ngc/preferences.cpp similarity index 99% rename from source/ngc/preferences.c rename to source/ngc/preferences.cpp index 890a1c1..100a722 100644 --- a/source/ngc/preferences.c +++ b/source/ngc/preferences.cpp @@ -15,14 +15,13 @@ #include #include +#include "images/saveicon.h" #include "menudraw.h" #include "memcardop.h" #include "fileop.h" #include "fceugx.h" #include "pad.h" -extern const unsigned short saveicon[1024]; - /**************************************************************************** * Prepare Preferences Data *