summaryrefslogtreecommitdiffstats
path: root/tpu.h
diff options
context:
space:
mode:
authorLouis Burda <quent.burda@gmail.com>2023-07-24 04:43:28 +0200
committerLouis Burda <quent.burda@gmail.com>2023-07-24 04:43:28 +0200
commit5835917f57d4dc04b406c8e3e06bf3b046d709e3 (patch)
tree49aa1aa85220801fe2e7f63e5a1bfbb9af9b65e2 /tpu.h
parentd7865d956f9fe3a08ebe4429dce4428a9f74bc6c (diff)
downloadtis100-5835917f57d4dc04b406c8e3e06bf3b046d709e3.tar.gz
tis100-5835917f57d4dc04b406c8e3e06bf3b046d709e3.zip
Add some more implementation details
Diffstat (limited to 'tpu.h')
-rw-r--r--tpu.h63
1 files changed, 45 insertions, 18 deletions
diff --git a/tpu.h b/tpu.h
index 702ccfc..6e93008 100644
--- a/tpu.h
+++ b/tpu.h
@@ -5,38 +5,57 @@
#include <stdlib.h>
#define TPU_MAP_BUCKETS 64
+#define LABEL_MAP_BUCKETS 64
+#define TPU_MAX_INST 256
-enum tpu_mode {
- MODE_IDLE, MODE_RUN, MODE_READ, MODE_WRITE
+/* enum order is important ! */
+
+enum tpu_status {
+ STATUS_IDLE, STATUS_RUN, STATUS_READ, STATUS_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
+ INST_JEZ, INST_JNZ, INST_JGZ, 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
+ OP_ACC, OP_BAK, OP_NIL, OP_LEFT, OP_RIGHT,
+ OP_UP, OP_DOWN, OP_ANY, OP_LAST, OP_LIT, OP_LABEL
};
enum tpu_port_dir {
- DIR_UP, DIR_RIGHT, DIR_DOWN, DIR_LEFT
+ DIR_LEFT, DIR_RIGHT, DIR_UP, DIR_DOWN
};
enum tpu_port_type {
PORT_IN = 0b01, PORT_OUT = 0b10, PORT_BIDI = 0b11
};
+struct label_map_link {
+ char *label;
+ size_t pc;
+ struct label_map_link *next;
+};
+
+struct label_map {
+ struct label_map_link *buckets[LABEL_MAP_BUCKETS];
+};
+
struct tpu_inst_op {
enum tpu_inst_op_type type;
- uint8_t lit;
+ union {
+ uint8_t lit;
+ char *label;
+ };
};
struct tpu_inst {
enum tpu_inst_type type;
struct tpu_inst_op ops[2];
+ uint8_t opcnt;
};
struct tpu_port {
@@ -45,18 +64,19 @@ struct tpu_port {
struct tpu_port *dst_port;
bool write, read;
uint8_t val;
+ bool attached;
};
struct tpu {
+ struct label_map labels;
struct tpu_port ports[4];
uint8_t acc, bak;
- int x, y;
+ size_t x, y;
+ int last;
size_t pc;
- struct inst *inst;
- size_t inst_cap;
- size_t inst_cnp;
-
+ struct tpu_inst insts[TPU_MAX_INST];
+ size_t inst_cnt;
};
struct tpu_map_link {
@@ -69,14 +89,21 @@ struct tpu_map {
struct tpu_map_link *buckets[TPU_MAP_BUCKETS];
};
+void label_map_init(struct label_map *map);
+void label_map_deinit(struct label_map *map);
+bool label_map_add(struct label_map *map, const char *name, size_t pc);
+size_t label_map_get(struct label_map *map, const char *name);
+
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);
+struct tpu_inst *tpu_current_inst(struct tpu *tpu);
+void tpu_init_ports(struct tpu *tpu, struct tpu_map *map);
+bool tpu_add_inst(struct tpu *tpu, enum tpu_inst_type inst,
+ int op1, uint8_t op1_lit, int op2, uint8_t op2_lit);
+enum tpu_status tpu_exec(struct tpu *tpu, struct tpu_inst *inst);
+void tpu_step(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);
+void tpu_map_add(struct tpu_map *map, struct tpu *tpu);
+struct tpu *tpu_map_get(struct tpu_map *map, size_t x, size_t y);