1
0
mirror of https://github.com/hsoft/collapseos.git synced 2024-11-27 09:48:05 +11:00

zasm: implement stdin/stdout in emulator

This commit is contained in:
Virgil Dupras 2019-04-16 13:59:19 -04:00
parent 1ae2331763
commit 43c1005d61
3 changed files with 29 additions and 7 deletions

View File

@ -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

View File

@ -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;
}

View File

@ -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