From: Robert Pengelly Date: Mon, 23 Sep 2024 21:37:07 +0000 (+0100) Subject: Set environment variables in COMMAND.COM X-Git-Url: https://git.candlhat.org/?a=commitdiff_plain;h=450c21fae3dad4b567ce2966725b88c1982fb63c;p=chimaera.git Set environment variables in COMMAND.COM --- diff --git a/build/chimaera.img b/build/chimaera.img index b454e69..0034477 100644 Binary files a/build/chimaera.img and b/build/chimaera.img differ diff --git a/build/chimaera.vhd b/build/chimaera.vhd index 3e022c8..2f3513a 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 bdad935..a7fc585 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 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 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 385d11a..6c4cfa8 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 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 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 0ccdbb5..ac84bbf 100644 --- a/src/apps/pcomm/commands +++ b/src/apps/pcomm/commands @@ -9,6 +9,7 @@ help mkdir reboot rmdir +set shutdown time touch diff --git a/src/apps/pcomm/pcomm.asm b/src/apps/pcomm/pcomm.asm index e14ce4d..8a67bf5 100644 --- a/src/apps/pcomm/pcomm.asm +++ b/src/apps/pcomm/pcomm.asm @@ -1850,6 +1850,7 @@ _handler_help.msg: db "MKDIR Create a new directory.", HEX (0D), HEX (0A) db "REBOOT Reboots the machine.", HEX (0D), HEX (0A) db "RMDIR Delete an empty directory.", HEX (0D), HEX (0A) + db "SET Display, enable or disable environment variables.", HEX (0D), HEX (0A) db "TIME Displays the system time.", HEX (0D), HEX (0A) db "TOUCH Create a new file if it doesn't already exist.", HEX (0D), HEX (0A) db "TYPE Displays the contents of a text file.", HEX (0D), HEX (0A) @@ -2002,6 +2003,9 @@ _need_ext: dw HEX (0000) global _vec_history _vec_history: db 6 dup (0) +global _vec_env +_vec_env: db 6 dup (0) + global _curr_row _curr_row: db HEX (00) @@ -2073,6 +2077,10 @@ _cmd_table: dw 0 dw _handler_rmdir + dw hash_set + dw 0 + dw _handler_set + dw hash_time dw 0 dw _handler_time diff --git a/src/apps/pcomm/set.asm b/src/apps/pcomm/set.asm new file mode 100644 index 0000000..2c19553 --- /dev/null +++ b/src/apps/pcomm/set.asm @@ -0,0 +1,368 @@ +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; @file set.asm +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +%ifndef HEX +% define HEX(y) 0x##y +%endif + +;****************************************************************************** +; @function _handler_set +;****************************************************************************** +global _handler_set +_handler_set: + + 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_set.copy + + mov si, cs:[_vec_env] + mov cx, cs:[_vec_env + 4] + + mov es, si + xor di, di + +_handler_set.print: + + and cx, cx + jz _handler_set.done + + push es + push ds + + mov ax, es:[di] + mov es, ax + + xor bx, bx + mov ax, es:[bx] + + mov ds, ax + + xor bx, bx + call _writestr + + mov al, '=' + call _writechr + + mov ax, es:[bx + 2] + + and ax, ax + jz _handler_set.no_value + + mov ds, ax + + xor bx, bx + call _writestr + +_handler_set.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_set.done + + jmp _handler_set.print + +_handler_set.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_set.trim: + + cmp byte ptr [di - 1], ' ' + ja _handler_set.got_arg + + mov byte ptr [di - 1], 0 + dec di + + jmp _handler_set.trim + +_handler_set.got_arg: + + mov bx, offset _arg + push di + mov di, offset _var + +_handler_set.check: + + cmp byte ptr [bx], ' ' + jbe _handler_set.got_var + + cmp byte ptr [bx], '=' + je _handler_set.got_var + + mov al, byte ptr [bx] + stosb + + inc bx + jmp _handler_set.check + +_handler_set.got_var: + + xor al, al + stosb + + mov si, cs:[_vec_env] + mov cx, cs:[_vec_env + 4] + + push bx + + mov es, si + xor di, di + +_handler_set.find: + + and cx, cx + jz _handler_set.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_set.found + + pop ax + pop es + + add di, 2 + + dec cx + jz _handler_set.no_var + + jmp _handler_set.find + +_handler_set.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_set.found: + + pop si + + mov es, si + xor bx, bx + + mov ax, es:[bx + 2] + + and ax, ax + jz _handler_set.get_value + + push ax + + call _free + add sp, 2 + + xor ax, ax + mov es:[bx + 2], ax + +_handler_set.get_value: + + pop es + pop bx + + call _skip_whitespace + + cmp byte ptr [bx], 0 + je _handler_set.no_equals + + cmp byte ptr [bx], ' ' + jbe _handler_set.err_invalid + + cmp byte ptr [bx], '=' + jne _handler_set.no_equals + + inc bx + call _skip_whitespace + +_handler_set.no_equals: + + pop cx + sub cx, bx + + and cx, cx + jz _handler_set.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_set.done + +_handler_set.err_invalid: + + mov bx, offset _err_invalid + call _writestr + +_handler_set.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_invalid: db "too many arguments", HEX (0D), HEX (0A), HEX (00) + +_arg: db 256 dup (0) +_var: db 256 dup (0) +_temp: db 256 dup (0) diff --git a/src/apps/pcomm/writechr.asm b/src/apps/pcomm/writechr.asm index b268990..c735600 100644 --- a/src/apps/pcomm/writechr.asm +++ b/src/apps/pcomm/writechr.asm @@ -15,25 +15,19 @@ _writechr: ;; Preserve registers. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; push ax - push bx - push bp ; Some BIOSes destroy BP when the screen scrolls + push dx ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Print the character to the screen. - ;; - ;; AH = 0Eh - Teletype output - ;; AL - Character to print - ;; BX - Page number and color - ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; - mov ah, HEX (0E) - mov bx, HEX (0007) - int HEX (10) + ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + mov ah, HEX (02) + mov dl, al + int HEX (21) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Restore registers. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; - pop bp - pop bx + pop dx pop ax ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; diff --git a/src/apps/pcomm/writestr.asm b/src/apps/pcomm/writestr.asm index 64cc800..3e50fb8 100644 --- a/src/apps/pcomm/writestr.asm +++ b/src/apps/pcomm/writestr.asm @@ -34,10 +34,6 @@ _writestr.print: ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Print the character to the screen. - ;; - ;; AH = 0Eh - Teletype output - ;; AL - Character to print - ;; BX - Page number and color ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; mov ah, HEX (02) mov dl, al diff --git a/src/kernel/mem.asm b/src/kernel/mem.asm index 477a423..2bd24a0 100644 --- a/src/kernel/mem.asm +++ b/src/kernel/mem.asm @@ -168,7 +168,7 @@ _free_mem: xor al, al mov cx, 16 - rep movsb + rep stosb xor ax, ax clc