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_int_ack(WS_INT_ACK_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_int_set_handler(WS_INT_VBLANK, (ws_int_handler_t) vblank_int_handler);

// Enable the vertical blank hardware interrupt.
ws_int_enable(WS_INT_ENABLE_VBLANK);

// Disable the vertical blank hardware interrupt.
ws_int_disable(WS_INT_ENABLE_VBLANK);