cursor operation in protected mode using ports

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
spectrum
Member
Member
Posts: 37
Joined: Wed Jun 13, 2007 7:06 am

cursor operation in protected mode using ports

Post by spectrum »

hi all,

i was trying to set the cursor blinking on the screen, in a certain position. I've read documentation aboud ports 0x3d4 0x3d5, but they are not really human-readable, so i'm getting no success. I' haven't understand how to move the cursor on a certain row, column, and how to make it blink.

So i'm looking for some easy sample.

Many thanks,
angelo
Pyrofan1
Member
Member
Posts: 234
Joined: Sun Apr 29, 2007 1:13 am

Post by Pyrofan1 »

this is from Bran's kernel tut

Code: Select all

/* Updates the hardware cursor: the little blinking line
*  on the screen under the last character pressed! */
void move_csr(void)
{
    unsigned temp;

    /* The equation for finding the index in a linear
    *  chunk of memory can be represented by:
    *  Index = [(y * width) + x] */
    temp = csr_y * 80 + csr_x;

    /* This sends a command to indicies 14 and 15 in the
    *  CRT Control Register of the VGA controller. These
    *  are the high and low bytes of the index that show
    *  where the hardware cursor is to be 'blinking'. To
    *  learn more, you should look up some VGA specific
    *  programming documents. A great start to graphics:
    *  http://www.brackeen.com/home/vga */
    outportb(0x3D4, 14);
    outportb(0x3D5, temp >> 8);
    outportb(0x3D4, 15);
    outportb(0x3D5, temp);
}
User avatar
Dex
Member
Member
Posts: 1444
Joined: Fri Jan 27, 2006 12:00 am
Contact:

Post by Dex »

Assembly snip-it

Code: Select all

 ;'''''''''''''''''''''''''''''''''''''''''''''''''''';
 ; Sets cursor pos                                    ;
 ;----------------------------------------------------;
 ;                                                    ;
 ;  Input:                                            ;
 ;     [screen_x]    points to X                      ;
 ;                                                    ;
 ;     [screen_Y]    points to Y                      ;
 ;                                                    ;
 ; Output:                                            ;
 ;      None.                                         ;
 ;....................................................;

set_cursor_pos:
	push  eax
	push  ebx
	push  ecx
	push  edx
	xor   ebx,ebx
	mov   bl,[screen_x]
	mov   ecx,ebx
	mov   bl,[screen_y]
	mov   eax,80
	mul   bx
	add   eax,ecx
	mov   edx,0x3d4
	mov   ecx,eax
	mov   al,0x0f
	out   dx,al
	mov   eax,ecx
	inc   edx
	out   dx,al
	mov   al,0x0e
	dec   edx
	out   dx,al
	mov   eax,ecx
	mov   al,ah
	inc   edx
	out   dx,al
	pop   edx
	pop   ecx
	pop   ebx
	pop   eax
	ret

spectrum
Member
Member
Posts: 37
Joined: Wed Jun 13, 2007 7:06 am

Post by spectrum »

ok, thanks

thatt works, now i can move my cusrsor right,

but for make it blink ?
User avatar
Dex
Member
Member
Posts: 1444
Joined: Fri Jan 27, 2006 12:00 am
Contact:

Post by Dex »

May be like this

Code: Select all

;--------------------------------------;
;  change cursor attribs               ;
;            in: bx = cursor attribs   ;
;--------------------------------------;
changecursor:
	  push	  ax
	  push	  dx

	  mov	  dx, 0x3D4
	  mov	  al, 0x0A
	  mov	  ah, bh
	  out	  dx, ax
	  inc	  ax
	  mov	  ah, bl
	  out	  dx, ax

	  pop	  dx
	  pop	  ax
	  ret
Post Reply