From 96e2a3f1d5ac36d2cc534e55dc3a5abb714f930e Mon Sep 17 00:00:00 2001 From: Ben Kurtovic Date: Tue, 24 Mar 2015 23:58:58 -0400 Subject: [PATCH] Stub out some GG methods; minor cleanup. --- crater.c | 8 ++++++-- src/assembler.h | 1 + src/config.h | 1 + src/disassembler.h | 1 + src/gamegear.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ src/gamegear.h | 19 +++++++++++++++++++ src/logging.h | 26 ++++++++++++-------------- src/rom.c | 3 ++- src/rom.h | 2 ++ src/util.h | 3 ++- 10 files changed, 96 insertions(+), 18 deletions(-) create mode 100644 src/gamegear.c create mode 100644 src/gamegear.h diff --git a/crater.c b/crater.c index 6177669..95e3334 100644 --- a/crater.c +++ b/crater.c @@ -7,6 +7,7 @@ #include "src/assembler.h" #include "src/config.h" #include "src/disassembler.h" +#include "src/gamegear.h" #include "src/logging.h" #include "src/rom.h" @@ -43,10 +44,13 @@ int main(int argc, char *argv[]) ERROR("couldn't load ROM image '%s': %s", config->rom_path, errmsg) retval = EXIT_FAILURE; } else { - printf("crater: emulating: %s\n", rom->name); + GameGear *gg = gamegear_create(); - // TODO: emulate game here... + printf("crater: emulating: %s\n", rom->name); + gamegear_load(gg, rom); + gamegear_power(gg); + gamegear_destroy(gg); rom_close(rom); } } diff --git a/src/assembler.h b/src/assembler.h index 51f9266..75c6d48 100644 --- a/src/assembler.h +++ b/src/assembler.h @@ -2,6 +2,7 @@ Released under the terms of the MIT License. See LICENSE for details. */ #pragma once + #include /* Structs */ diff --git a/src/config.h b/src/config.h index 47fbff2..fde297b 100644 --- a/src/config.h +++ b/src/config.h @@ -2,6 +2,7 @@ Released under the terms of the MIT License. See LICENSE for details. */ #pragma once + #include #define CONFIG_OK 0 diff --git a/src/disassembler.h b/src/disassembler.h index a30ee51..1343e10 100644 --- a/src/disassembler.h +++ b/src/disassembler.h @@ -2,6 +2,7 @@ Released under the terms of the MIT License. See LICENSE for details. */ #pragma once + #include /* Structs */ diff --git a/src/gamegear.c b/src/gamegear.c new file mode 100644 index 0000000..e484967 --- /dev/null +++ b/src/gamegear.c @@ -0,0 +1,50 @@ +/* Copyright (C) 2014-2015 Ben Kurtovic + Released under the terms of the MIT License. See LICENSE for details. */ + +#include "gamegear.h" +#include "logging.h" + +/* + Create and return a pointer to a new GameGear object. + + If memory could not be allocated, OUT_OF_MEMORY() is triggered. +*/ +GameGear* gamegear_create() +{ + GameGear *gg = malloc(sizeof(GameGear)); + if (!gg) + OUT_OF_MEMORY() + + gg->rom = NULL; + return gg; +} + +/* + Destroy a previously-allocated GameGear object. + + Does *not* destroy any loaded ROM objects. +*/ +void gamegear_destroy(GameGear* gg) +{ + free(gg); +} + +/* + Load a ROM image into the GameGear object. + + Does *not* steal the reference to the ROM object. +*/ +void gamegear_load(GameGear* gg, ROM* rom) +{ + gg->rom = rom; +} + +/* + Powers a GameGear object, beginning emulation. + + This function call blocks until the GameGear is powered off. +*/ +void gamegear_power(GameGear* gg) +{ + // TODO +} diff --git a/src/gamegear.h b/src/gamegear.h new file mode 100644 index 0000000..056e274 --- /dev/null +++ b/src/gamegear.h @@ -0,0 +1,19 @@ +/* Copyright (C) 2014-2015 Ben Kurtovic + Released under the terms of the MIT License. See LICENSE for details. */ + +#pragma once + +#include "rom.h" + +/* Structs */ + +typedef struct { + ROM *rom; +} GameGear; + +/* Functions */ + +GameGear* gamegear_create(); +void gamegear_destroy(GameGear*); +void gamegear_load(GameGear*, ROM*); +void gamegear_power(GameGear*); diff --git a/src/logging.h b/src/logging.h index f95398b..6e22b9a 100644 --- a/src/logging.h +++ b/src/logging.h @@ -10,29 +10,27 @@ /* Internal usage only */ -#define LOG_MSG(level, extra, after, ...) { \ - fprintf(stderr, level ": " __VA_ARGS__); \ - extra; \ - fprintf(stderr, "\n"); \ - after; \ +#define LOG_MSG(dest, level, extra, after, ...) { \ + fprintf(dest, level ": " __VA_ARGS__); \ + extra; \ + fprintf(dest, "\n"); \ + after; \ } #define PRINT_ERRNO() fprintf(stderr, ": %s", strerror(errno)) /* Public logging macros */ -#define FATAL(...) LOG_MSG("Error", {}, exit(EXIT_FAILURE), __VA_ARGS__) -#define FATAL_ERRNO(...) LOG_MSG("Error", PRINT_ERRNO(), exit(EXIT_FAILURE), __VA_ARGS__) -#define ERROR(...) LOG_MSG("Error", {}, {}, __VA_ARGS__) -#define ERROR_ERRNO(...) LOG_MSG("Error", PRINT_ERRNO(), {}, __VA_ARGS__) -#define WARN(...) LOG_MSG("Warning", {}, {}, __VA_ARGS__) -#define WARN_ERRNO(...) LOG_MSG("Warning", PRINT_ERRNO(), {}, __VA_ARGS__) +#define FATAL(...) LOG_MSG(stderr, "Error", {}, exit(EXIT_FAILURE), __VA_ARGS__) +#define FATAL_ERRNO(...) LOG_MSG(stderr, "Error", PRINT_ERRNO(), exit(EXIT_FAILURE), __VA_ARGS__) +#define ERROR(...) LOG_MSG(stderr, "Error", {}, {}, __VA_ARGS__) +#define ERROR_ERRNO(...) LOG_MSG(stderr, "Error", PRINT_ERRNO(), {}, __VA_ARGS__) +#define WARN(...) LOG_MSG(stderr, "Warning", {}, {}, __VA_ARGS__) +#define WARN_ERRNO(...) LOG_MSG(stderr, "Warning", PRINT_ERRNO(), {}, __VA_ARGS__) #ifdef DEBUG_MODE -#define DEBUG(...) LOG_MSG("[DEBUG]", {}, {}, __VA_ARGS__) -#define DEBUG_ERRNO(...) LOG_MSG("[DEBUG]", PRINT_ERRNO(), {}, __VA_ARGS__) +#define DEBUG(...) LOG_MSG(stdout, "[DEBUG]", {}, {}, __VA_ARGS__) #else #define DEBUG(...) {} -#define DEBUG_ERRNO(...) {} #endif #define OUT_OF_MEMORY() FATAL("couldn't allocate enough memory") diff --git a/src/rom.c b/src/rom.c index 7bcebb2..b17df97 100644 --- a/src/rom.c +++ b/src/rom.c @@ -220,7 +220,8 @@ void rom_close(ROM *rom) NULL is returned if the region code is invalid. - Region code information is taken from http://www.smspower.org/Development/ROMHeader. + Region code information is taken from: + http://www.smspower.org/Development/ROMHeader */ const char* rom_region(const ROM *rom) { diff --git a/src/rom.h b/src/rom.h index 2b23a20..acc7ffc 100644 --- a/src/rom.h +++ b/src/rom.h @@ -2,7 +2,9 @@ Released under the terms of the MIT License. See LICENSE for details. */ #pragma once + #include +#include /* Error strings */ diff --git a/src/util.h b/src/util.h index 744c989..a867a8b 100644 --- a/src/util.h +++ b/src/util.h @@ -2,7 +2,8 @@ Released under the terms of the MIT License. See LICENSE for details. */ #pragma once -#include "stdint.h" + +#include /* Functions */