/[projet1]/public/oric/demos/AlchimieX/main.c
Defence Force logotype

Contents of /public/oric/demos/AlchimieX/main.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 970 - (show annotations)
Tue Nov 12 20:07:47 2013 UTC (5 years, 10 months ago) by dbug
File MIME type: text/plain
File size: 6146 byte(s)
Source code for the AlchimieGarden demo
1 //
2 // AlchimieGarden
3 //
4 // An Oric intro for Alchimie-X coded at the Kindergarden 2013 demo party.
5 //
6 //
7 #include <lib.h>
8
9 #include "script.h"
10
11
12 extern unsigned char LabelPictureAlchemieLogo[];
13 extern unsigned char LabelPictureKindergardenLogo[];
14 extern unsigned char LabelPictureEvolution[];
15 extern unsigned char PictureShip[]; // 126x56 (21 blocs)
16
17 extern unsigned char ScrollerCommand;
18 extern unsigned char ScrollerCommandParam1;
19 extern unsigned char ScrollerCommandParam2;
20 extern unsigned char ScrollerCommandParam3;
21 extern unsigned char ScrollerCommandParam4;
22
23
24
25 void System_InstallIRQ_SimpleVbl();
26 void ScrollerInit();
27
28
29 void (*BottomEffectCallBack)(void);
30 void (*TopEffectCallBack)(void);
31
32
33
34 // http://www-users.cs.york.ac.uk/~jowen/hashlife.html
35
36 #define GOL_WIDTH 32
37 #define GOL_HEIGHT 8
38
39 #define GOL_GLIDER 0
40 #define GOL_FPENTAMINO 1
41 #define GOL_BLINKER 2
42 #define GOL_BLOCK 3
43 #define GOL_SMALLSHIP 4
44
45
46
47 extern unsigned char GameOfLifeBuffer1[GOL_WIDTH*GOL_HEIGHT];
48 extern unsigned char GameOfLifeBuffer2[GOL_WIDTH*GOL_HEIGHT];
49
50 extern unsigned char *ptr_buffer1;
51 extern unsigned char *ptr_buffer2;
52
53 void GOL_DrawPattern(unsigned char x,unsigned char y,unsigned char type)
54 {
55 unsigned char* buffer=ptr_buffer1;
56 buffer+=x+y*GOL_WIDTH;
57
58 switch (type)
59 {
60 case GOL_GLIDER:
61 buffer[(GOL_WIDTH*0)+2]=1;
62 buffer[(GOL_WIDTH*1)+0]=1;
63 buffer[(GOL_WIDTH*1)+2]=1;
64 buffer[(GOL_WIDTH*2)+1]=1;
65 buffer[(GOL_WIDTH*2)+2]=1;
66 break;
67
68 case GOL_FPENTAMINO:
69 buffer[(GOL_WIDTH*0)+1]=1;
70 buffer[(GOL_WIDTH*0)+2]=1;
71 buffer[(GOL_WIDTH*1)+0]=1;
72 buffer[(GOL_WIDTH*1)+1]=1;
73 buffer[(GOL_WIDTH*2)+1]=1;
74 break;
75
76 case GOL_BLINKER:
77 buffer[(GOL_WIDTH*0)+0]=1;
78 buffer[(GOL_WIDTH*0)+1]=1;
79 buffer[(GOL_WIDTH*0)+2]=1;
80 break;
81
82 case GOL_BLOCK:
83 buffer[(GOL_WIDTH*0)+0]=1;
84 buffer[(GOL_WIDTH*0)+1]=1;
85 buffer[(GOL_WIDTH*1)+0]=1;
86 buffer[(GOL_WIDTH*1)+1]=1;
87 break;
88
89 case GOL_SMALLSHIP:
90 buffer[(GOL_WIDTH*0)+1]=1;
91 buffer[(GOL_WIDTH*0)+4]=1;
92 buffer[(GOL_WIDTH*1)+0]=1;
93 buffer[(GOL_WIDTH*2)+0]=1;
94 buffer[(GOL_WIDTH*2)+4]=1;
95 buffer[(GOL_WIDTH*3)+0]=1;
96 buffer[(GOL_WIDTH*3)+1]=1;
97 buffer[(GOL_WIDTH*3)+2]=1;
98 buffer[(GOL_WIDTH*3)+3]=1;
99 break;
100 }
101 }
102
103 void GameOfLife_Init()
104 {
105 GOL_RedefineCharacters();
106
107 ptr_buffer1=GameOfLifeBuffer1;
108 ptr_buffer2=GameOfLifeBuffer2;
109
110 GOL_DrawPattern(5,5,GOL_BLOCK);
111 GOL_DrawPattern(15,5,GOL_BLINKER);
112 GOL_DrawPattern(20,10,GOL_GLIDER);
113 GOL_DrawPattern(5,10,GOL_FPENTAMINO);
114 GOL_DrawPattern(25,5,GOL_SMALLSHIP);
115 }
116
117 unsigned char GameOfLifeCounter=0;
118
119 void GameOfLife()
120 {
121 unsigned char* temp;
122
123 GOL_ShowBuffer();
124 GOL_Evolve();
125 temp=ptr_buffer1;
126 ptr_buffer1=ptr_buffer2;
127 ptr_buffer2=temp;
128
129 GameOfLifeCounter++;
130 if (GameOfLifeCounter==8)
131 {
132 GameOfLifeCounter=0;
133
134 GOL_DrawPattern(rand()&31,rand()&7,rand()%4);
135 }
136 }
137
138
139 void ClearTextWindow()
140 {
141 memset((char*)0xbb80+40*11,32,17*40);
142 poke(0xa000+40*8,16+0); // Black
143
144 poke(0xa000+40*84,16+1);
145 poke(0xa000+40*85,16+3);
146 poke(0xa000+40*86,16+1);
147 poke(0xa000+40*87,16+0);
148 }
149
150
151
152
153 void EffectDoNothing()
154 {
155
156 }
157
158
159 unsigned char ShipPosition=39;
160
161 void SpaceShipAnimation()
162 {
163 int y;
164 int sizeToShow=40-ShipPosition;
165 if (sizeToShow>21)
166 {
167 sizeToShow=21;
168 }
169 if (ShipPosition==0)
170 {
171 TopEffectCallBack=EffectDoNothing;
172 }
173 else
174 {
175 for (y=0;y<56;y++)
176 {
177 memcpy((char*)0xa000+40*9+40*10+y*40+ShipPosition,PictureShip+y*21,sizeToShow);
178 }
179 ShipPosition--;
180 }
181 }
182
183
184
185 extern unsigned char CosTable[256];
186
187 unsigned char angle;
188 unsigned char angle0;
189 unsigned char angle1;
190
191 extern unsigned char zoom;
192 extern unsigned char zoomstart;
193
194
195
196
197 void ChessBoard_MakeVideoMode()
198 {
199 // void ChessBoard_MakeVideoMode()
200 unsigned char *ptr_screen;
201 unsigned int y,x;
202 unsigned char c,cc,color;
203
204 for (y=88;y<200;y++)
205 {
206 poke(0xa000+40*y+3,26); // TEXT 50
207 }
208
209 for (y=11;y<25;y++)
210 {
211 poke(0xbb80+40*y,30); // HIRES 50
212 }
213
214
215 // Fill the screen with characters to redefine for the zoommer
216 ptr_screen=(unsigned char*)0xbb80+11*40;
217 for (y=11;y<24;y++)
218 {
219 c=32+10;
220 cc=3;
221 for (x=4;x<40;x++)
222 {
223 ptr_screen[x]=c;
224 c++;
225 cc--;
226 if (!cc)
227 {
228 c++;
229 cc=4;
230 }
231 }
232 ptr_screen+=40;
233 }
234 }
235
236
237 void ChessBoard_MainLoop()
238 {
239 zoom=30+(CosTable[angle]>>2);
240
241 zoomstart=1+(((int)zoom)*((int)CosTable[angle0]))/255;
242 DrawHorizontalChecker();
243
244 zoomstart=1+(((int)zoom)*((int)CosTable[angle1]))/255;
245 DrawVerticalChecker();
246
247 angle++;
248 angle0+=2;
249 angle1+=3;
250 }
251
252
253 void main()
254 {
255 //
256 // Clear the screen
257 //
258 memset((char*)0xa000,0,8000);
259
260 //
261 // Pseudo hires switch
262 //
263 ScrollerInit();
264
265 BottomEffectCallBack=EffectDoNothing;
266 TopEffectCallBack=EffectDoNothing;
267
268 System_InstallIRQ_SimpleVbl();
269
270
271 GameOfLife_Init();
272 ClearTextWindow();
273
274 while (1)
275 {
276 if (ScrollerCommand!=SCROLLER_NOTHING)
277 {
278 unsigned char command=ScrollerCommand;
279 ScrollerCommand=SCROLLER_NOTHING;
280 switch (command)
281 {
282 case SCROLLER_SHOW_LOGO:
283 {
284 file_unpack((char*)0xa000+40*9,LabelPictureAlchemieLogo);
285 }
286 break;
287
288 case SCROLLER_SHOW_KGLOGO:
289 {
290 file_unpack((char*)0xa000+40*9,LabelPictureKindergardenLogo);
291 }
292 break;
293
294 case SCROLLER_SHOW_EVOLUTIONLOGO:
295 {
296 file_unpack((char*)0xa000+40*9,LabelPictureEvolution);
297 }
298 break;
299
300 case SCROLLER_START_GAMEOFLIFE:
301 {
302 ClearTextWindow();
303 BottomEffectCallBack=GameOfLife;
304 }
305 break;
306
307 case SCROLLER_SHOW_SPACESHIP:
308 {
309 memset((char*)0xa000+40*9,64,40*75);
310 ShipPosition=39;
311 TopEffectCallBack=SpaceShipAnimation;
312 }
313 break;
314
315 case SCROLLER_START_CHESSBOARD:
316 {
317 ClearTextWindow();
318 ChessBoard_MakeVideoMode();
319 BottomEffectCallBack=ChessBoard_MainLoop;
320 }
321 break;
322
323 case SCROLLER_END:
324 break;
325 }
326 }
327
328 // Stuff
329 BottomEffectCallBack();
330 TopEffectCallBack();
331 }
332 }
333

  ViewVC Help
Powered by ViewVC 1.1.26