This repository has been archived by the owner on May 27, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Snow.c
254 lines (224 loc) · 4.84 KB
/
Snow.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
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
#include "mathf.h"
char *Disp_GetVRAMPtr(void);
int Timer_Install(int TimerID, void (*handler)(void), int delay);
int Timer_Start(int TimerID);
void App_PROG();
int RTC_GetTicks();
void AllClear_VRAM();
typedef struct{
unsigned int x1;
unsigned int y1;
unsigned int x2;
unsigned int y2;
unsigned char f[4];
unsigned int on_bits;
unsigned int off_bits;
} TShape;
void ShapeToVRAM( TShape* x );
char *vram;
const int SysCallWrapper[] = {0xD201422B,0x60F20000,0x80010070};
const int (*iSysCallFuncPtr)( int R4, int R5, int R6, int R7, int FNo ) = (void*)&SysCallWrapper;
#define Alpha_GetData(VarName,Dest) (void)(*iSysCallFuncPtr)( VarName,(int)Dest, 0, 0, 0x04DF)
#define Alpha_ClearAll() (void)(*iSysCallFuncPtr)( 0,0, 0, 0, 0x004E1)
int InputString( unsigned char*buff, unsigned char *heading, int maxlen );
static unsigned int lastrandom=0x12345678;
unsigned int random( int seed){
if (seed) lastrandom=seed;
lastrandom = ( 0x41C64E6D*lastrandom ) + 0x3039;
return ( lastrandom >> 16 );
}
const char sprite[9][3] = {
{ 0 , 1 , 0 },
{ 1 , 1 , 1 },
{ 1 , 0 , 1 },
{ 1 , 0 , 1 },
{ 1 , 0 , 1 },
{ 1 , 1 , 1 },
{ 0 , 0 , 1 },
{ 0 , 0 , 1 },
{ 0 , 0 , 1 }
};
#define abs(x) (x < 0)?-x:x
#define sgn(x) (x < 0)?-1:(x == 0)?0:1
void setpixel(unsigned char x, char y)
{
TShape t;
if(x&~127 || y&~63) return;
t.x1 = x;
t.y1 = y;
t.f[0] = 2;
t.f[1] = 1;
t.f[2] = 1;
t.f[3] = 1;
ShapeToDD(&t);
}
void line(int x1, int y1, int x2, int y2)
{
int i, x, y, dx, dy, sx, sy, cumul;
x = x1;
y = y1;
dx = x2 - x1;
dy = y2 - y1;
sx = sgn(dx);
sy = sgn(dy);
dx = abs(dx);
dy = abs(dy);
setpixel(x, y);
if(dx > dy)
{
cumul = dx / 2;
for(i=1 ; i<dx ; i++)
{
x += sx;
cumul += dy;
if(cumul > dx)
{
cumul -= dx;
y += sy;
}
setpixel(x, y);
}
}
else
{
cumul = dy / 2;
for(i=1 ; i<dy ; i++)
{
y += sy;
cumul += dx;
if(cumul > dy)
{
cumul -= dy;
x += sx;
}
setpixel(x, y);
}
}
}
void drawsprite(unsigned char px, char py, float dirx)
{
char x;
float y;
for(y = 0; y < 9; y += 1)
for(x = 0; x < 3; x++)
if(sprite[(int)y][x] == 1)
setpixel(px + x + ((9 - (int)y) * dirx), py + (int)y);
}
#define P2I 6.28318531
void drawboom(unsigned char px, char py, char boom, float radius)
{
float cnt;
for(cnt = 0; cnt < P2I; cnt += radius)
line(px, py, px + (int)(cosf(cnt) * boom), py + (int)(sinf(cnt) * boom));
}
#define CNT 15
struct {unsigned char active;char boom;float dirx, y, x, radius;} fire[CNT];
void display_vram()
{
char *LCD_register_selector = (char*)0xB4000000, *LCD_data_register = (char*)0xB4010000, *mvram;
int i, j;
mvram = vram;
for(i=0 ; i<64 ; i++)
{
*LCD_register_selector = 4;
*LCD_data_register = i|192;
*LCD_register_selector = 4;
*LCD_data_register = 0;
*LCD_register_selector = 7;
for(j=0 ; j<16 ; j++) *LCD_data_register = *mvram++;
}
}
char isMainMenu()
{
unsigned int ea;
unsigned int j;
ea = *(unsigned int*)0x8001007C;
ea += 0x0490*4;
ea = *(unsigned int*)( ea );
j = *(unsigned char*)( ea + 1 );
j *= 4;
j = ( ea + j + 4 ) & 0xFFFFFFFC;
j = *(unsigned int*)( j ) + 1;
return *(unsigned char*)j;
}
char variable[24]={0};
void snowtimer(void)
{
unsigned char x;
if(!isMainMenu())
{
display_vram();
for(x =CNT - 1; x > 0 ; x--)
{
if(fire[x].active == 1)
{
if(fire[x].boom == 0)
{
drawsprite(fire[x].x, fire[x].y, fire[x].dirx);
fire[x].y -= fire[x].y / 64;
fire[x].x += fire[x].dirx;
if(fire[x].y == 0 || fire[x].x > 127 || fire[x].x < 0)
fire[x].active = 0;
if(random(0) % (int)fire[x].y == 0 && fire[x].boom == 0)
fire[x].boom++;
}
else
{
drawboom(fire[x].x, fire[x].y, fire[x].boom++, fire[x].radius);
if(fire[x].boom >= (random(0) % 16) + 16)
fire[x].active = 0;
}
}
else
{
if(random(0) % 32 == 0)
{
fire[x].active = 1;
fire[x].x = random(0) % 128;
fire[x].dirx = (random(0) % 20) / 10.0 - 1.0;
fire[x].y = 64;
fire[x].boom = 0;
fire[x].radius = P2I / ((random(0) % 16) + 8);
}
}
}
}
Alpha_GetData('A',variable);
if(variable[0])
{
KillTimer(1);
}
}
int AddIn_main(int isAppli, unsigned short OptionNum)
{
unsigned int key;
unsigned char text[3] = {0xE6, 0x91, 0};
random(RTC_GetTicks());
vram = Disp_GetVRAMPtr();
Alpha_ClearAll();
AllClr_VRAM();
locate(3,3);
Print(&"~*| Firework |*~");
locate(4,1);
Print(&"(C) by Casimo");
locate(4,5);
Print(&"press any key");
locate(6,6);
Print(&"to start");
locate(4,8);
Print(&"exit with 1 A");
locate(15,8);
Print(&text);
display_vram();
GetKey(&key);
Timer_Install(6, &snowtimer, 300);
Timer_Start(6);
App_PROG();
}
#pragma section _BR_Size
unsigned long BR_Size;
#pragma section
#pragma section _TOP
int InitializeSystem(int isAppli, unsigned short OptionNum)
{return INIT_ADDIN_APPLICATION(isAppli, OptionNum);}
#pragma section