Page 2 of 2
Re: OS dies when I try to move cursor.
Posted: Wed Nov 04, 2009 2:51 am
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 >> ;
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).
Re: Moving Video Cursor/Calling BIOS Interrupts [Protected Mode]
Posted: Wed Nov 04, 2009 3:11 am
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
Re: Moving Video Cursor/Calling BIOS Interrupts [Protected Mode]
Posted: Wed Nov 04, 2009 3:26 am
by chibicitiberiu
Okay so I replaced that with this:
unsigned short address = *((unsigned short *)0x0463)
and still doesn't work.
Re: Moving Video Cursor/Calling BIOS Interrupts [Protected Mode]
Posted: Wed Nov 04, 2009 7:28 am
by Combuster
Have you checked what value that returns? (which would be basic debugging)
Re: Moving Video Cursor/Calling BIOS Interrupts [Protected Mode]
Posted: Thu Nov 05, 2009 1:04 am
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.
Re: Moving Video Cursor/Calling BIOS Interrupts [Protected Mode]
Posted: Thu Nov 05, 2009 1:52 am
by Combuster
I suggest you read
VGA Hardware again, and figure what 0x3D4, 0x00D4 and 0x3B4 have in common...
Re: OS dies when I try to move cursor.
Posted: Thu Nov 05, 2009 4:03 am
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