| @@ -7,6 +7,7 @@ | |||||
| #include "src/assembler.h" | #include "src/assembler.h" | ||||
| #include "src/config.h" | #include "src/config.h" | ||||
| #include "src/disassembler.h" | #include "src/disassembler.h" | ||||
| #include "src/gamegear.h" | |||||
| #include "src/logging.h" | #include "src/logging.h" | ||||
| #include "src/rom.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) | ERROR("couldn't load ROM image '%s': %s", config->rom_path, errmsg) | ||||
| retval = EXIT_FAILURE; | retval = EXIT_FAILURE; | ||||
| } else { | } 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); | rom_close(rom); | ||||
| } | } | ||||
| } | } | ||||
| @@ -2,6 +2,7 @@ | |||||
| Released under the terms of the MIT License. See LICENSE for details. */ | Released under the terms of the MIT License. See LICENSE for details. */ | ||||
| #pragma once | #pragma once | ||||
| #include <stdbool.h> | #include <stdbool.h> | ||||
| /* Structs */ | /* Structs */ | ||||
| @@ -2,6 +2,7 @@ | |||||
| Released under the terms of the MIT License. See LICENSE for details. */ | Released under the terms of the MIT License. See LICENSE for details. */ | ||||
| #pragma once | #pragma once | ||||
| #include <stdbool.h> | #include <stdbool.h> | ||||
| #define CONFIG_OK 0 | #define CONFIG_OK 0 | ||||
| @@ -2,6 +2,7 @@ | |||||
| Released under the terms of the MIT License. See LICENSE for details. */ | Released under the terms of the MIT License. See LICENSE for details. */ | ||||
| #pragma once | #pragma once | ||||
| #include <stdbool.h> | #include <stdbool.h> | ||||
| /* Structs */ | /* Structs */ | ||||
| @@ -0,0 +1,50 @@ | |||||
| /* Copyright (C) 2014-2015 Ben Kurtovic <ben.kurtovic@gmail.com> | |||||
| 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 | |||||
| } | |||||
| @@ -0,0 +1,19 @@ | |||||
| /* Copyright (C) 2014-2015 Ben Kurtovic <ben.kurtovic@gmail.com> | |||||
| 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*); | |||||
| @@ -10,29 +10,27 @@ | |||||
| /* Internal usage only */ | /* 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)) | #define PRINT_ERRNO() fprintf(stderr, ": %s", strerror(errno)) | ||||
| /* Public logging macros */ | /* 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 | #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 | #else | ||||
| #define DEBUG(...) {} | #define DEBUG(...) {} | ||||
| #define DEBUG_ERRNO(...) {} | |||||
| #endif | #endif | ||||
| #define OUT_OF_MEMORY() FATAL("couldn't allocate enough memory") | #define OUT_OF_MEMORY() FATAL("couldn't allocate enough memory") | ||||
| @@ -220,7 +220,8 @@ void rom_close(ROM *rom) | |||||
| NULL is returned if the region code is invalid. | 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) | const char* rom_region(const ROM *rom) | ||||
| { | { | ||||
| @@ -2,7 +2,9 @@ | |||||
| Released under the terms of the MIT License. See LICENSE for details. */ | Released under the terms of the MIT License. See LICENSE for details. */ | ||||
| #pragma once | #pragma once | ||||
| #include <stdint.h> | #include <stdint.h> | ||||
| #include <stdlib.h> | |||||
| /* Error strings */ | /* Error strings */ | ||||
| @@ -2,7 +2,8 @@ | |||||
| Released under the terms of the MIT License. See LICENSE for details. */ | Released under the terms of the MIT License. See LICENSE for details. */ | ||||
| #pragma once | #pragma once | ||||
| #include "stdint.h" | |||||
| #include <stdint.h> | |||||
| /* Functions */ | /* Functions */ | ||||