moving cursor

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
kerim

moving cursor

Post by kerim »

can anyone give me low level assembler code for moving a cursor on the screen ?
Adek336

RE:moving cursor

Post by Adek336 »

Sure.


It's in Sphinx, but I think it's self-explainatory.

void gotoxy(byte x, y)
{
BX = y * 80;   // this counts the
BX += x;       // cursor pos
BX -= 81;      // on screen

$ MOV DX, 0x3d4  // set low
$ MOV AL, 0xf    // byte of
$ OUT DX, AL     // cursor position

$ MOV DX, 0x3d5  // send the
$ MOV AL, BL     // low
$ OUT DX, AL     // byte

$ MOV DX, 0x3d4  // set the
$ MOV AL, 0xe    // high
$ OUT DX, AL     // byte

$ MOV DX, 0x3d5  // now
$ MOV AL, BH     // send
$ OUT DX, AL     // it
}

Getting the actual xPos and yPos is also simple, I think you'll figure it out yourself.

Hope it helps,
Adrian.
Code Slasher

RE:moving cursor

Post by Code Slasher »

You have to add the start screen address of the visible page to the X and Y positions. ie
In mode 0x03, we have 8 pages of Vram. the first starts at 0x0b8000, the next one if 80*25*2(4000)bytes after that, and it continues until the end of Vram.
page 1 starts =0x0B8000
page 2 starts =0x0B8FA0
page 3 starts =0x0B9FA0
.....
.....
so to put the cursor at (3,2) in page 1, before writing the low and high parts for X and Y, you have to add  0x0B8000 to each one.      

Also
BX = y * 80;   // this counts the
BX += x;       // cursor pos
BX -= 81;      // on screen

should be

BX=y*160 //the are 2 bytes per postion on a line,
BX += x*2;      // cursor pos(same reason as above)
BX -= 81;      // on screen (I'm not sure about this line)
Adek336

RE:moving cursor

Post by Adek336 »

is it so?

I'm no good at hardware programming, but the the version I've given worked well for me.

BX -= 81;      // on screen (I'm not sure about this line)
This is neccessary when X and Y is in the range from 1..80, 1..25 and the hardware controller would like to have 0..79 and 0..24. Without this line gotoxy(a,b) is the same as gotoxy(a+1, b+1) with the line.

Adrian
Post Reply