This commit is contained in:
julianb0 2019-07-10 22:37:59 +02:00
parent 8dfcae8820
commit 42202788da
No known key found for this signature in database
GPG Key ID: DDF8325C95299A62
9 changed files with 159 additions and 9 deletions

View File

@ -22,3 +22,5 @@ start:
include "usr/cmd/main.k"
include "usr/cmd/dir.k"
cmd.versionstr = "COMMAND.COM, version 0.1 (KVISC)\nCopyright (C) 2019, The OS/K Team\nMIT license (permissive), see LICENCE file in source tree"

View File

@ -24,6 +24,13 @@ Sys.FindNext := 0x21
;
Sys.Exit := 0x00
;
; SHUTDOWN syscall
;
; End virtual machine
;
Sys.Shutdown := 0x01
; Halt mode
Sys.HLT := 0x99

View File

@ -16,6 +16,7 @@ trap0_handler:
b.z rax, Sys.HLT, .handle_HLT
b.z rax, Sys.Exit, .handle_Exit
b.z rax, Sys.Shutdown, .handle_Shutdown
b.z rax, Sys.FindNext, .handle_FindNext
b.z rax, Sys.FindFirst, .handle_FindFirst
@ -107,6 +108,9 @@ trap0_handler:
;
; Misc.
;
.handle_Shutdown:
stop
.handle_HLT:
hlt
.HLT.loop:

View File

@ -68,7 +68,6 @@ main:
jmp .input_loop
.extract_argv0:
; did we read anything at all?
; if not, just go back to waiting input
b.z rcx, 0, .print_prompt
@ -79,8 +78,24 @@ main:
scasb.rep.nz rdx, ' '
; argv1 exists? if so, save its position
; (to do)
mov r11, rdx
b.z b[r11], 0, .no_argv1
inc r11
.next_space:
mov rx8, b[r11]
b.z rx8, 0, .no_argv1
; skip spaces
cmp rx8, ' '
inc.z r11
jmp.z .next_space
mov q[argv1pos], r11
; fallthrough
.no_argv1:
; empty argv0
mov rcx, argbuf.size
mov rax, argv0
@ -94,13 +109,48 @@ main:
.detect_builtin:
.builtin_dir = "dir"
.builtin_cls = "cls"
mov ax0, argv0
mov ax1, .builtin_cls
call strcmp
b.z rax, 0, .handle_CLS
.builtin_dir = "dir"
mov ax0, argv0
mov ax1, .builtin_dir
call strcmp
b.z rax, 0, .handle_DIR
.builtin_echo = "echo"
mov ax0, argv0
mov ax1, .builtin_echo
call strcmp
b.z rax, 0, .handle_ECHO
.builtin_exit = "exit"
mov ax0, argv0
mov ax1, .builtin_exit
call strcmp
b.z rax, 0, .handle_EXIT
.builtin_help = "help"
mov ax0, argv0
mov ax1, .builtin_help
call strcmp
b.z rax, 0, .handle_HELP
.builtin_print = "print"
mov ax0, argv0
mov ax1, .builtin_print
call strcmp
b.z rax, 0, .handle_PRINT
.builtin_ver = "ver"
mov ax0, argv0
mov ax1, .builtin_ver
call strcmp
b.z rax, 0, .handle_VER
; fallthrough
.exec_prog:
@ -122,7 +172,68 @@ main:
;
; call builtins
;
.handle_CLS:
prn 0xC15000AF
jmp .print_prompt
.handle_DIR:
call builtins.dir
jmp .print_prompt
.handle_ECHO:
mov rdx, q[argv1pos]
b.z rdx, 0, .echo.end
mov rcx, argbuf.size
prns.rep.nz rdx
.echo.end:
prn 10
jmp .print_prompt
.handle_EXIT:
mov rax, Sys.Shutdown
trap 0
.handle_PRINT:
jmp .print_prompt
.handle_VER:
mov rcx, STRLEN_MAX
mov rdx, cmd.versionstr
prns.rep.nz rdx
prn 10
jmp .print_prompt
.handle_HELP:
mov rcx, STRLEN_MAX
mov rdx, .helpmsg
prns.rep.nz rdx
mov rdx, .helpmsg.cls
prns.rep.nz rdx
mov rdx, .helpmsg.dir
prns.rep.nz rdx
mov rdx, .helpmsg.echo
prns.rep.nz rdx
mov rdx, .helpmsg.exit
prns.rep.nz rdx
mov rdx, .helpmsg.help
prns.rep.nz rdx
mov rdx, .helpmsg.print
prns.rep.nz rdx
mov rdx, .helpmsg.ver
prns.rep.nz rdx
jmp .print_prompt
.helpmsg = "The following commands are built-in:\n"
.helpmsg.cls = " CLS Clear screen\n"
.helpmsg.dir = " DIR Print contents of current directory\n"
.helpmsg.echo = " ECHO Write arguments to standard output\n"
.helpmsg.exit = " EXIT Initiate machine shutdown\n"
.helpmsg.help = " HELP Show these messages\n"
.helpmsg.print = " PRINT Show contents of text file\n"
.helpmsg.ver = " VER Show current COMMAND.COM and DOS kernel versions\n"

View File

@ -26,7 +26,7 @@ IMPL_START_1(dump)
{
(void)v1;
#if 1
#ifndef NDEBUG
if (ctx->dumpsw && !v1)
trace("0x%lX:\t...\n", rpc);

View File

@ -6,10 +6,17 @@
IMPL_START_1(prn)
{
if (p1->mlen > 1) {
trace("prn warning: large access size\n");
// Magic value? :)
if (__builtin_expect(v1 == 0xC15000AF, 0))
console_clear(ctx);
else
{
if (p1->mlen > 1) {
trace("prn warning: large access size\n");
}
console_putc(ctx, (char)v1);
}
console_putc(ctx, (char)v1);
}
IMPL_END

View File

@ -26,6 +26,9 @@ char scr_lines[CONSOLE_HEIGHT][CONSOLE_WIDTH+1] = { 0 };
SDL_Texture *scr_texts[CONSOLE_HEIGHT] = { 0 };
SDL_Rect *scr_rects[CONSOLE_HEIGHT] = { 0 };
int csn_x = 0;
int csn_y = 0;
//----------------------------------------------------------------------------//
void console_init(ctx_t *ctx)
@ -133,6 +136,18 @@ void console_update(ctx_t *ctx)
//----------------------------------------------------------------------------//
void console_clear(ctx_t *ctx)
{
csn_y = CONSOLE_HEIGHT - 1;
for (int i = 0; i < CONSOLE_HEIGHT; i++)
console_putc(ctx, '\n');
csn_x = csn_y = 0;
}
//----------------------------------------------------------------------------//
void console_putat(ctx_t *ctx, char ch, int x, int y)
{
SDL_Surface *surf;
@ -196,8 +211,7 @@ void console_putat(ctx_t *ctx, char ch, int x, int y)
console_render(ctx);
}
int csn_x = 0;
int csn_y = 0;
//----------------------------------------------------------------------------//
void console_putc(ctx_t *ctx, char ch)
{

View File

@ -15,5 +15,7 @@ void console_putat(ctx_t *ctx, char ch, int x, int y);
void console_putc(ctx_t *ctx, char ch);
void console_update(ctx_t *ctx);
void console_clear(ctx_t *ctx);
void console_handle_input(ctx_t *, SDL_Keycode);

View File

@ -81,7 +81,10 @@ int main(int argc, char **argv)
main_ctx.r = arch_r;
main_ctx.i = arch_i;
#ifndef NDEBUG
main_ctx.dumpsw = 1;
#endif
//
// srand