Skip to content

Commit cde7764

Browse files
committed
Added basic IO macros
1 parent b5a86fa commit cde7764

File tree

3 files changed

+91
-17
lines changed

3 files changed

+91
-17
lines changed

bootloader/constants.asm

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
%define C_BLACK 0
2+
%define C_BLUE 1
3+
%define C_GREEN 2
4+
%define C_CYAN 3
5+
%define C_RED 4
6+
%define C_MAGENTA 5
7+
%define C_BROWN 6
8+
%define C_LIGHT_GRAY 7
9+
%define C_DARK_GRAY 8
10+
%define C_LIGHT_BLUE 9
11+
%define C_LIGHT_GREEN A
12+
%define C_LIGHT_CYAN B
13+
%define C_LIGHT_RED C
14+
%define C_LIGHT_MAGENTA D
15+
%define C_YELLOW E
16+
%define C_WHITE F

bootloader/io.asm

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
%macro print_string 4
2+
; Args: (str, len, x, y)
3+
; check es, bx
4+
mov ax, 0x1301 ; (print string, update cursor)
5+
mov bp, %1 ; (es:bp string pointer)
6+
mov cx, %2 ; (string length)
7+
mov dx, 0x%4%3 ; (pos_y, pos_x)
8+
int 0x10
9+
%endmacro
10+
11+
%macro print_string_ext 7
12+
; Args: (str, len, x, y, fg_color, bg_color, page)
13+
; check es
14+
mov bx, 0x%7%6%5 ; (pagenumber, attribute)
15+
print_string %1, %2, %3, %4
16+
%endmacro
17+
18+
%macro put_chars 2
19+
; Args: (char, count)
20+
mov ah, 0x09 ; (write)
21+
mov al, %1 ; (char)
22+
mov cx, %2 ; (count)
23+
int 0x10
24+
%endmacro
25+
26+
%macro put_chars_ext 5
27+
; Args: (char, count, fg_color, bg_color, page)
28+
mov bx, 0x%5%4%3 ; (page, attribute)
29+
put_chars %1, %2
30+
%endmacro
31+
32+
%macro read_char 0
33+
; Output: (ah: scan code, al: ascii code)
34+
mov ah, 0x00 ; (read character)
35+
int 0x16
36+
%endmacro
37+
38+
%macro set_blinking 1
39+
; Args: (should_blink)
40+
; check es
41+
mov ax, 0x1003
42+
mov bx, 0x000%1
43+
int 10h
44+
%endmacro
45+
46+
[SECTION .data]
47+
digit_to_hex db "0123456789ABCDEF"

bootloader/main.asm

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,37 @@
11
; Fuzzy Bootloader
2+
%include "constants.asm"
3+
%include "io.asm"
24

3-
ORG 0x7C00
4-
BITS 16
5+
[ORG 0x7C00]
6+
[BITS 16]
57

68

7-
SECTION .text
9+
[SECTION .text]
810

11+
cli
912
mov ax, 0x0000
1013
mov es, ax ; es := 0
11-
12-
start:
13-
mov ax, 0x1301 ; (print string, update cursor)
14-
mov bx, 0x0007 ; (pagenumber, attribute)
15-
mov bp, bl_welcome ; (string pointer)
16-
mov cx, bl_welcome_sz ; (string length)
17-
mov dx, bl_welcome_loc ; (pos_y, pos_x)
18-
int 0x10
19-
hlt
20-
21-
SECTION .data
2214

23-
bl_welcome db "Starting Fuzzy Bootloader... (^_^)"
24-
bl_welcome_sz equ $-bl_welcome
25-
bl_welcome_loc equ 0x0101 ; (pos_y, pos_x)
15+
set_blinking 0
16+
print_string_ext bl_welcome, bl_welcome_len, 02, 02, C_BLACK, C_WHITE, 0
17+
print_string_ext bl_op_os, bl_op_os_len, 05, 04, C_WHITE, C_BLACK, 0
18+
print_string bl_op_reboot, bl_op_reboot_len, 05, 05
19+
print_string bl_op_shutdown, bl_op_shutdown_len, 05, 06
20+
print_string bl_op_instrut, bl_op_instrut_len, 03, 08
21+
loop:
22+
read_char
23+
put_chars_ext al, 1, C_GREEN, C_YELLOW, 0
24+
jmp loop
25+
hlt
2626

27+
[SECTION .data]
28+
bl_welcome db "Fuzzy OS... (^_^)"
29+
bl_welcome_len equ ($-bl_welcome)
30+
bl_op_os db "A. Load OS"
31+
bl_op_os_len equ ($-bl_op_os)
32+
bl_op_reboot db "B. Reboot"
33+
bl_op_reboot_len equ ($-bl_op_reboot)
34+
bl_op_shutdown db "C. Shutdown"
35+
bl_op_shutdown_len equ ($-bl_op_shutdown)
36+
bl_op_instrut db "Press A/B/C key to continue..."
37+
bl_op_instrut_len equ ($-bl_op_instrut)

0 commit comments

Comments
 (0)