diff --git a/ka/command.k b/ka/command.k index 0e864ca..7402476 100644 --- a/ka/command.k +++ b/ka/command.k @@ -11,6 +11,7 @@ start: xor rbp, rbp cls + cld call main mov rax, Sys.HLT diff --git a/ka/crt/str/strcmp.k b/ka/crt/str/strcmp.k index f33de41..1ba9b3e 100644 --- a/ka/crt/str/strcmp.k +++ b/ka/crt/str/strcmp.k @@ -6,8 +6,8 @@ ; ; Returns: ; 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 -; -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 greater 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: mov ax2, STRLEN_MAX @@ -21,11 +21,10 @@ strncmp: mov.cxz rax, 0 ret.cxz - cmpzsb.rep.e ax0, ax1 + cmpzsb.rep.z ax0, ax1 - mov rax, b[ax0] - sub rax, b[ax1] - sgn rax, rax + mov rax, b[ax0-1] + sub rax, b[ax1-1] ret diff --git a/ka/usr/cmd/main.k b/ka/usr/cmd/main.k index 010985b..965b39f 100644 --- a/ka/usr/cmd/main.k +++ b/ka/usr/cmd/main.k @@ -33,6 +33,24 @@ main: scan rax 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 prn.z rax b.z rax, 10, .extract_argv0 @@ -51,6 +69,10 @@ main: .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 mov rcx, argbuf.size mov rdx, argbuf @@ -59,18 +81,21 @@ main: ; argv1 exists? if so, save its position ; (to do) + ; empty argv0 + mov rcx, argbuf.size + mov rax, argv0 + stosb.rep rax, 0 + ; extract argv0 - sub rcx, argbuf.size, rcx + sub rcx, rdx, argbuf mov rdx, argbuf mov rax, argv0 movsb.rep rax, rdx - ; null-terminate argv0 - mov b[rax], 0 - .detect_builtin: .builtin_dir = "dir" + mov ax0, argv0 mov ax1, .builtin_dir call strcmp @@ -79,8 +104,21 @@ main: ; fallthrough .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 +.errmsg = " : command not found\n" + ; ; call builtins ;