Преглед на файлове

zasm: implement stdin/stdout in emulator

pull/10/head
Virgil Dupras преди 5 години
родител
ревизия
43c1005d61
променени са 3 файла, в които са добавени 29 реда и са изтрити 7 реда
  1. +4
    -2
      apps/zasm/emul/wrapper.asm
  2. +21
    -3
      apps/zasm/emul/zasm.c
  3. +4
    -2
      apps/zasm/zasm.asm

+ 4
- 2
apps/zasm/emul/wrapper.asm Целия файл

@@ -4,10 +4,12 @@ ld sp, hl
; zasm input
ld hl, 0x9000
; zasm output
ld hl, 0xc000
ld de, 0xc000
call zasm
; signal the emulator we're done
out (0), a
; BC contains the number of written bytes
ld a, b
out (c), a
halt
zasm:
; beginning of the code

+ 21
- 3
apps/zasm/emul/zasm.c Целия файл

@@ -1,4 +1,5 @@
#include <stdint.h>
#include <stdio.h>
#include "libz80/z80.h"
#include "wrapper.h"
#include "zasm.h"
@@ -10,9 +11,17 @@
* zasm in a special wrapper, wait until we receive the stop signal, then
* spit the contents of the dest memory to stdout.
*/

// in sync with wrapper.asm
#define READFROM 0x9000
#define WRITETO 0xc000

static Z80Context cpu;
static uint8_t mem[0xffff];
static int running;
// Number of bytes written to WRITETO
// We receive that result from an OUT (C), A call. C contains LSB, A is MSB.
static uint16_t written;


static uint8_t io_read(int unused, uint16_t addr)
@@ -22,8 +31,7 @@ static uint8_t io_read(int unused, uint16_t addr)

static void io_write(int unused, uint16_t addr, uint8_t val)
{
// zasm doesn't do any IO. If we receive any IO, it means that we're done
// because the wrapper told us through an "out"
written = (val << 8) + (addr & 0xff);
running = 0;
}

@@ -48,6 +56,13 @@ int main()
for (int i=0; i<zasm; i++) {
mem[i+wrapperlen] = ZASM[i];
}
int ptr = READFROM;
int c = getchar();
while (c != EOF) {
mem[ptr] = c;
ptr++;
c = getchar();
}
// Run!
running = 1;
Z80RESET(&cpu);
@@ -59,6 +74,9 @@ int main()
while (running) {
Z80Execute(&cpu);
}
printf("and... %d!\n", mem[0x100]);

for (int i=0; i<written; i++) {
putchar(mem[WRITETO+i]);
}
return 0;
}

+ 4
- 2
apps/zasm/zasm.asm Целия файл

@@ -1,4 +1,6 @@
; dummy code, to test emulator
ld a, 0x42
ld (0x100), a
ld a, (hl)
inc a
ld (de), a
ld bc, 1
ret

Loading…
Отказ
Запис