gbasys

view src/intr.c @ 2:e3dc7705ad9c

communications stuff
author John Tsiombikas <nuclear@member.fsf.org>
date Wed, 07 Mar 2012 06:11:51 +0200
parents
children 72c6429ae953 047c61960005
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 unsigned short *reg_int_master = (unsigned short*)0x04000208;
27 unsigned short *reg_int_mask = (unsigned short*)0x04000200;
28 static volatile unsigned short *reg_int = (unsigned short*)0x04000202;
30 #define MAX_INTR 14
31 static void (*intr_table[MAX_INTR])(void);
33 static void unexpected_intr(void) {
34 panic("unexpected interrupt");
35 }
37 static void intr_handler(void) {
38 int i;
39 unsigned short irq;
40 char buf[20];
42 clr_int();
44 irq = *reg_int & 0x3fff;
46 for(i=0; i<MAX_INTR; i++) {
47 unsigned short irq_bit = (1 << i);
48 if((irq & irq_bit) && intr_table[i]) {
49 intr_table[i]();
50 }
51 }
53 *reg_int = irq;
55 set_int();
56 }
58 void intr_init(void) {
59 int i;
60 unsigned long *ptr = (unsigned long*)0x3007ffc;
61 *ptr = (unsigned long)intr_handler;
63 for(i=0; i<MAX_INTR; i++) {
64 interrupt(i, unexpected_intr);
65 }
66 }
68 void interrupt(int intr, void (*handler)(void)) {
69 intr_table[intr] = handler;
70 }