Page 1 of 1
printf function
Posted: Thu Mar 13, 2003 1:59 pm
by slacker
when i call a printf function is there a technique i can use to save the last location of the chracter printed to memory so that when i call printf again, it will start printing after the last char printed before.
Re:printf function
Posted: Thu Mar 13, 2003 2:13 pm
by Pype.Clicker
Yes. Store the offset of the next output in a static variable (top-level) rather than in an automatic (function-hosted) variable.
Re:printf function
Posted: Sun Mar 16, 2003 7:12 pm
by John Thomas
Or two statics (x, y) if you want to be able to position them anywhere on the screen. That would probably be better done in a console driver, so everything works correctly when you go from 80x25 to another mode.
That way, if you hit a \n character, then it's simply a matter of setting x to 0 and adding 1 to y to perform a crlf (carriage return, line feed).
Re:printf function
Posted: Mon Mar 17, 2003 2:16 am
by Ozguxxx
Hi, I am just trying to figure out for some days what the situation will be when implementing virtual consoles in that case since screen output will be a kind of shared resource we will have some problems;
- Our console driver should be aware of the fact that no two consoles should be able to access(write) video memory at the same time.
- (a result of first one) While doing some of your jobs with one virtual console other console's(or consoles') output should be directed to somewhere else like screen buffer of virtual consoles.
- When one virtual console are called back to screen, screen contents should be copied into currently running virtual console's screen buffer and the screen buffer of console that will be run newly should be copied back to actual video memory.
These are all my ideas, I havent currently read Tanenbaum's approach on these... So I think console driver cannot be as simple as keeping two static variables for output if one is to implement virtual consoles, it should also take these synchronization thing into consideration. (Right?) So what do you think, what is your way of implementing virtual consoles?
Re:printf function
Posted: Mon Mar 17, 2003 2:36 am
by Pype.Clicker
if you plan to have several virtual consoles, then store the offset of the next char to be written within the vconsole structure.
When you print to a console, you always print into its private memory structure.
If you're really worried about consistent display, you could for instance disable interrupts while you're copying things to the virtualscreen memory.
When a console switch is asked by the user, you just
Code: Select all
static console* curr_console;
switchto(console *next_console) {
memcpy (curr_console->data,screen,80*25*2);
memcpy (screen,next_console->data,80*25*2);
curr_console->active=curr_console->data;
next_console->active=screen;
curr_console=next_console;
}