Dolphin, the GameCube and Wii emulator - Forums
Programming Discussion Thread - Printable Version

+- Dolphin, the GameCube and Wii emulator - Forums (https://forums.dolphin-emu.org)
+-- Forum: Offtopic (https://forums.dolphin-emu.org/Forum-offtopic)
+--- Forum: Delfino Plaza (https://forums.dolphin-emu.org/Forum-delfino-plaza)
+--- Thread: Programming Discussion Thread (/Thread-programming-discussion-thread)



RE: Programming Discussion Thread - Leo - 02-19-2013

(02-19-2013, 12:01 AM)neobrain Wrote: Qt!
Is it really flexible? I'll search for it, then, try to get started. I'm tired of wxWidgets.


Just a question that I can't put out of my mind...
Does interrupts get queued when they are disabled, until the next EI?
Or they are simply ignored?
Because, if they are ignored, some timing events(such as the lcdc int)can get out of sync!!!


RE: Programming Discussion Thread - neobrain - 02-19-2013

Just try it out, but imo when it comes to GUI toolkits, nothing beats Qt. It's a matter of taste because some people say the large size of the SDK and the requirement of the moc compiler step suck, but IMO the latter really is a non-issue and not using qt because of that is just stupid. And the large SDK also is a non-issue for linux users Wink


RE: Programming Discussion Thread - AnyOldName3 - 02-20-2013

On the subject of GUIs, does anyone know how to use JList in Java? I tried using one yesterday, but (partly because I was pretty sleepy) found things confusing. I'm also going to need it to scroll, as the list won't fit in the space I have available for it.


RE: Programming Discussion Thread - Shonumi - 02-20-2013

Leo Wrote:Does interrupts get queued when they are disabled, until the next EI?
Or they are simply ignored?
Because, if they are ignored, some timing events(such as the lcdc int)can get out of sync!!!

For the GameBoy, there are three pieces of info that determine which interrupt to perform and when. The Interrupt Enable aka IE register (0xFFFF), the Interrupt Flag aka IF (0xFF0F), and some sort of boolean (most people refer to it as the IME) that's flipped to tell the CPU if interrupts are permitted or not (used in the DI, EI, and RETI opcodes). Before executing an opcode, the CPU checks the IME. If it's set, you go to your interrupt handling, if not, you process opcodes normally. Remember, simply because the IME is set doesn't mean an interrupt has occurred. You need to examine the Interrupt Enable and Interrupt Flags in your interrupt handling.

The IE register tells the CPU which interrupts are enabled; you do this by checking bits 0-4 of the register. If a certain interrupt is enabled, you then have to check if the emulated hardware has "tripped" the interrupt, i.e. it has set one of the bits of the IF register (it also only uses bits 0-4). If both the correct bits in IE and IF are set, you execute the interrupt and reset the bit in IF. The IME is also reset, so other interrupts cannot happen until the current one is finished. During your interrupt handling, you should only handle one interrupt at a time. Usually after the interrupts, the game code calls RETI so that any other interrupts can take place.

If the game code generates one or more interrupts at the same time, you could say they are queued, since the IF register keeps track of which interrupts are generated by hardware. The GB hardware has a hierarchy of which interrupt it will handle first in this order: V-Blank, LCDC, Timer Overflow, Serial, and High-to-Low for P10-P13 (e.g. gamepad input). So it goes something like this if two or more are generated at the same time:

Handle interrupt with greatest priority -> Disable interrupt handling since one is being processed right now -> Reset corresponding IF bit so we only handle the interrupt once until it's generated again -> Push PC to stack, Jump to interrupt location (e.g. 0x40) -> Process Interrupt -> Return from interrupt, re-enable interrupts usually with RETI -> Repeat, handle the next interrupt with the greatest priority.

Here's some psuedo code to wrap your head around Wink

Code:
handle_interrupts()
{
    if(IME)
    {
    
        //V-Blank
        if(Bit 0 of IF == 1 && Bit 0 of IE == 1)
        {
            Push stuff to stack, increment cycles by 32
            Set Program Counter to 0x40
            Set Bit 0 of IF to 0 since the interrupt has been handled
            Set IME to false, disabling interrupt handling, game will reset it by itself via RETI, usually
        }

        //LCDC
        else if(Bit 1 of IF == 1 && Bit 1 of IE == 1)
        {
            Same as above, but we set the Program Counter to 0x48
        }

        //Timer overflow
        else if(Bit 2 of IF == 1 && Bit 1 of IE == 1)
        {
            Same as above, but we set the Program Counter to 0x50
        }

        ... More code ...
    }
}

Note the use of else-ifs since we must handle one interrupt and one interrupt only at a time. This allows the GB to keep everything in-sync, assuming the people who programmed the ROM knew what they were doing, of course :p

As for GUIs, FLTK FTW! I dabbled with it; it's pretty light on resources and it doesn't take much code to get going, good for simple projects. That said, it doesn't have nearly as many features as GTK, wxWidgets, or Qt. I second Qt if you really want to make GUI-based programs. I haven't programmed in it myself, but I do use a lot of programs written in it, and there's much to be impressed by.


RE: Programming Discussion Thread - Leo - 02-20-2013

(02-20-2013, 09:00 AM)Shonumi Wrote: Usually after the interrupts, the game code calls RETI so that any other interrupts can take place.

That was the point!!! So, when an interrupt is happening, the IME is reset, and at the RETI, the IME is enabled and other interrupts that occurred during this one are handled right now, following the priority!!!


RE: Programming Discussion Thread - AnyOldName3 - 02-21-2013

No-one knows JList?


RE: Programming Discussion Thread - Leo - 02-21-2013

The only reason I know Java It's because of Android development. I like speed on my programs.

I plan to write an emulator, just like Shonumi, but writing it in Java would not be a good idea, because I'm just starting emu developing.
(And I like much more C++ ^^)


RE: Programming Discussion Thread - AnyOldName3 - 02-21-2013

I don't really have a choice language-wise, as it's for my A-Level coursework, and as java is what we're taught, java is what we use.


RE: Programming Discussion Thread - Leo - 02-21-2013

Is Shonumi writing it in Java? I didn't know of it!! Sorry!! XP

(O.o Noticed that my post count doesn't increase, creepy)
( EDIT: and AWFUL!!!! Angry )


RE: Programming Discussion Thread - AnyOldName3 - 02-21-2013

No, I was talking about java because I asked if anyone knew the correct way of implementing a JList.