diff --git a/crater.c b/crater.c index 716259a..d26442b 100644 --- a/crater.c +++ b/crater.c @@ -16,7 +16,7 @@ #define ROMS_DIR "roms" /* Print command-line help/usage. */ -static void print_help(char *arg1) +static void print_help(const char *arg1) { printf("%s [--help|-h] [--version|-v] [rom_path]\n", arg1); } @@ -54,7 +54,7 @@ static void parse_args(int argc, char *argv[]) } /* Return whether the given string ends with the given suffix. */ -static bool ends_with(char *input, char *suffix) +static bool ends_with(const char *input, const char *suffix) { size_t ilen = strlen(input), slen = strlen(suffix); @@ -156,9 +156,11 @@ int main(int argc, char *argv[]) else FATAL_ERRNO("couldn't load ROM image '%s'", rom_path) } - printf("Loaded ROM image: %s.\n", rom_path); if (argc <= 1) free(rom_path); + printf("Loaded ROM image: %s.\n", rom->name); + + // TODO: start from here close_rom(rom); return 0; diff --git a/src/rom.c b/src/rom.c index f62e426..2621d29 100644 --- a/src/rom.c +++ b/src/rom.c @@ -3,12 +3,13 @@ #include #include +#include #include "rom.h" /* Create and return a ROM object located at the given path. Return NULL if there was an error; errno will be set appropriately. */ -rom_type* open_rom(char *path) +rom_type* open_rom(const char *path) { rom_type *rom; FILE* fp; @@ -17,9 +18,12 @@ rom_type* open_rom(char *path) return NULL; if (!(rom = malloc(sizeof(rom_type)))) return NULL; + rom->name = malloc(sizeof(char) * (strlen(path) + 1)); + strcpy(rom->name, path); // load data from file into a buffer + fclose(fp); return rom; } diff --git a/src/rom.h b/src/rom.h index 63288a1..a28f9c4 100644 --- a/src/rom.h +++ b/src/rom.h @@ -12,5 +12,5 @@ typedef struct { /* Functions */ -rom_type* open_rom(char*); +rom_type* open_rom(const char*); void close_rom(rom_type*); diff --git a/src/z80.h b/src/z80.h index afae3a2..020cf1f 100644 --- a/src/z80.h +++ b/src/z80.h @@ -3,6 +3,11 @@ #pragma once +/* Clock speed in Hz was taken from the official Sega GG documentation */ +#define CLOCK_SPEED 3579545 + +/* Structs */ + typedef struct { int pc; -} register_type; +} z80_type;