summaryrefslogtreecommitdiff
path: root/terminal.asm
blob: b3beb7cca68a4f72ea51547b30dfb32c521c3d6a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
%ifndef _TERMINAL_ASM
%define _TERMINAL_ASM

MAXBUF equ 254

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
		.cl:
			mov [di], byte 0
			inc di
			dec cx
			jne .cl
		mov di, bx

	.do_prompt:	
		mov cx, 0
		mov al, CR
		call putc

		push t_msg_prompt
		push t_msg_prompt_fmt
		call printf
		add sp, 4
	
	mov di, t_buffer	
	.read_command:
		call kbd_read
		.update_buffer:
			cmp al, CR
			je .dump_buffer
			stosb
			inc cx

			jmp .output

		.dump_buffer:
			cmp [di-1], byte 0
			je .do_prompt

			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
			
	.output:
		call putc
		jmp .read_command

	jmp .do_prompt

	mov sp, bp
	pop bp
	ret

; data
t_msg_prompt_fmt: db '%s', 0
t_msg_prompt: db '$ ', 0
t_buffer_fmt: db '%s', 0
t_buffer: times MAXBUF db 0

%endif