Help With my Kernel

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
KieranFoot

Help With my Kernel

Post by KieranFoot »

I need help with my kernel!!!

At the moment my kernel can write a string, change the cursor size and clear the text screen. I want to be able to Disable The Cursor, Set Cursor position and be able to renable the cursor.

There is a bug in my print string routine, i havent got the code with me since i'm at collage, but I would be gratefull for any code that does the same thing and is known to work.

I'v tried messing arround with the cursor resizing but I can never seem to get rid ofthe cursor. I'v tried Setting
DH and DL to 00

Code: Select all

MOV DH, 0
MOV DL, 0
All this seems to do is move the cursor either right to the top or right to the bottom!!!
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re:Help With my Kernel

Post by Solar »

Hm, that's not much information to work with (and my print function is C++ so it wouldn't help you).

But, do I understand correctly that you attempt to disable the cursor by moving it off-screen? I don't think that's possible; there should be a dedicated BIOS function to disable the cursor.

(Sorry, not much into the BIOS stuff myself, yet.)
Every good solution is obvious once you've found it.
thooot

Re:Help With my Kernel

Post by thooot »

Well, I'm going to assume that you're using real mode and BIOS functions. If so, here's a couple of functions that you can use as you see fit:

Code: Select all

; Hides the cursor
hide_cursor:
  mov ah, 0x01                  ; Interrupt function
  mov al, 0x03                  ; Current video mode
  mov ch, 0x23                  ; 2 = Invisible   3 = Start scan line
  mov cl, 0x04                  ; End scan line
  int 0x10  
  ret


; Shows the cursor
show_cursor:
  mov ah, 0x01                  ; Interrupt function
  mov al, 0x03                  ; Current video mode
  mov ch, 0x03                  ; 0 = Visible     3 = Start scan line
  mov cl, 0x04                  ; End scan line
  int 0x10  
  ret
  
  
; Clears the screen to black (space character)
cls:
  mov ax, 0x0720                ; Space character
  mov cx, 2000
  rep stosw
  
  mov [ds:cursorX], byte 0
  mov [ds:cursorY], byte 0
  
  call move_cursor
  
  ret
  
  
; Prints the 0-terminated string at ds:si
print_string:
  mov al, [ds:cursorY]
  mov bl, 160
  mul bl
  add al, [ds:cursorX]
  add al, [ds:cursorX]
  
  mov di, ax
   
print_loop:
  mov al, [ds:si]

  cmp al, 0                     ; End of string
  je print_done
  
  cmp al, 13                    ; Return character
  jne not_enter
  
  sub di, [ds:cursorX]
  sub di, [ds:cursorX]
  add di, 160                   ; Move to the next line
  inc si
  
  mov byte [ds:cursorX], 0
  inc byte [ds:cursorY]
  
  jmp print_loop
  
not_enter:
  mov ah, 0x07
  mov [es:di], ax
  
  add di, 2
  inc si
  inc byte [ds:cursorX]
  
  jmp print_loop
  
print_done:
  call move_cursor
  
  ret
  

; Moves the cursor to cursorX, cursorY
move_cursor:
  mov ah, 0x02                  ; Function #
  mov bh, 0x00                  ; Screen page
  mov dh, [ds:cursorY]
  mov dl, [ds:cursorX]
  int 0x10  
  ret
cursorX and cursorY are just one byte variables I have declared elsewhere. It is assumed that es:di points to location of the cursor on the screen. Also, these functions don't preserve registers (so you might want to add that it).
User avatar
Neo
Member
Member
Posts: 842
Joined: Wed Oct 18, 2006 9:01 am

Re:Help With my Kernel

Post by Neo »

If you are talking about real mode then i dont see why you need to bother with the cursor postion int13h seems to handle all this pretty well anyway if you need a string printing function for real mode i've attached mine it just needs the address of the null terminated string to be in SI and then call it.

Code: Select all

bios_print:
;_______________________________________________________________________________
;???BIOS Print Function for NULL terminated Strings????????????\
;???the NULL terminated string must be present in SI 
;-------------------------------------------------------------------------------
???push???ax??????; Save AX???
???push???bx??????; and BX registers???
ploop:
???cld
???lodsb?????????; AL = [DS:SI]???
   or ???al, al ??????; Set zero flag if al=0
???jz ???short pstop???; jump to stop if zero flag is set???
???mov ???ah, 0eh ???; video function 0Eh (print char)??????
???mov ???bx, 0007h ???; color??????????????????
???int ???10h??????; interrupt 10h for screen display??????
???jmp ???short ploop???; keep printing???????????????
pstop:??????????????????????????????
???pop???bx??????; Restore the BX????????????
???pop???ax??????; and AX Values???????????????
???retn?????????; end print and return????????????
;_______________________________________________________________________________/
if its the pmode print function you want mine is in C almost similar to the libc function (i c=used that as a model anyway) with adjustments in the cursor positioning etc. if thats what you want then let me know.
Only Human
KieranFoot

Re:Help With my Kernel

Post by KieranFoot »

Thanx Guys ;D ;D ;D ;D ;D ;D ;D
Post Reply