andreasjhkarlsson / gbdk-n

gbdk libraries updated for newer versions of sdcc
174 stars 25 forks source link

Interrupt handler hangs #10

Open mmuszkow opened 7 years ago

mmuszkow commented 7 years ago

When I try to handle interrupts using the add_JOY, add_VBL etc. functions, the emulator (BGB) hangs after the handler is called for the first time. The code I used for test:

#include <gb/gb.h>
#include <gb/rand.h>

UINT8 tiles[64], i, jp;

void joypad_irq() {
    jp = joypad();
    set_bkg_tiles(0, 0, 1, 1, &jp);
}

void main() {
    disable_interrupts();
    DISPLAY_OFF;
    for(i=0; i<64; i++)
        tiles[i] = _rand();
    set_bkg_data(0, 128, tiles);
    SHOW_BKG;
    DISPLAY_ON;

    /* this hangs */
    add_JOY(joypad_irq);
    enable_interrupts();
    set_interrupts(JOY_IFLAG);
    while(1) { }

    /* this works */
    //enable_interrupts();
    //while(1) { joypad_irq(); }
}
robbi-blechdose commented 5 years ago

This might be related to how you use the hardware here. What does "set_interrupts()" do? Anyway, try moving it before the interrupt enabler, and put a halt (whatever the C equivalent is) into your loop.

basxto commented 4 years ago
set_interrupts(VBL_IFLAG | JOY_IFLAG);

I think set_bkg_data() needs VBL interrupt active for moving the data into VRAM

So it is likely that the emulator does not hang and you are just not getting any visual feedback.