OSDev.org

The Place to Start for Operating System Developers
It is currently Sat Apr 27, 2024 3:11 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Issues with terminal scrolling in graphical mode
PostPosted: Mon Nov 06, 2023 1:50 pm 
Offline

Joined: Sun Jan 15, 2023 12:48 pm
Posts: 2
Hi, I'm new to OSDev and I setup a minimal kernel with BOOTBOOT and all it does so far is printing. For a few days, I've been trying to figure out how to copy a row of glyphs up by one row, like I managed in VGA mode, but it seems that my code only clears the line above.

(For context) How the glyphs are drawn:
Code:
void
kdrawc(char c, int x, int y, uint32_t color)
{
        uint8_t *glyph =        (uint8_t *) &BINARY_FONT_PSF_START
                                + font->header_size
                                + (c > 0 && c < font->num_glyph ? c : 0)
                                * font->bytes_per_glyph;

        int offset =    (y * font->height * bootboot.fb_scanline) +
                        (x * (font->width + 1) * sizeof(uint32_t));

        int bytes_per_line = (font->width + 7) / 8;

        for (int y = 0; y < font->height; ++y) {
                int line = offset;
                int mask = 1 << (font->width - 1);

                for (int x = 0; x < font->width; ++x) {
                        *((PIXEL *) ((uint64_t) &fb + line)) =
                        ((int) *glyph) & mask ? color : 0;

                        mask >>= 1;
                        line += sizeof(PIXEL);
                }

                glyph += bytes_per_line;
                offset += bootboot.fb_scanline;
        }
}


The function that's supposed to replace the destination line with the source line (possibly bad code quality):
Code:
void
kmoveline(int dst_line, int src_line)
{
        int dst_offset =        (dst_line * pfont->height * bootboot.fb_scanline) +
                                (0 * (pfont->width + 1) * sizeof(uint32_t));
       
        int src_offset =        (src_line * pfont->height * bootboot.fb_scanline) +
                                (0 * (pfont->width + 1) * sizeof(uint32_t));

        for (int dst_y = 0; dst_y < pfont->height; ++dst_y) {
                int dst_line = dst_offset;

                for (int src_y = 0; src_y < pfont->height; ++src_y) {
                        int src_line = src_offset;

                        for (int dst_x = 0; dst_x < (pfont->width + 1); ++dst_x) {

                                for (int src_x = 0; src_x < (pfont->width + 1); ++src_x) {
                                        *((PIXEL *) ((uint64_t) &fb + dst_line)) =
                                        *((PIXEL *) ((uint64_t) &fb + src_line));

                                        src_line += sizeof(PIXEL);
                                }
                                dst_line += sizeof(PIXEL);
                        }
                        src_offset += bootboot.fb_scanline;
                }
                dst_offset += bootboot.fb_scanline;
        }
}


I hope this is complete, but if I missed anything, let me know and I will provide any details.
Thank you in advance.

_________________
https://git.zun1.de/zun1/zunix


Top
 Profile  
 
 Post subject: Re: Issues with terminal scrolling in graphical mode
PostPosted: Tue Feb 13, 2024 11:14 am 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5146
Adjusting the source and destination pointers should happen at the same time. You've nested the source pointer calculation one loop deeper, which means instead of copying each source pixel to each destination pixel, you're copying entire characters to single pixels.

Also, since you're copying entire scanlines, you don't really need a nested loop for each character, you can just copy the whole scanline.

Also, reading the framebuffer is usually very slow, so you might be able to speed it up by saving the text somewhere and redrawing it instead of copying the already-drawn scanlines.


Top
 Profile  
 
 Post subject: Re: Issues with terminal scrolling in graphical mode
PostPosted: Tue Feb 13, 2024 2:55 pm 
Offline

Joined: Sun Jan 15, 2023 12:48 pm
Posts: 2
Octocontrabass wrote:
Adjusting the source and destination pointers should happen at the same time. You've nested the source pointer calculation one loop deeper, which means instead of copying each source pixel to each destination pixel, you're copying entire characters to single pixels.

Also, since you're copying entire scanlines, you don't really need a nested loop for each character, you can just copy the whole scanline.

Also, reading the framebuffer is usually very slow, so you might be able to speed it up by saving the text somewhere and redrawing it instead of copying the already-drawn scanlines.


Thank you very much, I've actually been able to make it work after writing this post (a few months ago) and I'll take your suggestions to heart!

_________________
https://git.zun1.de/zun1/zunix


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: Bing [Bot], SemrushBot [Bot] and 48 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