From 807bd70b6371a885e3fd1785bbac38f1e77995a4 Mon Sep 17 00:00:00 2001 From: Virgil Dupras Date: Fri, 17 May 2019 13:22:45 -0400 Subject: [PATCH] zasm emul: add dumpSymbolTable debug routine Very helpful... --- tools/emul/zasm/glue.asm | 2 ++ tools/emul/zasm/user.asm | 44 ++++++++++++++++++++++++++++++++++++++++++++ tools/emul/zasm/zasm.c | 3 +++ 3 files changed, 49 insertions(+) diff --git a/tools/emul/zasm/glue.asm b/tools/emul/zasm/glue.asm index 405a882..286a91b 100644 --- a/tools/emul/zasm/glue.asm +++ b/tools/emul/zasm/glue.asm @@ -5,6 +5,7 @@ .equ STDIN_SEEK 0x01 .equ FS_DATA_PORT 0x02 .equ FS_SEEK_PORT 0x03 +.equ STDERR_PORT 0x04 jp init ; 3 bytes ; *** JUMP TABLE *** @@ -53,6 +54,7 @@ init: ; signal the emulator we're done halt +; *** I/O *** emulGetC: in a, (STDIO_PORT) or a ; cp 0 diff --git a/tools/emul/zasm/user.asm b/tools/emul/zasm/user.asm index 28becd6..864a311 100644 --- a/tools/emul/zasm/user.asm +++ b/tools/emul/zasm/user.asm @@ -16,7 +16,51 @@ fsSeek .equ 0x2a fsTell .equ 0x2d .equ FS_HANDLE_SIZE 8 +.equ STDERR_PORT 0x04 .equ USER_CODE 0x4800 .equ RAMSTART 0x5800 .org USER_CODE + + call zasmMain + ;call dumpSymTable + ret + #include "main.asm" + +; *** Debug *** +debugPrint: + push af + push hl +.loop: + ld a, (hl) + or a + jr z, .end + out (STDERR_PORT), a + inc hl + jr .loop +.end: + ld a, 0x0a + out (STDERR_PORT), a + pop hl + pop af + ret + +dumpSymTable: + ld hl, SYM_NAMES + ld de, SYM_VALUES +.loop: + call debugPrint + ld a, (de) + out (12), a + inc de + ld a, (de) + out (12), a + inc de + xor a + call findchar + inc hl + ld a, (hl) + or a + ret z + jr .loop + diff --git a/tools/emul/zasm/zasm.c b/tools/emul/zasm/zasm.c index 158ae0e..19fe986 100644 --- a/tools/emul/zasm/zasm.c +++ b/tools/emul/zasm/zasm.c @@ -31,6 +31,7 @@ #define STDIN_SEEK_PORT 0x01 #define FS_DATA_PORT 0x02 #define FS_SEEK_PORT 0x03 +#define STDERR_PORT 0x04 // Other consts #define STDIN_BUFSIZE 0x8000 @@ -128,6 +129,8 @@ static void io_write(int unused, uint16_t addr, uint8_t val) fsdev_ptr = (val << 8) & 0xff00; fsdev_middle_of_seek_tell = 1; } + } else if (addr == STDERR_PORT) { + fputc(val, stderr); } else { fprintf(stderr, "Out of bounds I/O write: %d / %d\n", addr, val); }