diff --git a/roska.fasm b/roska.fasm index 9857b2a..a718dc9 100644 --- a/roska.fasm +++ b/roska.fasm @@ -12,9 +12,9 @@ MB_HEADER_FLAGS equ MB_PAGE_ALIGN or MB_MEMORY_INFO or MB_VIDEO_REQUEST or MB_CHECKSUM equ -(MB_HEADER_MAGIC + MB_HEADER_FLAGS) ;; safe modes according to https://wiki.osdev.org/VESA_Video_Modes -VWIDTH equ 640 ; 640/720 -VHEIGHT equ 480 ; 480 -VDEPTH equ 32 ; 24/32 +VWIDTH equ 80 ; 640/720 +VHEIGHT equ 25 ; 480 +VDEPTH equ 0 ; 24/32, zero in textmode multiboot: dd MB_HEADER_MAGIC @@ -26,7 +26,7 @@ multiboot: dd bss_end ; bss end address dd start ; entry address - dd 0 ; video mode_type (0:fb, 1:txt) (set flags[2]!) + dd 1 ; video mode_type (0:fb, 1:txt) (set flags[2]!) dd VWIDTH ; video width dd VHEIGHT ; video height dd VDEPTH ; video depth @@ -39,132 +39,86 @@ start: ;push ebx ; mboot info struct addr ;push eax ; 0x2BADB002 - ;mov [mbootmagic], eax + mov [mbootmagic], eax ;mov [mbootaddr], ebx - ; store video info - mov ecx, [ebx+88] - mov [fb.addr], ecx - mov ecx, [ebx+98] - mov [fb.pitch], ecx - mov ecx, [ebx+100] - mov [fb.width], ecx - mov ecx, [ebx+104] - mov [fb.height], ecx - mov cl, [ebx+108] - mov [fb.depth], cl + call con_disable_cursor + call conclear - ; calculate bytespp - movzx eax, cl - mov cl, 8 - div byte cl - mov [fb.bytespp], al + mov esi, msg.roskainiting + call conwriteln - ; color component positions - mov cl, [ebx+110+2] - mov [fb.rpos], cl - ;mov cl, [ebx+111] - ;mov [fb.rmasksize], cl - mov cl, [ebx+112+2] - mov [fb.gpos], cl - ;mov cl, [ebx+113] - ;mov [fb.gmasksize], cl - mov cl, [ebx+114+2] - mov [fb.bpos], cl - ;mov cl, [ebx+115] - ;mov [fb.bmasksize], cl -testpixels: - ; construct pixel R - mov al, 0xff ;r - mov ah, 0x00 ;g - mov ch, 0x00 ;b - xor edx, edx ;final pixel - ;ebx is temp pixel - movzx ebx, al - mov cl, [fb.rpos] - shl ebx, cl - ;and ebx, [fb.rmasksize] - or edx, ebx - movzx ebx, ah - mov cl, [fb.gpos] - shl ebx, cl - ;and ebx, [fb.gmasksize] - or edx, ebx - movzx ebx, ch - mov cl, [fb.bpos] - shl ebx, cl - ;and ebx, [fb.bmasksize] - or edx, ebx - mov ecx, [fb.addr] - mov [ecx], edx - - ; construct pixel G - mov al, 0x00 ;r - mov ah, 0xff ;g - mov ch, 0x00 ;b - xor edx, edx ;final pixel - ;ebx is temp pixel - movzx ebx, al - mov cl, [fb.rpos] - shl ebx, cl - ;and ebx, [fb.rmasksize] - or edx, ebx - movzx ebx, ah - mov cl, [fb.gpos] - shl ebx, cl - ;and ebx, [fb.gmasksize] - or edx, ebx - movzx ebx, ch - mov cl, [fb.bpos] - shl ebx, cl - ;and ebx, [fb.bmasksize] - or edx, ebx - mov ecx, [fb.addr] - movzx ebx, [fb.bytespp] - add ecx, ebx - mov [ecx], edx - - ; construct pixel B - mov al, 0x00 ;r - mov ah, 0x00 ;g - mov ch, 0xff ;b - xor edx, edx ;final pixel - ;ebx is temp pixel - movzx ebx, al - mov cl, [fb.rpos] - shl ebx, cl - ;and ebx, [fb.rmasksize] - or edx, ebx - movzx ebx, ah - mov cl, [fb.gpos] - shl ebx, cl - ;and ebx, [fb.gmasksize] - or edx, ebx - movzx ebx, ch - mov cl, [fb.bpos] - shl ebx, cl - ;and ebx, [fb.bmasksize] - or edx, ebx - mov ecx, [fb.addr] - movzx ebx, [fb.bytespp] - add ecx, ebx - add ecx, ebx - mov [ecx], edx - - ;mov dword [edx], 0xff00ff00 -testpixels_end: hang: ;cli .loop: ;hlt jmp .loop -error: - mov dword [0xFD000000], 0x00FF0000 - jmp hang + +;give character in AL +conputchar: + mov ah, [txtbuf.col] + mov dx, ax + ; dx has the whole character cell now + xor eax, eax + mov al, [txtbuf.y] + mov bl, 25 + mul bl + movzx bx, [txtbuf.x] + add ax, bx + add ax, ax + add eax, 0xb8000 + mov [eax], dx + cmp bl, 24 + je connewline + inc bl + mov [txtbuf.x], bl + ret +conwriteln: + lodsb + cmp al, 0 + je connewline + call conputchar + jmp conwriteln +connewline: + mov [txtbuf.x], 0 + mov al, [txtbuf.y] + cmp al, 24 + je conscroll + inc al + mov [txtbuf.y], al + ret +conscroll: + ret + +conclear: + mov ecx, 80*25 + mov edi, 0xb8000 + mov ah, 0x07 + mov al, 0 + rep stosw + mov [txtbuf.col], ah + mov [txtbuf.x], 0 + mov [txtbuf.y], 0 + ret + +con_disable_cursor: + mov dx, 0x3D4 + mov al, 0xA ; low cursor shape register + out dx, al + + inc dx + mov al, 0x20 ; bits 6-7 unused, bit 5 disables the cursor, bits 0-4 control the cursor shape + out dx, al + ret mbootaddr: dd 0 mbootmagic: dd 0 +txtbuf: + .x db 0 + .y db 0 + .col db 0x07 ;gray on black + fb: .addr dd 0 .pitch dd 0 @@ -179,6 +133,9 @@ fb: .bpos db 0 ;.bmasksize db 0 +msg: + .roskainiting db "rOSka initializing...", 0 + align 4096 bss_start: align 4096