-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathf_wipe.c
More file actions
242 lines (198 loc) · 4.31 KB
/
f_wipe.c
File metadata and controls
242 lines (198 loc) · 4.31 KB
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
#include "doomdef.h"
#include "mars.h"
static short *melt_yy;
//
// SCREEN WIPE PACKAGE
//
int wipe_InitMelt(short *y)
{
int i, r;
int width = WIPEWIDTH;
// setup initial column positions
// (y<0 => not ready to scroll yet)
y[0] = -(M_Random()%16);
for (i=1;i<width;i++)
{
r = (M_Random()%3) - 1;
y[i] = y[i-1] + r;
if (y[i] > 0) y[i] = 0;
else if (y[i] == -16) y[i] = -15;
}
return 0;
}
#ifdef MARS
static char wipe_lock = 0;
static void wipe_lockMelt(void)
{
int res;
do {
__asm volatile (\
"tas.b %1\n\t" \
"movt %0\n\t" \
: "=&r" (res) \
: "m" (wipe_lock) \
);
} while (res == 0);
}
static void wipe_unlockMelt(void)
{
wipe_lock = 0;
}
static int wipe_getNextMeltCol(void)
{
int col;
wipe_lockMelt();
col = MARS_SYS_COMM6;
MARS_SYS_COMM6 = col + 1;
wipe_unlockMelt();
return col;
}
#endif
static void wipe_meltBottomUp(void)
{
int i;
short *yy = melt_yy;
int width = WIPEWIDTH;
int height = I_FrameBufferHeight();
short *fb = (short *)I_FrameBuffer();
#ifdef MARS
__asm volatile("mov %1,%0\n\t" : "=&r" (width) : "r"(WIPEWIDTH));
#endif
for (i=0;i<width;i++)
{
int j;
unsigned dy, oy;
unsigned n;
short* s;
short* d;
#ifdef MARS
i = wipe_getNextMeltCol();
if (i >= width)
break;
#endif
dy = yy[i];
if (dy == 0)
continue;
oy = (dy >> 8) & 0xff;
dy = dy & 0xff;
d = &fb[(height - 1)*width + i];
s = &fb[(height - dy - 1)*width + i];
j = height - oy - dy - 1;
if (j <= 0)
continue;
n = ((unsigned)j + 3) >> 2;
switch (j & 3)
{
case 0: do { *d = *s, d -= width, s -= width;
case 3: *d = *s, d -= width, s -= width;
case 2: *d = *s, d -= width, s -= width;
case 1: *d = *s, d -= width, s -= width;
} while (--n > 0);
}
}
}
static int wipe_doMelt(short *y, short *yy, int ticks, int step)
{
int i;
int width = WIPEWIDTH;
int height = I_FrameBufferHeight();
#ifdef MARS
int movy = I_IsPAL() ? 5 : 4; // half the original movement to account for double buffering
#else
int movy = 8;
#endif
boolean done;
done = true;
for (i=0;i<width;i++)
{
int t;
int dy, oy;
if (step > 0)
{
/* restore columns from the previous step */
dy = (uint16_t)yy[i];
if (dy > 0)
{
done = false;
oy = ((unsigned)dy >> 8) & 0xff;
dy = (unsigned)dy & 0xff;
#ifdef MARS
Mars_LoadWordColumnFromMDVRAM(i, oy, dy);
#endif
}
}
oy = y[i];
for (t = 0; t < ticks; t++)
{
if (y[i]<0)
{
y[i]++;
done = false;
}
else if (y[i] < height)
{
dy = (y[i] < 16) ? y[i]+1 : movy;
if (y[i]+dy >= height) dy = height - y[i];
y[i] += dy;
done = false;
}
}
dy = y[i];
if (oy < 0)
oy = 0;
if (dy <= oy)
dy = oy = 0;
dy = dy - oy;
yy[i] = ((unsigned)oy<<8)|dy;
}
#ifdef MARS
Mars_Finish();
#endif
UpdateBuffer();
melt_yy = yy;
#ifdef MARS
Mars_melt_BeginWipe();
#endif
wipe_meltBottomUp();
#ifdef MARS
Mars_melt_EndWipe();
#endif
return done;
}
#ifdef MARS
void Mars_Sec_wipe_doMelt(void)
{
Mars_ClearCache();
wipe_meltBottomUp();
}
#endif
int wipe_ExitMelt(void)
{
#ifdef MARS
// re-init the VDP and VRAM on the MD
Mars_CtlMDVDP(1);
clearscreen = 2;
#endif
return 0;
}
int wipe_StartScreen(void)
{
#ifdef MARS
Mars_CtlMDVDP(0);
#endif
I_StoreScreenCopy();
UpdateBuffer();
I_RestoreScreenCopy();
return 0;
}
int wipe_EndScreen(void)
{
I_SwapScreenCopy();
// the new screen is now stored on the MD
// the start screen is back in 32X framebuffer
return 0;
}
int wipe_ScreenWipe(short *y, short *yy, int ticks, int step)
{
return wipe_doMelt(y, yy, ticks, step);
}