PIC Problem [SOLVED]
Posted: Sun Feb 03, 2008 3:19 am
Hello, I am working on remapping pic and I am having some unknown problems with my C code. Right now the program displays a message once main has been given control.
Whenever I add this code:
to my video.c source:
My program prints out garbage on the screen instead of the intended message; even without calling the function remap_pics();. When I do call it:
The system crashes.
My out() and in() functions are both in my ports.c source:
Any help?
Code: Select all
void main()
{
cls(0x07);
printf(0x07, "Hello",1,1);
for(;;);
}
Code: Select all
void remap_pics()
{
/* send ICW1 */
out(0x20, 0x11);
out(0xA0, 0x11);
/* send ICW2 */
out(0x20 + 1, 0x20); //master
out(0xA0 + 1, 0x28); //slave
/* send ICW3 */
out(0x20 + 1, 4);
out(0xA0 + 1, 2);
/* send ICW4 */
out(0x20 + 1, 0x01);
out(0xA0 + 1, 0x01);
/* disable all IRQs */
out(0x20 + 1, 0xFF);
}
Code: Select all
//***********************
// Function: Clear the Screen
// Equivalent: cls();
//***********************
void cls(int color)
{
char *vga = (char *) 0xb8000;
unsigned int i=0;
while(i < (80*25*2))
{
vga[i]=' ';
i++;
vga[i]=color;
i++;
}
}
//*****************************
// Function: Print Formatted Strings
// Equivalent: printf();
//*****************************
void printf(unsigned char color, char *string, int x, int y)
{
char *vga = (char *) 0xb8000;
unsigned int i = 160*y + 2*x;
while (*string)
{
switch(*string)
{
case '\n': //newline
y++;
i = 160*y + 2*x;
*string++;
break;
}
//print formatted string
vga[i++] = *string++;
vga[i++] = color;
}
}
Code: Select all
void main()
{
cls(0x07);
printf(0x07, "Hello",1,1);
remap_pics();
for(;;);
}
My out() and in() functions are both in my ports.c source:
Code: Select all
unsigned char in(unsigned short _port) //input a byte
{
// "=a" (result) means: put AL register in variable result when finished
// "d" (_port) means: load EDX with _port
unsigned char result;
__asm__ __volatile__("in %%dx, %%al" : "=a" (result) : "d" (_port));
return result;
}
void out(unsigned short _port, unsigned char _data) //output a byte to a port
{
// "a" (_data) means: load EAX with _data
// "d" (_port) means: load EDX with _port
__asm__ __volatile__("out %%al, %%dx" : :"a" (_data), "d" (_port));
}