This commit is contained in:
Franck STAUFFER 2020-08-03 17:34:41 +02:00
parent 2bfddbbfd0
commit efce4d6d29
Signed by: franck.stauffer
GPG Key ID: AAF5A94045CEC261
1 changed files with 19 additions and 11 deletions

View File

@ -1,4 +1,4 @@
#include "SDL/SDL.h" #include "SDL2/SDL.h"
#include <signal.h> #include <signal.h>
#include <stdint.h> #include <stdint.h>
#include <stdio.h> #include <stdio.h>
@ -37,11 +37,12 @@ byte st = 0;
word stack[16]; word stack[16];
byte v[16]; byte v[16];
SDL_Surface* s;
SDL_Event e; SDL_Event e;
SDL_Surface* s;
SDL_Window* w;
Uint8 fg; Uint32 fg;
Uint8 bg; Uint32 bg;
void void
init_chip8(void) init_chip8(void)
@ -81,6 +82,7 @@ void
cleanup(void) cleanup(void)
{ {
SDL_FreeSurface(s); SDL_FreeSurface(s);
SDL_DestroyWindow(w);
SDL_Quit(); SDL_Quit();
} }
@ -92,7 +94,15 @@ init_SDL(const char* path)
return 0; return 0;
} }
s = SDL_SetVideoMode(64 * SCALE, 32 * SCALE, 8, SDL_HWSURFACE); char caption[7 + strlen(path)];
sprintf(caption, "CHIP-8 - %s", path);
w = SDL_CreateWindow(caption, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 64 * SCALE, 32 * SCALE, SDL_WINDOW_SHOWN);
if (!w) {
fputs("ERROR: Failed to create a window\n", stderr);
return 0;
}
s = SDL_GetWindowSurface(w);
if (!s) { if (!s) {
fputs("ERROR: Failed to create SDL surface\n", stderr); fputs("ERROR: Failed to create SDL surface\n", stderr);
return 0; return 0;
@ -105,10 +115,6 @@ init_SDL(const char* path)
return 0; return 0;
} }
char caption[7 + strlen(path)];
sprintf(caption, "CHIP-8 - %s", path);
SDL_WM_SetCaption(caption, NULL);
return 1; return 1;
} }
@ -315,7 +321,7 @@ render(void)
SDL_FillRect(s, &r, (gfx[x][y]) ? fg : bg); SDL_FillRect(s, &r, (gfx[x][y]) ? fg : bg);
} }
SDL_Flip(s); SDL_UpdateWindowSurface(w);
} }
static inline uint_fast8_t static inline uint_fast8_t
@ -323,7 +329,7 @@ op_handler(void)
{ {
switch (op) { switch (op) {
case 0x00E0: case 0x00E0:
memset(gfx, 0, 32 * 63 * sizeof(byte)); memset(gfx, 0, 32 * 64 * sizeof(byte));
SDL_Rect r; SDL_Rect r;
r.h = 32 * SCALE; r.h = 32 * SCALE;
@ -332,6 +338,8 @@ op_handler(void)
r.y = 0; r.y = 0;
SDL_FillRect(s, &r, bg); SDL_FillRect(s, &r, bg);
SDL_UpdateWindowSurface(w);
pc += 2; pc += 2;
return 1; return 1;
case 0x00EE: case 0x00EE: