c kernel--printf 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
slacker

c kernel--printf problem

Post by slacker »

for some reason when i use a pointer to a char to specify a string to print the copmuter reboots..any ideas?

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
main kernel

#include "text.h"

asm("jmp _main");


int main()
{
char *temp="hello";
print(temp);
return 0;
};
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
print function..................
CURLINE, CURPOS = start of text output


void print(char *string) //uses curline, curpos
{
char *vidmem;
vidmem=(char *) 0xb8000;

while(*string!=0)
{
if(CURLINE==(MAXLINE+1))
{
scrolldown();
CURLINE--;
};

if(CURPOS<80)
{
vidmem[((CURLINE*160)+(CURPOS*2))]=*string;
vidmem[((CURLINE*160)+(CURPOS*2) + 1)]=BACKROUND;
*string++;
CURPOS++;
};

if(CURPOS==80)
{
CURPOS=0;

if(CURLINE==MAXLINE)
{
scrolldown();
CURLINE--;
};

CURLINE++;
};
};
};
stonedzealot

Re:c kernel--printf problem

Post by stonedzealot »

The sole thing that I can see is on this line:

Code: Select all

  *string++;


And that's just because I didn't do it that way, but I think it should be string++ (no asterisk). I can't imagine this would cause the computer to reboot, especially if the line got through your compiler. Hey, stranger things have happened. Sorry I can't be of more help.
gtsphere

Re:c kernel--printf problem

Post by gtsphere »

*string++;

that could possibly reboot the machine by causing a trap if the memory location the string is at isn't there, or incrementing goes over a boundary.

As for the printing problem, i am somewhat lost of what these lines are attempting to do:

vidmem[((CURLINE*160)+(CURPOS*2))]=*string;
vidmem[((CURLINE*160)+(CURPOS*2) + 1)] = BACKROUND;
so that is saying, make that vidmem[...] = *string? I am not too sure but I don't believe you want to make all of that simply equal "hello". I believe that you might have those backwards.

I hope this helps figure that out.
-GT
Ozguxxx

Re:c kernel--printf problem

Post by Ozguxxx »

I think *string++; does not cause any problem because what compiler ++ operator has more precedence than * operator so, this expression will increase address string is pointing to and then return the value at the PREVIOUS address that it is pointing to. As far as I know about c I could not see a problem about the code, however if you have enabled paging this might cause a page fault but this is very unlikely I mean your string should be crossing a page boundary, I advice you to comment out all the lines that you think are working and then try to find which line is not working... Hope this helps... Good luck.
slacker

Re:c kernel--printf problem

Post by slacker »

FOR GT....

vidmem[((CURLINE*160)+(CURPOS*2))]=*string;
vidmem[((CURLINE*160)+(CURPOS*2) + 1)] = BACKROUND;

80x25 = screen

CURLINE*2 will calc the offset beginning at the current line number. CURPOS *2 will calc the offset and add it to the curline

ex.

say i wanted to print text on line 2 but start printing text 5 spaces from the left.

CURLINE = 2
CURPOS = 5

since each line has 160 bytes....CURLINE*160 will give the offset of the line.

CURPOS will be added to curline to get an offset. it is multiplied by two because i dont count the attribute byte as a position. its easier to print text this way. i think :(
slacker

Re:c kernel--printf problem

Post by slacker »

it might also help to know that it works with ...

print("slacker's os");

but not with variables..
print(variable);
slacker

Re:c kernel--printf problem

Post by slacker »

ok people. im a dumbshit.

i needed to have my ASM code first.....
thanks for your help..it works now..


asm("jmp _start");

#include "text.h"

void start()
{
char *temp="hello joe, my name is bill";
clear();
CURLINE=3;
CURPOS=0;

print("hello my name is joe");
print(temp);
asm("hlt");

};
Post Reply