Printf help

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
thoover
Posts: 14
Joined: Thu Nov 24, 2005 12:00 am
Location: A HOT PLACE CALLED HELL!!!
Contact:

Printf help

Post 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 = .;
}
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Post 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)
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
thoover
Posts: 14
Joined: Thu Nov 24, 2005 12:00 am
Location: A HOT PLACE CALLED HELL!!!
Contact:

Post 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
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Post 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...).
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
thoover
Posts: 14
Joined: Thu Nov 24, 2005 12:00 am
Location: A HOT PLACE CALLED HELL!!!
Contact:

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