cscg22-gearboy

CSCG 2022 Challenge 'Gearboy'
git clone https://git.sinitax.com/sinitax/cscg22-gearboy
Log | Files | Refs | sfeed.txt

isr.h (2357B)


      1/** @file gb/isr.h
      2
      3    Macros for creating raw interrupt service routines (ISRs)
      4    which do not use the default GBDK ISR dispatcher.
      5
      6    Handlers installed this way will have less overhead than
      7    ones which use the GBDK ISR dispatcher.
      8*/
      9#ifndef _ISR_H_INCLUDE_
     10#define _ISR_H_INCLUDE_
     11
     12#include <stdint.h>
     13#include <types.h>
     14
     15// #define VECTOR_VBL     0x40 // you can not define raw vector for VBlank interrupt
     16#define VECTOR_STAT    0x48  /**< Address for the STAT interrupt vector */
     17#define VECTOR_TIMER   0x50  /**< Address for the TIMER interrupt vector */
     18#define VECTOR_SERIAL  0x58  /**< Address for the SERIAL interrupt vector */
     19#define VECTOR_JOYPAD  0x60  /**< Address for the JOYPAD interrupt vector */
     20
     21typedef struct isr_vector_t {
     22    uint8_t opcode;
     23    void * func;
     24} isr_vector_t;
     25
     26/** Creates an interrupt vector at the given address for a raw
     27    interrupt service routine (which does not use the GBDK ISR dispatcher)
     28
     29    @param ADDR   Address of the interrupt vector, any of: @ref VECTOR_STAT, @ref VECTOR_TIMER, @ref VECTOR_SERIAL, @ref VECTOR_JOYPAD
     30    @param FUNC   ISR function supplied by the user
     31
     32    This cannot be used with the VBLANK interrupt.
     33
     34    Do not use this in combination with interrupt installers
     35    that rely on the default GBDK ISR dispatcher such as
     36    @ref add_TIM(), @ref remove_TIM()
     37    (and the same for all other interrupts).
     38
     39    Example:
     40    \code{.c}
     41    #include <gb/isr.h>
     42
     43    void TimerISR() __critical __interrupt {
     44    // some ISR code here
     45    }
     46
     47    ISR_VECTOR(VECTOR_TIMER, TimerISR)
     48    \endcode
     49
     50    @see ISR_NESTED_VECTOR, set_interrupts
     51*/
     52#define ISR_VECTOR(ADDR, FUNC) \
     53static const isr_vector_t AT((ADDR)) __ISR_ ## ADDR = {0xc3, (void *)&(FUNC)};
     54
     55typedef struct isr_nested_vector_t {
     56    uint8_t opcode[2];
     57    void * func;
     58} isr_nested_vector_t;
     59
     60/** Creates an interrupt vector at the given address for a raw
     61    interrupt service routine allowing nested interrupts
     62
     63    @param ADDR   Address of the interrupt vector, any of: @ref VECTOR_STAT, @ref VECTOR_TIMER, @ref VECTOR_SERIAL, @ref VECTOR_JOYPAD
     64    @param FUNC   ISR function
     65
     66    This cannot be used with the VBLANK interrupt
     67
     68    @see ISR_VECTOR
     69*/
     70#define ISR_NESTED_VECTOR(ADDR, FUNC) \
     71static const isr_nested_vector_t AT((ADDR)) __ISR_ ## ADDR = {{0xfb, 0xc3}, (void *)&(FUNC)};
     72
     73
     74#endif // _ISR_H_INCLUDE_