summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormrb0nk500 <b0nk@b0nk.xyz>2022-02-02 15:14:31 -0400
committermrb0nk500 <b0nk@b0nk.xyz>2022-02-02 15:14:31 -0400
commita14401b261d8f38f30676f993acbc1def7482c22 (patch)
tree46cd7ca0af24cae1ce1c16c8acbf4160a813bccc
parentf508cbeaad62b3cdc77cb295ce105c3527ba019c (diff)
sux.c, sux.h: Add code for using the new instruction
handler.
-rw-r--r--sux.c36
-rw-r--r--sux.h68
2 files changed, 91 insertions, 13 deletions
diff --git a/sux.c b/sux.c
index dce4d29..5df1ad3 100644
--- a/sux.c
+++ b/sux.c
@@ -185,10 +185,10 @@ void *run(void *args) {
#endif
address.u64 = 0;
value.u64 = 0;
- uint32_t inst = read_value(cpu, 0, cpu->pc, 4, 1, 0);
- uint8_t *tmp_inst = (uint8_t *)&inst;
+ uint32_t instr = read_value(cpu, 0, cpu->pc, 4, 1, 0);
+ uint8_t *tmp_inst = (uint8_t *)&instr;
uint8_t inst_len = 0;
- prefix = ((inst & 3) == 3) ? tmp_inst[inst_len++] : 0;
+ prefix = ((instr & 3) == 3) ? tmp_inst[inst_len++] : 0;
ext_prefix = ((tmp_inst[inst_len] & 0xF) == 0xD) ? tmp_inst[inst_len++] : 0;
opcode = tmp_inst[inst_len++];
op_id = (ext_prefix == 0x1D) ? tmp_inst[inst_len++] : 0;
@@ -200,6 +200,7 @@ void *run(void *args) {
uint8_t tmp_opcode = opcode;
uint8_t tmp_ext_prefix = ext_prefix;
int is_ortho = 0;
+ int is_ext = 0;
if (ext_prefix) {
ext_id = (ext_prefix >> 4);
switch (ext_id) {
@@ -207,6 +208,7 @@ void *run(void *args) {
am = ext_optype[opcode];
if (!is_extop(opcode, 0)) {
tmp_ext_prefix = 0;
+ is_ext = 1;
switch (opcode) {
case ADC_E: tmp_opcode = ADC_IMM; break;
case SBC_E: tmp_opcode = SBC_IMM; break;
@@ -282,14 +284,16 @@ void *run(void *args) {
cpu->pc = address.u64;
}
#endif
- if (am != IMPL && am != BREG) {
- address.u64 = get_addr(cpu, opcode, prefix, ext_prefix, 1, 1, thread);
- /*if (address.u64 > mem_size-1) {
- addr[STEP_ADDR] = 1;
- step = 1;
- }*/
- if (isrw(opcode, ext_prefix) && am != REL && isread(opcode, ext_prefix)) {
- value.u64 = read_value(cpu, 0, address.u64, size, 1, check_io);
+ if (ext_prefix && ext_id == 0) {
+ if (am != IMPL && am != BREG) {
+ address.u64 = get_addr(cpu, opcode, prefix, ext_prefix, 1, 1, thread);
+ /*if (address.u64 > mem_size-1) {
+ addr[STEP_ADDR] = 1;
+ step = 1;
+ }*/
+ if (isrw(opcode, ext_prefix) && am != REL && isread(opcode, ext_prefix)) {
+ value.u64 = read_value(cpu, 0, address.u64, size, 1, check_io);
+ }
}
}
/*decode_microinst(&uc, &uc_test, prefix, 0);*/
@@ -302,7 +306,13 @@ void *run(void *args) {
case 0x1: exec_ortho_inst(cpu, opcode, prefix, size, operand_type, ortho_id, thread); break;
}
} else {
- exec_base_inst(cpu, opcode, prefix, value.u64, address.u64, size, thread);
+ if (is_ext) {
+ exec_base_inst(cpu, opcode, prefix, value.u64, address.u64, size, thread);
+ } else {
+ const int inc_pc = 1;
+ const int inc_clk = getclk;
+ i[opcode](cpu, prefix, 7, inc_pc, inc_clk, thread);
+ }
}
/*usleep(1);*/
#if !IO
@@ -316,7 +326,7 @@ void *run(void *args) {
wrefresh(regs);
wrefresh(inst_win);
#endif
- for (; step && c != 19 && !end; c = get_key(scr));
+ for (; step && c != 19 && !end; c = get_key(scr, -1, cpu->clk));
#if debug
wrefresh(scr);
wrefresh(regs);
diff --git a/sux.h b/sux.h
index aa579fd..079750c 100644
--- a/sux.h
+++ b/sux.h
@@ -1,3 +1,5 @@
+#ifndef SUX_H
+#define SUX_H
#include "opcode.h"
#include <pthread.h>
#include <ctype.h>
@@ -1891,6 +1893,72 @@ static /*inline*/ void inst_##op(struct sux *cpu, uint8_t prefix, uint8_t size,
t(0, 0x07660376, 0x03660376, 0x16361776, 0x06761776, 0x16760576, 0x04760576, 0x04760576, 0x04760576) { setflag(tmp >> (msb-1), N); } /* Update negative flag. */ \
}
+typedef void (inst_func)(struct sux *cpu, uint8_t prefix, uint8_t size, int inc_pc, int inc_clk, uint8_t thread);
+
+#define inst_func(op) inst_##op
+
+#define INST \
+ o(00) o(01) o(02) o(03) o(04) o(05) o(06) o(07) \
+ o(08) o(09) o(0A) o(0B) o(0C) o(0D) o(0E) o(0F) \
+ o(10) o(11) o(12) o(13) o(14) o(15) o(16) o(17) \
+ o(18) o(19) o(1A) o(1B) o(1C) o(1D) o(1E) o(1F) \
+ o(20) o(21) o(22) o(23) o(24) o(25) o(26) o(27) \
+ o(28) o(29) o(2A) o(2B) o(2C) o(2D) o(2E) o(2F) \
+ o(30) o(31) o(32) o(33) o(34) o(35) o(36) o(37) \
+ o(38) o(39) o(3A) o(3B) o(3C) o(3D) o(3E) o(3F) \
+ o(40) o(41) o(42) o(43) o(44) o(45) o(46) o(47) \
+ o(48) o(49) o(4A) o(4B) o(4C) o(4D) o(4E) o(4F) \
+ o(50) o(51) o(52) o(53) o(54) o(55) o(56) o(57) \
+ o(58) o(59) o(5A) o(5B) o(5C) o(5D) o(5E) o(5F) \
+ o(60) o(61) o(62) o(63) o(64) o(65) o(66) o(67) \
+ o(68) o(69) o(6A) o(6B) o(6C) o(6D) o(6E) o(6F) \
+ o(70) o(71) o(72) o(73) o(74) o(75) o(76) o(77) \
+ o(78) o(79) o(7A) o(7B) o(7C) o(7D) o(7E) o(7F) \
+ o(80) o(81) o(82) o(83) o(84) o(85) o(86) o(87) \
+ o(88) o(89) o(8A) o(8B) o(8C) o(8D) o(8E) o(8F) \
+ o(90) o(91) o(92) o(93) o(94) o(95) o(96) o(97) \
+ o(98) o(99) o(9A) o(9B) o(9C) o(9D) o(9E) o(9F) \
+ o(A0) o(A1) o(A2) o(A3) o(A4) o(A5) o(A6) o(A7) \
+ o(A8) o(A9) o(AA) o(AB) o(AC) o(AD) o(AE) o(AF) \
+ o(B0) o(B1) o(B2) o(B3) o(B4) o(B5) o(B6) o(B7) \
+ o(B8) o(B9) o(BA) o(BB) o(BC) o(BD) o(BE) o(BF) \
+ o(C0) o(C1) o(C2) o(C3) o(C4) o(C5) o(C6) o(C7) \
+ o(C8) o(C9) o(CA) o(CB) o(CC) o(CD) o(CE) o(CF) \
+ o(D0) o(D1) o(D2) o(D3) o(D4) o(D5) o(D6) o(D7) \
+ o(D8) o(D9) o(DA) o(DB) o(DC) o(DD) o(DE) o(DF) \
+ o(E0) o(E1) o(E2) o(E3) o(E4) o(E5) o(E6) o(E7) \
+ o(E8) o(E9) o(EA) o(EB) o(EC) o(ED) o(EE) o(EF) \
+ o(F0) o(F1) o(F2) o(F3) o(F4) o(F5) o(F6) o(F7) \
+ o(F8) o(F9) o(FA) o(FB) o(FC) o(FD) o(FE) o(FF) \
+ i(100) i(101) i(102)
+
+#if 1
+#define i(n) inst(n, 0)
+#define o(n) inst(n, 0)
+INST
+#undef o
+#undef i
+#else
+#include "inst_funcs.h"
+#endif
+
+#if 0
+#define i(n) (/*const*/ inst_func *const)inst_func(n),
+#define o(n) (/*const*/ inst_func *const)inst_func(n),
+#else
+#define i(n) inst_func(n),
+#define o(n) inst_func(n),
+#endif
+
+static inst_func *const i[] = {
+ INST
+};
+#undef o
+#undef i
+
+
+
#undef ORTHO_1CC
#undef ORTHO_1OP
#undef ORTHO_2OP
+#endif