Browse Source

Small tweaks; const fixes.

master
Ben Kurtovic 9 years ago
parent
commit
d2f6e1e1a7
4 changed files with 17 additions and 6 deletions
  1. +5
    -3
      crater.c
  2. +5
    -1
      src/rom.c
  3. +1
    -1
      src/rom.h
  4. +6
    -1
      src/z80.h

+ 5
- 3
crater.c View File

@@ -16,7 +16,7 @@
#define ROMS_DIR "roms" #define ROMS_DIR "roms"


/* Print command-line help/usage. */ /* 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); 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. */ /* 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); size_t ilen = strlen(input), slen = strlen(suffix);


@@ -156,9 +156,11 @@ int main(int argc, char *argv[])
else else
FATAL_ERRNO("couldn't load ROM image '%s'", rom_path) FATAL_ERRNO("couldn't load ROM image '%s'", rom_path)
} }
printf("Loaded ROM image: %s.\n", rom_path);
if (argc <= 1) if (argc <= 1)
free(rom_path); free(rom_path);
printf("Loaded ROM image: %s.\n", rom->name);

// TODO: start from here


close_rom(rom); close_rom(rom);
return 0; return 0;


+ 5
- 1
src/rom.c View File

@@ -3,12 +3,13 @@


#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h>


#include "rom.h" #include "rom.h"


/* Create and return a ROM object located at the given path. Return NULL if /* Create and return a ROM object located at the given path. Return NULL if
there was an error; errno will be set appropriately. */ 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; rom_type *rom;
FILE* fp; FILE* fp;
@@ -17,9 +18,12 @@ rom_type* open_rom(char *path)
return NULL; return NULL;
if (!(rom = malloc(sizeof(rom_type)))) if (!(rom = malloc(sizeof(rom_type))))
return NULL; return NULL;
rom->name = malloc(sizeof(char) * (strlen(path) + 1));
strcpy(rom->name, path);


// load data from file into a buffer // load data from file into a buffer


fclose(fp);
return rom; return rom;
} }




+ 1
- 1
src/rom.h View File

@@ -12,5 +12,5 @@ typedef struct {


/* Functions */ /* Functions */


rom_type* open_rom(char*);
rom_type* open_rom(const char*);
void close_rom(rom_type*); void close_rom(rom_type*);

+ 6
- 1
src/z80.h View File

@@ -3,6 +3,11 @@


#pragma once #pragma once


/* Clock speed in Hz was taken from the official Sega GG documentation */
#define CLOCK_SPEED 3579545

/* Structs */

typedef struct { typedef struct {
int pc; int pc;
} register_type;
} z80_type;

Loading…
Cancel
Save