Debian Codegraph @

mednafen/wswan/interrupt.c

raw symbols SCIP
1 #include "wswan.h"
2 #include "interrupt.h"
3 #include "v30mz.h"
4 #include "../state.h"
5
6 static uint8 IStatus;
7 static uint8 IEnable;
8 static uint8 IVectorBase;
9
10 static bool IOn_Cache;
11 static uint32 IOn_Which;
12 static uint32 IVector_Cache;
13
14 static void RecalcInterrupt(void)
15 {
16 unsigned i;
17 IOn_Cache = false;
18 IOn_Which = 0;
19 IVector_Cache = 0;
20
21 for(i = 0; i < 8; i++)
22 {
23 if(IStatus & IEnable & (1 << i))
24 {
25 IOn_Cache = true;
26 IOn_Which = i;
27 IVector_Cache = (IVectorBase + i) * 4;
28 break;
29 }
30 }
31 }
32
33 void WSwan_Interrupt(int which)
34 {
35 if(IEnable & (1 << which))
36 IStatus |= 1 << which;
37
38 RecalcInterrupt();
39 }
40
41 void WSwan_InterruptWrite(uint32 A, uint8 V)
42 {
43 switch(A)
44 {
45 case 0xB0:
46 IVectorBase = V;
47 RecalcInterrupt();
48 break;
49 case 0xB2:
50 IEnable = V;
51 IStatus &= IEnable;
52 RecalcInterrupt();
53 break;
54 case 0xB6:
55 IStatus &= ~V;
56 RecalcInterrupt();
57 break;
58 }
59 }
60
61 uint8 WSwan_InterruptRead(uint32 A)
62 {
63 switch(A)
64 {
65 case 0xB0:
66 return(IVectorBase);
67 case 0xB2:
68 return(IEnable);
69 case 0xB6:
70 return(1 << IOn_Which); //return(IStatus);
71 }
72
73 return 0;
74 }
75
76 void WSwan_InterruptCheck(void)
77 {
78 if(IOn_Cache)
79 v30mz_int(IVector_Cache, false);
80 }
81
82 void WSwan_InterruptReset(void)
83 {
84 IEnable = 0x00;
85 IStatus = 0x00;
86 IVectorBase = 0x00;
87 RecalcInterrupt();
88 }
89
90 int WSwan_InterruptStateAction(StateMem *sm, int load, int data_only)
91 {
92 SFORMAT StateRegs[] =
93 {
94 { &(IStatus), (uint32_t)sizeof(IStatus), MDFNSTATE_RLSB, "IStatus" },
95 { &(IEnable), (uint32_t)sizeof(IEnable), MDFNSTATE_RLSB, "IEnable"},
96 { &(IVectorBase), (uint32_t)sizeof(IVectorBase), MDFNSTATE_RLSB, "IVectorBase" },
97 { 0, 0, 0, 0 }
98 };
99
100 if(!MDFNSS_StateAction(sm, load, data_only, StateRegs, "INTR", false))
101 return 0;
102
103 if(load)
104 RecalcInterrupt();
105
106 return 1;
107 }