gbasys

view src/intr.c @ 7:72c6429ae953

changed all the copyright headers and added a README
author John Tsiombikas <nuclear@member.fsf.org>
date Fri, 18 Apr 2014 02:04:46 +0300
parents 875ef6085efc
children 85f219fcdc82
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 unsigned short *reg_int_master = (unsigned short*)0x04000208;
24 unsigned short *reg_int_mask = (unsigned short*)0x04000200;
25 static volatile unsigned short *reg_int = (unsigned short*)0x04000202;
27 #define MAX_INTR 14
28 static void (*intr_table[MAX_INTR])(void);
30 static void unexpected_intr(void) {
31 panic("unexpected interrupt");
32 }
34 static void intr_handler(void) {
35 int i;
36 unsigned short irq;
37 char buf[20];
39 clr_int();
41 irq = *reg_int & 0x3fff;
43 for(i=0; i<MAX_INTR; i++) {
44 unsigned short irq_bit = (1 << i);
45 if((irq & irq_bit) && intr_table[i]) {
46 intr_table[i]();
47 }
48 }
50 *reg_int = irq;
52 set_int();
53 }
55 void intr_init(void) {
56 int i;
57 unsigned long *ptr = (unsigned long*)0x3007ffc;
58 *ptr = (unsigned long)intr_handler;
60 for(i=0; i<MAX_INTR; i++) {
61 interrupt(i, unexpected_intr);
62 }
63 }
65 void interrupt(int intr, void (*handler)(void)) {
66 intr_table[intr] = handler;
67 }