Add hexadecimal dump function

The function which is added with this commit writes a caller-supplied
hexadecimal string of a caller-supplied length to the display, nibble
by nibble, leaving the background black and making the text white.
This commit is contained in:
Eric-Paul Ickhorn 2024-07-21 02:54:48 +02:00
parent 6342b433b4
commit 4acf6f3a44
Signed by: epickh
GPG Key ID: 1358818BAA38B104
1 changed files with 106 additions and 0 deletions

View File

@ -0,0 +1,106 @@
FRAMEBUFFER_ADDRESS equ 0xb8000
; Arguments:
; [FURTHEST FROM EBP]
; 4. U32 Target Y-Position
; 3. U32 Target X-Position
; 2. U32 Length of Hexadecimal String
; 1. Ptr32 Hexadecimal String
; [NEAREST TO EBP]
write_hexadecimal_string:
push dword esi
sub esp, 64
mov esi, esp
mov [esi + (64 - 4)], eax
mov [esi + (64 - 8)], ebx
mov [esi + (64 - 12)], ecx
mov [esi + (64 - 16)], edx
mov [esi + (64 - 20)], edi
; [esi]:
.initialize_writer_loop:
xor ecx, ecx
.writer_loop:
cmp ecx, [ebp - 8]
jae .epilog
; Calculate the byte's start on-screen (A single byte from
; the input uses 6 bytes in the framebuffer as every single
; character uses 2 bytes and there are 3 characters per byte
; written; the upper nibble, the lower nibble and the padding.
; Multiply the row with 80, the number of cells per row
mov eax, [ebp - 16]
mov edx, 80
mul edx
; Add the offset within the row ontop
add eax, [ebp - 12]
add eax, ecx
; Multiply with 2 to get the byte offset
; from the character index
mov edx, 6
mul edx
; Point into the framebuffer
add eax, FRAMEBUFFER_ADDRESS
; Save the value
mov [esi], eax
.write_upper_nibble:
; Lookup the hexadecimal character
xor eax, eax
mov ebx, [ebp - 4]
add ebx, ecx
mov al, [ebx]
shr al, 4
mov ebx, .hexadecimal_lookup
add ebx, eax
mov dl, [ebx]
mov ebx, [esi]
mov [ebx], dl
; Set the color code for leaving the background black (0x0?)
; and making the foreground be white (0x?f).
mov [ebx + 1], byte 0x0f
.write_lower_nibble:
; Lookup the hexadecimal character
xor eax, eax
mov ebx, [ebp - 4]
add ebx, ecx
mov al, [ebx]
and al, 0x0f
mov ebx, .hexadecimal_lookup
add ebx, eax
mov dl, [ebx]
mov ebx, [esi]
mov [ebx + 2], dl
; Set the color code for leaving the background black (0x0?)
; and making the foreground be white (0x?f).
mov [ebx + 3], byte 0x0f
inc ecx
jmp .writer_loop
.epilog:
mov eax, [esi + (64 - 4)]
mov ebx, [esi + (64 - 8)]
mov ecx, [esi + (64 - 12)]
mov edx, [esi + (64 - 16)]
mov edi, [esi + (64 - 20)]
add esp, 64
pop dword esi
ret
.hexadecimal_lookup:
db "0123456789abcdef"