Page 1 of 1

Problems writing to video memory

Posted: Sun Jul 10, 2005 11:12 pm
by justin
I am new to OS programming and I am having some problems writing to the video memory. The following code functions correctly. It detects a 1.44mb floppy drive and prints "drivelocated" (with the attribute 0xC).

Code: Select all

int main()
{ 
   const char * msg1  = "drivelocated";
   clrscr();
   if(Exist144Floppy())
      printc(msg1,0xC);
   for(;;);
   return 0;
}
However, if I change msg1 to "drivefound", it fails and resets my computer. It also fails if I add a space and make it "drive located". I believe I have my problem narrowed down to the letter "u" in "drivefound". Can someone explain to me why certain strings work just fine and others reset the computer?

Thank you,
Justin

Re:Problems writing to video memory

Posted: Sun Jul 10, 2005 11:47 pm
by Solar
No way to tell without seeing the source of printc...

Re:Problems writing to video memory

Posted: Sun Jul 10, 2005 11:56 pm
by kerim
none of us is visionary, so post the printc code

Re:Problems writing to video memory

Posted: Mon Jul 11, 2005 8:47 am
by justin
Sorry 'bout that. Here is the code for printc:

Code: Select all

void printc(const char * message,const char color)
{
   unsigned long i;
   unsigned char *vidmem = (unsigned char *)0xB8000;
   for (i=0;message[i] != 0;i++) {
      *vidmem = message[i];
      vidmem++;
      *vidmem = color;
      vidmem++;
   }
}
I shaved it down to this and it still doesn't work.

Re:Problems writing to video memory

Posted: Mon Jul 11, 2005 3:50 pm
by beyondsociety
What settings do you use when you link your kernel? Because on my kernel project it works fine if I change msg1 = drivelocated and print it.

Code: Select all

const char *drivefound = "drivelocated";
printc(drivefound,0xC);
Two ways of doing the basic printc function:

Code: Select all

Your way, just smaller
void printc(const char *message, const char color)
{
       unsigned long i;
       unsigned char *vidmem = (unsigned char *) 0xB8000;

       for(i = 0; message[i] != 0; i++) 
       {
???      *vidmem++ = message[i];
???      *vidmem++ = color;
       }
}

Code: Select all

Or the way I do it
void printc(const char *message, const char color)
{
       unsigned long i;
       unsigned char *vidmem = (unsigned char *) 0xb8000;

       while(*message != 0)
      {
???       vidmem[i++] = *message++;
???       vidmem[i++] = color;
      }
}
Hope this helps.

Re:Problems writing to video memory

Posted: Tue Jul 12, 2005 2:05 am
by pini
Urg... you'd better initialize your 'i' counter in the second solution, our you'll get bad bad results :), or use this instead :

Code: Select all

void printc(const char *message, const char color)
{
      unsigned char *vidmem = (unsigned char *) 0xb8000;

      while(*message != 0)
      {
         *vidmem++ = *message++;
         *vidmem++ = color;
      }
}
(though I'm not sure if this works... I'm better at ASM than at C ;D)