ainedit: .S_PUSH/.MSG assembler ops

Assembler ops which add a new string/message to the ain file and emit an
S_PUSH/MSG instruction. E.g. to display a message box in Rance 10:

    .S_PUSH "test"
    CALLHLL system MsgBox -1
    DELETE

The .STR and (old) .MSG ops are renamed to .SETSTR and .SETMSG.
This is a breaking change.
This commit is contained in:
Nunuhara Cabbage
2020-05-06 17:23:38 -07:00
parent 3f57ed1b74
commit 43818e636a
2 changed files with 32 additions and 6 deletions
+3 -1
View File
@@ -30,7 +30,9 @@ enum {
enum asm_pseudo_opcode {
PO_CASE = PSEUDO_OP_OFFSET,
PO_DEFAULT,
PO_STR,
PO_SETSTR,
PO_SETMSG,
PO_S_PUSH,
PO_MSG,
PO_LOCALREF,
PO_GLOBALREF,
+29 -5
View File
@@ -57,8 +57,10 @@ KHASH_MAP_INIT_STR(string_ht, size_t);
const struct instruction asm_pseudo_ops[NR_PSEUDO_OPS - PSEUDO_OP_OFFSET] = {
PSEUDO_OP(PO_CASE, ".CASE", 2),
PSEUDO_OP(PO_DEFAULT, ".DEFAULT", 1),
PSEUDO_OP(PO_STR, ".STR", 2),
PSEUDO_OP(PO_MSG, ".MSG", 2),
PSEUDO_OP(PO_SETSTR, ".SETSTR", 2),
PSEUDO_OP(PO_SETMSG, ".SETMSG", 2),
MACRO(PO_S_PUSH, ".S_PUSH", 1, 6),
MACRO(PO_MSG, ".MSG", 1, 6),
MACRO(PO_LOCALREF, ".LOCALREF", 1, 10),
MACRO(PO_LOCALREFREF, ".LOCALREFREF", 1, 10),
MACRO(PO_LOCALINC, ".LOCALINC", 1, 10),
@@ -524,9 +526,9 @@ void handle_pseudo_op(struct asm_state *state, struct parse_instruction *instr)
state->ain->switches[n_switch].default_address = state->buf_ptr;
break;
}
case PO_STR: {
case PO_SETSTR: {
int n_str = parse_integer_constant(state, kv_A(*instr->args, 0)->text);
if (n_str < 0 || n_str)
if (n_str < 0)
ASM_ERROR(state, "Invalid string index: %d", n_str);
realloc_string_table(state->ain, n_str);
if (state->ain->strings[n_str])
@@ -536,7 +538,7 @@ void handle_pseudo_op(struct asm_state *state, struct parse_instruction *instr)
free(sjis);
break;
}
case PO_MSG: {
case PO_SETMSG: {
int n_msg = parse_integer_constant(state, kv_A(*instr->args, 0)->text);
if (n_msg < 0)
ASM_ERROR(state, "Invalid message index: %d", n_msg);
@@ -548,6 +550,28 @@ void handle_pseudo_op(struct asm_state *state, struct parse_instruction *instr)
free(sjis);
break;
}
case PO_S_PUSH: {
int n_str = state->ain->nr_strings;
realloc_string_table(state->ain, n_str);
char *sjis = encode_text(kv_A(*instr->args, 0)->text);
state->ain->strings[n_str] = make_string(sjis, strlen(sjis));
free(sjis);
asm_write_opcode(state, S_PUSH);
asm_write_argument(state, n_str);
break;
}
case PO_MSG: {
int n_msg = state->ain->nr_messages;
realloc_message_table(state->ain, n_msg);
char *sjis = encode_text(kv_A(*instr->args, 0)->text);
state->ain->messages[n_msg] = make_string(sjis, strlen(sjis));
free(sjis);
asm_write_opcode(state, MSG);
asm_write_argument(state, n_msg);
break;
}
case PO_LOCALREF: {
asm_write_opcode(state, PUSHLOCALPAGE);
asm_write_opcode(state, PUSH);