diff --git a/src/alu.c b/src/alu.c index bcc0af3..09f3cc1 100644 --- a/src/alu.c +++ b/src/alu.c @@ -188,15 +188,15 @@ static enum alu_state alu_state; // deterministic finite automaton // predefined stuff static struct ronode *op_tree = NULL; // tree to hold operators static struct ronode op_list[] = { - PREDEFNODE(s_asr, &ops_asr), - PREDEFNODE(s_lsr, &ops_lsr), - PREDEFNODE(s_asl, &ops_shift_left), + PREDEFNODE("asr", &ops_asr), + PREDEFNODE("lsr", &ops_lsr), + PREDEFNODE("asl", &ops_shift_left), PREDEFNODE("lsl", &ops_shift_left), PREDEFNODE("div", &ops_intdiv), PREDEFNODE("mod", &ops_modulo), - PREDEFNODE(s_and, &ops_and), + PREDEFNODE("and", &ops_and), PREDEFNODE("or", &ops_or), - PREDEFNODE(s_eor, &ops_eor), // FIXME - remove + PREDEFNODE("eor", &ops_eor), // FIXME - remove PREDEFLAST("xor", &ops_xor), // ^^^^ this marks the last element }; diff --git a/src/encoding.c b/src/encoding.c index 7891fc5..da409b0 100644 --- a/src/encoding.c +++ b/src/encoding.c @@ -86,9 +86,9 @@ const struct encoder encoder_file = { static struct ronode *encoder_tree = NULL; // tree to hold encoders static struct ronode encoder_list[] = { //no! PREDEFNODE("file", &encoder_file), "!ct file" is not needed; just use {} after initial loading of table! - PREDEFNODE(s_pet, &encoder_pet), - PREDEFNODE(s_raw, &encoder_raw), - PREDEFLAST(s_scr, &encoder_scr), + PREDEFNODE("pet", &encoder_pet), + PREDEFNODE("raw", &encoder_raw), + PREDEFLAST("scr", &encoder_scr), // ^^^^ this marks the last element }; diff --git a/src/global.c b/src/global.c index a59f834..52d6fcd 100644 --- a/src/global.c +++ b/src/global.c @@ -29,20 +29,7 @@ // constants - -const char s_and[] = "and"; -const char s_asl[] = "asl"; -const char s_asr[] = "asr"; -const char s_bra[] = "bra"; -const char s_brl[] = "brl"; -const char s_eor[] = "eor"; -const char s_error[] = "error"; -const char s_lsr[] = "lsr"; -const char s_scrxor[] = "scrxor"; char s_untitled[] = ""; // FIXME - this is actually const -const char s_pet[] = "pet"; -const char s_raw[] = "raw"; -const char s_scr[] = "scr"; // Exception messages during assembly diff --git a/src/global.h b/src/global.h index 310c3f0..2398e7a 100644 --- a/src/global.h +++ b/src/global.h @@ -21,19 +21,7 @@ #define SF_FOUND_BLANK (1u << 0) // statement had space or tab #define SF_IMPLIED_LABEL (1u << 1) // statement had implied label def -extern const char s_and[]; -extern const char s_asl[]; -extern const char s_asr[]; -extern const char s_bra[]; -extern const char s_brl[]; -extern const char s_eor[]; -extern const char s_error[]; -extern const char s_lsr[]; -extern const char s_scrxor[]; extern char s_untitled[]; -extern const char s_pet[]; -extern const char s_raw[]; -extern const char s_scr[]; // error messages during assembly extern const char exception_cannot_open_input_file[]; extern const char exception_missing_string[]; diff --git a/src/input.c b/src/input.c index 98ec4c2..9bc4be6 100644 --- a/src/input.c +++ b/src/input.c @@ -76,14 +76,15 @@ static void report_srcchar(char new_char) // show line number... fprintf(report->fd, "%6d ", Input_now->line_number - 1); // prepare outbytes' start address - if (report->bin_used) + if (report->bin_used) { #if _BSD_SOURCE || _XOPEN_SOURCE >= 500 || _ISOC99_SOURCE || _POSIX_C_SOURCE >= 200112L snprintf(hex_address, HEXBUFSIZE, "%04x", report->bin_address); #else sprintf(hex_address, "%04x", report->bin_address); #endif - else + } else { hex_address[0] = '\0'; + } // prepare outbytes hexdump[0] = '\0'; for (ii = 0; ii < report->bin_used; ++ii) diff --git a/src/mnemo.c b/src/mnemo.c index 426a469..2bfbbcf 100644 --- a/src/mnemo.c +++ b/src/mnemo.c @@ -15,8 +15,7 @@ #include "typesystem.h" -// Constants -#define s_ror (s_error + 2) // Yes, I know I'm sick +// constants #define MNEMO_DYNABUF_INITIALSIZE 8 // 4 + terminator should suffice // These values are needed to recognize addressing modes: @@ -179,18 +178,18 @@ static struct ronode *mnemo_m65_tree = NULL; // MEGA65 extensions static struct ronode mnemos_6502[] = { PREDEFNODE("ora", MERGE(GROUP_ACCU, IDX_ORA)), - PREDEFNODE(s_and, MERGE(GROUP_ACCU, IDX_AND)), - PREDEFNODE(s_eor, MERGE(GROUP_ACCU, IDX_EOR)), + PREDEFNODE("and", MERGE(GROUP_ACCU, IDX_AND)), + PREDEFNODE("eor", MERGE(GROUP_ACCU, IDX_EOR)), PREDEFNODE("adc", MERGE(GROUP_ACCU, IDX_ADC)), PREDEFNODE("sta", MERGE(GROUP_ACCU, IDX_STA)), PREDEFNODE("lda", MERGE(GROUP_ACCU, IDX_LDA)), PREDEFNODE("cmp", MERGE(GROUP_ACCU, IDX_CMP)), PREDEFNODE("sbc", MERGE(GROUP_ACCU, IDX_SBC)), PREDEFNODE("bit", MERGE(GROUP_MISC, IDX_BIT)), - PREDEFNODE(s_asl, MERGE(GROUP_MISC, IDX_ASL)), + PREDEFNODE("asl", MERGE(GROUP_MISC, IDX_ASL)), PREDEFNODE("rol", MERGE(GROUP_MISC, IDX_ROL)), - PREDEFNODE(s_lsr, MERGE(GROUP_MISC, IDX_LSR)), - PREDEFNODE(s_ror, MERGE(GROUP_MISC, IDX_ROR)), + PREDEFNODE("lsr", MERGE(GROUP_MISC, IDX_LSR)), + PREDEFNODE("ror", MERGE(GROUP_MISC, IDX_ROR)), PREDEFNODE("sty", MERGE(GROUP_MISC, IDX_STY)), PREDEFNODE("stx", MERGE(GROUP_MISC, IDX_STX)), PREDEFNODE("ldy", MERGE(GROUP_MISC, IDX_LDY)), @@ -209,31 +208,31 @@ static struct ronode mnemos_6502[] = { PREDEFNODE("beq", MERGE(GROUP_RELATIVE8, 0xf0)), PREDEFNODE("jmp", MERGE(GROUP_ALLJUMPS, IDX_JMP)), PREDEFNODE("jsr", MERGE(GROUP_ALLJUMPS, IDX_JSR)), - PREDEFNODE("brk", MERGE(GROUP_IMPLIEDONLY, 0)), - PREDEFNODE("php", MERGE(GROUP_IMPLIEDONLY, 8)), - PREDEFNODE("clc", MERGE(GROUP_IMPLIEDONLY, 24)), - PREDEFNODE("plp", MERGE(GROUP_IMPLIEDONLY, 40)), - PREDEFNODE("sec", MERGE(GROUP_IMPLIEDONLY, 56)), - PREDEFNODE("rti", MERGE(GROUP_IMPLIEDONLY, 64)), - PREDEFNODE("pha", MERGE(GROUP_IMPLIEDONLY, 72)), - PREDEFNODE("cli", MERGE(GROUP_IMPLIEDONLY, 88)), - PREDEFNODE("rts", MERGE(GROUP_IMPLIEDONLY, 96)), - PREDEFNODE("pla", MERGE(GROUP_IMPLIEDONLY, 104)), - PREDEFNODE("sei", MERGE(GROUP_IMPLIEDONLY, 120)), - PREDEFNODE("dey", MERGE(GROUP_IMPLIEDONLY, 136)), - PREDEFNODE("txa", MERGE(GROUP_IMPLIEDONLY, 138)), - PREDEFNODE("tya", MERGE(GROUP_IMPLIEDONLY, 152)), - PREDEFNODE("txs", MERGE(GROUP_IMPLIEDONLY, 154)), - PREDEFNODE("tay", MERGE(GROUP_IMPLIEDONLY, 168)), - PREDEFNODE("tax", MERGE(GROUP_IMPLIEDONLY, 170)), - PREDEFNODE("clv", MERGE(GROUP_IMPLIEDONLY, 184)), - PREDEFNODE("tsx", MERGE(GROUP_IMPLIEDONLY, 186)), - PREDEFNODE("iny", MERGE(GROUP_IMPLIEDONLY, 200)), - PREDEFNODE("dex", MERGE(GROUP_IMPLIEDONLY, 202)), - PREDEFNODE("cld", MERGE(GROUP_IMPLIEDONLY, 216)), - PREDEFNODE("inx", MERGE(GROUP_IMPLIEDONLY, 232)), - PREDEFNODE("nop", MERGE(GROUP_IMPLIEDONLY, 234)), - PREDEFLAST("sed", MERGE(GROUP_IMPLIEDONLY, 248)), + PREDEFNODE("brk", MERGE(GROUP_IMPLIEDONLY, 0x00)), + PREDEFNODE("php", MERGE(GROUP_IMPLIEDONLY, 0x08)), + PREDEFNODE("clc", MERGE(GROUP_IMPLIEDONLY, 0x18)), + PREDEFNODE("plp", MERGE(GROUP_IMPLIEDONLY, 0x28)), + PREDEFNODE("sec", MERGE(GROUP_IMPLIEDONLY, 0x38)), + PREDEFNODE("rti", MERGE(GROUP_IMPLIEDONLY, 0x40)), + PREDEFNODE("pha", MERGE(GROUP_IMPLIEDONLY, 0x48)), + PREDEFNODE("cli", MERGE(GROUP_IMPLIEDONLY, 0x58)), + PREDEFNODE("rts", MERGE(GROUP_IMPLIEDONLY, 0x60)), + PREDEFNODE("pla", MERGE(GROUP_IMPLIEDONLY, 0x68)), + PREDEFNODE("sei", MERGE(GROUP_IMPLIEDONLY, 0x78)), + PREDEFNODE("dey", MERGE(GROUP_IMPLIEDONLY, 0x88)), + PREDEFNODE("txa", MERGE(GROUP_IMPLIEDONLY, 0x8a)), + PREDEFNODE("tya", MERGE(GROUP_IMPLIEDONLY, 0x98)), + PREDEFNODE("txs", MERGE(GROUP_IMPLIEDONLY, 0x9a)), + PREDEFNODE("tay", MERGE(GROUP_IMPLIEDONLY, 0xa8)), + PREDEFNODE("tax", MERGE(GROUP_IMPLIEDONLY, 0xaa)), + PREDEFNODE("clv", MERGE(GROUP_IMPLIEDONLY, 0xb8)), + PREDEFNODE("tsx", MERGE(GROUP_IMPLIEDONLY, 0xba)), + PREDEFNODE("iny", MERGE(GROUP_IMPLIEDONLY, 0xc8)), + PREDEFNODE("dex", MERGE(GROUP_IMPLIEDONLY, 0xca)), + PREDEFNODE("cld", MERGE(GROUP_IMPLIEDONLY, 0xd8)), + PREDEFNODE("inx", MERGE(GROUP_IMPLIEDONLY, 0xe8)), + PREDEFNODE("nop", MERGE(GROUP_IMPLIEDONLY, 0xea)), + PREDEFLAST("sed", MERGE(GROUP_IMPLIEDONLY, 0xf8)), // ^^^^ this marks the last element }; @@ -252,7 +251,7 @@ static struct ronode mnemos_6502undoc1[] = { PREDEFNODE("sha", MERGE(GROUP_ACCU, IDXuSHA)), // {addr} = A & X & {H+1} (aka AXA aka AHX) PREDEFNODE("shx", MERGE(GROUP_MISC, IDXuSHX)), // {addr} = X & {H+1} (aka XAS aka SXA) PREDEFNODE("shy", MERGE(GROUP_MISC, IDXuSHY)), // {addr} = Y & {H+1} (aka SAY aka SYA) - PREDEFNODE(s_asr, MERGE(GROUP_MISC, IDXuASR)), // LSR + EOR (aka ALR) + PREDEFNODE("asr", MERGE(GROUP_MISC, IDXuASR)), // LSR + EOR (aka ALR) PREDEFNODE("arr", MERGE(GROUP_MISC, IDXuARR)), // ROR + ADC PREDEFNODE("sbx", MERGE(GROUP_MISC, IDXuSBX)), // DEX + CMP (aka AXS aka SAX) PREDEFNODE("nop", MERGE(GROUP_MISC, IDXuNOP)), // combines documented $ea and the undocumented dop/top below @@ -272,7 +271,7 @@ static struct ronode mnemos_6502undoc2[] = { // additional opcodes of c64dtv2: static struct ronode mnemos_c64dtv2[] = { - PREDEFNODE(s_bra, MERGE(GROUP_RELATIVE8, 0x12)), // branch always + PREDEFNODE("bra", MERGE(GROUP_RELATIVE8, 0x12)), // branch always PREDEFNODE("sac", MERGE(GROUP_MISC, IDX_SAC)), // set accumulator mapping PREDEFLAST("sir", MERGE(GROUP_MISC, IDX_SIR)), // set index register mapping // ^^^^ this marks the last element @@ -282,8 +281,8 @@ static struct ronode mnemos_c64dtv2[] = { static struct ronode mnemos_65c02[] = { // more addressing modes for some mnemonics: PREDEFNODE("ora", MERGE(GROUP_ACCU, IDXcORA)), - PREDEFNODE(s_and, MERGE(GROUP_ACCU, IDXcAND)), - PREDEFNODE(s_eor, MERGE(GROUP_ACCU, IDXcEOR)), + PREDEFNODE("and", MERGE(GROUP_ACCU, IDXcAND)), + PREDEFNODE("eor", MERGE(GROUP_ACCU, IDXcEOR)), PREDEFNODE("adc", MERGE(GROUP_ACCU, IDXcADC)), PREDEFNODE("sta", MERGE(GROUP_ACCU, IDXcSTA)), PREDEFNODE("lda", MERGE(GROUP_ACCU, IDXcLDA)), @@ -294,11 +293,11 @@ static struct ronode mnemos_65c02[] = { PREDEFNODE("dec", MERGE(GROUP_MISC, IDXcDEC)), PREDEFNODE("inc", MERGE(GROUP_MISC, IDXcINC)), // and eight new mnemonics: - PREDEFNODE(s_bra, MERGE(GROUP_RELATIVE8, 0x80)), - PREDEFNODE("phy", MERGE(GROUP_IMPLIEDONLY, 90)), - PREDEFNODE("ply", MERGE(GROUP_IMPLIEDONLY, 122)), - PREDEFNODE("phx", MERGE(GROUP_IMPLIEDONLY, 218)), - PREDEFNODE("plx", MERGE(GROUP_IMPLIEDONLY, 250)), + PREDEFNODE("bra", MERGE(GROUP_RELATIVE8, 0x80)), + PREDEFNODE("phy", MERGE(GROUP_IMPLIEDONLY, 0x5a)), + PREDEFNODE("ply", MERGE(GROUP_IMPLIEDONLY, 0x7a)), + PREDEFNODE("phx", MERGE(GROUP_IMPLIEDONLY, 0xda)), + PREDEFNODE("plx", MERGE(GROUP_IMPLIEDONLY, 0xfa)), PREDEFNODE("tsb", MERGE(GROUP_MISC, IDXcTSB)), PREDEFNODE("trb", MERGE(GROUP_MISC, IDXcTRB)), PREDEFLAST("stz", MERGE(GROUP_MISC, IDXcSTZ)), @@ -344,8 +343,8 @@ static struct ronode mnemos_bitmanips[] = { // "stp" and "wai" extensions by WDC: static struct ronode mnemos_stp_wai[] = { - PREDEFNODE("stp", MERGE(GROUP_IMPLIEDONLY, 219)), - PREDEFLAST("wai", MERGE(GROUP_IMPLIEDONLY, 203)), + PREDEFNODE("wai", MERGE(GROUP_IMPLIEDONLY, 0xcb)), + PREDEFLAST("stp", MERGE(GROUP_IMPLIEDONLY, 0xdb)), // ^^^^ this marks the last element }; @@ -359,8 +358,8 @@ static struct ronode mnemos_65816[] = { PREDEFNODE("bit", MERGE(GROUP_MISC, IDXcBIT | IM_ACCUMULATOR)), // more addressing modes for some mnemonics: PREDEFNODE("ora", MERGE(GROUP_ACCU, IDX16ORA | IM_ACCUMULATOR)), - PREDEFNODE(s_and, MERGE(GROUP_ACCU, IDX16AND | IM_ACCUMULATOR)), - PREDEFNODE(s_eor, MERGE(GROUP_ACCU, IDX16EOR | IM_ACCUMULATOR)), + PREDEFNODE("and", MERGE(GROUP_ACCU, IDX16AND | IM_ACCUMULATOR)), + PREDEFNODE("eor", MERGE(GROUP_ACCU, IDX16EOR | IM_ACCUMULATOR)), PREDEFNODE("adc", MERGE(GROUP_ACCU, IDX16ADC | IM_ACCUMULATOR)), PREDEFNODE("sta", MERGE(GROUP_ACCU, IDX16STA)), PREDEFNODE("lda", MERGE(GROUP_ACCU, IDX16LDA | IM_ACCUMULATOR)), @@ -374,27 +373,29 @@ static struct ronode mnemos_65816[] = { PREDEFNODE("jsl", MERGE(GROUP_ALLJUMPS, IDX16JSL)), PREDEFNODE("mvp", MERGE(GROUP_BOTHMOVES, 0x44)), PREDEFNODE("mvn", MERGE(GROUP_BOTHMOVES, 0x54)), - PREDEFNODE("per", MERGE(GROUP_REL16_3, 98)), - PREDEFNODE(s_brl, MERGE(GROUP_REL16_3, 130)), + PREDEFNODE("per", MERGE(GROUP_REL16_3, 0x62)), + PREDEFNODE("brl", MERGE(GROUP_REL16_3, 0x82)), PREDEFNODE("cop", MERGE(GROUP_MISC, IDX16COP)), PREDEFNODE("rep", MERGE(GROUP_MISC, IDX16REP)), PREDEFNODE("sep", MERGE(GROUP_MISC, IDX16SEP)), PREDEFNODE("pea", MERGE(GROUP_MISC, IDX16PEA)), - PREDEFNODE("phd", MERGE(GROUP_IMPLIEDONLY, 11)), - PREDEFNODE("tcs", MERGE(GROUP_IMPLIEDONLY, 27)), - PREDEFNODE("pld", MERGE(GROUP_IMPLIEDONLY, 43)), - PREDEFNODE("tsc", MERGE(GROUP_IMPLIEDONLY, 59)), - PREDEFNODE("wdm", MERGE(GROUP_IMPLIEDONLY, 66)), - PREDEFNODE("phk", MERGE(GROUP_IMPLIEDONLY, 75)), - PREDEFNODE("tcd", MERGE(GROUP_IMPLIEDONLY, 91)), - PREDEFNODE("rtl", MERGE(GROUP_IMPLIEDONLY, 107)), - PREDEFNODE("tdc", MERGE(GROUP_IMPLIEDONLY, 123)), - PREDEFNODE("phb", MERGE(GROUP_IMPLIEDONLY, 139)), - PREDEFNODE("txy", MERGE(GROUP_IMPLIEDONLY, 155)), - PREDEFNODE("plb", MERGE(GROUP_IMPLIEDONLY, 171)), - PREDEFNODE("tyx", MERGE(GROUP_IMPLIEDONLY, 187)), - PREDEFNODE("xba", MERGE(GROUP_IMPLIEDONLY, 235)), - PREDEFLAST("xce", MERGE(GROUP_IMPLIEDONLY, 251)), + PREDEFNODE("phd", MERGE(GROUP_IMPLIEDONLY, 0x0b)), + PREDEFNODE("tcs", MERGE(GROUP_IMPLIEDONLY, 0x1b)), + PREDEFNODE("pld", MERGE(GROUP_IMPLIEDONLY, 0x2b)), + PREDEFNODE("tsc", MERGE(GROUP_IMPLIEDONLY, 0x3b)), + PREDEFNODE("phk", MERGE(GROUP_IMPLIEDONLY, 0x4b)), + PREDEFNODE("tcd", MERGE(GROUP_IMPLIEDONLY, 0x5b)), + PREDEFNODE("rtl", MERGE(GROUP_IMPLIEDONLY, 0x6b)), + PREDEFNODE("tdc", MERGE(GROUP_IMPLIEDONLY, 0x7b)), + PREDEFNODE("phb", MERGE(GROUP_IMPLIEDONLY, 0x8b)), + PREDEFNODE("txy", MERGE(GROUP_IMPLIEDONLY, 0x9b)), + PREDEFNODE("plb", MERGE(GROUP_IMPLIEDONLY, 0xab)), + PREDEFNODE("tyx", MERGE(GROUP_IMPLIEDONLY, 0xbb)), + // 0xcb is WAI + // 0xdb is STP + PREDEFNODE("xba", MERGE(GROUP_IMPLIEDONLY, 0xeb)), + PREDEFNODE("xce", MERGE(GROUP_IMPLIEDONLY, 0xfb)), + PREDEFLAST("wdm", MERGE(GROUP_IMPLIEDONLY, 0x42)), // ^^^^ this marks the last element }; @@ -402,8 +403,8 @@ static struct ronode mnemos_65816[] = { static struct ronode mnemos_65ce02[] = { // 65ce02 changes (zp) addressing of 65c02 to (zp),z addressing: PREDEFNODE("ora", MERGE(GROUP_ACCU, IDXeORA)), - PREDEFNODE(s_and, MERGE(GROUP_ACCU, IDXeAND)), - PREDEFNODE(s_eor, MERGE(GROUP_ACCU, IDXeEOR)), + PREDEFNODE("and", MERGE(GROUP_ACCU, IDXeAND)), + PREDEFNODE("eor", MERGE(GROUP_ACCU, IDXeEOR)), PREDEFNODE("adc", MERGE(GROUP_ACCU, IDXeADC)), PREDEFNODE("sta", MERGE(GROUP_ACCU, IDXeSTA)), // +1 for (8,s),y PREDEFNODE("lda", MERGE(GROUP_ACCU, IDXeLDA)), // +1 for (8,s),y @@ -767,7 +768,7 @@ static bits calc_arg_size(bits force_bit, struct number *argument, bits addressi static void group_only_implied_addressing(int opcode) { // for 65ce02 and 4502, warn about buggy decimal mode - if ((opcode == 248) && (CPU_state.type->flags & CPUFLAG_DECIMALSUBTRACTBUGGY)) + if ((opcode == 0xf8) && (CPU_state.type->flags & CPUFLAG_DECIMALSUBTRACTBUGGY)) Throw_first_pass_warning("Found SED instruction for CPU with known decimal SBC bug."); Output_byte(opcode); Input_ensure_EOS(); @@ -954,7 +955,7 @@ static void group_main(int index, bits flags) case LONG_INDIRECT_ADDRESSING: // [$ff] for 65816 and m65 // if in quad mode, m65 encodes this as NOP + ($ff),z if (flags & LI_PREFIX_NOP) - Output_byte(234); + Output_byte(0xea); make_command(force_bit, &result, accu_lind8[index]); break; case LONG_INDIRECT_Y_INDEXED_ADDRESSING: // [$ff],y only for 65816 @@ -966,7 +967,7 @@ static void group_main(int index, bits flags) case LONG_INDIRECT_Z_INDEXED_ADDRESSING: // [$ff],z only for m65 // if not in quad mode, m65 encodes this as NOP + ($ff),z if (flags & LI_PREFIX_NOP) - Output_byte(234); + Output_byte(0xea); make_command(force_bit, &result, accu_lindz8[index]); break; default: // other combinations are illegal diff --git a/src/output.c b/src/output.c index d820a07..a8bd28e 100644 --- a/src/output.c +++ b/src/output.c @@ -516,7 +516,7 @@ void vcpu_set_pc(intval_t new_pc, bits segment_flags) } } pc_change = new_pc - CPU_state.pc.val.intval; - CPU_state.pc.val.intval = new_pc; + CPU_state.pc.val.intval = new_pc; // FIXME - oversized values are accepted without error and will be wrapped at end of statement! CPU_state.pc.ntype = NUMTYPE_INT; // FIXME - remove when allowing undefined! CPU_state.pc.addr_refs = 1; // yes, PC counts as address // now tell output buffer to start a new segment diff --git a/src/pseudoopcodes.c b/src/pseudoopcodes.c index 5f87eab..d5d2412 100644 --- a/src/pseudoopcodes.c +++ b/src/pseudoopcodes.c @@ -32,10 +32,6 @@ enum eos { }; // constants -static const char s_08[] = "08"; -#define s_8 (s_08 + 1) // Yes, I know I'm sick -#define s_sl (s_asl + 1) // Yes, I know I'm sick -#define s_rl (s_brl + 1) // Yes, I know I'm sick static const char exception_unknown_pseudo_opcode[] = "Unknown pseudo opcode."; @@ -105,7 +101,7 @@ static enum eos po_initmem(void) // get value ALU_defined_int(&intresult); - if ((intresult.val.intval > 0xff) || (intresult.val.intval < -0x80)) + if ((intresult.val.intval > 255) || (intresult.val.intval < -128)) Throw_error(exception_number_out_of_range); if (output_initmem(intresult.val.intval & 0xff)) return SKIP_REMAINDER; @@ -121,7 +117,7 @@ static enum eos po_xor(void) old_value = output_get_xor(); ALU_any_int(&change); - if ((change > 0xff) || (change < -0x80)) { + if ((change > 255) || (change < -128)) { Throw_error(exception_number_out_of_range); change = 0; } @@ -195,7 +191,7 @@ static enum eos iterate(void (*fn)(intval_t)) } -// Insert 8-bit values ("!08" / "!8" / "!by" / "!byte" pseudo opcode) +// insert 8-bit values ("!8" / "!08" / "!by" / "!byte" pseudo opcode) static enum eos po_byte(void) { return iterate(output_8); @@ -329,7 +325,7 @@ static enum eos user_defined_encoding(FILE *stream) } encoder_current = &encoder_file; // activate new encoding encoding_loaded_table = local_table; // activate local table - // If there's a block, parse that and then restore old values + // if there's a block, parse that and then restore old values if (Parse_optional_block()) { encoder_current = buffered_encoder; } else { @@ -457,7 +453,7 @@ static enum eos po_scrxor(void) return encode_string(&encoder_scr, xor); } -// Include binary file ("!binary" pseudo opcode) +// include binary file ("!binary" pseudo opcode) // FIXME - split this into "parser" and "worker" fn and move worker fn somewhere else. static enum eos po_binary(void) { @@ -760,13 +756,12 @@ static enum eos po_set(void) // now GotByte = illegal char return SKIP_REMAINDER; } - // TODO: in versions before 0.97, force bit handling was broken - // in both "!set" and "!for": - // trying to change a force bit correctly raised an error, but - // in any case, ALL FORCE BITS WERE CLEARED in symbol. only - // cases like !set N=N+1 worked, because the force bit was - // taken from result. - // maybe support this behaviour via --dialect? + // TODO: in versions before 0.97, force bit handling was broken in both + // "!set" and "!for": + // trying to change a force bit raised an error (which is correct), but + // in any case, ALL FORCE BITS WERE CLEARED in symbol. only cases like + // !set N=N+1 worked, because the force bit was taken from result. + // maybe support this behaviour via --dialect? I'd rather not... parse_assignment(scope, force_bit, POWER_CHANGE_VALUE | POWER_CHANGE_OBJTYPE); return ENSURE_EOS; } @@ -814,10 +809,10 @@ static enum eos po_zone(void) // set default values in case there is no valid title new_title = s_untitled; allocated = FALSE; - // Check whether a zone title is given. If yes and it can be read, + // check whether a zone title is given. if yes and it can be read, // get copy, remember pointer and remember to free it later on. if (BYTE_CONTINUES_KEYWORD(GotByte)) { - // Because we know of one character for sure, + // because we know of one character for sure, // there's no need to check the return value. Input_read_keyword(); new_title = DynaBuf_get_copy(GlobalDynaBuf); @@ -827,7 +822,7 @@ static enum eos po_zone(void) // section type is "subzone", just in case a block follows section_new(section_now, "Subzone", new_title, allocated); if (Parse_optional_block()) { - // Block has been parsed, so it was a SUBzone. + // block has been parsed, so it was a SUBzone. section_finalize(section_now); // end inner zone *section_now = entry_values; // restore entry values } else { @@ -1157,6 +1152,60 @@ static enum eos po_macro(void) // now GotByte = illegal char return ENSURE_EOS; } +/* +// trace/watch +#define TRACEWATCH_LOAD (1u << 0) +#define TRACEWATCH_STORE (1u << 1) +#define TRACEWATCH_EXEC (1u << 2) +#define TRACEWATCH_DEFAULT (TRACEWATCH_LOAD | TRACEWATCH_STORE | TRACEWATCH_EXEC) +#define TRACEWATCH_BREAK (1u << 3) +static enum eos tracewatch(boolean enter_monitor) +{ + struct number pc; + bits flags = 0; + + vcpu_read_pc(&pc); + SKIPSPACE(); + // check for flags + if (GotByte != CHAR_EOS) { + do { + // parse flag. if no keyword given, give up + if (Input_read_and_lower_keyword() == 0) + return SKIP_REMAINDER; // fail (error has been reported) + + if (strcmp(GlobalDynaBuf->buffer, "load") == 0) { + flags |= TRACEWATCH_LOAD; + } else if (strcmp(GlobalDynaBuf->buffer, "store") == 0) { + flags |= TRACEWATCH_STORE; + } else if (strcmp(GlobalDynaBuf->buffer, "exec") == 0) { + flags |= TRACEWATCH_EXEC; + } else { + Throw_error("Unknown flag (known are: load, store, exec)."); // FIXME - add to docs! + return SKIP_REMAINDER; + } + } while (Input_accept_comma()); + } + // shortcut: no flags at all -> set all flags! + if (!flags) + flags = TRACEWATCH_DEFAULT; + if (enter_monitor) + flags |= TRACEWATCH_BREAK; + if (pc.ntype != NUMTYPE_UNDEFINED) { + //FIXME - store pc and flags! + } + return ENSURE_EOS; +} +// make next byte a trace point (for VICE debugging) +static enum eos po_trace(void) +{ + return tracewatch(FALSE); // do not enter monitor, just output +} +// make next byte a watch point (for VICE debugging) +static enum eos po_watch(void) +{ + return tracewatch(TRUE); // break into monitor +} +*/ // constants #define USERMSG_DYNABUF_INITIALSIZE 80 @@ -1250,10 +1299,10 @@ static struct ronode pseudo_opcode_list[] = { PREDEFNODE("initmem", po_initmem), PREDEFNODE("xor", po_xor), PREDEFNODE("to", po_to), - PREDEFNODE(s_8, po_byte), - PREDEFNODE(s_08, po_byte), PREDEFNODE("by", po_byte), PREDEFNODE("byte", po_byte), + PREDEFNODE("8", po_byte), + PREDEFNODE("08", po_byte), // legacy alias, don't ask... PREDEFNODE("wo", po_16), PREDEFNODE("word", po_16), PREDEFNODE("16", po_16), @@ -1272,10 +1321,10 @@ static struct ronode pseudo_opcode_list[] = { PREDEFNODE("convtab", po_convtab), PREDEFNODE("tx", po_text), PREDEFNODE("text", po_text), - PREDEFNODE(s_raw, po_raw), - PREDEFNODE(s_pet, po_pet), - PREDEFNODE(s_scr, po_scr), - PREDEFNODE(s_scrxor, po_scrxor), + PREDEFNODE("raw", po_raw), + PREDEFNODE("pet", po_pet), + PREDEFNODE("scr", po_scr), + PREDEFNODE("scrxor", po_scrxor), PREDEFNODE("bin", po_binary), PREDEFNODE("binary", po_binary), PREDEFNODE("fi", po_fill), @@ -1287,13 +1336,13 @@ static struct ronode pseudo_opcode_list[] = { PREDEFNODE("cpu", po_cpu), PREDEFNODE("al", po_al), PREDEFNODE("as", po_as), - PREDEFNODE(s_rl, po_rl), + PREDEFNODE("rl", po_rl), PREDEFNODE("rs", po_rs), PREDEFNODE("addr", po_address), PREDEFNODE("address", po_address), // PREDEFNODE("enum", po_enum), PREDEFNODE("set", po_set), - PREDEFNODE(s_sl, po_symbollist), + PREDEFNODE("sl", po_symbollist), PREDEFNODE("symbollist", po_symbollist), PREDEFNODE("zn", po_zone), PREDEFNODE("zone", po_zone), @@ -1308,10 +1357,12 @@ static struct ronode pseudo_opcode_list[] = { PREDEFNODE("do", po_do), PREDEFNODE("while", po_while), PREDEFNODE("macro", po_macro), +/* PREDEFNODE("trace", po_trace), + PREDEFNODE("watch", po_watch), */ // PREDEFNODE("debug", po_debug), // PREDEFNODE("info", po_info), PREDEFNODE("warn", po_warn), - PREDEFNODE(s_error, po_error), + PREDEFNODE("error", po_error), PREDEFNODE("serious", po_serious), PREDEFNODE("eof", po_endoffile), PREDEFLAST("endoffile", po_endoffile), diff --git a/src/symbol.c b/src/symbol.c index c04db6b..6a0b06e 100644 --- a/src/symbol.c +++ b/src/symbol.c @@ -232,6 +232,7 @@ void symbols_vicelabels(FILE *fd) fputc('\n', fd); // dump address symbols Tree_dump_forest(symbols_forest, SCOPE_GLOBAL, dump_vice_address, fd); + // TODO - add trace points and watch points with load/store/exec args! } diff --git a/src/version.h b/src/version.h index 9c8b283..951320b 100644 --- a/src/version.h +++ b/src/version.h @@ -9,7 +9,7 @@ #define RELEASE "0.97" // update before release FIXME #define CODENAME "Zem" // update before release -#define CHANGE_DATE "4 Jul" // update before release FIXME +#define CHANGE_DATE "12 Jul" // update before release FIXME #define CHANGE_YEAR "2020" // update before release //#define HOME_PAGE "http://home.pages.de/~mac_bacon/smorbrod/acme/" #define HOME_PAGE "http://sourceforge.net/p/acme-crossass/" // FIXME