-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
434 lines (401 loc) · 15.4 KB
/
main.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
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
#include <lib.h>
#include<sound.h>
int loopcounter1,loopcounter2;
int waitcount,cyc;
int maxheight=22;
int lastheight=10;
int shipx=4,shipy=10;
int score = 0;
int a=0;
int shipcolour=4;
int aliencolour=1;
int alienflag=0;
int aliencounter=0;
int bufferstart= 44960; //start memory location of screen buffer
int bufferend =46079; //end memory location of text screen
int scrnstart=48000; //start memory location of text screen
int scrnend =49119; //end memory location of text screen
int shipmem =46856; //end memory location of ship characters
const char blanks[4] = " ";
char *writePtr; //declare pointers for screen and ship memory locations
char *writePtr2;
char *shipPtr;
char *shipPtr2;
char *scrnshipPtr;
char *scrnshipPtr2;
char *alienPtr;
char *alienPtr2;
char *scrnalienPtr;
char *scrnalienPtr2;
char *tmpPtr; //temp pointer for various routines
char *keyPtr; //mem location for keyboard scan
char *x; // pointer for plotship routine
char y[4]=" "; //blanks to erase last ship position
int z;
char *w; //pointer for plotship routine
int touch; //keyboard scan result
int terrain;
char ship[4]="abcd";
char ship1 [4]= "abcd";
char ship2 [4]= "efgh";
char alien[4]="ijk ";
char redefchar[88]=
{
0,36,16,31,8,36,0,0,
15,0,0,63,31,0,0,0,
63,2,7,58,54,58,31,15,
63,0,48,40,38,51,63,62,
0,8,16,63,8,16,0,0,
0,0,0,63,31,0,0,0,
15,2,7,58,54,58,31,15,
32,0,48,40,38,51,63,62,
0,0,3,15,3,0,0,0,
32,63,42,21,42,63,36,0,
32,32,56,30,56,32,32,0
};
char intros[1120]={
16,7,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,
16,7,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,
16,1,32,32,32,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,16,32,32,32,
16,1,32,32,32,20,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,20,16,32,32,32,
16,1,32,32,32,20,18,127,127,127,18,127,18,127,18,127,127,127,18,127,127,127,18,127,127,127,18,127,127,127,18,127,127,127,18,20,16,32,32,32,
16,1,32,32,32,20,18,127,18,18,18,127,18,127,18,127,18,127,18,127,18,127,18,127,18,127,18,127,18,18,18,127,18,127,18,20,16,32,32,32,
16,1,32,32,32,20,18,127,18,18,18,127,18,127,18,127,18,127,18,127,18,127,18,127,18,127,18,127,18,18,18,127,18,127,18,20,16,32,32,32,
16,1,32,32,32,20,18,127,18,18,18,127,127,127,18,127,18,127,18,127,127,127,18,127,127,127,18,127,127,127,18,127,127,18,18,20,16,32,32,32,
16,1,32,32,32,20,18,127,18,18,18,127,18,127,18,127,18,127,18,127,18,18,18,127,18,18,18,127,18,18,18,127,127,18,18,20,16,32,32,32,
16,1,32,32,32,20,18,127,18,18,18,127,18,127,18,127,18,127,18,127,18,18,18,127,18,18,18,127,18,18,18,127,18,127,18,20,16,32,32,32,
16,1,32,32,32,20,18,127,127,127,18,127,18,127,18,127,127,127,18,127,18,18,18,127,18,18,18,127,127,127,18,127,18,127,18,20,16,32,32,32,
16,7,32,32,32,20,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,20,16,32,32,32,
16,7,32,32,32,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,16,32,32,32,
16,7,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,
16,7,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,
16,7,32,32,32,32,32,32,32,32,32,32,32,32,75,69,89,83,58,65,45,85,80,32,32,32,32,32,1,105,106,107,7,32,32,32,32,32,32,32,
16,7,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,
16,7,32,4,97,98,99,100,7,32,32,32,32,32,32,32,32,32,32,90,45,68,79,87,78,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,
16,7,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,
16,7,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,75,45,76,69,70,84,32,32,32,32,32,1,1,105,106,107,7,32,32,32,32,
16,7,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,
16,7,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,76,45,82,73,71,72,84,32,32,32,32,32,32,32,32,32,32,32,32,32,32,
16,7,32,32,4,97,98,99,100,7,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,
16,7,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,
16,7,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,
16,7,32,32,32,32,32,32,32,32,32,32,80,82,69,83,83,32,69,78,84,69,82,32,84,79,32,83,84,65,82,84,32,32,32,32,32,32,32,32,
16,7,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,
16,7,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32
};
char level1[1120]={
22,7,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,
22,7,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,
22,7,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,
22,7,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,
22,7,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,
22,7,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,
22,7,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,
22,7,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,
22,7,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,
22,7,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,
22,7,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,
22,7,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,
22,7,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,
22,0,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,
22,0,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,
22,0,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,
22,0,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,
22,0,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,
22,0,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,
22,0,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,
22,2,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,
22,2,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,
22,2,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,
22,2,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,
22,2,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,
22,2,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,
22,2,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,
22,2,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32
};
int lvl1cols[26]={7,7,7,7,7,7,7,7,7,7,7,7,7,0,0,0,0,0,0,2,2,2,2,2,2,2
};
void main()
{
//set up basic conditions - redef chars, curso and keyclicks
//void w8912(unsigned char reg,unsigned char value); Future use for sound?
keyPtr=(char*)520; //mem location for keyboard scanning
memcpy((unsigned char*)shipmem,redefchar,88); //redine characters
tmpPtr=(char*)618;
*tmpPtr=10; // turn off cursor and keyboard click
introscreen();
cls(); //clear screen - oric specific command to be replaced
memcpy(ship,ship1,4);
play (58,80,100,60); //chopper sound - oric specifc command to be replaced
startgame();
}
void scroll()
{
int ret = strcmp(ship, ship1); //animate chopper - flip between 2 characters
if (ret<0)
{
memcpy(ship,ship2,4);
}
else
{
memcpy(ship,ship1,4);
}
memcpy((unsigned char*)shipPtr,blanks,4); //blank out ship
memcpy((unsigned char*)shipPtr+1,ship,4);
writePtr= (char*)bufferstart +82 ;
writePtr2=(char*)bufferstart+83;
for (loopcounter1=1;loopcounter1<26;loopcounter1++)
{
memcpy((void*)writePtr,(void*)writePtr2,38); // scroll buffer memory for each row
writePtr+=40;
writePtr2+=40;
}
memcpy(y,ship,4);
plotship(scrnshipPtr,4,shipPtr,shipcolour);
aliencounter ++;
if(aliencounter>=40)
{
aliencounter = 0;
alienflag =1;
alienPtr=(char*)(bufferstart+33+((26-lastheight)/2*40));
alienPtr2=(char*)(bufferstart+32+((26-lastheight)/2*40));
scrnalienPtr=(char*)(scrnstart+33+((26-lastheight)/2*40));
scrnalienPtr2=(char*)(scrnstart+32+((26-lastheight)/2*40));
}
if (alienflag==1)
{
memcpy(y,alien,4);
plotship(scrnalienPtr,4,alienPtr,aliencolour);
alienflag=0;
}
}
void nextmountain()
{
if (rand()%100>=50) // random up or down on terrain
{
lastheight=lastheight + 1;
}
else
{
lastheight=lastheight - 1;
}
if (lastheight>maxheight)
{
lastheight = maxheight-1;
}
if (lastheight<3)
{
lastheight = 3;
}
writePtr= (char*)(bufferstart+117 ) ; //set pointer for screen buffer
for (loopcounter1=26;loopcounter1>1;loopcounter1--)
{
if (lastheight>loopcounter1)
{
*writePtr=127;
}
else
{
*writePtr=32; // add new characters to ernd column
}
writePtr+=40;
}
}
void init_terrain() //create start terrain and put characters into buffer
{
for (loopcounter1=3;loopcounter1<41;loopcounter1++)
{
if (rand()%100>=50)
{
lastheight=lastheight + 1;
}
else
{
lastheight=lastheight - 1;
}
if (lastheight>maxheight)
{
lastheight = maxheight-1;
}
if (lastheight<2)
{
lastheight = 2;
}
writePtr= (char*)(bufferstart+loopcounter1+79 ) ; //set pointer for screen buffer
for (loopcounter2=26;loopcounter2>1;loopcounter2--)
{
if (lastheight>loopcounter2)
{
*writePtr=127;
}
else
{
*writePtr=32; // add new characters to end column
}
writePtr+=40;
}
}
flipscrn();
}
void init_screen()
{
memcpy((unsigned char*)bufferstart,(unsigned char*)scrnstart,bufferend-bufferstart); //copy buffer to screen
}
void wait(int cyc)
{
for (waitcount=1;waitcount<cyc;waitcount++)
{
// just a wait
}
}
void startgame()
{
a=0;
memcpy((unsigned char*)bufferstart,level1,1120);
memcpy((unsigned char*)scrnstart,level1,1120);
init_screen();
init_terrain(); //create starting terrain
wait(25000);
score=0;
shipx=4; //ship x
shipy=10; //ship y
shipPtr= (char*)(bufferstart+shipx+shipy*40) ; //set pointer for screen buffer
shipPtr2= (char*)(bufferstart+shipx+shipy*40-1) ; //set pointer for screen buffer to blank after scroll
scrnshipPtr= (char*)(scrnstart+shipx+shipy*40) ; //set pointer for screen buffer
scrnshipPtr2= (char*)(scrnstart+shipx+shipy*40-1) ; //set pointer for screen buffer to blank after scroll
memcpy(y,ship,4);
plotship(scrnshipPtr,4,shipPtr,shipcolour);
playgame();
}
void playgame()
{
do // main play loop
{
getkeys(); // check for key press
tmpPtr = (char*)(bufferstart+shipx+5+shipy*40);
if (*tmpPtr>32) //basic collision check
{
collision();
}
plotblanks();
scroll();
nextmountain(); //generate last column of terrain after scrolling
memcpy(y,ship,4);
plotship(scrnshipPtr,4,shipPtr,shipcolour);
flipscrn(); // swap buffer to screen
}
while( a ==0 );
gameover();
}
void flipscrn()
{
memcpy((unsigned char*)scrnstart,(unsigned char*)bufferstart,bufferend-bufferstart); // buffer to screen
memcpy((unsigned char*)bufferstart,(unsigned char*)scrnstart,bufferend-bufferstart); // copy new screen to buffer
}
void getkeys()
{
touch=0x7f&*keyPtr; // keyboard check and basic screen limits for movement
if(touch==56)
{
return;
}
if ((touch==15) && (shipx!=33) )
{
plotblanks();
shipx++;
shipPtr++;
shipPtr2++;
scrnshipPtr++;
scrnshipPtr2++;
memcpy((unsigned char*)scrnshipPtr-1,blanks,4);
memcpy(y,ship,4);
plotship(scrnshipPtr,4,shipPtr,shipcolour);
return;
}
if ((touch==3) && (shipx!=4))
{
plotblanks();
shipx--;
shipPtr--;
shipPtr2--;
scrnshipPtr--;
scrnshipPtr2--;
memcpy((unsigned char*)scrnshipPtr+1,blanks,4);
memcpy(y,ship,4);
plotship(scrnshipPtr,4,shipPtr,shipcolour);
return;
}
if ((touch==46) && (shipy!=2) )
{
plotblanks();
shipy--;
shipPtr-=40;
shipPtr2-=40;
scrnshipPtr-=40;
scrnshipPtr2-=40;
memcpy((unsigned char*)scrnshipPtr+40,blanks,4);
memcpy(y,ship,4);
plotship(scrnshipPtr,4,shipPtr,shipcolour);
return;
}
if ((touch==42) && (shipy!=24) )
{
plotblanks();
shipy++;
shipPtr+=40;
shipPtr2+=40;
scrnshipPtr+=40;
scrnshipPtr2+=40;
memcpy((unsigned char*)scrnshipPtr-40,blanks,4);
memcpy(y,ship,4);
plotship(scrnshipPtr,4,shipPtr,shipcolour);
return;
}
}
void collision()
{
a=1; // will stop the main do...while and go to game over routine
}
void firebullet()
{
// use plotship routine after bullet init
}
void movebullet()
{
// nothing as yet - use plotship routine
}
void plotship(x,z,w,thiscol) //actually plots any item to position sent to routine and colour and maintains terrain colours
{
memcpy((unsigned char*)x,y,z);
memcpy((unsigned char*)w,y,z);
memset((unsigned char*)x-1,thiscol,1); // colour for item
memset((unsigned char*)w-1,thiscol,1); // colour for item
memset((unsigned char*)x+4,lvl1cols[shipy-1],1);
memset((unsigned char*)w+4,lvl1cols[shipy-1],1);
}
void plotblanks()
{
memcpy((unsigned char*)shipPtr,blanks,4);
//memcpy((unsigned char*)scrnshipPtr,blanks,4);
}
void gameover()
{
play (58,80,100,60);
explode;
printf("You Hit Something"); //basic collision
wait(22000);
//memcpy((unsigned char*)bufferstart,(unsigned char*)scrnstart,bufferend-bufferstart);
main();
//startgame(); //just returns to scrolling action
}
void introscreen()
{
char c;
memcpy((unsigned char*)bufferstart,intros,1120);
flipscrn();
while (0x7f&*keyPtr ==56); //repeat until enter 56
{
// wait for enter key
}
wait(5000);
}