-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathgdc_pset.c
174 lines (137 loc) · 3.46 KB
/
gdc_pset.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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
#include "compiler.h"
#include "cpucore.h"
#include "pccore.h"
#include "iocore.h"
#include "memegc.h"
#include "gdc_sub.h"
#include "gdc_pset.h"
#include "vram.h"
static void MEMCALL _nop(GDCPSET pset, UINT addr, UINT bit) {
(void)pset;
(void)addr;
(void)bit;
}
static void MEMCALL _replace0(GDCPSET pset, UINT addr, UINT bit) {
vramupdate[addr] |= pset->update.b[0];
pset->base.ptr[addr] &= ~(0x80 >> bit);
}
static void MEMCALL _replace1(GDCPSET pset, UINT addr, UINT bit) {
vramupdate[addr] |= pset->update.b[0];
pset->base.ptr[addr] |= (0x80 >> bit);
}
static void MEMCALL _complemnt(GDCPSET pset, UINT addr, UINT bit) {
vramupdate[addr] |= pset->update.b[0];
pset->base.ptr[addr] ^= (0x80 >> bit);
}
static void MEMCALL _clear(GDCPSET pset, UINT addr, UINT bit) {
vramupdate[addr] |= pset->update.b[0];
pset->base.ptr[addr] &= ~(0x80 >> bit);
}
static void MEMCALL _set(GDCPSET pset, UINT addr, UINT bit) {
vramupdate[addr] |= pset->update.b[0];
pset->base.ptr[addr] |= (0x80 >> bit);
}
// ---- grcg
static void MEMCALL withtdw(GDCPSET pset, UINT addr, UINT bit) {
UINT8 *ptr;
addr &= ~1;
*(UINT16 *)(vramupdate + addr) |= pset->update.w;
ptr = pset->base.ptr + addr;
*(UINT16 *)(ptr + VRAM_B) = grcg.tile[0].w;
*(UINT16 *)(ptr + VRAM_R) = grcg.tile[1].w;
*(UINT16 *)(ptr + VRAM_G) = grcg.tile[2].w;
*(UINT16 *)(ptr + VRAM_E) = grcg.tile[3].w;
(void)bit;
}
static void MEMCALL withrmw(GDCPSET pset, UINT addr, UINT bit) {
UINT8 *ptr;
UINT8 data;
UINT8 mask;
vramupdate[addr] |= pset->update.b[0];
ptr = pset->base.ptr + addr;
data = (0x80 >> bit);
mask = ~data;
ptr[VRAM_B] &= mask;
ptr[VRAM_B] |= data & grcg.tile[0].b[0];
ptr[VRAM_R] &= mask;
ptr[VRAM_R] |= data & grcg.tile[1].b[0];
ptr[VRAM_G] &= mask;
ptr[VRAM_G] |= data & grcg.tile[2].b[0];
ptr[VRAM_E] &= mask;
ptr[VRAM_E] |= data & grcg.tile[3].b[0];
}
// ---- egc
static void MEMCALL withegc(GDCPSET pset, UINT addr, UINT bit) {
REG16 data;
data = (0x80 >> bit);
if (addr & 1) {
addr &= ~1;
data <<= 8;
}
egc_writeword(pset->base.addr + addr, data);
}
static const GDCPFN psettbl[4][2] = {
{_replace0, _replace1},
{_nop, _complemnt},
{_nop, _clear},
{_nop, _set}};
// ----
void MEMCALL gdcpset_prepare(GDCPSET pset, UINT32 csrw, REG16 pat, REG8 op) {
UINT8 *base;
UINT8 update;
if (vramop.operate & (1 << VOPBIT_EGC)) {
pset->func[0] = _nop;
pset->func[1] = withegc;
pset->base.addr = gdcplaneseg[(csrw >> 14) & 3];
}
else {
base = mem;
if (!gdcs.access) {
update = 1;
}
else {
base += VRAM_STEP;
update = 2;
}
op &= 3;
if (!(grcg.gdcwithgrcg & 0x8)) {
pset->func[0] = psettbl[op][0];
pset->func[1] = psettbl[op][1];
pset->base.ptr = base + gdcplaneseg[(csrw >> 14) & 3];
}
else {
pset->func[0] = _nop;
pset->func[1] = (grcg.gdcwithgrcg & 0x4)?withrmw:withtdw;
pset->base.ptr = base;
}
gdcs.grphdisp |= update;
pset->update.b[0] = update;
pset->update.b[1] = update;
}
pset->pattern = pat;
pset->x = (UINT16)((((csrw & 0x3fff) % 40) << 4) + ((csrw >> 20) & 0x0f));
pset->y = (UINT16)((csrw & 0x3fff) / 40);
pset->dots = 0;
}
void MEMCALL gdcpset(GDCPSET pset, REG16 x, REG16 y) {
UINT dot;
dot = pset->pattern & 1;
pset->pattern = (pset->pattern >> 1) + (dot << 15);
pset->dots++;
x = LOW16(x);
y = LOW16(y);
if (y > 409) {
return;
}
else if (y == 409) {
if (x >= 384) {
return;
}
}
else {
if (x >= 640) {
return;
}
}
(*pset->func[dot])(pset, (y * 80) + (x >> 3), x & 7);
}