os/asm/boot/print32.asm

81 lines
1.8 KiB
NASM
Raw Normal View History

2021-08-22 01:32:20 +00:00
[bits 32]
; 32-bit protected print helpers
; VGA is 80 x 25 characters starting at 0xb8000
; 1st byte is ASCII code of char to display, 2nd byte is display info
; Address of particular row/col as: 0xb8000 + 2 * (row * 80 + col)
; Constants
i_video_memory equ 0xb8000
i_white_on_black equ 0x0f
; Variables
i_print32_row_start equ 0xb8000
i_print32_row_current equ 0xb8000
i_print32_row_end equ 0xb8002 + 160
print32_raw_simple:
; prints null-terminated string pointed to by edx
pusha
mov edx, i_video_memory ; set edx to start of the row
print32_raw_simple_loop:
mov al, [ebx] ; store char at ebx in al
mov ah, i_white_on_black ; store display info in ah
cmp al, 0 ; if al is null, then this is the end of the string
je g_return
mov [edx], ax ; store char and attributes at current char cell
add ebx, 1 ; increment ebx to next char in string
add edx, 2 ; move to next char cell in video memory
jmp print32_raw_simple_loop
print32_newline: ; TODO fix this...
pusha
mov eax, i_print32_row_start
mov ebx, i_print32_row_current
mov ecx, i_print32_row_end
add eax, 0xa0
add ebx, 0xa0
mov ecx, eax
jmp g_return
print32_raw:
; prints null-terminated string pointed to by edx
pusha
mov edx, i_print32_row_current ; set edx to start of the row
jmp print32_raw_loop
print32_raw_next_line:
call print32_newline
print32_raw_loop:
cmp edx, i_print32_row_end
je print32_raw_next_line
mov al, [ebx] ; store char at ebx in al
mov ah, i_white_on_black ; store display info in ah
cmp al, 0 ; if al is null, then this is the end of the string
je g_return
mov [edx], ax ; store char and attributes at current char cell
add ebx, 1 ; increment ebx to next char in string
add edx, 2 ; move to next char cell in video memory
jmp print32_raw_loop
print32:
call print32_raw
call print32_newline
ret
[bits 16]