From 70a7e80d3ec11ba9f48577910fc2bc4e4926c73e Mon Sep 17 00:00:00 2001 From: Max Regan Date: Sat, 20 May 2017 16:47:57 -0700 Subject: [PATCH] gbasm: add support for "ld, r8, r8" --- src/gbasm/opcodes.c | 42 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-) diff --git a/src/gbasm/opcodes.c b/src/gbasm/opcodes.c index 08c3132..15a0e28 100644 --- a/src/gbasm/opcodes.c +++ b/src/gbasm/opcodes.c @@ -74,8 +74,26 @@ int inc_dec_check(const struct gbasm_parsed_inst *inst, return 0; } -size_t inc_emit(struct emitter *emitter, - const struct gbasm_parsed_inst *inst) +static int ld_check(const struct gbasm_parsed_inst *inst, + const struct gbasm_op_info *op_info) +{ + if (inst->num_operands < 2) { + gbasm_too_many_args_error(inst, op_info); + } + + if (inst->num_operands > 2) { + gbasm_too_few_args_error(inst, op_info); + } + + if (!gbasm_argtype_in_set(op_info->operand_types[0], inst->operands[0].type)) { + gbasm_arg_wrong_type_error(inst, op_info); + } + + return 0; +} + +static size_t inc_emit(struct emitter *emitter, + const struct gbasm_parsed_inst *inst) { uint8_t opcode = 0x00; @@ -144,6 +162,18 @@ size_t dec_emit(struct emitter *emitter, return 1; } +size_t ld_emit(struct emitter *emitter, + const struct gbasm_parsed_inst *inst) +{ + uint64_t opcode = 0x40; + + opcode += inst->operands[0].r8.type * 8; + opcode += inst->operands[1].r8.type; + + emit(emitter, &opcode, 1); + + return 1; +} struct gbasm_op_info gbasm_op_infos[] = { { @@ -260,6 +290,14 @@ struct gbasm_op_info gbasm_op_infos[] = { .length = length_one_byte, .emit = dec_emit, }, + { + .opcode = "ld", + /* support all of the other operands */ + .operand_types = { GBASM_OPERAND_REG_8, GBASM_OPERAND_REG_8 }, + .check = ld_check, + .length = length_one_byte, + .emit = ld_emit, + }, };