Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6130979
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:55:16+00:00 2026-05-23T16:55:16+00:00

What would be the fastest way to render characters in a framebuffer based console?

  • 0

What would be the fastest way to render characters in a framebuffer based console? I’m using the iso_font.h font from the XNU distribution.

Right now I’m using this code to render a character, but it doesn’t seem to be too efficient:

px = px* ISO_CHAR_WIDTH;
py = py* (ISO_CHAR_HEIGHT-1);

for (int i = 0; i < 15; i += 1) 
{
    int sym = iso_font[c*16+i];

    int x = px;
    int y = py + i;

    for (int ii =0; ii < 8; ii++) 
    {
        x+=1;
        if ((sym & (1 << ii)))
        {
            fb_set_px(x,y,fg);
        }
        else 
        {
            fb_set_px(x,y,bg);
        }

    }   
}

And I’m also wondering if this code could be simpliefied:

void fb_set_px(x,y,hex){
    void*ptr = ((_base + (_bpr*y) + (_bpe*x)));
    unsigned int *p = (unsigned int *) ptr;
    *p=hex;
}

It is decent up to the point where there are too many lines and I need to redraw the whole console (to scroll) at which point there is a significant delay.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T16:55:17+00:00Added an answer on May 23, 2026 at 4:55 pm

    Typically most hardware frame-buffers, such as the VGA frame buffer, have a hardware scrolling capability. Not only that, but some frame-buffers (not the VGA-character console unfortunately) will “wrap-around”, meaning when you write to the last byte (or bits) of the frame-buffer, and then write again to the first bytes (or bits) of the frame-buffer, those bytes will appear in the hardware as the next line on the screen. So there are a couple things you can do:

    1. Use the hardware scrolling capabilities of your frame-buffer to scroll to the next line when you get done. This means that you will first clear the next line of the frame-buffer, write the character that you need to on that line, and then increment the frame-buffer starting line pointer by one. This will then “appear” as though the frame-buffer has scrolled down a single line. When you get to the end of the frame buffer’s memory, keep the same process going, but the next line you’ll clear will be the first line in memory of the frame-buffer. You’ll then keep incrementing the starting address of the frame-buffer (this is still pointing somewhere near the end of the frame-buffer’s memory) until that too is pointing to the last line in memory of the frame-buffer, at which point you’ll then wrap around to the first line in memory.
    2. If your frame-buffer is still multi-page, but does not have a wrap-around capability (like the VGA character console), then keep a pointer to the start of the frame-buffer, and when you get to the last “page” in memory, use memcpy() to copy the last page in memory into the first page of the frame-buffer in memory … Once you’ve done that step, keep up the same page-scrolling routine where you clear the next line, and then increment the starting line pointer of the frame-buffer to give the illusion of scrolling up a single line. The page-copy will be a little slower than all the other hardware page-scrolls used up to that point, but memcpy() is very efficient, especially if you copy multiple bytes at a time using a larger memory-type like a long rather than a char.

    Next, as far as your access function fb_set_px goes, I would 1) make it inline inside a header file so that you avoid the overhead of an actual function call that requires using the stack to setup an activation frame, and 2) you could use the fact that your frame-buffer is just a memory array to actually map an array of pointers to some struct type that represents the per-character data layout of to your frame_buffer (i.e., some frame-buffers have a byte for a character and another byte for some type of attribute like color, etc. applied to the character). So for instance, you could do the following:

    typedef struct frame_buffer_t
    {
        unsigned char character;
        unsigned char attributes;
        //add or omit any fields that describe your frame-buffer data-layout
    } __attribute__((packed)) frame_buffer_t;
    
    //define as global variable
    //make volatile to avoid any compiler re-ordering
    unsigned volatile frame_buffer_t* framebuffer[MAX_ROWS_IN_FRAMEBUFFER];
    
    int main()
    {
        unsigned volatile frame_buffer_t* temp = global_frame_buffer_start_ptr;
    
        for (int i=0; i < MAX_ROWS_IN_FRAMEBUFFER; i++)
        {
            framebuffer[i] = temp;
            temp += NUM_COLUMNS;
        }
    
        //... more code
    }
    

    Now you can simply address a x,y position in your frame-buffer as

    framebuffer[Y_POS][X_POS].character = SOME_VALUE;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What would be the fastest way to list the names of files from 1000+
What would be the absolute fastest possible way to write a string to the
I would like to know what is the best, fastest and easiest way to
What would be the fastest way to search for a file programtically in C#.
What would be the fastest way to check for not 0 in an indexed
What would be the fastest way to add a new column in a large
What would be the fastest way to get the numerical format ( NOT THE
What would be the fastest way to search for a number (eg. 12.31) in
What would be the fastest way to sort a list that contains a list
What would be the fastest way to store List of type Point, in a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.