gbasys

view src/intr.c @ 8:047c61960005

- added bg2 matrix support - changed some stupid const pointers to register addresses to hardcoded compile-time defines
author John Tsiombikas <nuclear@member.fsf.org>
date Sun, 22 Jun 2014 06:26:11 +0300
parents 875ef6085efc
children 85f219fcdc82
line source
1 /*
2 Copyright 2004 John Tsiombikas <nuclear@siggraph.org>
4 This file is part of libgba, a library for GameBoy Advance development.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
21 #include "intr.h"
22 #include "error.h"
24 #include "gfx.h"
26 #define MAX_INTR 14
27 static void (*intr_table[MAX_INTR])(void);
29 static void unexpected_intr(void) {
30 panic("unexpected interrupt");
31 }
33 static void intr_handler(void) {
34 int i;
35 unsigned short irq;
36 char buf[20];
38 clr_int();
40 irq = REG_INTR & 0x3fff;
42 for(i=0; i<MAX_INTR; i++) {
43 unsigned short irq_bit = (1 << i);
44 if((irq & irq_bit) && intr_table[i]) {
45 intr_table[i]();
46 }
47 }
49 REG_INTR = irq;
51 set_int();
52 }
54 void intr_init(void) {
55 int i;
56 unsigned long *ptr = (unsigned long*)0x3007ffc;
57 *ptr = (unsigned long)intr_handler;
59 for(i=0; i<MAX_INTR; i++) {
60 interrupt(i, unexpected_intr);
61 }
62 }
64 void interrupt(int intr, void (*handler)(void)) {
65 intr_table[intr] = handler;
66 }