-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathARM.c
168 lines (123 loc) · 3.35 KB
/
ARM.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
#include "ARM.h"
#include <math.h>
void ClaimWRAM()
{
WRAMCNT=WRAMCNT_ARM9_ALL;
asm volatile (
" mcr p15,0,%0,C6,C2,0\n" // Configure region 2 as 16 MB from 0x3000000
" mrc p15,0,r0,C5,C0,0\n"
" orr r0,r0,#0x30\n"
" mcr p15,0,r0,C5,C0,0\n" // Enable data read/write for region 2
::"r" (0x300002f):"r2");
}
#define Width 128
#define FullWidth 128
#define Height 96
static inline int32_t approxabs(int32_t x) { return x^(x>>31); }
// Uncomment to force inlining.
//static inline int ATTR_ITCM __attribute__((always_inline)) RenderPixel(int32_t x,int32_t y,int32_t z,int32_t dx,int32_t dy,int32_t dz);
static inline int ATTR_ITCM RenderPixel(int32_t x,int32_t y,int32_t z,int32_t dx,int32_t dy,int32_t dz);
static inline int ATTR_ITCM RenderPixel(int32_t x,int32_t y,int32_t z,int32_t dx,int32_t dy,int32_t dz)
{
int i=23;
while(i)
{
/* int32_t tx=approxabs(x)>>15;
int32_t ty=approxabs(y)>>15;
int32_t tz=approxabs(z)>>15;
int32_t dist=tx;
if(ty>dist) dist=ty;
if(tz>dist) dist=tz;
dist-=0x8000;
if(dist<0x800) break;*/
int32_t tx=approxabs(x)>>16;
int32_t ty=approxabs(y)>>16;
int32_t tz=approxabs(z)>>16;
// int32_t dist=tx+ty+tz-0x8000;
int32_t dist=(tx+ty+(tz&0xf0f0))-0x8000;
// int32_t dist=(tx+ty+(tz&0x005555))-0x8000;
//
if(dist<=0x400) break;
/* int32_t tx=approxabs(x)>>15;
int32_t ty=approxabs(y)>>15;
int32_t tz=approxabs(z)>>15;
int32_t dist1=tx;
if(tz>dist1) dist1=tz;
int32_t dist2=tx;
if(ty>dist2) dist2=ty;
int32_t dist=dist1;
if(dist2<dist1) dist=dist2;
dist-=0x4000;
if(dist<0x400) break;*/
/* int32_t tx=approxabs(x)>>15;
int32_t ty=approxabs(y)>>15;
int32_t tz=approxabs(z)>>15;
int32_t dist1=tx;
if(tz>dist1) dist1=tz;
int32_t dist2=tx;
if(ty>dist2) dist2=ty;
int32_t dist3=ty;
if(tz>dist3) dist3=tz;
int32_t dist=dist1;
if(dist2<dist) dist=dist2;
if(dist3<dist) dist=dist3;
dist-=0x4000;
if(dist<0x400) break;*/
/* int32_t tx=approxabs(x)>>16;
int32_t ty=approxabs(y)>>16;
int32_t tz=approxabs(z)>>16;
int32_t dist=approxabs(ty-tz)+tx-0x3000;
if(dist<0x200) break;*/
/* int32_t tx=approxabs(x)>>16;
int32_t ty=approxabs(y)>>16;
int32_t tz=approxabs(z)>>16;
// int32_t dist=(tx|ty^tz)-0x5000;
// int32_t dist=(tx|ty&tz)-0x5000;
// int32_t dist=(tx|ty+tz)-0x5000;
// int32_t dist=(tx+ty)&tz-0x8000;
int32_t dist=(tx+ty+(tz&0xf0f0))-0x8000;
// int32_t dist=(tx+ty+(tz&0x005555))-0x8000;
if(dist<0x200) break;
*/
/* int32_t tx=approxabs(x)>>16;
int32_t ty=approxabs(y)>>15;
int32_t tz=approxabs(z)>>16;
int32_t dist=(tx+(ty&0xc3c3c000)+(tz&0xf0f0f0f0))-0x8000;
if(dist<0x200) break;*/
x+=dx*dist;
y+=dy*dist;
z+=dz*dist;
i--;
}
return i;
}
void ATTR_ITCM RenderFieldARM(int t,uint16_t *vram,int16_t *rays)
{
int32_t x0=(0+Fix(0.5))<<20;
int32_t y0=(isin(t*7)+Fix(0.5))<<20;
int32_t z0=(t*50+Fix(0.5))<<20;
int32_t sin_a=isin(t*5);
int32_t cos_a=icos(t*5);
for(int y=0;y<Height;y++)
{
for(int x=0;x<Width/2;x++)
{
int32_t dx=*rays++;
int32_t dy=*rays++;
int32_t dz=*rays++;
int32_t t=(dx*cos_a+dz*sin_a)>>12;
dz=(-dx*sin_a+dz*cos_a)>>12;
dx=t;
int i1=RenderPixel(x0,y0,z0,dx,dy,dz);
dx=*rays++;
dy=*rays++;
dz=*rays++;
t=(dx*cos_a+dz*sin_a)>>12;
dz=(-dx*sin_a+dz*cos_a)>>12;
dx=t;
int i2=RenderPixel(x0,y0,z0,dx,dy,dz);
*vram++=(i2<<8)|i1;
}
vram+=(FullWidth-Width)/2;
}
}