From a5c33b00e110928e86fa08f91f8ccab86b9a9eb1 Mon Sep 17 00:00:00 2001 From: mrb0nk500 Date: Mon, 11 Nov 2019 20:43:05 -0500 Subject: Started work on simultanious multithreading, and branching. --- sux.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 46 insertions(+), 2 deletions(-) (limited to 'sux.c') diff --git a/sux.c b/sux.c index 43699d3..1efbc77 100644 --- a/sux.c +++ b/sux.c @@ -3,11 +3,13 @@ uint64_t a; /* Accumulator. */ uint64_t y; /* Y index. */ uint64_t x; /* X index. */ +uint8_t crt; /* Current Running Threads. */ +uint64_t pc[8]; /* Program counter. */ uint64_t ps; /* Processor status. */ -uint64_t alu(uint8_t opcode, uint64_t value) { +int alu(uint8_t opcode, uint64_t value) { uint64_t sum; - uint8_t carry, vf; + uint8_t carry = 0, vf = 0; switch(opcode) { /* Add with carry. */ case ADC: @@ -102,4 +104,46 @@ uint64_t alu(uint8_t opcode, uint64_t value) { (a >> value) | (a << (64-value)); break; } + ps |= vf; + ps |= carry; + return 1; +} + +int threads(uint8_t opcode, uint64_t value) { + uint8_t t = value & 0xFF; /* This tells the CPU, which threads to start, or end. */ + switch(opcode) { + /* Start Thread. */ + case STT: + crt |= t; + for (uint8_t i = 0; i < 8; i++) + if ((t >> i) & 1) + pc[i] = value >> 8; + break; + /* End Thread. */ + case ENT: + crt &= ~t; + for (uint8_t i = 0; i < 8; i++) + if ((t >> i) & 1) + pc[i] = 0; + break; + } +} + +int branch(uint8_t opcode, uint64_t value, uint8_t thread) { + switch (opcode) { + /* Jump. */ + case JMP: + pc[thread] = value; + break; + /* Jump to subroutine. */ + case JSR: + pc[thread] = value; + pushaddr(value); + break; + /* Return from subroutine. */ + case RTS: + pulladdr(); + break; + } + } } -- cgit v1.2.3-13-gbd6f