2019-05-17 23:33:20 +10:00
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdio.h>
|
2019-12-03 08:35:49 +11:00
|
|
|
#include "../emul.h"
|
2019-05-17 23:33:20 +10:00
|
|
|
|
|
|
|
/* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
int main()
|
|
|
|
{
|
2019-12-03 08:35:49 +11:00
|
|
|
Machine *m = emul_init();
|
2019-05-17 23:33:20 +10:00
|
|
|
// read stdin in mem
|
|
|
|
int i = 0;
|
|
|
|
int c = getchar();
|
|
|
|
while (c != EOF) {
|
2019-12-03 08:35:49 +11:00
|
|
|
m->mem[i] = c & 0xff;
|
2019-05-17 23:33:20 +10:00
|
|
|
i++;
|
|
|
|
c = getchar();
|
|
|
|
}
|
2019-05-28 23:57:29 +10:00
|
|
|
if (!i) {
|
|
|
|
fprintf(stderr, "No input, aborting\n");
|
|
|
|
return 1;
|
|
|
|
}
|
2019-12-03 08:35:49 +11:00
|
|
|
emul_loop();
|
|
|
|
return m->cpu.R1.br.A;
|
2019-05-17 23:33:20 +10:00
|
|
|
}
|
|
|
|
|