@@ -3,3 +3,4 @@ roms/* | |||||
!roms/README | !roms/README | ||||
crater | crater | ||||
crater-dev | crater-dev | ||||
tests/runner |
@@ -24,12 +24,19 @@ Installing | |||||
---------- | ---------- | ||||
Only OS X and Linux are tested. You'll need a modern compiler that supports C11 | Only OS X and Linux are tested. You'll need a modern compiler that supports C11 | ||||
(clang preferred) and SDL 2. Using Homebrew, you can `brew install sdl2`; using | |||||
apt, you can `apt-get install libsdl2-dev`. | |||||
([clang][clang] preferred) and [SDL 2][sdl2]. Using Homebrew, you can | |||||
`brew install sdl2`; using apt, you can `apt-get install libsdl2-dev`. | |||||
Run `make` to create `./crater`. To build the development version with debug | Run `make` to create `./crater`. To build the development version with debug | ||||
symbols (they can exist simultaneously), run `make DEBUG=1`, which creates | |||||
`./crater-dev`. This also enables the printing of debugging info to stdout. | |||||
symbols and extra diagnostic info (they can exist simultaneously), run | |||||
`make DEBUG=1`, which creates `./crater-dev`. | |||||
crater has a number of test cases. Run the entire suite with `make test`; | |||||
individual components can be tested by doing `make test-{component}`, where | |||||
`{component}` is one of `cpu`, `vdp`, `psg`, `asm`, `dis`, or `integrate`. | |||||
[clang]: http://clang.llvm.org/ | |||||
[sdl2]: https://www.libsdl.org/ | |||||
Usage | Usage | ||||
----- | ----- | ||||
@@ -1,50 +1,59 @@ | |||||
# Copyright (C) 2014 Ben Kurtovic <ben.kurtovic@gmail.com> | |||||
# Copyright (C) 2014-2015 Ben Kurtovic <ben.kurtovic@gmail.com> | |||||
# Released under the terms of the MIT License. See LICENSE for details. | # Released under the terms of the MIT License. See LICENSE for details. | ||||
PROGRAM = crater | PROGRAM = crater | ||||
SOURCES = src | SOURCES = src | ||||
BUILD = build | BUILD = build | ||||
DEVEXT = -dev | DEVEXT = -dev | ||||
TESTS = cpu vdp psg asm dis integrate | |||||
CC = clang | CC = clang | ||||
FLAGS = -O2 -Wall -Wextra -pedantic -std=c11 | FLAGS = -O2 -Wall -Wextra -pedantic -std=c11 | ||||
CFLAGS = $(shell sdl2-config --cflags) | CFLAGS = $(shell sdl2-config --cflags) | ||||
LIBS = $(shell sdl2-config --libs) | LIBS = $(shell sdl2-config --libs) | ||||
DFLAGS = -g -DDEBUG_MODE | |||||
MKDIR = mkdir -p | MKDIR = mkdir -p | ||||
RM = rm -rf | RM = rm -rf | ||||
ASM_UP = scripts/update_asm_instructions.py | ASM_UP = scripts/update_asm_instructions.py | ||||
MODE = release | MODE = release | ||||
BNRY = $(PROGRAM) | BNRY = $(PROGRAM) | ||||
FLGS = $(FLAGS) | |||||
SDRS = $(shell find $(SOURCES) -type d | xargs echo) | SDRS = $(shell find $(SOURCES) -type d | xargs echo) | ||||
SRCS = $(filter-out %.inc.c,$(foreach d,. $(SDRS),$(wildcard $(addprefix $(d)/*,.c)))) | SRCS = $(filter-out %.inc.c,$(foreach d,. $(SDRS),$(wildcard $(addprefix $(d)/*,.c)))) | ||||
OBJS = $(patsubst %.c,%.o,$(addprefix $(BUILD)/$(MODE)/,$(SRCS))) | OBJS = $(patsubst %.c,%.o,$(addprefix $(BUILD)/$(MODE)/,$(SRCS))) | ||||
DEPS = $(OBJS:%.o=%.d) | DEPS = $(OBJS:%.o=%.d) | ||||
DIRS = $(sort $(dir $(OBJS))) | DIRS = $(sort $(dir $(OBJS))) | ||||
TCPS = $(addprefix test-,$(TESTS)) | |||||
ifdef DEBUG | ifdef DEBUG | ||||
BNRY := $(BNRY)$(DEVEXT) | |||||
FLAGS += -g -DDEBUG_MODE | |||||
MODE = debug | |||||
BNRY := $(BNRY)$(DEVEXT) | |||||
FLGS += $(DFLAGS) | |||||
MODE = debug | |||||
endif | endif | ||||
.PHONY: all clean test test-all test-z80 test-asm test-dasm | |||||
export CC | |||||
export FLAGS | |||||
export RM | |||||
.PHONY: all clean test-prereqs test tests $(TCPS) | |||||
all: $(BNRY) | all: $(BNRY) | ||||
clean: | clean: | ||||
$(RM) $(BUILD) $(PROGRAM) $(PROGRAM)$(DEVEXT) | $(RM) $(BUILD) $(PROGRAM) $(PROGRAM)$(DEVEXT) | ||||
$(MAKE) -C tests clean | |||||
$(DIRS): | $(DIRS): | ||||
$(MKDIR) $@ | $(MKDIR) $@ | ||||
$(BNRY): $(OBJS) | $(BNRY): $(OBJS) | ||||
$(CC) $(FLAGS) $(LIBS) $(OBJS) -o $@ | |||||
$(CC) $(FLGS) $(LIBS) $(OBJS) -o $@ | |||||
$(OBJS): | $(DIRS) | $(OBJS): | $(DIRS) | ||||
$(BUILD)/$(MODE)/%.o: %.c | $(BUILD)/$(MODE)/%.o: %.c | ||||
$(CC) $(FLAGS) $(CFLAGS) -MMD -MP -c $< -o $@ | |||||
$(CC) $(FLGS) $(CFLAGS) -MMD -MP -c $< -o $@ | |||||
-include $(DEPS) | -include $(DEPS) | ||||
@@ -52,16 +61,13 @@ ASM_INST = $(SOURCES)/assembler/instructions | |||||
$(ASM_INST).inc.c: $(ASM_INST).yml $(ASM_UP) | $(ASM_INST).inc.c: $(ASM_INST).yml $(ASM_UP) | ||||
python $(ASM_UP) | python $(ASM_UP) | ||||
test: test-all test-z80 test-asm test-dasm | |||||
test-all: | |||||
@echo "running all tests" | |||||
test-prereqs: | |||||
$(MAKE) $(PROGRAM) DEBUG= | |||||
test-z80: | |||||
@echo "running Z80 CPU tests" | |||||
test: test-prereqs | |||||
$(MAKE) -C tests all | |||||
test-asm: | |||||
@echo "running assembler tests" | |||||
tests: test | |||||
test-dasm: | |||||
@echo "running disassembler tests" | |||||
$(TCPS): test-prereqs | |||||
$(MAKE) -C tests $(subst test-,,$@) |
@@ -0,0 +1,18 @@ | |||||
# Copyright (C) 2014-2015 Ben Kurtovic <ben.kurtovic@gmail.com> | |||||
# Released under the terms of the MIT License. See LICENSE for details. | |||||
RUNNER = runner | |||||
COMPONENTS = cpu vdp psg asm dis integrate | |||||
.PHONY: all clean $(COMPONENTS) | |||||
all: $(COMPONENTS) | |||||
clean: | |||||
$(RM) $(RUNNER) | |||||
$(RUNNER): $(RUNNER).c | |||||
$(CC) $(FLAGS) $< -o $@ | |||||
$(COMPONENTS): $(RUNNER) | |||||
./$(RUNNER) $@ |
@@ -1,4 +1,101 @@ | |||||
/* Copyright (C) 2014-2015 Ben Kurtovic <ben.kurtovic@gmail.com> | /* Copyright (C) 2014-2015 Ben Kurtovic <ben.kurtovic@gmail.com> | ||||
Released under the terms of the MIT License. See LICENSE for details. */ | Released under the terms of the MIT License. See LICENSE for details. */ | ||||
// ... | |||||
#include <stdbool.h> | |||||
#include <stdio.h> | |||||
#include <stdlib.h> | |||||
#include <string.h> | |||||
#include "../src/logging.h" | |||||
/* | |||||
TODO | |||||
*/ | |||||
static bool test_cpu() | |||||
{ | |||||
// TODO | |||||
return true; | |||||
} | |||||
/* | |||||
TODO | |||||
*/ | |||||
static bool test_vdp() | |||||
{ | |||||
// TODO | |||||
return true; | |||||
} | |||||
/* | |||||
TODO | |||||
*/ | |||||
static bool test_psg() | |||||
{ | |||||
// TODO | |||||
return true; | |||||
} | |||||
/* | |||||
TODO | |||||
*/ | |||||
static bool test_asm() | |||||
{ | |||||
// TODO | |||||
return true; | |||||
} | |||||
/* | |||||
TODO | |||||
*/ | |||||
static bool test_dis() | |||||
{ | |||||
// TODO | |||||
return true; | |||||
} | |||||
/* | |||||
TODO | |||||
*/ | |||||
static bool test_integrate() | |||||
{ | |||||
// TODO | |||||
return true; | |||||
} | |||||
/* | |||||
Main function. | |||||
*/ | |||||
int main(int argc, char *argv[]) | |||||
{ | |||||
if (argc != 2) | |||||
FATAL("a component name is required") | |||||
const char *component = argv[1], *name; | |||||
bool (*func)(); | |||||
if (!strcmp(component, "cpu")) { | |||||
name = "Z80 CPU"; | |||||
func = test_cpu; | |||||
} else if (!strcmp(component, "vdp")) { | |||||
name = "VDP"; | |||||
func = test_vdp; | |||||
} else if (!strcmp(component, "psg")) { | |||||
name = "SN76489 PSG"; | |||||
func = test_psg; | |||||
} else if (!strcmp(component, "asm")) { | |||||
name = "assembler"; | |||||
func = test_asm; | |||||
} else if (!strcmp(component, "dis")) { | |||||
name = "disassembler"; | |||||
func = test_dis; | |||||
} else if (!strcmp(component, "integrate")) { | |||||
name = "integration"; | |||||
func = test_integrate; | |||||
} else { | |||||
FATAL("unknown component: %s", component) | |||||
} | |||||
printf("crater: running %s tests\n", name); | |||||
return func() ? EXIT_SUCCESS : EXIT_FAILURE; | |||||
} |