From 8b20b35bf5506ff74b7337e35d6827064eace425 Mon Sep 17 00:00:00 2001 From: mrb0nk500 Date: Sat, 7 Dec 2019 12:21:35 -0500 Subject: Added six instructions for transfering data between the three main registers. These instructions are: TAY: Transfer Accumulator to Y. TAX: Transfer Accumulator to X. TYX: Transfer Y to X. TYA: Transfer Y to Accumulator. TXA: Transfer X to Accumulator. TXY: Transfer X to Y. --- sux.c | 36 +++++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) (limited to 'sux.c') diff --git a/sux.c b/sux.c index 4df60cb..08f5ebe 100644 --- a/sux.c +++ b/sux.c @@ -17,7 +17,6 @@ uint8_t threads_done = 0; uint8_t lines[THREADS]; pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; pthread_cond_t cond = PTHREAD_COND_INITIALIZER; -pthread_barrier_t bar; struct suxthr { struct sux sx; uint8_t th; @@ -175,6 +174,39 @@ void *run(void *args) { addr[0xFF91] = cpu->sp >> 8; } break; + case TAY: /* Transfer Accumulator to Y. */ + case TAX: /* Transfer Accumulator to Y. */ + case TYX: /* Transfer Y to X. */ + case TYA: /* Transfer Y to Accumulator. */ + case TXA: /* Transfer X to Accumulator. */ + case TXY: /* Transfer X to Y. */ + if (opcode == TAY) + cpu->y[thread] = cpu->a[thread]; + if (opcode == TAX) + cpu->x[thread] = cpu->a[thread]; + if (opcode == TYX) + cpu->x[thread] = cpu->y[thread]; + if (opcode == TYA) + cpu->a[thread] = cpu->y[thread]; + if (opcode == TXA) + cpu->a[thread] = cpu->x[thread]; + if (opcode == TXY) + cpu->y[thread] = cpu->x[thread]; + if (opcode == TYA || opcode == TXA) { + cpu->z[thread] = (cpu->a[thread] == 0); + cpu->n[thread] = (cpu->a[thread] >> 63); + } + if (opcode == TAY || opcode == TXY) { + cpu->z[thread] = (cpu->y[thread] == 0); + cpu->n[thread] = (cpu->y[thread] >> 63); + } + if (opcode == TAX || opcode == TYX) { + cpu->z[thread] = (cpu->x[thread] == 0); + cpu->n[thread] = (cpu->x[thread] >> 63); + } + (cpu->z[thread]) ? (cpu->ps |= (Z << 8*thread)) : (cpu->ps &= ~(Z << 8*thread)); + (cpu->n[thread]) ? (cpu->ps |= (N << 8*thread)) : (cpu->ps &= ~(N << 8*thread)); + break; case PHX: /* PusH X register to stack. */ tmp = addr[cpu->pc[thread]++]; if (tmp > 7) @@ -1413,7 +1445,6 @@ int main(int argc, char **argv) { inst[i] = 0; } pthread_t therads[THREADS]; - pthread_barrier_init(&bar, NULL, THREADS); int result; puts("\033[2J\033[H"); for (int i = 0; i < THREADS; i++) { @@ -1425,7 +1456,6 @@ int main(int argc, char **argv) { pthread_cond_wait(&cond, &mutex); } pthread_mutex_unlock(&mutex); - pthread_barrier_destroy(&bar); #if bench if (threads_done == THREADS) { double tm_sec, tm_usec, tm[THREADS], ttm; -- cgit v1.2.3-13-gbd6f