summaryrefslogtreecommitdiffstats
path: root/tis100.c
diff options
context:
space:
mode:
authorLouis Burda <quent.burda@gmail.com>2023-12-25 01:46:55 +0100
committerLouis Burda <quent.burda@gmail.com>2023-12-25 01:46:55 +0100
commit5ff5bb25cc864e7fa06aa8fed0c4ec92e99f103a (patch)
tree646a3a56d5e9d831e81d64c48a2e39e594cf0685 /tis100.c
parent70d48f0db2ff618436df7c8c52ead5a0701fd7ab (diff)
downloadtis100-5ff5bb25cc864e7fa06aa8fed0c4ec92e99f103a.tar.gz
tis100-5ff5bb25cc864e7fa06aa8fed0c4ec92e99f103a.zip
Make mode/state behaviour compatible with game
Diffstat (limited to 'tis100.c')
-rw-r--r--tis100.c21
1 files changed, 16 insertions, 5 deletions
diff --git a/tis100.c b/tis100.c
index 2f1c0d3..b79567a 100644
--- a/tis100.c
+++ b/tis100.c
@@ -24,16 +24,18 @@ io_active(struct tis *tis)
for (i = 0; i < TIS_MAX_IO_PORTS; i++) {
io_port = tis->in_ports[i];
if (!io_port || !io_port->file) continue;
- if (!feof(io_port->file) && io_port->port.attached
- && io_port->port.dst_port->reading)
+ if (io_port->port.attached && !io_port->port.writing
+ && !feof(io_port->file))
return true;
}
+
return false;
}
int
main(int argc, const char **argv)
{
+ struct tis_stats stats;
bool idle, prev_idle;
if (argc < 2) {
@@ -43,15 +45,24 @@ main(int argc, const char **argv)
tis_init(&tis);
- tis_load(&tis, argv[1]);
- tis_load_io(&tis, argv + 2);
+ tis_load(&tis, argv);
idle = false;
while (!idle || !prev_idle || io_active(&tis)) {
- tis_communicate(&tis);
prev_idle = idle;
idle = !tis_step(&tis);
}
+ tis.steps -= 1; /* remove last idle step */
+
+ if (tis.show_stats) {
+ stats = tis_gen_stats(&tis);
+ printf("=== stats ===\n");
+ printf(" cycles: %zu\n", stats.steps);
+ printf(" blocks: %zu\n", stats.blocks);
+ printf(" insts: %zu\n", stats.blocks);
+ printf(" idle: %2.1f%%\n", stats.idle * 100);
+ printf("=============\n");
+ }
tis_deinit(&tis);
}