diff options
-rw-r--r-- | asmmon.h | 8 | ||||
-rw-r--r-- | assemble.c | 6 | ||||
-rw-r--r-- | disasm.c | 32 | ||||
-rw-r--r-- | disasm.h | 10 | ||||
-rw-r--r-- | enums.h | 10 | ||||
-rw-r--r-- | lexer.c | 8 | ||||
-rw-r--r-- | programs/sub-suite/subsuite.s | 2 | ||||
-rw-r--r-- | programs/sub-suite/tmp-stuff/cmd_cpy.c | 33 | ||||
-rw-r--r-- | programs/sub-suite/tmp-stuff/free-new.s (renamed from programs/sub-suite/free-new.s) | 0 | ||||
-rw-r--r-- | programs/sub-suite/tmp-stuff/free-old.s (renamed from programs/sub-suite/free-old.s) | 0 | ||||
-rw-r--r-- | programs/sub-suite/tmp-stuff/print_char.s (renamed from programs/sub-suite/print_char.s) | 0 | ||||
-rw-r--r-- | programs/sub-suite/tmp-stuff/shift_line.c (renamed from programs/sub-suite/shift_line.c) | 0 | ||||
-rw-r--r-- | programs/sub-suite/tmp-stuff/subeditor-new.s (renamed from programs/sub-suite/subeditor-new.s) | 0 | ||||
-rw-r--r-- | programs/sub-suite/tmp-stuff/test-size.s (renamed from programs/sub-suite/test-size.s) | 0 | ||||
-rw-r--r-- | sux.c | 2 | ||||
-rw-r--r-- | sux.h | 43 | ||||
-rw-r--r-- | test/ortho.s | 2 |
17 files changed, 103 insertions, 53 deletions
@@ -280,13 +280,13 @@ enum baseext_ortho { static const uint8_t ext_ortho_ops[9] = { [OP_LEA] = 0x63, - [OP_PEA] = 0x0C, + [OP_PEA] = 0x4C, [OP_ADD] = 0x03, [OP_SUB] = 0x23, [OP_NOT] = 0x44, [OP_CLZ] = 0xC4, [OP_CLO] = 0xE4, - [OP_SWP] = 0x2C, + [OP_SWP] = 0x6C, [OP_PCN] = 0x43 }; @@ -357,8 +357,8 @@ static const instruction inst[OPNUM] = { [INC] = {(AM_IMPL|AM_ZM|AM_ABS|AM_EIND2|AM_ORTHO2), 0xA4}, [INX] = {(AM_IMPL), 0xC9}, [INY] = {(AM_IMPL), 0x89}, - [JMP] = {(AM_ABS|AM_IND|AM_ZM2|AM_EIND), 0x00}, - [JSR] = {(AM_ABS|AM_IND|AM_ZM2|AM_EIND), 0x20}, + [JMP] = {(AM_ABS|AM_IND|AM_ZM2|AM_EIND|AM_ORTHO|AM_ORTHO2), 0x00}, + [JSR] = {(AM_ABS|AM_IND|AM_ZM2|AM_EIND|AM_ORTHO|AM_ORTHO2), 0x20}, [LDA] = {(AM_IMM|AM_ZM|AM_ZMX|AM_ZMY|AM_IND|AM_INDX|AM_INDY|AM_ABS|AM_EIND), 0xC2}, [LDB] = {(AM_IMM|AM_ZM|AM_ZMX|AM_ZMY|AM_IND|AM_INDX|AM_INDY|AM_ABS|AM_EIND), 0xE2}, [LDX] = {(AM_IMM|AM_ZM|AM_IND|AM_ABS|AM_EIND2), 0x64}, @@ -898,7 +898,11 @@ uint64_t handle_opcode(token *t, bytecount *bc, uint8_t isasm, uint64_t address, int i2 = 0; int j = 0; (op[i].type == 1) ? (opcode |= (1 << (3+!i))) : (opcode &= ~(1 << (3+!i))); - if (op[i].type == 1 && (am & AM_ORTHO|AM_ORTHO2)) { + if ((am & (AM_ORTHO|AM_ORTHO2)) == (AM_ORTHO|AM_ORTHO2)) { + opcode |= 0x0C; + } + + if (op[i].type == 1 && (am & (AM_ORTHO|AM_ORTHO2))) { switch (op[i].id) { case MEM_RIND: break; case MEM_IMM: @@ -217,36 +217,6 @@ static int is_os(uint8_t opcode, operand *op) { return 0; } -static int is_1cc(uint8_t opcode) { - switch (opcode) { - case ORTHO_1CC(SET, NG): - case ORTHO_1CC(SET, PO): - case ORTHO_1CC(SET, CS): - case ORTHO_1CC(SET, CC): - case ORTHO_1CC(SET, EQ): - case ORTHO_1CC(SET, NE): - case ORTHO_1CC(SET, VS): - case ORTHO_1CC(SET, VC): return 1; - } - return 0; -} - -static int is_1op(uint8_t opcode) { - switch (opcode) { - case ORTHO_1OP(PSH): - case ORTHO_1OP(PEA): - case ORTHO_1OP(PUL): - case ORTHO_1OP(SWP): - case ORTHO_1OP(NOT): - case ORTHO_1OP(NEG): - case ORTHO_1OP(DEC): - case ORTHO_1OP(INC): - case ORTHO_1OP(CLZ): - case ORTHO_1OP(CLO): return 1; - } - return 0; -} - static int is_2op(uint8_t opcode) { switch (opcode) { case ORTHO_2OP(MNG): @@ -437,7 +407,7 @@ void disasm(struct sux *cpu, WINDOW *w, uint8_t lines, uint8_t opcode, uint8_t p if (ext_prefix != 0x1D) { address = get_addr(cpu, opcode, prefix, ext_prefix, 0, 0, thread); } else { - get_ortho_addr(cpu, prefix, cpu->pc, ortho_op, ortho_addr, op_type, op_id, 0, 0, thread); + get_ortho_addr(cpu, opcode, prefix, cpu->pc, ortho_op, ortho_addr, op_type, op_id, 0, 0, thread); } uint8_t rs = (prefix >> 4) & 3; char *postfix; @@ -365,7 +365,7 @@ static const char *ortho_opname[] = { ORTHO_2OP(ADD/**/), /* ADD Ortho. */ ORTHO_1OP(PSH/**/), /* PuSH operand onto the stack. */ ORTHO_1CC(SET, NG), /* SET if NeGative. */ - ORTHO_1OP(PEA/**/), /* PEA Ortho. */ + ORTHO_1OP(JMP/**/), /* JMP Ortho. */ /* 0x20-0x3C */ ORTHO_2OP(MPO/**/), /* Move if POsitive. */ ORTHO_2OP(SBC/**/), /* SBC Ortho. */ @@ -373,21 +373,23 @@ static const char *ortho_opname[] = { ORTHO_2OP(SUB/**/), /* SUB Ortho. */ ORTHO_1OP(PUL/**/), /* PuLl operand off of the stack. */ ORTHO_1CC(SET, PO), /* SET if POsitive. */ - ORTHO_1OP(SWP/**/), /* SWP Ortho. */ - /* 0x40-0x55 */ + ORTHO_1OP(JSR/**/), /* JSR Ortho. */ + /* 0x40-0x5C */ ORTHO_2OP(MCS/**/), /* Move if Carry Set. */ ORTHO_2OP(AND/**/), /* AND Ortho. */ ORTHO_2OP(DIV/**/), /* DIV Ortho. */ ORTHO_2OP(PCN/**/), /* PCN Ortho. */ ORTHO_1OP(NOT/**/), /* NOT Ortho. */ ORTHO_1CC(SET, CS), /* SET if Carry Set. */ - /* 0x60-0x75 */ + ORTHO_1OP(PEA/**/), /* PEA Ortho. */ + /* 0x60-0x7C */ ORTHO_2OP(MCC/**/), /* Move if Carry Clear. */ ORTHO_2OP(OR /**/), /* Bitwise OR. */ ORTHO_2OP(ASR/**/), /* ASR Ortho. */ ORTHO_2OP(LEA/**/), /* LEA Ortho. */ ORTHO_1OP(NEG/**/), /* NEGate operand. */ ORTHO_1CC(SET, CC), /* SET if Carry Clear. */ + ORTHO_1OP(SWP/**/), /* SWP Ortho. */ /* 0x80-0x95 */ ORTHO_2OP(MEQ/**/), /* Move if EQual. */ ORTHO_2OP(XOR/**/), /* XOR Ortho. */ @@ -560,7 +560,7 @@ enum ortho { ORTHO_2OP(ADD, 0x03/**/), /* ADD Ortho. */ ORTHO_1OP(PSH, 0x04/**/), /* PuSH operand onto the stack. */ ORTHO_1CC(SET, 0x05, NG), /* SET if NeGative. */ - ORTHO_1OP(PEA, 0x0C/**/), /* PEA Ortho. */ + ORTHO_1OP(JMP, 0x0C/**/), /* JMP Ortho. */ /* 0x20-0x3C */ ORTHO_2OP(MPO, 0x20/**/), /* Move if POsitive. */ ORTHO_2OP(SBC, 0x21/**/), /* SBC Ortho. */ @@ -568,21 +568,23 @@ enum ortho { ORTHO_2OP(SUB, 0x23/**/), /* SUB Ortho. */ ORTHO_1OP(PUL, 0x24/**/), /* PuLl operand off of the stack. */ ORTHO_1CC(SET, 0x25, PO), /* SET if POsitive. */ - ORTHO_1OP(SWP, 0x2C/**/), /* SWP Ortho. */ - /* 0x40-0x55 */ + ORTHO_1OP(JSR, 0x2C/**/), /* JSR Ortho. */ + /* 0x40-0x5C */ ORTHO_2OP(MCS, 0x40/**/), /* Move if Carry Set. */ ORTHO_2OP(AND, 0x41/**/), /* AND Ortho. */ ORTHO_2OP(DIV, 0x42/**/), /* DIV Ortho. */ ORTHO_2OP(PCN, 0x43/**/), /* PCN Ortho. */ ORTHO_1OP(NOT, 0x44/**/), /* NOT Ortho. */ ORTHO_1CC(SET, 0x45, CS), /* SET if Carry Set. */ - /* 0x60-0x75 */ + ORTHO_1OP(PEA, 0x4C/**/), /* PEA Ortho. */ + /* 0x60-0x7C */ ORTHO_2OP(MCC, 0x60/**/), /* Move if Carry Clear. */ ORTHO_2OP(OR , 0x61/**/), /* Bitwise OR. */ ORTHO_2OP(ASR, 0x62/**/), /* ASR Ortho. */ ORTHO_2OP(LEA, 0x63/**/), /* LEA Ortho. */ ORTHO_1OP(NEG, 0x64/**/), /* NEGate operand. */ ORTHO_1CC(SET, 0x65, CC), /* SET if Carry Clear. */ + ORTHO_1OP(SWP, 0x6C/**/), /* SWP Ortho. */ /* 0x80-0x95 */ ORTHO_2OP(MEQ, 0x80/**/), /* Move if EQual. */ ORTHO_2OP(XOR, 0x81/**/), /* XOR Ortho. */ @@ -773,6 +773,7 @@ int get_expr_type(char **p, uint64_t address, void *val, int *found_reg, char st expr *parse_expr(char **line, uint64_t address, int *found_reg, int is_left, char stop, uint8_t dbg) { char *str = *line; + char *start = *line; int dummy = 0; found_reg = (found_reg == NULL) ? &dummy : found_reg; @@ -833,7 +834,6 @@ expr *parse_expr(char **line, uint64_t address, int *found_reg, int is_left, cha left = new; } } - *line = str; return left; } @@ -1035,7 +1035,7 @@ uint64_t lex(char *str, uint64_t address, uint16_t bline, uint8_t dbg) { lex_type = TOK_EXPR; memset(lexeme, 0, strlen(lexeme)+1); char *tmp = &str[i]; - expr *e = parse_expr(&tmp, address, NULL, 1, delm, dbg); + expr *e = parse_expr(&tmp, address, NULL, 0, delm, dbg); t = make_token(lex_type, 0, space, tab, 0, "", NULL, e); j = tmp - &str[i]; memcpy(lexeme, &str[i], j); @@ -1070,7 +1070,7 @@ uint64_t lex(char *str, uint64_t address, uint16_t bline, uint8_t dbg) { memset(lexeme, 0, strlen(lexeme)+1); do { char *tmp = &str[i]; - expr *e = parse_expr(&tmp, address, NULL, 1, delm, dbg); + expr *e = parse_expr(&tmp, address, NULL, 0, delm, dbg); t = make_token(lex_type, 0, space, tab, 0, "", NULL, e); j = tmp - &str[i]; memcpy(lexeme, &str[i], j); @@ -1296,7 +1296,7 @@ uint64_t lex(char *str, uint64_t address, uint16_t bline, uint8_t dbg) { lex_type = TOK_EXPR; memset(lexeme, 0, strlen(lexeme)+1); char *tmp = &str[i]; - expr *e = parse_expr(&tmp, address, NULL, 1, delm, dbg); + expr *e = parse_expr(&tmp, address, NULL, 0, delm, dbg); j = tmp - &str[i]; memcpy(lexeme, &str[i], j); /*i += j;*/ diff --git a/programs/sub-suite/subsuite.s b/programs/sub-suite/subsuite.s index 7b31c31..3fc025d 100644 --- a/programs/sub-suite/subsuite.s +++ b/programs/sub-suite/subsuite.s @@ -20,5 +20,5 @@ a ;.org reset ;v ;f "subsuite.bin" $8000 -;q +q d diff --git a/programs/sub-suite/tmp-stuff/cmd_cpy.c b/programs/sub-suite/tmp-stuff/cmd_cpy.c new file mode 100644 index 0000000..6b89e7d --- /dev/null +++ b/programs/sub-suite/tmp-stuff/cmd_cpy.c @@ -0,0 +1,33 @@ +#include <stdint.h> + +int cmd_size = 0x400; +int maxcol = 80; + +extern uint8_t scr_row; +extern uint8_t scr_col; +extern uint8_t scr_str; + +int find_end(char *str, int pos) { + int i; + for (i = pos; str[i] != '\0'; i++); + return i; +} + +void cmd_cpy(char *scr_buf, char *cmd_buf, int pos) { + int end_line = (find_end(scr_buf, pos)/(maxcol+1)) - scr_str; + int start_line = (find_start(scr_buf, end_line) + scr_str) * (maxcol+1); + + for (int i = 0, done = 0; !done; i++) { + uint64_t tmp = (uint64_t)scr_buf[i]; + for (int j = 0; j < 8; j++ , tmp >>= 8) { + int idx = (i*8) + j; + uint8_t tmp2 = tmp; + if (idx >= cmd_size || !tmp2) { + done = 1; + cmd_buf[idx] = '\0'; + break; + } + cmd_buf[idx] = tmp2; + } + } +} diff --git a/programs/sub-suite/free-new.s b/programs/sub-suite/tmp-stuff/free-new.s index dad19d0..dad19d0 100644 --- a/programs/sub-suite/free-new.s +++ b/programs/sub-suite/tmp-stuff/free-new.s diff --git a/programs/sub-suite/free-old.s b/programs/sub-suite/tmp-stuff/free-old.s index 7f75edd..7f75edd 100644 --- a/programs/sub-suite/free-old.s +++ b/programs/sub-suite/tmp-stuff/free-old.s diff --git a/programs/sub-suite/print_char.s b/programs/sub-suite/tmp-stuff/print_char.s index e12461c..e12461c 100644 --- a/programs/sub-suite/print_char.s +++ b/programs/sub-suite/tmp-stuff/print_char.s diff --git a/programs/sub-suite/shift_line.c b/programs/sub-suite/tmp-stuff/shift_line.c index 365666b..365666b 100644 --- a/programs/sub-suite/shift_line.c +++ b/programs/sub-suite/tmp-stuff/shift_line.c diff --git a/programs/sub-suite/subeditor-new.s b/programs/sub-suite/tmp-stuff/subeditor-new.s index 6c1cfb1..6c1cfb1 100644 --- a/programs/sub-suite/subeditor-new.s +++ b/programs/sub-suite/tmp-stuff/subeditor-new.s diff --git a/programs/sub-suite/test-size.s b/programs/sub-suite/tmp-stuff/test-size.s index b543a36..b543a36 100644 --- a/programs/sub-suite/test-size.s +++ b/programs/sub-suite/tmp-stuff/test-size.s @@ -117,7 +117,7 @@ int is_wait_kbd(struct sux *cpu, uint8_t opcode, uint8_t prefix, uint8_t ext_pre if (ext_prefix != 0x1D) { address = get_addr(cpu, opcode, prefix, ext_prefix, 0, 0, thread); } else { - get_ortho_addr(cpu, prefix, cpu->pc, ortho_op, ortho_addr, op_type, op_id, 0, 0, thread); + get_ortho_addr(cpu, opcode, prefix, cpu->pc, ortho_op, ortho_addr, op_type, op_id, 0, 0, thread); } cpu->pc = tmp_pc; return (address == CTRL_ADDR || ortho_addr[0] == CTRL_ADDR || ortho_addr[1] == CTRL_ADDR); @@ -119,6 +119,38 @@ static /*inline*/ uint8_t get_ortho_addrsize(uint8_t prefix, uint8_t addrmode) { return get_addrsize(prefix, type); } +static int is_1op(uint8_t opcode) { + switch (opcode) { + case ORTHO_1OP(JMP): + case ORTHO_1OP(JSR): + case ORTHO_1OP(PSH): + case ORTHO_1OP(PEA): + case ORTHO_1OP(PUL): + case ORTHO_1OP(SWP): + case ORTHO_1OP(NOT): + case ORTHO_1OP(NEG): + case ORTHO_1OP(DEC): + case ORTHO_1OP(INC): + case ORTHO_1OP(CLZ): + case ORTHO_1OP(CLO): return 1; + } + return 0; +} + +static int is_1cc(uint8_t opcode) { + switch (opcode) { + case ORTHO_1CC(SET, NG): + case ORTHO_1CC(SET, PO): + case ORTHO_1CC(SET, CS): + case ORTHO_1CC(SET, CC): + case ORTHO_1CC(SET, EQ): + case ORTHO_1CC(SET, NE): + case ORTHO_1CC(SET, VS): + case ORTHO_1CC(SET, VC): return 1; + } + return 0; +} + static /*inline*/ uint8_t isrw(uint8_t opcode, uint8_t ext_prefix) { if ((ext_prefix & 0xD) == 0xD) { switch (ext_prefix >> 4) { @@ -535,9 +567,12 @@ static /*inline*/ uint64_t ortho_ind_idx_addr(struct sux *cpu, uint8_t prefix, u } } -static /*inline*/ uint64_t get_ortho_addr(struct sux *cpu, uint8_t prefix, uint64_t address, operand *op, uint64_t *value, uint8_t *op_type, uint8_t *op_id, uint8_t inc_pc, uint8_t inc_clk, uint8_t thread) { +static /*inline*/ uint64_t get_ortho_addr(struct sux *cpu, uint8_t opcode, uint8_t prefix, uint64_t address, operand *op, uint64_t *value, uint8_t *op_type, uint8_t *op_id, uint8_t inc_pc, uint8_t inc_clk, uint8_t thread) { uint64_t tmp_addr = address; - for (int i = 0; i < 2; i++) { + + int num_ops = 1 + !(is_1op(opcode) || is_1cc(opcode)); + + for (int i = 0; i < num_ops; i++) { union reg tmp; tmp.u64 = 0; op[i].type = op_type[i]; @@ -963,7 +998,7 @@ static /*inline*/ void exec_ortho_inst(struct sux *cpu, uint8_t opcode, uint8_t int is_lea = ((opcode & ~0x18) == LEA_RR); int is_write = 1; operand op[2]; - cpu->pc = get_ortho_addr(cpu, prefix, cpu->pc, op, address, op_type, op_id, 1, 1, thread); + cpu->pc = get_ortho_addr(cpu, opcode, prefix, cpu->pc, op, address, op_type, op_id, 1, 1, thread); for (int i = 0; i < 2; i++) { if (op[i].type) { if (is_lea) { @@ -1077,6 +1112,8 @@ static /*inline*/ void exec_ortho_inst(struct sux *cpu, uint8_t opcode, uint8_t is_write = 0; } while (0); break; + case ORTHO_1OP(JSR): push(cpu, cpu->pc, (size) ? size : 7, thread); /* Falls Through. */ + case ORTHO_1OP(JMP): cpu->pc = (op[0].type) ? address[0] : dst; break; case ORTHO_1OP(INC): dst = inc_dec(cpu, dst, (op[0].type) ? size+1 : 8, 1, thread); break; case ORTHO_1OP(DEC): dst = inc_dec(cpu, dst, (op[0].type) ? size+1 : 8, 0, thread); break; case ORTHO_1OP(PSH): push(cpu, dst, size, thread); is_write = 0; break; diff --git a/test/ortho.s b/test/ortho.s index c7cdd83..6499d6e 100644 --- a/test/ortho.s +++ b/test/ortho.s @@ -32,6 +32,8 @@ reset: lea s, count mov (e), #0 mov a, (e) + lea d, loop + jmp (d) loop: inc b inc.q count |