-
Notifications
You must be signed in to change notification settings - Fork 0
/
scubacodb.asm
3403 lines (3308 loc) · 71.2 KB
/
scubacodb.asm
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
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
;----------------------------------------------------------------------------
INCLUDE "scubacoda.txt"
;----------------------------------------------------------------------------
ORG $6000
;----------------------------------------------------------------------------
; Sprites
INCLUDE "scubasprt.asm"
;----------------------------------------------------------------------------
L9C50 DEFB $00 ; $00 = no Octopus, $01 = we have Octopus on the game screen
L9C51 DEFW $0000 ; Octopus screen address
L9C53 DEFW LA41B ; Octopus previous sprite address or LA41B for empty sprite
L9C55 DEFB $04 ; Octopus phase
; Draw game screen
; Draws 3x3 blocks = 24x24 tiles, draws Octopus if present, draws static objects on the screen.
; I: HL Screen position on mini-map
DrawGameScr
DI
LD DE,$4000 ; screen pixels start address
XOR A
LD (L9C50),A ; no Octopus by default
PUSH IX
PUSH IY
LD IX,$5800 ; screen attributes start address
LD B,$03 ; loop counter; game screen 3 blocks high = 24 tiles
EX DE,HL ; now DE = screen position, HL = address on the screen
L9C69 PUSH BC
LD B,$03 ; loop counter; game screen 3 blocks wide = 24 tiles
L9C6C PUSH BC
PUSH IX
EX DE,HL ; now HL = screen position, DE = address on the screen
CALL MiniMap_Get ; Calc address in MiniMap and Get block number
PUSH AF
EX DE,HL
CP $1C ; place for Octopus?
JR NZ,L9C89 ; no => skip
LD (L9C51),HL ; save the Octopus screen address
PUSH HL
LD HL,LA41B ; empty sprite address
LD (L9C53),HL ; set previous sprite
POP HL
LD A,$01 ; flag value
LD (L9C50),A ; we have the Octopus on the screen
L9C89 INC E
LD A,E
AND $1F ; 0..31
LD E,A
POP AF
PUSH DE
PUSH HL
PUSH HL
LD H,A
LD L,$00
SRL H
RR L
SRL H
RR L
LD DE,LA4DD ; base address for relief blocks, 8x8 tiles each block
ADD HL,DE ; now HL = address of the block
PUSH HL
POP IY ; now IY = address of the block
POP HL
LD B,$08 ; repeat 8 times - block height in tiles
L9CA7 PUSH BC
LD B,$08 ; repeat 8 times - block width in tiles
L9CAA PUSH BC
LD A,(IY+$00) ; get tile number
PUSH HL
PUSH HL
AND $7F ; 0..127
LD L,A
LD H,$00
ADD HL,HL
ADD HL,HL
ADD HL,HL ; *8
LD BC,L9134 ; base address for relief tiles, 8x8 pixels each tile
ADD HL,BC ; now HL = tile address
POP DE
LD B,$08 ; repeat 8 times - tile height
L9CBF LD A,(HL) ; get tile pixels
LD (DE),A ; write to the screen
INC HL ; next tile byte
INC D ; next pixel row
DJNZ L9CBF
POP HL
LD A,(L5B03+1) ; get Screen position on mini-map, row value
OR A
JR NZ,L9CD5
LD A,H
AND $18 ; 0 / 8 / 16 / 24
JR NZ,L9CD5
LD C,$29
JR L9CEB
L9CD5 LD C,$06
LD A,(IY+$00)
OR A
JR Z,L9CEB
CP $32
JR Z,L9CEB
LD C,$02 ; red on black (color for relief)
BIT 7,(IY+$00)
JR Z,L9CEB
LD C,$06 ; yellow on black
L9CEB LD (IX+$00),C ; set screen attribute
INC IY
INC IX
INC L ; next column
POP BC
DJNZ L9CAA ; continue horizontal loop for tiles in the block
LD BC,$0018 ; 24
ADD IX,BC
DEC L
LD A,L
AND $F8
ADD A,$20
LD L,A
POP BC
DJNZ L9CA7 ; continue vertical loop for tiles in the block
POP HL
LD BC,$0008
ADD HL,BC
POP DE
POP IX
ADD IX,BC
POP BC
DEC B
JP NZ,L9C6C ; continue horizontal loop for blocks on the screen
LD L,$00
LD A,H
ADD A,$08
LD H,A
LD BC,$00E8
ADD IX,BC
INC D
DEC E
DEC E
DEC E
LD A,E
AND $1F ; 0..31
LD E,A
POP BC
DEC B
JP NZ,L9C69 ; continue vertical loop for blocks on the screen
LD A,(L9C50) ; get Octopus flag
OR A ; do we have the Octopus on the screen?
JR Z,L9D38 ; no => skip
LD A,(L9C55) ; get Octopus phase
CALL LB346 ; Draw Octopus
L9D38 POP IY
L9D3A POP IX
L9D3C CALL DrawStatics ; Draw static objects on the screen; prepare LB07D table
RET
; Calculate address in the MiniMap table
; I: HL H = row, L = column 0..31
; O: HL = address in the MiniMap table
MiniMap_Addr
LD A,L
LD L,$00
SRL H
RR L
SRL H
RR L
SRL H
RR L ; HL shifted right 3 bits
OR L
LD L,A ; HL := H * 32 + L
LD DE,MiniMap
ADD HL,DE ; HL := MiniMap + H * 32 + L
RET
; Calculate address in the MiniMap table and Get block number
; I: H = row, L = column 0..31
; O: A = value
MiniMap_Get
PUSH HL
PUSH DE
CALL MiniMap_Addr ; Calculate address in the MiniMap table
LD A,(HL) ; get value
POP DE
POP HL
RET
; Check value in the MiniMap table, if row and column in range 0..31
; I: H = row, L = column
; If column or row is out of range 0..31 - returns flag Z=0;
; else, gets value from MiniMap table;
; if this value is $01, returns flag Z=1, in other case flag Z=0.
MiniMap_Check
PUSH HL
PUSH AF
LD A,L
AND $E0 ; check Column for range 0..31
JR NZ,L9D73
LD A,H
AND $E0 ; check Row for range 0..31
JR NZ,L9D73
CALL MiniMap_Get ; Calc address in MiniMap and Get block number
LD L,A
POP AF
DEC L
POP HL
RET
L9D73 POP AF
LD L,$01
INC L
POP HL
RET
; Calculate address in the MiniMap table and Set block number
; I: H = row, L = column 0..31, A = value to set
MiniMap_Set
PUSH HL
PUSH DE
PUSH AF
CALL MiniMap_Addr ; Calculate address in the MiniMap table
POP AF
LD (HL),A ; set value
POP DE
POP HL
RET
; Random
; Calculate next number in pseudo-random sequence
NextRandom
LD HL,(RANDOM) ; get current Random
LD D,H
LD E,L
ADD HL,HL ; x2
ADD HL,HL ; x4
ADD HL,HL ; x8
ADD HL,HL ; x16
PUSH HL
ADD HL,HL ; x32
EX (SP),HL
OR A
SBC HL,DE ; HL = x15
POP BC ; BC = x32
ADD HL,BC ; x47
ADD HL,HL ; x94
ADD HL,HL ; x188
ADD HL,HL ; x376
ADD HL,DE ; x377
ADD HL,HL ; x754
ADD HL,HL ; x1508
ADD HL,DE ; x1509
LD DE,$0029
ADD HL,DE
LD (RANDOM),HL ; (RANDOM) := (RANDOM) * 1509 + 41
RET
L9DA4 DEFB $AF
; Fill block at HL with A
; I: HL = block address, A = value, B = length of the block to fill
FillBlock
LD (HL),A
INC HL
DJNZ FillBlock
RET
; Prepare the MiniMap table
PrepareMiniMap
LD HL,MiniMap+3*32+2 ; $ACBF = $AC5D + 3 * 32 + 2: row 3 column 2
LD B,$1C
LD A,$16
CALL FillBlock ; Fill block at $ACBF with $16
LD (HL),$06 ; ($ACDB) <- $06
INC HL ; HL = $ACDC
LD B,$22
LD A,$01
CALL FillBlock ; Fill block at $ACDC with $01
INC HL ; HL = $ACFF
LD A,$1A
LD B,$1C
CALL FillBlock ; Fill block at $ACFF with $1A
INC HL
INC HL
LD (HL),$02
LD HL,MiniMap+6*32+31 ; $AD3C = $AC5D + 6 * 32 + 31; row 6 column 31
LD (HL),$06 ; ($AD3C) <- $06
INC HL
INC HL
INC HL ; HL = $AD3F
LD B,$1C
LD A,$16
CALL FillBlock ; Fill block at $AD3F with $16
INC HL
INC HL ; HL = $AD5D; $AD5D = $AC5D + $100: row 8 column 0
LD B,$00
LD A,$01
CALL FillBlock ; Fill block at $AD5D with $01, 256 bytes: fill rows 8..15
CALL FillBlock ; Fill block at $AE5D with $01, 256 bytes: fill rows 16..23
CALL FillBlock ; Fill block at $AF5D with $01, 256 bytes: fill rows 24..31
CALL NextRandom ; Calculate next random value
LD A,H
AND $0F ; 0..15
ADD A,$07 ; A = (Random:H) & 15 + 7 => 7..22
LD L,A ; column
LD H,$03 ; row = 3
XOR A
CALL MiniMap_Set ; Calc address in MiniMap and Set block number = 0
INC L ; next column; column = 4
CALL MiniMap_Set ; Calc address in MiniMap and Set block number = 0
LD H,$05 ; row = 5
CALL MiniMap_Set ; Calc address in MiniMap and set block number = 0
DEC L ; previous column; column = 3
CALL MiniMap_Set ; Calc address in MiniMap and Set block number = 0
DEC H ; previous row; row = 4
LD A,$1C ; $1C = place for Octopus, left block
CALL MiniMap_Set ; Calc address in MiniMap and Set block number = $1C
INC A ; = $1D = place for Octopus, right block
INC L ; next column; column = 4
CALL MiniMap_Set ; Calc address in MiniMap and Set block number = $1D
LD HL,MiniMap+3*32 ; $ACBD = $AC5D + 3 * 32: row 3 column 0
LD B,$A0 ; repeat 160 times = 5 rows, rows 3..7
L9E14 LD A,(HL) ; get block number
CP $02 ; block $02 is dead end to the left, exit to the right
JR Z,L9E2A
CP $06 ; block $06 is dead end to the right, exit to the left
JR Z,L9E2A
CP $16 ; block $16 looks like floor (seabed)
JR Z,L9E2A
CP $1A ; block $1A looks like ceiling
JR Z,L9E2A
L9E25 INC HL ; to the next block
DJNZ L9E14
JR L9E38
; Block $02 / $06 / $16 / $1A
L9E2A PUSH BC
PUSH HL
CALL NextRandom ; Calculate next random value
BIT 5,H
POP HL
POP BC
JR Z,L9E25
INC (HL) ; increase block number
JR L9E25 ; continue the loop
; Coming here after the loop end; continue to build the map
L9E38 LD A,$02 ; initial trunk width
LD (L5B09),A ; set trunk width
CALL NextRandom ; Calculate next random value
LD A,H
AND $0F ; 0..15
ADD A,$07 ; 7..22
LD L,A
LD H,$07 ; row = 7
XOR A
CALL MiniMap_Set ; Calc address in MiniMap and Set block number = 0
INC L ; next column
CALL MiniMap_Set ; Calc address in MiniMap and Set block number = 0
INC H ; next row
LD A,$1D ; $1D = place for Octopus, right block
CALL MiniMap_Set ; Calc address in MiniMap and Set block number = $1D - Octopus place
DEC A ; = $1C = place for Octopus, left block
DEC L ; previous column
CALL MiniMap_Set ; Calc address in MiniMap and Set block number = $1C - Octopus place
DEC L ; previous column
; Building the labyrinth down from the hole with Octopus
LD (L5B07),HL ; store the octopus place as the current trunk position
L9E5F LD HL,(L5B07) ; get current trunk position
INC H ; next row
LD (L5B07),HL ; set current trunk position
LD A,(L5B09) ; get trunk width
LD (L5B0A),A ; and save it
LD A,(LEVEL) ; LEVEL
ADD A,A ; *2
ADD A,A ; *4
ADD A,$10 ; now A = [Game level] * 4 + 16 => 20 / 24 / 28 / 32
LD C,A
DEC C ; now C = 19 / 23 / 27 / 31 - row where the labirinth ends
CP H ; row = A ?
JR NZ,L9E99 ; no => jump
; The labyrinth ends on this depth
DEC H ; previous row
LD A,(L5B09) ; get trunk width
LD B,A ; B = loop counter
L9E7D PUSH HL
PUSH BC
CALL NextRandom ; Calculate next random value
LD D,H
POP BC
POP HL
INC L ; next column
LD A,$16 ; block $16 is floor (seabed)
BIT 1,D
JR Z,L9E8D
INC A ; change to block $17 - a bit different floor (seabed)
L9E8D CALL MiniMap_Set ; Calc address in MiniMap and Set block number
DJNZ L9E7D
CALL LA193
CALL LB1D4
RET
; Fill the labyrinth on this row level
L9E99 PUSH HL
PUSH BC
CALL NextRandom ; Calculate next random value
POP BC
POP DE
EX DE,HL
LD A,D
AND $07 ; 0..7
JR NZ,L9EB3
L9EA6 LD A,$02 ; block $02 is dead end to the left, exit to the right
BIT 6,D
JR Z,L9EAD
INC A ; change to block $03, same as $02 with a bit different relief
L9EAD CALL MiniMap_Set ; Calc address in MiniMap and Set block number
JP L9F0E
L9EB3 LD A,E
AND $C0
JR NZ,L9EFB
L9EB8 BIT 4,E
JR Z,L9ED8
LD A,L
OR A
JR Z,L9EA6
LD A,H
CP C
JR Z,L9ED8
LD A,$05 ; block $05 is wall to left/up, exit to right/down
CALL MiniMap_Set ; Calc address in MiniMap and Set block number
DEC L ; previous column
LD (L5B07),HL ; set current trunk position
INC L ; next column
LD A,(L5B0A)
INC A
LD (L5B0A),A
JP L9F0E
L9ED8 LD A,(L5B09) ; get trunk width
ADD A,L
CP $1E
JR Z,L9EA6
LD A,(L5B0A)
DEC A
JR Z,L9EA6
LD (L5B0A),A
LD A,(L5B09)
DEC A ; decrease trunk width
LD (L5B09),A
INC L ; next column
LD (L5B07),HL ; set current trunk position
LD A,$04 ; block $04 is wall to left/down, exit to rigth/up
CALL MiniMap_Set ; Calc address in MiniMap and Set block number
JR L9F0E
L9EFB DEC L ; previous column
CALL MiniMap_Check ; Check value in MiniMap table
PUSH AF
INC L ; next column
POP AF
JR NZ,L9EB8
LD A,$0B ; block $0B is floor and ceiling, passage to left/right
CALL MiniMap_Set ; Calc address in MiniMap and Set block number = $0B
PUSH BC
CALL L9F81
POP BC
L9F0E LD A,(L5B09) ; get trunk width
LD B,A ; B = loop counter
XOR A
L9F13 INC L ; next column
CALL MiniMap_Set ; Calc address in MiniMap and Set block number = 0
DJNZ L9F13
INC L ; next column
PUSH HL
PUSH BC
CALL NextRandom ; Calculate next random value
POP BC
POP DE
EX DE,HL
LD A,D
AND $07 ; 0..7
JR NZ,L9F34
L9F27 LD A,$06 ; block $06 is dead end to the right, exit to the left
BIT 6,D
JR NZ,L9F2E
INC A ; change to block $07 - same as $06 with a bit different relief
L9F2E CALL MiniMap_Set ; Calc address in MiniMap and Set block number
JP L9F78
L9F34 LD A,E
AND $C0
JR NZ,L9F67
L9F39 BIT 4,E
JR Z,L9F4F
LD A,(L5B0A)
DEC A
JR Z,L9F4F
LD (L5B0A),A
DEC L
LD A,$08 ; block $08 is wall to right/down, exit to left/up
CALL MiniMap_Set ; Calc address in MiniMap and Set block number = $08
JP L9F78
L9F4F LD A,L
CP $1E
JR NC,L9F27
LD A,H
CP C
JR Z,L9F27
LD A,$09 ; block $09 is wall to right/up, exit to left/down
CALL MiniMap_Set ; Calc address in MiniMap and Set block number = $09
LD A,(L5B0A)
INC A
LD (L5B0A),A
JP L9F78
L9F67 INC L ; next column
CALL MiniMap_Check ; Check value in MiniMap table
PUSH AF
DEC L ; previous column
POP AF
JR NZ,L9F39
LD A,$0A ; block $0A is floor and ceiling, passage to left/right
CALL MiniMap_Set ; Calc address in MiniMap and Set block number = $0A
CALL LA03B
L9F78 LD A,(L5B0A)
LD (L5B09),A ; restore trunk width
JP L9E5F ; continue the loop by mini-map rows
; Initialize left part of the map
L9F81 LD (L5B01),HL
L9F84 DEC L
PUSH HL
CALL NextRandom ; Calculate next random value
POP DE
EX DE,HL
LD A,D
AND $02 ; check bit 1
JR NZ,L9FEB
L9F90 DEC L
CALL MiniMap_Check ; Check value in MiniMap table
JR Z,L9FC0
LD A,L
CP $FF
JR NZ,L9FB6
LD L,$1F
CALL MiniMap_Get ; Calc address in MiniMap and Get block number
CP $14
JR NZ,L9FB4
LD A,$0B
CALL MiniMap_Set ; Calc address in MiniMap and Set block number
LD L,$00
LD A,$0A
CALL MiniMap_Set ; Calc address in MiniMap and Set block number
LD HL,(L5B01)
RET
L9FB4 LD L,$FF
L9FB6 INC L
LD A,$15
CALL MiniMap_Set ; Calc address in MiniMap and Set block number
LD HL,(L5B01)
RET
L9FC0 INC L
BIT 7,E
JR Z,L9FE0
DEC H
CALL MiniMap_Get ; Calc address in MiniMap and Get block number
INC H
SUB $10
JR C,L9FE0
CP $04
JR NC,L9FE0
LD A,$18
CALL MiniMap_Set ; Calc address in MiniMap and Set block number
DEC H
INC A
CALL MiniMap_Set ; Calc address in MiniMap and Set block number
INC H
JP L9F84
L9FE0 LD A,D
AND $03 ; 0..3
ADD A,$10 ; $10..$13
CALL MiniMap_Set ; Calc address in MiniMap and Set block number
JP L9F84
L9FEB BIT 6,E
JR NZ,LA011
INC H
CALL MiniMap_Check ; Check value in MiniMap table
JR Z,L9FF8
DEC H
JR L9F90
L9FF8 DEC L
CALL MiniMap_Check ; Check value in MiniMap table
JR Z,LA002
INC L
DEC H
JR L9F90
LA002 INC L
LD A,$0D
CALL MiniMap_Set ; Calc address in MiniMap and Set block number
DEC H
DEC A
CALL MiniMap_Set ; Calc address in MiniMap and Set block number
INC H
JP L9F84
LA011 LD A,$09
CP H
JP Z,L9F90
DEC H
CALL MiniMap_Check ; Check value in MiniMap table
JR Z,LA021
INC H
JP L9F90
LA021 DEC L
CALL MiniMap_Check ; Check value in MiniMap table
JR Z,LA02C
INC L
INC H
JP L9F90
LA02C LD A,$0E
INC L
CALL MiniMap_Set ; Calc address in MiniMap and Set block number
INC H
INC A
CALL MiniMap_Set ; Calc address in MiniMap and Set block number
DEC H
JP L9F84
; Initialize right part of the map
LA03B LD (L5B01),HL
LA03E INC L
PUSH HL
CALL NextRandom ; Calculate next random value
POP DE
EX DE,HL
LD A,D
AND $04 ; check bit 2
JR NZ,LA0A5
LA04A INC L
CALL MiniMap_Check ; Check value in MiniMap table
JR Z,LA079
LD A,L
AND $1F ; 0..31
JR NZ,LA06F
LD L,A
CALL MiniMap_Get ; Calc address in MiniMap and Get block number
CP $15
JR NZ,LA06D
LD A,$0A
CALL MiniMap_Set ; Calc address in MiniMap and Set block number
LD L,$1F
LD A,$0B
CALL MiniMap_Set ; Calc address in MiniMap and Set block number
LD HL,(L5B01)
RET
LA06D LD L,$20
LA06F DEC L
LD A,$14
CALL MiniMap_Set ; Calc address in MiniMap and Set block number
LD HL,(L5B01)
RET
LA079 DEC L
BIT 7,E
JR Z,LA09A
DEC H
CALL MiniMap_Get ; Calc address in MiniMap and Get block number
INC H
SUB $10
JR C,LA09A
CP $04
JR NC,LA09A
LD A,$18
CALL MiniMap_Set ; Calc address in MiniMap and Set block number
DEC H
LD A,$19
CALL MiniMap_Set ; Calc address in MiniMap and Set block number
INC H
JP LA03E
LA09A LD A,D
AND $03 ; 0..3
ADD A,$10 ; $10..$13
CALL MiniMap_Set ; Calc address in MiniMap and Set block number
JP LA03E
LA0A5 BIT 6,E
JR NZ,LA0CB
INC H
CALL MiniMap_Check ; Check value in MiniMap table
JR Z,LA0B2
DEC H
JR LA04A
LA0B2 INC L
CALL MiniMap_Check ; Check value in MiniMap table
JR Z,LA0BC
DEC L
DEC H
JR LA04A
LA0BC DEC L
LD A,$0F
CALL MiniMap_Set ; Calc address in MiniMap and Set block number
DEC H
DEC A
CALL MiniMap_Set ; Calc address in MiniMap and Set block number
INC H
JP LA03E
LA0CB LD A,$09
CP H
JP Z,LA04A
DEC H
CALL MiniMap_Check ; Check value in MiniMap table
JR Z,LA0DB
INC H
JP LA04A
LA0DB INC L
CALL MiniMap_Check ; Check value in MiniMap table
JR Z,LA0E6
INC H
DEC L
JP LA04A
LA0E6 LD A,$0C
DEC L
CALL MiniMap_Set ; Calc address in MiniMap and Set block number
INC H
INC A
CALL MiniMap_Set ; Calc address in MiniMap and Set block number
DEC H
JP LA03E
; Calculate address in relief block
; I: HL = Char coords: H = row, L = column
LA0F5 PUSH HL
SRL H
SRL H
SRL H
SRL H
RR L
SRL H
RR L
SRL H
RR L
LD DE,MiniMap
ADD HL,DE ; now HL = address in MiniMap
LD H,(HL) ; get block number from MiniMap
POP DE ; restore row/column
LD A,E ; get column
AND $07 ; 0..7
LD E,A
LD A,D ; get row
RRCA
RRCA
RRCA
AND $E0
LD L,A
SRL H
RR L
SRL H
RR L
LD A,L
OR E
LD L,A
LD DE,LA4DD ; address of relief bblocks
ADD HL,DE ; now HL = address in the block
RET
; Calculate address in relief block and Get tile nummber
; I: HL = Char coords: H = row, L = column
GetTileInBlock
PUSH HL
PUSH DE
CALL LA0F5 ; Calculate address in relief block
LD A,(HL) ; get tile number
POP DE
POP HL
RET
LA132 DEFB $E5,$D5,$F5,$CD,$F5,$A0,$F1,$5F
DEFB $7E,$E6,$3F,$7B,$D1,$E1,$C9,$E5
DEFB $D5,$F5,$CD,$F5,$A0,$F1,$D1,$BE
DEFB $E1,$C9
; Get screen attribute address
GetScrAttrAddr
PUSH DE
LD A,L
LD L,$00
SRL H
RR L
SRL H
RR L
SRL H
RR L
OR L
LD L,A
LD DE,$5800 ; Screen attributes area
ADD HL,DE
POP DE
RET
; Convert char coords HL to ZX screen address
; I: HL = Char coords: H = row 0..23, L = column 0..31
; O: HL = address on the ZX screen
GetScrAddr
PUSH DE
LD A,H
LD D,A
AND $18 ; 0 / 8 / 16 / 24
SET 6,A
LD H,A
LD A,D
RRCA
RRCA
RRCA
AND $E0
OR L
LD L,A
POP DE
RET
; Draw tile 16x8 at the screen
; I: HL = Char coords: H = row 0..23, L = column 0..31
; I: DE = Tile address; 16 bytes
DrawTile16x8
CALL GetScrAddr ; Convert char coords HL to ZX screen address
LD B,$08 ; repeat 8 times
LA17B LD A,(DE)
LD (HL),A
INC DE
INC L
LD A,(DE)
LD (HL),A
DEC L
INC H
INC DE
DJNZ LA17B
RET
; Draw tile 8x8 at the screen
; I: HL = Char coords: H = row 0..23, L = column 0..31
; I: DE = Tile address; 8 bytes
DrawTile8x8
CALL GetScrAddr ; Convert char coords HL to ZX screen address
LD B,$08 ; repeat 8 times
LA18C LD A,(DE)
LD (HL),A
INC DE
INC H
DJNZ LA18C
RET
LA193 LD HL,$20FF
LD DE,TableStatics ; Table of static objects on the map
XOR A
LD (L5B00),A
LD A,$03
LD (L5B0F),A
LA1A2 INC L
LD A,L
AND $1F ; 0..31
JR NZ,LA1B0
LD L,A
DEC H
JR NZ,LA1B0
LD A,$80 ; end of list marker
LD (DE),A
RET
LA1B0 CALL MiniMap_Get ; Calc address in MiniMap and Get block number
LD C,A
PUSH HL
CP $14
JR Z,LA1CC
CP $15
JR NZ,LA1F6
LD A,L
OR A
JR NZ,LA1F6
LD L,$04
LD A,H
ADD A,A
ADD A,A
ADD A,A
ADD A,$04
LD H,A
JR LA1DA
LA1CC LD A,L
CP $1F
JR NZ,LA1F6
LD L,$FB
LD A,H
ADD A,A
ADD A,A
ADD A,A
ADD A,$06
LD H,A
LA1DA LD A,(L5B0F)
OR A
JR Z,LA1F6
LD A,$40
LD (DE),A
INC DE
LD A,L
LD (DE),A
INC DE
LD A,H
LD (DE),A
INC DE
LD A,(L5B0F)
LD (DE),A
INC DE
DEC A
LD (L5B0F),A
POP HL
JR LA1A2
LA1F6 LD H,C
LD L,$C0
SRL H
RR L
SRL H
RR L
LD BC,LA4DD
PUSH HL
ADD HL,BC
POP BC
LD B,$10 ; repeat 16 times
LA209 LD A,(HL)
INC HL
INC C
SUB $1C
JR C,LA278
CP $04
JR NC,LA278
LD A,(HL)
INC HL
INC C
SUB $1C
JR C,LA278
CP $04
JR NC,LA278
LD A,C
AND $07 ; 0..7
JR Z,LA278
PUSH HL
PUSH DE
PUSH BC
CALL NextRandom ; Calculate next random value
POP BC
POP DE
LD A,H
POP HL
AND $02 ; check bit 1
JR NZ,LA278
LD A,(L5B00)
INC A
CP $64 ; 100
JR Z,LA278
LD (L5B00),A
LD A,$0A
LD (DE),A
EX (SP),HL
LD A,H
CP $04
JR C,LA249
LD A,$00
LD (DE),A
LA249 INC DE
LD A,C
DEC A
DEC A
AND $07 ; 0..7
PUSH DE
LD D,A
LD A,L
ADD A,A
ADD A,A
ADD A,A
AND $F8
OR D
POP DE
LD (DE),A
INC DE
PUSH DE
LD A,H
ADD A,A
ADD A,A
ADD A,A
AND $F8
LD D,A
LD A,C
AND $38
RRCA
RRCA
RRCA
OR D
POP DE
EX (SP),HL
LD (DE),A
INC DE
LD A,(RANDOM) ; get current Random lo byte
AND $7F ; 0..127
LD (DE),A
INC DE
INC HL
INC C
DEC B
LA278 DJNZ LA209
POP HL
JP LA1A2