/
dstar_gencon.c
733 lines (682 loc) · 20.3 KB
/
dstar_gencon.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
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
/*
* DStar converted to use generic console/conio for drawing
*
* Program history is in other versions of dstar
*
* -DUSE_JOYSTICK switches to using the joystick
* -DUSE_UDGS uses UDGs for the characters
* -DSWITCH_MODE=x switches to screenmode x for display
* -DSOUND or -DSOUNDB adds bells and whistles if available
*/
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <ctype.h>
#include <games.h>
#include <sys/ioctl.h>
#ifdef SOUND
#include <sound.h>
#endif
#ifdef SOUNDB
#include <sound.h>
#endif
/* Key definitions, change these to define your keys! */
#ifndef USE_JOYSTICK
#define K_UP 'Q'
#define K_DOWN 'A'
#define K_LEFT 'O'
#define K_RIGHT 'P'
#define K_SWITCH ' '
#define K_EXIT 'G'
#define K_CLEAR 'H'
#endif
#define MAXLEVEL 25
#define STARTLEV 0 /* Start level -1 */
#define WALL 1
#define BUBB 2
#define BALL 3
#define BOX 4
/* Mapping between block numbers and ascii characters */
#ifdef USE_UDGS
static const unsigned char blocks[] = { ' ', 128, 129, 130, 131 };
#else
static const unsigned char blocks[] = { ' ', 'X', 'o', '@', '#' };
#endif
static unsigned char balloffset; /* Ball position */
static unsigned char boxoffset; /* Box position */
static unsigned char ballorbox; /* 1 if box, 0 if ball */
static unsigned char level; /* Take a guess! */
static unsigned char x_offset;
static unsigned char y_offset;
static unsigned char board[144]; /* Level internal map thing */
#ifdef USE_UDGS
static unsigned char udgs[] = {
0b01111110, // Wall
0b10101001,
0b11000111,
0b10110001,
0b11001011,
0b10100101,
0b10101001,
0b01111110,
0b00000000, // bubble
0b00000000,
0b00011000,
0b00100100,
0b00100100,
0b00011000,
0b00000000,
0b00000000,
0b00000000, // movable ball
0b00111100,
0b01110110,
0b01111010,
0b01111010,
0b01111110,
0b00111100,
0b00000000,
0b00000000, // movable block
0b01111110,
0b01000010,
0b01000010,
0b01000010,
0b01000010,
0b01111110,
0b00000000
};
#endif
// Level definition
static const unsigned char levels[][38] = {
{
17,30, //ball offset, box offset
0b01010101,0b01010101,0b01010101,0b01010101,
0b01000101,0b00000000,0b00000000,0b10010001,
0b01000000,0b00000000,0b00000010,0b00010101,
0b01000000,0b00000000,0b01011000,0b00000001,
0b01000000,0b01010010,0b00000000,0b00000101,
0b01010010,0b00001000,0b00000000,0b10000001,
0b01001000,0b00000000,0b00100101,0b00100001,
0b01000000,0b00000101,0b10000000,0b00001001,
0b01010101,0b01010101,0b01010101,0b01010101
},
{
//.level2
30,86,
0b00010000,0b01000100,0b01000000,0b01000101,
0b01000000,0b10000000,0b00000000,0b00000001,
0b00000001,0b10000001,0b10000000,0b10000000,
0b01000100,0b10000000,0b00001000,0b00010001,
0b00000000,0b00000100,0b00001000,0b00000100,
0b01000000,0b00010001,0b00001000,0b00000001,
0b00000001,0b00000100,0b01000000,0b01101001,
0b01000000,0b00000000,0b00000000,0b00000100,
0b00010000,0b01000000,0b00000000,0b00010000
},
{
//.level3
30,46,
0b01010101,0b01010101,0b01010101,0b01010101,
0b01000000,0b00000000,0b00000000,0b10010001,
0b01000000,0b01010000,0b00000000,0b01010001,
0b01000000,0b01100000,0b00000010,0b00000001,
0b01001000,0b00000000,0b10010100,0b00001001,
0b01000110,0b00001000,0b00100100,0b00100101,
0b01000101,0b10000110,0b00001000,0b10010101,
0b01100000,0b00000101,0b10000000,0b00000001,
0b01010101,0b01010101,0b01010101,0b01010101
},
{
//.level4
125,30,
0b01010101,0b01010101,0b01010101,0b01010101,
0b01000000,0b00000000,0b00000000,0b00010001,
0b01000000,0b00000100,0b00000000,0b00000001,
0b01011001,0b10001001,0b10011001,0b10011001,
0b01000100,0b01100010,0b01000100,0b01000101,
0b01011001,0b10011000,0b10011001,0b10011001,
0b01000000,0b00000100,0b00000000,0b00000001,
0b01000000,0b01000000,0b00000000,0b01000001,
0b01010101,0b01010101,0b01010101,0b01010101
},
{
//.level5
17,110,
0b00010101,0b01010101,0b01010101,0b01010100,
0b01000000,0b01000000,0b01000001,0b00000001,
0b01000001,0b10000100,0b10000010,0b00010001,
0b01010000,0b00000000,0b01000001,0b00000001,
0b01100001,0b10010000,0b00000000,0b00000101,
0b01010000,0b00000001,0b00100001,0b00000001,
0b01100100,0b00010001,0b00010000,0b00010001,
0b01000000,0b01000000,0b00100100,0b00011001,
0b00010101,0b01010101,0b01010101,0b01010100
},
{
//.level6
65,113,
0b00000000,0b01010101,0b01010101,0b01010101,
0b00000001,0b00000010,0b00000001,0b10001001,
0b00000100,0b00000010,0b00000000,0b01000101,
0b00010000,0b00000010,0b00000000,0b00000001,
0b01000000,0b00000010,0b00000000,0b00000001,
0b01010000,0b00000010,0b00000100,0b00000101,
0b01000000,0b00000010,0b00000000,0b01000001,
0b01000001,0b00000010,0b00000101,0b10000001,
0b01010101,0b01010101,0b01010101,0b01010101
},
{
//.level7
115,122,
0b01010101,0b01010101,0b01010101,0b01010101,
0b01000000,0b00000000,0b00000000,0b00000001,
0b00010100,0b01010100,0b00011000,0b01011001,
0b00011000,0b00011000,0b01000100,0b01000100,
0b00000100,0b00010000,0b01010100,0b01010000,
0b00010100,0b00010000,0b01100100,0b01100100,
0b01000000,0b00000000,0b00000000,0b00000001,
0b01000000,0b01100000,0b00000000,0b00011001,
0b01010101,0b01010101,0b01010101,0b01010101
},
{
//.level8
108,98,
0b01010101,0b01010101,0b01010101,0b01010100,
0b01000010,0b01010000,0b00000000,0b00000101,
0b01000001,0b10000001,0b01001000,0b00000001,
0b01000010,0b01010001,0b00011000,0b00000001,
0b01010000,0b00000001,0b01000001,0b10010001,
0b01010001,0b00000000,0b00000010,0b01100001,
0b01100010,0b01000000,0b10000001,0b00010001,
0b01010000,0b00000000,0b00000000,0b00000001,
0b00010101,0b01010101,0b01010101,0b01010101
},
{
//.level9
30,72,
0b00000100,0b01010101,0b01010101,0b01010100,
0b00011001,0b10000000,0b00000001,0b00000001,
0b01100010,0b01000000,0b00100000,0b00000100,
0b00010001,0b00001001,0b01000010,0b01000001,
0b01000001,0b10000110,0b00100000,0b00001001,
0b01000000,0b00001001,0b01000000,0b00000100,
0b01100110,0b00000000,0b00000000,0b00010000,
0b01000000,0b00000000,0b00000000,0b01000000,
0b01010101,0b01010101,0b01010101,0b00000000
},
{
//.level10
93,36,
0b00000000,0b01010101,0b01010101,0b01010100,
0b01010101,0b00100000,0b00000000,0b00000001,
0b01000000,0b00000101,0b01100010,0b01001001,
0b01001000,0b00000110,0b00011000,0b00000100,
0b01000000,0b00000100,0b00100000,0b01001001,
0b01100110,0b00000100,0b10010000,0b01000100,
0b00011000,0b00000101,0b01000001,0b01010000,
0b01000000,0b00000000,0b00000100,0b01000100,
0b00010101,0b01010101,0b01010000,0b01000001
},
{
//.level11
30,108,
0b01010101,0b01010101,0b01010101,0b01010101,
0b01000000,0b00000001,0b00000000,0b00000001,
0b01000001,0b10100000,0b00000010,0b10000101,
0b01010000,0b00100000,0b00010100,0b00001001,
0b01100000,0b00000110,0b01101000,0b00010101,
0b01010001,0b01000000,0b00010100,0b00000001,
0b01100000,0b10010010,0b00000000,0b00001001,
0b01011001,0b01010000,0b00000100,0b00000101,
0b00010100,0b01010101,0b01010101,0b01010100
},
{
//.level12
17,92,
0b01010000,0b00000001,0b01000001,0b01010100,
0b01000101,0b01010110,0b00010101,0b00100101,
0b01000000,0b00101000,0b00000000,0b10000001,
0b01000101,0b00000101,0b10000001,0b10010001,
0b01000100,0b10000101,0b01100001,0b01000001,
0b01000101,0b00000101,0b00000001,0b00010001,
0b01000000,0b00001000,0b00000000,0b00000001,
0b01000000,0b00000000,0b00100000,0b00000001,
0b01010101,0b01010101,0b01010101,0b01010101
},
{
//.level13
18,113,
0b00010101,0b01010101,0b01010101,0b01010100,
0b01000001,0b00000000,0b00000000,0b10000101,
0b01000100,0b00000110,0b00000010,0b01010001,
0b01000000,0b00000000,0b10000000,0b00010001,
0b01001000,0b00000000,0b00000000,0b00011001,
0b01000100,0b00000000,0b00100000,0b00000001,
0b01010000,0b00000000,0b10001000,0b00011001,
0b01000000,0b01000000,0b00100001,0b00010001,
0b00010101,0b01010101,0b01010101,0b01010100
},
{
//.level14
36,50,
0b01010101,0b01010101,0b01010101,0b01010101,
0b01100110,0b00000000,0b00000000,0b10011001,
0b01001001,0b00000000,0b00000001,0b01000001,
0b01000000,0b00000000,0b00000010,0b00000001,
0b01000000,0b00000000,0b00100100,0b00000001,
0b01000000,0b00000010,0b00000000,0b00000001,
0b01001001,0b00000000,0b00000000,0b01000001,
0b01100110,0b00000000,0b00000000,0b10011001,
0b01010101,0b01010101,0b01010101,0b01010101
},
{
//.level15
51,76,
0b00010101,0b01010100,0b01010101,0b01010100,
0b01000000,0b00001001,0b00000000,0b00100001,
0b01000100,0b10000100,0b00010000,0b00100001,
0b01000000,0b01000000,0b01101000,0b01100001,
0b00010001,0b00000001,0b00100000,0b00010001,
0b01100000,0b00000000,0b00010000,0b01100001,
0b00010000,0b00000000,0b10000000,0b00000100,
0b01100000,0b00000000,0b00000000,0b00001001,
0b00010101,0b01010101,0b01010101,0b01010100
},
{
//.level16
35,19,
0b01010101,0b01010101,0b01010101,0b01010101,
0b01010000,0b01100010,0b00000000,0b00001001,
0b01100000,0b10011000,0b00000000,0b00000101,
0b01010001,0b01010000,0b00001000,0b00000101,
0b01010000,0b00000010,0b01100100,0b00000001,
0b01101000,0b00000000,0b00001001,0b10000001,
0b01010010,0b00000000,0b01010101,0b10000001,
0b01011001,0b00000100,0b00000000,0b00000001,
0b01010101,0b01010101,0b01010101,0b01010101
},
{
//.level17
29,124,
0b01010101,0b01010101,0b01010101,0b01010101,
0b01001001,0b00000000,0b00000000,0b01000001,
0b01000100,0b00100110,0b10011000,0b00010001,
0b01000000,0b00011001,0b01100100,0b10000001,
0b01001001,0b00000000,0b00000010,0b01000001,
0b01000010,0b01100000,0b00001001,0b00000001,
0b01000100,0b00010001,0b01100100,0b00010001,
0b01000000,0b00100001,0b10000000,0b00000001,
0b01010101,0b01010101,0b01010101,0b01010101
},
{
//.level18
115,26,
0b01010101,0b01010101,0b01010101,0b01010101,
0b01001000,0b00000010,0b00000001,0b00000001,
0b01000001,0b10011000,0b00000110,0b00000001,
0b01000000,0b01100100,0b00000001,0b10000001,
0b01000000,0b10000001,0b00000010,0b01100001,
0b01000110,0b01000000,0b01001001,0b00000001,
0b01001001,0b10000100,0b10000100,0b00000001,
0b01100100,0b00000100,0b00000000,0b01000001,
0b01010101,0b01010101,0b01010101,0b01010101
},
{
//.level19
126,110,
0b01010101,0b01010101,0b01010101,0b01010101,
0b01100000,0b00010100,0b00000000,0b01011001,
0b01000100,0b00010000,0b00000000,0b01100001,
0b01001001,0b00000010,0b01010000,0b10000001,
0b01000100,0b00000001,0b10000000,0b00000001,
0b01000000,0b00010000,0b00100100,0b00000001,
0b01000101,0b00100100,0b01011000,0b00010001,
0b01001001,0b00011000,0b00000000,0b01010001,
0b01010101,0b01010101,0b01010101,0b01010101
},
{
//.level20
77,66,
0b01010101,0b01010101,0b01010101,0b01010101,
0b01000000,0b10011000,0b00000000,0b00000001,
0b01011000,0b00100100,0b01011000,0b00000101,
0b01000100,0b01001000,0b00000100,0b00010001,
0b01000000,0b01000001,0b01000001,0b00001001,
0b01000100,0b00010000,0b00100001,0b00010001,
0b01010000,0b00100101,0b00011000,0b00100101,
0b01000000,0b00000000,0b00100110,0b00000001,
0b01010101,0b01010101,0b01010101,0b01010101
},
{
//.level21
103,105,
0b01010101,0b01010101,0b01010101,0b01010101,
0b01000101,0b01000000,0b00001000,0b00000101,
0b01000000,0b01000000,0b00000000,0b01000101,
0b01000000,0b01011000,0b00000000,0b00100001,
0b01000010,0b00000000,0b10000000,0b10000101,
0b01000000,0b00010000,0b00000101,0b01100001,
0b01000010,0b00100000,0b00000010,0b00101001,
0b01010101,0b01010101,0b01010101,0b01010101,
0b00000000,0b00000000,0b00000000,0b00000000
},
{
//.level22
103,105,
0b01010101,0b01010101,0b01010101,0b01010101,
0b01100100,0b00011001,0b00011000,0b00010001,
0b01000000,0b00010000,0b00000000,0b00000001,
0b01100000,0b00010000,0b01100000,0b10000001,
0b01010001,0b10000000,0b00000010,0b00010101,
0b01001000,0b01000000,0b01010110,0b00000001,
0b01000000,0b00000100,0b01000000,0b10000001,
0b01010101,0b01010101,0b01010101,0b01010101,
0b00000000,0b00000000,0b00000000,0b00000000
},
{
//.level23
103,105,
0b00010101,0b01010101,0b01010101,0b01010100,
0b01000100,0b00011001,0b00011000,0b00010001,
0b01000000,0b00100000,0b01000000,0b00000001,
0b01010000,0b00010000,0b00100001,0b10000001,
0b01000001,0b10000001,0b00001010,0b00100001,
0b01011000,0b01000000,0b01010010,0b00000001,
0b01000000,0b00000100,0b01000000,0b10000001,
0b00010101,0b01010101,0b01010101,0b01010100,
0b00000000,0b00000000,0b00000000,0b00000000
},
{
//.level24
103,105,
0b01010101,0b01010101,0b01010101,0b01010101,
0b01000000,0b00000100,0b00000000,0b00000101,
0b01000101,0b10001000,0b00000001,0b01100101,
0b01000110,0b00000000,0b00100100,0b00010101,
0b01001010,0b00001001,0b00010100,0b00000001,
0b01000110,0b00100001,0b00000000,0b01010001,
0b01000101,0b00000000,0b01000101,0b01101001,
0b01010101,0b01010101,0b01010101,0b01010101,
0b00000000,0b00000000,0b00000000,0b00000000
},
{
//.level25
103,105,
0b01010101,0b01010101,0b01010101,0b01010101,
0b01000000,0b00000000,0b00000000,0b00010001,
0b01001000,0b01011000,0b00001000,0b00000001,
0b01000000,0b01100000,0b10000001,0b01000001,
0b01001000,0b00000001,0b01000001,0b10000001,
0b01000110,0b00000010,0b01000000,0b00100001,
0b01000101,0b10000100,0b00000000,0b00000001,
0b01010101,0b01010101,0b01010101,0b01010101,
0b00000000,0b00000000,0b00000000,0b00000000
}
};
static void playgame();
static void setupgame();
static void gamekeys();
static void left(unsigned char *ptr);
static void right(unsigned char *ptr);
static void down(unsigned char *ptr);
static void up(unsigned char *ptr);
static void setuplevel();
static void drawboard();
static int checkfinish();
static int standardmiddle(unsigned char nextpos);
int
main()
{
int maxx, maxy;
#ifdef USE_UDGS
void *param = &udgs;
console_ioctl(IOCTL_GENCON_SET_UDGS, ¶m);
#endif
#ifdef SWITCH_MODE
maxy = SWITCH_MODE;
console_ioctl(IOCTL_GENCON_SET_MODE, &maxy);
#endif
#ifdef __SPECTRUM
cputs("\x01 ");
#endif
screensize(&maxx, &maxy);
x_offset = (maxx - 16) / 2;
y_offset = (maxy - 9) / 2;
clrscr();
gotoxy(0,0);
cputs("DSTAR TERMINAL");
playgame(); /* Play the game */
return 0;
}
static void playgame()
{
setupgame(); /* Set level to 1, get level etc */
/* Loop while checkfinish() says we haven't finished! */
while (checkfinish()) {
gamekeys(); /* Scan keys */
}
}
/* Set some variables up at the start.. */
static void setupgame()
{
ballorbox = 0;
level = STARTLEV;
setuplevel();
}
#ifndef USE_JOYSTICK
static void gamekeys()
{
unsigned char* charptr;
if (ballorbox)
charptr = &boxoffset;
else
charptr = &balloffset;
switch (toupper(getk())) {
case K_DOWN:
down(charptr);
break;
case K_UP:
up(charptr);
break;
case K_RIGHT:
right(charptr);
break;
case K_LEFT:
left(charptr);
break;
case K_SWITCH:
ballorbox ^= 1; /* Toggle ball/box */
#ifdef SOUND
bit_fx4 (5);
#endif
#ifdef SOUNDB
bit_fx6 (6);
#endif
break;
case K_EXIT:
#ifdef SOUNDB
bit_fx6 (4);
#endif
exit(0);
case K_CLEAR:
#ifdef SOUND
bit_fx4 (3);
#endif
#ifdef SOUNDB
bit_fx6 (1);
#endif
setuplevel();
}
}
#else
static void gamekeys()
{
unsigned char* charptr;
unsigned char joy;
if (ballorbox)
charptr = &boxoffset;
else
charptr = &balloffset;
joy = joystick(1);
if (joy & MOVE_DOWN) {
down(charptr);
} else if (joy & MOVE_UP) {
up(charptr);
} else if (joy & MOVE_RIGHT) {
right(charptr);
} else if (joy & MOVE_LEFT) {
left(charptr);
} else if (joy & MOVE_FIRE) {
ballorbox ^= 1; /* Toggle ball/box */
} else if (joy & MOVE_FIRE2) {
setuplevel();
}
}
#endif
/* Movement functions - all of these are pretty well similar so I
* will only comment the first one - it's fairly obvious what is
* happening though
*/
static void left(unsigned char *ptr)
{
unsigned char *locn;
while (1) {
locn = *(ptr) + board;
if (standardmiddle(*(locn - 1)))
return;
*(locn - 1) = *locn;
*locn = 0;
(*ptr)--; /* ptr is the location of blob */
drawboard(); /* Draw screen */
}
}
static void right(unsigned char *ptr)
{
unsigned char* locn;
while (1) {
locn = *(ptr) + board;
if (standardmiddle(*(locn + 1)))
return;
*(locn + 1) = *locn;
*locn = 0;
(*ptr)++;
drawboard();
}
}
static void down(unsigned char *ptr)
{
unsigned char *locn;
while (1) {
locn = *(ptr) + board;
if (standardmiddle(*(locn + 16)))
return;
*(locn + 16) = *locn;
*locn = 0;
(*ptr) += 16;
drawboard();
}
}
static void up(unsigned char *ptr)
{
unsigned char *locn;
while (1) {
locn = *(ptr) + board;
if (standardmiddle(*(locn - 16)))
return;
*(locn - 16) = *locn;
*locn = 0;
(*ptr) -= 16;
drawboard();
}
}
/* Check to see if we're running into anything, if box is set then
* if we hit anything we want to stop, if we're ball then if we
* hit anything except for bubble we wanna stop
*/
static int standardmiddle(unsigned char nextpos)
{
if (ballorbox)
return (nextpos); /* For box */
else if (nextpos == BUBB || nextpos == 0)
return (0);
return (1);
}
/* Check to see if a level is finished
* There are 144 squares in each level, note the use of != instead of
* </<= - this is quicker to execute on the Z80!
*/
static int checkfinish()
{
unsigned char *ptr;
int i;
ptr = board;
for (i = 1; i != 144; i++) {
if (*ptr++ == BUBB)
return (1);
}
if (++level == MAXLEVEL)
return (0); /* Done all the levels!! */
setuplevel();
return (1);
}
/* Setup a level..the level is stored compressed, taking up 38 bytes a
* time.
* byte 0 - position of ball
* byte 1 - position of box
* 2-37 - level data
*
* Level data is stored as two bits per square, so we have to shift our
* picked up byte round to get it
*/
static void setuplevel()
{
int y;
const unsigned char *ptr;
unsigned char *ptr2;
ptr2 = board;
ptr = &levels[level][0];
/* ptr points to start of level now */
/* First two bytes are the ball and the boxes position */
balloffset = *ptr++;
boxoffset = *ptr++;
/* Now, decompress level into board */
for (y = 0; y != 36; y++) {
*ptr2++ = ((*ptr) >> 6) & 3;
*ptr2++ = ((*ptr) >> 4) & 3;
*ptr2++ = ((*ptr) >> 2) & 3;
*ptr2++ = (*ptr) & 3;
ptr++;
}
/* Now, plot the ball and box into the internal map */
ptr2 = board;
*(ptr2 + balloffset) = BALL;
*(ptr2 + boxoffset) = BOX;
drawboard();
#ifdef SOUND
bit_fx4 (1);
#endif
#ifdef SOUNDB
bit_fx6 (0);
#endif
}
static void drawboard()
{
unsigned char x, y;
unsigned char *ptr;
ptr = board;
for (y = 0; y != 9; y++) {
for (x = 0; x != 16; x++) {
gotoxy(x + x_offset, y + y_offset);
putch(blocks[*ptr++]);
}
}
#ifdef SOUND
bit_open();
bit_click();
bit_close();
#endif
#ifdef SOUNDB
bit_open();
bit_click();
bit_close();
#endif
}