Mirror of CollapseOS
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

34 lines
653B

  1. #include <stdint.h>
  2. #include <stdio.h>
  3. #include "../emul.h"
  4. /* runbin loads binary from stdin directly in memory address 0 then runs it
  5. * until it halts. The return code is the value of the register A at halt time.
  6. */
  7. static void iowr_stderr(uint8_t val)
  8. {
  9. fputc(val, stderr);
  10. }
  11. int main()
  12. {
  13. Machine *m = emul_init();
  14. m->iowr[0] = iowr_stderr;
  15. // read stdin in mem
  16. int i = 0;
  17. int c = getchar();
  18. while (c != EOF) {
  19. m->mem[i] = c & 0xff;
  20. i++;
  21. c = getchar();
  22. }
  23. if (!i) {
  24. fprintf(stderr, "No input, aborting\n");
  25. return 1;
  26. }
  27. emul_loop();
  28. return m->cpu.R1.br.A;
  29. }