diff options
author | mrb0nk500 <b0nk@b0nk.xyz> | 2019-11-11 20:43:05 -0500 |
---|---|---|
committer | mrb0nk500 <b0nk@b0nk.xyz> | 2019-11-11 20:43:05 -0500 |
commit | a5c33b00e110928e86fa08f91f8ccab86b9a9eb1 (patch) | |
tree | f5a9f2c1ab9315cd49bfc09107f4f82392e4b456 /sux.c | |
parent | e3fc06b083598f244b3949e06d4ffbd3d2b235cc (diff) |
Started work on simultanious multithreading, and branching.
Diffstat (limited to 'sux.c')
-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; + } + } } |