Cursor not moving
Posted: Thu Feb 18, 2010 3:23 pm
I'm trying to write a simple putchar function, and functions for moving the cursor. The cursor doesn't move at all though. Here is what i got:
Why isn't my cursor moving?
Code: Select all
#include "ports.h"
#include "video.h"
unsigned char color_fg = WHITE;
unsigned char color_bg = BLACK;
unsigned short cursor_xpos = 0;
unsigned short cursor_ypos = 0;
unsigned short screen_cols = 80;
unsigned short screen_rows = 25;
void set_fgcolor(unsigned char fg)
{
color_bg = fg;
}
void set_bgcolor(unsigned char bg)
{
color_bg = bg;
}
unsigned char get_fgcolor()
{
return color_fg;
}
unsigned char get_bgcolor()
{
return color_bg;
}
int get_color()
{
return (color_bg << 4) | (color_fg & 0x0F);
}
void move_hw_cursor(unsigned short x, unsigned short y)
{
unsigned short position = (y * screen_cols) + x;
outb(0x3D4, 0x0F);
outb(0x3D5, (unsigned char)(position&0xFF));
outb(0x3D4, 0x0E);
outb(0x3D5, (unsigned char )((position>>8)&0xFF));
}
void gotoX(unsigned short x)
{
cursor_xpos = x;
update_hw_cursor();
}
void gotoY(unsigned short y)
{
cursor_ypos = y;
update_hw_cursor();
}
void gotoXY(unsigned short x, unsigned short y)
{
gotoX(x);
gotoY(y);
}
unsigned short getX()
{
return cursor_xpos;
}
unsigned short getY()
{
return cursor_ypos;
}
void update_hw_cursor()
{
move_hw_cursor(getX(), getY());
}
unsigned short get_position()
{
return (getY() * screen_cols) * getX();
}
void putc(const char c)
{
// Read cursor position
unsigned short offset = get_position();
unsigned char *vidmem = (unsigned char *)0xB8000;
vidmem += (offset * 2);
*vidmem = c;
*++vidmem = get_color();
increment_cursor();
}
void increment_cursor()
{
if(getX() == 79)
{
gotoX(0);
gotoY(getY() + 1);
}
else
{
gotoX(getX() + 1);
}
}
void cls()
{
unsigned char *vidmem = (unsigned char *)0xB8000;
// Clear visible video memory
long loop;
for(loop = 0; loop < (screen_rows * screen_cols); loop++)
{
*vidmem++ = 0;
*vidmem++ = 0xF;
}
gotoXY(0, 0);
}