I have a little problem with my printf function, it prints only Genuin instead of printing GenuineIntel on the screen .
But if I use print ( without stdarg ), it works properly .
What's wrong please ?
Thanks .
PS : Here's my code :
Code: Select all
#include <stdarg.h>
void clrscr ();
void scroll ();
void print (const char*);
void printf (int, ...);
extern void get_vendor (char*);
unsigned int x=0;
unsigned int y=0;
int kernel_main(void)
{
char buffer[13];
clrscr();
get_vendor(buffer);
printf(3,"\n>CPU Vendor : ",buffer,"\n");
while(1);
return(0);
}
void clrscr (){
int i;
unsigned char* screen = (unsigned char *) 0xB8000;
for (i=0;i<80*25;i++){
*screen++=0x0;
*screen++=0x07;
}
}
void scroll()
{
int i;
unsigned char *screen = (unsigned char*) 0xB8000;
for (i = 0*80; i < 24*80; i++)
{
screen[i] = screen[i+160];
}
for (i = 24*80; i < 25*80; i++)
{
screen[i] = 0;
}
y = 24;
}
void printf( int n, ... ){
va_list ap;
int i=0;
va_start(ap, n);
for( ; n>0 ; n--) print(va_arg(ap, const char* ));
va_end(ap);
}
void print( const char* chaine )
{
int i;
unsigned char* screen = (unsigned char*) (0xB8000+y*160+x*2);
while ( *chaine ){
if (*chaine == 0xA ){ // LF : 0x0A
x=0;
y++;
screen=(unsigned char*) (0xB8000+y*160);
chaine++;
} else {
*(screen++)=*(chaine++);
*(screen++)=0x07;
x++;
}
if (x>=79){
x=0;
y++;
}
if (y>=24){
scroll();
y=1;
}
}
}