summaryrefslogtreecommitdiffstats
path: root/tpu.c
diff options
context:
space:
mode:
authorLouis Burda <quent.burda@gmail.com>2023-07-26 18:38:11 +0200
committerLouis Burda <quent.burda@gmail.com>2023-07-26 18:38:11 +0200
commit130db985e5594204897ad28d7463e7e9b5ef94c7 (patch)
treeb5c825de9374b82713b642ab423ad4e18b7fd00b /tpu.c
parentd9dd10cd6a69f6da102814ebefe1d7ad2a32a020 (diff)
downloadtis100-130db985e5594204897ad28d7463e7e9b5ef94c7.tar.gz
tis100-130db985e5594204897ad28d7463e7e9b5ef94c7.zip
Restrict assembly input to fit game spec
Diffstat (limited to 'tpu.c')
-rw-r--r--tpu.c23
1 files changed, 13 insertions, 10 deletions
diff --git a/tpu.c b/tpu.c
index 22b6039..d95d8a9 100644
--- a/tpu.c
+++ b/tpu.c
@@ -62,7 +62,7 @@ djb_hash(const char *str)
void
label_map_init(struct label_map *map)
{
- memset(map->labels, 0, sizeof(char *) * TPU_MAX_INST);
+ memset(map->labels, 0, sizeof(char *) * TPU_MAX_INST_CNT);
memset(map->buckets, 0, sizeof(void *) * LABEL_MAP_BUCKETS);
}
@@ -123,7 +123,7 @@ label_map_get(struct label_map *map, const char *name)
struct label_map_link **link;
link = label_map_link_pos(map, name);
- if (!*link) return TPU_MAX_INST;
+ if (!*link) return TPU_MAX_INST_CNT;
return (*link)->pc;
}
@@ -165,6 +165,7 @@ tpu_init(struct tpu *tpu)
tpu->acc = 0;
tpu->bak = 0;
tpu->inst_cnt = 0;
+ tpu->label_cnt = 0;
label_map_init(&tpu->label_map);
tpu->last = -1;
@@ -265,7 +266,7 @@ tpu_update_ports(struct tpu *tpu)
}
bool
-tpu_set_inst(struct tpu *tpu, uint8_t pc, enum tpu_inst_type inst_type,
+tpu_set_inst(struct tpu *tpu, int pc, enum tpu_inst_type inst_type,
unsigned opcnt, struct tpu_inst_op op1, struct tpu_inst_op op2)
{
struct tpu_inst *inst;
@@ -304,15 +305,17 @@ tpu_set_inst(struct tpu *tpu, uint8_t pc, enum tpu_inst_type inst_type,
return true;
}
-bool
+struct tpu_inst *
tpu_add_inst(struct tpu *tpu, enum tpu_inst_type inst_type,
unsigned opcnt, struct tpu_inst_op op1, struct tpu_inst_op op2)
{
- if (tpu->inst_cnt >= TPU_MAX_INST)
+ if (tpu->inst_cnt >= TPU_MAX_INST_CNT)
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, opcnt, op1, op2);
+ tpu->x, tpu->y, TPU_MAX_INST_CNT);
+ if (!tpu_set_inst(tpu, (uint8_t) tpu->inst_cnt,
+ inst_type, opcnt, op1, op2))
+ return false;
+ return &tpu->insts[tpu->inst_cnt++];
}
/* tpu can always write to an empty port (->out), but only
@@ -354,7 +357,7 @@ tpu_jmp_label(struct tpu *tpu, const char *label)
size_t pc;
pc = label_map_get(&tpu->label_map, label);
- if (pc >= TPU_MAX_INST) abort();
+ if (pc >= TPU_MAX_INST_CNT) abort();
tpu->pc = (uint8_t) pc;
}
@@ -439,7 +442,7 @@ enum tpu_status
tpu_exec(struct tpu *tpu, struct tpu_inst *inst)
{
enum tpu_status status;
- uint8_t lit;
+ int lit;
int val;
switch (inst->type) {