diff options
-rw-r--r-- | src/kernel/boot.asm | 2 | ||||
-rw-r--r-- | src/kernel/graphics/graphics.h | 3 | ||||
-rw-r--r-- | src/kernel/graphics/vesa.asm | 201 | ||||
-rw-r--r-- | src/kernel/graphics/vesa.c | 7 | ||||
-rw-r--r-- | src/kernel/kernel.c | 1 |
5 files changed, 214 insertions, 0 deletions
diff --git a/src/kernel/boot.asm b/src/kernel/boot.asm index 198625a..4dccebb 100644 --- a/src/kernel/boot.asm +++ b/src/kernel/boot.asm @@ -44,6 +44,8 @@ stublet: %include "src/kernel/apm/apm.asm" +%include "src/kernel/graphics/vesa.asm" + ; Store the stack SECTION .bss resb 8192 ; Reserve 8KiB diff --git a/src/kernel/graphics/graphics.h b/src/kernel/graphics/graphics.h index a9ed917..1f36d48 100644 --- a/src/kernel/graphics/graphics.h +++ b/src/kernel/graphics/graphics.h @@ -18,4 +18,7 @@ void terminal_put_char(char c); void terminal_write_line(const char *data); +// VESA +void vesa_init(); + #endif
\ No newline at end of file diff --git a/src/kernel/graphics/vesa.asm b/src/kernel/graphics/vesa.asm new file mode 100644 index 0000000..9d8e231 --- /dev/null +++ b/src/kernel/graphics/vesa.asm @@ -0,0 +1,201 @@ +global find_mode +global best_video_mode + +vbe_info_block: + .signature db "VBE2" ; indicate support for VBE 2.0+ + .version dw 0 + .oem dd 0 + .capabilities dd 0 + .video_modes dd 0 + .video_memory dw 0 + .software_rev dw 0 + .vendor dd 0 + .product_name dd 0 + .product_rev dd 0 + .reserved times 222 db 0 + .oem_data times 256 db 0 + +mode_info_block: + .attributes dw 0 + .window_a db 0 + .window_b db 0 + .granularity dw 0 + .window_size dw 0 + .segment_a dw 0 + .segment_b dw 0 + .win_func_ptr dd 0 + .pitch dw 0 + .width dw 0 + .height dw 0 + .w_char db 0 + .y_char db 0 + .planes db 0 + .bpp db 0 + .banks db 0 + .memory_model db 0 + .bank_size db 0 + .image_pages db 0 + .reserved0 db 0 + + .red_mask db 0 + .red_position db 0 + .green_mask db 0 + .green_position db 0 + .blue_mask db 0 + .blue_position db 0 + .reserved_mask db 0 + .reserved_position db 0 + .direct_color_attributes db 0 + + .framebuffer dd 0 + .off_screen_mem_off dd 0 + .off_screen_mem_size dw 0 + .reserved1 times 206 db 0 + +best_video_mode: + .bpp db 0 + .height dw 0 + .width dw 0 + .mode dw 0 + .framebuffer dd 0 + .bytes_per_line dw 0 + .bytes_per_pixel dd 0 + .x_cur_max dw 0 + .y_cur_max dw 0 + +segments dw 0 +offset dw 0 +mode dw 0 + +width equ 1024 +height equ 768 +bpp equ 32 + +search_video_mode: + [bits 16] + + push es + mov ax, 0x4F00 + mov di, vbe_info_block + int 0x10 + pop es + + mov ax, word [vbe_info_block.video_modes] + mov [offset], ax + mov ax, word [vbe_info_block.video_modes+2] + mov [segments], ax + + mov ax, [segments] + mov fs, ax + mov si, [offset] + + mov cx, 1 + push cx + +find_mode: + mov dx, [fs:si] + add si, 2 + mov [offset], si + mov [mode], dx + mov ax, 0 + mov fs, ax + + push es + mov ax, 0x4F01 + mov cx, [mode] + mov di, mode_info_block + int 0x10 + pop es + + cmp ax, 0x004F + + pop cx + cmp cx, 4 + je reset_counter + inc cx + push cx + + check_mode: + mov cx, 0 + mov bx, [best_video_mode.width] + cmp bx, [mode_info_block.width] + jl save_and_continue + je compare_height + jmp next_mode + + compare_height: + mov bx, [best_video_mode.height] + cmp bx, [mode_info_block.height] + jl save_and_continue + je compare_bpp + jmp next_mode + + compare_bpp: + mov dx, [best_video_mode.bpp] + mov ax, [mode_info_block.bpp] + and ax, 11111111b + cmp dx, ax + jl save_and_continue + jmp next_mode + + save_and_continue: + mov bx, [mode_info_block.width] + mov [best_video_mode.width], bx + + shr bx,3 + dec bx + mov [best_video_mode.x_cur_max], bx + + mov bx, [mode_info_block.height] + mov [best_video_mode.height], bx + + shr bx, 4 + dec bx + mov word [best_video_mode.y_cur_max], ax + + mov ebx, 0 + mov bl, [mode_info_block.bpp] + mov byte [best_video_mode.bpp], bl + shr ebx, 3 + mov dword [best_video_mode.bytes_per_pixel], ebx + + + mov bx, [mode] + mov [best_video_mode.mode], bx + mov ebx, [mode_info_block.framebuffer] + mov dword[best_video_mode.framebuffer], ebx + mov bx, [mode_info_block.pitch] + mov word [best_video_mode.bytes_per_line],bx + jmp next_mode + +pop es + +jmp $ + +new_line_and_next_mode: + mov cx,1 + push cx + jmp next_mode + +reset_counter: + mov cx, 1 + push cx + jmp check_mode + +set_mode: + push es + mov ax, 0x4F02 + mov bx, [best_video_mode.mode] + or bx, 0x4000 + mov di, 0 + int 0x10 + pop es + + cmp ax, 0x4F + clc + +next_mode: + mov ax, [segments] + mov fs, ax + mov si, [offset] + jmp find_mode diff --git a/src/kernel/graphics/vesa.c b/src/kernel/graphics/vesa.c new file mode 100644 index 0000000..b178645 --- /dev/null +++ b/src/kernel/graphics/vesa.c @@ -0,0 +1,7 @@ +#include "graphics.h" + +extern char *find_mode(); + +void vesa_init() { + terminal_write_line(find_mode()); +}
\ No newline at end of file diff --git a/src/kernel/kernel.c b/src/kernel/kernel.c index 49fe0b7..fb180ae 100644 --- a/src/kernel/kernel.c +++ b/src/kernel/kernel.c @@ -14,6 +14,7 @@ void kernel_main(void) { __asm__ __volatile__ ("sti"); terminal_initialize(); + vesa_init(); terminal_write_string("Melvix loaded successfully!\n"); timer_install(); |