-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathkernel.asm
More file actions
231 lines (157 loc) · 3.88 KB
/
kernel.asm
File metadata and controls
231 lines (157 loc) · 3.88 KB
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
; AtieDOS 2.10 Kernel
; Copyright (c) 2020 AtieSoftware
; See LICENSE in root folder
; KERNEL STARTS HERE
kernel_main:
call os_print_new_line ; calls new line function
mov bx, STARTED_SUCCESS_MSG ; prints "AtieDOS started successfully."
call os_print_string
call os_print_new_line
mov word[PROMPT], word "> " ; moves "> " to prompt
get_input:
call os_print_new_line
mov bx, PROMPT
call os_print_string
call null_input_string
; I am using SI as an index for the DI array of chars.
; I'm making this to handle backspaces well.
; postdata: this time the array starts at 1 because there's no negative
; numbers
mov si, 1
xor di, di
mov di, INPUT
.get_chars:
cmp si, 26
je .get_chars_error
call os_keystroke
cmp ah, [KEY_ENTER]
je .compare
cmp ah, [KEY_BACKSPACE]
je .handle_backspace
inc si
mov ah, 0x0e
int 10h
stosb
jmp .get_chars
.compare:
xor al, al
stosb
mov ax, INPUT
call os_string_to_lowercase
mov si, ABOUT_STR
mov di, INPUT
mov cx, command_about
call os_string_compare_and_jump
mov si, STRA_STR
mov di, INPUT
mov cx, command_stra
call os_string_compare_and_jump
mov si, CLEAR_STR
mov di, INPUT
mov cx, command_clear
call os_string_compare_and_jump
mov si, CHSET_STR
mov di, INPUT
mov cx, command_charset
call os_string_compare_and_jump
mov si, ECHO_STR
mov di, INPUT
mov cx, command_echo
call os_string_compare_and_jump
mov si, HELP_STR
mov di, INPUT
mov cx, command_help
call os_string_compare_and_jump
mov si, PROMPT_STR
mov di, INPUT
mov cx, command_prompt
call os_string_compare_and_jump
mov si, PAUSE_STR
mov di, INPUT
mov cx, command_pause
call os_string_compare_and_jump
mov si, RESTART_STR
mov di, INPUT
mov cx, command_exit
call os_string_compare_and_jump
mov si, SHUTDOWN_STR
mov di, INPUT
mov cx, command_shutdown
call os_string_compare_and_jump
mov si, WRITE_STR
mov di, INPUT
mov cx, command_write
call os_string_compare_and_jump
call os_print_new_line
mov bx, INVALID_CMD_MSG
call os_print_string
mov bx, QUOTE
call os_print_string
mov bx, di
call os_print_string
mov bx, QUOTE
call os_print_string
call os_print_new_line
jmp get_input
.get_chars_error:
call os_print_new_line
mov bx, .GET_CHARS_ERROR
call os_print_string
jmp get_input
.GET_CHARS_ERROR: db "You cannot write something larger than 25 chars to avoid bugs. Sorry.",0
.handle_backspace:
cmp si, 1
je .handle_backspace_no_backspace
dec di
dec si
call os_get_cursor_position
mov ah, 0x02
dec dl
xor bh, bh
int 10h
mov ah, 0x0e
mov al, ' '
int 10h
mov ah, 0x02
dec dl
xor bh, bh
int 10h
mov ah, 0x02
inc dl
xor bh, bh
int 10h
jmp .get_chars
.handle_backspace_no_backspace:
jmp .get_chars
null_input_string:
xor di, di
mov di, INPUT
mov si, 25
.null_input_string_loop:
cmp si, 0
je .null_input_string_done
mov al, 0
stosb
dec si
jmp .null_input_string_loop
.null_input_string_done:
ret
STARTED_SUCCESS_MSG: db "AtieDOS started successfully.", 0
INVALID_CMD_MSG: db "Invalid command: ", 0
QUOTE: db '"', 0
PROMPT: times 25 db 0
INPUT: times 25 db 0
ABOUT_STR: db "about", 0
STRA_STR: db "stra", 0
CLEAR_STR: db "clear", 0
CHSET_STR: db "chset", 0
ECHO_STR: db "echo", 0
HELP_STR: db "help", 0
PROMPT_STR: db "prompt", 0
PAUSE_STR: db "pause", 0
RESTART_STR: db "restart", 0
SHUTDOWN_STR: db "shutdown", 0
WRITE_STR: db "write", 0
%include "syscalls/_syscalls.asm"
%include "commands/_commands.asm"
%include "data/keys.asm"