Commits

kasicass committed c8780ee

init

  • Participants

Comments (0)

Files changed (3)

File src/common.h

+#ifndef SDL2PAL_COMMON_H
+#define SDL2PAL_COMMON_H
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <time.h>
+#include <limits.h>
+#include <stdarg.h>
+#include <stdbool.h>
+#include <assert.h>
+
+#include <SDL2/SDL.h>
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+#include "video.h"
+
+
+static struct
+{
+	SDL_Window *window;
+	SDL_Renderer *renderer;
+	SDL_Surface *screenReal;
+	SDL_Surface *screen;
+	SDL_Surface *screenBak;
+} G;
+
+/*
+	Purpose:
+		Initialize the video subsystem.
+
+	Parameters:
+		[IN] w - screen width.
+		[IN] h - screen height.
+		[IN] fullscreen - true to use fullscreen mode, false to use windowed mode.
+
+	Return value:
+		0  = success
+		-1 = fail to create the screen surface
+		-2 = fail to create screen buffer
+*/
+int VIDEO_Init(Uint32 w, Uint32 h, bool fullscreen)
+{
+	// TODO here
+	w = 640;
+	h = 480;
+
+	G.window = SDL_CreateWindow("SDL2PAL",
+		SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, w, h, SDL_WINDOW_SHOWN);
+	assert(G.window != NULL);
+
+	G.renderer = SDL_CreateRenderer(window, -1, 0);
+	assert(G.renderer != NULL);
+
+	G.screenReal = SDL_CreateRGBSurface(0, w, h, 8, 0, 0, 0, 0);
+	assert(G.screenReal != NULL);
+
+	G.screen = SDL_CreateRGBSurface(0, 320, 200, 8, 0, 0, 0, 0);
+	assert(G.screen != NULL);
+
+	G.screenBak = SDL_CreateRGBSurface(0, 320, 200, 8, 0, 0, 0, 0);
+	assert(G.screenBak != NULL);
+
+	G.screenReal
+
+	// TODO, fullscreen
+
+	return 0;
+}
+
+/*
+	Purpose:
+		Shutdown the video subsystem.
+
+	Parameters:
+		None.
+
+	Return value:
+		None.
+*/
+void VIDEO_Shutdown(void)
+{
+	SDL_FreeSurface(G.screenBak);
+	G.screenBak = NULL;
+
+	SDL_FreeSurface(G.screen);
+	G.screen = NULL;
+
+	SDL_FreeSurface(G.screenReal);
+	G.screenReal = NULL;
+
+	SDL_DestroyRenderer(G.renderer);
+	G.renderer = NULL;
+
+	SDL_DestroyWindow(G.window);
+	G.window = NULL;
+}
+
+/*
+	Purpose:
+		Update the screen area specified by rect.
+
+	Parameters:
+		[IN] rect - screen area to update.
+
+	Return value:
+		None.
+*/
+void VIDEO_UpdateScreen(const SDL_Rect *rect)
+{
+	SDL_Rect srcrect, dstrect;
+	Uint16 offset           = 240 - 200;
+	Uint16 screenRealHeight = G.window->h - offset;
+	Uint16 scrrenRealY      = offset / 2;
+
+	if (rect != NULL)
+	{
+	}
+}
+
+
+void VIDEO_SetPalette(SDL_Color palette[256]);
+SDL_Color *VIDEO_GetPalette(void);
+
+void VIDEO_Resize(Uint32 w, Uint32 h);
+void VIDEO_ToggleFullscreen(void);
+void VIDEO_SaveScreenshot(void);
+void VIDEO_BackupScreen(void);
+void VIDEO_RestoreScreen(void);
+void VIDEO_ShakeScreen(Uint16 shakeTime, Uint16 shakeLevel);
+void VIDEO_SwitchScreen(Uint16 speed);
+void VIDEO_FadeScreen(Uint16 speed);
+#ifndef VIDEO_H
+#define VIDEO_H
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include "common.h"
+
+int VIDEO_Init(Uint32 w, Uint32 h, bool fullscreen);
+void VIDEO_Shutdown(void);
+
+void VIDEO_UpdateScreen(const SDL_Rect *rect);
+void VIDEO_SetPalette(SDL_Color palette[256]);
+SDL_Color *VIDEO_GetPalette(void);
+
+void VIDEO_Resize(Uint32 w, Uint32 h);
+void VIDEO_ToggleFullscreen(void);
+void VIDEO_SaveScreenshot(void);
+void VIDEO_BackupScreen(void);
+void VIDEO_RestoreScreen(void);
+void VIDEO_ShakeScreen(Uint16 shakeTime, Uint16 shakeLevel);
+void VIDEO_SwitchScreen(Uint16 speed);
+void VIDEO_FadeScreen(Uint16 speed);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif