gbasys

view src/intr.c @ 9:85f219fcdc82

merged
author John Tsiombikas <nuclear@member.fsf.org>
date Sun, 22 Jun 2014 06:27:18 +0300
parents 047c61960005 72c6429ae953
children
line source
1 /*
2 gbasys - a gameboy advance hardware abstraction library
3 Copyright (C) 2004-2014 John Tsiombikas <nuclear@member.fsf.org>
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.
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.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18 #include "intr.h"
19 #include "error.h"
21 #include "gfx.h"
23 #define MAX_INTR 14
24 static void (*intr_table[MAX_INTR])(void);
26 static void unexpected_intr(void) {
27 panic("unexpected interrupt");
28 }
30 static void intr_handler(void) {
31 int i;
32 unsigned short irq;
33 char buf[20];
35 clr_int();
37 irq = REG_INTR & 0x3fff;
39 for(i=0; i<MAX_INTR; i++) {
40 unsigned short irq_bit = (1 << i);
41 if((irq & irq_bit) && intr_table[i]) {
42 intr_table[i]();
43 }
44 }
46 REG_INTR = irq;
48 set_int();
49 }
51 void intr_init(void) {
52 int i;
53 unsigned long *ptr = (unsigned long*)0x3007ffc;
54 *ptr = (unsigned long)intr_handler;
56 for(i=0; i<MAX_INTR; i++) {
57 interrupt(i, unexpected_intr);
58 }
59 }
61 void interrupt(int intr, void (*handler)(void)) {
62 intr_table[intr] = handler;
63 }