-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathio.asm
More file actions
82 lines (72 loc) · 1.81 KB
/
Copy pathio.asm
File metadata and controls
82 lines (72 loc) · 1.81 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
section .text
global print_char
global print_string
global get_key
; ----------------------------------------
; void print_char(char c)
; Expects: char c in [esp + 32] (first argument after pusha)
print_char:
pusha
movzx eax, byte [esp + 32] ; get char argument
mov edi, [cursor_pos]
add edi, 0xB8000 ; VGA base
mov ah, 0x07 ; Light gray on black
mov [edi], ax ; Write character + attr
add edi, 2
sub edi, 0xB8000
mov [cursor_pos], edi
popa
ret
; ----------------------------------------
; void print_string(const char* str)
; Expects: pointer to null-terminated string at [esp + 32]
print_string:
pusha
mov esi, [esp + 32]
mov edi, [cursor_pos]
add edi, 0xB8000
.loop:
lodsb
test al, al
jz .done
mov ah, 0x07
mov [edi], ax ; correctly pairs char + attr
add edi, 2
jmp .loop
.done:
sub edi, 0xB8000
mov [cursor_pos], edi
popa
ret
; ----------------------------------------
; char get_key()
; Returns: ASCII in AL
get_key:
.wait_key:
in al, 0x64
test al, 1
jz .wait_key
in al, 0x60 ; Read from keyboard
cmp al, 0x1C
je .enter
; Lookup in scancode_table
movzx eax, al
mov al, [scancode_table + eax]
ret
.enter:
mov al, 0x0D ; carriage return
ret
; ----------------------------------------
section .bss
cursor_pos: resd 1
section .data
scancode_table:
; 0x00–0x0F
db 0, 0, '1','2','3','4','5','6','7','8','9','0','-','=',0, 0
; 0x10–0x1F
db 'Q','W','E','R','T','Y','U','I','O','P','[',']',0, 0, 'A','S'
; 0x20–0x2F
db 'D','F','G','H','J','K','L',';', '\'', '`',0, '\\','Z','X','C','V'
; 0x30–0x3B
db 'B','N','M',',','.','/',' ',0, 0, 0, 0, 0, 0, 0, 0, 0
times 128 - ($ - scancode_table) db 0