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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
|
/*
* Snes9x - Portable Super Nintendo Entertainment System (TM) emulator.
*
* (c) Copyright 1996 - 2001 Gary Henderson (gary.henderson@ntlworld.com) and
* Jerremy Koot (jkoot@snes9x.com)
*
* Super FX C emulator code
* (c) Copyright 1997 - 1999 Ivar (ivar@snes9x.com) and
* Gary Henderson.
* Super FX assembler emulator code (c) Copyright 1998 zsKnight and _Demo_.
*
* DSP1 emulator code (c) Copyright 1998 Ivar, _Demo_ and Gary Henderson.
* C4 asm and some C emulation code (c) Copyright 2000 zsKnight and _Demo_.
* C4 C code (c) Copyright 2001 Gary Henderson (gary.henderson@ntlworld.com).
*
* DOS port code contains the works of other authors. See headers in
* individual files.
*
* Snes9x homepage: http://www.snes9x.com
*
* Permission to use, copy, modify and distribute Snes9x in both binary and
* source form, for non-commercial purposes, is hereby granted without fee,
* providing that this license information and copyright notice appear with
* all copies and any derived work.
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event shall the authors be held liable for any damages
* arising from the use of this software.
*
* Snes9x is freeware for PERSONAL USE only. Commercial users should
* seek permission of the copyright holders first. Commercial use includes
* charging money for Snes9x or software derived from Snes9x.
*
* The copyright holders request that bug fixes and improvements to the code
* should be forwarded to them so everyone can benefit from the modifications
* in future versions.
*
* Super NES and Super Nintendo Entertainment System are trademarks of
* Nintendo Co., Limited and its subsidiary companies.
*/
// ARM V5 Assembly by bitrider
#include "snes9x.h"
#include "memmap.h"
#include "ppu.h"
#include "display.h"
#include "gfx.h"
#include "tile16.h"
extern uint32 HeadMask [4];
extern uint32 TailMask [5];
extern uint8 ConvertTile (uint8 *pCache, uint32 TileAddr);
// DrawTile16 -----------------------------------------
void DrawTile16NoPrio (uint32 Tile, uint32 Offset, uint32 StartLine, uint32 LineCount)
{
TILE_PREAMBLE
if (Tile & V_FLIP){
if (!(Tile & H_FLIP)){
asm volatile (
"2: \n"
#define FN(p, p2, p3, p4) \
" ldrb r9, [%[bp], #" p "] \n"\
" ldrb r8, [%[bp], #" p3 "] \n"\
" movs r9, r9, lsl #2 \n"\
" ldrne r9, [%[colors], r9] \n"\
" strneb %[gfx_z2], [%[depth], #" p "] \n"\
" strneh r9, [%[screen], #" p2 "] \n"\
"3: \n"\
" movs r9, r8, lsl #2 \n"\
" ldrne r9, [%[colors], r9] \n"\
" strneb %[gfx_z2], [%[depth], #" p3 "] \n"\
" strneh r9, [%[screen], #" p4 "] \n"\
"3: \n"
FN("0", "0", "1", "2")
FN("2", "4", "3", "6")
FN("4", "8", "5", "10")
FN("6", "12", "7", "14")
// Loop
" sub %[bp], %[bp], #8 \n"
" add %[screen], %[screen], #640 \n"
" add %[depth], %[depth], #320 \n"
" subs %[lcount], %[lcount], #1 \n"
" bne 2b"
// output
: // none
// input
: [lcount] "r" (LineCount),
[gfx_z1] "r" (GFX.Z1),
[gfx_z2] "r" (GFX.Z2),
[screen] "r" ((uint16 *) GFX.S + Offset),
[colors] "r" (GFX.ScreenColors),
[depth] "r" (GFX.DB + Offset),
[bp] "r" (pCache + 56 - StartLine)
// clobbered
: "r9", "r8", "cc" // r8 & flags
);
} else {
asm volatile (
"2: \n"
#define FN1(p, p2, p3, p4, p5, p6) \
" ldrb r9, [%[bp], #" p3 "] \n"\
" ldrb r8, [%[bp], #" p6 "] \n"\
" movs r9, r9, lsl #2 \n"\
" ldrne r9, [%[colors], r9] \n"\
" strneb %[gfx_z2], [%[depth], #" p "] \n"\
" strneh r9, [%[screen], #" p2 "] \n"\
"3: \n"\
" movs r9, r8, lsl #2 \n"\
" ldrne r9, [%[colors], r9] \n"\
" strneb %[gfx_z2], [%[depth], #" p4 "] \n"\
" strneh r9, [%[screen], #" p5 "] \n"\
"3: \n"
FN1("0", "0", "7", "1", "2", "6")
FN1("2", "4", "5", "3", "6", "4")
FN1("4", "8", "3", "5", "10", "2")
FN1("6", "12", "1", "7", "14", "0")
// Loop
" sub %[bp], %[bp], #8 \n"
" add %[screen], %[screen], #640 \n"
" add %[depth], %[depth], #320 \n"
" subs %[lcount], %[lcount], #1 \n"
" bne 2b"
// output
: // none
// input
: [lcount] "r" (LineCount),
[gfx_z1] "r" (GFX.Z1),
[gfx_z2] "r" (GFX.Z2),
[screen] "r" ((uint16 *) GFX.S + Offset),
[colors] "r" (GFX.ScreenColors),
[depth] "r" (GFX.DB + Offset),
[bp] "r" (pCache + 56 - StartLine)
// clobbered
: "r9", "r8", "cc" // r8 & flags
);
}
} else {
if (!(Tile & H_FLIP)){
asm volatile (
"2: \n"
FN("0", "0", "1", "2")
FN("2", "4", "3", "6")
FN("4", "8", "5", "10")
FN("6", "12", "7", "14")
// Loop
" add %[bp], %[bp], #8 \n"
" add %[screen], %[screen], #640 \n"
" add %[depth], %[depth], #320 \n"
" subs %[lcount], %[lcount], #1 \n"
" bne 2b"
// output
: // none
// input
: [lcount] "r" (LineCount),
[gfx_z1] "r" (GFX.Z1),
[gfx_z2] "r" (GFX.Z2),
[screen] "r" ((uint16 *) GFX.S + Offset),
[colors] "r" (GFX.ScreenColors),
[depth] "r" (GFX.DB + Offset),
[bp] "r" (pCache + StartLine)
// clobbered
: "r9", "r8", "cc" // r8 & flags
);
} else {
asm volatile (
"2: \n"
FN1("0", "0", "7", "1", "2", "6")
FN1("2", "4", "5", "3", "6", "4")
FN1("4", "8", "3", "5", "10", "2")
FN1("6", "12", "1", "7", "14", "0")
// Loop
" add %[bp], %[bp], #8 \n"
" add %[screen], %[screen], #640 \n"
" add %[depth], %[depth], #320 \n"
" subs %[lcount], %[lcount], #1 \n"
" bne 2b"
// output
: // none
// input
: [lcount] "r" (LineCount),
[gfx_z1] "r" (GFX.Z1),
[gfx_z2] "r" (GFX.Z2),
[screen] "r" ((uint16 *) GFX.S + Offset),
[colors] "r" (GFX.ScreenColors),
[depth] "r" (GFX.DB + Offset),
[bp] "r" (pCache + StartLine)
// clobbered
: "r9", "r8", "cc" // r8 & flags
);
}
}
#undef FN
#undef FN1
}
// DrawClippedTile16NoPrio -----------------------------------------
void DrawClippedTile16NoPrio (uint32 Tile, uint32 Offset,
uint32 StartPixel, uint32 Width,
uint32 StartLine, uint32 LineCount)
{
if (Width == 0) return;
TILE_PREAMBLE
Offset = Offset + StartPixel;
if (Tile & V_FLIP){
if (!(Tile & H_FLIP)){
asm volatile (
"2: \n"
#define FN(p) \
" ldrb r9, [%[bp], #" p "] \n"\
" movs r9, r9, lsl #2 \n"\
" ldrne r9, [%[colors], r9] \n"\
" strneb %[gfx_z2], [%[depth], #" p "] \n"\
" strneh r9, [%[screen], #(" p " * 2)] \n"\
"3: \n"
#define C(p) " cmp %[width], #(" p " + 1) \n"\
" beq 1f \n"
FN("0")
C("0")
FN("1")
C("1")
FN("2")
C("2")
FN("3")
C("3")
FN("4")
C("4")
FN("5")
C("5")
FN("6")
C("6")
FN("7")
// Loop
"1: \n"
" sub %[bp], %[bp], #8 \n"
" add %[screen], %[screen], #640 \n"
" add %[depth], %[depth], #320 \n"
" subs %[lcount], %[lcount], #1 \n"
" bne 2b"
// output
: // none
// input
: [lcount] "r" (LineCount),
[gfx_z1] "r" (GFX.Z1),
[gfx_z2] "r" (GFX.Z2),
[screen] "r" ((uint16 *) GFX.S + Offset),
[colors] "r" (GFX.ScreenColors),
[depth] "r" (GFX.DB + Offset),
[width] "r" (Width),
[bp] "r" (pCache + 56 - StartLine + StartPixel)
// clobbered
: "r9", "cc" // r8 & flags
);
} else {
asm volatile (
"2: \n"
#define FN1(p) \
" ldrb r9, [%[bp], #(7 - " p ")] \n"\
" movs r9, r9, lsl #2 \n"\
" ldrne r9, [%[colors], r9] \n"\
" strneb %[gfx_z2], [%[depth], #" p "] \n"\
" strneh r9, [%[screen], #(" p " * 2)] \n"\
"3: \n"\
FN1("0")
C("0")
FN1("1")
C("1")
FN1("2")
C("2")
FN1("3")
C("3")
FN1("4")
C("4")
FN1("5")
C("5")
FN1("6")
C("6")
FN1("7")
// Loop
"1: \n"
" sub %[bp], %[bp], #8 \n"
" add %[screen], %[screen], #640 \n"
" add %[depth], %[depth], #320 \n"
" subs %[lcount], %[lcount], #1 \n"
" bne 2b"
// output
: // none
// input
: [lcount] "r" (LineCount),
[gfx_z1] "r" (GFX.Z1),
[gfx_z2] "r" (GFX.Z2),
[screen] "r" ((uint16 *) GFX.S + Offset),
[colors] "r" (GFX.ScreenColors),
[depth] "r" (GFX.DB + Offset),
[width] "r" (Width),
[bp] "r" (pCache + 56 - StartLine - StartPixel)
// clobbered
: "r9", "cc" // r8 & flags
);
}
} else {
if (!(Tile & H_FLIP)){
asm volatile (
"2: \n"
FN("0")
C("0")
FN("1")
C("1")
FN("2")
C("2")
FN("3")
C("3")
FN("4")
C("4")
FN("5")
C("5")
FN("6")
C("6")
FN("7")
// Loop
"1: \n"
" add %[bp], %[bp], #8 \n"
" add %[screen], %[screen], #640 \n"
" add %[depth], %[depth], #320 \n"
" subs %[lcount], %[lcount], #1 \n"
" bne 2b"
// output
: // none
// input
: [lcount] "r" (LineCount),
[gfx_z1] "r" (GFX.Z1),
[gfx_z2] "r" (GFX.Z2),
[screen] "r" ((uint16 *) GFX.S + Offset),
[colors] "r" (GFX.ScreenColors),
[depth] "r" (GFX.DB + Offset),
[width] "r" (Width),
[bp] "r" (pCache + StartLine + StartPixel)
// clobbered
: "r9", "cc" // r8 & flags
);
} else {
asm volatile (
"2: \n"
FN1("0")
C("0")
FN1("1")
C("1")
FN1("2")
C("2")
FN1("3")
C("3")
FN1("4")
C("4")
FN1("5")
C("5")
FN1("6")
C("6")
FN1("7")
// Loop
"1: \n"
" add %[bp], %[bp], #8 \n"
" add %[screen], %[screen], #640 \n"
" add %[depth], %[depth], #320 \n"
" subs %[lcount], %[lcount], #1 \n"
" bne 2b"
// output
: // none
// input
: [lcount] "r" (LineCount),
[gfx_z1] "r" (GFX.Z1),
[gfx_z2] "r" (GFX.Z2),
[screen] "r" ((uint16 *) GFX.S + Offset),
[colors] "r" (GFX.ScreenColors),
[depth] "r" (GFX.DB + Offset),
[width] "r" (Width),
[bp] "r" (pCache + StartLine - StartPixel)
// clobbered
: "r9", "cc" // r8 & flags
);
}
}
#undef FN
#undef FN1
#undef C
}
|