Page 1 of 1

Implementing a buffer with history for a terminal

Posted: Tue Nov 05, 2013 3:44 pm
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?

Re: Implementing a buffer with history for a terminal

Posted: Tue Nov 05, 2013 3:58 pm
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.

Re: Implementing a buffer with history for a terminal

Posted: Sat Nov 09, 2013 11:03 am
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]