Table of Contents

Writing interrupt handlers

C interrupt handlers

For less performance-sensitive interrupts (such as the vertical blank interrupt), it is possible to write the relevant handlers using only C. This is done by marking the interrupt function with special attributes:

__attribute__((assume_ss_data, interrupt))
void __far vblank_int_handler(void) {
    vbl_ticks++;
    
    // Acknowledge the hardware interrupt.
    ws_hwint_ack(HWINT_VBLANK);
}

These mean the following:

Configuring interrupt handlers

libws provides useful functions for configuring interrupt handlers:

// Set the function "vblank_int_handler" to run during vertical blank.
ws_hwint_set_handler(HWINT_IDX_VBLANK, (ws_int_handler_t) vblank_int_handler);

// Enable the vertical blank hardware interrupt.
ws_hwint_enable(HWINT_VBLANK);

// Disable the vertical blank hardware interrupt.
ws_hwint_disable(HWINT_VBLANK);

Watch out! ws_hwint_set_handler expects a HWINT_IDX parameter, while most other ws_hwint operations - enable, disable, ack - expect a HWINT parameter.

I admit, this is a little confusing. ^^;