Page 1 of 1

Printf help

Posted: Sat Sep 15, 2007 7:37 am
by thoover
ok this is driving me insane... ok each time i call the printf to print to screen, it comes up as well lets say crap none of the symbols i wanted, my putch command works fine, here is my text mode header and link.ld

Code: Select all

#define WHITE_TXT 0x07 // white on black text
typedef unsigned char byte;
byte *VGA=(byte *)0xA0000000L;


void ccls(int color)
{
	char *vidmem = (char *) 0xb8000;
	unsigned int i=0;
	while(i < (80*25*2))
	{
		vidmem[i]=' ';
		i++;
		vidmem[i]=color;
		i++;
	};
};

void cls() // clear the entire text screen
{
	char *vidmem = (char *) 0xb8000;
	unsigned int i=0;
	while(i < (80*25*2))
	{
		vidmem[i]=' ';
		i++;
		vidmem[i]=WHITE_TXT;
		i++;
	};
};

void putch(char ch, int pos, int color)
{
	char *vidmem = (char *) 0xb8000;
	vidmem[pos]=ch;
	vidmem[pos+1]=color;
};

void puts(int ch, int x, int y, int color)
{
	unsigned int i=0;
	char *vidmem = (char *) 0xb8000;
	i=(80*2*x)+(y*2);
	vidmem[i]=ch;
	vidmem[i+1]=color;
};

void pset(int x, int y, int color)
{
	VGA[y*320+x]=color;
};

void printf(int color, const char *string, int x, int y)
{
	char *vidmem=(char *)0xB8000;
	unsigned int i=(80*2*x)+(2*y);
	while(*string!=0)
	{
		vidmem[i]=*string;
		string++;
		i++;
		vidmem[i]=color;
		i++;
	};
};

&

Code: Select all

OUTPUT_FORMAT("binary")
ENTRY(start)
phys = 0x00100000;
SECTIONS
{
  .text phys : AT(phys) {
    code = .;
    *(.text)
    *(.rodata)
    . = ALIGN(16);
  }
  .data : AT(phys + (data - code))
  {
    data = .;
    *(.data)
    . = ALIGN(16);
  }
  .bss : AT(phys + (bss - code))
  {
    bss = .;
    *(.bss)
    . = ALIGN(16);
  }
  end = .;
}

Posted: Sat Sep 15, 2007 8:29 am
by Combuster
i=(80*2*x)+(y*2);
The display is ordered horizontally - you are printing vertically.
You probably wanted to use i = (160 * y + 2 * x)

Posted: Sat Sep 15, 2007 9:14 am
by thoover
well... that is not my problem, i knew it wasn't before i tried but i did try so you wouldn't get mad well my problem is not it finding the place its what chars it prints to the screen, it dosn't put a single char correctly and it is impossible to read anything, the only reason i came back here again was i got sick of writing one char at a time, i think my problem lies within the const char *string control is there a special way i compile for this i only use:

gcc -c ksmain.c -o ksmain.o

i tried:

gcc -Wall -O -fstrength-reduce -fomit-frame-pointer -finline-functions -nostdinc -fno-builtin -c -o kmain.o kmain.c

and got a worse result

Posted: Sat Sep 15, 2007 9:24 am
by Combuster
try passing at least -Wall -Wextra -pedantic -Werror to gcc.

Also, you are using function names that are from libc without giving them libc-compatible arguments, which is a Bad Thing (I once noticed that gcc optimizes libc calls - after hours of debugging I figured that it refused to use my implementation of those functions in some cases, that behaviour might be related...).

Posted: Sat Sep 22, 2007 6:38 pm
by thoover
Just fixed it, had to take const out of it, wow didn't think that would ever be the problem... (also i changed printf to print)