On CG50 gint utilizes a triple-buffer mechanism to speed up rendering by DMA transfering one of the back buffers to display while allowing client code to write to the other at the same time. Except being swapped in and out between the two, they are apparently independ to each other, eg. there is no pixel copy when `dupdate()`. This is suitable for frame based applications like games.

In one of my add-ins I simply disabled triple-buffering (to save one `memcpy()` call), but the calc would reboot in a few seconds each time when the add-in was launched.

Anyone ever encountered the same problem please advise?

Here is the relevant
Code:


static void print(const char *buf, int len) {
#define LINE_HEIGHT     16

    static struct {
        bool init;
        int x, y;
    } a = { .init = false, };

    if (!a.init) {
        a.init = true;
        a.x = 0;
        a.y = LINE_HEIGHT;

        // Disable triple buffer
        uint16_t *vram1, *vram2;
        dgetvram(&vram1, &vram2);
        dsetvram(vram1, NULL);

        dclear(C_WHITE);
        dupdate();
    }

    int x1 = a.x;
    int y1 = a.y;

    int len1 = 0;
    while (len1 < len) {
        int w;
        dnsize(buf + len1, 1, NULL, &w, NULL);

        int max_w = DWIDTH - x1;
        if (w > max_w) {
            x1 = 0;
            y1 += LINE_HEIGHT;
            if (y1 >= DHEIGHT) {
                dupdate();
                dclear(C_WHITE);
                dupdate();
                y1 = LINE_HEIGHT;
            }
        }

        dtext_opt(x1, y1, C_BLACK, C_NONE, DTEXT_LEFT, DTEXT_BOTTOM, buf + len1, 1);
        x1 += w;
        len1++;
    } // while

    dupdate();

    a.x = x1;
    a.y = y1;

#undef LINE_HEIGHT
}


Thanks!
I noticed recently that despite what's being advertised in the prototype, you need to set both pointers for it to works:


Code:
dsetvram(vram1, vram1);

I am planning to make double-buffering back the default in the next version. This is because, while it was believed years ago that the performance boost from triple buffering could be reaped "transparently" just by running C code, performance testing in various add-ins since have shown that this is far from the case, and the boost that you get is debatable at best.
Lephe wrote:


Code:
dsetvram(vram1, vram1);


This does the trick. Thanks! Good Idea
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
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 vote in polls in this forum

 

Advertisement