1. kasicass
  2. sdl2pal

Commits

kasicass  committed 4f5684b

some palette

  • Participants
  • Parent commits d4b2022
  • Branches default

Comments (0)

Files changed (9)

File README

View file
  • Ignore whitespace
+http://sdlpal.codeplex.com/
+http://code.google.com/p/palresearch

File src/common.h

View file
  • Ignore whitespace
 
 #include <SDL2/SDL.h>
 
+// TODO difference system (iOS, Android?)
+#define PAL_PREFIX				"./"
+#define PAL_SAVE_PREFIX		"./"
+
 #ifdef __cplusplus
 }
 #endif

File src/main.c

View file
  • Ignore whitespace
 	{255, 0, 0, 0},
 };
 
+void PAL_Shutdown(void)
+{
+}
+
 int main(int argc, char *argv[])
 {
 	SDL_Event event;

File src/palcommon.h

View file
  • Ignore whitespace
+#ifndef SDL2PAL_PALCOMMON_H
+#define SDL2PAL_PALCOMMON_H
+
+#include "common.h"
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+typedef Uint8							SPRITE, BITMAPRLE;
+
+typedef Uint32						PAL_POS;
+#define PAL_XY(x, y)			(PAL_POS)(((((Uint16)(y))<<16) & 0xFFFF0000) | (((Uint16)(x)) & 0xFFFF))
+#define PAL_X(xy)					(Uint16)((xy) & 0xFFFF)
+#define PAL_Y(xy)					(Uint16)(((xy) >> 16) & 0xFFFF)
+
+typedef enum tagPALDIRECTION
+{
+	kDirSouth = 0,
+	kDirWest,
+	kDirNorth,
+	kDirEast,
+	kDirUnknown
+} PALDIRECTION;
+
+int PAL_RLEBlitToSurface(const BITMAPRLE* bitmapRLE, SDL_Surface* dstSurface, PAL_POS pos);
+int PAL_RLEBlitWithColorShift(const BITMAPRLE* bitmapRLE, SDL_Surface* dstSurface,
+			PAL_POS pos, int colorShift);
+int PAL_RLEBlitMonoColor(const BITMAPRLE* bitmapRLE, SDL_Surface* dstSurface,
+			PAL_POS pos, Uint8 color, int colorShift);
+int PAL_FBPBlitToSurface(Uint8* bitmapFBP, SDL_Surface* dstSurface);
+
+Uint32 PAL_RLEGetWidth(const BITMAPRLE* bitmapRLE);
+Uint32 PAL_RLEGetHeight(const BITMAPRLE* bitmapRLE);
+
+Sint16 PAL_SpriteGetNumFrames(const SPRITE* sprite);
+const BITMAPRLE* PAL_SpriteGetFrame(const SPRITE* sprite, int frameNum);
+
+int PAL_MKFGetChunkCount(FILE *fp);
+int PAL_MKFGetChunkSize(Uint32 chunkNum, FILE *fp);
+int PAL_MKFReadChunk(Uint8* buffer, Uint32 bufferSize, Uint32 chunkNum, FILE *fp);
+int PAL_MKFGetDecompressedSize(Uint32 chunkNum, FILE *fp);
+int PAL_MKFDecompressChunk(Uint8* buffer, Uint32 bufferSize, Uint32 chunkNum, FILE *fp);
+
+// from yj1.c
+int Decompress(const void *src, void *dst, int dstSize);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif

File src/palette.c

View file
  • Ignore whitespace
+#include "palette.h"
+
+/*
+	Purpose:
+		Get the specified palette in pat.mkf file.
+
+	Parameters:
+		[IN] paletteNum - numbe of the palette.
+		[IN] isNight - whether use the night palette or not.
+
+	Return value:
+		Pointer to the palette. NULL if failed.
+*/
+SDL_Color *PAL_GetPalette(int paletteNum, bool isNight)
+{
+}
+
+void PAL_SetPalette(int paletteNum, bool isNight);
+
+void PAL_FadeOut(int delay);
+void PAL_FadeIn(int paletteNum, bool isNight, int delay);
+
+void PAL_SceneFade(int paletteNum, bool isNight, int step);
+void PAL_PaletteFade(int paletteNum, bool isNight, int delay);
+void PAL_ColorFade(int delay, Uint8 color, bool isFrom);
+void PAL_FadeToRed(void);

File src/palette.h

View file
  • Ignore whitespace
+#ifndef SDL2PAL_PALETTE_H
+#define SDL2PAL_PALETTE_H
+
+#include "common.h"
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+SDL_Color *PAL_GetPalette(int paletteNum, bool isNight);
+void PAL_SetPalette(int paletteNum, bool isNight);
+
+void PAL_FadeOut(int delay);
+void PAL_FadeIn(int paletteNum, bool isNight, int delay);
+
+void PAL_SceneFade(int paletteNum, bool isNight, int step);
+void PAL_PaletteFade(int paletteNum, bool isNight, int delay);
+void PAL_ColorFade(int delay, Uint8 color, bool isFrom);
+void PAL_FadeToRed(void);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif

File src/util.c

View file
  • Ignore whitespace
 	return string;
 }
 
+/*
+	Purpose:
+		Terminate the game as an error occurs and prints the
+		error message provided.
+
+	Parameters:
+		[IN] format - error message.
+
+	Return value:
+		None.
+*/
+void TerminateOnError(const char *format, ...)
+{
+	va_list argptr;
+	char s[256];
+	extern void PAL_Shutdown(void);
+
+	va_start(argptr, format);
+	vsnprintf(s, sizeof(s), format, argptr);
+	va_end(argptr);
+
+	fprintf(stderr, "\nFATA ERROR: %s\n", s);
+
+#if defined(WIN32)
+	MessageBoxA(NULL, s, "FATAL ERROR", MB_ICONERROR);
+#endif
+
+#if defined(__linux__)
+	system(va("beep; xmessage -center \"FATAL ERROR: %s\"", s));
+#endif
+
+#if defined(_DEBUG)
+	assert(0 || "TerminateOnError()");	// allows jumping to debugger
+#endif
+
+	PAL_Shutdown();
+	exit(255);
+}
+
+/*
+	Purpose:
+		sleep for a while.
+
+	Parameters:
+		[IN] ms - ms to sleep.
+
+	Return value:
+		None.
+*/
 void UTIL_Delay(unsigned int ms)
 {
 	unsigned int t = SDL_GetTicks() + ms;
 	}
 }
 
+/*
+	Purpose:
+		Open a required file. If fails, quit the program.
+
+	Parameters:
+		[IN] fileName - file name to open.
+
+	Return value:
+		Pointer to the file.
+*/
+FILE* UTIL_OpenRequiredFile(const char *fileName)
+{
+	FILE *fp;
+	fp = fopen(va("%s%s", PAL_PREFIX, fileName), "rb");
+	if (fp == NULL)
+	{
+		TerminateOnError("File not found: %s!\n", fileName);
+	}
+	return fp;
+}
+
+/*
+	Purpose:
+		Close a file.
+
+	Parameters:
+		[IN] fp - file handle to be closed.
+
+	Return value:
+		None.
+*/
+void UTIL_CloseFile(FILE *fp)
+{
+	if (fp != NULL)
+	{
+		fclose(fp);
+	}
+}
+

File src/util.h

View file
  • Ignore whitespace
 
 char *va(const char *format, ...);
 
-void UTIL_Delay(unsigned int ms);
+void TerminateOnError(const char *format, ...);
 
+void  UTIL_Delay(unsigned int ms);
+FILE* UTIL_OpenRequiredFile(const char *fileName);
+void  UTIL_CloseFile(FILE *fp);
 
 #ifdef __cplusplus
 }

File src/video.c

View file
  • Ignore whitespace
 
 	for (i = 0; i <= 9999; i++)
 	{
-		file = va("./scrn%.4d.bmp", i);
+		file = va("%sscrn%.4d.bmp", PAL_PREFIX, i);
 		fp = fopen(file, "rb");
 		if (fp == NULL)
 		{