putchar problem

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
tbone

putchar problem

Post by tbone »

I've wrote a printf function and it works really strange. On Bochs it prints everything nice and on my 486sx it prints nice, but on my duron 650 mhz when it wants to print the computer resets. I think that the problem is with the putchar function. Here is the code:
void putchar(char c)
{
   unsigned att;
   att= 0x02 << 8;
   
   if ( c == 0x08 )
   {
      if ( curX != 0 )
         curX--;

      else if ( curX == 0 && curY > 0 )
      {
         curY--;
         curX = scrwidth - 1;   
            update_cursor();
            return;
      }
   }
   else if ( c == 0x09 )
   {
      curX += 4;   
   }

   else if ( c == '\r' )
   {
      curX = 0;
   }
   else if ( c == '\n' )      
   {
      curX = 0;
      curY++;
   }
   else if ( c >= ' ' )
   {
      unsigned short *where;

      where = vgaadr + ( curY * scrwidth + curX );
      *where = c | att;
      curX++;
   }

   if ( curX >= scrwidth )
   {
      curX = 0;
      curY++;
   }

   update_cursor();
}
jrfritz

Re:putchar problem

Post by jrfritz »

Strange...seems that the video card is non standard on the computer that resets? Think so anyone?
tbone

Re:putchar problem

Post by tbone »

I have a geforce 2 mx 32mb on my duron.when using the code from osdev.neopages.net:
unsigned int k_printf(char *message, unsigned int line) // the message and then the line #
{
   char *vidmem = (char *) 0xb8000;
   unsigned int i=0;

   i=(line*80*2);

   while(*message!=0)
   {
      if(*message=='\n') // check for a new line
      {
         line++;
         i=(line*80*2);
         *message++;
      } else {
         vidmem=*message;
         *message++;
         i++;
         vidmem=WHITE_TXT;
         i++;
      };
   };

   return(1);
}
it works fine.
Slasher

Re:putchar problem

Post by Slasher »

Then the problem is somewhere else! :(
Best bet, start to trace the cod manually, start from your kernel's main function, and follow each function call, check each function as you go along. I had problems with my output code but the bug was in my link list updating function, so you can see what i mean!
Post Reply