~rabbits/gyo

c46a84ba3765950df216a19bf529c831b44b2707 — neauoire 1 year, 5 days ago 9d45972
Housekeeping
4 files changed, 57 insertions(+), 56 deletions(-)

M src/base3.c
M src/gyo.c
M src/tern.c
M src/tern.h
M src/base3.c => src/base3.c +1 -1
@@ 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;

M src/gyo.c => src/gyo.c +5 -5
@@ 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;

M src/tern.c => src/tern.c +38 -37
@@ 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;
}

M src/tern.h => src/tern.h +13 -13
@@ 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);