From c839703682cc3cb4109974428b578232829e5349 Mon Sep 17 00:00:00 2001 From: Virgil Dupras Date: Thu, 25 Jul 2019 14:23:13 -0400 Subject: [PATCH] recipes/sms/romasm: ed and zasm, fully functional! --- recipes/sms/README.md | 1 + recipes/sms/kbd/glue.asm | 4 ++-- recipes/sms/romasm/README.md | 46 ++++++++++++++++++++++++++++++++++++ recipes/sms/romasm/glue.asm | 18 ++++++++++---- 4 files changed, 63 insertions(+), 6 deletions(-) diff --git a/recipes/sms/README.md b/recipes/sms/README.md index a37a4fe..8532257 100644 --- a/recipes/sms/README.md +++ b/recipes/sms/README.md @@ -18,6 +18,7 @@ This recipe is for installing a minimal Collapse OS system on the SMS. There are other recipes related to the SMS: * [Interfacing a PS/2 keyboard](kbd/README.md) +* [zasm and ed from ROM](romasm/README.md) ## Gathering parts diff --git a/recipes/sms/kbd/glue.asm b/recipes/sms/kbd/glue.asm index 8599268..dcd403d 100644 --- a/recipes/sms/kbd/glue.asm +++ b/recipes/sms/kbd/glue.asm @@ -1,7 +1,7 @@ ; 8K of onboard RAM .equ RAMSTART 0xc000 ; Memory register at the end of RAM. Must not overwrite -.equ RAMEND 0xfdd0 +.equ RAMEND 0xddd0 jp init @@ -14,7 +14,7 @@ #include "sms/kbd.asm" .equ KBD_RAMSTART RAMSTART -.equ KBD_FETCHKC smskbdFetchKCA +.equ KBD_FETCHKC smskbdFetchKCB #include "kbd.asm" .equ VDP_RAMSTART KBD_RAMEND diff --git a/recipes/sms/romasm/README.md b/recipes/sms/romasm/README.md index b66a8c4..5918ed4 100644 --- a/recipes/sms/romasm/README.md +++ b/recipes/sms/romasm/README.md @@ -13,3 +13,49 @@ compile them and run them. * A SMS that can run Collapse OS. * A [PS/2 keyboard adapter](../kbd/README.md) + +## Build + +There's nothing special with building this recipe. Like the base recipe, run +`make` then copy `os.sms` to your destination medium. + +If you look at the makefile, however, you'll see that we use a new trick here: +we embed "apps" binaries directly in our ROM so that we don't have to load them +in memory. + +## Usage + +Alright, here's what we'll do: we'll author a source file, assemble it and run +it, *all* on your SMS! Commands: + + Collapse OS + > fnew 1 src + > ed src + : 1i + .org 0xc200 + : 1a + ld hl, sFoo + : 2a + call 0x3f + : 3a + xor a + : 4a + ret + : 5a + sFoo: .db "foo", 0 + : w + > fnew 1 dest + > fopn 0 src + > fopn 1 dest + > zasm 1 2 + First pass + Second pass + > dest + foo> + +Awesome right? Some precisions: + +* Our glue code specifies a `USER_RAMSTART` of `0xc200`. This is where + `dest` is loaded by the `pgm` shell hook. +* `0x3f` is the offset of `printstr` in the jump table of our glue code. +* `xor a` is for the command to report as successful to the shell. diff --git a/recipes/sms/romasm/glue.asm b/recipes/sms/romasm/glue.asm index 9379f5c..4352aaa 100644 --- a/recipes/sms/romasm/glue.asm +++ b/recipes/sms/romasm/glue.asm @@ -1,5 +1,6 @@ ; 8K of onboard RAM .equ RAMSTART 0xc000 +.equ USER_RAMSTART 0xc200 ; Memory register at the end of RAM. Must not overwrite .equ RAMEND 0xddd0 @@ -53,8 +54,9 @@ .equ STDIO_RAMSTART VDP_RAMEND #include "stdio.asm" -.equ MMAP_START 0xd800 -.equ MMAP_LEN RAMEND-MMAP_START +.equ MMAP_START 0xd700 +; 0x180 is to leave some space for the stack +.equ MMAP_LEN RAMEND-MMAP_START-0x180 #include "mmap.asm" .equ BLOCKDEV_RAMSTART STDIO_RAMEND @@ -71,14 +73,20 @@ #include "fs.asm" .equ SHELL_RAMSTART FS_RAMEND -.equ SHELL_EXTRA_CMD_COUNT 11 +.equ SHELL_EXTRA_CMD_COUNT 10 #include "shell.asm" -.dw edCmd, zasmCmd, fnewCmd, fdelCmd, fopnCmd, flsCmd, fsOnCmd, blkBselCmd +.dw edCmd, zasmCmd, fnewCmd, fdelCmd, fopnCmd, flsCmd, blkBselCmd .dw blkSeekCmd, blkLoadCmd, blkSaveCmd #include "blockdev_cmds.asm" #include "fs_cmds.asm" +.equ PGM_RAMSTART SHELL_RAMEND +.equ PGM_CODEADDR USER_RAMSTART +#include "pgm.asm" + +.out PGM_RAMEND + init: di im 1 @@ -109,6 +117,8 @@ init: call vdpInit call shellInit + ld hl, pgmShellHook + ld (SHELL_CMDHOOK), hl jp shellLoop f0GetC: