diff options
-rw-r--r-- | sux.c | 48 |
1 files changed, 46 insertions, 2 deletions
@@ -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; + } + } } |