Implementing a buffer with history for a terminal

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
chbaker0
Posts: 2
Joined: Thu Dec 09, 2010 8:04 pm

Implementing a buffer with history for a terminal

Post by chbaker0 »

After a long hiatus, I've returned with renewed interested in OS dev. I'm just in the basics of it, and I'm wondering what you guys think is an efficient way to do this. I was thinking of having a large circular buffer of size 80 * (whatever number of lines) * 2 for the basic VGA text mode and having a pointer to the current "window" that will be visible. Then, displaying text would be done by copying the data at window pointer to the VGA buffer. By knowing the size of the buffer and the position of the window, it would be pretty easy to keep track of the history. What are some better ways of doing this?
User avatar
AndrewAPrice
Member
Member
Posts: 2303
Joined: Mon Jun 05, 2006 11:00 pm
Location: USA (and Australia)

Re: Implementing a buffer with history for a terminal

Post by AndrewAPrice »

Some ways;

..You could use a circular buffer of characters. Then have another buffer holding the character index of each line. Easy if you don't have dynamic memory allocation yet.
..You could have a linked list of string objects. This is probably the most flexible and easiest to implement, but requires dynamic memory allocation.
My OS is Perception.
User avatar
b.zaar
Member
Member
Posts: 294
Joined: Wed May 21, 2008 4:33 am
Location: Mars MTC +6:00
Contact:

Re: Implementing a buffer with history for a terminal

Post by b.zaar »

One simple way to implement a buffer requires paging. Say you are using a resolution of 80 * 25 * 2 so a full page of text equals 4000 bytes.

Allocate 3 pages for the buffer and use 4 entries in the page table set like the following:

Code: Select all

page[0] = 0;
page[1] = 4096;
page[2] = 8192;
page[3] = 0;


When you are half way through the 3rd page it automatically wraps back to the first page buffer. When your buffer tail > 16000 then reset the buffer head back inside page[0]
"God! Not Unix" - Richard Stallman

Website: venom Dev
OS project: venom OS
Hexadecimal Editor: hexed
Post Reply