forked from nanochess/bootOS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstaller.asm
138 lines (134 loc) · 2.82 KB
/
installer.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
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
org 0x7c00
init:
xor ax,ax ; Set all segments to zero
mov ds,ax
mov es,ax
mov ss,ax
mov sp,0x8000
mov byte [0xffff], dl
get_disk:
mov al, "#"
call input_line
call xdigit ; Get a hexadecimal digit
mov cl,4
shl al,cl
xchg ax,cx
call xdigit ; Get a hexadecimal digit
or al,cl
mov ah, 0x00
push ax
cmp al, [0xffff]
je error
copy: push cs
pop ds
mov si, dap
mov ah, 0x42
mov dl, [0xffff]
pusha
int 0x13
popa
jc exit
pop dx
push dx
mov ah, 0x43
sub word [dap.lba_lower], 1
pusha
int 0x13
popa
jc exit
add word [dap.lba_lower], 2
cmp word [dap.lba_lower], 0xffff
jne copy
exit:
mov si, success
mov byte [0xfffe], 0xff
_print:
lodsb
cmp al, 0x00
je _exit
pusha
call output_char
popa
jmp _print
_exit:
mov ah,0x00
int 0x16
jmp 0xffff:0x0000
error: mov si, error_msg
jmp _print
xdigit:
lodsb
cmp al,0x00 ; Zero character marks end of line
je r
sub al,0x30 ; Avoid spaces (anything below ASCII 0x30)
jc xdigit
cmp al,0x0a
jc r
sub al,0x07
and al,0x0f
stc
r:
ret
input_line:
call output_char; Output prompt character
mov si,0xa000 ; Setup SI and DI to start of line buffer
mov di,si ; Target for writing line
mov dl, al
os1: cmp al,0x08 ; Backspace?
jne os2
dec di ; Undo the backspace write
cmp si, di
je os2_
dec di ; Erase a character
push ax
mov al, " "
call output_char
mov al, 0x08
call output_char
pop ax
os2: call input_key ; Read keyboard
cmp al,0x0d ; CR pressed?
jne os10
mov al,0x00
os10: stosb ; Save key in buffer
jne os1 ; No, wait another key
ret ; Yes, return
os2_: mov al, dl
call output_char
jmp os2
;
; Read a key into al
; Also outputs it to screen
;
input_key:
mov ah,0x00
int 0x16
;
; Screen output of character contained in al
; Expands 0x0d (CR) into 0x0a 0x0d (LF CR)
;
output_char:
cmp al,0x0d
jne os3
mov al,0x0a
call output_char
mov al,0x0d
os3:
mov ah,0x0e ; Output character to TTY
mov bx,0x0007 ; Gray. Required for graphic modes
int 0x10 ; BIOS int 0x10 = Video
ret
success: db "Success. Press a key to reboot...", 0x0d, 0
error_msg: db "Cannot install to source drive!", 0x0d, 0
dap:
dap.header: db 0x10
dap.unused: db 0x00
dap.count: dw 0x0001
dap.offset_offset:
dw 0x0000
dap.offset_segment:
dw 0x1000
dap.lba_lower: dq 0x0001
dap.lba_upper: dq 0x0000
times 510 - ($ - $$) db 0x00
db 0x55, 0xaa