Преглед изворни кода

Stub out assembler/disassembler code.

master
Ben Kurtovic пре 9 година
родитељ
комит
103dfaf841
8 измењених фајлова са 92 додато и 24 уклоњено
  1. +17
    -8
      crater.c
  2. +16
    -0
      src/assembler.c
  3. +13
    -0
      src/assembler.h
  4. +3
    -1
      src/config.c
  5. +16
    -0
      src/disassembler.c
  6. +13
    -0
      src/disassembler.h
  7. +13
    -13
      src/logging.h
  8. +1
    -2
      src/rom.c

+ 17
- 8
crater.c Прегледај датотеку

@@ -2,8 +2,11 @@
Released under the terms of the MIT License. See LICENSE for details. */

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

#include "src/assembler.h"
#include "src/config.h"
#include "src/disassembler.h"
#include "src/logging.h"
#include "src/rom.h"

@@ -13,7 +16,7 @@
int main(int argc, char *argv[])
{
Config *config;
int retval;
int retval = EXIT_SUCCESS;

retval = config_create(&config, argc, argv);
if (retval != CONFIG_OK)
@@ -23,10 +26,15 @@ int main(int argc, char *argv[])
config_dump_args(config);
#endif

if (config->assemble) {
printf("Running assembler: %s -> %s.\n", config->src_path, config->dst_path);
} else if (config->disassemble) {
printf("Running disassembler: %s -> %s.\n", config->src_path, config->dst_path);
if (config->assemble || config->disassemble) {
printf("crater: running %s: %s -> %s\n",
config->assemble ? "assembler" : "disassembler",
config->src_path, config->dst_path);
if (config->assemble)
retval = assemble(config->src_path, config->dst_path);
else
retval = disassemble(config->src_path, config->dst_path);
retval = retval ? EXIT_SUCCESS : EXIT_FAILURE;
} else {
ROM *rom;

@@ -37,12 +45,13 @@ int main(int argc, char *argv[])
else
FATAL_ERRNO("couldn't load ROM image '%s'", config->rom_path)
}
printf("Loaded ROM image: %s.\n", rom->name);
printf("Loaded ROM image: %s\n", rom->name);

// TODO: emulate game here...

// TODO: start from here
rom_close(rom);
}

config_destroy(config);
return EXIT_SUCCESS;
return retval;
}

+ 16
- 0
src/assembler.c Прегледај датотеку

@@ -0,0 +1,16 @@
/* Copyright (C) 2014-2015 Ben Kurtovic <ben.kurtovic@gmail.com>
Released under the terms of the MIT License. See LICENSE for details. */

#include "assembler.h"

/*
Assemble the z80 source code at the input path into a binary.

Return true if the operation was a success and false if it was a failure.
Errors are printed to STDOUT; if the operation was successful then nothing
is printed.
*/
bool assemble(const char* src_path, const char* dst_path)
{
return true;
}

+ 13
- 0
src/assembler.h Прегледај датотеку

@@ -0,0 +1,13 @@
/* 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 <stdbool.h>

/* Structs */

// ...

/* Functions */

bool assemble(const char*, const char*);

+ 3
- 1
src/config.c Прегледај датотеку

@@ -312,7 +312,9 @@ static bool sanity_check(Config* config)
Create a new config object and load default values into it.

Return value is one of CONFIG_OK, CONFIG_EXIT_SUCCESS, CONFIG_EXIT_FAILURE
and indicates how the caller should proceed.
and indicates how the caller should proceed. If the caller should exit,
then the config object should *not* be freed; otherwise it should be freed
with config_destroy() when the caller is ready.
*/
int config_create(Config** config_ptr, int argc, char* argv[])
{


+ 16
- 0
src/disassembler.c Прегледај датотеку

@@ -0,0 +1,16 @@
/* Copyright (C) 2014-2015 Ben Kurtovic <ben.kurtovic@gmail.com>
Released under the terms of the MIT License. See LICENSE for details. */

#include "disassembler.h"

/*
Disassemble the binary file at the input path into z80 source code.

Return true if the operation was a success and false if it was a failure.
Errors are printed to STDOUT; if the operation was successful then nothing
is printed.
*/
bool disassemble(const char* src_path, const char* dst_path)
{
return true;
}

+ 13
- 0
src/disassembler.h Прегледај датотеку

@@ -0,0 +1,13 @@
/* 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 <stdbool.h>

/* Structs */

// ...

/* Functions */

bool disassemble(const char*, const char*);

+ 13
- 13
src/logging.h Прегледај датотеку

@@ -10,26 +10,26 @@

/* Internal usage only */

#define LOG_MSG(level, extra, tail, after, ...) { \
fprintf(stderr, level ": " __VA_ARGS__); \
extra; \
fprintf(stderr, tail ? ".\n" : "\n"); \
after; \
#define LOG_MSG(level, extra, after, ...) { \
fprintf(stderr, level ": " __VA_ARGS__); \
extra; \
fprintf(stderr, "\n"); \
after; \
}
#define PRINT_ERRNO() fprintf(stderr, ": %s", strerror(errno))

/* Public logging macros */

#define FATAL(...) LOG_MSG("Error", {}, 1, exit(EXIT_FAILURE), __VA_ARGS__)
#define FATAL_ERRNO(...) LOG_MSG("Error", PRINT_ERRNO(), 1, exit(EXIT_FAILURE), __VA_ARGS__)
#define ERROR(...) LOG_MSG("Error", {}, 1, {}, __VA_ARGS__)
#define ERROR_ERRNO(...) LOG_MSG("Error", PRINT_ERRNO(), 1, {}, __VA_ARGS__)
#define WARN(...) LOG_MSG("Warning", {}, 1, {}, __VA_ARGS__)
#define WARN_ERRNO(...) LOG_MSG("Warning", PRINT_ERRNO(), 1, {}, __VA_ARGS__)
#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__)

#ifdef DEBUG_MODE
#define DEBUG(...) LOG_MSG("[DEBUG]", {}, 0, {}, __VA_ARGS__)
#define DEBUG_ERRNO(...) LOG_MSG("[DEBUG]", PRINT_ERRNO(), 0, {}, __VA_ARGS__)
#define DEBUG(...) LOG_MSG("[DEBUG]", {}, {}, __VA_ARGS__)
#define DEBUG_ERRNO(...) LOG_MSG("[DEBUG]", PRINT_ERRNO(), {}, __VA_ARGS__)
#endif

#define OUT_OF_MEMORY() FATAL("couldn't allocate enough memory")

+ 1
- 2
src/rom.c Прегледај датотеку

@@ -27,8 +27,7 @@ ROM* rom_open(const char *path)
return NULL;
}
if (!(s.st_mode & S_IFREG)) {
if (s.st_mode & S_IFDIR)
errno = EISDIR;
errno = (s.st_mode & S_IFDIR) ? EISDIR : ENOENT;
fclose(fp);
return NULL;
}


Loading…
Откажи
Сачувај