printf function

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

printf function

Post 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.
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:printf function

Post 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.
John Thomas

Re:printf function

Post 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).
Ozguxxx

Re:printf function

Post 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?
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:printf function

Post 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;
}
Post Reply