-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bootloader.x
116 lines (115 loc) · 2.02 KB
/
bootloader.x
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
asm{
"[bits 16]",
"[org 0x7c00]"
}
//global character to print
char pchar;pchar=0;
char x_pos,y_pos;
//enter key
char enter_key;enter_key=0x1c;
///global array
char vbuffer[32];
//bootloader starting point
void start(){
char ch;
clear_screen();
//print each alphabet from A to Z
for(ch='A';ch<='Z';ch++){
pchar=ch;
print_char();
}
//goto nextline
goto_newline();
//assign type:characters to array vbuffer
vbuffer[0]='T';
vbuffer[1]='y';
vbuffer[2]='p';
vbuffer[3]='e';
vbuffer[4]=':';
vbuffer[5]=0;
//print whole array
print_array();
goto_newline();goto_newline();
//test the input
input_test();
}
//print array until 0 found in vbuffer
void print_array(){
char i;
for(i=0;i<32;i++){
pchar=vbuffer[i];
if(pchar==0){
break;
}else{
print_char();
}
}
}
/*get key by callling read_key()
if key is enter_key then goto nextline
otherwise orint that char
*/
void input_test(){
short key;
char key_code;
while(1){
key=read_key();
pchar=(char)key;
key=key&240;
key_code=key;
if(key_code == enter_key){
goto_newline();
}else{
print_char();
}
}
}
void goto_newline()
{
y_pos++;
x_pos = 0;
gotoxy();
}
//call BIOS interrupt to read key
//result is always in eax register, so no return statement
short read_key()
{
asm{
"\tmov ax,0x00",
"\tint 0x16"
}
}
//BIOS interrupt to goto x,y pos
void gotoxy()
{
asm{ "\tmov ah, 0x02",
"\tmov bh, 0x00",
"\tmov dl, %" ["=m"(x_pos):],
"\tmov dh, %" ["=m"(y_pos):],
"\tint 0x10"
}
}
//print character using BIOS interrupt
void print_char()
{
asm{
"\txor bx, bx",
"\tmov bl, 10",
"\tmov al, %" ["=m"(pchar):],
"\tmov ah, 0x0E",
"\tint 0x10"
}
}
void clear_screen()
{
asm{
"\tmov al, 2",
"\tmov ah, 0",
"\tint 0x10"
}
}
//define bootloader signature
asm{
"times (510 - ($ - $$)) db 0x00",
"dw 0xAA55"
}