Skip to content

bgSetMapPtr can corrupt other layer's tile address, or the scroll offset of the first layer #300

@FavoritoHJS

Description

@FavoritoHJS

This ocurrs as writes to BG12NBA and BG34NBA are done in 16-bit mode, while these are 8-bit registers, resulting in an incorrect write to the byte above - BG34NBA for BG1 and BG2, and BG0HOFS for BG3 and BG4

Example program:

/*---------------------------------------------------------------------------------


    Simple console 'hello world' demo
    -- alekmaul


---------------------------------------------------------------------------------*/
#include <snes.h>

extern char tilfont, palfont;
//---------------------------------------------------------------------------------
int main(void)
{
    // Initialize text console with our font
    consoleSetTextVramBGAdr(0x6800);
    consoleSetTextVramAdr(0x3000);
    consoleSetTextOffset(0x0100);
    consoleInitText(0, 16 * 2, &tilfont, &palfont);

    bgSetGfxPtr(2, 0x4000);
    /*If you pause in a debugger, BG34NBA has been loaded correcty*/
    consoleMesenBreakpoint();
    // Init background
    bgSetGfxPtr(0, 0x2000);
    /*and now, it has been corrupted.*/
    consoleMesenBreakpoint();
    bgSetMapPtr(0, 0x6800, SC_32x32);

    // Now Put in 16 color mode and disable Bgs except current
    setMode(BG_MODE1, 0);
    bgSetDisable(1);
    bgSetDisable(2);
    // Draw a wonderful text :P
    consoleDrawText(10, 10, "Hello World !");
    consoleDrawText(6, 14, "WELCOME TO PVSNESLIB");
    consoleDrawText(3, 18, "HTTPS://WWW.PORTABLEDEV.COM");
    // Wait for nothing :P
    setScreenOn();
    while (1)
    {
        WaitForVBlank();
    }
    return 0;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions