forked from r-type/xmil-libretro
-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathievent.c
97 lines (78 loc) · 1.49 KB
/
ievent.c
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#include "compiler.h"
#include "z80core.h"
#include "pccore.h"
#include "iocore.h"
#include "nevent.h"
#include "ievent.h"
/* ここでデイジーチェイン */
typedef BOOL (*IEVENTFN)(UINT id);
static BOOL dummy(UINT id) {
(void)id;
return(FALSE);
}
static const IEVENTFN ieventfn[IEVENT_MAX] = {
dummy, /* IEVENT_SIO */
ieitem_dmac, /* IEVENT_DMA */
ieitem_ctc, /* IEVENT_CTC0 */
ieitem_ctc, /* IEVENT_CTC1 */
ieitem_ctc, /* IEVENT_CTC2 */
ieitem_scpu}; /* IEVENT_SUBCPU */
/* ---- */
void ievent_progress(void) {
UINT i;
UINT bit;
if ((CPU_REQIRQ == 0) || (Z80_DI)) {
return;
}
for (i=0, bit=1; i<IEVENT_MAX; i++, bit<<=1) {
if (CPU_IRQ & bit) {
break;
}
if (CPU_REQIRQ & bit) {
CPU_REQIRQ ^= bit;
if (ieventfn[i](i)) {
if (i != IEVENT_SUBCPU) { /* サブCPUは別処理 */
CPU_IRQ |= bit;
}
return;
}
}
}
}
void ievent_setbit(UINT bit) {
UINT r;
if (CPU_REQIRQ & bit) {
return;
}
CPU_REQIRQ |= bit;
if (Z80_DI) {
return;
}
r = CPU_IRQ;
r = (r ^ (r - 1)) >> 1;
if (!(r & bit)) {
return;
}
nevent_forceexit();
}
void ievent_eoi(void) {
UINT i;
UINT bit;
if (CPU_IRQ == 0) {
return;
}
for (i=0, bit=1; i<IEVENT_MAX; i++, bit<<=1) {
if (CPU_IRQ & bit) {
CPU_IRQ ^= bit;
if ((i >= IEVENT_CTC0) && (i <= IEVENT_CTC2)) {
ieeoi_ctc(i);
}
break;
}
}
if ((!(Z80_IFF & ((1 << IFF_IFLAG) | (1 << IFF_NMI)))) &&
(CPU_REQIRQ != 0)) {
CPU_BASECLOCK -= CPU_REMCLOCK;
CPU_REMCLOCK = 0;
}
}