+
Skip to content

Improve page flipping explanation #107

@exelotl

Description

@exelotl

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载