diff options
| author | Louis Burda <quent.burda@gmail.com> | 2023-07-24 00:43:33 +0200 |
|---|---|---|
| committer | Louis Burda <quent.burda@gmail.com> | 2023-07-24 00:43:33 +0200 |
| commit | d7865d956f9fe3a08ebe4429dce4428a9f74bc6c (patch) | |
| tree | afcc976934add55eed727a3f782eea8912646122 /tpu.h | |
| download | tis100-d7865d956f9fe3a08ebe4429dce4428a9f74bc6c.tar.gz tis100-d7865d956f9fe3a08ebe4429dce4428a9f74bc6c.zip | |
Add initial rough outline
Diffstat (limited to 'tpu.h')
| -rw-r--r-- | tpu.h | 82 |
1 files changed, 82 insertions, 0 deletions
@@ -0,0 +1,82 @@ +#pragma once + +#include <stdint.h> +#include <stdbool.h> +#include <stdlib.h> + +#define TPU_MAP_BUCKETS 64 + +enum tpu_mode { + MODE_IDLE, MODE_RUN, MODE_READ, MODE_WRITE +}; + +enum tpu_inst_type { + INST_NOP, INST_MOV, INST_SWP, INST_SAV, + INST_ADD, INST_SUB, INST_NEG, INST_JMP, + INST_JEZ, INST_JNZ, INST_JLZ, INST_JRO +}; + +enum tpu_inst_op_type { + OP_LIT, OP_UP, OP_DOWN, OP_LEFT, OP_RIGHT, + OP_ACC, OP_BAK, OP_NIL, OP_ANY, OP_LAST +}; + +enum tpu_port_dir { + DIR_UP, DIR_RIGHT, DIR_DOWN, DIR_LEFT +}; + +enum tpu_port_type { + PORT_IN = 0b01, PORT_OUT = 0b10, PORT_BIDI = 0b11 +}; + +struct tpu_inst_op { + enum tpu_inst_op_type type; + uint8_t lit; +}; + +struct tpu_inst { + enum tpu_inst_type type; + struct tpu_inst_op ops[2]; +}; + +struct tpu_port { + struct tpu *dst_tpu; + enum tpu_port_type type; + struct tpu_port *dst_port; + bool write, read; + uint8_t val; +}; + +struct tpu { + struct tpu_port ports[4]; + uint8_t acc, bak; + int x, y; + + size_t pc; + struct inst *inst; + size_t inst_cap; + size_t inst_cnp; + +}; + +struct tpu_map_link { + size_t x, y; + struct tpu *tpu; + struct tpu_map_link *next; +}; + +struct tpu_map { + struct tpu_map_link *buckets[TPU_MAP_BUCKETS]; +}; + +void tpu_init(struct tpu *tpu); +void tpu_add_inst(struct tpu *tpu, enum tpu_inst_type inst, + int op1, uint8_t op1_lit, int op2, uint8_t op2_lit); +void tpu_step(struct tpu *tpu, uint8_t *up, uint8_t *right, + uint8_t *down, uint8_t *left); +void tpu_deinit(struct tpu *tpu); + +void tpu_map_init(struct tpu_map *map); +void tpu_map_add(struct tpu_map *map, struct tpu *tpu); +struct tpu *tpu_map_get(int x, int y); +void tpu_map_deinit(struct tpu_map *map); |
