2024-07-21 00:54:48 +00:00
|
|
|
|
|
|
|
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.
|
|
|
|
|
2024-07-21 03:59:41 +00:00
|
|
|
; Multiply the row with 160, the number of bytes per row
|
2024-07-21 00:54:48 +00:00
|
|
|
mov eax, [ebp - 16]
|
2024-07-21 03:59:41 +00:00
|
|
|
mov edx, 160
|
2024-07-21 00:54:48 +00:00
|
|
|
mul edx
|
2024-07-21 03:59:41 +00:00
|
|
|
mov [esi + 4], eax
|
2024-07-21 00:54:48 +00:00
|
|
|
|
2024-07-21 03:59:41 +00:00
|
|
|
; Get the byte offset within the row
|
|
|
|
mov eax, [ebp - 12]
|
2024-07-21 00:54:48 +00:00
|
|
|
add eax, ecx
|
|
|
|
mov edx, 6
|
|
|
|
mul edx
|
|
|
|
|
2024-07-21 03:59:41 +00:00
|
|
|
; Add the start offset of the line
|
|
|
|
add eax, [esi + 4]
|
|
|
|
|
2024-07-21 00:54:48 +00:00
|
|
|
; 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"
|