Skip to content

Commit be85f74

Browse files
committed
Added sleep
1 parent 36b38e7 commit be85f74

File tree

4 files changed

+157
-23
lines changed

4 files changed

+157
-23
lines changed

src/bootloader/io.asm

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
int 0x16
3636
%endmacro
3737

38-
%macro set_cursor_xy 3
38+
%macro move_xy 3
3939
; Args: (x, y, page)
4040
mov ah, 0x02 ; (set custor position)
4141
mov bh, 0x%3 ; (page number)
@@ -78,7 +78,16 @@ label_marker:
7878
; check es
7979
mov ax, 0x1003
8080
mov bx, 0x000%1
81-
int 10h
81+
int 0x10
82+
%endmacro
83+
84+
%macro clear_screen 2
85+
; Output: (fg_color, bg_color)
86+
mov ax, 0x0600 ; (scroll 0 lines)
87+
mov bh, 0x%2%1 ; (attribute)
88+
mov cx, 0x0000 ; (window top-left RC)
89+
mov dx, 0x184F ; (window bottom-right RC)
90+
int 0x10
8291
%endmacro
8392

8493
[SECTION .data]

src/bootloader/stage1.asm

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
MOV es, ax ; es := 0
2020

2121
set_blinking 0
22+
clear_screen C_WHITE, C_BLACK
2223
print_string_ext bl_welcome, bl_welcome_len, 02, 02, C_MAGENTA, C_WHITE, 0
2324
print_string_ext bls1, bls1_len, 04, 04, C_WHITE, C_BLACK, 0
2425

@@ -30,10 +31,8 @@
3031
JMP label_exit
3132

3233
label_bts2_loaded:
33-
set_cursor_xy 06, 07, 00
34+
move_xy 06, 07, 00
3435
print_hex_string_ext 0x8000, 10, C_WHITE, 0
35-
print_string_ext bls2_loaded, bls2_loaded_len, 06, 06, C_WHITE, C_BLACK, 0
36-
3736
JMP 0x8000
3837
JMP label_exit
3938

src/bootloader/stage2.asm

Lines changed: 57 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,14 @@
22
%include "constants.asm"
33
%include "io.asm"
44

5-
[BITS 16]
5+
[BITS 16]
66

7-
global _low_print
8-
extern entry_stage2
7+
extern entry_stage
8+
9+
global _low_put_chars
10+
global _low_move_xy
11+
global _low_clear_screen
12+
global _low_sleep
913

1014
[SECTION .text]
1115
CLI
@@ -14,25 +18,63 @@ extern entry_stage2
1418
set_blinking 0
1519

1620
print_string_ext bl_stage_2, bl_stage_2_len, 04, 09, C_WHITE, C_BLACK, 0
17-
call entry_stage2
18-
21+
call entry_stage
1922
JMP label_exit
2023

21-
_low_print:
24+
_low_put_chars:
25+
push ebp
26+
mov ebp, esp
27+
28+
mov ah, 0x09 ; (write)
29+
mov al, [ebp + 0x8] ; (char)
30+
mov cx, [ebp + 0xc] ; (count)
31+
mov bh, 0x00 ; (pagenumber)
32+
mov bl, [ebp + 0x10] ; (attribute)
33+
int 0x10
34+
35+
mov esp, ebp
36+
pop ebp
37+
ret
38+
39+
_low_move_xy:
2240
push ebp
2341
mov ebp, esp
2442

25-
; check es, bx
26-
mov ax, 0x1301 ; (print string, update cursor)
27-
mov bh, 0 ; (pagenumber)
28-
mov bl, [ebp + 0x18] ; (attribute)
29-
mov dh, [ebp + 0x14] ; (pos_y)
30-
mov dl, [ebp + 0x10] ; (pos_x)
31-
mov ecx, [ebp + 0xc] ; (string length)
32-
mov ebp, [ebp + 0x8] ; (es:bp string pointer)
43+
mov ah, 0x02 ; (set custor position)
44+
mov dl, [ebp + 0x8] ; (pos_x)
45+
mov dh, [ebp + 0xc] ; (pos_y)
46+
mov bh, [ebp + 0x10] ; (page number)
3347
int 0x10
3448

35-
mov ax, 0
49+
mov esp, ebp
50+
pop ebp
51+
ret
52+
53+
_low_clear_screen:
54+
push ebp
55+
mov ebp, esp
56+
57+
mov ah, 0x06 ; (scroll)
58+
mov al, 0x00 ; (line count)
59+
mov bh, [ebp + 0x08] ; (attribute)
60+
mov cl, [ebp + 0x0c] ; (window top-left x)
61+
mov ch, [ebp + 0x10] ; (window top-left y)
62+
mov dl, [ebp + 0x14] ; (window bottom-right x)
63+
mov dh, [ebp + 0x18] ; (window bottom-right y)
64+
int 0x10
65+
66+
mov esp, ebp
67+
pop ebp
68+
ret
69+
70+
_low_sleep:
71+
push ebp
72+
mov ebp, esp
73+
mov ebx, [ebp + 0x08] ; (cycles)
74+
_low_sleep_internal:
75+
sub ebx, 1
76+
jnc _low_sleep_internal
77+
3678
mov esp, ebp
3779
pop ebp
3880
ret

src/bootloader/stage2.c

Lines changed: 87 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,98 @@
1515
#define C_YELLOW 0xE
1616
#define C_WHITE 0xF
1717

18+
#define INT_MAX 0xFFFFFFFF
19+
20+
#define WINDOW_HEIGHT 0x18
21+
#define WINDOW_WIDTH 0x4F
22+
#define CLOCKS_PER_MS 56230 // 5% of Host CPU
23+
24+
#define SLEEP_FACTOR_NUM 3 // Possiblity of improvement.
25+
#define SLEEP_FACTOR_DENO 2
26+
#define SLEEP_BURST_MS INT_MAX/CLOCKS_PER_MS/SLEEP_FACTOR_NUM*SLEEP_FACTOR_DENO
27+
1828
#define make_color(fg, bg) ((unsigned char)((fg) + ((bg)<<4)))
1929

20-
extern void _low_print(char str[], unsigned short int n,
30+
extern void _low_print(char str[], unsigned short n,
2131
unsigned char x,unsigned char y,
2232
unsigned char color);
2333

34+
extern void _low_put_chars(char c,unsigned short count, unsigned char color);
35+
extern void _low_move_xy(unsigned char x, unsigned char y, unsigned char page);
36+
extern void _low_clear_screen(unsigned char color,
37+
unsigned char x1,unsigned char y1,
38+
unsigned char x2, unsigned char y2);
39+
extern void _low_sleep(unsigned int half_instructions_count);
40+
41+
void run();
42+
2443
char message_welcome[] = "C says 'Hello World'";
2544

26-
void entry_stage2() {
27-
_low_print(message_welcome,sizeof(message_welcome)-1,6,11, make_color(C_GREEN, C_BLACK));
45+
unsigned char CURRENT_X = 0;
46+
unsigned char CURRENT_Y = 0;
47+
48+
void move_xy(unsigned char x, unsigned char y) {
49+
CURRENT_X=x;
50+
CURRENT_Y=y;
51+
_low_move_xy(x,y,0);
52+
}
53+
54+
void move_xy_diff(unsigned char dx, unsigned char dy) {
55+
CURRENT_X+=dx;
56+
CURRENT_Y+=dy;
57+
_low_move_xy(CURRENT_X,CURRENT_Y,0);
58+
}
59+
60+
void put_char(char c, unsigned char color) {
61+
_low_put_chars(c,1, color);
62+
move_xy_diff(1, 0);
63+
}
64+
65+
void put_chars(char c,unsigned short count, unsigned char color) {
66+
_low_put_chars(c,count, color);
67+
move_xy_diff(count, 0);
68+
}
69+
70+
void put_string(char *str, unsigned char color) {
71+
while((*str)!='\0') {
72+
put_char(*str, color);
73+
str++;
74+
}
75+
}
76+
77+
void sleep(unsigned int ms) {
78+
while(ms>0) {
79+
unsigned int fms = ms>SLEEP_BURST_MS?SLEEP_BURST_MS:ms;
80+
unsigned int cycles = CLOCKS_PER_MS*fms/SLEEP_FACTOR_DENO*SLEEP_FACTOR_NUM;
81+
_low_sleep(cycles);
82+
ms-=fms;
83+
}
84+
}
85+
86+
void entry_stage() {
87+
move_xy(6, 11);
88+
put_string(message_welcome, make_color(C_GREEN, C_BLACK));
89+
sleep(1000);
90+
run();
91+
while(1);
92+
}
93+
94+
char application_list[5][10] = {"Sample 1", "Sample 2", "Sample 3", "Sample 4", "Sample 5"};
95+
void print_applications(unsigned char x, unsigned char y, char *list, unsigned char count, unsigned char max_strlen) {
96+
for(int i=0;i<count;i++) {
97+
move_xy(x,y+i);
98+
put_string("X ",make_color(C_BLUE, C_LIGHT_GRAY));
99+
put_string(list,make_color(C_BLACK, C_LIGHT_GRAY));
100+
list+=max_strlen;
101+
}
102+
}
103+
104+
void run() {
105+
_low_clear_screen(make_color(C_WHITE, C_DARK_GRAY), 0, 0, WINDOW_WIDTH, WINDOW_HEIGHT);
106+
_low_clear_screen(make_color(C_WHITE, C_LIGHT_GRAY), 1, 1, WINDOW_WIDTH-1, WINDOW_HEIGHT-1);
107+
move_xy(1,0);
108+
put_string("Fuzzy OS", make_color(C_WHITE, C_DARK_GRAY));
109+
move_xy(3,3);
110+
put_string("Applications:", make_color(C_BLACK, C_LIGHT_GRAY));
111+
print_applications(3,4, (char*)application_list, 5, 10);
28112
}

0 commit comments

Comments
 (0)