From f9c0bd3db6c8053ca474676c8929ed5f50cc2ddd Mon Sep 17 00:00:00 2001 From: Jarkko Toivanen Date: Fri, 8 Sep 2023 12:02:02 +0300 Subject: [PATCH] Improved framebuffer compatibility and memory safeguard --- src/framebuffer.asm | 25 ++++++++++++++----------- src/mbootinfo.asm | 6 ------ src/start32.asm | 11 ++++++----- 3 files changed, 20 insertions(+), 22 deletions(-) diff --git a/src/framebuffer.asm b/src/framebuffer.asm index d831dec..9c215a4 100644 --- a/src/framebuffer.asm +++ b/src/framebuffer.asm @@ -10,15 +10,23 @@ putpixel: cld + ; check pixel is in screen + mov ebx, [ebp+12] ;y + cmp ebx, [mbootinfo.fb_height] + jge .done + mov ecx, [ebp+8] ;x + cmp ecx, [mbootinfo.fb_width] + jge .done + ; Destination mov edi, [mbootinfo.fb_addr] mov eax, [mbootinfo.fb_pitch] - mul dword [ebp+12] ;y + mul dword ebx ;y add edi, eax - mov eax, [ebp+8] ;x - movzx ebx, byte [mbootinfo.fb_bytespp] - mul ebx + mov eax, ecx ;x + movzx ecx, byte [mbootinfo.fb_bytespp] + mul ecx add edi, eax @@ -26,13 +34,8 @@ putpixel: mov eax, [ebp + 16] ; Poke videomemory - stosb - stosb - stosb - - cmp [mbootinfo.fb_bpp], 24 - je .done - stosb + cld + rep stosb .done: pop edi pop ecx diff --git a/src/mbootinfo.asm b/src/mbootinfo.asm index 1a6f559..2ff07e8 100644 --- a/src/mbootinfo.asm +++ b/src/mbootinfo.asm @@ -45,12 +45,6 @@ mbootgetinfo: add esi, 4 mov al, [esi] - cmp al, 32 - je .bppokay - cmp al, 24 - je .bppokay - jmp mbootunsupportedfbbpp -.bppokay: mov [mbootinfo.fb_bpp], al inc esi diff --git a/src/start32.asm b/src/start32.asm index fc3ae85..f8e5d36 100644 --- a/src/start32.asm +++ b/src/start32.asm @@ -11,8 +11,9 @@ MB_HEADER_FLAGS equ MB_PAGE_ALIGN or MB_MEMORY_INFO or MB_VIDEO_REQUEST MB_HEADER_FLAGS equ MB_PAGE_ALIGN or MB_MEMORY_INFO or MB_VIDEO_REQUEST or MB_AOUT_KLUDGE MB_CHECKSUM equ -(MB_HEADER_MAGIC + MB_HEADER_FLAGS) -VWIDTH equ 1024 -VHEIGHT equ 768 +VWIDTH equ 640 +VHEIGHT equ 480 +VDEPTH equ 24 multiboot: dd MB_HEADER_MAGIC @@ -26,7 +27,7 @@ multiboot: dd 0 ; video mode_type (0:fb, 1:txt) (set flags[2]!) dd VWIDTH ; video width dd VHEIGHT ; video height - dd 24 ; video depth + dd VDEPTH ; video depth start: ; Setup stack @@ -103,8 +104,8 @@ start: mov ebx, 767 mov ecx, 1023 push 0xff - push 767 - push 1023 + push 479 + push 639 call putpixel add esp, 3*4