Problems writing to video memory

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.
Post Reply
justin

Problems writing to video memory

Post 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
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re:Problems writing to video memory

Post by Solar »

No way to tell without seeing the source of printc...
Every good solution is obvious once you've found it.
kerim

Re:Problems writing to video memory

Post by kerim »

none of us is visionary, so post the printc code
justin

Re:Problems writing to video memory

Post 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.
beyondsociety

Re:Problems writing to video memory

Post 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.
pini

Re:Problems writing to video memory

Post 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)
Post Reply