-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathartic.c
108 lines (80 loc) · 1.62 KB
/
artic.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
97
98
99
100
101
102
103
104
105
106
107
#include "compiler.h"
#include "cpucore.h"
#include "pccore.h"
#include "iocore.h"
void artic_callback(void) {
SINT32 mul;
SINT32 leng;
mul = pccore.multiple;
if (pccore.cpumode & CPUMODE_8MHZ) {
mul *= 13;
}
else {
mul *= 16;
}
leng = CPU_CLOCK + CPU_BASECLOCK - CPU_REMCLOCK;
leng *= 2;
leng -= artic.lastclk2;
if (leng > 0) {
leng /= mul;
artic.counter += leng;
artic.lastclk2 += leng * mul;
}
}
static UINT32 artic_getcnt(void) {
SINT32 mul;
SINT32 leng;
mul = pccore.multiple;
if (pccore.cpumode & CPUMODE_8MHZ) {
mul *= 13;
}
else {
mul *= 16;
}
leng = CPU_CLOCK + CPU_BASECLOCK - CPU_REMCLOCK;
leng *= 2;
leng -= artic.lastclk2;
if (leng > 0) {
leng /= mul;
return(artic.counter + leng);
}
return(artic.counter);
}
// ---- I/O
static void IOOUTCALL artic_o5f(UINT port, REG8 dat) {
(void)port;
(void)dat;
CPU_REMCLOCK -= 20;
}
static REG8 IOINPCALL artic_i5c(UINT port) {
(void)port;
return((UINT8)artic_getcnt());
}
static REG8 IOINPCALL artic_i5d(UINT port) {
(void)port;
return((UINT8)(artic_getcnt() >> 8));
}
static REG8 IOINPCALL artic_i5f(UINT port) {
(void)port;
return((UINT8)(artic_getcnt() >> 16));
}
// ---- I/F
void artic_reset(const NP2CFG *pConfig) {
ZeroMemory(&artic, sizeof(artic));
(void)pConfig;
}
void artic_bind(void) {
iocore_attachout(0x005f, artic_o5f);
iocore_attachinp(0x005c, artic_i5c);
iocore_attachinp(0x005d, artic_i5d);
iocore_attachinp(0x005e, artic_i5d);
iocore_attachinp(0x005f, artic_i5f);
}
REG16 IOINPCALL artic_r16(UINT port) {
UINT32 cnt;
cnt = artic_getcnt();
if (port & 2) {
cnt >>= 8;
}
return((UINT16)cnt);
}