1
0
mirror of https://github.com/hsoft/collapseos.git synced 2024-11-21 02:18:06 +11:00
collapseos/tools/emul/runbin/runbin.c
Virgil Dupras a034f63e23 test: begin adding common test harnessing code
This should make tests a bit more convenient to write and debug.

Moreover, begin de de-IX-ization of parseExpr. I have, in a local WIP, a
parseExpr implemented using a recursive descent algo, it passes all tests, but
it unfortunately assembles a faulty zasm. I have to find the expressions that
it doesn't parse properly.

But before I do that, I prefer to commit these significant improvements I've
been making to tests harness in parallel of this development.
2019-12-23 15:41:25 -05:00

35 lines
678 B
C

#include <stdint.h>
#include <stdio.h>
#include "../emul.h"
/* runbin loads binary from stdin directly in memory address 0 then runs it
* until it halts. The return code is the value of the register A at halt time.
*/
static void iowr_stderr(uint8_t val)
{
fputc(val, stderr);
}
int main()
{
Machine *m = emul_init();
m->iowr[0] = iowr_stderr;
// read stdin in mem
int i = 0;
int c = getchar();
while (c != EOF) {
m->mem[i] = c & 0xff;
i++;
c = getchar();
}
if (!i) {
fprintf(stderr, "No input, aborting\n");
return 1;
}
emul_loop();
if (m->cpu.R1.wr.HL)
return m->cpu.R1.br.A;
}