diff --git a/apps/zasm/io.asm b/apps/zasm/io.asm index b70f892..7d8bdd8 100644 --- a/apps/zasm/io.asm +++ b/apps/zasm/io.asm @@ -22,8 +22,7 @@ ioPutC: ld ix, (IO_OUT_PUTC) jp (ix) -ioRewind: - ld hl, 0 +ioSeek: ld ix, (IO_IN_SEEK) jp (ix) diff --git a/apps/zasm/main.asm b/apps/zasm/main.asm index 4788bf8..6be040e 100644 --- a/apps/zasm/main.asm +++ b/apps/zasm/main.asm @@ -75,7 +75,8 @@ zasmMain: call zasmParseFile ret nz ; Second pass - call ioRewind + ld hl, 0 + call ioSeek xor a ld (ZASM_FIRST_PASS), a call zasmParseFile diff --git a/tools/emul/zasm.c b/tools/emul/zasm.c index d087174..2c1ee1c 100644 --- a/tools/emul/zasm.c +++ b/tools/emul/zasm.c @@ -27,7 +27,7 @@ // in sync with zasm_glue.asm #define USER_CODE 0x4800 #define STDIO_PORT 0x00 -#define STDIN_REWIND 0x01 +#define STDIN_SEEK 0x01 // Other consts #define STDIN_BUFSIZE 0x8000 @@ -41,6 +41,7 @@ static uint8_t mem[0x10000]; static uint8_t inpt[STDIN_BUFSIZE]; static int inpt_size; static int inpt_ptr; +static uint8_t received_first_seek_byte = 0; static uint8_t io_read(int unused, uint16_t addr) { @@ -65,8 +66,14 @@ static void io_write(int unused, uint16_t addr, uint8_t val) #ifndef MEMDUMP putchar(val); #endif - } else if (addr == STDIN_REWIND) { - inpt_ptr = 0; + } else if (addr == STDIN_SEEK) { + if (received_first_seek_byte) { + inpt_ptr |= val; + received_first_seek_byte = 0; + } else { + inpt_ptr = (val << 8) & 0xff00; + received_first_seek_byte = 1; + } } else { fprintf(stderr, "Out of bounds I/O write: %d / %d\n", addr, val); } diff --git a/tools/emul/zasm_glue.asm b/tools/emul/zasm_glue.asm index c1b48b1..8a897bf 100644 --- a/tools/emul/zasm_glue.asm +++ b/tools/emul/zasm_glue.asm @@ -2,7 +2,7 @@ .equ RAMSTART 0x4000 .equ USER_CODE 0x4800 .equ STDIO_PORT 0x00 -.equ STDIN_REWIND 0x01 +.equ STDIN_SEEK 0x01 jr init ; 2 bytes ; *** JUMP TABLE *** @@ -43,7 +43,12 @@ emulPutC: ret emulSeek: - out (STDIN_REWIND), a + ; the STDIN_SEEK port works by poking it twice. First poke is for high + ; byte, second poke is for low one. + ld a, h + out (STDIN_SEEK), a + ld a, l + out (STDIN_SEEK), a ret #include "core.asm"