diff options
| author | Louis Burda <quent.burda@gmail.com> | 2023-07-25 05:56:08 +0200 |
|---|---|---|
| committer | Louis Burda <quent.burda@gmail.com> | 2023-07-25 05:56:08 +0200 |
| commit | 7d73b738a5703d5263a84dcbe3564e2267af6804 (patch) | |
| tree | e386ecb7813d86577b9fc5ef5153785de60d6f51 /tpu.c | |
| parent | 41760436d528552d64122bb0c837f4d8274a0bdd (diff) | |
| download | tis100-7d73b738a5703d5263a84dcbe3564e2267af6804.tar.gz tis100-7d73b738a5703d5263a84dcbe3564e2267af6804.zip | |
Improve parsing, make stdin / stdout port optional
Diffstat (limited to 'tpu.c')
| -rw-r--r-- | tpu.c | 48 |
1 files changed, 20 insertions, 28 deletions
@@ -199,8 +199,7 @@ tpu_init_ports(struct tpu *tpu, struct tpu_map *map) { struct tpu *neighbor; enum tpu_port_dir odir; - size_t x, y; - int i; + int x, y, i; for (i = 0; i < 4; i++) { switch (i) { @@ -262,36 +261,30 @@ tpu_update_ports(struct tpu *tpu) bool tpu_set_inst(struct tpu *tpu, uint8_t pc, enum tpu_inst_type inst_type, - int op1, union tpu_inst_op_val v1, - int op2, union tpu_inst_op_val v2) + unsigned opcnt, struct tpu_inst_op op1, struct tpu_inst_op op2) { struct tpu_inst *inst; inst = &tpu->insts[pc]; inst->type = inst_type; - - if (op2 >= 0) { - inst->ops[1].type = (enum tpu_inst_op_type) op2; - inst->ops[1].val = v1; - inst->ops[0].type = (enum tpu_inst_op_type) op1; - inst->ops[0].val = v2; - inst->opcnt = 2; - } else if (op1 >= 0) { - inst->ops[0].type = (enum tpu_inst_op_type) op1; - inst->ops[0].val = v1; - inst->opcnt = 1; - } else { - inst->opcnt = 0; - } + inst->opcnt = opcnt; + inst->ops[0] = op1; + inst->ops[1] = op2; switch (inst->type) { case INST_NOP: case INST_SAV: case INST_SWP: case INST_NEG: - return inst->opcnt == 0; + if (inst->opcnt != 0) return false; + break; case INST_ADD: case INST_SUB: - return inst->opcnt == 1; + if (inst->opcnt != 1) return false; + break; + case INST_JRO: + if (inst->opcnt != 1) return false; + if (inst->ops[0].type != OP_LIT) return false; + break; case INST_JMP: case INST_JEZ: case INST_JNZ: - case INST_JGZ: case INST_JLZ: case INST_JRO: + case INST_JGZ: case INST_JLZ: if (inst->opcnt != 1) return false; if (inst->ops[0].type != OP_LABEL) return false; break; @@ -308,14 +301,13 @@ tpu_set_inst(struct tpu *tpu, uint8_t pc, enum tpu_inst_type inst_type, bool tpu_add_inst(struct tpu *tpu, enum tpu_inst_type inst_type, - int op1, union tpu_inst_op_val v1, - int op2, union tpu_inst_op_val v2) + unsigned opcnt, struct tpu_inst_op op1, struct tpu_inst_op op2) { if (tpu->inst_cnt >= TPU_MAX_INST) - die("tpu_add_inst: tpu X%lu Y%lu, >= max %i instructions", + die("tpu_add_inst: tpu X%i Y%i, >= max %i instructions", tpu->x, tpu->y, TPU_MAX_INST); return tpu_set_inst(tpu, (uint8_t) tpu->inst_cnt++, - inst_type, op1, v1, op2, v2); + inst_type, opcnt, op1, op2); } /* tpu can always write to an empty port (->out), but only @@ -575,12 +567,12 @@ tpu_map_deinit(struct tpu_map *map) } static struct tpu_map_link ** -tpu_map_link_pos(struct tpu_map *map, size_t x, size_t y) +tpu_map_link_pos(struct tpu_map *map, int x, int y) { struct tpu_map_link **link; size_t i; - i = (x + y) % TPU_MAP_BUCKETS; + i = (size_t) (x + y) % TPU_MAP_BUCKETS; link = &map->buckets[i]; while (*link && !((*link)->x == x && (*link)->y == y)) link = &(*link)->next; @@ -603,7 +595,7 @@ 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) +tpu_map_get(struct tpu_map *map, int x, int y) { struct tpu_map_link **link; |
