Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
alexbevi
GitHub Repository: alexbevi/BizHawk
Path: blob/master/wonderswan/interrupt.cpp
2 views
1
#include "system.h"
2
//#include <trio/trio.h>
3
4
namespace MDFN_IEN_WSWAN
5
{
6
void Interrupt::Recalc()
7
{
8
IStatus |= (IAsserted & LevelTriggeredMask) & IEnable;
9
10
IOn_Cache = false;
11
IOn_Which = 0;
12
IVector_Cache = 0;
13
14
for(int i = 0; i < 8; i++)
15
{
16
if(IStatus & IEnable & (1U << i))
17
{
18
IOn_Cache = TRUE;
19
IOn_Which = i;
20
IVector_Cache = (IVectorBase + i) * 4;
21
break;
22
}
23
}
24
}
25
26
void Interrupt::AssertInterrupt(unsigned which, bool asserted)
27
{
28
const uint8 prev_IAsserted = IAsserted;
29
30
IAsserted &= ~(1U << which);
31
IAsserted |= (unsigned)asserted << which;
32
33
IStatus |= ((prev_IAsserted ^ IAsserted) & IAsserted) & IEnable;
34
35
Recalc();
36
}
37
38
void Interrupt::DoInterrupt(unsigned which)
39
{
40
IStatus |= (1U << which) & IEnable;
41
Recalc();
42
}
43
44
void Interrupt::Write(uint32 A, uint8 V)
45
{
46
//printf("Write: %04x %02x\n", A, V);
47
switch(A)
48
{
49
case 0xB0: IVectorBase = V; Recalc(); break;
50
case 0xB2: IEnable = V; IStatus &= IEnable; Recalc(); break;
51
case 0xB6: IStatus &= ~V; Recalc(); break;
52
}
53
}
54
55
uint8 Interrupt::Read(uint32 A)
56
{
57
//printf("Read: %04x\n", A);
58
switch(A)
59
{
60
case 0xB0: return(IVectorBase);
61
case 0xB2: return(IEnable);
62
case 0xB6: return(1 << IOn_Which); //return(IStatus);
63
}
64
return(0);
65
}
66
67
void Interrupt::Check()
68
{
69
if(IOn_Cache)
70
{
71
sys->cpu.interrupt(IVector_Cache, FALSE);
72
}
73
}
74
75
void Interrupt::Reset()
76
{
77
IAsserted = 0x00;
78
IEnable = 0x00;
79
IStatus = 0x00;
80
IVectorBase = 0x00;
81
Recalc();
82
}
83
84
SYNCFUNC(Interrupt)
85
{
86
NSS(IAsserted);
87
NSS(IStatus);
88
NSS(IEnable);
89
NSS(IVectorBase);
90
91
NSS(IOn_Cache);
92
NSS(IOn_Which);
93
NSS(IVector_Cache);
94
}
95
}
96
97