diff --git a/apps/basic/README.md b/apps/basic/README.md index 23963fd..7474a22 100644 --- a/apps/basic/README.md +++ b/apps/basic/README.md @@ -227,3 +227,9 @@ device (bseek, getb, putb). **ldbas **: loads the content of the file specified in the argument (as an unquoted filename) and replace the current code listing with this contents. Any line not starting with a number is ignored (not an error). + +**basPgmHook**: That is not a command, but a routine to hook into +`BAS_FINDHOOK`. If you do, whenever a command name isn't found, the filesystem +is iterated to see if it finds a file with the same name. If it does, it loads +its contents at `USER_CODE` (from `user.h`) and calls that address, with HL +pointing to the the remaining args in the command line. diff --git a/apps/basic/fs.asm b/apps/basic/fs.asm index bff2c3d..d5d75b2 100644 --- a/apps/basic/fs.asm +++ b/apps/basic/fs.asm @@ -77,6 +77,29 @@ basFOPEN: push de \ pop ix ; IX now points to the file handle. jp fsOpen +basPgmHook: + ; Cmd to find is in (DE) + ex de, hl + ; (HL) is suitable for a direct fsFindFN call + call fsFindFN + ret nz + ; We have a file! Let's load it in memory + ld ix, BFS_FILE_HDL + call fsOpen + ld hl, 0 ; addr that we read in file handle + ld de, USER_CODE ; addr in mem we write to +.loop: + call fsGetB ; we use Z at end of loop + ld (de), a ; Z preserved + inc hl ; Z preserved in 16-bit + inc de ; Z preserved in 16-bit + jr z, .loop + ; Ready to jump. Return USER_CODE in IX and basCallCmd will take care + ; of setting (HL) to the arg string. + ld ix, USER_CODE + cp a ; ensure Z + ret + basFSCmds: .dw basFLS .db "fls", 0, 0, 0 diff --git a/tools/emul/bshell/glue.asm b/tools/emul/bshell/glue.asm index ef26dd5..3a3c907 100644 --- a/tools/emul/bshell/glue.asm +++ b/tools/emul/bshell/glue.asm @@ -3,6 +3,7 @@ .inc "err.h" .inc "ascii.h" .equ RAMSTART 0x4000 +.equ USER_CODE 0x4200 .equ STDIO_PORT 0x00 .equ FS_DATA_PORT 0x01 .equ FS_ADDR_PORT 0x02 @@ -109,7 +110,9 @@ basFindCmdExtra: call basFindCmd ret z ld hl, basBLKCmds - jp basFindCmd + call basFindCmd + ret z + jp basPgmHook emulGetC: ; Blocks until a char is returned diff --git a/tools/emul/bshell/user.h b/tools/emul/bshell/user.h index 2fb0145..47aac6d 100644 --- a/tools/emul/bshell/user.h +++ b/tools/emul/bshell/user.h @@ -1,5 +1,5 @@ .equ SHELL_RAMSTART 0x4100 -.equ USER_CODE 0x4200 +.equ USER_CODE 0x4200 ; in sync with glue.asm ; *** JUMP TABLE *** .equ strncmp 0x03