-
Notifications
You must be signed in to change notification settings - Fork 0
/
kernel.asm
81 lines (81 loc) · 1.75 KB
/
kernel.asm
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
%include "type_macros.asm"
; setup segment
mov bx, KERNEL_CODE_BEGIN_SEG
mov ds, bx
; setup stack
mov ss, bx ; bx is ds
mov bp, KERNEL_CODE_SIZE + KERNEL_STACK_SIZE
mov sp, bp
jmp main
; --- modules ---
%include "console_sub.asm"
%include "list16_sub.asm"
%include "list8_sub.asm"
%include "interpreter_sub.asm"
; --- data ---
kernel_data :
.greeting :
db "W", (WHITE)
db "e", (WHITE)
db "l", (WHITE)
db "c", (WHITE)
db "o", (WHITE)
db "m", (WHITE)
db "e", (WHITE)
db " ", (WHITE)
db "t", (WHITE)
db "o", (WHITE)
db " ", (WHITE)
db "p", (BRIGHT + YELLOW)
db "i", (BRIGHT + RED)
db "k", (BRIGHT + GREEN)
db "o", (BRIGHT + BLUE)
db "-", (WHITE)
db "p", (BRIGHT + CYAN)
db "i", (BRIGHT + MAGENTA)
db "k", (BRIGHT + GREEN)
db "o", (BRIGHT + YELLOW)
db "!", (WHITE)
dw 0
.input_buffer :
times 1 dw 0 ; list 16 header (max and length)
times BUFFER_WIDTH dw 0 ; list 16 content
.raw_buffer :
times 1 dw 0 ; list 8 header (max and length)
times BUFFER_WIDTH db 0 ; list 8 content
; --- subroutines ---
main :
; initialization
STORAGE_SET_DRIVE
CONSOLE_INIT
INTERPRETER_INIT
mov di, kernel_data.input_buffer
LIST16_INIT BUFFER_WIDTH
mov di, kernel_data.raw_buffer
LIST8_INIT BUFFER_WIDTH
; print greeting
mov si, kernel_data.greeting
xor cx, cx
call consoleWriteAttributedCString
PRINT_NL
.loop :
mov si, kernel_data.input_buffer
; get user input
PRINT_CHAR '>'
PRINT_CHAR ' '
mov bx, interpreterPaint
call consoleReadLine
PRINT_NL
mov di, kernel_data.raw_buffer
call list16TakeLower
mov si, kernel_data.raw_buffer
clc
call interpreterExecute
jmp .loop
; --- checks ---
%if ($-$$) > KERNEL_CODE_SIZE
%error "Kernel is bigger than expected."
%endif
%if KERNEL_FINAL_ADDR > (CONSOLE_DUMP_SEG << 4)
%error "Kernel is overlapping video dump."
%endif