diff --git a/Fitd/fitd.cpp b/Fitd/fitd.cpp index 3eaff39..76a82e4 100644 --- a/Fitd/fitd.cpp +++ b/Fitd/fitd.cpp @@ -1,12 +1,12 @@ extern "C" { int FitdMain(int argc, char* argv[]); -} - +} + int FitdInit(int argc, char* argv[]); int main(int argc, char* argv[]) -{ +{ FitdInit(argc, argv); FitdMain(argc, argv); return 0; -} +} diff --git a/FitdLib/AITD1_Tatou.cpp b/FitdLib/AITD1_Tatou.cpp index 6d08c5a..80937f0 100644 --- a/FitdLib/AITD1_Tatou.cpp +++ b/FitdLib/AITD1_Tatou.cpp @@ -16,17 +16,18 @@ int make3dTatou(void) { char* tatou2d; char* tatou3d; - unsigned char* tatouPal; int time; int deltaTime; int rotation; int unk1; - unsigned char paletteBackup[768]; unsigned int localChrono; + palette_t tatouPal; + palette_t paletteBackup; tatou2d = CheckLoadMallocPak("ITD_RESS",AITD1_TATOU_MCG); tatou3d = CheckLoadMallocPak("ITD_RESS",AITD1_TATOU_3DO); - tatouPal = (unsigned char*)CheckLoadMallocPak("ITD_RESS",AITD1_TATOU_PAL); + char* tatouPalRaw = CheckLoadMallocPak("ITD_RESS",AITD1_TATOU_PAL); + copyPalette(tatouPalRaw, tatouPal); time = 8920; deltaTime = 50; @@ -58,15 +59,18 @@ int make3dTatou(void) //timeGlobal++; timer = timeGlobal; - if(evalChrono(&localChrono)<=180) // avant eclair + if(evalChrono(&localChrono)<=180) { + // before lightning strike if(key || Click) { break; } } - else // eclair + else { + // lightning strike + /* LastSample = -1; LastPriority = -1; */ @@ -95,8 +99,10 @@ int make3dTatou(void) osystem_CopyBlockPhys((unsigned char*)frontBuffer,0,0,320,200); - while(key==0 && Click == 0 && JoyD == 0) // boucle de rotation du tatou + while(key==0 && Click == 0 && JoyD == 0) { + // Armadillo rotation loop + process_events(); time+=deltaTime-25; @@ -121,7 +127,6 @@ int make3dTatou(void) } }while(1); - free(tatouPal); free(tatou3d); free(tatou2d); @@ -133,13 +138,13 @@ int make3dTatou(void) } FadeOutPhys(32,0); - copyPalette((unsigned char*)paletteBackup,currentGamePalette); + copyPalette(paletteBackup,currentGamePalette); return(1); } else { FadeOutPhys(16,0); - copyPalette((unsigned char*)paletteBackup,currentGamePalette); + copyPalette(paletteBackup,currentGamePalette); return(0); } diff --git a/FitdLib/AITD2.cpp b/FitdLib/AITD2.cpp index adeadf5..950ab24 100644 --- a/FitdLib/AITD2.cpp +++ b/FitdLib/AITD2.cpp @@ -291,8 +291,8 @@ void AITD2_ReadBook(int index, int type) case 0: // READ_MESSAGE { LoadPak("ITD_RESS", AITD2_LETTRE, aux); - unsigned char lpalette[0x300]; - copyPalette((unsigned char*)aux+64000,lpalette); + palette_t lpalette; + copyPalette(aux+64000,lpalette); convertPaletteIfRequired(lpalette); copyPalette(lpalette,currentGamePalette); setPalette(lpalette); @@ -304,8 +304,8 @@ void AITD2_ReadBook(int index, int type) case 1: // READ_BOOK { LoadPak("ITD_RESS", AITD2_LIVRE, aux); - unsigned char lpalette[0x300]; - copyPalette((unsigned char*)aux+64000,lpalette); + palette_t lpalette; + copyPalette(aux+64000,lpalette); convertPaletteIfRequired(lpalette); copyPalette(lpalette,currentGamePalette); setPalette(lpalette); @@ -317,8 +317,8 @@ void AITD2_ReadBook(int index, int type) case 2: // READ_CARNET { LoadPak("ITD_RESS", AITD2_CARNET, aux); - unsigned char lpalette[0x300]; - copyPalette((unsigned char*)aux+64000,lpalette); + palette_t lpalette; + copyPalette(aux+64000,lpalette); convertPaletteIfRequired(lpalette); copyPalette(lpalette,currentGamePalette); setPalette(lpalette); diff --git a/FitdLib/JACK.cpp b/FitdLib/JACK.cpp index 580c805..d8c75e1 100644 --- a/FitdLib/JACK.cpp +++ b/FitdLib/JACK.cpp @@ -20,7 +20,8 @@ void JACK_ReadBook(int index, int type) { unsigned char* pImage = (unsigned char*)loadPak("ITD_RESS", JACK_LIVRE); memcpy(aux, pImage, 320*200); - unsigned char* lpalette = pImage+320*200; + palette_t lpalette; + copyPalette(aux + 64000, lpalette); convertPaletteIfRequired(lpalette); copyPalette(lpalette,currentGamePalette); setPalette(lpalette); diff --git a/FitdLib/common.h b/FitdLib/common.h index 57ca483..fe05147 100644 --- a/FitdLib/common.h +++ b/FitdLib/common.h @@ -87,7 +87,7 @@ int getCVarsIdx(int); ////////////////// - + #if !AITD_UE4 typedef unsigned char uint8; typedef unsigned short uint16; @@ -98,7 +98,7 @@ typedef unsigned int uint; typedef signed char int8; typedef signed short int16; typedef signed long int32; -#endif +#endif typedef unsigned char U8; typedef unsigned short U16; @@ -147,6 +147,7 @@ typedef signed long S32; #include "fmopl.h" #include "main.h" #include "sequence.h" +#include "palette.h" // include game specific stuff #include "AITD1.h" @@ -180,16 +181,16 @@ typedef signed long S32; #define FORCEINLINE inline #endif #endif - -FORCEINLINE u8 READ_LE_U8(void *ptr) -{ - return *(u8*)ptr; -} - -FORCEINLINE s8 READ_LE_S8(void *ptr) -{ - return *(s8*)ptr; -} + +FORCEINLINE u8 READ_LE_U8(void *ptr) +{ + return *(u8*)ptr; +} + +FORCEINLINE s8 READ_LE_S8(void *ptr) +{ + return *(s8*)ptr; +} FORCEINLINE u16 READ_LE_U16(void *ptr) { diff --git a/FitdLib/input.cpp b/FitdLib/input.cpp index 266174c..bd0d889 100644 --- a/FitdLib/input.cpp +++ b/FitdLib/input.cpp @@ -6,18 +6,18 @@ extern float nearVal; extern float farVal; extern float cameraZoom; extern float fov; - -extern bool debuggerVar_debugMenuDisplayed; - -void handleKeyDown(SDL_Event& event) -{ - switch (event.key.key) - { - case SDL_SCANCODE_GRAVE: - debuggerVar_debugMenuDisplayed ^= 1; - break; - } -} + +extern bool debuggerVar_debugMenuDisplayed; + +void handleKeyDown(SDL_Event& event) +{ + switch (event.key.key) + { + case SDL_SCANCODE_GRAVE: + debuggerVar_debugMenuDisplayed ^= 1; + break; + } +} void readKeyboard(void) { @@ -34,9 +34,9 @@ void readKeyboard(void) ImGui_ImplSDL3_ProcessEvent(&event); - switch (event.type) { - case SDL_EVENT_KEY_DOWN: - handleKeyDown(event); + switch (event.type) { + case SDL_EVENT_KEY_DOWN: + handleKeyDown(event); break; case SDL_EVENT_QUIT: cleanupAndExit(); @@ -111,7 +111,7 @@ void readKeyboard(void) case SDL_SCANCODE_SPACE: Click = 1; break; -#ifdef FITD_DEBUGGER +#ifdef FITD_DEBUGGER case SDL_SCANCODE_O: debufferVar_topCameraZoom += 100; break; diff --git a/FitdLib/life.cpp b/FitdLib/life.cpp index 5eff648..f07aa58 100644 --- a/FitdLib/life.cpp +++ b/FitdLib/life.cpp @@ -1643,8 +1643,8 @@ void processLife(int lifeNum, bool callFoundLife) FadeOutPhys(32, 0); LoadPak("ITD_RESS", lifeTempVar1, aux); - unsigned char lpalette[0x300]; - copyPalette((unsigned char*)aux + 64000, lpalette); + palette_t lpalette; + copyPalette(aux + 64000, lpalette); convertPaletteIfRequired(lpalette); copyPalette(lpalette, currentGamePalette); setPalette(lpalette); @@ -2004,8 +2004,8 @@ void processLife(int lifeNum, bool callFoundLife) if (g_gameId > AITD1) { FadeOutPhys(0x10, 0); - unsigned char lpalette[0x300]; - copyPalette((unsigned char*)aux + 64000, lpalette); + palette_t lpalette; + copyPalette(aux + 64000, lpalette); convertPaletteIfRequired(lpalette); copyPalette(lpalette, currentGamePalette); setPalette(lpalette); diff --git a/FitdLib/main.cpp b/FitdLib/main.cpp index 4a0f7cc..27c2b03 100644 --- a/FitdLib/main.cpp +++ b/FitdLib/main.cpp @@ -582,7 +582,7 @@ void fillBox(int x1, int y1, int x2, int y2, char color) // fast recode. No RE void loadPalette(void) { - unsigned char localPalette[768]; + palette_t localPalette; if(g_gameId == AITD2) { @@ -592,7 +592,7 @@ void loadPalette(void) { LoadPak("ITD_RESS",3,aux); } - copyPalette((unsigned char*)aux,currentGamePalette); + copyPalette(aux,currentGamePalette); copyPalette(currentGamePalette,localPalette); // fadeInSub1(localPalette); @@ -1335,11 +1335,15 @@ void loadCamera(int cameraIdx) } else { - memcpy(currentGamePalette,defaultPalette,0x30); - convertPaletteIfRequired((unsigned char*)currentGamePalette); + for (int i = 0; i < 16; i++) { + currentGamePalette[i][0] = defaultPalette[i * 3 + 0]; + currentGamePalette[i][1] = defaultPalette[i * 3 + 1]; + currentGamePalette[i][2] = defaultPalette[i * 3 + 2]; + } + convertPaletteIfRequired(currentGamePalette); } - osystem_setPalette(currentGamePalette); + osystem_setPalette(¤tGamePalette); } } diff --git a/FitdLib/osystem.h b/FitdLib/osystem.h index 53fc4cd..e79bd34 100644 --- a/FitdLib/osystem.h +++ b/FitdLib/osystem.h @@ -10,7 +10,8 @@ #include "debugFont.h" #endif -extern "C"{ +#include "palette.h" + #endif #define byte char @@ -49,6 +50,7 @@ extern "C"{ void osystem_putpixel(int x, int y, int pixel); void osystem_setColor(byte i, byte R, byte G, byte B); void osystem_setPalette(unsigned byte * palette); + void osystem_setPalette(palette_t* palette); void osystem_setPalette320x200(byte * palette); void osystem_flip(unsigned char *videoBuffer); void osystem_draw320x200BufferToScreen(unsigned char *videoBuffer); @@ -57,7 +59,6 @@ extern "C"{ void osystem_drawText(int X, int Y, char *text); void osystem_drawTextColor(int X, int Y, char *string, unsigned char R, unsigned char G, unsigned char B); void osystem_drawLine(int X1,int X2,int Y1,int Y2,unsigned char color, unsigned char* palette); - void osystem_getPalette(unsigned char* palette); void osystem_playSampleFromName(char* sampleName); void osystem_playSample(char* samplePtr,int size); // void getMouseStatus(mouseStatusStruct * mouseData); @@ -90,8 +91,4 @@ extern "C"{ int osystem_playTrack(int trackId); void osystem_playAdlib(); -#ifdef __cplusplus -} -#endif - #endif diff --git a/FitdLib/palette.cpp b/FitdLib/palette.cpp new file mode 100644 index 0000000..ba357bd --- /dev/null +++ b/FitdLib/palette.cpp @@ -0,0 +1,63 @@ +#include "common.h" +#include "palette.h" + +void paletteFill(palette_t& palette, unsigned char r, unsigned char g, unsigned b) +{ + r <<= 1; + g <<= 1; + b <<= 1; + + for (int i = 0; i < 256; i++) + { + palette[i][0] = r; + palette[i][1] = g; + palette[i][2] = b; + } +} + +void setPalette(palette_t& sourcePal) +{ + osystem_setPalette(&sourcePal); +} + +void copyPalette(palette_t& source, palette_t& dest) +{ + for (int i = 0; i < 256; i++) + { + dest[i] = source[i]; + } +} + +void copyPalette(void* source, palette_t& dest) +{ + for (int i = 0; i < 256; i++) + { + for (int j = 0; j < 3; j++) { + dest[i][j] = ((uint8*)source)[i * 3 + j]; + } + } +} + +void convertPaletteIfRequired(palette_t& lpalette) +{ + if (g_gameId >= JACK && g_gameId < AITD3) + { + for (int i = 0; i < 256; i++) + { + for (int j = 0; j < 3; j++) + { + lpalette[i][j] = (((unsigned int)lpalette[i][j] * 255) / 63) & 0xFF; + } + } + } +} + +void computePalette(palette_t& inPalette, palette_t& outPalette, int coef) +{ + for (int i = 0; i < 256; i++) + { + for (int j = 0; j < 3; j++) { + outPalette[i][j] = (inPalette[i][j] * coef) >> 8; + } + } +} \ No newline at end of file diff --git a/FitdLib/palette.h b/FitdLib/palette.h new file mode 100644 index 0000000..f409909 --- /dev/null +++ b/FitdLib/palette.h @@ -0,0 +1,12 @@ +#pragma once + +#include +typedef std::array, 256> palette_t; +void paletteFill(palette_t& palette, unsigned char r, unsigned char g, unsigned b); +void setPalette(palette_t& palette); +void copyPalette(void* source, palette_t& dest); +void copyPalette(palette_t& source, palette_t& dest); +void convertPaletteIfRequired(palette_t& lpalette); +void computePalette(palette_t& inPalette, palette_t& outPalette, int coef); + +extern palette_t currentGamePalette; diff --git a/FitdLib/rendererBGFX.cpp b/FitdLib/rendererBGFX.cpp index 2a2444f..917dcf3 100644 --- a/FitdLib/rendererBGFX.cpp +++ b/FitdLib/rendererBGFX.cpp @@ -208,9 +208,15 @@ void osystem_setPalette(u8* palette) bgfx::updateTexture2D(g_paletteTexture, 0, 0, 0, 0, 3, 256, bgfx::copy(RGB_Pal, 256 * 3)); } -void osystem_getPalette(unsigned char* palette) +void osystem_setPalette(palette_t* palette) { - memcpy(palette, RGB_Pal, 256 * 3); + for (int i = 0; i < 256; i++) { + for (int j = 0; j < 3; j++) { + RGB_Pal[i * 3 + j] = palette->at(i)[j]; + } + } + + bgfx::updateTexture2D(g_paletteTexture, 0, 0, 0, 0, 3, 256, bgfx::copy(RGB_Pal, 256 * 3)); } struct s_vertexData diff --git a/FitdLib/sequence.cpp b/FitdLib/sequence.cpp index 03d853a..e60c347 100644 --- a/FitdLib/sequence.cpp +++ b/FitdLib/sequence.cpp @@ -1,25 +1,5 @@ #include "common.h" -void convertPaletteIfRequired(unsigned char* lpalette) -{ - if(g_gameId >= JACK && g_gameId < AITD3) - { - int i; - unsigned char* ptr2 = lpalette; - for(i=0;i<256;i++) - { - int j; - for(j=0;j<3;j++) - { - unsigned int composante = *(ptr2); - composante*=255; - composante/=63; - *(ptr2++) = composante&0xFF; - } - } - } -} - const char* sequenceListAITD2[]= { "BATL", @@ -156,7 +136,6 @@ void playSequence(int sequenceIdx, int fadeStart, int fadeOutVar) int var_4 = 1; int quitPlayback = 0; int nextFrame = 1; - unsigned char localPalette[0x300]; char buffer[256]; if (g_gameId == AITD2) @@ -194,7 +173,8 @@ void playSequence(int sequenceIdx, int fadeStart, int fadeOutVar) if(!currentFrameId) // first frame { - memcpy(localPalette,logicalScreen,0x300); // copy palette + palette_t localPalette; + copyPalette(logicalScreen, localPalette); // copy palette memcpy(aux,logicalScreen+0x300,64000); nextFrame = READ_LE_U16(logicalScreen+64768); @@ -213,7 +193,7 @@ void playSequence(int sequenceIdx, int fadeStart, int fadeOutVar) flipOtherPalette(palette); } */ - osystem_setPalette(localPalette); + osystem_setPalette(&localPalette); copyPalette(localPalette,currentGamePalette); } } diff --git a/FitdLib/sequence.h b/FitdLib/sequence.h index 52ada68..824329f 100644 --- a/FitdLib/sequence.h +++ b/FitdLib/sequence.h @@ -12,5 +12,3 @@ typedef struct sequenceParamStruct sequenceParamStruct; extern int numSequenceParam; extern sequenceParamStruct sequenceParams[NUM_MAX_SEQUENCE_PARAM]; - -void convertPaletteIfRequired(unsigned char* lpalette); diff --git a/FitdLib/tatou.cpp b/FitdLib/tatou.cpp index 2adda77..65a3fe6 100644 --- a/FitdLib/tatou.cpp +++ b/FitdLib/tatou.cpp @@ -22,56 +22,13 @@ void blitScreenTatou(void) */ } -void copyPalette(unsigned char* source, unsigned char* dest) -{ - int i; - - for(i=0;i<768;i++) - { - dest[i] = source[i]; - } -} - void FastCopyScreen(void* source, void* dest) { memcpy(dest, source, 64000); } -void paletteFill(void* palette, unsigned char r, unsigned char g, unsigned b) -{ - unsigned char* paletteLocal = (unsigned char*) palette; - int offset = 0; - int i; - - r<<=1; - g<<=1; - b<<=1; - - for(i=0;i<256;i++) - { - paletteLocal[offset] = r; - paletteLocal[offset+1] = g; - paletteLocal[offset+2] = b; - offset += 3; - } -} - -void computePalette(unsigned char* inPalette, unsigned char* outPalette, int coef) -{ - int i; - - for(i=0;i<256;i++) - { - *(outPalette++) = ((*(inPalette++))*coef)>> 8; - *(outPalette++) = ((*(inPalette++))*coef)>> 8; - *(outPalette++) = ((*(inPalette++))*coef)>> 8; - } -} - void FadeInPhys(int step,int start) { - unsigned char localPalette[0x300]; - freezeTime(); if(fadeState == 2) // only used for the ending ? @@ -82,6 +39,7 @@ void FadeInPhys(int step,int start) for(int i=0;i<256;i+=step) { process_events(); + palette_t localPalette; computePalette(currentGamePalette,localPalette,i); setPalette(localPalette); osystem_refreshFrontTextureBuffer(); @@ -96,13 +54,12 @@ void FadeInPhys(int step,int start) void FadeOutPhys(int var1, int var2) { - unsigned char localPalette[0x300]; - freezeTime(); for(int i=256;i>=0;i-=var1) { process_events(); + palette_t localPalette; computePalette(currentGamePalette,localPalette,i); setPalette(localPalette); osystem_refreshFrontTextureBuffer(); @@ -112,11 +69,6 @@ void FadeOutPhys(int var1, int var2) unfreezeTime(); } -void setPalette(void* sourcePal) -{ - osystem_setPalette((unsigned char*)sourcePal); -} - #ifdef PCLIKE void process_events( void ) { diff --git a/FitdLib/tatou.h b/FitdLib/tatou.h index 72b9e2b..b7e3cf9 100644 --- a/FitdLib/tatou.h +++ b/FitdLib/tatou.h @@ -3,17 +3,15 @@ int make3dTatou(void); //////////////// to mode -void paletteFill(void* palette, unsigned char r, unsigned char g, unsigned b); -void setPalette(void* palette); -void startChrono(unsigned int* chrono); -int evalChrono(unsigned int* chrono); void process_events( void ); -void copyPalette(unsigned char* source, unsigned char* dest); void FastCopyScreen(void* source, void* dest); void Rotate(unsigned int x, unsigned int y, unsigned int z, int* xOut, int* yOut); void FadeInPhys(int var1,int var2); void FadeOutPhys(int var1, int var2); void playSound(int num); void setCameraTarget(int x,int y,int z,int alpha,int beta,int gamma,int time); + +void startChrono(unsigned int* chrono); +int evalChrono(unsigned int* chrono); ////////////// #endif diff --git a/FitdLib/vars.cpp b/FitdLib/vars.cpp index d3de9ac..f0dc4bb 100644 --- a/FitdLib/vars.cpp +++ b/FitdLib/vars.cpp @@ -29,7 +29,7 @@ char* PtrFont; char* PtrCadre; -unsigned char currentGamePalette[256*3]; +palette_t currentGamePalette; //OSystem osystem; diff --git a/FitdLib/vars.h b/FitdLib/vars.h index ff9faaa..a2d7053 100644 --- a/FitdLib/vars.h +++ b/FitdLib/vars.h @@ -284,8 +284,6 @@ extern char* PtrFont; extern char* PtrCadre; -extern unsigned char currentGamePalette[0x300]; - //extern OSystem osystem; extern unsigned char frontBuffer[320*200]; extern char rgbaBuffer[320*200*4];