From c46a84ba3765950df216a19bf529c831b44b2707 Mon Sep 17 00:00:00 2001 From: neauoire Date: Thu, 9 Nov 2023 19:51:44 -0800 Subject: [PATCH] Housekeeping --- src/base3.c | 2 +- src/gyo.c | 10 +++---- src/tern.c | 75 +++++++++++++++++++++++++++-------------------------- src/tern.h | 26 +++++++++---------- 4 files changed, 57 insertions(+), 56 deletions(-) diff --git a/src/base3.c b/src/base3.c index f19663e..679a6b1 100644 --- a/src/base3.c +++ b/src/base3.c @@ -73,7 +73,7 @@ main(int argc, char **argv) for(int j = -50; j <= 50; j += 1) { bc15 a = intbc15(i); bc15 b = intbc15(j); - bc15 c = bc15add(a, b); + bc15 c = bc_add(a, b); int k = bc15int(c); int l = i + j; total += 1; diff --git a/src/gyo.c b/src/gyo.c index f7a1be7..db06e58 100644 --- a/src/gyo.c +++ b/src/gyo.c @@ -18,7 +18,7 @@ gyo_eval(uc15 *rom, uc3 *ram, uc15 pc) uc15 inst, addr, opc, acc, t, n; while((inst = rom[uc15int(pc)])) { disinstr(inst); - pc = op_inc(pc); + pc = uc_inc(pc); switch(inst & 0x3) { /* LIT */ case 0x2: dst[++dsp] = inst >> 0x2; break; @@ -49,10 +49,10 @@ gyo_eval(uc15 *rom, uc3 *ram, uc15 pc) } /* ALU */ switch((opc >> 4) & 0xf) { - case OP_CM: acc = op_cmp(acc, n); break; - case OP_UN: acc = op_una(acc, opc >> 16); break; - case OP_BI: acc = op_bin(acc, n, opc >> 16); break; - case OP_AD: acc = op_add(acc, n); break; + case OP_CM: acc = uc_cmp(acc, n); break; + case OP_UN: acc = uc_una(acc, opc >> 16); break; + case OP_BI: acc = uc_bin(acc, n, opc >> 16); break; + case OP_AD: acc = uc_add(acc, n); break; case OP_LS: acc = n << (uc15int(acc) << 1); break; case OP_RS: acc = n >> (uc15int(acc) << 1); break; case OP_ST: acc = rst[rsp]; break; diff --git a/src/tern.c b/src/tern.c index 27b4834..761a6cf 100644 --- a/src/tern.c +++ b/src/tern.c @@ -155,7 +155,7 @@ bc15sign(bc15 a) } bc15 -bc15tnand(bc15 a, bc15 b) +bc_tnand(bc15 a, bc15 b) { bc15 acc = 0; int i; @@ -169,7 +169,7 @@ bc15tnand(bc15 a, bc15 b) } bc15 -bc15tnor(bc15 a, bc15 b) +bc_tnor(bc15 a, bc15 b) { bc15 acc = 0; int i, digit; @@ -188,7 +188,7 @@ bc15tnor(bc15 a, bc15 b) } bc15 -bc15negate(bc15 a) +bc_negate(bc15 a) { bc15 acc = 0; for(int i = 0; i < 30; i += 2) { @@ -200,22 +200,22 @@ bc15negate(bc15 a) } bc15 -bc15add(bc15 a, bc15 b) +bc_add(bc15 a, bc15 b) { bc15 acc = 0; int i, carry = 0; for(i = 0; i < 30; i += 2) { int digit = carry; carry = 0; - bc15carry((a >> i) & 0x3, &digit, &carry); - bc15carry((b >> i) & 0x3, &digit, &carry); + bc_carry((a >> i) & 0x3, &digit, &carry); + bc_carry((b >> i) & 0x3, &digit, &carry); acc |= (digit << i); } return acc; } void -bc15carry(int next, int *digit, int *carry) +bc_carry(int next, int *digit, int *carry) { int sum = *digit + next; int part = sum & 0x3; @@ -228,7 +228,7 @@ bc15carry(int next, int *digit, int *carry) } bc3 -bc15cmp(bc15 a, bc15 b) +bc_cmp(bc15 a, bc15 b) { int i; for(i = 28; i >= 0; i -= 2) { @@ -261,33 +261,10 @@ intuc15(int t) return acc; } -// Heptavintimal - -char -bc3hep(bc3 t) -{ - return t == 0x3f ? '0' : 'A' + bc3int(t) + 12; -} - -bc3 -hepbc3(char c) -{ - return c == '0' ? 0x3f : intbc3(c - 'A' - 12); -} - -uc15 -hepuc15(char *str) -{ - uc15 acc = 0; - char c; - while((c = *str++)) - acc <<= 6, acc |= intuc15(c ? (c - 'A') + 1 : 0); - return acc; -} - +// Operations uc15 -op_inc(uc15 a) +uc_inc(uc15 a) { int i, carry = 1; uc15 acc = 0; @@ -303,7 +280,7 @@ op_inc(uc15 a) } uc15 -op_add(uc15 a, uc15 b) +uc_add(uc15 a, uc15 b) { int i, carry = 0; uc15 acc = 0; @@ -317,7 +294,7 @@ op_add(uc15 a, uc15 b) } uc15 -op_cmp(uc15 a, uc15 b) +uc_cmp(uc15 a, uc15 b) { int i; for(i = 0; i < 32; i += 2) { @@ -330,7 +307,7 @@ op_cmp(uc15 a, uc15 b) } uc15 -op_una(uc15 a, uc3 gate) +uc_una(uc15 a, uc3 gate) { int i; uc15 acc = 0; @@ -343,7 +320,7 @@ op_una(uc15 a, uc3 gate) } uc15 -op_bin(uc15 a, uc15 b, uc15 gate) +uc_bin(uc15 a, uc15 b, uc15 gate) { int i; uc15 acc = 0; @@ -354,3 +331,27 @@ op_bin(uc15 a, uc15 b, uc15 gate) } return acc; } + +// Heptavintimal + +char +bc3hep(bc3 t) +{ + return t == 0x3f ? '0' : 'A' + bc3int(t) + 12; +} + +bc3 +hepbc3(char c) +{ + return c == '0' ? 0x3f : intbc3(c - 'A' - 12); +} + +uc15 +hepuc15(char *str) +{ + uc15 acc = 0; + char c; + while((c = *str++)) + acc <<= 6, acc |= intuc15(c ? (c - 'A') + 1 : 0); + return acc; +} diff --git a/src/tern.h b/src/tern.h index 53cd700..eb34faa 100644 --- a/src/tern.h +++ b/src/tern.h @@ -39,27 +39,27 @@ void pbc3(bc3 t); bc15 intbc15(int n); int bc15int(bc15 t); bc3 bc15sign(bc15 a); -bc15 bc15tnand(bc15 a, bc15 b); -bc15 bc15tnor(bc15 a, bc15 b); -bc15 bc15negate(bc15 a); -bc15 bc15add(bc15 a, bc15 b); -void bc15carry(int sum, int *digit, int *carry); -bc3 bc15cmp(bc15 a, bc15 b); + +bc15 bc_tnand(bc15 a, bc15 b); +bc15 bc_tnor(bc15 a, bc15 b); +bc15 bc_negate(bc15 a); +bc15 bc_add(bc15 a, bc15 b); +void bc_carry(int sum, int *digit, int *carry); +bc3 bc_cmp(bc15 a, bc15 b); // Unsigned int uc15int(uc15 t); uc15 intuc15(int n); int uc15bin(uc15 t); +uc15 uc_inc(uc15 a); +uc15 uc_add(uc15 a, uc15 b); +uc15 uc_cmp(uc15 a, uc15 b); +uc15 uc_una(uc15 a, uc3 gate); +uc15 uc_bin(uc15 a, uc15 b, uc15 gate); + // Heptavintimal char bc3hep(bc3 t); bc3 hepbc3(char c); - - uc15 hepuc15(char *str); -uc15 op_inc(uc15 a); -uc15 op_add(uc15 a, uc15 b); -uc15 op_cmp(uc15 a, uc15 b); -uc15 op_una(uc15 a, uc3 gate); -uc15 op_bin(uc15 a, uc15 b, uc15 gate); -- 2.45.2