initial commit
[gba_blender] / src / intr.c
1 /*
2 blender for the Gameboy Advance
3 Copyright (C) 2021  John Tsiombikas <nuclear@member.fsf.org>
4
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program.  If not, see <https://www.gnu.org/licenses/>.
17 */
18 #include "intr.h"
19
20 #define MAX_INTR        14
21 static void (*intr_table[MAX_INTR])(void);
22
23 __attribute__ ((target("arm")))
24 static void intr_handler(void)
25 {
26         int i;
27         uint16_t iflags;
28
29         clr_intr();
30         iflags = REG_IF & 0x3fff;
31
32
33         for(i=0; i<MAX_INTR; i++) {
34                 if((iflags & (1 << i)) && intr_table[i]) {
35                         intr_table[i]();
36                 }
37         }
38
39         REG_IF = iflags;        /* ack intr */
40         set_intr();
41 }
42
43 void intr_init(void)
44 {
45         INTR_VECTOR = (uint32_t)intr_handler;
46 }
47
48 void interrupt(int intr, void (*handler)(void))
49 {
50         intr_table[intr] = handler;
51 }