kernel/src/framebuffer.asm

67 lines
874 B
NASM

;; x, y, r, g, b
putpixel:
push ebp
mov ebp, esp
push eax
push ebx
push ecx
push edi
; 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 ebx ;y
add edi, eax
mov eax, ecx ;x
movzx ecx, byte [mbootinfo.fb_bytespp]
mul ecx
add edi, eax
; Poke videomemory
xor eax, eax
mov ebx, [ebp+16]
mov cl, [mbootinfo.fb_rpos]
shl ebx, cl
or eax, ebx
mov ebx, [ebp+20]
mov cl, [mbootinfo.fb_gpos]
shl ebx, cl
or eax, ebx
mov ebx, [ebp+24]
mov cl, [mbootinfo.fb_bpos]
shl ebx, cl
or eax, ebx
cmp [mbootinfo.fb_bpp], 32
jne .bpp24
stosd
jmp .done
.bpp24:
stosb
shr eax, 8
stosb
shr eax, 8
stosb
.done:
pop edi
pop ecx
pop ebx
pop eax
pop ebp
ret