OSDev.org

The Place to Start for Operating System Developers
It is currently Tue Dec 18, 2018 6:00 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: [solved] VGA Text Mode Scrolling
PostPosted: Tue May 08, 2018 3:03 pm 
Offline
Member
Member

Joined: Tue Apr 24, 2018 9:46 pm
Posts: 37
How does the VGA text buffer relate to the display? Is the buffer an array? If so does buffer[0..NCOLS] correspond to the top row of text displayed on the screen?

If so, why does this scrolling code work? If buffer[0..NCOLS] holds the oldest data (top row) and buffer[lastRow*NCOLS..NROWS*NCOLS] holds the most recent data (bottom row), shouldn't we be shifting the buffer elements by -row instead of +row?

Code:
void monitor_scrollUp ()
{
   int i;
   int lastRow = NROWS - 1;

   u16int spaceChar = m_attribute | 0x20;  // space character

   // Move the current text chunk that makes up the screen back in the buffer by a line
   for ( i = 0; i < NROWS * NCOLS; i += 1 )
   {
      videoMemory[ i ] = videoMemory[ i + NCOLS ];
   }

   // The last line should now be blank. Do this by writing 80 spaces to it
   for ( i = lastRow * NCOLS; i < NROWS * NCOLS; i += 1 )
   {
      videoMemory[ i ] = spaceChar;
   }

   // The cursor should now be on the last line
   cursorY = lastRow;
}


Re: OSDev Wiki, JamesM Kernel Tutorial


Last edited by quadrant on Wed May 09, 2018 12:59 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: VGA Text Mode Scrolling
PostPosted: Tue May 08, 2018 6:24 pm 
Offline

Joined: Mon Apr 09, 2018 7:09 am
Posts: 2
The buffer is a string of memory organized as you wrote: row 0 = 0 to NCOLS - 1, row 1 = NCOLS to NCOLS * 2 - 1. As for the code: it would work, but it should only copy NROWS - 1. The buffer elements are being shifted -1 row: i is initially 0, and videoMemory[i] is getting the value of the next row (i + NCOLS). So let's say you had a 5 column video display (NCOLS = 5), this is what's going on:
Code:
line 0 (address 0 to NCOLS - 1)        : *****
line 1 (address NCOLS to NCOLS * 2 - 1): 12345

videoMemory[0] = videoMemory[NCOLS + 0], line 0: 1****
videoMemory[1] = videoMemory[NCOLS + 1], line 0: 12***
videoMemory[2] = videoMemory[NCOLS + 2], line 0: 123**
videoMemory[3] = videoMemory[NCOLS + 3], line 0: 1234*
videoMemory[4] = videoMemory[NCOLS + 4], line 0: 12345


Top
 Profile  
 
 Post subject: Re: VGA Text Mode Scrolling
PostPosted: Wed May 09, 2018 12:59 pm 
Offline
Member
Member

Joined: Tue Apr 24, 2018 9:46 pm
Posts: 37
Ah, thank you! :)


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Google [Bot] and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group