mirror of
https://gitlab.os-k.eu/os-k-team/kvisc.git
synced 2023-08-25 14:05:46 +02:00
cmd
This commit is contained in:
parent
c60dfb47fc
commit
8dfcae8820
@ -11,6 +11,7 @@ start:
|
|||||||
xor rbp, rbp
|
xor rbp, rbp
|
||||||
|
|
||||||
cls
|
cls
|
||||||
|
cld
|
||||||
call main
|
call main
|
||||||
|
|
||||||
mov rax, Sys.HLT
|
mov rax, Sys.HLT
|
||||||
|
@ -6,8 +6,8 @@
|
|||||||
;
|
;
|
||||||
; Returns:
|
; Returns:
|
||||||
; 0 if the contents of both strings are equal
|
; 0 if the contents of both strings are equal
|
||||||
; 1 if the first character that does not match has a greater value in str1 than in str2
|
; >0 if the first character that does not match has a greater value in str1 than in str2
|
||||||
; -1 if the first character that does not match has a lower value in str1 than in str2
|
; <0 if the first character that does not match has a lower value in str1 than in str2
|
||||||
;
|
;
|
||||||
strcmp:
|
strcmp:
|
||||||
mov ax2, STRLEN_MAX
|
mov ax2, STRLEN_MAX
|
||||||
@ -21,11 +21,10 @@ strncmp:
|
|||||||
mov.cxz rax, 0
|
mov.cxz rax, 0
|
||||||
ret.cxz
|
ret.cxz
|
||||||
|
|
||||||
cmpzsb.rep.e ax0, ax1
|
cmpzsb.rep.z ax0, ax1
|
||||||
|
|
||||||
mov rax, b[ax0]
|
mov rax, b[ax0-1]
|
||||||
sub rax, b[ax1]
|
sub rax, b[ax1-1]
|
||||||
sgn rax, rax
|
|
||||||
|
|
||||||
ret
|
ret
|
||||||
|
|
||||||
|
@ -33,6 +33,24 @@ main:
|
|||||||
scan rax
|
scan rax
|
||||||
b.z rax, 0, .input_loop
|
b.z rax, 0, .input_loop
|
||||||
|
|
||||||
|
; 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:
|
||||||
cmp b[stdin_echoing], 1
|
cmp b[stdin_echoing], 1
|
||||||
prn.z rax
|
prn.z rax
|
||||||
b.z rax, 10, .extract_argv0
|
b.z rax, 10, .extract_argv0
|
||||||
@ -51,6 +69,10 @@ main:
|
|||||||
|
|
||||||
.extract_argv0:
|
.extract_argv0:
|
||||||
|
|
||||||
|
; did we read anything at all?
|
||||||
|
; if not, just go back to waiting input
|
||||||
|
b.z rcx, 0, .print_prompt
|
||||||
|
|
||||||
; find first whitespace or null-terminator
|
; find first whitespace or null-terminator
|
||||||
mov rcx, argbuf.size
|
mov rcx, argbuf.size
|
||||||
mov rdx, argbuf
|
mov rdx, argbuf
|
||||||
@ -59,18 +81,21 @@ main:
|
|||||||
; argv1 exists? if so, save its position
|
; argv1 exists? if so, save its position
|
||||||
; (to do)
|
; (to do)
|
||||||
|
|
||||||
|
; empty argv0
|
||||||
|
mov rcx, argbuf.size
|
||||||
|
mov rax, argv0
|
||||||
|
stosb.rep rax, 0
|
||||||
|
|
||||||
; extract argv0
|
; extract argv0
|
||||||
sub rcx, argbuf.size, rcx
|
sub rcx, rdx, argbuf
|
||||||
mov rdx, argbuf
|
mov rdx, argbuf
|
||||||
mov rax, argv0
|
mov rax, argv0
|
||||||
movsb.rep rax, rdx
|
movsb.rep rax, rdx
|
||||||
|
|
||||||
; null-terminate argv0
|
|
||||||
mov b[rax], 0
|
|
||||||
|
|
||||||
.detect_builtin:
|
.detect_builtin:
|
||||||
|
|
||||||
.builtin_dir = "dir"
|
.builtin_dir = "dir"
|
||||||
|
|
||||||
mov ax0, argv0
|
mov ax0, argv0
|
||||||
mov ax1, .builtin_dir
|
mov ax1, .builtin_dir
|
||||||
call strcmp
|
call strcmp
|
||||||
@ -79,8 +104,21 @@ main:
|
|||||||
; fallthrough
|
; fallthrough
|
||||||
|
|
||||||
.exec_prog:
|
.exec_prog:
|
||||||
|
|
||||||
|
; fallthrough
|
||||||
|
|
||||||
|
.not_found:
|
||||||
|
mov rcx, STRLEN_MAX
|
||||||
|
mov rdx, argv0
|
||||||
|
prns.rep.nz rdx
|
||||||
|
|
||||||
|
mov rdx, .errmsg
|
||||||
|
prns.rep.nz rdx
|
||||||
|
|
||||||
jmp .print_prompt
|
jmp .print_prompt
|
||||||
|
|
||||||
|
.errmsg = " : command not found\n"
|
||||||
|
|
||||||
;
|
;
|
||||||
; call builtins
|
; call builtins
|
||||||
;
|
;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user