From e9bff7768290a38e02f693166d4c202d3dd86517 Mon Sep 17 00:00:00 2001 From: neauoire Date: Thu, 9 Nov 2023 10:05:33 -0800 Subject: [PATCH] Standardized phep --- src/gyodis.c | 10 +++++----- src/gyoemu.c | 22 +++++++++++----------- src/tern.c | 18 +++++++++++++----- src/tern.h | 4 ++-- 4 files changed, 31 insertions(+), 23 deletions(-) diff --git a/src/gyodis.c b/src/gyodis.c index 897b642..9677230 100644 --- a/src/gyodis.c +++ b/src/gyodis.c @@ -23,13 +23,13 @@ void disinstr(uc15 inst) { if((inst & 0x3) == 2) { - putchar('#'), phep(inst >> 2); + putchar('#'), phep(inst >> 2, 5); return; } else if((inst & 0x3) == 1) { switch((inst >> 2) & 0x3) { - case 0: printf("%s:", "call"), phep(inst >> 4); break; - case 1: putchar('?'), phep(inst >> 4); break; - case 2: putchar('>'), phep(inst >> 4); break; + case 0: printf("%s:", "call"), phep(inst >> 4, 5); break; + case 1: putchar('?'), phep(inst >> 4, 5); break; + case 2: putchar('>'), phep(inst >> 4, 5); break; } return; } else { @@ -83,7 +83,7 @@ disassemble(FILE *f) uc15 t; while(!feof(f)) { if(fread(&t, sizeof(uc15), 1, f)) - phep(i), printf(" | "), disinstr(t), putchar('\n'); + phep(i, 5), printf(" | "), disinstr(t), putchar('\n'); i++; } return 1; diff --git a/src/gyoemu.c b/src/gyoemu.c index a75755c..f360bb2 100644 --- a/src/gyoemu.c +++ b/src/gyoemu.c @@ -69,14 +69,14 @@ void disinstr(uc15 inst) { if((inst & 0x3) == 2) { - putchar('#'), phep(inst >> 2), putchar('\n'); + putchar('#'), phep(inst >> 2, 5), putchar('\n'); return; } else if((inst & 0x3) == 1) { if(((inst >> 2) & 0x3) == 1) { - putchar('?'), phep(inst >> 4), putchar('\n'); + putchar('?'), phep(inst >> 4, 5), putchar('\n'); return; } else if(((inst >> 2) & 0x3) == 0) { - putchar('>'), phep(inst >> 4), putchar('\n'); + putchar('>'), phep(inst >> 4, 5), putchar('\n'); return; } printf("CALL\n"); @@ -129,23 +129,23 @@ void print_instruction(uc15 inst, uc15 pc) { uc15 addr; - phep(pc), putchar('='); - phep(inst), putchar(' '); + phep(pc, 5), putchar('='); + phep(inst, 5), putchar(' '); switch(inst & 0x3) { case 0x2: - printf("[ #"), phep(inst >> 2), printf(" ][+] "); + printf("[ #"), phep(inst >> 2, 5), printf(" ][+] "); break; case 0x1: addr = inst >> 0x4; switch(inst & 0xf) { case 0x9: /* JMP */ - printf("[ >"), phep(addr), printf(" ][+][0] "); + printf("[ >"), phep(addr, 5), printf(" ][+][0] "); break; case 0x5: /* JCN */ - printf("[ ?"), phep(addr), printf(" ][0][0] "); + printf("[ ?"), phep(addr, 5), printf(" ][0][0] "); break; case 0x1: /* JSR */ - printf("[ call:"), phep(addr), printf(" ][-][0] "); + printf("[ call:"), phep(addr, 5), printf(" ][-][0] "); break; } break; @@ -159,7 +159,7 @@ print_instruction(uc15 inst, uc15 pc) uc3 x = (opc >> 12) & 0x3; uc3 o = (opc >> 14) & 0x3; uc15 ins = opc >> 16; - printf("[ "), phep(ins); + printf("[ "), phep(ins, 5); printf(" ][%c][%c][%c][%c][ %s ][%c][%c][-] ", trit2char(o), trit2char(x), @@ -181,7 +181,7 @@ print_stack(uc15 *stack, int ptr) if(!ptr) printf(".."); for(i = 1; i <= ptr; i++) - phep(stack[i]), printf(" "); + phep(stack[i], 5), printf(" "); } void diff --git a/src/tern.c b/src/tern.c index 98cd771..9655b0b 100644 --- a/src/tern.c +++ b/src/tern.c @@ -14,15 +14,23 @@ WITH REGARD TO THIS SOFTWARE. */ void -phep(uc15 n) +pbin(uc15 t, int len) { - int i; - for(i = 4; i > -1; --i) { - int t = uc15bin((n >> (i * 6)) & 0x3f); - putchar(t ? '@' + t : '0'); + for(int i = (len << 1) - 1; i > -1; --i) { + putchar('0' + ((t >> i) & 0x1)); + if(!(i % 2) && i) putchar(' '); } } +void +phep(uc15 t, int len) +{ + int i; + for(i = len-1; i > -1; --i) { + int x = uc15bin((t >> (i * 6)) & 0x3f); + putchar(x ? '@' + x : '0'); + } +} uc15 binuc15(int n) diff --git a/src/tern.h b/src/tern.h index f7d4057..a4f98a3 100644 --- a/src/tern.h +++ b/src/tern.h @@ -14,7 +14,8 @@ WITH REGARD TO THIS SOFTWARE. typedef uint32_t uc15; typedef uint_fast8_t uc3; -void phep(uc15 n); +void pbin(uc15 n, int len); +void phep(uc15 n, int len); int uc15bin(uc15 t); uc15 binuc15(int n); @@ -25,7 +26,6 @@ uc15 op_cmp(uc15 a, uc15 b); uc15 op_una(uc15 a, uc3 gate); uc15 op_bin(uc15 a, uc15 b, uc15 gate); - uc3 chr2tri(char c); uc15 str2ter(char *str); uc15 hep2ter(char *str); -- 2.45.2