summaryrefslogtreecommitdiff
path: root/terminal.asm
diff options
context:
space:
mode:
authorJoseph Hunkeler <jhunkeler@gmail.com>2017-12-02 16:58:34 -0500
committerJoseph Hunkeler <jhunkeler@gmail.com>2017-12-02 16:58:34 -0500
commit273c0801dee82f0e5e2d89edd743b9d62e026437 (patch)
tree5170da320b0704368db9a9a0977fef11c9783a1b /terminal.asm
parentc9d2819d72bece6470bb3a7cf0edf669699a7ab4 (diff)
downloadminos-273c0801dee82f0e5e2d89edd743b9d62e026437.tar.gz
Improve clarity; Trap long input
Diffstat (limited to 'terminal.asm')
-rw-r--r--terminal.asm94
1 files changed, 53 insertions, 41 deletions
diff --git a/terminal.asm b/terminal.asm
index b3beb7c..13ed786 100644
--- a/terminal.asm
+++ b/terminal.asm
@@ -1,64 +1,76 @@
%ifndef _TERMINAL_ASM
%define _TERMINAL_ASM
-MAXBUF equ 254
+T_BUFSZ equ 256 ; maximum length of terminal input buffer
terminal:
push bp
mov bp, sp
- ;sub sp, MAXBUF ; allocate large string buffer
-
+
.clear_buffer:
- mov cx, MAXBUF
- mov bx, t_buffer
- mov di, bx
+ mov cx, T_BUFSZ ; counter is length of buffer
+ mov bx, t_buffer ; get address of buffer
+ mov di, bx ; destination is buffer
.cl:
- mov [di], byte 0
- inc di
- dec cx
- jne .cl
- mov di, bx
-
- .do_prompt:
- mov cx, 0
+ mov [di], byte 0 ; zero out
+ inc di ; increment buffer address
+ dec cx ; decrement counter
+ jne .cl ; repeat until counter is 0
+
+ mov di, bx ; reset destination to original address
+
+ .do_prompt:
+ mov cx, 0 ; reset counter
+ ; this tracks keyboard presses
mov al, CR
- call putc
+ call putc ; write carriage return to console
+
+ push t_msg_prompt ; address of prompt string
+ push t_msg_prompt_fmt ; address of prompt format string
+ call printf ; print prompt to console
+ add sp, 4 ; clean up stack
- push t_msg_prompt
- push t_msg_prompt_fmt
- call printf
- add sp, 4
-
- mov di, t_buffer
+ mov di, t_buffer ; input destination is buffer
.read_command:
- call kbd_read
+ call kbd_read ; get input from user
.update_buffer:
cmp al, CR
- je .dump_buffer
- stosb
- inc cx
+ je .flush_buffer ; if carriage return, flush buffer
+
+ cmp cx, T_BUFSZ
+ jge .read_command ; trap lines to long to fit in memory
+ ; we cannot continue until user hits return
- jmp .output
+ stosb ; write input character to buffer
+ inc cx ; increment character count
- .dump_buffer:
- cmp [di-1], byte 0
- je .do_prompt
+ jmp .output ; output character (default)
+
+ .flush_buffer:
+ cmp [di-1], byte 0 ; stosb above increments di.
+ ; (di - 1) is the previous input
+ je .do_prompt ; if no input (null), start over
mov al, CR
- call putc
-
- push t_buffer ; push onto stack
- push t_buffer_fmt
- call printf ; write out string
- add sp, 4
-
- jmp .clear_buffer
-
+ call putc ; print carriage return
+
+ ; ---- TEMPORARY ---
+ ; A jump to a command parser occur here eventually
+ ; TODO: write string tokenizer
+
+ push t_buffer ; push buffer string address
+ push t_buffer_fmt ; push buffer format string address
+ call printf ; write input to console
+ add sp, 4 ; clean up stack
+ ; --- END TEMPORARY ---
+
+ jmp .clear_buffer ; zero out buffer / start over
+
.output:
call putc
- jmp .read_command
+ jmp .read_command ; print input to screen as we type
- jmp .do_prompt
+ jmp .do_prompt ; start over
mov sp, bp
pop bp
@@ -68,6 +80,6 @@ terminal:
t_msg_prompt_fmt: db '%s', 0
t_msg_prompt: db '$ ', 0
t_buffer_fmt: db '%s', 0
-t_buffer: times MAXBUF db 0
+t_buffer: times T_BUFSZ db 0
%endif