Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
alexbevi
GitHub Repository: alexbevi/BizHawk
Path: blob/master/wonderswan/tcache.cpp
2 views
1
/* Cygne
2
*
3
* Copyright notice for this file:
4
* Copyright (C) 2002 Dox [email protected]
5
*
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 2 of the License, or
9
* (at your option) any later version.
10
*
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
15
*
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
*/
20
21
#include "system.h"
22
23
#include <cstring>
24
25
namespace MDFN_IEN_WSWAN
26
{
27
28
void GFX::InvalidByAddr(uint32 ws_offset)
29
{
30
if(wsVMode && (ws_offset>=0x4000)&&(ws_offset<0x8000))
31
{
32
wsTCacheUpdate[(ws_offset-0x4000)>>5]=FALSE; /*invalidate tile*/
33
return;
34
}
35
else if((ws_offset>=0x2000)&&(ws_offset<0x4000))
36
{
37
wsTCacheUpdate[(ws_offset-0x2000)>>4]=FALSE; /*invalidate tile*/
38
return;
39
}
40
41
if(wsVMode && (ws_offset>=0x8000)&&(ws_offset<0xc000))
42
{
43
wsTCacheUpdate2[(ws_offset-0x8000)>>5]=FALSE; /*invalidate tile*/
44
return;
45
}
46
else if((ws_offset>=0x4000)&&(ws_offset<0x6000))
47
{
48
wsTCacheUpdate2[(ws_offset-0x4000)>>4]=FALSE; /*invalidate tile*/
49
return;
50
}
51
}
52
53
void GFX::SetVideo(int number,bool force)
54
{
55
if((number!=wsVMode)||(force))
56
{
57
wsVMode=number;
58
std::memset(wsTCacheUpdate,0,512);
59
std::memset(wsTCacheUpdate2,0,512);
60
}
61
}
62
63
void GFX::MakeTiles()
64
{
65
int x,y,b0,b1,b2,b3,b4,b5,b6,b7;
66
for(x=0;x<256;x++)
67
for(y=0;y<256;y++)
68
{
69
b0=(x&128)>>7;b1=(x&64)>>6;b2=(x&32)>>5;b3=(x&16)>>4;b4=(x&8)>>3;b5=(x&4)>>2;b6=(x&2)>>1;b7=(x&1);
70
b0|=(y&128)>>6;b1|=(y&64)>>5;b2|=(y&32)>>4;b3|=(y&16)>>3;b4|=(y&8)>>2;b5|=(y&4)>>1;b6|=(y&2);b7|=(y&1)<<1;
71
tiles[x][y][0][0]=b0;
72
tiles[x][y][0][1]=b1;
73
tiles[x][y][0][2]=b2;
74
tiles[x][y][0][3]=b3;
75
tiles[x][y][0][4]=b4;
76
tiles[x][y][0][5]=b5;
77
tiles[x][y][0][6]=b6;
78
tiles[x][y][0][7]=b7;
79
tiles[x][y][1][0]=b7;
80
tiles[x][y][1][1]=b6;
81
tiles[x][y][1][2]=b5;
82
tiles[x][y][1][3]=b4;
83
tiles[x][y][1][4]=b3;
84
tiles[x][y][1][5]=b2;
85
tiles[x][y][1][6]=b1;
86
tiles[x][y][1][7]=b0;
87
}
88
}
89
90
void GFX::GetTile(uint32 number,uint32 line,int flipv,int fliph,int bank)
91
{
92
uint32 t_adr,t_index,i;
93
uint8 byte0,byte1,byte2,byte3;
94
const uint8 *ram = sys->memory.wsRAM;
95
96
if((!bank)||(!(wsVMode &0x07)))
97
{
98
if(!wsTCacheUpdate[number])
99
{
100
wsTCacheUpdate[number]=true;
101
switch(wsVMode)
102
{
103
case 7:
104
t_adr=0x4000+(number<<5);
105
t_index=number<<6;
106
for(i=0;i<8;i++)
107
{
108
byte0=ram[t_adr++];
109
byte1=ram[t_adr++];
110
byte2=ram[t_adr++];
111
byte3=ram[t_adr++];
112
wsTCache[t_index]=byte0>>4;
113
wsTCacheFlipped[t_index++]=byte3&15;
114
wsTCache[t_index]=byte0&15;
115
wsTCacheFlipped[t_index++]=byte3>>4;
116
wsTCache[t_index]=byte1>>4;
117
wsTCacheFlipped[t_index++]=byte2&15;
118
wsTCache[t_index]=byte1&15;
119
wsTCacheFlipped[t_index++]=byte2>>4;
120
wsTCache[t_index]=byte2>>4;
121
wsTCacheFlipped[t_index++]=byte1&15;
122
wsTCache[t_index]=byte2&15;
123
wsTCacheFlipped[t_index++]=byte1>>4;
124
wsTCache[t_index]=byte3>>4;
125
wsTCacheFlipped[t_index++]=byte0&15;
126
wsTCache[t_index]=byte3&15;
127
wsTCacheFlipped[t_index++]=byte0>>4;
128
}
129
break;
130
131
case 6:
132
t_adr=0x4000+(number<<5);
133
t_index=number<<6;
134
for(i=0;i<8;i++)
135
{
136
byte0=ram[t_adr++];
137
byte1=ram[t_adr++];
138
byte2=ram[t_adr++];
139
byte3=ram[t_adr++];
140
wsTCache[t_index]=((byte0>>7)&1)|(((byte1>>7)&1)<<1)|(((byte2>>7)&1)<<2)|(((byte3>>7)&1)<<3);
141
wsTCacheFlipped[t_index++]=((byte0)&1)|(((byte1)&1)<<1)|(((byte2)&1)<<2)|(((byte3)&1)<<3);
142
wsTCache[t_index]=((byte0>>6)&1)|(((byte1>>6)&1)<<1)|(((byte2>>6)&1)<<2)|(((byte3>>6)&1)<<3);
143
wsTCacheFlipped[t_index++]=((byte0>>1)&1)|(((byte1>>1)&1)<<1)|(((byte2>>1)&1)<<2)|(((byte3>>1)&1)<<3);
144
wsTCache[t_index]=((byte0>>5)&1)|(((byte1>>5)&1)<<1)|(((byte2>>5)&1)<<2)|(((byte3>>5)&1)<<3);
145
wsTCacheFlipped[t_index++]=((byte0>>2)&1)|(((byte1>>2)&1)<<1)|(((byte2>>2)&1)<<2)|(((byte3>>2)&1)<<3);
146
wsTCache[t_index]=((byte0>>4)&1)|(((byte1>>4)&1)<<1)|(((byte2>>4)&1)<<2)|(((byte3>>4)&1)<<3);
147
wsTCacheFlipped[t_index++]=((byte0>>3)&1)|(((byte1>>3)&1)<<1)|(((byte2>>3)&1)<<2)|(((byte3>>3)&1)<<3);
148
wsTCache[t_index]=((byte0>>3)&1)|(((byte1>>3)&1)<<1)|(((byte2>>3)&1)<<2)|(((byte3>>3)&1)<<3);
149
wsTCacheFlipped[t_index++]=((byte0>>4)&1)|(((byte1>>4)&1)<<1)|(((byte2>>4)&1)<<2)|(((byte3>>4)&1)<<3);
150
wsTCache[t_index]=((byte0>>2)&1)|(((byte1>>2)&1)<<1)|(((byte2>>2)&1)<<2)|(((byte3>>2)&1)<<3);
151
wsTCacheFlipped[t_index++]=((byte0>>5)&1)|(((byte1>>5)&1)<<1)|(((byte2>>5)&1)<<2)|(((byte3>>5)&1)<<3);
152
wsTCache[t_index]=((byte0>>1)&1)|(((byte1>>1)&1)<<1)|(((byte2>>1)&1)<<2)|(((byte3>>1)&1)<<3);
153
wsTCacheFlipped[t_index++]=((byte0>>6)&1)|(((byte1>>6)&1)<<1)|(((byte2>>6)&1)<<2)|(((byte3>>6)&1)<<3);
154
wsTCache[t_index]=((byte0)&1)|(((byte1)&1)<<1)|(((byte2)&1)<<2)|(((byte3)&1)<<3);
155
wsTCacheFlipped[t_index++]=((byte0>>7)&1)|(((byte1>>7)&1)<<1)|(((byte2>>7)&1)<<2)|(((byte3>>7)&1)<<3);
156
}
157
break;
158
159
default:
160
t_adr=0x2000+(number<<4);
161
t_index=number<<6;
162
for(i=0;i<8;i++)
163
{
164
byte0=ram[t_adr++];
165
byte1=ram[t_adr++];
166
wsTCache[t_index]=tiles[byte0][byte1][0][0];
167
wsTCacheFlipped[t_index++]=tiles[byte0][byte1][1][0];
168
wsTCache[t_index]=tiles[byte0][byte1][0][1];
169
wsTCacheFlipped[t_index++]=tiles[byte0][byte1][1][1];
170
wsTCache[t_index]=tiles[byte0][byte1][0][2];
171
wsTCacheFlipped[t_index++]=tiles[byte0][byte1][1][2];
172
wsTCache[t_index]=tiles[byte0][byte1][0][3];
173
wsTCacheFlipped[t_index++]=tiles[byte0][byte1][1][3];
174
wsTCache[t_index]=tiles[byte0][byte1][0][4];
175
wsTCacheFlipped[t_index++]=tiles[byte0][byte1][1][4];
176
wsTCache[t_index]=tiles[byte0][byte1][0][5];
177
wsTCacheFlipped[t_index++]=tiles[byte0][byte1][1][5];
178
wsTCache[t_index]=tiles[byte0][byte1][0][6];
179
wsTCacheFlipped[t_index++]=tiles[byte0][byte1][1][6];
180
wsTCache[t_index]=tiles[byte0][byte1][0][7];
181
wsTCacheFlipped[t_index++]=tiles[byte0][byte1][1][7];
182
}
183
}
184
}
185
if(flipv)
186
line=7-line;
187
if(fliph)
188
memcpy(&wsTileRow[0],&wsTCacheFlipped[(number<<6)|(line<<3)],8);
189
else
190
memcpy(&wsTileRow[0],&wsTCache[(number<<6)|(line<<3)],8);
191
}
192
else
193
{
194
195
196
if(!wsTCacheUpdate2[number])
197
{
198
wsTCacheUpdate2[number]=TRUE;
199
switch(wsVMode)
200
{
201
case 7:
202
t_adr=0x8000+(number<<5);
203
t_index=number<<6;
204
for(i=0;i<8;i++)
205
{
206
byte0=ram[t_adr++];
207
byte1=ram[t_adr++];
208
byte2=ram[t_adr++];
209
byte3=ram[t_adr++];
210
wsTCache2[t_index]=byte0>>4;
211
wsTCacheFlipped2[t_index++]=byte3&15;
212
wsTCache2[t_index]=byte0&15;
213
wsTCacheFlipped2[t_index++]=byte3>>4;
214
wsTCache2[t_index]=byte1>>4;
215
wsTCacheFlipped2[t_index++]=byte2&15;
216
wsTCache2[t_index]=byte1&15;
217
wsTCacheFlipped2[t_index++]=byte2>>4;
218
wsTCache2[t_index]=byte2>>4;
219
wsTCacheFlipped2[t_index++]=byte1&15;
220
wsTCache2[t_index]=byte2&15;
221
wsTCacheFlipped2[t_index++]=byte1>>4;
222
wsTCache2[t_index]=byte3>>4;
223
wsTCacheFlipped2[t_index++]=byte0&15;
224
wsTCache2[t_index]=byte3&15;
225
wsTCacheFlipped2[t_index++]=byte0>>4;
226
}
227
break;
228
case 6:
229
t_adr=0x8000+(number<<5);
230
t_index=number<<6;
231
for(i=0;i<8;i++)
232
{
233
byte0=ram[t_adr++];
234
byte1=ram[t_adr++];
235
byte2=ram[t_adr++];
236
byte3=ram[t_adr++];
237
wsTCache2[t_index]=((byte0>>7)&1)|(((byte1>>7)&1)<<1)|(((byte2>>7)&1)<<2)|(((byte3>>7)&1)<<3);
238
wsTCacheFlipped2[t_index++]=((byte0)&1)|(((byte1)&1)<<1)|(((byte2)&1)<<2)|(((byte3)&1)<<3);
239
wsTCache2[t_index]=((byte0>>6)&1)|(((byte1>>6)&1)<<1)|(((byte2>>6)&1)<<2)|(((byte3>>6)&1)<<3);
240
wsTCacheFlipped2[t_index++]=((byte0>>1)&1)|(((byte1>>1)&1)<<1)|(((byte2>>1)&1)<<2)|(((byte3>>1)&1)<<3);
241
wsTCache2[t_index]=((byte0>>5)&1)|(((byte1>>5)&1)<<1)|(((byte2>>5)&1)<<2)|(((byte3>>5)&1)<<3);
242
wsTCacheFlipped2[t_index++]=((byte0>>2)&1)|(((byte1>>2)&1)<<1)|(((byte2>>2)&1)<<2)|(((byte3>>2)&1)<<3);
243
wsTCache2[t_index]=((byte0>>4)&1)|(((byte1>>4)&1)<<1)|(((byte2>>4)&1)<<2)|(((byte3>>4)&1)<<3);
244
wsTCacheFlipped2[t_index++]=((byte0>>3)&1)|(((byte1>>3)&1)<<1)|(((byte2>>3)&1)<<2)|(((byte3>>3)&1)<<3);
245
wsTCache2[t_index]=((byte0>>3)&1)|(((byte1>>3)&1)<<1)|(((byte2>>3)&1)<<2)|(((byte3>>3)&1)<<3);
246
wsTCacheFlipped2[t_index++]=((byte0>>4)&1)|(((byte1>>4)&1)<<1)|(((byte2>>4)&1)<<2)|(((byte3>>4)&1)<<3);
247
wsTCache2[t_index]=((byte0>>2)&1)|(((byte1>>2)&1)<<1)|(((byte2>>2)&1)<<2)|(((byte3>>2)&1)<<3);
248
wsTCacheFlipped2[t_index++]=((byte0>>5)&1)|(((byte1>>5)&1)<<1)|(((byte2>>5)&1)<<2)|(((byte3>>5)&1)<<3);
249
wsTCache2[t_index]=((byte0>>1)&1)|(((byte1>>1)&1)<<1)|(((byte2>>1)&1)<<2)|(((byte3>>1)&1)<<3);
250
wsTCacheFlipped2[t_index++]=((byte0>>6)&1)|(((byte1>>6)&1)<<1)|(((byte2>>6)&1)<<2)|(((byte3>>6)&1)<<3);
251
wsTCache2[t_index]=((byte0)&1)|(((byte1)&1)<<1)|(((byte2)&1)<<2)|(((byte3)&1)<<3);
252
wsTCacheFlipped2[t_index++]=((byte0>>7)&1)|(((byte1>>7)&1)<<1)|(((byte2>>7)&1)<<2)|(((byte3>>7)&1)<<3);
253
}
254
break;
255
default:
256
t_adr=0x4000+(number<<4);
257
t_index=number<<6;
258
for(i=0;i<8;i++)
259
{
260
byte0=ram[t_adr++];
261
byte1=ram[t_adr++];
262
wsTCache2[t_index]=tiles[byte0][byte1][0][0];
263
wsTCacheFlipped2[t_index++]=tiles[byte0][byte1][1][0];
264
wsTCache2[t_index]=tiles[byte0][byte1][0][1];
265
wsTCacheFlipped2[t_index++]=tiles[byte0][byte1][1][1];
266
wsTCache2[t_index]=tiles[byte0][byte1][0][2];
267
wsTCacheFlipped2[t_index++]=tiles[byte0][byte1][1][2];
268
wsTCache2[t_index]=tiles[byte0][byte1][0][3];
269
wsTCacheFlipped2[t_index++]=tiles[byte0][byte1][1][3];
270
wsTCache2[t_index]=tiles[byte0][byte1][0][4];
271
wsTCacheFlipped2[t_index++]=tiles[byte0][byte1][1][4];
272
wsTCache2[t_index]=tiles[byte0][byte1][0][5];
273
wsTCacheFlipped2[t_index++]=tiles[byte0][byte1][1][5];
274
wsTCache2[t_index]=tiles[byte0][byte1][0][6];
275
wsTCacheFlipped2[t_index++]=tiles[byte0][byte1][1][6];
276
wsTCache2[t_index]=tiles[byte0][byte1][0][7];
277
wsTCacheFlipped2[t_index++]=tiles[byte0][byte1][1][7];
278
}
279
}
280
}
281
if(flipv)
282
line=7-line;
283
if(fliph)
284
memcpy(&wsTileRow[0],&wsTCacheFlipped2[(number<<6)|(line<<3)],8);
285
else
286
memcpy(&wsTileRow[0],&wsTCache2[(number<<6)|(line<<3)],8);
287
}
288
}
289
290
}
291
292