From: Robert Pengelly Date: Tue, 24 Sep 2024 02:38:39 +0000 (+0100) Subject: Implemented internal PATH command X-Git-Url: https://git.candlhat.org/?a=commitdiff_plain;h=d26bc9c9b95cf56f36864535f77b4fad197598e3;p=chimaera.git Implemented internal PATH command --- diff --git a/build/chimaera.img b/build/chimaera.img index e54efb6..9b33336 100644 Binary files a/build/chimaera.img and b/build/chimaera.img differ diff --git a/build/chimaera.vhd b/build/chimaera.vhd index e95ce1d..d5b0b48 100644 Binary files a/build/chimaera.vhd and b/build/chimaera.vhd differ diff --git a/src/apps/pcomm/Makefile.unix b/src/apps/pcomm/Makefile.unix index a7fc585..cf1db90 100644 --- a/src/apps/pcomm/Makefile.unix +++ b/src/apps/pcomm/Makefile.unix @@ -46,7 +46,7 @@ genver: genver.c gcc -o $@ $^ endif -pcomm.com: ../../lib/crt/crt0.o cbreak.o cd.o crlf.o date.o del.o dir.o erase.o exit.o history.o mkdir.o pcomm.o rmdir.o set.o time.o touch.o type.o vector.o writechr.o writedec.o writehex.o writestr.o xmalloc.o xstrcpy.o ../../lib/crt/libc.a +pcomm.com: ../../lib/crt/crt0.o cbreak.o cd.o crlf.o date.o del.o dir.o erase.o exit.o history.o mkdir.o path.o pcomm.o rmdir.o set.o time.o touch.o type.o vector.o writechr.o writedec.o writehex.o writestr.o xmalloc.o xstrcpy.o ../../lib/crt/libc.a ../../utils/binutils/slink --oformat msdos -o $@ $^ %.o: %.asm diff --git a/src/apps/pcomm/Makefile.w32 b/src/apps/pcomm/Makefile.w32 index 6c4cfa8..f694373 100644 --- a/src/apps/pcomm/Makefile.w32 +++ b/src/apps/pcomm/Makefile.w32 @@ -30,7 +30,7 @@ genhash.exe: genhash.c genver.exe: genver.c gcc -o $@ $^ -pcomm.com: ../../lib/crt/crt0.o cbreak.o cd.o crlf.o date.o del.o dir.o erase.o exit.o history.o mkdir.o pcomm.o rmdir.o set.o time.o touch.o type.o vector.o writedec.o writehex.o writestr.o xmalloc.o xstrcpy.o ../../lib/crt/libc.a +pcomm.com: ../../lib/crt/crt0.o cbreak.o cd.o crlf.o date.o del.o dir.o erase.o exit.o history.o mkdir.o path.o pcomm.o rmdir.o set.o time.o touch.o type.o vector.o writedec.o writehex.o writestr.o xmalloc.o xstrcpy.o ../../lib/crt/libc.a ../../utils/binutils/slink --oformat msdos -o $@ $^ %.o: %.asm diff --git a/src/apps/pcomm/commands b/src/apps/pcomm/commands index ac84bbf..52e07c9 100644 --- a/src/apps/pcomm/commands +++ b/src/apps/pcomm/commands @@ -7,6 +7,7 @@ echo exit help mkdir +path reboot rmdir set diff --git a/src/apps/pcomm/path.asm b/src/apps/pcomm/path.asm new file mode 100644 index 0000000..ff43d04 --- /dev/null +++ b/src/apps/pcomm/path.asm @@ -0,0 +1,382 @@ +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; @file path.asm +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +%ifndef HEX +% define HEX(y) 0x##y +%endif + +;****************************************************************************** +; @function _handler_path +;****************************************************************************** +global _handler_path +_handler_path: + + push ax + push bx + push cx + push dx + push si + push di + push es + push ds + + xor dx, dx + call _skip_whitespace + + cmp byte ptr [bx], 0 + jne _handler_path.copy + + mov si, cs:[_vec_env] + mov cx, cs:[_vec_env + 4] + + mov es, si + xor di, di + +_handler_path.find: + + and cx, cx + jz _handler_path.err_no_path + + push es + mov ax, es:[di] + + mov es, ax + push es + + xor bx, bx + mov ax, es:[bx] + + push cx + push es + push ds + + mov cx, ds + mov es, cx + mov ds, ax + + xor ax, ax + push ax + + mov ax, offset _temp + push ax + + call _strcpy + add sp, 4 + + pop ds + + mov ax, ds + mov es, ax + + mov ax, offset _var + push ax + + mov ax, offset _temp + push ax + + call _strcmp + add sp, 4 + + pop es + pop cx + + and ax, ax + jz _handler_path.print + + pop ax + pop es + + add di, 2 + + dec cx + jz _handler_path.err_no_path + + jmp _handler_path.find + +_handler_path.print: + + pop ax + pop es + + mov ds, ax + + xor bx, bx + call _writestr + + mov al, '=' + call _writechr + + mov ax, es:[bx + 2] + + and ax, ax + jz _handler_path.no_value + + mov ds, ax + + xor bx, bx + call _writestr + +_handler_path.no_value: + + pop ds + pop es + add di, 2 + + mov al, HEX (0D) + call _writechr + + mov al, HEX (0A) + call _writechr + + dec cx + jz _handler_path.done + +_handler_path.copy: + + mov si, bx + + mov di, offset _arg + push di + + xor al, al + + mov cx, 256 + rep stosb + + pop di + push si + + call _strlen + add sp, 2 + + mov cx, ax + rep movsb + +_handler_path.trim: + + cmp byte ptr [di - 1], ' ' + ja _handler_path.got_arg + + mov byte ptr [di - 1], 0 + dec di + + jmp _handler_path.trim + +_handler_path.got_arg: + + mov bx, offset _arg + push di + + mov si, cs:[_vec_env] + mov cx, cs:[_vec_env + 4] + + push bx + + mov es, si + xor di, di + +_handler_path.find2: + + and cx, cx + jz _handler_path.no_var + + push es + mov ax, es:[di] + + mov es, ax + push es + + xor bx, bx + mov ax, es:[bx] + + push cx + push es + push ds + + mov cx, ds + mov es, cx + mov ds, ax + + xor ax, ax + push ax + + mov ax, offset _temp + push ax + + call _strcpy + add sp, 4 + + pop ds + + mov ax, ds + mov es, ax + + mov ax, offset _var + push ax + + mov ax, offset _temp + push ax + + call _strcmp + add sp, 4 + + pop es + pop cx + + and ax, ax + jz _handler_path.found + + pop ax + pop es + + add di, 2 + + dec cx + jz _handler_path.no_var + + jmp _handler_path.find2 + +_handler_path.no_var: + + mov ax, 4 + push ax + + xor ax, ax + push ax + + call _xmalloc + add sp, 4 + + mov si, ax + push ax + + mov ax, offset _vec_env + push ax + + call _vec_push + add sp, 4 + + mov ax, offset _var + push ax + + call _strlen + add sp, 2 + + mov cx, ax + inc cx + + push cx + push dx + + call _xmalloc + add sp, 4 + + push es + push si + + mov es, si + xor si, si + + mov word ptr es:[si], ax + push di + mov es, ax + + mov si, offset _var + xor di, di + rep movsb + + pop di + +_handler_path.found: + + pop si + + mov es, si + xor bx, bx + + mov ax, es:[bx + 2] + + and ax, ax + jz _handler_path.get_value + + push ax + + call _free + add sp, 2 + + xor ax, ax + mov es:[bx + 2], ax + +_handler_path.get_value: + + pop es + pop bx + + pop cx + sub cx, bx + + and cx, cx + jz _handler_path.done + + push cx + push dx + + call _xmalloc + add sp, 4 + + mov es, si + xor di, di + + mov es:[di + 2], ax + mov es, ax + + mov si, bx + xor di, di + rep movsb + + jmp _handler_path.done + +_handler_path.err_no_path: + + mov bx, offset _err_no_path + call _writestr + +_handler_path.done: + + pop ds + pop es + pop di + pop si + pop dx + pop cx + pop bx + pop ax + ret + +;****************************************************************************** +; @function _skip_whitespace +;****************************************************************************** +global _skip_whitespace +_skip_whitespace: + + cmp byte ptr [bx], 0 + je _skip_whitespace.done + + cmp byte ptr [bx], ' ' + ja _skip_whitespace.done + + inc bx + jmp _skip_whitespace + +_skip_whitespace.done: + + ret + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; Data area. +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +_err_no_path: db "No Path", HEX (0D), HEX (0A), HEX (00) +_var: db "PATH", HEX (00) + +_arg: db 256 dup (0) +_temp: db 256 dup (0) diff --git a/src/apps/pcomm/pcomm.asm b/src/apps/pcomm/pcomm.asm index 484b6db..8a41be4 100644 --- a/src/apps/pcomm/pcomm.asm +++ b/src/apps/pcomm/pcomm.asm @@ -2321,6 +2321,10 @@ _cmd_table: dw 0 dw _handler_mkdir + dw hash_path + dw 0 + dw _handler_path + dw hash_reboot dw 0 dw _handler_reboot