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).