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
|
#include "native.h"
#include "endianutils.h"
#define MAIN_TYPE ParallaxType
#include "macros.h"
#define READ_LE_UINT32(ptr) *(const uint32 *)(ptr)
UInt32 Screen_renderParallax(void *userData68KP) {
// import variables
SETPTR (UInt8 * ,data );
SETPTR (UInt32 * ,lineIndexes);
SETPTR (UInt8 * ,_screenBuf );
SET16 (UInt16, _scrnSizeX );
SET16 (UInt16, scrnScrlX );
SET16 (UInt16, scrnScrlY );
SET16 (UInt16, paraScrlX );
SET16 (UInt16, paraScrlY );
SET16 (UInt16, scrnWidth );
SET16 (UInt16, scrnHeight );
// end of import
for (uint16 cnty = 0; cnty < scrnHeight; cnty++) {
uint8 *src = data + READ_LE_UINT32(lineIndexes + cnty + paraScrlY);
uint8 *dest = _screenBuf + scrnScrlX + (cnty + scrnScrlY) * _scrnSizeX;
uint16 remain = paraScrlX;
uint16 xPos = 0;
bool copyFirst = false;
while (remain) { // skip past the first part of the parallax to get to the right scrolling position
uint8 doSkip = *src++;
if (doSkip <= remain)
remain -= doSkip;
else {
xPos = doSkip - remain;
dest += xPos;
remain = 0;
}
if (remain) {
uint8 doCopy = *src++;
if (doCopy <= remain) {
remain -= doCopy;
src += doCopy;
} else {
uint16 remCopy = doCopy - remain;
MemMove(dest, src + remain, remCopy);
dest += remCopy;
src += doCopy;
xPos = remCopy;
remain = 0;
}
} else
copyFirst = true;
}
while (xPos < scrnWidth) {
if (!copyFirst) {
if (uint8 skip = *src++) {
dest += skip;
xPos += skip;
}
} else
copyFirst = false;
if (xPos < scrnWidth) {
if (uint8 doCopy = *src++) {
if (xPos + doCopy > scrnWidth)
doCopy = scrnWidth - xPos;
MemMove(dest, src, doCopy);
dest += doCopy;
xPos += doCopy;
src += doCopy;
}
}
}
}
return 0;
}
|