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:
39
src/gbasm/assemble.c
Normal file
39
src/gbasm/assemble.c
Normal file
@@ -0,0 +1,39 @@
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "gbasm/assemble.h"
|
||||
#include "gbasm/parser.h"
|
||||
#include "gbasm/types.h"
|
||||
#include "gbasm/errors.h"
|
||||
#include "gbasm/opcodes.h"
|
||||
#include "common.h"
|
||||
|
||||
#define GBASM_MAX_INSTS 1024
|
||||
|
||||
struct gb_asm_prog *prog;
|
||||
|
||||
int gbasm_assemble(char *program, struct emitter *emitter)
|
||||
{
|
||||
struct gbasm_parsed_inst insts[GBASM_MAX_INSTS];
|
||||
int num_insts;
|
||||
|
||||
num_insts = gbasm_parse_buffer(program, insts, ARRAY_SIZE(insts));
|
||||
if (num_insts < 0) {
|
||||
return num_insts;
|
||||
}
|
||||
|
||||
DEBUG_LOG("parsed %d instructions\n", num_insts);
|
||||
|
||||
for (int i = 0; i < num_insts; i++) {
|
||||
DEBUG_LOG("emitting %s\n", insts[i].opcode);
|
||||
const struct gbasm_op_info *info = gbasm_get_opcode_info(insts[i].opcode);
|
||||
if (info == NULL) {
|
||||
gbasm_unknown_opcode_error(&insts[i]);
|
||||
}
|
||||
|
||||
info->check(&insts[i], info);
|
||||
info->emit(emitter, &insts[i]);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user