我终于设法使用 VESA BIOS Extensions (1920px * 1080px, 24bpp) 在屏幕上绘制了一个青色像素。
;esi = bytes per scan line
;edx = physical address of linear framebuffer memory.
;ebx = x coord * 3
;ecx = y coord
DrawPixel:
push edx
mov edx, 0
mov eax, 0
lea eax, [esi]
;mov ecx, 0
mul ecx
add eax, ebx
jmp draw
draw:
pop edx
add edx, eax
mov ebx, 0x3296fa
mov [edx], ebx
ret
我尝试以这种方式使用“for循环”在屏幕上绘制一条青色水平线:
mov edi, 1920
call drawLoop
jmp $
drawLoop:
dec edi ;decrease edi
cmp edi, 0 ;is edi equal to zero?
jl doneLoop ;then return
imul ebx, edi, 3 ;multiply edi by three and save the result in ebx
mov ecx, 0 ;y = 0
mov esi, ModeInfoBlock + 10h
mov edx, dword[ModeInfoBlock + 28h]
call DrawPixel ;Draw it!
jmp drawLoop ;run this again
doneLoop:
ret
但是,这不起作用:它会画一条绿线。
当我尝试使用绘图/绘图像素代码再次绘制垂直线时,它也不起作用。它在各处绘制具有随机颜色的像素。以下是我使用该DrawPixel
函数绘制垂直线的方法:
%include "../kernel/Services/Display/display.asm"
kernel:
mov edi, 1080
call drawLoop
jmp $
drawLoop:
dec edi
cmp edi, 0
jl doneLoop
mov ecx, edi
mov ebx, 0
mov esi, ModeInfoBlock + 10h
mov edx, dword[ModeInfoBlock + 28h]
call DrawPixel
jmp drawLoop
doneLoop:
ret
有什么办法可以解决这些问题?