diff --git a/desmume/src/ARM9.h b/desmume/src/ARM9.h index bc1cd8cf8..4dae037d8 100644 --- a/desmume/src/ARM9.h +++ b/desmume/src/ARM9.h @@ -3,10 +3,6 @@ #include "types.h" -#ifdef __cplusplus -extern "C" { -#endif - typedef struct { //ARM9 mem u8 ARM9_ITCM[0x8000]; @@ -34,8 +30,4 @@ typedef struct { extern ARM9_struct ARM9Mem; -#ifdef __cplusplus -} -#endif - #endif diff --git a/desmume/src/Disassembler.c b/desmume/src/Disassembler.cpp similarity index 100% rename from desmume/src/Disassembler.c rename to desmume/src/Disassembler.cpp diff --git a/desmume/src/Disassembler.h b/desmume/src/Disassembler.h index 367b070b3..63fa2b818 100644 --- a/desmume/src/Disassembler.h +++ b/desmume/src/Disassembler.h @@ -24,17 +24,9 @@ #include "types.h" -#ifdef __cplusplus -extern "C" { -#endif - extern char * (* des_arm_instructions_set[4096])(u32 adr, u32 i, char * txt); extern char * (* des_thumb_instructions_set[1024])(u32 adr, u32 i, char * txt); -#ifdef __cplusplus -} -#endif - #endif diff --git a/desmume/src/FIFO.c b/desmume/src/FIFO.cpp similarity index 100% rename from desmume/src/FIFO.c rename to desmume/src/FIFO.cpp diff --git a/desmume/src/FIFO.h b/desmume/src/FIFO.h index 361ee2e1f..9dd4b52d4 100644 --- a/desmume/src/FIFO.h +++ b/desmume/src/FIFO.h @@ -26,10 +26,6 @@ #include "types.h" -#ifdef __cplusplus -extern "C" { -#endif - typedef struct { u32 data[0x8000]; @@ -56,8 +52,4 @@ typedef struct{ u32 irq; } GFXFIFO; -#ifdef __cplusplus -} -#endif - #endif diff --git a/desmume/src/GPU.c b/desmume/src/GPU.cpp similarity index 100% rename from desmume/src/GPU.c rename to desmume/src/GPU.cpp diff --git a/desmume/src/GPU.h b/desmume/src/GPU.h index 252dba1fb..827c15270 100644 --- a/desmume/src/GPU.h +++ b/desmume/src/GPU.h @@ -32,10 +32,6 @@ #include "FIFO.h" #include "MMU.h" -#ifdef __cplusplus -extern "C" { -#endif - /******************************************************************************* this structure is for display control, @@ -816,9 +812,5 @@ void SetupFinalPixelBlitter (GPU *gpu); #define GPU_setBLDY_EVY(gpu, val) {gpu->BLDY_EVY = (val&0x1f) > 16 ? 16 : (val&0x1f);} -#ifdef __cplusplus -} -#endif - #endif diff --git a/desmume/src/MMU.c b/desmume/src/MMU.cpp similarity index 99% rename from desmume/src/MMU.c rename to desmume/src/MMU.cpp index ee45642ad..95376ebe6 100644 --- a/desmume/src/MMU.c +++ b/desmume/src/MMU.cpp @@ -2663,7 +2663,7 @@ void FASTCALL MMU_write32(u32 proc, u32 adr, u32 val) case 1: return; } - T1WriteLong(MMU.MMU_MEM[proc][0x40], 0x2B4, (u32) sqrt(v)); + T1WriteLong(MMU.MMU_MEM[proc][0x40], 0x2B4, (u32) sqrt((double)v)); T1WriteLong(MMU.MMU_MEM[proc][0x40], 0x2B0, cnt & 0x7FFF); SQRTLOG("BOUT1 sqrt(%08X%08X) = %08X\r\n", (u32)(v>>32), (u32)v, T1ReadLong(MMU.MMU_MEM[proc][0x40], 0x2B4)); @@ -2684,7 +2684,7 @@ void FASTCALL MMU_write32(u32 proc, u32 adr, u32 val) v = T1ReadQuad(MMU.MMU_MEM[proc][0x40], 0x2B8); break; } - T1WriteLong(MMU.MMU_MEM[proc][0x40], 0x2B4, (u32) sqrt(v)); + T1WriteLong(MMU.MMU_MEM[proc][0x40], 0x2B4, (u32) sqrt((double)v)); T1WriteLong(MMU.MMU_MEM[proc][0x40], 0x2B0, cnt & 0x7FFF); SQRTLOG("BOUT2 sqrt(%08X%08X) = %08X\r\n", (u32)(v>>32), (u32)v, T1ReadLong(MMU.MMU_MEM[proc][0x40], 0x2B4)); diff --git a/desmume/src/MMU.h b/desmume/src/MMU.h index 0a957d3cc..6a453ca58 100644 --- a/desmume/src/MMU.h +++ b/desmume/src/MMU.h @@ -30,10 +30,6 @@ #include "ARM9.h" #include "mc.h" -#ifdef __cplusplus -extern "C" { -#endif - extern char szRomPath[512]; extern char szRomBaseName[512]; @@ -193,9 +189,4 @@ extern struct armcpu_memory_iface arm9_base_memory_iface; extern struct armcpu_memory_iface arm7_base_memory_iface; extern struct armcpu_memory_iface arm9_direct_memory_iface; - -#ifdef __cplusplus -} -#endif - #endif diff --git a/desmume/src/NDSSystem.c b/desmume/src/NDSSystem.cpp similarity index 99% rename from desmume/src/NDSSystem.c rename to desmume/src/NDSSystem.cpp index 533913650..eeb889b2e 100644 --- a/desmume/src/NDSSystem.c +++ b/desmume/src/NDSSystem.cpp @@ -195,7 +195,7 @@ BOOL NDS_SetROM(u8 * rom, u32 mask) NDS_header * NDS_getROMHeader(void) { - NDS_header * header = malloc(sizeof(NDS_header)); + NDS_header * header = new NDS_header(); memcpy(header->gameTile, MMU.CART_ROM, 12); memcpy(header->gameCode, MMU.CART_ROM + 12, 4); @@ -306,7 +306,7 @@ int NDS_LoadROM( const char *filename, int bmtype, u32 bmsize, char * p; ROMReader_struct * reader; - FILE * file; + void* file; u32 size, mask; u8 *data; char * noext; @@ -532,7 +532,7 @@ void NDS_Reset( void) MMU_write32(0, 0x0000010, 0xE3B02020); // MMU_write32(0, 0x0000010, 0xE2100202); - free(header); + delete header; GPU_Reset(MainScreen.gpu, 0); GPU_Reset(SubScreen.gpu, 1); diff --git a/desmume/src/NDSSystem.h b/desmume/src/NDSSystem.h index 931330f5d..3d5ff8fef 100644 --- a/desmume/src/NDSSystem.h +++ b/desmume/src/NDSSystem.h @@ -31,11 +31,6 @@ #include "mem.h" #include "wifi.h" -#ifdef __cplusplus -extern "C" { -#endif - - extern volatile BOOL execute; extern BOOL click; @@ -242,10 +237,6 @@ NDS_exec(s32 nb, BOOL force); } int NDS_WriteBMP_32bppBuffer(int width, int height, const void* buf, const char *filename); - -#ifdef __cplusplus -} -#endif #endif diff --git a/desmume/src/ROMReader.c b/desmume/src/ROMReader.cpp similarity index 89% rename from desmume/src/ROMReader.c rename to desmume/src/ROMReader.cpp index 506d5326a..364ba3b23 100644 --- a/desmume/src/ROMReader.c +++ b/desmume/src/ROMReader.cpp @@ -23,9 +23,6 @@ #ifdef HAVE_LIBZZIP #include #endif -#ifdef WIN32 -#define strcasecmp stricmp -#endif ROMReader_struct * ROMReaderInit(char ** filename) { @@ -71,7 +68,7 @@ void * STDROMReaderInit(const char * filename) void STDROMReaderDeInit(void * file) { if (!file) return ; - fclose(file); + fclose((FILE*)file); } u32 STDROMReaderSize(void * file) @@ -80,9 +77,9 @@ u32 STDROMReaderSize(void * file) if (!file) return 0 ; - fseek(file, 0, SEEK_END); - size = ftell(file); - fseek(file, 0, SEEK_SET); + fseek((FILE*)file, 0, SEEK_END); + size = ftell((FILE*)file); + fseek((FILE*)file, 0, SEEK_SET); return size; } @@ -90,13 +87,13 @@ u32 STDROMReaderSize(void * file) int STDROMReaderSeek(void * file, int offset, int whence) { if (!file) return 0 ; - return fseek(file, offset, whence); + return fseek((FILE*)file, offset, whence); } int STDROMReaderRead(void * file, void * buffer, u32 size) { if (!file) return 0 ; - return fread(buffer, 1, size, file); + return fread(buffer, 1, size, (FILE*)file); } #ifdef HAVE_LIBZ @@ -188,7 +185,7 @@ void * ZIPROMReaderInit(const char * filename) void ZIPROMReaderDeInit(void * file) { - zzip_close(file); + zzip_close((ZZIP_FILE*)file); } u32 ZIPROMReaderSize(void * file) @@ -197,20 +194,20 @@ u32 ZIPROMReaderSize(void * file) u32 tmp; u32 size = 0; - zzip_seek(file, 0, SEEK_END); - size = zzip_tell(file); - zzip_seek(file, 0, SEEK_SET); + zzip_seek((ZZIP_FILE*)file, 0, SEEK_END); + size = zzip_tell((ZZIP_FILE*)file); + zzip_seek((ZZIP_FILE*)file, 0, SEEK_SET); return size; } int ZIPROMReaderSeek(void * file, int offset, int whence) { - return zzip_seek(file, offset, whence); + return zzip_seek((ZZIP_FILE*)file, offset, whence); } int ZIPROMReaderRead(void * file, void * buffer, u32 size) { - return zzip_read(file, buffer, size); + return zzip_read((ZZIP_FILE*)file, buffer, size); } #endif diff --git a/desmume/src/SPU.c b/desmume/src/SPU.cpp similarity index 98% rename from desmume/src/SPU.c rename to desmume/src/SPU.cpp index a7796bea9..7b7dc0f1a 100644 --- a/desmume/src/SPU.c +++ b/desmume/src/SPU.cpp @@ -87,10 +87,10 @@ int SPU_ChangeSoundCore(int coreid, int buffersize) SNDCore->DeInit(); // Allocate memory for sound buffer - if ((SPU->sndbuf = malloc(buffersize * 4 * 2)) == NULL) + if ((SPU->sndbuf = new s32[buffersize * 2]) == NULL) return -1; - if ((SPU->outbuf = malloc(buffersize * 2 * 2)) == NULL) + if ((SPU->outbuf = new s16[buffersize * 2]) == NULL) return -1; memset(SPU->sndbuf, 0, buffersize * 4 * 2); @@ -180,10 +180,10 @@ void SPU_Reset(void) void SPU_DeInit(void) { if (SPU->sndbuf) - free(SPU->sndbuf); + delete[] SPU->sndbuf; if (SPU->outbuf) - free(SPU->outbuf); + delete[] SPU->outbuf; if (SNDCore) SNDCore->DeInit(); @@ -204,13 +204,13 @@ void SPU_KeyOn(int channel) switch(chan->format) { case 0: // 8-bit - chan->buf8 = &MMU.MMU_MEM[1][(chan->addr>>20)&0xFF][(chan->addr & MMU.MMU_MASK[1][(chan->addr >> 20) & 0xFF])]; + chan->buf8 = (s8*)&MMU.MMU_MEM[1][(chan->addr>>20)&0xFF][(chan->addr & MMU.MMU_MASK[1][(chan->addr >> 20) & 0xFF])]; chan->loopstart = chan->loopstart << 2; chan->length = (chan->length << 2) + chan->loopstart; chan->sampcnt = 0; break; case 1: // 16-bit - chan->buf16 = (u16 *)&MMU.MMU_MEM[1][(chan->addr>>20)&0xFF][(chan->addr & MMU.MMU_MASK[1][(chan->addr >> 20) & 0xFF])]; + chan->buf16 = (s16 *)&MMU.MMU_MEM[1][(chan->addr>>20)&0xFF][(chan->addr & MMU.MMU_MASK[1][(chan->addr >> 20) & 0xFF])]; chan->loopstart = chan->loopstart << 1; chan->length = (chan->length << 1) + chan->loopstart; chan->sampcnt = 0; @@ -219,7 +219,7 @@ void SPU_KeyOn(int channel) { u32 temp; - chan->buf8 = &MMU.MMU_MEM[1][(chan->addr>>20)&0xFF][(chan->addr & MMU.MMU_MASK[1][(chan->addr >> 20) & 0xFF])]; + chan->buf8 = (s8*)&MMU.MMU_MEM[1][(chan->addr>>20)&0xFF][(chan->addr & MMU.MMU_MASK[1][(chan->addr >> 20) & 0xFF])]; chan->pcm16b = (s16)((chan->buf8[1] << 8) | chan->buf8[0]); chan->index = chan->buf8[2] & 0x7F; chan->lastsampcnt = 7; diff --git a/desmume/src/SPU.h b/desmume/src/SPU.h index 47d610c8c..eff5845f5 100644 --- a/desmume/src/SPU.h +++ b/desmume/src/SPU.h @@ -22,10 +22,6 @@ #include "types.h" -#ifdef __cplusplus -extern "C" { -#endif - #define SNDCORE_DEFAULT -1 #define SNDCORE_DUMMY 0 #define SNDCORE_FILEWRITE 1 @@ -95,8 +91,4 @@ void SPU_WriteLong(u32 addr, u32 val); u32 SPU_ReadLong(u32 addr); void SPU_Emulate(void); -#ifdef __cplusplus -} -#endif - #endif diff --git a/desmume/src/arm_instructions.c b/desmume/src/arm_instructions.cpp similarity index 99% rename from desmume/src/arm_instructions.c rename to desmume/src/arm_instructions.cpp index 3c628980f..3d799130f 100644 --- a/desmume/src/arm_instructions.c +++ b/desmume/src/arm_instructions.cpp @@ -22,10 +22,16 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +//zero 9/8/08 - fixed a bug +//SIGNED_UNDERFLOW(a, (!cpu->CPSR.bits.C), tmp) +//was being called. but SIGNED_UNDERFLOW expects values in bit31. replaced with +//SIGNED_UNDERFLOW(a, (cpu->CPSR.bits.C?0:0x80000000), tmp) + #include "cp15.h" #include "debug.h" #include "MMU.h" +BOOL execute; // Use this macros for reading/writing, so the GDB stub isn't broken #ifdef GDB_STUB @@ -235,8 +241,6 @@ #define IMM_OFF_12 ((i)&0xFFF) -extern BOOL execute; - static u32 FASTCALL OP_UND(armcpu_t *cpu) { u32 i = cpu->instruction; @@ -1331,8 +1335,8 @@ static u32 FASTCALL OP_SBC_IMM_VAL(armcpu_t *cpu) }\ cpu->CPSR.bits.N = BIT31(cpu->R[REG_POS(i,12)]);\ cpu->CPSR.bits.Z = (cpu->R[REG_POS(i,12)]==0);\ - cpu->CPSR.bits.C = (!UNSIGNED_UNDERFLOW(v, (!cpu->CPSR.bits.C), tmp)) & (!UNSIGNED_UNDERFLOW(tmp, shift_op, cpu->R[REG_POS(i,12)]));\ - cpu->CPSR.bits.V = SIGNED_UNDERFLOW(v, (!cpu->CPSR.bits.C), tmp) | SIGNED_UNDERFLOW(tmp, shift_op, cpu->R[REG_POS(i,12)]);\ + cpu->CPSR.bits.C = (!UNSIGNED_UNDERFLOW(v, (cpu->CPSR.bits.C?0:0x80000000), tmp)) & (!UNSIGNED_UNDERFLOW(tmp, shift_op, cpu->R[REG_POS(i,12)]));\ + cpu->CPSR.bits.V = SIGNED_UNDERFLOW(v, (cpu->CPSR.bits.C?0:0x80000000), tmp) | SIGNED_UNDERFLOW(tmp, shift_op, cpu->R[REG_POS(i,12)]);\ return a; \ } @@ -1504,8 +1508,8 @@ static u32 FASTCALL OP_RSC_IMM_VAL(armcpu_t *cpu) }\ cpu->CPSR.bits.N = BIT31(cpu->R[REG_POS(i,12)]);\ cpu->CPSR.bits.Z = (cpu->R[REG_POS(i,12)]==0);\ - cpu->CPSR.bits.C = (!UNSIGNED_UNDERFLOW(shift_op, (!cpu->CPSR.bits.C), tmp)) & (!UNSIGNED_UNDERFLOW(tmp, v, cpu->R[REG_POS(i,12)]));\ - cpu->CPSR.bits.V = SIGNED_UNDERFLOW(shift_op, (!cpu->CPSR.bits.C), tmp) | SIGNED_UNDERFLOW(tmp, v, cpu->R[REG_POS(i,12)]);\ + cpu->CPSR.bits.C = (!UNSIGNED_UNDERFLOW(shift_op, (cpu->CPSR.bits.C?0:0x80000000), tmp)) & (!UNSIGNED_UNDERFLOW(tmp, v, cpu->R[REG_POS(i,12)]));\ + cpu->CPSR.bits.V = SIGNED_UNDERFLOW(shift_op, (cpu->CPSR.bits.C?0:0x80000000), tmp) | SIGNED_UNDERFLOW(tmp, v, cpu->R[REG_POS(i,12)]);\ return a; \ } diff --git a/desmume/src/armcpu.c b/desmume/src/armcpu.cpp similarity index 100% rename from desmume/src/armcpu.c rename to desmume/src/armcpu.cpp diff --git a/desmume/src/armcpu.h b/desmume/src/armcpu.h index 733716f64..bc8a42f63 100644 --- a/desmume/src/armcpu.h +++ b/desmume/src/armcpu.h @@ -26,10 +26,6 @@ #include "bits.h" #include "MMU.h" -#ifdef __cplusplus -extern "C" { -#endif - #define ARMCPU_ARM7 1 #define ARMCPU_ARM9 0 @@ -280,9 +276,4 @@ static INLINE void NDS_makeInt(u8 proc_ID,u32 num) } } - -#ifdef __cplusplus -} -#endif - #endif diff --git a/desmume/src/bios.c b/desmume/src/bios.cpp similarity index 100% rename from desmume/src/bios.c rename to desmume/src/bios.cpp diff --git a/desmume/src/cflash.c b/desmume/src/cflash.cpp similarity index 99% rename from desmume/src/cflash.c rename to desmume/src/cflash.cpp index dc6eab6aa..c10d6cfcc 100644 --- a/desmume/src/cflash.c +++ b/desmume/src/cflash.cpp @@ -332,6 +332,7 @@ static BOOL cflash_build_fat( void) { numExtraEntries[i] = 0; } + //COMMENT OUT THIS LINE TO STOP THE IRRITATING FILESYSTEM SCANNING BEHAVIOR list_files(sRomPath); k = 0; diff --git a/desmume/src/cflash.h b/desmume/src/cflash.h index c22ac12e3..5f33ff0d2 100644 --- a/desmume/src/cflash.h +++ b/desmume/src/cflash.h @@ -8,10 +8,6 @@ #include "fat.h" -#ifdef __cplusplus -extern "C" { -#endif - typedef struct { int level,parent,filesInDir; } FILE_INFO; @@ -25,8 +21,4 @@ void cflash_write(unsigned int address,unsigned int data); void cflash_close( void); -#ifdef __cplusplus -} -#endif - #endif diff --git a/desmume/src/cli/Makefile.am b/desmume/src/cli/Makefile.am index 31f342b05..562b278df 100644 --- a/desmume/src/cli/Makefile.am +++ b/desmume/src/cli/Makefile.am @@ -3,5 +3,5 @@ include $(top_srcdir)/src/desmume.mk AM_CFLAGS += $(SDL_CFLAGS) bin_PROGRAMS = desmume-cli -desmume_cli_SOURCES = main.c ../sndsdl.c ../ctrlssdl.h ../ctrlssdl.c +desmume_cli_SOURCES = main.cpp ../sndsdl.cpp ../ctrlssdl.h ../ctrlssdl.cpp desmume_cli_LDADD = ../libdesmume.a ../gdbstub/libgdbstub.a $(SDL_LIBS) diff --git a/desmume/src/cli/main.c b/desmume/src/cli/main.cpp similarity index 100% rename from desmume/src/cli/main.c rename to desmume/src/cli/main.cpp diff --git a/desmume/src/cp15.c b/desmume/src/cp15.cpp similarity index 100% rename from desmume/src/cp15.c rename to desmume/src/cp15.cpp diff --git a/desmume/src/ctrlssdl.c b/desmume/src/ctrlssdl.cpp similarity index 100% rename from desmume/src/ctrlssdl.c rename to desmume/src/ctrlssdl.cpp diff --git a/desmume/src/debug.c b/desmume/src/debug.cpp similarity index 100% rename from desmume/src/debug.c rename to desmume/src/debug.cpp diff --git a/desmume/src/debug.h b/desmume/src/debug.h index f2ee99570..4d204d65f 100644 --- a/desmume/src/debug.h +++ b/desmume/src/debug.h @@ -23,10 +23,6 @@ #include "types.h" #include -#ifdef __cplusplus -extern "C" { -#endif - typedef enum { DEBUG_STRING, DEBUG_STREAM , DEBUG_STDOUT, DEBUG_STDERR } DebugOutType; typedef struct { @@ -90,8 +86,4 @@ void LogStop(void); #define DMALOG(...) #endif -#ifdef __cplusplus -} -#endif - #endif diff --git a/desmume/src/fs-linux.c b/desmume/src/fs-linux.cpp similarity index 100% rename from desmume/src/fs-linux.c rename to desmume/src/fs-linux.cpp diff --git a/desmume/src/fs-windows.c b/desmume/src/fs-windows.cpp similarity index 100% rename from desmume/src/fs-windows.c rename to desmume/src/fs-windows.cpp diff --git a/desmume/src/fs.h b/desmume/src/fs.h index 2cbdb4da6..c48bb0da1 100644 --- a/desmume/src/fs.h +++ b/desmume/src/fs.h @@ -22,10 +22,6 @@ #include "types.h" -#ifdef __cplusplus -extern "C" { -#endif - #define FS_IS_DIR 1 #define FS_ERR_UNKNOWN -1 @@ -45,8 +41,4 @@ int FsReadNext(void * search, FsEntry * entry); void FsClose(void * search); int FsError(void); -#ifdef __cplusplus -} -#endif - #endif diff --git a/desmume/src/gdbstub.h b/desmume/src/gdbstub.h index b6fe7d560..21bdff123 100644 --- a/desmume/src/gdbstub.h +++ b/desmume/src/gdbstub.h @@ -27,9 +27,6 @@ typedef void *gdbstub_handle_t; /* * The function interface */ -#ifdef __cplusplus -extern "C" { -#endif gdbstub_handle_t createStub_gdb( u16 port, @@ -44,20 +41,21 @@ activateStub_gdb( gdbstub_handle_t stub, struct armcpu_ctrl_iface *cpu_ctrl); +#ifdef __cplusplus +#define EXTERNC extern "C" +#else +#define EXTERNC +#endif + /* * An implementation of the following functions is required * for the GDB stub to function. */ -void * +EXTERNC void * createThread_gdb( void (*thread_function)( void *data), void *thread_data); -void +EXTERNC void joinThread_gdb( void *thread_handle); - -#ifdef __cplusplus -} -#endif - #endif /* End of _GDBSTUB_H_ */ diff --git a/desmume/src/instruction_tabdef.inc b/desmume/src/instruction_tabdef.inc index f63763a73..a06ca2ec8 100644 --- a/desmume/src/instruction_tabdef.inc +++ b/desmume/src/instruction_tabdef.inc @@ -31,7 +31,7 @@ TYPE_RETOUR (*CALLTYPE NOM_TAB[4096])(PARAMETRES)={ OP_AND_LSL_IMM, // 000 0000 0 1000 OP_MUL, // 000 0000 0 1001 - OP_AND_LSR_IMM, // OOO OOOO O 1010 + OP_AND_LSR_IMM, // 000 0000 0 1010 OP_STRH_POS_INDE_M_REG_OFF, // 000 0000 0 1011 OP_AND_ASR_IMM, // 000 0000 0 1100 OP_LDRD_STRD_POST_INDEX, diff --git a/desmume/src/matrix.c b/desmume/src/matrix.cpp similarity index 79% rename from desmume/src/matrix.c rename to desmume/src/matrix.cpp index b7ce14092..b5b240abb 100644 --- a/desmume/src/matrix.c +++ b/desmume/src/matrix.cpp @@ -24,38 +24,16 @@ #include #include "matrix.h" +extern "C" { + void MatrixInit (float *matrix) { memset (matrix, 0, sizeof(float)*16); matrix[0] = matrix[5] = matrix[10] = matrix[15] = 1.f; } -#ifdef SSE2 -void __fastcall MatrixIdentity (float *matrix) //============== TODO -{ - memset (matrix, 0, sizeof(float)*16); - matrix[0] = matrix[5] = matrix[10] = matrix[15] = 1.f; -} - -float __fastcall MatrixGetMultipliedIndex (int index, float *matrix, float *rightMatrix) -{ - int iMod = index%4, iDiv = (index>>2)<<2; - - return (matrix[iMod ]*rightMatrix[iDiv ])+(matrix[iMod+ 4]*rightMatrix[iDiv+1])+ - (matrix[iMod+8]*rightMatrix[iDiv+2])+(matrix[iMod+12]*rightMatrix[iDiv+3]); -} - -void __fastcall MatrixSet (float *matrix, int x, int y, float value) // TODO -{ - matrix [x+(y<<2)] = value; -} - -void __fastcall MatrixCopy (float *matrixDST, float *matrixSRC) -{ - memcpy (matrixDST, matrixSRC, sizeof(float)*16); -} -#else -void MatrixMultVec4x4 (float *matrix, float *vecPtr) +#ifndef SSE2 +void __fastcall MatrixMultVec4x4 (const float *matrix, float *vecPtr) { float x = vecPtr[0]; float y = vecPtr[1]; @@ -68,7 +46,7 @@ void MatrixMultVec4x4 (float *matrix, float *vecPtr) vecPtr[3] = x * matrix[3] + y * matrix[7] + z * matrix[11] + w * matrix[15]; } -void MatrixMultVec3x3 (float *matrix, float *vecPtr) +void __fastcall MatrixMultVec3x3 (const float *matrix, float *vecPtr) { float x = vecPtr[0]; float y = vecPtr[1]; @@ -79,14 +57,7 @@ void MatrixMultVec3x3 (float *matrix, float *vecPtr) vecPtr[2] = x * matrix[2] + y * matrix[6] + z * matrix[10]; } -void MatrixIdentity (float *matrix) -{ - memset (matrix, 0, sizeof(float)*16); - - matrix[0] = matrix[5] = matrix[10] = matrix[15] = 1.f; -} - -void MatrixMultiply (float *matrix, float *rightMatrix) +void __fastcall MatrixMultiply (float *matrix, const float *rightMatrix) { float tmpMatrix[16]; @@ -113,50 +84,7 @@ void MatrixMultiply (float *matrix, float *rightMatrix) memcpy (matrix, tmpMatrix, sizeof(float)*16); } -float MatrixGetMultipliedIndex (int index, float *matrix, float *rightMatrix) -{ - int iMod = index%4, iDiv = (index>>2)<<2; - - return (matrix[iMod ]*rightMatrix[iDiv ])+(matrix[iMod+ 4]*rightMatrix[iDiv+1])+ - (matrix[iMod+8]*rightMatrix[iDiv+2])+(matrix[iMod+12]*rightMatrix[iDiv+3]); -} - -void MatrixSet (float *matrix, int x, int y, float value) -{ - matrix [x+(y<<2)] = value; -} - -void MatrixTranspose(float *matrix) -{ - float temp; -#define swap(A,B) temp = matrix[A];matrix[A] = matrix[B]; matrix[B] = temp; - swap(1,4); - swap(2,8); - swap(3,0xC); - swap(6,9); - swap(7,0xD); - swap(0xB,0xE); -#undef swap - -/* -0 1 2 3 -4 5 6 7 -8 9 A B -C D E F - -0 4 8 C -1 5 9 D -2 6 A E -3 7 B F -*/ -} - -void MatrixCopy (float *matrixDST, float *matrixSRC) -{ - memcpy (matrixDST, matrixSRC, sizeof(float)*16); -} - -void MatrixTranslate (float *matrix, float *ptr) +void __fastcall MatrixTranslate (float *matrix, const float *ptr) { matrix[12] += (matrix[0]*ptr[0])+(matrix[4]*ptr[1])+(matrix[ 8]*ptr[2]); matrix[13] += (matrix[1]*ptr[0])+(matrix[5]*ptr[1])+(matrix[ 9]*ptr[2]); @@ -164,7 +92,7 @@ void MatrixTranslate (float *matrix, float *ptr) matrix[15] += (matrix[3]*ptr[0])+(matrix[7]*ptr[1])+(matrix[11]*ptr[2]); } -void MatrixScale (float *matrix, float *ptr) +void __fastcall MatrixScale (float *matrix, const float *ptr) { matrix[0] *= ptr[0]; matrix[1] *= ptr[0]; @@ -181,9 +109,46 @@ void MatrixScale (float *matrix, float *ptr) matrix[10] *= ptr[2]; matrix[11] *= ptr[2]; } -#endif +#endif //switched c/asm functions //----------------------------------------- +void MatrixTranspose(float *matrix) +{ + float temp; +#define swap(A,B) temp = matrix[A];matrix[A] = matrix[B]; matrix[B] = temp; + swap(1,4); + swap(2,8); + swap(3,0xC); + swap(6,9); + swap(7,0xD); + swap(0xB,0xE); +#undef swap +} + +void __fastcall MatrixIdentity (float *matrix) //============== TODO +{ + memset (matrix, 0, sizeof(float)*16); + matrix[0] = matrix[5] = matrix[10] = matrix[15] = 1.f; +} + +float __fastcall MatrixGetMultipliedIndex (int index, float *matrix, float *rightMatrix) +{ + int iMod = index%4, iDiv = (index>>2)<<2; + + return (matrix[iMod ]*rightMatrix[iDiv ])+(matrix[iMod+ 4]*rightMatrix[iDiv+1])+ + (matrix[iMod+8]*rightMatrix[iDiv+2])+(matrix[iMod+12]*rightMatrix[iDiv+3]); +} + +void __fastcall MatrixSet (float *matrix, int x, int y, float value) // TODO +{ + matrix [x+(y<<2)] = value; +} + +void __fastcall MatrixCopy (float* matrixDST, const float* matrixSRC) +{ + memcpy ((void*)matrixDST, matrixSRC, sizeof(float)*16); +} + void MatrixStackInit (MatrixStack *stack) { stack->matrix = NULL; @@ -226,7 +191,7 @@ void MatrixStackSetStackPosition (MatrixStack *stack, int pos) stack->position = stack->size; } -void MatrixStackPushMatrix (MatrixStack *stack, float *ptr) +void MatrixStackPushMatrix (MatrixStack *stack, const float *ptr) { MatrixCopy (&stack->matrix[stack->position*16], ptr); @@ -250,38 +215,38 @@ float * MatrixStackGet (MatrixStack *stack) return &stack->matrix[stack->position*16]; } -void MatrixStackLoadMatrix (MatrixStack *stack, int pos, float *ptr) +void MatrixStackLoadMatrix (MatrixStack *stack, int pos, const float *ptr) { MatrixCopy (&stack->matrix[pos*16], ptr); } -float Vector3Dot(float *a, float *b) +float Vector3Dot(const float *a, const float *b) { return a[0]*b[0] + a[1]*b[1] + a[2]*b[2]; } -float Vector3Length(float *a) +float Vector3Length(const float *a) { float lengthSquared = Vector3Dot(a,a); float length = sqrt(lengthSquared); return length; } -void Vector3Add(float *dst, float *src) +void Vector3Add(float *dst, const float *src) { dst[0] += src[0]; dst[1] += src[1]; dst[2] += src[2]; } -void Vector3Scale(float *dst, float scale) +void Vector3Scale(float *dst, const float scale) { dst[0] *= scale; dst[1] *= scale; dst[2] *= scale; } -void Vector3Copy(float *dst, float *src) +void Vector3Copy(float *dst, const float *src) { dst[0] = src[0]; dst[1] = src[1]; @@ -294,10 +259,12 @@ void Vector3Normalize(float *dst) Vector3Scale(dst,1.0f/length); } -void Vector4Copy(float *dst, float *src) +void Vector4Copy(float *dst, const float *src) { dst[0] = src[0]; dst[1] = src[1]; dst[2] = src[2]; dst[3] = src[3]; -} \ No newline at end of file +} + +} //extern "C" \ No newline at end of file diff --git a/desmume/src/matrix.h b/desmume/src/matrix.h index 8e8481e4d..04fdeb772 100644 --- a/desmume/src/matrix.h +++ b/desmume/src/matrix.h @@ -23,9 +23,7 @@ #include "types.h" -#ifdef __cplusplus -extern "C" { -#endif +extern "C" { #ifdef SSE2 #include @@ -48,51 +46,36 @@ typedef struct MatrixStack } MatrixStack; void MatrixInit (float *matrix); -#ifdef SSE2 -extern void __fastcall MatrixMultVec3x3 (const gMatrix matrix, const gMatrix vecPtr); -extern void __fastcall MatrixMultVec4x4 (const gMatrix matrix, const gMatrix vecPtr); -void __fastcall MatrixIdentity (float *matrix); -extern void __fastcall MatrixMultiply (const gMatrix matrix, const gMatrix rightMatrix); + +void __fastcall MatrixMultVec3x3 (const float * matrix, float * vecPtr); +void __fastcall MatrixMultVec4x4 (const float * matrix, float * vecPtr); +void __fastcall MatrixMultiply (float * matrix, const float * rightMatrix); +void __fastcall MatrixTranslate (float *matrix, const float *ptr); +void __fastcall MatrixScale (float * matrix, const float * ptr); float __fastcall MatrixGetMultipliedIndex (int index, float *matrix, float *rightMatrix); void __fastcall MatrixSet (float *matrix, int x, int y, float value); -void __fastcall MatrixCopy (const gMatrix matrixDST, const gMatrix matrixSRC); -extern void __fastcall MatrixTranslate (float *matrix, float *ptr); -extern void __fastcall MatrixScale (const gMatrix matrix, const gMatrix ptr); -void __fastcall MatrixScale (const gMatrix matrix, const gMatrix ptr); -#else -void MatrixMultVec3x3 (float *matrix, float *vecPtr); -void MatrixMultVec4x4 (float *matrix, float *vecPtr); -void MatrixIdentity (float *matrix); -void MatrixMultiply (float *matrix, float *rightMatrix); -float MatrixGetMultipliedIndex(int index, float *matrix, float *rightMatrix); -void MatrixSet (float *matrix, int x, int y, float value); -void MatrixCopy (float *matrixDST, float *matrixSRC); -void MatrixTranslate (float *matrix, float *ptr); -void MatrixScale (float *matrix, float *ptr); -#endif - -void MatrixTranspose(float *matrix); +void __fastcall MatrixCopy (float * matrixDST, const float * matrixSRC); +void __fastcall MatrixIdentity (float *matrix); +void MatrixTranspose (float *matrix); void MatrixStackInit (MatrixStack *stack); void MatrixStackSetMaxSize (MatrixStack *stack, int size); void MatrixStackSetStackPosition (MatrixStack *stack, int pos); -void MatrixStackPushMatrix (MatrixStack *stack, float *ptr); +void MatrixStackPushMatrix (MatrixStack *stack, const float *ptr); float* MatrixStackPopMatrix (MatrixStack *stack, int size); float* MatrixStackGetPos (MatrixStack *stack, int pos); float* MatrixStackGet (MatrixStack *stack); -void MatrixStackLoadMatrix (MatrixStack *stack, int pos, float *ptr); +void MatrixStackLoadMatrix (MatrixStack *stack, int pos, const float *ptr); -float Vector3Dot(float *a, float *b); -float Vector3Length(float *a); -void Vector3Add(float *dst, float *src); -void Vector3Scale(float *dst, float scale); -void Vector3Copy(float *dst, float *src); +float Vector3Dot(const float *a, const float *b); +float Vector3Length(const float *a); +void Vector3Add(float *dst, const float *src); +void Vector3Scale(float *dst, const float scale); +void Vector3Copy(float *dst, const float *src); void Vector3Normalize(float *dst); -void Vector4Copy(float *dst, float *src); +void Vector4Copy(float *dst, const float *src); -#ifdef __cplusplus -} -#endif +} //extern "C" #endif diff --git a/desmume/src/mc.c b/desmume/src/mc.cpp similarity index 99% rename from desmume/src/mc.c rename to desmume/src/mc.cpp index 226dcc48c..1e2abb526 100644 --- a/desmume/src/mc.c +++ b/desmume/src/mc.cpp @@ -80,7 +80,7 @@ void mc_init(memory_chip_t *mc, int type) u8 *mc_alloc(memory_chip_t *mc, u32 size) { u8 *buffer; - buffer = malloc(size); + buffer = new u8[size]; mc->data = buffer; if(!buffer) { return NULL; } @@ -92,8 +92,8 @@ u8 *mc_alloc(memory_chip_t *mc, u32 size) void mc_free(memory_chip_t *mc) { - if(mc->data) free(mc->data); - mc_init(mc, 0); + if(mc->data) delete[] mc->data; + mc_init(mc, 0); } void mc_reset_com(memory_chip_t *mc) diff --git a/desmume/src/mc.h b/desmume/src/mc.h index f78b7c39f..04ec6d599 100644 --- a/desmume/src/mc.h +++ b/desmume/src/mc.h @@ -21,10 +21,6 @@ #ifndef __FW_H__ #define __FW_H__ -#ifdef __cplusplus -extern "C" { -#endif - #include #include "types.h" @@ -86,9 +82,5 @@ void mc_reset_com(memory_chip_t *mc); /* reset communication with mc */ u8 fw_transfer(memory_chip_t *mc, u8 data); /* transfer to, then receive data from firmware */ u8 bm_transfer(memory_chip_t *mc, u8 data); /* transfer to, then receive data from backup memory */ -#ifdef __cplusplus -} -#endif - #endif /*__FW_H__*/ diff --git a/desmume/src/render3D.c b/desmume/src/render3D.cpp similarity index 100% rename from desmume/src/render3D.c rename to desmume/src/render3D.cpp diff --git a/desmume/src/render3D.h b/desmume/src/render3D.h index f869e27ab..fac293c22 100644 --- a/desmume/src/render3D.h +++ b/desmume/src/render3D.h @@ -27,10 +27,6 @@ #define CALL_CONVENTION #endif -#ifdef __cplusplus -extern "C" { -#endif - /* enum DRIVER_3D { @@ -146,8 +142,4 @@ extern GPU3DInterface *gpu3D; void NDS_3D_SetDriver (int core3DIndex); -#ifdef __cplusplus -} -#endif - #endif diff --git a/desmume/src/saves.c b/desmume/src/saves.cpp similarity index 99% rename from desmume/src/saves.c rename to desmume/src/saves.cpp index f2ebf103e..19c82e99a 100644 --- a/desmume/src/saves.c +++ b/desmume/src/saves.cpp @@ -30,6 +30,8 @@ #include #include +savestates_t savestates[NB_STATES]; + #define SAVESTATE_VERSION 010 #ifndef MAX_PATH diff --git a/desmume/src/saves.h b/desmume/src/saves.h index 85004a926..e97d27f8e 100644 --- a/desmume/src/saves.h +++ b/desmume/src/saves.h @@ -21,10 +21,6 @@ #ifndef _SRAM_H #define _SRAM_H -#ifdef __cplusplus -extern "C" { -#endif - #include "types.h" #define SRAM_ADDRESS 0x0A000000 @@ -37,7 +33,7 @@ typedef struct char date[40]; } savestates_t; -savestates_t savestates[NB_STATES]; +extern savestates_t savestates[NB_STATES]; void clear_savestates(); void scan_savestates(); @@ -52,8 +48,4 @@ int savestate_save (const char *file_name); void savestate_slot(int num); void loadstate_slot(int num); -#ifdef __cplusplus -} -#endif - #endif diff --git a/desmume/src/sndsdl.c b/desmume/src/sndsdl.cpp similarity index 100% rename from desmume/src/sndsdl.c rename to desmume/src/sndsdl.cpp diff --git a/desmume/src/thumb_instructions.c b/desmume/src/thumb_instructions.cpp similarity index 98% rename from desmume/src/thumb_instructions.c rename to desmume/src/thumb_instructions.cpp index fbe5e31c8..f592a62bb 100644 --- a/desmume/src/thumb_instructions.c +++ b/desmume/src/thumb_instructions.cpp @@ -24,6 +24,11 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +//zero 9/8/08 - fixed a bug +//SIGNED_UNDERFLOW(a, (!cpu->CPSR.bits.C), tmp) +//was being called. but SIGNED_UNDERFLOW expects values in bit31. replaced with +//SIGNED_UNDERFLOW(a, (cpu->CPSR.bits.C?0:0x80000000), tmp) + #include "bios.h" #include "debug.h" #include "MMU.h" @@ -365,8 +370,8 @@ static u32 FASTCALL OP_SBC_REG(armcpu_t *cpu) cpu->CPSR.bits.N = BIT31(res); cpu->CPSR.bits.Z = res == 0; - cpu->CPSR.bits.C = (!UNSIGNED_UNDERFLOW(a, !cpu->CPSR.bits.C, tmp)) & (!UNSIGNED_OVERFLOW(tmp, b, res)); - cpu->CPSR.bits.V = SIGNED_UNDERFLOW(a, !cpu->CPSR.bits.C, tmp) | SIGNED_OVERFLOW(tmp, b, res); + cpu->CPSR.bits.C = (!UNSIGNED_UNDERFLOW(a, (cpu->CPSR.bits.C?0:0x80000000), tmp)) & (!UNSIGNED_OVERFLOW(tmp, b, res)); + cpu->CPSR.bits.V = SIGNED_UNDERFLOW(a, (cpu->CPSR.bits.C?0:0x80000000), tmp) | SIGNED_OVERFLOW(tmp, b, res); return 3; } diff --git a/desmume/src/wifi.c b/desmume/src/wifi.cpp similarity index 100% rename from desmume/src/wifi.c rename to desmume/src/wifi.cpp diff --git a/desmume/src/wifi.h b/desmume/src/wifi.h index 7a513d780..925b82fc2 100644 --- a/desmume/src/wifi.h +++ b/desmume/src/wifi.h @@ -22,10 +22,6 @@ #ifndef WIFI_H #define WIFI_H -#ifdef __cplusplus -extern "C" { -#endif - /* standardize socket interface for linux and windows */ #ifdef WIN32 #include @@ -459,10 +455,6 @@ extern u8 FW_RFChannel[6*14] ; extern u8 FW_BBChannel[14] ; extern u8 FW_WFCProfile[0xC0] ; -#ifdef __cplusplus -} -#endif - #endif #endif /* #ifdef EXPERIMENTAL_WIFI */ diff --git a/desmume/src/windows/DeSmuME_2005.vcproj b/desmume/src/windows/DeSmuME_2005.vcproj index 5748b09ea..e8ae0b188 100644 --- a/desmume/src/windows/DeSmuME_2005.vcproj +++ b/desmume/src/windows/DeSmuME_2005.vcproj @@ -546,19 +546,19 @@ > - - - @@ -666,7 +658,7 @@ > diff --git a/desmume/src/windows/OGLRender.cpp b/desmume/src/windows/OGLRender.cpp index 95007ed8d..003fc4105 100644 --- a/desmume/src/windows/OGLRender.cpp +++ b/desmume/src/windows/OGLRender.cpp @@ -1536,9 +1536,9 @@ __forceinline void NDS_glFlush(unsigned long v) glBegin(type==3?GL_TRIANGLES:GL_QUADS); for(j=0;jlist[poly->vertIndexes[j]]; - float tempCoord[4]; - Vector4Copy(tempCoord,vert->coord); + //float tempCoord[4]; + //Vector4Copy(tempCoord,vert->coord); //we havent got the whole pipeline working yet, so we cant do this ////convert from ds device coords to opengl //tempCoord[0] *= 2; @@ -1549,7 +1549,8 @@ __forceinline void NDS_glFlush(unsigned long v) //todo - edge flag? glTexCoord2fv(vert->texcoord); glColor4iv(vert->color); - glVertex3fv(tempCoord); + //glVertex3fv(tempCoord); + glVertex3fv(vert->coord); } glEnd(); } diff --git a/desmume/src/windows/main.cpp b/desmume/src/windows/main.cpp index c1a37f740..a2e730342 100644 --- a/desmume/src/windows/main.cpp +++ b/desmume/src/windows/main.cpp @@ -116,7 +116,6 @@ int sndcoretype=SNDCORE_DIRECTX; int sndbuffersize=735*4; int sndvolume=100; -extern "C" { SoundInterface_struct *SNDCoreList[] = { &SNDDummy, &SNDFile, @@ -128,7 +127,6 @@ GPU3DInterface *core3DList[] = { &gpu3DNull, &gpu3Dgl, }; -} int autoframeskipenab=1; int frameskiprate=0; @@ -659,7 +657,7 @@ BOOL LoadROM(char * filename, const char *cflash_disk_image) /* * The thread handling functions needed by the GDB stub code. */ -void * +extern "C" void * createThread_gdb( void (*thread_function)( void *data), void *thread_data) { void *new_thread = CreateThread( NULL, 0, @@ -669,7 +667,7 @@ createThread_gdb( void (*thread_function)( void *data), return new_thread; } -void +extern "C" void joinThread_gdb( void *thread_handle) { }