From 1c6a7caeae544d48aacfb6a3c08bc74453c45625 Mon Sep 17 00:00:00 2001 From: Virgil Dupras Date: Tue, 23 Jul 2019 16:50:19 -0400 Subject: [PATCH] recipes/sms/romasm: make zasm's memory usage fit the SMS --- apps/zasm/glue.asm | 21 ++++++++++++++++++--- apps/zasm/symbol.asm | 28 +++++++++------------------- recipes/sms/romasm/user-tmpl.h | 6 ++++++ tools/tests/unit/test_expr.asm | 5 +++++ tools/tests/unit/test_symbol.asm | 5 +++++ 5 files changed, 43 insertions(+), 22 deletions(-) diff --git a/apps/zasm/glue.asm b/apps/zasm/glue.asm index 09aaf2b..0c4af4a 100644 --- a/apps/zasm/glue.asm +++ b/apps/zasm/glue.asm @@ -44,9 +44,25 @@ ; FS_HANDLE_SIZE ; BLOCKDEV_SIZE -; *** Variables *** - #include "user.h" + +; *** Overridable consts *** +; Maximum number of symbols we can have in the global and consts registry +.equ ZASM_REG_MAXCNT 0xff + +; Maximum number of symbols we can have in the local registry +.equ ZASM_LREG_MAXCNT 0x40 + +; Size of the symbol name buffer size. This is a pool. There is no maximum name +; length for a single symbol, just a maximum size for the whole pool. +; Global labels and consts have the same buf size +.equ ZASM_REG_BUFSZ 0x1000 + +; Size of the names buffer for the local context registry +.equ ZASM_LREG_BUFSZ 0x200 + +; ****** + #include "err.h" .org USER_CODE @@ -69,4 +85,3 @@ jp zasmMain #include "zasm/symbol.asm" .equ ZASM_RAMSTART SYM_RAMEND #include "zasm/main.asm" - diff --git a/apps/zasm/symbol.asm b/apps/zasm/symbol.asm index 1718c4d..33a7aaa 100644 --- a/apps/zasm/symbol.asm +++ b/apps/zasm/symbol.asm @@ -5,28 +5,18 @@ ; Local labels during the "official" first pass are ignored. To register them ; in the global registry during that pass would be wasteful in terms of memory. ; -; What we don instead is set up a separate register for them and have a "second +; What we do instead is set up a separate register for them and have a "second ; first pass" whenever we encounter a new context. That is, we wipe the local ; registry, parse the code until the next global symbol (or EOF), then rewind ; and continue second pass as usual. ; *** Constants *** -; Maximum number of symbols we can have in the global and consts registry -.equ SYM_MAXCOUNT 0xff -; Maximum number of symbols we can have in the local registry -.equ SYM_LOC_MAXCOUNT 0x40 ; Size of each record in registry .equ SYM_RECSIZE 3 -; Size of the symbol name buffer size. This is a pool. There is no maximum name -; length for a single symbol, just a maximum size for the whole pool. -; Global labels and consts have the same buf size -.equ SYM_BUFSIZE 0x1000 -.equ SYM_REGSIZE SYM_BUFSIZE+1+SYM_MAXCOUNT*SYM_RECSIZE +.equ SYM_REGSIZE ZASM_REG_BUFSZ+1+ZASM_REG_MAXCNT*SYM_RECSIZE -; Size of the names buffer for the local context registry -.equ SYM_LOC_BUFSIZE 0x200 -.equ SYM_LOC_REGSIZE SYM_LOC_BUFSIZE+1+SYM_LOC_MAXCOUNT*SYM_RECSIZE +.equ SYM_LOC_REGSIZE ZASM_LREG_BUFSZ+1+ZASM_LREG_MAXCNT*SYM_RECSIZE ; *** Variables *** ; A registry has three parts: record count (byte) record list and names pool. @@ -53,16 +43,16 @@ ; records list of the register and then the max record count. SYM_GLOBAL_REGISTRY: - .dw SYM_GLOB_REG, SYM_GLOB_REG+SYM_BUFSIZE - .db SYM_MAXCOUNT + .dw SYM_GLOB_REG, SYM_GLOB_REG+ZASM_REG_BUFSZ + .db ZASM_REG_MAXCNT SYM_LOCAL_REGISTRY: - .dw SYM_LOC_REG, SYM_LOC_REG+SYM_LOC_BUFSIZE - .db SYM_LOC_MAXCOUNT + .dw SYM_LOC_REG, SYM_LOC_REG+ZASM_LREG_BUFSZ + .db ZASM_LREG_MAXCNT SYM_CONST_REGISTRY: - .dw SYM_CONST_REG, SYM_CONST_REG+SYM_BUFSIZE - .db SYM_MAXCOUNT + .dw SYM_CONST_REG, SYM_CONST_REG+ZASM_REG_BUFSZ + .db ZASM_REG_MAXCNT ; *** Code *** diff --git a/recipes/sms/romasm/user-tmpl.h b/recipes/sms/romasm/user-tmpl.h index ba23a5b..f0b3ee7 100644 --- a/recipes/sms/romasm/user-tmpl.h +++ b/recipes/sms/romasm/user-tmpl.h @@ -8,6 +8,12 @@ .equ ED_BUF_MAXLINES 0x100 .equ ED_BUF_PADMAXLEN 0x800 +; Make zasm fit in SMS's memory +.equ ZASM_REG_MAXCNT 0x80 +.equ ZASM_LREG_MAXCNT 0x10 +.equ ZASM_REG_BUFSZ 0x800 +.equ ZASM_LREG_BUFSZ 0x100 + ; *** JUMP TABLE *** .equ strncmp 0x03 .equ addDE 0x06 diff --git a/tools/tests/unit/test_expr.asm b/tools/tests/unit/test_expr.asm index b4a9d6e..fe37b14 100644 --- a/tools/tests/unit/test_expr.asm +++ b/tools/tests/unit/test_expr.asm @@ -1,4 +1,9 @@ .equ RAMSTART 0x4000 +.equ ZASM_REG_MAXCNT 0xff +.equ ZASM_LREG_MAXCNT 0x40 +.equ ZASM_REG_BUFSZ 0x1000 +.equ ZASM_LREG_BUFSZ 0x200 + jp test #include "core.asm" diff --git a/tools/tests/unit/test_symbol.asm b/tools/tests/unit/test_symbol.asm index d75450e..b19880b 100644 --- a/tools/tests/unit/test_symbol.asm +++ b/tools/tests/unit/test_symbol.asm @@ -1,4 +1,9 @@ .equ RAMSTART 0x4000 +.equ ZASM_REG_MAXCNT 0xff +.equ ZASM_LREG_MAXCNT 0x40 +.equ ZASM_REG_BUFSZ 0x1000 +.equ ZASM_LREG_BUFSZ 0x200 + jp test #include "core.asm"