From: Robert Pengelly Date: Fri, 27 Sep 2024 18:57:38 +0000 (+0100) Subject: Read and process batch files and bug fixes X-Git-Url: https://git.candlhat.org/?a=commitdiff_plain;h=271d034556c3eb1b03065274ff4152f15f0b3520;p=chimaera.git Read and process batch files and bug fixes --- diff --git a/build/chimaera.img b/build/chimaera.img index 79c30fd..0e30930 100644 Binary files a/build/chimaera.img and b/build/chimaera.img differ diff --git a/build/chimaera.vhd b/build/chimaera.vhd index 7c92d87..e629017 100644 Binary files a/build/chimaera.vhd and b/build/chimaera.vhd differ diff --git a/src/Makefile.unix b/src/Makefile.unix index be37d93..f33d33f 100644 --- a/src/Makefile.unix +++ b/src/Makefile.unix @@ -18,11 +18,18 @@ clean: $(MAKE) -C "$(OBJDIR)/$$d" -f "$(SRCDIR)/$$d/Makefile.unix" OBJDIR="$(OBJDIR)/$$d" SRCDIR="$(SRCDIR)/$$d" clean; \ fi; \ done + if [ -f autoexec.bat ]; then rm -rf autoexec.bat; fi if [ -f freeldr.cfg ]; then rm -rf freeldr.cfg; fi chimaera.img: all + if [ -f autoexec.bat ]; then rm -rf autoexec.bat; fi if [ -f $@ ]; then rm -rf $@; fi + echo set PATH=A:\\DOS >> autoexec.bat +# echo echo 123 >> temp.bat +# echo @ echo %PATH% >> temp.bat +# echo temp.bat >> temp.bat + utils/dosfstools/mkdosfs --boot boot/freeldr/bootsect/fat12.bin --sectors 720 -F 12 -n "CHIMAERA OS" $@ utils/dosfstools/mmd -i $@ boot boot/freeldr @@ -30,13 +37,20 @@ chimaera.img: all utils/dosfstools/mcopy -i $@ boot/freeldr/core/freeldr.sys :: utils/dosfstools/mcopy -i $@ kernel/kernel.sys :: utils/dosfstools/mcopy -i $@ apps/pcomm/pcomm.com ::command.com + utils/dosfstools/mcopy -i $@ autoexec.bat :: -# utils/dosfstools/mmd -i $@ dos + utils/dosfstools/mmd -i $@ dos +# utils/dosfstools/mcopy -i $@ temp.bat ::/dos/temp.bat # utils/dosfstools/mcopy -i $@ apps/hello/hello.com ::dos/hello.com chimaera.vhd: all + if [ -f autoexec.bat ]; then rm -rf autoexec.bat; fi if [ -f $@ ]; then rm -rf $@; fi + echo set PATH=C:\\DOS >> autoexec.bat +# echo echo %PATH% >> autoexec.bat +# echo autoexec.bat >> autoexec.bat + # utils/parted/parted --arca --boot boot/mbr/dosmbr.bin mkpart 128,06,17,65535 $@ # utils/dosfstools/mkdosfs --arca --boot boot/freeldr/bootsect/fat16.bin --offset 17 --sectors 65535 -F 16 -n "CHIMAERA OS" $@ @@ -49,6 +63,7 @@ chimaera.vhd: all utils/dosfstools/mcopy --arca --offset 17 -i $@ boot/freeldr/core/freeldr.sys :: utils/dosfstools/mcopy --arca --offset 17 -i $@ kernel/kernel.sys :: utils/dosfstools/mcopy --arca --offset 17 -i $@ apps/pcomm/pcomm.com ::command.com + utils/dosfstools/mcopy --arca --offset 17 -i $@ autoexec.bat :: # utils/dosfstools/mcopy --arca --offset 17 -i $@ apps/hello/hello.com ::hello.com run-qemu: chimaera.img chimaera.vhd diff --git a/src/apps/pcomm/Makefile.unix b/src/apps/pcomm/Makefile.unix index cf1db90..f52306e 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 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 +pcomm.com: ../../lib/crt/crt0.o cbreak.o cd.o crlf.o date.o del.o dir.o erase.o exit.o history.o ll.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 xrealloc.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 f694373..8b28d85 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 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 +pcomm.com: ../../lib/crt/crt0.o cbreak.o cd.o crlf.o date.o del.o dir.o erase.o exit.o history.o ll.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 xrealloc.o xstrcpy.o ../../lib/crt/libc.a ../../utils/binutils/slink --oformat msdos -o $@ $^ %.o: %.asm diff --git a/src/apps/pcomm/ll.asm b/src/apps/pcomm/ll.asm new file mode 100644 index 0000000..fc46e45 --- /dev/null +++ b/src/apps/pcomm/ll.asm @@ -0,0 +1,692 @@ +;****************************************************************************** +; @file ll.asm +;****************************************************************************** +%define CAPACITY_INCREMENT 256 + +%ifndef HEX +% define HEX(y) 0x##y +%endif + +;****************************************************************************** +; @function _load_line +;****************************************************************************** +global _load_line +_load_line: + + push bp + + mov bp, sp + sub sp, 12 + + push bx + push cx + push dx + push si + push di + push es + push ds + + mov bx, word ptr [bp + 12] + + and bx, bx + jz .L18 + + mov cx, ds + + push es + push ds + push si + push di + + mov es, cx + mov ds, bx + + mov di, offset _load_line_data + xor si, si + + mov cx, 14 + rep movsb + + pop di + pop si + pop ds + pop es + + mov ax, ss + mov es, ax + + xor ax, ax + lea di, word ptr [bp - 12] + + mov cx, 12 + rep stosb + + mov cx, word ptr [_load_line_data + 12] + + and cx, cx + jz .L1 + + push es + push ds + + mov ax, word ptr [_load_line_data + 8] + sub ax, word ptr [_load_line_data + 12] + + push ax + + mov ax, word ptr [_load_line_data + 2] + xor dx, dx + + mov cx, 16 + mul cx + + add ax, word ptr [_load_line_data + 12] + adc dx, 0 + + div cx + push dx + + xor bx, bx + push bx + + mov bx, word ptr [_load_line_data + 2] + mov es, bx + + mov ds, ax + + call _memmove + add sp, 6 + + pop ds + pop es + + mov cx, word ptr [_load_line_data + 12] + sub word ptr [_load_line_data + 8], cx + +.L1: + + mov ax, word ptr [_load_line_data + 4] + + cmp ax, word ptr [bp - 12] + jb .L2 + + cmp ax, word ptr [bp - 8] + ja .L3 + +.L2: + + mov ax, word ptr [_load_line_data + 4] + xor dx, dx + + add ax, CAPACITY_INCREMENT + mov word ptr [_load_line_data + 4], ax + + mov bx, ax + xor cx, cx + + add bx, 2 + adc cx, 0 + + push ax + push dx + + push bx + push cx + push word ptr word ptr [_load_line_data + 0] + + call _xrealloc + add sp, 6 + + mov word ptr [_load_line_data + 0], ax + pop dx + pop ax + + mov bx, ax + mov cx, dx + + add bx, 1 + adc cx, 0 + + push ax + push dx + + push bx + push cx + push word ptr word ptr [_load_line_data + 2] + + call _xrealloc + add sp, 6 + + mov word ptr [_load_line_data + 2], ax + pop dx + pop ax + +.L3: + + mov ax, word ptr [_load_line_data + 8] + + cmp ax, word ptr [bp - 8] + ja .L4 + + push ds + push word ptr [bp + 10] + + mov ax, word ptr [_load_line_data + 4] + sub ax, word ptr [bp - 8] + + push ax + + mov ax, 1 + push ax + + mov ax, word ptr [_load_line_data + 2] + xor dx, dx + + mov cx, 16 + mul cx + + add ax, word ptr [bp - 8] + adc dx, 0 + + div cx + + mov ds, ax + push dx + + call _fread + add sp, 8 + + pop ds + jc .L5 + + add ax, word ptr [bp - 8] + mov word ptr [_load_line_data + 8], ax + + mov ax, word ptr [_load_line_data + 2] + xor dx, dx + + mov cx, 16 + mul cx + + add ax, word ptr [_load_line_data + 8] + adc dx, 0 + + div cx + + push es + push di + + mov es, ax + mov di, dx + + xor al, al + mov es:[di], al + + pop di + pop es + +.L15: + + cmp word ptr [bp - 4], 1 + jne .L4 + +.L17: + + mov ax, word ptr [_load_line_data + 8] + + cmp ax, word ptr [bp - 8] + jb .L4 + + mov ax, word ptr [_load_line_data + 2] + xor dx, dx + + mov cx, 16 + mul cx + + add ax, word ptr [bp - 8] + adc dx, 0 + + div cx + + push es + push di + + mov es, ax + mov di, dx + + mov bl, es:[di] + pop di + pop es + + cmp bl, HEX (0A) + jne .L16 + + mov word ptr [bp - 4], 0 + jmp .L4 + +.L16: + + add word ptr [bp - 8], 1 + jmp .L17 + +.L4: + + mov ax, word ptr [_load_line_data + 8] + + cmp ax, word ptr [bp - 8] + jbe .L6 + +.L10: + + mov ax, word ptr [_load_line_data + 4] + + cmp ax, word ptr [bp - 12] + jbe .L6 + +.L11: + + push es + push di + + mov ax, word ptr [_load_line_data + 2] + xor dx, dx + + mov cx, 16 + mul cx + + add ax, word ptr [bp - 8] + adc dx, 0 + + div cx + + mov es, ax + mov di, dx + + mov bl, es:[di] + pop di + pop es + + add word ptr [bp - 8], 1 + + push es + push di + + mov ax, word ptr [_load_line_data + 0] + xor dx, dx + + mov cx, 16 + mul cx + + add ax, word ptr [bp - 12] + adc dx, 0 + + div cx + + mov es, ax + mov di, dx + + mov es:[di], bl + + pop di + pop es + + cmp bl, '#' + jne .L14 + + mov word ptr [bp - 4], 1 + jmp .L15 + +.L14: + + cmp bl, HEX (0A) + jne .L7 + + mov si, word ptr [bp - 12] + + and si, si + jz .L12 + + dec si + + mov ax, word ptr [_load_line_data + 0] + xor dx, dx + + mov cx, 16 + mul cx + + add ax, si + adc dx, 0 + + inc si + div cx + + push es + push di + + mov es, ax + mov di, dx + + mov bl, es:[di] + pop di + pop es + + cmp bl, HEX (0D) + jne .L13 + + push es + push di + + mov es, ax + mov di, dx + + mov bl, HEX (0A) + mov es:[di], bl + + pop di + pop es + + mov word ptr [bp - 12], si + +.L13: + + and si, si + jz .L12 + + dec si + + mov ax, word ptr [_load_line_data + 0] + xor dx, dx + + mov cx, 16 + mul cx + + add ax, si + adc dx, 0 + + div cx + + push es + push di + + mov es, ax + mov di, dx + + mov bl, es:[di] + pop di + pop es + + cmp bl, ' ' + jne .L12 + + push es + push di + + mov es, ax + mov di, dx + + mov bl, HEX (0A) + mov es:[di], bl + + pop di + pop es + + mov word ptr [bp - 12], si + jmp .L13 + +.L12: + + mov bx, word ptr [bp - 12] + inc bx + + mov ax, word ptr [_load_line_data + 0] + xor dx, dx + + mov cx, 16 + mul cx + + add ax, bx + adc dx, 0 + + div cx + + push es + push di + + mov es, ax + mov di, dx + + xor al, al + mov es:[di], al + + pop di + pop es + + mov bx, word ptr [bp - 8] + mov word ptr [_load_line_data + 12], bx + + mov bx, word ptr [bp + 4] + + mov ax, word ptr [_load_line_data + 0] + mov [bx], ax + + jmp .L8 + +.L7: + + add word ptr [bp - 12], 1 + jmp .L4 + +.L6: + + push word ptr [bp + 10] + + call _feof + add sp, 2 + + and ax, ax + jz .L1 + + mov cx, word ptr [_load_line_data + 8] + + and cx, cx + jz .L5 + + mov ax, word ptr [_load_line_data + 0] + xor dx, dx + + mov cx, 16 + mul cx + + add ax, word ptr [bp - 12] + adc dx, 0 + + div cx + + push es + push di + + mov es, ax + mov di, dx + + mov al, HEX (0A) + mov es:[di], al + + pop di + pop es + + mov bx, word ptr [bp - 12] + inc bx + + mov ax, word ptr [_load_line_data + 0] + xor dx, dx + + mov cx, 16 + mul cx + + add ax, bx + adc dx, 0 + + push es + push di + + mov es, ax + mov di, dx + + xor ax, ax + mov es:[di], al + + pop di + pop es + + mov word ptr [_load_line_data + 12], ax + mov word ptr [_load_line_data + 8], ax + + mov bx, word ptr [bp + 4] + + mov ax, word ptr [_load_line_data + 0] + mov [bx], ax + + jmp .L8 + +.L5: + + mov ax, word ptr [bp + 12] + mov es, ax + + mov si, offset _load_line_data + xor di, di + + mov cx, 14 + rep movsb + +.L18: + + mov ax, 1 + + pop ds + pop es + pop di + pop si + pop dx + pop cx + pop bx + + add sp, 12 + stc + + pop bp + ret + +.L8: + + mov ax, word ptr [bp + 12] + mov es, ax + + mov si, offset _load_line_data + xor di, di + + mov cx, 14 + rep movsb + + xor ax, ax + + pop ds + pop es + pop di + pop si + pop dx + pop cx + pop bx + + add sp, 12 + clc + + pop bp + ret + +;****************************************************************************** +; @function _load_line_create_internal_data +;****************************************************************************** +global _load_line_create_internal_data +_load_line_create_internal_data: + + push dx + +.L19: + + mov ax, 16 + xor dx, dx + + push ax + push dx + + call _xmalloc + add sp, 4 + +.L20: + + pop dx + ret + +;****************************************************************************** +; @function _load_line_destroy_internal_data +;****************************************************************************** +global _load_line_destroy_internal_data +_load_line_destroy_internal_data: + + push bp + mov bp, sp + + push es + push bx + push si + + mov bx, word ptr [bp + 4] + + and bx, bx + jz .L21 + + mov es, bx + xor bx, bx + + mov si, es:[bx + 0] + + and si, si + jz .L22 + + push si + + call _free + add sp, 2 + +.L22: + + mov si, es:[bx + 2] + + and si, si + jz L23 + + push si + + call _free + add sp, 2 + +L23: + + push es + + call _free + add sp, 2 + +.L21: + + pop si + pop bx + pop es + pop bp + ret + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; Data area. +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +_load_line_data: db 14 dup (0) diff --git a/src/apps/pcomm/pcomm.asm b/src/apps/pcomm/pcomm.asm index 8e01127..ff12bf4 100644 --- a/src/apps/pcomm/pcomm.asm +++ b/src/apps/pcomm/pcomm.asm @@ -17,6 +17,15 @@ _main: mov bx, offset _welcome_message call _writestr + + xor ax, ax + push ax + + mov bx, offset _autoexec + push bx + + call _read_batch + add sp, 4 .L5: @@ -1175,1110 +1184,1266 @@ _main: .L21: - mov di, offset _formatted_command - push di - - xor al, al - - mov cx, 255 - rep stosb - mov bx, offset _scratch push bx - call _expand_vars - add sp, 4 + call _process_line + add sp, 2 - mov bx, offset _formatted_command + jmp .L5 + +.L1: + + and ch, ch + jz .L67 - call _get_command - jc .L23 + push ax + push bx + push cx + push dx - mov si, bx - xor ax, ax + xor ah, ah + mov al, cs:[_curr_col] - lodsb + xor dx, dx - and al, al - jz .L7 + mov cl, ch + xor ch, ch - push bx - xor bx, bx + add ax, cx - or al, HEX (20) - mov bl, al - -.L28: - - lodsb + mov di, offset _scratch + add di, cx - or al, al - jz .L31 + mov cx, 80 + div cx - mov cl, 5 - rol bx, cl + mov dh, cs:[_curr_row] + add dh, al - or al, HEX (20) - xor bx, ax + mov ax, HEX (0200) + xor bx, bx + int HEX (10) - jmp .L28 + pop dx + pop cx + pop bx + pop ax -.L31: +.L67: - mov di, bx - pop bx - - mov si, offset _cmd_table - mov cx, offset _cmd_count + call _history_up + jmp .L11 -.L29: +.L2: - lodsw + and ch, ch + jz .L66 - cmp di, ax - je .L30 + push ax + push bx + push cx + push dx - lodsw - lodsw - loop .L29 + xor ah, ah + mov al, cs:[_curr_col] - jmp .L23 - -.L30: - - push bx + xor dx, dx - call _strlen - add sp, 2 + mov cl, ch + xor ch, ch - add bx, ax - inc bx - -.L33: - - cmp byte ptr [bx], 0 - je .L32 + add ax, cx - cmp byte ptr [bx], ' ' - ja .L32 + mov di, offset _scratch + add di, cx - inc bx - jmp .L33 + mov cx, 80 + div cx + + mov dh, cs:[_curr_row] + add dh, al + + mov ax, HEX (0200) + xor bx, bx + int HEX (10) + + pop dx + pop cx + pop bx + pop ax -.L32: +.L66: - lodsw - - call cs:[si] - jmp .L5 + call _history_down + jmp .L11 -.L23: +.L75: - mov di, offset _app_path + and ch, ch + jz .L11 - mov ax, '\\' push ax - - mov si, bx push bx + push cx + push dx - call _strrchr - add sp, 4 + xor ah, ah + mov al, cs:[_curr_col] - and ax, ax - jz .L27 + xor dx, dx - mov bx, ax - mov byte ptr [bx], 0 + mov cl, ch + xor ch, ch - call _format_path + add ax, cx - mov al, '\\' - stosb + mov di, offset _scratch + add di, cx - inc bx + mov cx, 80 + div cx + + mov dh, cs:[_curr_row] + add dh, al + + mov ax, HEX (0200) + xor bx, bx + int HEX (10) + + pop dx + pop cx + pop bx + pop ax + + jmp .L11 -.L27: +.L74: - mov ax, '.' push ax - - mov si, bx push bx + push cx + push dx - call _strrchr - add sp, 4 + mov dh, cs:[_curr_row] + mov dl, cs:[_curr_col] - and ax, ax - jnz .L24 + mov ax, HEX (0200) + xor bx, bx + int HEX (10) + + mov di, offset _scratch + pop dx + pop cx + pop bx + pop ax + + jmp .L11 -.L26: +;****************************************************************************** +; @function _concat_exec +;****************************************************************************** +_concat_exec: + push bp + mov bp, sp + + push ax push bx + push cx + push dx + push si + push di + push es - call _strlen - add sp, 2 + mov ax, ds + mov es, ax - mov cx, ax - rep movsb + mov di, offset _full_path - mov word ptr cs:[_need_ext], 1 - add bx, ax + mov si, word ptr [bp + 4] + call _format_path - mov al, '.' + mov al, '\\' stosb - mov al, 'c' - stosb + mov si, word ptr [bp + 6] + call _format_path - mov al, 'o' - stosb + mov dx, offset _full_path + inc bx + mov di, bx - mov al, 'm' - stosb + mov bx, offset _param_blk - jmp .L25 + mov word ptr [bx + 2], di + mov word ptr [bx + 4], ds + + mov ax, HEX (4B00) + int HEX (21) -.L24: +_concat_exec.done: - push bx - - call _strlen - add sp, 2 - - mov cx, ax - rep movsb - - add bx, ax + pop es + pop di + pop si + pop dx + pop cx + pop bx + pop ax + pop bp + ret -.L25: +;****************************************************************************** +; @function _concat_read +;****************************************************************************** +_concat_read: - xor al, al - stosb + push bp + mov bp, sp + push ax push bx + push cx + push dx + push si + push di + push es - mov dx, offset _app_path - inc bx - mov di, bx + mov ax, ds + mov es, ax - mov bx, offset _param_blk + mov di, offset _full_path - mov word ptr [bx + 2], di - mov word ptr [bx + 4], ds + mov si, word ptr [bp + 4] + call _format_path - mov ax, HEX (4B00) - int HEX (21) - pop bx - jnc .L5 + mov al, '\\' + stosb - mov ax, '\\' + mov si, word ptr [bp + 6] + call _format_path + + mov ax, 1 push ax - mov ax, offset _app_path + mov ax, offset _full_path push ax - call _strrchr + call _read_batch + jc _concat_read.err + add sp, 4 + clc - and ax, ax - jnz .L98 + jmp _concat_read.done -.L99: +_concat_read.err: - call _get_paths + add sp, 4 + stc + +_concat_read.done: + + pop es + pop di + pop si + pop dx + pop cx + pop bx + pop ax + pop bp + ret + +;****************************************************************************** +; @function _get_env +;****************************************************************************** +_get_env: + + push bp + mov bp, sp - push ax push bx push cx + push dx + push si push di push es - mov ax, cs:[_vec_paths] - mov es, ax - mov cx, cs:[_vec_paths + 4] + mov si, cs:[_vec_env] + mov cx, cs:[_vec_env + 4] + mov es, si xor di, di -.L96: +.L91: and cx, cx - jz .L97 + jz .L92 - mov ax, offset _app_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, cs + mov es, cx + mov ds, ax + + push es + push di + + mov di, offset _temp + xor al, al + + mov cx, 255 + rep stosb + + pop di + pop es + + xor ax, ax push ax - mov ax, es:[di] + mov ax, offset _temp push ax - call _concat_exec - jnc .L100 + call _strcpy add sp, 4 - add di, 2 - dec cx + mov ax, word ptr [bp + 4] + push ax - jmp .L96 - -.L100: - + mov ax, offset _temp + push ax + + call _strcmp add sp, 4 + pop ds pop es - pop di pop cx - pop bx + + and ax, ax + jz .L93 + pop ax + pop es - jmp .L5 + add di, 2 + dec cx + + jmp .L91 -.L97: +.L93: + + pop ax + pop es + + jmp .L90 + +.L92: + + xor ax, ax + +.L90: pop es pop di + pop si + pop dx pop cx pop bx - pop ax + pop bp + ret -.L98: +;****************************************************************************** +; @function _expand_vars +;****************************************************************************** +_expand_vars: - mov bx, offset _err_invalid - call _writestr - - cmp word ptr cs:[_need_ext], 1 - jb .L34 + push bp + mov bp, sp - mov ax, '.' push ax - - mov bx, offset _app_path push bx + push cx + push dx + push si + push di - call _strrchr - add sp, 4 + mov di, word ptr [bp + 6] + mov si, word ptr [bp + 4] - mov bx, ax - mov byte ptr [bx], 0 + mov dx, di -.L34: +.L87: - mov bx, offset _app_path - call _writestr - call _crlf + cmp byte ptr [si], 0 + je .L84 - jmp .L5 - -.L1: - - and ch, ch - jz .L67 + mov cx, di + sub cx, dx - push ax - push bx - push cx - push dx + cmp cx, 255 + jae .L84 - xor ah, ah - mov al, cs:[_curr_col] + cmp byte ptr [si], '%' + jne .L85 - xor dx, dx + inc si - mov cl, ch - xor ch, ch + cmp byte ptr [si], 0 + jne .L86 - add ax, cx + mov al, '%' + stosb - mov di, offset _scratch - add di, cx + jmp .L87 + +.L86: + + cmp byte ptr [si], '%' + je .L85 - mov cx, 80 - div cx + mov ax, '%' + push ax - mov dh, cs:[_curr_row] - add dh, al + push si - mov ax, HEX (0200) - xor bx, bx - int HEX (10) + call _strchr + add sp, 4 - pop dx - pop cx - pop bx - pop ax - -.L67: - - call _history_up - jmp .L11 + and ax, ax + jnz .L88 + + ;mov al, '%' + ;stosb + + jmp .L87 -.L2: +.L88: - and ch, ch - jz .L66 + mov bx, ax + mov byte ptr [bx], 0 - push ax - push bx - push cx - push dx + push si - xor ah, ah - mov al, cs:[_curr_col] + call _get_env + add sp, 2 - xor dx, dx + and ax, ax + jz .L89 - mov cl, ch - xor ch, ch + push si + push ds - add ax, cx + mov ds, ax + xor si, si - mov di, offset _scratch - add di, cx + mov ax, [si + 2] + mov ds, ax + +.L94: + + mov cx, di + sub cx, dx - mov cx, 80 - div cx + cmp cx, 255 + jae .L95 - mov dh, cs:[_curr_row] - add dh, al + lodsb - mov ax, HEX (0200) - xor bx, bx - int HEX (10) + and al, al + jz .L95 - pop dx - pop cx - pop bx - pop ax + stosb + jmp .L94 -.L66: +.L95: - call _history_down - jmp .L11 + pop ds + pop si + + jmp .L84 -.L75: +.L89: - and ch, ch - jz .L11 - - push ax - push bx - push cx - push dx - - xor ah, ah - mov al, cs:[_curr_col] - - xor dx, dx - - mov cl, ch - xor ch, ch - - add ax, cx - - mov di, offset _scratch - add di, cx - - mov cx, 80 - div cx - - mov dh, cs:[_curr_row] - add dh, al - - mov ax, HEX (0200) - xor bx, bx - int HEX (10) - - pop dx - pop cx - pop bx - pop ax + mov si, bx + inc si - jmp .L11 + jmp .L87 -.L74: +.L85: - push ax - push bx - push cx - push dx - - mov dh, cs:[_curr_row] - mov dl, cs:[_curr_col] - - mov ax, HEX (0200) - xor bx, bx - int HEX (10) - - mov di, offset _scratch + movsb + jmp .L87 + +.L84: + + pop di + pop si pop dx pop cx pop bx pop ax - - jmp .L11 + pop bp + ret ;****************************************************************************** -; @function _concat_exec +; @function _format_path ;****************************************************************************** -_concat_exec: +_format_path: - push bp - mov bp, sp - push ax push bx push cx push dx - push si - push di - push es - mov ax, ds - mov es, ax + mov dx, di + jmp short _format_path.loop + +_format_path.store: + + stosb - mov di, offset _full_path + cmp al, '\\' + jne _format_path.loop + +_format_path.skip: + + lodsb - mov si, word ptr [bp + 4] - call _format_path + cmp al, '\\' + je _format_path.skip - mov al, '\\' - stosb + dec si + +_format_path.loop: + + mov ax, di + sub ax, dx - mov si, word ptr [bp + 6] - call _format_path + cmp ax, 250 + ja _format_path.done - mov dx, offset _full_path - inc bx - mov di, bx + lodsb - mov bx, offset _param_blk + and al, al + jz _format_path.done - mov word ptr [bx + 2], di - mov word ptr [bx + 4], ds + cmp al, 127 + ja _format_path.done - mov ax, HEX (4B00) - int HEX (21) + cmp al, 32 + jb _format_path.done + + jmp short _format_path.store -_concat_exec.done: +_format_path.done: - pop es - pop di - pop si pop dx pop cx pop bx pop ax - pop bp ret ;****************************************************************************** -; @function _get_env +; @function _get_command ;****************************************************************************** -_get_env: +_get_command: push bp + mov bp, sp + sub sp, 2 - push bx - push cx - push dx push si - push di - push es - - mov si, cs:[_vec_env] - mov cx, cs:[_vec_env + 4] + push ax + push dx - mov es, si - xor di, di + mov word ptr [bp - 2], 0 + mov si, offset _formatted_command -.L91: +_get_command.loop: - and cx, cx - jz .L92 + lodsb - push es - mov ax, es:[di] + and al, al + jz _get_command.done - mov es, ax - push es + cmp al, ' ' + jbe _get_command.null - xor bx, bx - mov ax, es:[bx] + cmp al, ':' + je _get_command.not_internal - push cx - push es - push ds + cmp al, '\\' + je _get_command.not_internal - mov cx, ds - mov es, cx - mov ds, ax + cmp al, '.' + je _get_command.not_internal + +_get_command.check: + + xor ah, ah - push es - push di + mov dx, ax + push dx - mov di, offset _temp - xor al, al - - mov cx, 255 - rep stosb - - pop di - pop es - - 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, word ptr [bp + 4] - push ax - - mov ax, offset _temp - push ax - - call _strcmp - add sp, 4 - - pop es - pop cx + call _isalpha + add sp, 2 and ax, ax - jz .L93 + jz _get_command.loop - pop ax - pop es + push dx - add di, 2 - dec cx + call _tolower + add sp, 2 - jmp .L91 + mov [si - 1], al + jmp _get_command.loop -.L93: +_get_command.not_internal: - pop ax - pop es - - jmp .L90 + mov word ptr [bp - 2], 1 + jmp _get_command.loop -.L92: +_get_command.null: - xor ax, ax + mov byte ptr [si - 1], 0 -.L90: +_get_command.done: - pop es - pop di - pop si + mov bx, word ptr [bp - 2] + pop dx - pop cx - pop bx + pop ax + pop si + + add sp, 2 + clc + pop bp + + and bx, bx + jz _get_command.ret + + stc + +_get_command.ret: + + mov bx, offset _formatted_command ret ;****************************************************************************** -; @function _expand_vars +; @function _handle_backspace ;****************************************************************************** -_expand_vars: +_handle_backspace: - push bp - mov bp, sp + and ch, ch + jz .L12 + + xor ah, ah + mov al, cs:[_curr_col] - push ax push bx push cx push dx - push si - push di - mov di, word ptr [bp + 6] - mov si, word ptr [bp + 4] + xor dx, dx - mov dx, di - -.L87: - - cmp byte ptr [si], 0 - je .L84 + mov cl, ch + xor ch, ch - mov cx, di - sub cx, dx + add ax, cx - cmp cx, 255 - jae .L84 + mov cx, 80 + div cx - cmp byte ptr [si], '%' - jne .L85 + xchg ax, dx + pop dx + pop cx + pop bx - inc si + and ax, ax + jnz .L13 - cmp byte ptr [si], 0 - jne .L86 + push ax + push bx + push dx + push cx - mov al, '%' - stosb + mov ax, HEX (0300) + xor bx, bx + int HEX (10) - jmp .L87 - -.L86: - - cmp byte ptr [si], '%' - je .L85 + pop cx + dec dh - mov ax, '%' - push ax + mov ax, HEX (0200) + xor bx, bx + mov dl, HEX (50) + int HEX (10) - push si + call _erase_char - call _strchr - add sp, 4 + mov ax, HEX (0200) + xor bx, bx + mov dl, HEX (4F) + int HEX (10) - and ax, ax - jnz .L88 + pop dx + pop bx + pop ax - ;mov al, '%' - ;stosb + dec ch + dec di - jmp .L87 + mov byte ptr es:[di], 0 + ret -.L88: +.L13: - mov bx, ax - mov byte ptr [bx], 0 + call _erase_char - push si + dec ch + dec di - call _get_env - add sp, 2 + mov byte ptr es:[di], 0 + +.L12: + + ret + +;****************************************************************************** +; @function _handler_cls +;****************************************************************************** +_handler_cls: + + mov ax, HEX (0600) + mov bh, HEX (07) + xor cx, cx + mov dx, HEX (184F) + int HEX (10) - and ax, ax - jz .L89 + mov ax, HEX (0200) + xor bx, bx + xor dx, dx + int HEX (10) + ret + +;****************************************************************************** +; @function _handler_echo +;****************************************************************************** +_handler_echo: + + push ax + push dx push si - push ds - - mov ds, ax - xor si, si - mov ax, [si + 2] - mov ds, ax + mov si, bx -.L94: +_handler_echo.check: - mov cx, di - sub cx, dx - - cmp cx, 255 - jae .L95 + cmp word ptr cs:[_cbreak], 1 + je _handler_echo.done lodsb and al, al - jz .L95 + jz _handler_echo.newline - stosb - jmp .L94 - -.L95: - - pop ds - pop si - -.L89: - - mov si, bx - inc si + mov ah, HEX (02) + mov dl, al + int HEX (21) - jmp .L87 + jmp _handler_echo.check -.L85: +_handler_echo.newline: - movsb - jmp .L87 + mov ah, HEX (02) + mov dl, HEX (0D) + int HEX (21) + + mov ah, HEX (02) + mov dl, HEX (0A) + int HEX (21) -.L84: +_handler_echo.done: - pop di pop si pop dx - pop cx - pop bx pop ax - pop bp ret ;****************************************************************************** -; @function _format_path +; @function _handler_help ;****************************************************************************** -_format_path: +_handler_help: push ax push bx - push cx - push dx + push ds - mov dx, di - jmp short _format_path.loop + mov ax, cs + mov ds, ax + + mov bx, offset _handler_help.msg + call _writestr -_format_path.store: +_handler_help.done: - stosb + pop ds + pop bx + pop ax + ret + +_handler_help.msg: + + db "CD Change the current directory to the specified path.", HEX (0D), HEX (0A) + db "CLS Clears the screen.", HEX (0D), HEX (0A) + db "DATE Displays the system date.", HEX (0D), HEX (0A) + db "DEL Delete the specified files.", HEX (0D), HEX (0A) + db "DIR Displays a list of files and subdirectories in a directory.", HEX (0D), HEX (0A) + db "ECHO Specifies the text to display to the screen.", HEX (0D), HEX (0A) + db "EXIT Exit the current shell if it's not the last instance.", HEX (0D), HEX (0A) + 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) - cmp al, '\\' - jne _format_path.loop + db HEX (00) -_format_path.skip: +;****************************************************************************** +; @function _handler_reboot +;****************************************************************************** +_handler_reboot: - lodsb + ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + ;; Disable interrupts. + ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + cli - cmp al, '\\' - je _format_path.skip + ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + ;; Stop floppy motor. + ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + mov dx, HEX (03F2) + xor al, al + out dx, al - dec si + ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + ;; Reset console. + ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + mov ax, HEX (0003) + int HEX (10) + + ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + ;; Cold reboot. + ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + xor ax, ax + mov es, ax + + mov bx, HEX (0472) + mov word ptr es:[bx], 0 + + jmp HEX (F000) : HEX (FFF0) -_format_path.loop: +;****************************************************************************** +; @function _process_line +;****************************************************************************** +global _process_line +_process_line: - mov ax, di - sub ax, dx + push bp + mov bp, sp - cmp ax, 250 - ja _format_path.done + push ax + push bx + push cx + push dx + push si + push di + push es + push ds + + mov ax, cs + mov es, ax + +.L102: + + mov di, offset _formatted_command + push di + + xor al, al + + mov cx, 255 + rep stosb + + mov bx, word ptr [bp + 4] + push bx + + call _expand_vars + add sp, 4 + + mov ax, cs + mov ds, ax + + mov bx, offset _formatted_command + + call _get_command + jc .L23 + + mov si, bx + xor ax, ax lodsb and al, al - jz _format_path.done + jz .L101 - cmp al, 127 - ja _format_path.done + push bx + xor bx, bx - cmp al, 32 - jb _format_path.done + or al, HEX (20) + mov bl, al + +.L28: + + lodsb - jmp short _format_path.store + or al, al + jz .L31 + + mov cl, 5 + rol bx, cl + + or al, HEX (20) + xor bx, ax + + jmp .L28 -_format_path.done: +.L31: - pop dx - pop cx + mov di, bx pop bx - pop ax - ret + + mov si, offset _cmd_table + mov cx, offset _cmd_count -;****************************************************************************** -; @function _get_command -;****************************************************************************** -_get_command: +.L29: - push bp + lodsw - mov bp, sp - sub sp, 2 + cmp di, ax + je .L30 - push si - push ax - push dx + lodsw + lodsw + loop .L29 - mov word ptr [bp - 2], 0 - mov si, offset _formatted_command + jmp .L23 -_get_command.loop: +.L30: - lodsb + push bx - and al, al - jz _get_command.done + call _strlen + add sp, 2 - cmp al, ' ' - jbe _get_command.null + add bx, ax + inc bx + +.L33: + + cmp byte ptr [bx], 0 + je .L32 - cmp al, ':' - je _get_command.not_internal + cmp byte ptr [bx], ' ' + ja .L32 - cmp al, '\\' - je _get_command.not_internal + inc bx + jmp .L33 + +.L32: + + lodsw - cmp al, '.' - je _get_command.not_internal + call cs:[si] + jmp .L101 -_get_command.check: +.L23: - xor ah, ah + mov di, offset _app_path - mov dx, ax - push dx + mov ax, '\\' + push ax - call _isalpha - add sp, 2 + mov si, bx + push bx + + call _strrchr + add sp, 4 and ax, ax - jz _get_command.loop + jz .L27 - push dx + mov bx, ax + mov byte ptr [bx], 0 - call _tolower - add sp, 2 + call _format_path - mov [si - 1], al - jmp _get_command.loop - -_get_command.not_internal: - - mov word ptr [bp - 2], 1 - jmp _get_command.loop - -_get_command.null: - - mov byte ptr [si - 1], 0 + mov al, '\\' + stosb + + inc bx -_get_command.done: +.L27: - mov bx, word ptr [bp - 2] - - pop dx - pop ax - pop si - - add sp, 2 - clc + mov ax, '.' + push ax - pop bp + mov si, bx + push bx - and bx, bx - jz _get_command.ret + call _strrchr + add sp, 4 - stc - -_get_command.ret: - - mov bx, offset _formatted_command - ret + and ax, ax + jnz .L24 -;****************************************************************************** -; @function _handle_backspace -;****************************************************************************** -_handle_backspace: +.L26: - and ch, ch - jz .L12 + push bx - xor ah, ah - mov al, cs:[_curr_col] + call _strlen + add sp, 2 - push bx - push cx - push dx + mov cx, ax + rep movsb - xor dx, dx + mov word ptr cs:[_need_ext], 1 + add bx, ax - mov cl, ch - xor ch, ch + push di - add ax, cx + mov al, '.' + stosb - mov cx, 80 - div cx + mov al, 'c' + stosb - xchg ax, dx - pop dx - pop cx - pop bx + mov al, 'o' + stosb - and ax, ax - jnz .L13 + mov al, 'm' + stosb + jmp .L25 + +.L24: + push ax push bx - push dx - push cx - mov ax, HEX (0300) - xor bx, bx - int HEX (10) + call _strlen + add sp, 2 - pop cx - dec dh + mov cx, ax + rep movsb - mov ax, HEX (0200) - xor bx, bx - mov dl, HEX (50) - int HEX (10) + add bx, ax + +.L25: + + xor al, al + stosb - call _erase_char + mov word ptr cs:[_in_batch], 0 - mov ax, HEX (0200) - xor bx, bx - mov dl, HEX (4F) - int HEX (10) + mov ax, offset _ext_batch + push ax - pop dx - pop bx - pop ax + call _strcmp + add sp, 4 - dec ch - dec di + and ax, ax + jnz .L104 - mov byte ptr es:[di], 0 - ret + mov word ptr cs:[_in_batch], 1 + + mov ax, 1 + push ax + + mov ax, offset _app_path + push ax + + call _read_batch + jc .L107 + + add sp, 4 + jmp .L101 -.L13: +.L104: - call _erase_char + push bx - dec ch - dec di + mov dx, offset _app_path + inc bx + mov di, bx - mov byte ptr es:[di], 0 + mov bx, offset _param_blk + + mov word ptr [bx + 2], di + mov word ptr [bx + 4], ds + + mov ax, HEX (4B00) + int HEX (21) + pop bx + jnc .L101 + + jmp .L103 -.L12: +.L107: - ret + add sp, 4 -;****************************************************************************** -; @function _handler_cls -;****************************************************************************** -_handler_cls: +.L103: - mov ax, HEX (0600) - mov bh, HEX (07) - xor cx, cx - mov dx, HEX (184F) - int HEX (10) + mov ax, '\\' + push ax - mov ax, HEX (0200) - xor bx, bx - xor dx, dx - int HEX (10) + mov ax, offset _app_path + push ax - ret + call _strrchr + add sp, 4 + + and ax, ax + jnz .L98 -;****************************************************************************** -; @function _handler_echo -;****************************************************************************** -_handler_echo: +.L99: + call _get_paths + push ax - push dx - push si + push bx + push cx + push di + push es - mov si, bx + mov ax, cs:[_vec_paths] + mov es, ax + mov cx, cs:[_vec_paths + 4] + + xor di, di -_handler_echo.check: +.L96: - cmp word ptr cs:[_cbreak], 1 - je _handler_echo.done + and cx, cx + jz .L97 - lodsb + mov ax, offset _app_path + push ax - and al, al - jz _handler_echo.newline + mov ax, es:[di] + push ax - mov ah, HEX (02) - mov dl, al - int HEX (21) + cmp word ptr cs:[_in_batch], 1 + jne .L105 - jmp _handler_echo.check + call _concat_read + jnc .L100 + add sp, 4 + + add di, 2 + dec cx + + jmp .L96 -_handler_echo.newline: +.L105: - mov ah, HEX (02) - mov dl, HEX (0D) - int HEX (21) + call _concat_exec + jnc .L100 + add sp, 4 + + add di, 2 + dec cx + + jmp .L96 + +.L100: + + add sp, 4 - mov ah, HEX (02) - mov dl, HEX (0A) - int HEX (21) + pop es + pop di + pop cx + pop bx + pop ax + + jmp .L101 -_handler_echo.done: +.L97: - pop si - pop dx + pop es + pop di + pop cx + pop bx pop ax - ret -;****************************************************************************** -; @function _handler_help -;****************************************************************************** -_handler_help: +.L98: + mov bx, offset _err_invalid + call _writestr + + cmp word ptr cs:[_need_ext], 1 + jb .L34 + + mov ax, '.' push ax + + mov bx, offset _app_path push bx - push ds - mov ax, cs - mov ds, ax + call _strrchr + add sp, 4 - mov bx, offset _handler_help.msg + mov bx, ax + mov byte ptr [bx], 0 + +.L34: + + mov bx, offset _app_path call _writestr + call _crlf -_handler_help.done: +.L101: pop ds + pop es + pop di + pop si + pop dx + pop cx pop bx pop ax + pop bp ret -_handler_help.msg: - - db "CD Change the current directory to the specified path.", HEX (0D), HEX (0A) - db "CLS Clears the screen.", HEX (0D), HEX (0A) - db "DATE Displays the system date.", HEX (0D), HEX (0A) - db "DEL Delete the specified files.", HEX (0D), HEX (0A) - db "DIR Displays a list of files and subdirectories in a directory.", HEX (0D), HEX (0A) - db "ECHO Specifies the text to display to the screen.", HEX (0D), HEX (0A) - db "EXIT Exit the current shell if it's not the last instance.", HEX (0D), HEX (0A) - 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) - - db HEX (00) - -;****************************************************************************** -; @function _handler_reboot -;****************************************************************************** -_handler_reboot: - - ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; - ;; Disable interrupts. - ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; - cli - - ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; - ;; Stop floppy motor. - ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; - mov dx, HEX (03F2) - xor al, al - out dx, al - - ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; - ;; Reset console. - ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; - mov ax, HEX (0003) - int HEX (10) - - ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; - ;; Cold reboot. - ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; - xor ax, ax - mov es, ax - - mov bx, HEX (0472) - mov word ptr es:[bx], 0 - - jmp HEX (F000) : HEX (FFF0) - ;****************************************************************************** ; @function _prompt ;****************************************************************************** @@ -2347,6 +2512,201 @@ _prompt: pop ax ret +;****************************************************************************** +; @function _read_batch +;****************************************************************************** +global _read_batch +_read_batch: + + push bp + + mov bp, sp + sub sp, 6 + + push ax + push bx + push cx + push dx + push si + push di + push es + push ds + + mov word ptr [bp - 6], 0 + mov word ptr [bp - 4], 0 + mov word ptr [bp - 2], 0 + +_read_batch.open: + + mov ax, offset _batch_flags + push ax + + mov ax, word ptr [bp + 4] + push ax + + call _fopen + add sp, 4 + + and ax, ax + jz _read_batch.err + + mov word ptr [bp - 4], ax + +_read_batch.parse: + + call _load_line_create_internal_data + + and ax, ax + jz _read_batch.close + + mov word ptr [bp - 2], ax + +_read_batch.read_line: + + mov ax, word ptr [bp - 2] + push ax + + mov ax, word ptr [bp - 4] + push ax + + xor ax, ax + push ax + push ax + + lea ax, word ptr [bp - 6] + push ax + + call _load_line + add sp, 10 + + and ax, ax + jnz _read_batch.close + + push ax + push bx + push ds + + mov ax, word ptr [bp - 6] + mov ds, ax + xor bx, bx + +_read_batch.skip: + + cmp byte ptr [bx], ' ' + jne _read_batch.check + + inc bx + jmp _read_batch.skip + +_read_batch.check: + + cmp byte ptr [bx], HEX (0A) + je _read_batch.next + + mov ax, ds + mov es, ax + + mov di, bx + push di + + call _strlen + add sp, 2 + + add di, ax + dec di + + xor al, al + stosb + + cmp word ptr [bp + 6], 0 + je _read_batch.process + + cmp byte ptr [bx], '@' + jne _read_batch.echo + + inc bx + +_read_batch.skip2: + + cmp byte ptr [bx], ' ' + jne _read_batch.process + + inc bx + jmp _read_batch.skip2 + +_read_batch.echo: + + call _writestr + call _crlf + +_read_batch.process: + + push bx + + call _process_line + add sp, 2 + +_read_batch.next: + + pop ds + pop bx + pop ax + + jmp _read_batch.read_line + +_read_batch.close: + + push word ptr [bp - 4] + + call _fclose + add sp, 2 + +_read_batch.free: + + mov ax, word ptr [bp - 2] + + and ax, ax + jz _read_batch.done + + push ax + + call _load_line_destroy_internal_data + add sp, 2 + +_read_batch.done: + + pop ds + pop es + pop di + pop si + pop dx + pop cx + pop bx + pop ax + + add sp, 6 + clc + + pop bp + ret + +_read_batch.err: + + pop ds + pop es + pop di + pop si + pop dx + pop cx + pop bx + pop ax + + add sp, 6 + stc + + pop bp + ret + ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Includes. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; @@ -2371,20 +2731,28 @@ _scratch: db 257 dup (0) _app_path: db 256 dup (0) _param_blk: db 16 dup (0) -_full_path: db 256 dup (0) - ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Error messages. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +_err_segmentation: db "Segmentation fault", HEX (0D), HEX (0A), HEX (00) _err_invalid: db "Bad command or file name - ", HEX (00) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Data area. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; _formatted_command: db 256 dup (0) -_fn_wild: db "*.*", HEX (00) +_full_path: db 256 dup (0) _temp: db 257 dup (0) +_autoexec: db "AUTOEXEC.BAT", HEX (00) +_batch_flags: db "r", HEX (00) + +_in_batch: dw HEX (0000) +_ext_batch: db ".bat", HEX (00) + +_ll_scratch: dw HEX (0000) +_fn_wild: db "*.*", HEX (00) + _dta_addr: dw HEX (0000) _insert: dw HEX (0000) diff --git a/src/apps/pcomm/xrealloc.asm b/src/apps/pcomm/xrealloc.asm new file mode 100644 index 0000000..e5692c4 --- /dev/null +++ b/src/apps/pcomm/xrealloc.asm @@ -0,0 +1,45 @@ +;****************************************************************************** +; @file xrealloc.asm +;****************************************************************************** +%ifndef HEX +% define HEX(y) 0x##y +%endif + +;****************************************************************************** +; @function _xrealloc +;****************************************************************************** +global _xrealloc +_xrealloc: + + push bp + mov bp, sp + + push word ptr [bp + 8] + push word ptr [bp + 6] + push word ptr [bp + 4] + + call _realloc + add sp, 6 + + and ax, ax + jnz _xrealloc.done + +_xrealloc.error: + + pop bp + + mov ax, cs + mov ds, ax + + mov bx, offset _err_realloc + call _writestr + + mov ax, HEX (4C01) + int HEX (21) + +_xrealloc.done: + + pop bp + ret + +_err_realloc: db "Memory full (realloc)", HEX (0D), HEX (0A), HEX (00) diff --git a/src/boot/freeldr/core/ll.asm b/src/boot/freeldr/core/ll.asm index 9c0c4cb..fc46e45 100644 --- a/src/boot/freeldr/core/ll.asm +++ b/src/boot/freeldr/core/ll.asm @@ -610,7 +610,6 @@ _load_line: global _load_line_create_internal_data _load_line_create_internal_data: - push ax push dx .L19: @@ -627,7 +626,6 @@ _load_line_create_internal_data: .L20: pop dx - pop ax ret ;****************************************************************************** diff --git a/src/kernel/disk.asm b/src/kernel/disk.asm index 7c42816..8529e35 100644 --- a/src/kernel/disk.asm +++ b/src/kernel/disk.asm @@ -954,7 +954,8 @@ _read_sectors.success: ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Loop until cx is zero. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; - loop _read_sectors.next + dec cx + jnz _read_sectors.next _read_sectors.done: diff --git a/src/kernel/file.asm b/src/kernel/file.asm index 091aef0..8cdd429 100644 --- a/src/kernel/file.asm +++ b/src/kernel/file.asm @@ -75,7 +75,7 @@ _read_cluster.check: mov dx, cx call cs:[_convert_cluster] - jnc _read_cluster.read + jc _read_cluster.done _read_cluster.read: @@ -401,10 +401,9 @@ _close_file.ok: xor di, di ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; - ;; Our file handle info contains a pointer to a buffer at offset - ;; 52 so we need to free it. + ;; Our file handle info contains a pointer to a buffer so free it. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; - mov ax, es:[di + 68] + mov ax, es:[di + 70] push es mov es, ax @@ -764,15 +763,10 @@ _open_file.got_handle: ;; Allocate memory for a buffer that will be used to keep track of ;; the current data read. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; - push si - xor si, si - - mov ax, es:[si + 50] + mov ax, cs:[_clustsize] xor dx, dx call _kmalloc - pop si - ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Store the value. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; diff --git a/src/kernel/int21.asm b/src/kernel/int21.asm index 4a9903d..aaec6ce 100644 --- a/src/kernel/int21.asm +++ b/src/kernel/int21.asm @@ -3221,6 +3221,10 @@ _int21_3F.copy: lodsw mov cs:[_curr_cluster + 2], ax + push di + push es + push ax + mov di, offset _fat_bpb mov ax, cs mov es, ax @@ -3228,6 +3232,10 @@ _int21_3F.copy: mov cx, 25 rep movsb + pop ax + pop es + pop di + lodsb mov cs:[_drive_no], al diff --git a/src/kernel/kernel.asm b/src/kernel/kernel.asm index 8f21869..5f452d4 100644 --- a/src/kernel/kernel.asm +++ b/src/kernel/kernel.asm @@ -54,6 +54,18 @@ _all_read: ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; mov [_drive_no], dl + ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + ;; Calculate the initial cluster size. + ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + xor ch, ch + mov cl, byte ptr [bp - 62] + + mov ax, word ptr [bp - 64] + xor dx, dx + + mul cx + mov cs:[_clustsize], ax + ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Initialize the stack segment with the value stored in bx. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; diff --git a/src/kernel/krealloc.asm b/src/kernel/krealloc.asm index 82d3ec0..0a08af2 100644 --- a/src/kernel/krealloc.asm +++ b/src/kernel/krealloc.asm @@ -121,10 +121,10 @@ _krealloc.alloc: mov cx, word ptr es:[di + 3] mov es, ax - cmp cx, bx + cmp cx, si jb _krealloc.copy - mov cx, bx + mov cx, si _krealloc.copy: diff --git a/src/kernel/mem.asm b/src/kernel/mem.asm index 2bd24a0..9798ad1 100644 --- a/src/kernel/mem.asm +++ b/src/kernel/mem.asm @@ -5,12 +5,22 @@ % define HEX(y) 0x##y %endif +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; Include our fat.inc. +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +%include "fat.inc" + ;****************************************************************************** ; @function _alloc_mem ;****************************************************************************** global _alloc_mem _alloc_mem: + push bp + + mov bp, sp + sub sp, 20 + push cx push dx push si @@ -21,13 +31,12 @@ _alloc_mem: mov es, ax push es - mov ax, bx - xor di, di _alloc_mem.search: mov cx, es + xor di, di cmp cx, cs:[_free_seg] jb _alloc_mem.error @@ -101,9 +110,120 @@ _alloc_mem.retry: _alloc_mem.success: - xor di, di pop es + xor si, si + mov di, 1 + + mov ax, es + xor dx, dx + + mov cx, 16 + mul cx + + mov cx, 1 + push cx + + push di + push si + push dx + push ax + + call _udivmodsi4 + add sp, 10 + + mov word ptr [bp - 4], ax + + xor si, si + mov di, 1 + + mov ax, es + inc ax + xor dx, dx + + mov cx, 16 + mul cx + + add ax, cs:[_clustsize] + adc dx, 0 + + mov cx, 1 + push cx + + push di + push si + push dx + push ax + + call _udivmodsi4 + add sp, 10 + + cmp word ptr [bp - 4], ax + je _alloc_mem.ok + + mov ax, es + xor dx, dx + + mov cx, 16 + mul cx + + mov di, ax + mov si, dx + + xor ax, ax + mov dx, 1 + + mov cx, di + add cx, ax + + mov word ptr [bp - 12], cx + + mov cx, si + adc cx, dx + + mov word ptr [bp - 10], cx + + mov ax, word ptr [bp - 12] + add ax, -1 + + mov word ptr [bp - 16], ax + + mov ax, word ptr [bp - 10] + adc ax, -1 + + mov word ptr [bp - 14], ax + + ;xor ax, ax + ;push ax + + mov ax, 1 + push ax + push ax + + xor ax, ax + push ax + + push word ptr [bp - 14] + push word ptr [bp - 16] + + call _udivmodsi4 + add sp, 10 + + xchg ax, dx + + mov cx, 16 + div cx + + mov es, ax + push es + + mov ax, bx + jmp _alloc_mem.search + +_alloc_mem.ok: + + xor di, di + mov byte ptr es:[di], 'M' mov byte ptr es:[di + 1], 'C' mov byte ptr es:[di + 2], 'B' @@ -115,7 +235,6 @@ _alloc_mem.success: mov ax, es inc ax - clc jmp short _alloc_mem.done _alloc_mem.error: @@ -124,8 +243,18 @@ _alloc_mem.error: pop ax sub bx, ax - mov ax, 8 + pop es + pop di + pop si + pop dx + pop cx + + add sp, 20 stc + pop bp + + mov ax, 8 + ret _alloc_mem.done: @@ -134,6 +263,11 @@ _alloc_mem.done: pop si pop dx pop cx + + add sp, 20 + clc + pop bp + ret ;****************************************************************************** @@ -317,20 +451,6 @@ _resize_mem.ins: _resize_mem.got_seg: - pop es - - mov ax, es - sub bx, ax - - push es - - mov di, es - dec di - mov es, di - - xor di, di - mov word ptr es:[di + 3], bx - mov ax, 8 stc diff --git a/src/lib/crt/stdio/flags.asm b/src/lib/crt/stdio/flags.asm index 64efd06..c24be27 100644 --- a/src/lib/crt/stdio/flags.asm +++ b/src/lib/crt/stdio/flags.asm @@ -87,11 +87,11 @@ _sflags.loop: lodsb - or al, al + and al, al jz _sflags.done cmp al, '+' - jne _sflags.next + jne _sflags.loop mov di, __SRD | __SWR not di @@ -104,9 +104,7 @@ _sflags.loop: and cx, di or cx, O_RDWR - -_sflags.next: - + jmp short _sflags.loop _sflags.done: diff --git a/src/lib/crt/udivmodsi4.asm b/src/lib/crt/udivmodsi4.asm index 7a99176..e8c8d1e 100644 --- a/src/lib/crt/udivmodsi4.asm +++ b/src/lib/crt/udivmodsi4.asm @@ -11,12 +11,14 @@ global _udivmodsi4 _udivmodsi4: - push si push bp mov bp, sp sub sp, 12 + push bx + push si + mov word ptr [bp - 4], 1 mov word ptr [bp - 2], 0 mov word ptr [bp - 8], 0 @@ -147,7 +149,10 @@ _udivmodsi4: .L13: + pop si + pop bx + add sp, 12 pop bp - pop si + ret