-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathinterrupt.c
More file actions
44 lines (35 loc) · 1.02 KB
/
interrupt.c
File metadata and controls
44 lines (35 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <stdio.h>
#import "interrupt.h"
#import "cpu.h"
struct interrupt interrupt;
void interruptCycle(void) {
if (interrupt.pending == 1) {
interrupt.pending -= 1;
return;
}
// if everything is enabled and there is a flag set
if (interrupt.master && interrupt.enable && interrupt.flags) {
// get which interrupt is currently being executed
unsigned char inter = interrupt.enable & interrupt.flags;
if (inter & VBLANK) {
interrupt.flags &= ~VBLANK; // turn off the flag
cpuInterrupt(0x40);
}
if (inter & LCDSTAT) {
interrupt.flags &= ~LCDSTAT;
cpuInterrupt(0x48);
}
if (inter & TIMER) {
interrupt.flags &= ~TIMER;
cpuInterrupt(0x50);
}
if (inter & SERIAL) {
interrupt.flags &= ~SERIAL;
cpuInterrupt(0x58);
}
if (inter & JOYPAD) {
interrupt.flags &= ~JOYPAD;
cpuInterrupt(0x60);
}
}
}