-
Notifications
You must be signed in to change notification settings - Fork 0
/
s_para.inc
799 lines (725 loc) · 23.9 KB
/
s_para.inc
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
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
; =============================================================================
; A clone of the "robot take-over" game in Paradroid
; (C) by Jens Ch. Restemeier, <XXXXXXXXXXXX>
; =============================================================================
drw_para:
call display_off
call default_init
; init color-palette for GB-Color
ld a,0
ld hl,para_pal
call set_bg_pal
ld a,0
ld hl,para_pal
call set_ob_pal
ldh a, (EN_COLOR & 0FFh)
or a
call z, set_gray
ld hl, para_font ; install the paradroid-GFX
ld de, 08800h
ld bc, 36*8*2 ; size of font
call copy_nv
; every player can set 5 signals at the beginning:
ld a,5
ldh (lsig & 0FFh),a
ldh (rsig & 0FFh),a
; Draw screen
; left bar:
ld hl, 09800h + 0 + (3*32)
ld e, 13
ld a, 134
call draw_bar
; right bar:
ld hl, 09800h + 19 + (3*32)
ld e, 13
ld a, 135
call draw_bar
; draw totem-pole
ld a,148
call show_state
ld hl, 09800h + 9 + (5*32)
ld bc, 30
ld e, 12
ld a, 144
pd_l3: ldi (hl),a
xor 2
ldi (hl),a
add hl,bc
xor 3
dec e
jr nz, pd_l3
ld a,160
ldi (hl),a
inc a
ldi (hl),a
; draw circuit
; for now the circuit is hardcoded
ld a, 142 ; terminators left
ld (09800h + 3 + (7*32)),a
ld (09800h + 3 + (9*32)),a
ld (09800h + 3 + (12*32)),a
ld a, 140 ; repeaters left
ld (09800h + 7 + (15*32)),a
ld a, 162 ; inverters left
ld (09800h + 7 + (16*32)),a
; logics left
ld hl,09800h + 5 + (7*32)
ld e, 1
ld a, 134
call draw_bar
ld hl,09800h + 5 + (11*32)
ld e, 1
ld a, 134
call draw_bar
; wires left
ld a,129
ld (09800h + 1 + (4*32)),a ; contact
ld e,12
ld hl, 09800h + 1 + (5*32)
pp_l6: push hl
call pl_wire
pop hl
ld bc,32
add hl,bc
dec e
jr nz,pp_l6
ld a, 141 ; terminators right
ld (09800h + 16 + (7*32)),a
ld (09800h + 14 + (10*32)),a
ld (09800h + 14 + (12*32)),a
ld a, 143 ; repeaters right
ld (09800h + 16 + (11*32)),a
ld (09800h + 16 + (16*32)),a
ld a, 163 ; inverters right
;FIXME (16)
ld (09800h + 14 + (5 *32)),a
; logics right
ld hl,09800h + 14 + (6*32)
ld e, 1
ld a, 135
call draw_bar
ld hl,09800h + 12 + (10*32)
ld e, 1
ld a, 135
call draw_bar
; wires right
ld a,129
ld (09800h + 18 + (4*32)),a ; contact
ld e,12
ld hl, 09800h + 18 + (5*32)
pp_l7: push hl
call pr_wire
pop hl
ld bc,32
add hl,bc
dec e
jr nz,pp_l7
; init sprites
ld hl, 0c000h
xor a ; left player
ldi (hl),a
ldi (hl),a
ld a, 140
ldi (hl),a
xor a
ldi (hl),a
xor a ; right player
ldi (hl),a
ldi (hl),a
ld a, 143
ldi (hl),a
xor a
ldi (hl),a
ld a,1
ldh (speed & 0FFh),a
call display_on
ld a,27
ldh (SCREEN & 0FFh),a
ret
; =============================================================================
s1_para:
; animate powered lines
ld bc,13
ld hl, 08826h
rrc (hl)
inc hl
rrc (hl)
inc hl
rrc (hl)
inc hl
rrc (hl)
add hl,bc
rrc (hl)
inc hl
rrc (hl)
inc hl
rrc (hl)
inc hl
rrc (hl)
add hl,bc
rlc (hl)
inc hl
rlc (hl)
inc hl
rlc (hl)
inc hl
rlc (hl)
add hl,bc
rlc (hl)
inc hl
rlc (hl)
inc hl
rlc (hl)
inc hl
rlc (hl)
; if a player has no active signal, and signals are left
; give him a new one
ld hl, 0c000h ; left player
ld a,(hl)
or a
jr nz, p1_nol
ldh a,(lsig & 0FFh)
or a
jr z, p1_nol
dec a
ldh (lsig & 0FFh),a
ld a, 48
ldi (hl),a
ld a, 20
ld (hl),a
ldh a,(lsig & 0FFh)
ld d,a
or a
ld a,140
ld hl,09800h
p1_l1:
jr z, p1_nsl
ldi (hl),a
dec d
jr p1_l1
p1_nsl: ld a,0
ld (hl),a
p1_nol:
ld hl, 0c004h ; right player
ld a,(hl)
or a
jr nz, p1_nor
ldh a,(rsig & 0FFh)
or a
jr z, p1_nor
dec a
ldh (rsig & 0FFh),a
ld a, 48
ldi (hl),a
ld a, 148
ld (hl),a
ldh a,(rsig & 0FFh)
ld d,a
or a
ld a,143
ld hl,09800h+19
p1_l2:
jr z, p1_nsr
ldd (hl),a
dec d
jr p1_l2
p1_nsr: ld a,0
ld (hl),a
p1_nor:
; check, if the player may move his signal
ld a,(0c000h)
or a
jr z,p1_nb
; now evaluate joypad commands: up/down, A, B or start
ldh a,(JOY_TIPP & 0FFh)
and 080h ; down
jr z, p1_nd
ld a,(0c000h)
cp 144
jr z, p1_nd
add a,8
ld (0c000h),a
jr p1_ns
p1_nd:
ldh a,(JOY_TIPP & 0FFh)
and 040h ; up
jr z, p1_nu
ld a,(0c000h)
cp 48 ; inital position
jr z, p1_nu
cp 56 ; upper position
jr z, p1_nu
sub 8
ld (0c000h),a
jr p1_ns
p1_nu:
ldh a,(JOY_TIPP & 0FFh)
and 003h ; button A or B
jr z, p1_nb
ld a,(0c000h)
cp 48 ; it's not possible to drop the signal at
; the initial position
jr z, p1_nb
srl a ; a/=8 to get Y
srl a
srl a
dec a ; sprite origin is two lines to high
dec a
ld l,a ; hl=a*32
ld h,0
add hl,hl
add hl,hl
add hl,hl
add hl,hl
add hl,hl
ld de,09800h+3
add hl,de
ld a,(hl)
cp 142 ; terminated line ?
jr z, p1_nb
dec hl
ld a,(hl)
cp 140 ; already a signal here ?
jr z, p1_nb
ld a,140 ; place signal
ldi (hl),a
call pl_activate
xor a ; delete sprite
ld (0c000h),a
p1_nb:
ldh a,(JOY_TIPP & 0FFh)
and 008h ; start
jr z,p1_ns
ld a,0
ldh (SCREEN & 0FFh), a
ret
p1_ns:
; May player 2 move his sprite ?
ldh a, (speed & 0FFh)
dec a
ldh (speed & 0FFh), a
jr nz, p2_nx
ld a,5
ldh (speed & 0FFh), a
ld a,(0c004h)
or a
jr z,p2_nx
; The evaluation for player 2, using random values
ldh a,(DIV & 0FFh)
ld hl, random
add a,l
ld l,a
ld a,h
adc a,0
ld h,a
ld a,(hl)
push af
bit 0,a
jr z, p2_nu
ld a,(0c004h)
cp 48 ; inital position
jr z, p2_nu
cp 56 ; upper position
jr z, p2_nu
sub 8
ld (0c004h),a
jr p2_ns
p2_nu:
pop af
push af
bit 1,a
jr z, p2_nd
ld a,(0c004h)
cp 144
jr z, p2_nd
add a,8
ld (0c004h),a
jr p2_ns
p2_nd:
pop af
push af
bit 2,a
jr z, p2_ns
ld a,(0c004h)
cp 48 ; it's not possible to drop the signal at
; the initial position
jr z, p2_ns
srl a ; a/=8 to get Y
srl a
srl a
dec a ; sprite origin is two lines to high
dec a
ld l,a ; hl=a*32
ld h,0
add hl,hl
add hl,hl
add hl,hl
add hl,hl
add hl,hl
ld de,09800h+16
add hl,de
ld a,(hl)
cp 141 ; terminated line ?
jr z, p2_ns
inc hl
ld a,(hl)
cp 143 ; already a signal here ?
jr z, p2_ns
ld a,143 ; place signal
ldd (hl),a
call pr_activate
xor a ; delete sprite
ld (0c004h),a
p2_ns:
pop af
p2_nx:
; evaluate totem-pole
ld hl, 09800h + 8 + (5*32)
ld e, 12
pe_l1:
ldh a,(STAT & 0FFh)
bit 1,a
jr nz,pe_l1
ld bc,0
ldi a,(hl)
cp 130
jr nz, pe_l3
ld b,1
pe_l3: cp 131
jr nz, pe_l4
ld b,2
pe_l4:
inc hl
inc hl
ld a,(hl)
cp 133
jr nz, pe_l5
ld c,2
pe_l5: cp 132
jr nz, pe_l7
ld c,1
pe_l7: ld a,b
or c
cp 2
jr nz, pe_l2
dec hl
dec hl
ld a,(hl)
or 1
ldi (hl),a
ld a,(hl)
or 1
ldi (hl),a
jr pe_l6
pe_l2:
cp 1
jr nz, pe_l6
dec hl
dec hl
ld a,(hl)
and 0FEh
ldi (hl),a
ld a,(hl)
and 0FEh
ldi (hl),a
pe_l6:
cp 3
jr nz, pe_l10
dec hl
dec hl
ld a,(hl)
xor 1
ldi (hl),a
ld a,(hl)
xor 1
ldi (hl),a
pe_l10:
ld bc, 29
add hl,bc
dec e
jr nz, pe_l1
ld hl, 09800h + 9 + (5*32)
ld de, 12
pe_l8:
ldh a,(STAT & 0FFh)
bit 1,a
jr nz,pe_l8
ld a,(hl)
and 1
jr z, pe_l9
inc d
pe_l9:
ld bc,32
add hl,bc
dec e
jr nz, pe_l8
ld a,d
sub 6
or a
jr nz, no_draw
ld a,148
call show_state
ret
no_draw: and 080h
jr nz, win_left
ld a,156
call show_state
ret
win_left: ld a,152
call show_state
ret
; =============================================================================
; draw a vertical bar beginning at hl, length e and with start-character a
; =============================================================================
draw_bar:
ld bc, 32
ld (hl),a
add hl,bc
inc a
inc a
pd_l2: ld (hl),a
add hl,bc
dec e
jr nz, pd_l2
inc a
inc a
ld (hl),a
ret
; =============================================================================
; draw a horizontal wire at hl until a terminator is found (to left)
; =============================================================================
pl_wire:
ld a,(hl)
cp 134 ; upper border of an and
jr nz, pnua
ld bc, 32 + 1
add hl,bc
jr pl_wire
pnua:
cp 138 ; lower border of an and
jr nz, pnla
ld bc, -(32 - 1)
add hl,bc
jr pl_wire
pnla:
cp 136 ; center of splitter
jr nz, pnmo
push hl
ld bc, 32+1
add hl, bc
call pl_wire
pop hl
ld bc, -(32-1)
add hl, bc
call pl_wire
ret
pnmo:
cp 140 ; repeater
jr z, plskip
cp 162 ; inverter
jr z, plskip
or a ; everything else = exit
ret nz
ld a, 129
ld (hl),a
plskip: inc hl
jr pl_wire
; =============================================================================
; draw a horizontal wire at hl until a terminator is found (to right)
; =============================================================================
pr_wire:
ld a,(hl)
cp 135 ; upper border of and-gatter:
jr nz, pnuar
ld bc, 32 - 2
add hl,bc
jr pr_wire
pnuar:
cp 139 ; lower border of and-gatter:
jr nz, pnlar
ld bc, -(32 + 1)
add hl,bc
jr pr_wire
pnlar:
cp 137 ; center of splitter-gatter
jr nz, pnmor
push hl
ld bc, 32-1
add hl, bc
call pr_wire
pop hl
ld bc, -(32 + 1)
add hl, bc
call pr_wire
ret
pnmor:
cp 143 ; repeater
jr z, prskip
cp 163 ; inverter
jr z, prskip
or a ; everything else = exit
ret nz
ld a, 129 ; wire
ld (hl),a
prskip: dec hl
jr pr_wire
show_state:
push af
pw_l9: ldh a,(STAT & 0FFh)
bit 1,a
jr nz,pw_l9
pop af
ld (09800h + 9 + (3*32)),a
inc a
ld (09800h + 9 + (4*32)),a
inc a
ld (09800h + 10 + (3*32)),a
inc a
ld (09800h + 10 + (4*32)),a
ret
; =============================================================================
; activate wires for left player at hl
; =============================================================================
pl_activate:
ld a,(hl)
cp 134 ; upper border of an and
jr nz, panua
push hl
ld bc, 64-1
add hl,bc
ld a,(hl)
pop hl
cp 130 ; if other wire is active, too
ret nz
ld bc, 32+1
add hl,bc
jr pl_activate
panua:
cp 138 ; lower border of an and
jr nz, panla
push hl
ld bc, -(64+1)
add hl,bc
ld a,(hl)
pop hl
cp 130 ; if other wire is active, too
ret nz
ld bc, -(32-1)
add hl,bc
jr pl_activate
panla:
cp 136 ; center of splitter
jr nz, panmo
push hl
ld bc, 32+1
add hl, bc
call pl_activate
pop hl
ld bc, -(32-1)
add hl, bc
call pl_activate
ret
panmo:
cp 140 ; repeater
jr z, palskip
cp 162 ; inverter
jr z, lfill_invert
cp 129 ; if not a wire exit
ret nz
pw_4: ldh a,(STAT & 0FFh)
bit 1,a
jr nz,pw_4
ld a, 130
ld (hl),a
palskip: inc hl
jr pl_activate
lfill_invert:
inc hl
lf_l1:
ld a,(hl)
cp 129
ret nz
pw_2: ldh a,(STAT & 0FFh)
bit 1,a
jr nz,pw_2
ld a, 131
ldi (hl),a
jr lf_l1
; =============================================================================
; activate wires for right player at hl
; =============================================================================
pr_activate:
ld a,(hl)
cp 135 ; upper border of an and
jr nz, panuar
push hl
ld bc, 64+1
add hl,bc
ld a,(hl)
pop hl
cp 133 ; if other wire is active, too
ret nz
ld bc, 32-1
add hl,bc
jr pr_activate
panuar
cp 139 ; lower border of an and
jr nz, panlar
push hl
ld bc, -(64-1)
add hl,bc
ld a,(hl)
pop hl
cp 133 ; if other wire is active, too
ret nz
ld bc, -(32+1)
add hl,bc
jr pr_activate
panlar:
cp 137 ; center of splitter
jr nz, panmor
push hl
ld bc, 32-1
add hl, bc
call pr_activate
pop hl
ld bc, -(32+1)
add hl, bc
call pr_activate
ret
panmor:
cp 143 ; repeater
jr z, parskip
cp 163 ; inverter
jr z, rfill_invert
cp 129 ; if not a wire exit
ret nz
pw_1: ldh a,(STAT & 0FFh)
bit 1,a
jr nz,pw_1
ld a, 133
ld (hl),a
parskip: dec hl
jr pr_activate
rfill_invert:
dec hl
rf_l1:
ld a,(hl)
cp 129
ret nz
pw_3: ldh a,(STAT & 0FFh)
bit 1,a
jr nz,pw_3
ld a, 132
ldd (hl),a
jr rf_l1
; =============================================================================
; red/yellow/pink/black palette
para_pal:
.word 31
.word 7166
.word 31775
.word 0
; =============================================================================
; include the Paradroid font
#include "para.inc"