OSDev.org

The Place to Start for Operating System Developers
It is currently Tue Mar 02, 2021 9:16 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 7 posts ] 
Author Message
 Post subject: Terminal scrolling
PostPosted: Mon May 18, 2020 9:40 am 
Offline
Member
Member
User avatar

Joined: Tue Feb 18, 2020 3:29 pm
Posts: 639
Hello,
I am implementing a graphical terminal driver, and was wondering how you scroll. I know how to scroll in text mode, but not graphical mode.
Thank you for your help.

_________________
Currently working on the Nexware project, an attempt to make a less bloated version of GNU. All repos for it can be found at https://github.com/Nexware-Project.


Top
 Profile  
 
 Post subject: Re: Terminal scrolling
PostPosted: Mon May 18, 2020 10:12 am 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 2813
It works the same regardless of mode.

Move the contents of your back buffer up one line, then copy it to the display adapter's frame buffer.

Or, if your terminal fills the whole screen and you have appropriate driver support, tell the display adapter to begin displaying one line lower in the frame buffer.


Top
 Profile  
 
 Post subject: Re: Terminal scrolling
PostPosted: Mon May 18, 2020 11:06 am 
Offline
Member
Member
User avatar

Joined: Mon Jun 05, 2006 11:00 pm
Posts: 2142
Location: USA (and Australia)
Have your terminal driver/emulator store an array of lines (start a new entry whenever your program prints '\n', and if you have a fixed size display you can also start a new entry after reaching the edge).

When you go to update the screen, start drawing backwards from the scroll position (where scroll offset '0' means you're at the bottom and showing the latest stuff.)

_________________
My OS is Perception.


Top
 Profile  
 
 Post subject: Re: Terminal scrolling
PostPosted: Sat May 23, 2020 7:48 am 
Offline
Member
Member
User avatar

Joined: Tue Feb 18, 2020 3:29 pm
Posts: 639
I have gotten it to scroll one pixel, but when it tries to scroll up one line of text, it will freeze and display garbage at the top of the screen. Here is the scrolling code:

Code:
void video_scroll()
{
    for(int i = 0; i < 8; i++)
    {
        int i = 0;
        for(i = 0; i < vid_info.framebufferWidth * (vid_info.framebufferHeight - 1); i++)
        {
            framebuffer[i] = framebuffer[i + vid_info.framebufferWidth];
        }
        for(int i = vid_info.framebufferWidth * (vid_info.framebufferHeight - 1); i < vid_info.framebufferWidth * vid_info.framebufferHeight; i++)
           framebuffer[i] = 0x000a3cc8;
    }
}

It loops 8 times, as that is the size of my font.

_________________
Currently working on the Nexware project, an attempt to make a less bloated version of GNU. All repos for it can be found at https://github.com/Nexware-Project.


Top
 Profile  
 
 Post subject: Re: Terminal scrolling
PostPosted: Sat May 23, 2020 10:21 am 
Offline
Member
Member
User avatar

Joined: Fri Nov 22, 2019 5:46 am
Posts: 576
You use the int variable i in three different contexts. That seems wrong to me.

Greetings
Peter

_________________
The "fanboy"
https://wiki.osdev.org/User:PeterX


Top
 Profile  
 
 Post subject: Re: Terminal scrolling
PostPosted: Sat May 23, 2020 10:51 am 
Offline
Member
Member

Joined: Mon Feb 02, 2015 7:11 pm
Posts: 570
You should scroll all 8 pixels rows in one loop, not do it 1 pixel row at a time. This would make you scrolling 8 times faster.

Here is how I do it (my own characters are 16 bits high) and the frame buffer is 32 bits/pixel.

Code:
void GraphicsConsole::Scroll() const
{
    // Scroll text
    for (int y = 16; y != m_backbuffer->height; ++y)
    {
        void* dest = (void*)(((uintptr_t)m_backbuffer->pixels) + (y - 16) * m_backbuffer->pitch);
        const void* src = (void*)(((uintptr_t)m_backbuffer->pixels) + y * m_backbuffer->pitch);
        memcpy(dest, src, m_backbuffer->width * 4);
    }

    // Erase last line
    for (int y = m_backbuffer->height - 16; y != m_backbuffer->height; ++y)
    {
        uint32_t* dest = (uint32_t*)(((uintptr_t)m_backbuffer->pixels) + y * m_backbuffer->pitch);
        for (int i = 0; i != m_backbuffer->width; ++i)
        {
            *dest++ = m_backgroundColor;
        }
    }
}

_________________
https://github.com/kiznit/rainbow-os


Top
 Profile  
 
 Post subject: Re: Terminal scrolling
PostPosted: Sat May 23, 2020 1:02 pm 
Offline
Member
Member
User avatar

Joined: Mon May 22, 2017 5:56 am
Posts: 546
kzinti wrote:
You should scroll all 8 pixels rows in one loop, not do it 1 pixel row at a time. This would make you scrolling 8 times faster.

Yes. And, not to rush you, but if you buffer the input, you can scroll the number of lines in the buffer. XTerm calls this "jumpscrolling", and it is insanely quick! I guess the buffering would be another thing to get right, though.

_________________
Kaph link pending. code pending. design pending. plans in a state of flux! everything pending! choice of language still up in the air! why is nothing coming together?!?


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

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 12 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