WDC C Compiler for 65816 in action [PART III]

Hi all,

It’s been a while that I haven’t posted working code on my blog. As promised i come with mosaic and fade effect and very small debug output. I will come bacl on debug fonctionnality a bit later. The two gfx effect I provide here are more than just the effects it’s a whole event managing system trigered by the NMI interrupt. I had some issue with NMI for about a week but now everything is starting to become clear in my mind (I will come back with this problem in an other post).

The event managing system is quite simple to use. Here is the function prototype and the structure used to store the events :

void initEvents(void);
extern event* addEvent(char (*callback)(word counter),
	int noDuplicateCallback);
extern void removeEvent(event *eventElement);
extern void processEvents(void);

typedef struct event{
    word VBlankCount;
    char (*callback)(word counter);
    struct event *previousEvent;
    struct event *nextEvent;
} event;

As you can see there is an initEvents that need to be called before adding events. The processEvents function need to be called in the NMI handler. The events them self are simply stored in a double linked list for managing ease.

To add a function it’s very simple you just need to provide a callback function that take an int as argument. This argument will be the VBlank/NMI count since the add of the event. An other parameter allow to specify that you don’t want to add a event if it’s already in the event list. Here is an example on how to add an event and an event callback function for fading out :

addEvent(&fadeOut, 1);

char fadeOut(word counter) {
    static byte fadeOutValue;

    if(counter == 0) {
        // init fade value
        fadeOutValue = 0x0f;
    } else {
        fadeOutValue--;
    }

    *(byte*) 0x2100 = fadeOutValue;    

    if(fadeOutValue == 0x00) {
        return EVENT_STOP;
    } else {
        return EVENT_CONTINUE;
    }
}

I’m sure you saw the EVENT_CONTINUE and EVENT_STOP. In fact the callback function is needed to return a char that specify the processEvents function if the event still need to stay in the event list or if it should be removed. The removeEVent function is called internally in processEvents.

So now managing events triggered by VBlank/NMI is all easy.

So now the debugging facilities… Hmm not yet totally implemented like I wished. The font is there, the basic function is there… So what’s missing ? printf like functions for being able to display on the debug screen, some more code and memory space to backup VRAM and CGRAM so we are able to restore the previous screen config properly, many code cleaning is needed in debug part.

So I just make this realease, even if everything is not coded as I wished, but it’s been a while that I promised a release. So expect more debug stuff to become reality.

You can test the events in the archive by launching the rom.smc file and pressing up or down to play with mosaic and fade effects. Pressing left make the screen scroll left while right make it stop. The is a small isuue with the fluidity of the left scrolling. I don’t know if it’s a NMI timing issue in the emulators or if it’s my code. If someone can test that on real hardware you are welcome to give me feedback with a comment on this post.

Full archive is available here as usual. There is now a makefile provided instead of the make.bat, if any problem get in touch with me.

See ya, Lint

4 Responses to “WDC C Compiler for 65816 in action [PART III]”

  1. Tomy Says:

    I just tested it with bsnes v0.32a. The debug window have problem. Then I use Snes9X1.43.ep9r8 , window ok. But it is B/W, no color. Is it right ?

  2. lint Says:

    For the color It’s a small mistake by myself you need to change the paramaters of the debugFont conversion :

    tools\Pcx2Snes.exe ressource/debugFont -n -c16 -s8 -o16

    For the Bsnes i just saw the problem and I’m working on it. Does someone have the abality to test on a real SNES ?

    ++ Lint

  3. Tomy Says:

    I tested it in real hardware. It can display the KUNG-FU MASTER Title. Then it hang at there. Press key, nothing change. Or maybe readkey routine problem on real hardware ?

    lint, can you tell me why Bsnes have problem on it ? I’m interest to know it. Thank you.

  4. lint Says:

    Fix is available in the next post.