gb-emu: initial commit

Add a mostly non-functional Gameboy CPU and the skeleton
of a Gameboy assembler intended for unit tests.
This commit is contained in:
2016-12-18 23:43:41 -08:00
commit 6e2f4096a2
38 changed files with 4424 additions and 0 deletions

51
src/tests/gbasm/fixed.c Normal file
View File

@@ -0,0 +1,51 @@
#include "tests/gbasm/test.h"
#include "common.h"
#define GEN_FIXED_TEST(_opcode, _hex)\
uint8_t _opcode##_output[] = _hex; \
static const struct gbasm_test _opcode = { \
.name = #_opcode, \
.asm_source = #_opcode, \
.expected_output = _opcode##_output, \
.expected_output_len = sizeof(_opcode##_output), \
};
GEN_FIXED_TEST(nop, {0x00})
GEN_FIXED_TEST(halt, {0x76})
GEN_FIXED_TEST(stop, {0x10})
GEN_FIXED_TEST(di, {0xf3})
GEN_FIXED_TEST(ei, {0xfb})
GEN_FIXED_TEST(rla, {0x17})
GEN_FIXED_TEST(rra, {0x1f})
GEN_FIXED_TEST(rlca, {0x07})
GEN_FIXED_TEST(rrca, {0x0f})
GEN_FIXED_TEST(daa, {0x27})
GEN_FIXED_TEST(scf, {0x37})
GEN_FIXED_TEST(reti, {0xd9})
GEN_FIXED_TEST(cpl, {0x2f})
GEN_FIXED_TEST(ccf, {0x3f})
static const struct gbasm_test *tests[] = {
&nop,
&halt,
&stop,
&di,
&ei,
&rla,
&rra,
&rrca,
&daa,
&scf,
&reti,
&cpl,
&ccf,
};
struct gbasm_tests gbasm_fixed_tests = {
.name = "fixed",
.num_tests = ARRAY_SIZE(tests),
.tests = tests,
};

9
src/tests/gbasm/fixed.h Normal file
View File

@@ -0,0 +1,9 @@
#ifndef GBASM_TEST_FIXED_H
#define GBASM_TEST_FIXED_H
#include "tests/gbasm/test.h"
#include "common.h"
extern const struct gbasm_tests gbasm_fixed_tests;
#endif

41
src/tests/gbasm/inc.c Normal file
View File

@@ -0,0 +1,41 @@
#include "tests/gbasm/test.h"
#include "common.h"
/* TODO: There is probably a better way to do this */
static const char all_src[] =
"INC A\n"
"INC B\n"
"INC C\n"
"INC D\n"
"INC E\n"
"INC H\n"
"INC L\n"
"INC BC\n"
"INC DE\n"
"INC HL\n"
"INC SP\n"
"INC (HL)\n";
static const uint8_t all_output[] = {
0x3c, 0x04, 0x0c, 0x14,
0x1c, 0x24, 0x2c, 0x03,
0x13, 0x23, 0x33, 0x34,
};
static const struct gbasm_test all = {
.name = "all",
.asm_source = all_src,
.expected_output = all_output,
.expected_output_len = sizeof(all_output),
};
static const struct gbasm_test *tests[] = {
&all,
};
struct gbasm_tests gbasm_inc_tests = {
.name = "inc",
.num_tests = ARRAY_SIZE(tests),
.tests = tests,
};

9
src/tests/gbasm/inc.h Normal file
View File

@@ -0,0 +1,9 @@
#ifndef GBASM_TEST_INC_H
#define GBASM_TEST_INC_H
#include "tests/gbasm/test.h"
#include "common.h"
extern const struct gbasm_tests gbasm_inc_tests;
#endif

19
src/tests/gbasm/test.h Normal file
View File

@@ -0,0 +1,19 @@
#ifndef GBASM_TEST_H
#define GBASM_TEST_H
#include <stdint.h>
struct gbasm_test {
const char *name;
const char *asm_source;
const uint8_t *expected_output;
const int expected_output_len;
};
struct gbasm_tests {
const char *name;
int num_tests;
const struct gbasm_test **tests;
};
#endif