From ba534f81e41be520dfeca393014d76b124f6554b Mon Sep 17 00:00:00 2001 From: Max Regan Date: Tue, 23 May 2017 22:20:39 -0700 Subject: [PATCH] gbasm: do not differentiate immediate bit lengths Instead, treat them simply as values. Specific instructions can determine if their values are valid or representable. --- src/gbasm/gb_types.h | 18 ++++++------------ src/gbasm/operands.c | 13 +++---------- 2 files changed, 9 insertions(+), 22 deletions(-) diff --git a/src/gbasm/gb_types.h b/src/gbasm/gb_types.h index 1d2e807..5949042 100644 --- a/src/gbasm/gb_types.h +++ b/src/gbasm/gb_types.h @@ -10,11 +10,10 @@ enum gbasm_operand_type { GBASM_OPERAND_REG_8 = 0x01, /* A, B, etc */ GBASM_OPERAND_REG_16 = 0x02, /* BC, DE, etc */ - GBASM_OPERAND_IMM_8 = 0x04, /* $08, $FF */ - GBASM_OPERAND_IMM_16 = 0x08, /* $FF40, $0100 */ - GBASM_OPERAND_ADDR = 0x10, /* START, */ - GBASM_OPERAND_DEREF = 0x20, /* (HL), (HL+) */ - GBASM_OPERAND_COND = 0x40, /* C, NZ, etc */ + GBASM_OPERAND_IMM = 0x04, /* $08, $FF */ + GBASM_OPERAND_ADDR = 0x08, /* START, */ + GBASM_OPERAND_DEREF = 0x10, /* (HL), (HL+) */ + GBASM_OPERAND_COND = 0x20, /* C, NZ, etc */ }; enum gbasm_operand_r8_type { @@ -43,11 +42,7 @@ struct gbasm_operand_r16 { enum gbasm_operand_r16_type type; }; -struct gbasm_operand_d8 { - uint8_t value; -}; - -struct gbasm_operand_d16 { +struct gbasm_operand_imm { uint16_t value; }; @@ -69,8 +64,7 @@ struct gbasm_operand { union { struct gbasm_operand_r8 r8; struct gbasm_operand_r16 r16; - struct gbasm_operand_d8 d8; - struct gbasm_operand_d16 d16; + struct gbasm_operand_imm imm; struct gbasm_operand_cond cond; }; }; diff --git a/src/gbasm/operands.c b/src/gbasm/operands.c index 1d5782c..9d048e1 100644 --- a/src/gbasm/operands.c +++ b/src/gbasm/operands.c @@ -137,17 +137,10 @@ static const struct gbasm_operand_info gbasm_operand_infos[] = { static int convert_constant(const char *token, struct gbasm_operand *info) { - int val = strtol(token + 1, NULL, 0); + long val = strtol(token + 1, NULL, 0); - if (val <= 0xff || val >= -0xff) { - info->type = GBASM_OPERAND_IMM_8; - info->d8.value = val; - } else if (val <= 0xffff || val >= 0xffff) { - info->type = GBASM_OPERAND_IMM_16; - info->d16.value = val; - } else { - return -1; - } + info->type = GBASM_OPERAND_IMM; + info->imm.value = val; return 0; }