Moving Video Cursor/Calling BIOS Interrupts [Protected Mode]

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.
chibicitiberiu
Member
Member
Posts: 68
Joined: Thu May 28, 2009 11:46 pm

Re: OS dies when I try to move cursor.

Post by chibicitiberiu »

PatrickV wrote:You can move the cursor with inline assembly in your c file. This is one of the ways you can do this

Code: Select all

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);
}

outportb(0x3D4, 14);
outportb(0x3D5, temp >> 8);
outportb(0x3D4, 15);
outportb(0x3D5, temp);


Copying that exactly is not going to work. The code in red is the part you need to look at
Okay I'm stuck here. I don't get it, what do I have to do with these outportb instructions?

In the wiki article about this it says
Note, this quick example assumes 80x25 screen mode. Also note that the base port (here assumed to be 0x3D4) should be read from the BIOS data area.
So I have to do like this?

Code: Select all

unsigned short address = inportw (0x0463) // (2 bytes, taken as a word) base IO port for video
and then
outportb (address, 14)
outportb (address+1, temp>>8)
outportb (address, 15)
outportb (address+1, temp)
And my code for inportw function is:

Code: Select all

static __inline__ unsigned short inportw(unsigned short port)
{
   unsigned short ret;
   asm volatile ("inw %1,%0":"=a"(ret):"Nd"(port));
   return ret;
}
Where did I do wrong? If I try to put it in the first top half of the screen it doesn't appear, but if I try in the lower half it appears somewhere like (0, 15).
Last edited by chibicitiberiu on Wed Nov 04, 2009 3:13 am, edited 1 time in total.
Tibi,
Currently working on the Lux Operating System
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Moving Video Cursor/Calling BIOS Interrupts [Protected Mode]

Post by Combuster »

The Bios Data Area is located in main memory, not IO space.

Also, you can get/set the address needed directly from the VGA controller, which fixes the case where the bios doesn't match up with the hardware - see VGA Hardware about the VGA ports
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
chibicitiberiu
Member
Member
Posts: 68
Joined: Thu May 28, 2009 11:46 pm

Re: Moving Video Cursor/Calling BIOS Interrupts [Protected Mode]

Post by chibicitiberiu »

Okay so I replaced that with this:
unsigned short address = *((unsigned short *)0x0463)

and still doesn't work.
Tibi,
Currently working on the Lux Operating System
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Moving Video Cursor/Calling BIOS Interrupts [Protected Mode]

Post by Combuster »

Have you checked what value that returns? (which would be basic debugging)
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
chibicitiberiu
Member
Member
Posts: 68
Joined: Thu May 28, 2009 11:46 pm

Re: Moving Video Cursor/Calling BIOS Interrupts [Protected Mode]

Post by chibicitiberiu »

Combuster wrote:Have you checked what value that returns? (which would be basic debugging)
The address returned is 0x00D4. I tried in both a real and a virtual PC and same address, and same problem.
Tibi,
Currently working on the Lux Operating System
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Moving Video Cursor/Calling BIOS Interrupts [Protected Mode]

Post by Combuster »

I suggest you read VGA Hardware again, and figure what 0x3D4, 0x00D4 and 0x3B4 have in common...
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
jal
Member
Member
Posts: 1385
Joined: Wed Oct 31, 2007 9:09 am

Re: OS dies when I try to move cursor.

Post by jal »

chibicitiberiu wrote:Okay I'm stuck here. I don't get it, what do I have to do with these outportb instructions?
The fact that you don't get this implies that you are absolutely incapable of creating an operating system. Check the "needed skills" thread &.


JAL
Locked