--- /dev/null
+;******************************************************************************
+; @file list.asm
+;******************************************************************************
+%ifndef HEX
+% define HEX(y) 0x##y
+%endif
+
+;******************************************************************************
+; @function _list_push
+;******************************************************************************
+global _list_push
+_list_push:
+
+ push bp
+
+ mov bp, sp
+ sub sp, 2
+
+ push ax
+ push bx
+ push cx
+ push dx
+ push si
+ push di
+ push es
+ push ds
+
+ mov ax, 4
+ xor dx, dx
+
+ push ax
+ push dx
+
+ call _xmalloc
+ add sp, 4
+
+ mov word ptr [bp - 2], ax
+ mov es, ax
+
+ xor bx, bx
+
+ mov ax, word ptr [bp + 6]
+ mov es:[bx], ax
+
+ mov bx, word ptr [bp + 4]
+ mov ax, [bx]
+
+ and ax, ax
+ jnz _list_push.got_head
+
+ mov ax, word ptr [bp - 2]
+ ;mov es, ax
+ ;
+ ;xor bx, bx
+ ;mov es:[bx + 2], ax
+
+ mov di, word ptr [bp + 4]
+ mov [di], ax
+
+ jmp _list_push.done
+
+_list_push.got_head:
+
+ mov dx, ax
+ xor bx, bx
+
+_list_push.search:
+
+ mov es, ax
+ mov ax, es:[bx + 2]
+
+ and ax, ax
+ jnz _list_push.search
+
+ mov dx, word ptr [bp - 2]
+ mov es:[bx + 2], dx
+
+_list_push.done:
+
+ pop ds
+ pop es
+ pop di
+ pop si
+ pop dx
+ pop cx
+ pop bx
+ pop ax
+
+ add sp, 2
+ pop bp
+
+ ret
global _main
_main:
+ push bp
+
+ mov bp, sp
+ sub sp, 4
+
+ mov word ptr [bp - 4], 0
+ mov word ptr [bp - 2], 0
+
mov ax, HEX (2523)
mov dx, offset _cbreak_handler
int HEX (21)
.L5:
+ push es
+ push di
+ push cx
+
+ mov ax, cs:[_vec_scratch + 0]
+ mov es, ax
+
+ mov cx, cs:[_vec_scratch + 4]
+ xor di, di
+
+.L110:
+
+ and cx, cx
+ jz .L109
+
+ mov ax, es:[di]
+
+ push ds
+ push ax
+
+ mov ax, offset _scratch_list
+ push ax
+
+ call _list_push
+ add sp, 2
+
+ pop ax
+ pop ds
+ add di, 2
+
+ dec cx
+ jnz .L110
+
+.L109:
+
+ mov ax, es
+
+ and ax, ax
+ jz .L117
+
+ push ax
+
+ call _free
+ add sp, 2
+
+.L117:
+
+ mov ax, cs
+ mov es, ax
+
+ mov di, offset _vec_scratch
+ xor al, al
+
+ mov cx, 6
+ rep stosb
+
+ mov ax, [_scratch_list]
+ xor di, di
+
+.L112:
+
+ and ax, ax
+ jz .L111
+
+.L113:
+
+ mov es, ax
+
+ push ds
+ push di
+
+ mov ax, es:[di]
+ mov ds, ax
+
+ xor bx, bx
+
+ cmp byte ptr [bx], '@'
+ jne .L114
+
+ inc bx
+
+.L116:
+
+ cmp byte ptr [bx], ' '
+ jne .L115
+
+ inc bx
+ jmp .L116
+
+.L114:
+
+ cmp word ptr cs:[_echo_line], 0
+ je .L115
+
+ call _writestr
+ call _crlf
+
+.L115:
+
+ push bx
+
+ call _process_line
+ add sp, 2
+
+ push ds
+
+ call _free
+ add sp, 2
+
+ pop di
+ pop ds
+
+ mov ax, word ptr es:[di + 2]
+ push es
+
+ call _free
+ add sp, 2
+
+ mov [_scratch_list], ax
+ mov word ptr [bp - 2], ax
+
+ cmp word ptr cs:[_vec_scratch + 4], 0
+ je .L112
+
+ pop cx
+ pop di
+ pop es
+
+ jmp .L5
+
+.L111:
+
+ mov word ptr [_scratch_list], 0
+
+ pop cx
+ pop di
+ pop es
+
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Free the current command history if there is one.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
push si
push di
push es
+ push ds
mov si, cs:[_vec_env]
mov cx, cs:[_vec_env + 4]
pop di
pop es
- xor ax, ax
- push ax
+ xor si, si
+ push si
- mov ax, offset _temp
- push ax
+ call _strlen
+ add sp, 2
- call _strcpy
- add sp, 4
+ mov cx, ax
+ rep movsb
- mov ax, word ptr [bp + 4]
- push ax
+ inc di
+ pop ds
- mov ax, offset _temp
- push ax
+ mov si, word ptr [bp + 4]
+ push si
+
+ call _strlen
+ add sp, 2
+
+ mov cx, ax
+ rep movsb
+
+ mov ax, cs
+ mov ds, ax
+
+ mov di, offset _temp
+ push di
+
+ call _strlen
+
+ add di, ax
+ inc di
+
+ push di
call _strcmp
add sp, 4
- pop ds
pop es
pop cx
and ax, ax
jz .L93
+ xor ax, ax
+ int 0x19
+
pop ax
pop es
.L90:
+ pop ds
pop es
pop di
pop si
and ax, ax
jz .L89
+ mov si, bx
+ inc si
+
push si
push ds
pop ds
pop si
- jmp .L84
+ jmp .L87
.L89:
mov ax, cs
mov ds, ax
- mov bx, offset _formatted_command
-
call _get_command
jc .L23
push bp
mov bp, sp
- sub sp, 6
+ sub sp, 12
push ax
push bx
push es
push ds
+ mov word ptr [bp - 12], 0
+ mov word ptr [bp - 10], 0
+ mov word ptr [bp - 8], 0
mov word ptr [bp - 6], 0
mov word ptr [bp - 4], 0
mov word ptr [bp - 2], 0
push ax
push ax
- lea ax, word ptr [bp - 6]
+ mov ax, offset _ll_scratch
push ax
call _load_line
push bx
push ds
- mov ax, word ptr [bp - 6]
+ mov ax, [_ll_scratch]
mov ds, ax
xor bx, bx
call _strlen
add sp, 2
+ mov cx, ax
+ inc cx
+
add di, ax
dec di
xor al, al
stosb
- cmp word ptr [bp + 6], 0
- je _read_batch.process
+ mov ax, cx
+ xor dx, dx
- cmp byte ptr [bx], '@'
- jne _read_batch.echo
+ push ax
+ push dx
- inc bx
+ call _xmalloc
+ add sp, 4
-_read_batch.skip2:
-
- cmp byte ptr [bx], ' '
- jne _read_batch.process
+ mov es, ax
- inc bx
- jmp _read_batch.skip2
-
-_read_batch.echo:
-
- call _writestr
- call _crlf
-
-_read_batch.process:
-
- push bx
+ push ds
+ push di
+ push es
- call _process_line
- add sp, 2
+ mov ax, cs
+ mov ds, ax
+
+ mov ax, offset _vec_scratch
+ push ax
+
+ call _vec_push
+ add sp, 4
+
+ pop di
+ pop ds
+
+ xor ax, ax
+ push ax
+ push ax
+
+ call _strcpy
+ add sp, 4
_read_batch.next:
pop bx
pop ax
- add sp, 6
+ add sp, 12
clc
pop bp
pop bx
pop ax
- add sp, 6
+ add sp, 12
stc
pop bp
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Error messages.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-_err_segmentation: db "Segmentation fault", HEX (0D), HEX (0A), HEX (00)
+_err_nested: db "Too many nested loops", HEX (00)
_err_invalid: db "Bad command or file name - ", HEX (00)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
_autoexec: db "AUTOEXEC.BAT", HEX (00)
_batch_flags: db "r", HEX (00)
+_echo_line: dw HEX (0001)
_in_batch: dw HEX (0000)
_ll_scratch: dw HEX (0000)
global _need_ext
_need_ext: dw HEX (0000)
+global _scratch_list
+_scratch_list: dw HEX (0000)
+
global _vec_history
_vec_history: db 6 dup (0)
global _vec_paths
_vec_paths: db 6 dup (0)
+global _vec_scratch
+_vec_scratch: db 6 dup (0)
+
global _curr_row
_curr_row: db HEX (00)