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.
I used the Tutorial from www.osdever.net labeled Kernel in C++.
after following it (and noticing there is only 2 of the 4 parts) I started to implement my own code. I added a newline function but when I execute it all it does is move the next printed string one spot to the right. the tutorial says that the:
undefined int off;
should move the cursor or message down a line. but when I use my function it does not do so. It does the same thing as the pos integer (undefined int pos;)
#ifndef VIDEO_H
#define VIDEO_H //only one definition of Video
class Video
{
public:
Video();
~Video();
int newline();
void clear();
void write(char *cp);
void cout(char *cp);
void put(char c);
private:
unsigned short *videomem ;
unsigned int off ;
unsigned int pos ;
};
#endif
okay, I noticed in your put(char c) function that you increment off by 80 so that you don't have to mulitply it at the last moment. but in your newline function you only use off++ so you are adding one to your offset. this will move the text over one character instead of down one line.
on a side note. you could use a switch statement or an if..else statement to keep an eye out for /n the newline character and run your newline function when that character is encountered. then you wouldn't require two functions for basically the same function. the same could go for your clear function. you could select a special character /C or something that when encountered would clear the screen. or you could just make a call to the function outside of your write function.
Out of interest, how do you deal with memory allocation in this? Presumably std::hex needs to allocate space for a char array and free it later, or does it just use a static array?
Ok now that I hae the newline() function working I seem to have developed a new problem...The cursor (The blinking line) does'nt seem to move as a result of the changes in pos and off...how would I go about moving the cursor. After I boot my Kernel from GRUB it just stays in whatever position it was last in. Any Ideas?
"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 ]
after adding the code to my video driver it now says that outb is not declared...after much trying i looked about at other tutorials, they do not declare it either....
...other than allowing gcc to pick two registers at will where it can not...
the instructions you should have are
out dx, al
out dx, ax
out dx, eax
(in order: outb, outw, outl)
in al, dx
in ax, dx
in eax, dx
(inb, inw, inl)
But I suck at GCC inline assembly so I can't give the correct implementation.
"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 ]
it compiles nicely, yet it seems to do nothing. the cursor is still WAY at the bottom...hmmm...Is it possible to call functions declared in a ASM file?
if so there may be a way.
I use NASM and VC++ so I would compile the ASM file with the following
C:\OS Design\nasm -f win32 functions.h
then I have to make sure and add the resulting functions.obj to my project. I know it will be slightly differrent for you but the ability is there. check out brans tutorial on osdever.net for a way to do the same thing using NASM and GCC. good luck