|
|
|
@ -1,4 +1,5 @@
|
|
|
|
|
#include "SDL2/SDL.h"
|
|
|
|
|
#include <SDL2/SDL_mixer.h>
|
|
|
|
|
#include <signal.h>
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
#include <stdio.h>
|
|
|
|
@ -41,6 +42,8 @@ SDL_Event e;
|
|
|
|
|
SDL_Surface* s;
|
|
|
|
|
SDL_Window* w;
|
|
|
|
|
|
|
|
|
|
Mix_Chunk* buzzer;
|
|
|
|
|
|
|
|
|
|
Uint32 fg;
|
|
|
|
|
Uint32 bg;
|
|
|
|
|
|
|
|
|
@ -81,6 +84,8 @@ init_chip8(void)
|
|
|
|
|
void
|
|
|
|
|
cleanup(void)
|
|
|
|
|
{
|
|
|
|
|
Mix_FreeChunk(buzzer);
|
|
|
|
|
Mix_Quit();
|
|
|
|
|
SDL_FreeSurface(s);
|
|
|
|
|
SDL_DestroyWindow(w);
|
|
|
|
|
SDL_Quit();
|
|
|
|
@ -89,14 +94,19 @@ cleanup(void)
|
|
|
|
|
uint_fast8_t
|
|
|
|
|
init_SDL(const char* path)
|
|
|
|
|
{
|
|
|
|
|
if (SDL_Init(SDL_INIT_VIDEO)) {
|
|
|
|
|
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO)) {
|
|
|
|
|
fputs("ERROR: Failed to initialize SDL\n", stderr);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
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;
|
|
|
|
@ -108,6 +118,17 @@ init_SDL(const char* path)
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 1, 2048)) {
|
|
|
|
|
fputs("ERROR: Failed to open audio\n", stderr);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
buzzer = Mix_LoadWAV("resources/buzzer.wav");
|
|
|
|
|
if (!buzzer) {
|
|
|
|
|
fputs("ERROR: Failed to load sound effects\n", stderr);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (atexit(cleanup)) {
|
|
|
|
|
fputs("ERROR: Failed to set exit function\n", stderr);
|
|
|
|
|
SDL_FreeSurface(s);
|
|
|
|
@ -531,8 +552,10 @@ timers()
|
|
|
|
|
if (dt)
|
|
|
|
|
--dt;
|
|
|
|
|
|
|
|
|
|
if (st)
|
|
|
|
|
if (st) {
|
|
|
|
|
Mix_PlayChannel(-1, buzzer, 0);
|
|
|
|
|
--st;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|