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

Modulo operator don't work in interrupts #299

Open
FavoritoHJS opened this issue Dec 27, 2024 · 0 comments
Open

Modulo operator don't work in interrupts #299

FavoritoHJS opened this issue Dec 27, 2024 · 0 comments

Comments

@FavoritoHJS
Copy link

FavoritoHJS commented Dec 27, 2024

The function used (tcc_udiv) does not like having the direct page register being not zero, as one of its instructions uses absolute addressing and not the direct page addressing that the other instructions use.

The following is a small example based on the hello world example showing this. The value displayed should always be 0, 10 or 20 (remember, %x displays a number in hexadecimal), but it displays 70 instead.

There's a small hack with swapping out NMI routines since I don't know how to make new text display when using a custom NMI routine, if you can tell me how to do it I would appreciate it.

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


    Simple console 'hello world' demo
    -- alekmaul


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

extern char tilfont, palfont;
void (*oldnmi)(void);
u16 tileid;
//---------------------------------------------------------------------------------
void updateRowBuffer(void) {
    u16 temp = 4;
    /*This should never be greater than 0x20*/
    u16 tile = ( temp % 3 ) * 16;
    tileid = tile;
}
int main(void)
{
    // Initialize text console with our font
    consoleSetTextVramBGAdr(0x6800);
    consoleSetTextVramAdr(0x3000);
    consoleSetTextOffset(0x0100);
    consoleInitText(0, 16 * 2, &tilfont, &palfont);

    // Init background
    bgSetGfxPtr(0, 0x2000);
    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");

    oldnmi = nmi_handler;
    nmiSet(updateRowBuffer);
    WaitForVBlank();
    WaitForVBlank();
    consoleDrawText(5, 6, "%x", tileid);
    nmiSet(oldnmi);
    // Wait for nothing :P
    setScreenOn();
    while (1)
    {
        WaitForVBlank();
    }
    return 0;
}
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

1 participant