gbdk-2020 | GameBoy Development Kit |
| download: https://git.y1.nz/archives/gbdk.tar.gz | |
| README | Files | Log | Refs | LICENSE |
gbdk-lib/include/gb/isr.h
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
21 typedef 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) \
53 static const isr_vector_t AT((ADDR)) __ISR_ ## ADDR = {0xc3, (void *)&(FUNC)};
54
55 typedef 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 The LCD STAT vector (@ref VECTOR_STAT) cannot be used
69 in the same program as `stdio.h` since they install
70 an ISR vector to the same location.
71
72 @see ISR_VECTOR
73 */
74 #define ISR_NESTED_VECTOR(ADDR, FUNC) \
75 static const isr_nested_vector_t AT((ADDR)) __ISR_ ## ADDR = {{0xfb, 0xc3}, (void *)&(FUNC)};
76
77
78 #endif // _ISR_H_INCLUDE_
This webpage is intended to be an accessible preview of this repository. To get a fuller picture, clone it and use the git CLI.