2019-07-10 17:17:45 +02:00
|
|
|
; The OS/K Team licenses this file to you under the MIT license.
|
|
|
|
; See the LICENSE file in the project root for more information.
|
|
|
|
|
2019-07-10 20:11:35 +02:00
|
|
|
argbuf.size := 256
|
|
|
|
argbuf = [argbuf.size]
|
|
|
|
argv0 = [argbuf.size]
|
|
|
|
argv1pos = 0
|
|
|
|
|
|
|
|
stdin_echoing = 1
|
|
|
|
|
|
|
|
ps1 = "C:\\> "
|
|
|
|
|
2019-07-10 17:17:45 +02:00
|
|
|
main:
|
|
|
|
|
2019-07-10 20:11:35 +02:00
|
|
|
.print_prompt:
|
|
|
|
mov rcx, STRLEN_MAX
|
|
|
|
mov rdx, ps1
|
|
|
|
prns.rep.nz rdx
|
|
|
|
|
|
|
|
; empty argbuf
|
|
|
|
mov rcx, argbuf.size
|
|
|
|
mov rdx, argbuf
|
|
|
|
stosb.rep rdx, 0
|
|
|
|
|
|
|
|
; iterator through argbuf
|
|
|
|
xor rcx, rcx
|
|
|
|
|
|
|
|
.input_loop:
|
|
|
|
pause
|
|
|
|
pause
|
|
|
|
|
|
|
|
; Fill .buf with user input
|
|
|
|
scan rax
|
|
|
|
b.z rax, 0, .input_loop
|
|
|
|
|
2019-07-10 21:05:26 +02:00
|
|
|
; backspace character?
|
|
|
|
b.nz rax, 8, .handle_input
|
|
|
|
|
|
|
|
; anything to delete?
|
|
|
|
b.z rcx, 0, .input_loop
|
|
|
|
|
|
|
|
; delete it
|
|
|
|
dec rcx
|
|
|
|
add rdx, rcx, argbuf
|
|
|
|
mov b[rdx], 0
|
|
|
|
|
|
|
|
; update screen
|
|
|
|
cmp b[stdin_echoing], 1
|
|
|
|
prn.z 8
|
|
|
|
|
|
|
|
jmp .input_loop
|
|
|
|
|
|
|
|
.handle_input:
|
2019-07-10 20:11:35 +02:00
|
|
|
cmp b[stdin_echoing], 1
|
|
|
|
prn.z rax
|
|
|
|
b.z rax, 10, .extract_argv0
|
|
|
|
|
|
|
|
; when max line length is reached,
|
|
|
|
; force a newline
|
|
|
|
b.z rcx, argbuf.size, .extract_argv0
|
|
|
|
|
|
|
|
; add character to buffer and increase iterator (rcx)
|
|
|
|
add rdx, rcx, argbuf
|
|
|
|
mov b[rdx], rax
|
|
|
|
inc rcx
|
|
|
|
|
|
|
|
; another one
|
|
|
|
jmp .input_loop
|
|
|
|
|
|
|
|
.extract_argv0:
|
|
|
|
|
2019-07-10 21:05:26 +02:00
|
|
|
; did we read anything at all?
|
|
|
|
; if not, just go back to waiting input
|
|
|
|
b.z rcx, 0, .print_prompt
|
|
|
|
|
2019-07-10 20:11:35 +02:00
|
|
|
; find first whitespace or null-terminator
|
|
|
|
mov rcx, argbuf.size
|
|
|
|
mov rdx, argbuf
|
|
|
|
scasb.rep.nz rdx, ' '
|
|
|
|
|
|
|
|
; argv1 exists? if so, save its position
|
|
|
|
; (to do)
|
|
|
|
|
2019-07-10 21:05:26 +02:00
|
|
|
; empty argv0
|
|
|
|
mov rcx, argbuf.size
|
|
|
|
mov rax, argv0
|
|
|
|
stosb.rep rax, 0
|
|
|
|
|
2019-07-10 20:11:35 +02:00
|
|
|
; extract argv0
|
2019-07-10 21:05:26 +02:00
|
|
|
sub rcx, rdx, argbuf
|
2019-07-10 20:11:35 +02:00
|
|
|
mov rdx, argbuf
|
|
|
|
mov rax, argv0
|
|
|
|
movsb.rep rax, rdx
|
|
|
|
|
|
|
|
.detect_builtin:
|
|
|
|
|
|
|
|
.builtin_dir = "dir"
|
2019-07-10 21:05:26 +02:00
|
|
|
|
2019-07-10 20:11:35 +02:00
|
|
|
mov ax0, argv0
|
|
|
|
mov ax1, .builtin_dir
|
|
|
|
call strcmp
|
|
|
|
b.z rax, 0, .handle_DIR
|
|
|
|
|
|
|
|
; fallthrough
|
|
|
|
|
|
|
|
.exec_prog:
|
2019-07-10 21:05:26 +02:00
|
|
|
|
|
|
|
; fallthrough
|
|
|
|
|
|
|
|
.not_found:
|
|
|
|
mov rcx, STRLEN_MAX
|
|
|
|
mov rdx, argv0
|
|
|
|
prns.rep.nz rdx
|
|
|
|
|
|
|
|
mov rdx, .errmsg
|
|
|
|
prns.rep.nz rdx
|
|
|
|
|
2019-07-10 20:11:35 +02:00
|
|
|
jmp .print_prompt
|
|
|
|
|
2019-07-10 21:05:26 +02:00
|
|
|
.errmsg = " : command not found\n"
|
|
|
|
|
2019-07-10 20:11:35 +02:00
|
|
|
;
|
|
|
|
; call builtins
|
|
|
|
;
|
|
|
|
.handle_DIR:
|
|
|
|
call builtins.dir
|
|
|
|
jmp .print_prompt
|
2019-07-10 17:17:45 +02:00
|
|
|
|