From 23b7ab42c88e363bcda9148461c2759efa328536 Mon Sep 17 00:00:00 2001 From: neauoire Date: Thu, 9 Nov 2023 10:20:46 -0800 Subject: [PATCH] Houeskeeping --- src/base3.c | 2 +- src/bcb.c | 7 +++--- src/gyo.c | 4 ++-- src/gyo.h | 4 ++-- src/gyoemu.c | 62 ++++++---------------------------------------------- src/tern.c | 4 +--- src/tern.h | 1 - 7 files changed, 17 insertions(+), 67 deletions(-) diff --git a/src/base3.c b/src/base3.c index eef6b0c..794a00c 100644 --- a/src/base3.c +++ b/src/base3.c @@ -77,7 +77,7 @@ main(int argc, char **argv) int k = bc15int(c); int l = i + j; total += 1; - if (k == l) { + if(k == l) { passed += 1; } else { printf("FAIL "); diff --git a/src/bcb.c b/src/bcb.c index 6f68433..822b8df 100644 --- a/src/bcb.c +++ b/src/bcb.c @@ -147,12 +147,13 @@ bc15add(bc15 a, bc15 b) { bc15 acc = 0; int i, carry = 0; - for (i = 0; i < 30 && (carry != 0 || (a>>i) != 0 || (b>>i) != 0); i += 2) { + for(i = 0; i < 30 && (carry != 0 || (a >> i) != 0 || (b >> i) != 0); i += 2) { int digit = carry; carry = 0; bc15carry((a >> i) & 0x3, &digit, &carry); bc15carry((b >> i) & 0x3, &digit, &carry); - acc |= (digit << i);; + acc |= (digit << i); + ; } return acc; } @@ -162,7 +163,7 @@ bc15carry(int next, int *digit, int *carry) { int sum = *digit + next; int part = sum & 0x3; - if (part == 2) { + if(part == 2) { *carry = (*carry + (sum >> 1)) & 0x3; *digit = (sum ^ 4) >> 1; } else { diff --git a/src/gyo.c b/src/gyo.c index cd00bd4..9abc123 100644 --- a/src/gyo.c +++ b/src/gyo.c @@ -17,7 +17,7 @@ gyo_eval(uc15 *rom, uc3 *ram, uc15 pc) { uc15 inst, addr, opc, acc, t, n; while((inst = rom[uc15bin(pc)])) { - print_instruction(inst, pc); + disinstr(inst); pc = op_inc(pc); switch(inst & 0x3) { /* LIT */ @@ -74,7 +74,7 @@ gyo_eval(uc15 *rom, uc3 *ram, uc15 pc) break; } if(!pc) return 1; - print_state(); + print_state(pc); } return 0; } diff --git a/src/gyo.h b/src/gyo.h index 7990675..0326ea2 100644 --- a/src/gyo.h +++ b/src/gyo.h @@ -27,5 +27,5 @@ extern int dsp, rsp; extern uc15 dst[0x100], rst[0x100]; extern int emu_event(uc15 addr, uc15 value); -extern void print_instruction(uc15 inst, uc15 pc); -extern void print_state(void); +extern void disinstr(uc15 inst); +extern void print_state(int pc); diff --git a/src/gyoemu.c b/src/gyoemu.c index f360bb2..e51a11e 100644 --- a/src/gyoemu.c +++ b/src/gyoemu.c @@ -69,17 +69,17 @@ void disinstr(uc15 inst) { if((inst & 0x3) == 2) { - putchar('#'), phep(inst >> 2, 5), putchar('\n'); + putchar('#'), phep(inst >> 2, 5); return; } else if((inst & 0x3) == 1) { if(((inst >> 2) & 0x3) == 1) { - putchar('?'), phep(inst >> 4, 5), putchar('\n'); + putchar('?'), phep(inst >> 4, 5); return; } else if(((inst >> 2) & 0x3) == 0) { - putchar('>'), phep(inst >> 4, 5), putchar('\n'); + putchar('>'), phep(inst >> 4, 5); return; } - printf("CALL\n"); + printf("call:"), phep(inst >> 4, 5); return; } else { /* (RST->PC,NOP,T->N) */ @@ -125,55 +125,6 @@ disinstr(uc15 inst) printf("Unknown instruciton\n"); } -void -print_instruction(uc15 inst, uc15 pc) -{ - uc15 addr; - phep(pc, 5), putchar('='); - phep(inst, 5), putchar(' '); - switch(inst & 0x3) { - case 0x2: - printf("[ #"), phep(inst >> 2, 5), printf(" ][+] "); - break; - case 0x1: - addr = inst >> 0x4; - switch(inst & 0xf) { - case 0x9: /* JMP */ - printf("[ >"), phep(addr, 5), printf(" ][+][0] "); - break; - case 0x5: /* JCN */ - printf("[ ?"), phep(addr, 5), printf(" ][0][0] "); - break; - case 0x1: /* JSR */ - printf("[ call:"), phep(addr, 5), printf(" ][-][0] "); - break; - } - break; - case 0x0: { - uc15 opc = inst >> 0x2; - uc3 ret = opc & 0x3; - uc3 imm = (opc >> 2) & 0x3; - uc3 alu = (opc >> 4) & 0xf; - uc3 dsm = (opc >> 8) & 0x3; - uc3 rsm = (opc >> 10) & 0x3; - uc3 x = (opc >> 12) & 0x3; - uc3 o = (opc >> 14) & 0x3; - uc15 ins = opc >> 16; - printf("[ "), phep(ins, 5); - printf(" ][%c][%c][%c][%c][ %s ][%c][%c][-] ", - trit2char(o), - trit2char(x), - trit2char(rsm), - trit2char(dsm), - opcodes[uc15bin(alu)], - trit2char(imm), - trit2char(ret)); - break; - } - default: printf("UNKNOWN"); break; - } -} - static void print_stack(uc15 *stack, int ptr) { @@ -185,12 +136,13 @@ print_stack(uc15 *stack, int ptr) } void -print_state(void) +print_state(int pc) { + printf("\nPC "), phep(binuc15(pc), 5), printf(" :: "); print_stack(dst, dsp); printf("| "); print_stack(rst, rsp); - printf("\n"); + printf("\n "); } void diff --git a/src/tern.c b/src/tern.c index 9655b0b..7789eea 100644 --- a/src/tern.c +++ b/src/tern.c @@ -26,7 +26,7 @@ void phep(uc15 t, int len) { int i; - for(i = len-1; i > -1; --i) { + for(i = len - 1; i > -1; --i) { int x = uc15bin((t >> (i * 6)) & 0x3f); putchar(x ? '@' + x : '0'); } @@ -130,7 +130,6 @@ op_bin(uc15 a, uc15 b, uc15 gate) return acc; } - uc15 str2ter(char *str) { @@ -141,7 +140,6 @@ str2ter(char *str) return acc; } - uc15 hep2ter(char *str) { diff --git a/src/tern.h b/src/tern.h index a4f98a3..1a1f4dc 100644 --- a/src/tern.h +++ b/src/tern.h @@ -29,4 +29,3 @@ uc15 op_bin(uc15 a, uc15 b, uc15 gate); uc3 chr2tri(char c); uc15 str2ter(char *str); uc15 hep2ter(char *str); - -- 2.45.2