Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve page flipping explanation #107

Open
exelotl opened this issue May 27, 2024 · 1 comment
Open

Improve page flipping explanation #107

exelotl opened this issue May 27, 2024 · 1 comment

Comments

@exelotl
Copy link
Member

exelotl commented May 27, 2024

Suggested by @Kyrio on Discord:

I think we can make the page flipping explanation a little clearer. Tonc shows you this snippet but doesn't define most of the symbols used.

u16 *vid_flip()
{
    // toggle the write_buffer's page
    vid_page= (u16*)((u32)vid_page ^ VID_FLIP);
    REG_DISPCNT ^= DCNT_PAGE;            // update control register
    return vid_page;
}

The easy part is the register update, although Cearn doesn't waste time explaining that you can just xor the contents of DISPCNT with the offset of the page bit, and you get a nice toggle.

Now for the "hard" part. You are told that vid_page is your write buffer pointer, but we should probably mention that while it is declared by libtonc, you have to initialize it yourself (e.g. to vid_mem). I suppose it'd be more obvious if the following example used vid_page, but it doesn't.

More importantly, VID_FLIP is never defined. It's not a libtonc symbol and without further details, it's hard to tell what this line is actually doing. I think we can safely replace it with VRAM_PAGE_SIZE, and point out that the XOR lets you add or remove the page size offset.

What do you think?

@avivace
Copy link
Member

avivace commented May 30, 2024

Agree!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants