I took a break from osdev for about 6 months becasue i couldn't get my text output to work, so you are not alone!
First you will need some way of handling where the cursor is on the screen. In my example code I'll just have a variable which contains the cursor position.
You should have "get_cursor" and "set_cursor" functions later on (to update the cursor on screen, not only your variable)...
Then you move the content of bx, which is char and color, to the adress of the cursor position that you have stored multiplied with 2 (1 byte char+1 byte attribute=cursor position*2) + 0xB8000 which is the text mode memory.
Formula: (cursor position*2)+0xB8000=char+attribute
Example:
Code: Select all
cursor_offset dw 0
;-----------------------------------------;
; print char ;
; in: bl = char, bh = attrib ;
;-----------------------------------------;
print_char:
push eax
cmp bl, 13
jne .cont
; call new_line ; This is where you should call your "new_line"
jmp .done
.cont:
cmp bl, 10 ; ignore
je .done
mov ax, word [cursor_offset] ; somehow get the cursor
; position and add it to eax
mov [es:(eax*2 + 0xB8000)], bx
add [cursor_offset], 1 ; add 1 to cursor position
.done:
pop eax
ret
To test this code you do like this:
Code: Select all
mov bh, 0x07
mov bl, 'T'
call print_char
mov bh, 0x07
mov bl, 'e'
call print_char
mov bh, 0x07
mov bl, 's'
call print_char
mov bh, 0x07
mov bl, 't'
call print_char
I hope that it helps you..
/ Christoffer