-
Notifications
You must be signed in to change notification settings - Fork 2
/
game.asm
4988 lines (4416 loc) · 102 KB
/
game.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
; Disassembly of the file "gamecode_36621_28403"
;
; Created with dZ80 v1.31
;
; on Saturday, 23 of October 1999 at 07:00 PM
;
; Lemmings Entry Point is 36621
;
; djm Started 23/10/99 done all messages
;
; Levels are 64x16=8192 bytes and start at 23613
;
;Global replace: cp 0 w/ and a
; ld a,0 xor a
;
;62871-62871+2047 - needed for sommat!
;Variable space so far:
;
; 8405 = level data
; 4096 = back screen
; 2219 = varbase gunk
; 720 = @35901 for lemming data
;
;Total: 15440 ~=16384
;
;z88 memory map:
; 8192 = backscreen
;12288 = level data
;20693 = data @ 35901
;21413 = varbase
;23632 = my oz variables
MODULE game
defc sampleplay = 62850
defc comp_game = 1
INCLUDE "game.inc"
INCLUDE "fileio.def"
INCLUDE "director.def"
INCLUDE "syspar.def"
INCLUDE "stdio.def"
INCLUDE "time.def"
INCLUDE "error.def"
SECTION code
defc myzorg = 36750
org myzorg
;
; Routines In Other Modules
;
XREF ozscrcpy
XREF oztitlecopy
XREF messag
XREF dmessag
XREF messag32
XREF prchar
XREF prchar1
XREF windclr
XREF doposn
; Keyboard
XREF keys
XREF ozread
XREF retascii
XREF kfind
; Misc
XREF doudgs
XREF getcode
XREF inputcode
XREF jimmyattr
XREF applname
;Values for jimmy syyt
defc normal_attr = @01000001
defc inv_attr = @01010001
;Lem table:
; +0 = type
; +3 = y
; +4 = x
; 23403/4 23417/8 prob home and start things
XDEF cksound
XDEF entry
XDEF attr
XDEF fadeattr
XDEF startselect
XDEF firemsg
XDEF checkfire
XDEF numpri
XDEF copyright_text
XDEF ingame_text
XDEF preview_text
XDEF leveldone_text
XDEF startselect_text
.setup_mydata
ld hl,defaultdata
ld de,filename
ld bc,+(enddefault-defaultdata)
ldir
xor a
ld (myflags),a
ld hl,varbase
ld de,varbase+1
ld bc,75
ld (hl),a
ldir
ret
.domusic
call cksound ;exits with hl=myflags
bit 0,(hl)
ret nz
bit 1,(hl) ;music off
ret nz
ld hl,music_store
ld de,8377
push de
ld bc,1600
ldir
ret
.dotitlescreen
ld hl,titlescreen_store
ld de,screen
ld bc,1063
ldir
call screen
call oztitlecopy
ret
.entry
ld (spstor),sp
call setup_mydata
.entry1
ld sp,(spstor)
ld a,1
ld (level),a
ld hl,applname
call_oz(dc_nam)
call dotitlescreen
call copyright
.startlevel
.L8f54
call startselect
call previewtitle
call Lc400
call ingame_text
ld a,255
ld (gameon),a
jp ploop
.ingame_text
ld a,3
ld (gamemode),a
call windclr
call doudgs
ld hl,level_name
ld bc,$2020
call messag32
ld bc,$2228
call messag
defm "OUT 00 IN 00 TIME 0:00\x00"
ld a,255
ld (timeprflag),a
call prtime
call prstatnum
call copymap
call prpointer
jp ozscrcpy
; Clear the back screen
.cls ld hl,8192
ld de,8193
ld bc,4095
ld (hl),l
ldir
ret
; Set the attributes to the colour held in a
; Pause for bc loops
.pausebc
dec c
jr nz,pausebc
dec b
ld a,b
or c
ret z
dec c
jr pausebc
.fadeattr
ld a,7
ld (attr),a
.L8fc5 ld bc,$2710
; call pausebc
;Frazzle break up effect here maybe?
; call setattr
; jr nc,L8fc5 ; (-11)
ret
; Check To see if the fire button/space is pressed
.checkfire
call ozread ;handles menus and gubbins!
cp 'M'
jp z,entry1
cp 32
ret
; The initial intro and music..
.copyright
xor a
ld (gamemode),a
call copyright_text
call domusic
call_oz(os_pur)
.copy1
call ozread
and a
jr z,copy1
ret
.copyright_text
call dotitlescreen
call windclr
ld bc,$2129
call messag
defm "Lemmings Z88\x00"
ld bc,$2225
call messag
defm "(c) 1991 Psygnosis Ltd\x00"
ld bc,$2320
call messag
defm "Conversion by D Morris Feb 2000\x00"
ld bc,$2523
call messag
defm "Press Any Key To Continue\x00"
ret
; Text for startselect
.startselect_text
ld a,1
ld (gamemode),a
call dotitlescreen
call windclr
ld bc,$2129
call messag
defm "Current level\x00"
ld bc,$222C
call messag
defm "Level \x00"
ld a,(level)
call numpri
ld bc,$2325
call messag
defm "To access another level\x00"
ld bc,$242A
call messag
defm "Press Enter\x00"
call firemsg
ret
; Print up the level select thing
.startselect
call startselect_text
.start1
call ozread
cp 'M'
jp z,entry1
cp 13
jp z,inputcode
cp 32
jr nz,start1
; ------ START OF LOADING GUBBINS ------
; FIX, FIX! Length=8405
.loadlevel
call windclr
ld bc,$2220
call messag
defm "Loading and unzipping Level: \x00"
ld a,(level)
call numpri
ld bc,$2427
call messag
defm "...please wait...\x00"
ld a,(level)
call reda2de
ld hl,$3030
add hl,de
ld a,l
ld l,h
ld h,a
ld (filenamech),hl
ld de,filename
call inflate
jr c,filerr
ld hl,filename
call_oz (dc_nam)
ld a,(level)
ld hl,level_no
cp (hl)
ret
.filerr
push af
call windclr
pop af
.unziperr
ld bc,$2222
call messag
defm "An error has occurred whilst\x00"
ld bc,$2327
call messag
defm "loading level: \x00"
ld a,(level)
call numpri
call firemsg
.unzip1
call checkfire
jr nz,unzip1
jp startselect
;-------- END OF LOADING GUBBINS ---------
.previewtitle
call preview_text
jp waitstartgame
.preview_text
ld a,2
ld (gamemode),a
call cls
call previewlevel
;Copy screen over to OZ...
call oztitlecopy ;fixes types etc
call windclr
IF SILLY
ld bc,$202C
call messag
defm "Level \x00"
ld a,(level)
call numpri
ENDIF
ld hl,level_name
ld bc,$2020
call messag32
ld bc,$2128
call messag
defm "No. of Lemmings \x00"
ld a,(total_lemmings)
.L9201 call numpri
ld a,(to_be_saved)
ld bc,$2228
call numpri
inc c
inc c
call messag
defm "to be saved\x00"
ld bc,$2328
call messag
defm "Release Rate \x00"
ld a,(release_rate)
call numpri
ld bc,$2428
call messag
defm "Time \x00"
ld a,(time_allowed)
inc a
call numpri
call messag
defm " minutes\x00"
call firemsg
ld bc,$2528
call messag
defm "Rating \x00"
ld a,(rating)
cp 1
jr z,pr_fun ; (21)
.L926c cp 2
jr z,pr_tricky ; (27)
cp 3
jr z,pr_taxing ; (36)
call messag
defm "Mayhem\x00"
ret
.pr_fun
call messag
defm "Fun\x00"
ret
.pr_tricky
call messag
defm "Tricky\x00"
ret
.pr_taxing
call messag
defm "Taxing\x00"
ret
.firemsg
ld bc,$2625
call messag
defm "PRESS SPACE TO CONTINUE\x00"
ret
.leveldonescr
ld a,(level)
ld (levelnew),a
call leveldone_text
jr nc,gamedone
call waitstartgame
ld a,(levelnew)
ld (level),a
jp startlevel
.gamedone
call ozread
and a
jr z,gamedone
jp entry1
.leveldone_text
ld a,4
ld (gamemode),a
xor a
.L92f4 ld (reloadlevel),a
call cls
call dotitlescreen
call windclr
ld bc,$2023
call messag
defm "All Lemmings accounted for\x00"
ld bc,$2122
call messag
defm "You rescued \x00"
ld a,(savedlemmings)
call numpri
; ld bc,$2228
call messag
defm " You needed \x00"
ld a,(to_be_saved)
call numpri
ld a,(savedlemmings)
.L9356 and a
jp z,L93de
ld hl,to_be_saved
cp (hl)
jp c,L9428
ld a,(level)
cp lastlevel
jp z,gamefinished
ld a,255
ld (reloadlevel),a
ld a,(savedlemmings)
ld hl,total_lemmings
cp (hl)
jp z,perfectfinish
ld hl,to_be_saved
cp (hl)
jp z,spoton
ld bc,$2320
call messag
defm "That level seemed no problem to\x00"
ld bc,$2420
call messag
defm "you on that attempt one the next\x00"
.L93d8 call getcode
call firemsg
scf
ret
.L93de ld bc,$2322
call messag
defm "Rock Bottom! I Hope for your\x00"
ld bc,$2421
.L9408 call messag
defm "sake that you nuked that level\x00"
call firemsg
scf
ret
.L9428 ld bc,$2321
call messag
defm "Better rethink your strategy\x00"
ld bc,$2420
call messag
defm "before you try this level again!\x00"
call firemsg
scf
ret
.spoton ld bc,$2320
call messag
defm "Spot on.you can't get much closer\x00"
ld bc,$2420
call messag
defm "than that. lets try the next....\x00"
call getcode
call firemsg
scf
ret
.perfectfinish
ld bc,$2224
call messag
defm "Superb! You rescued every\x00"
ld bc,$2321
call messag
defm "Lemming on that level. Can you\x00"
ld bc,$2427
call messag
defm "do it again....?\x00"
call getcode
call firemsg
scf
ret
.gamefinished
call cls
call windclr
ld bc,$2129
call messag
defm "CONGRATULATIONS!!!\x00"
ld bc,$2221
call messag
defm "You have finished z88 Lemmings\x00"
ld bc,$2322
call messag
defm "You're now truly a Lemmings\x00"
ld bc,$2429
defm "GRAND MASTER!!\x00"
ld bc,$2520
defm "Hope you enjoyed playing.. - Dom\x00"
and a
ret
.waitstartgame
call checkfire
jr nz,waitstartgame ; (-8)
call fadeattr
ld a,255
ld (attr),a
jp cls
; This looks like the main in game loop
.ploop
ld a,(varbase+34)
bit 0,a
jp nz,scrollleft
bit 1,a
jp nz,scrollright
.mloop call copymap
call dokeyselectors
call L9910 ;lemming actions?
call La458 ;more actions?
call cklockon
call La20e ;?
call L98c3 ;both this and above address datatab1
ld a,0
ld (gameon),a
call interrupt_routine
ld a,255
ld (gameon),a
call prtime
call prlemsout
call prlemsin
call La600
ld a,(attr)
cp 255
jp nz,exitlevfin ;finished level
ld a,(varbase+18)
cp 0
jp nz,ploop
ld a,(attr)
cp 255
jp nz,mloop
.mloop1 ld a,5
ld (attr),a
jp mloop
xor a
ld (varbase+30),a
jp mloop
.exitlevfin
jp leveldonescr ;poss?
call setattr
jp c,leveldonescr
jp mloop
; Set the screen attribute - used in fade out
.setattr
ld a,(attr)
sub 1
ret c
ld (attr),a
ld bc,3000
call pausebc
xor a
ret
.scrollleft
xor a
ld (varbase+34),a
ld a,(scrxpos)
and a
jp z,mloop
dec a
ld (scrxpos),a
ld hl,(varbase+12)
ld de,8
and a
sbc hl,de
ld (varbase+12),hl
ld a,(varbase+35)
bit 0,a
jp z,L9790
xor a
ld (varbase+35),a
ld a,(scrxpos)
cp 2
jp c,L9790
dec a
dec a
ld (scrxpos),a
ld hl,(varbase+12)
ld de,16
and a
sbc hl,de
ld (varbase+12),hl
jp L9790
.scrollright
xor a
ld (varbase+34),a
ld a,(scrxpos)
cp 32
jp nc,mloop
inc a
ld (scrxpos),a
ld hl,(varbase+12)
ld de,8
add hl,de
ld (varbase+12),hl
ld a,(varbase+35)
bit 1,a
jp z,L9790
xor a
ld (varbase+35),a
ld a,(scrxpos)
cp 30
jp nc,L9790
inc a
inc a
ld (scrxpos),a
ld hl,(varbase+12)
ld de,16
add hl,de
ld (varbase+12),hl
.L9790 ld iy,(varbase+67)
ld a,(varbase+25)
ld b,a
and a
jp z,mloop
.L979d push bc
ld a,(iy+0)
and a
jp z,L97a9
call L9c94
.L97a9 pop bc
ld de,20
add iy,de
djnz L979d ; (-20)
jp mloop
; Print the lemming numbers
.prstatnum
ld bc,$2420
ld a,(release_rate)
call prstatusnum
ld a,(release_rate)
inc c
call prstatusnum
ld a,(num_climbers)
ld bc,$2426
call prstatusnum
.L97f3 ld a,(num_floaters)
ld bc,$2428
call prstatusnum
.L9800 ld a,(num_bombers)
ld bc,$242B
call prstatusnum
.L980d ld a,(num_blockers)
ld bc,$242E
call prstatusnum
.L981a ld a,(num_builders)
ld bc,$2430
call prstatusnum
.L9827 ld a,(num_bashers)
ld bc,$2433
call prstatusnum
.L9834 ld a,(num_miners)
ld bc,$2436
call prstatusnum
.L9841 ld a,(num_diggers)
ld bc,$2439
call prstatusnum
jp mksel_icon
; Print a numbr in a...at bc
.prselect
ld hl,invon
call_oz(gn_sop)
call prstatusnum
ld hl,invon
call_oz(gn_sop)
ret
.invon
defb 1,'R',0
.prstatusnum
ld hl,tinyon
call_oz(gn_sop)
call numpri
ld hl,tinyon
call_oz(gn_sop)
ret
.tinyon defb 1,'T',0
.numpri
push af
call doposn
pop af
call reda2de
push bc
push de
ld a,d
add a,48
call prchar1
pop de
pop bc
inc c
ld a,e
add a,48
call prchar1
ret
; Get a number in a into a tens in d and units in e
.reda2de
cp 10
jp c,L98b0
ld d,0
.L98a2 push af
sub 10
jp c,L98ad
inc d
pop hl
jp L98a2
.L98ad pop af
ld e,a
ret
.L98b0 ld e,a
ld d,0
ret
; Handles trapdoor?
.L98c3 ld iy,datatab1
ld de,20
add iy,de
add iy,de
call L99ce
ld de,20
add iy,de
call L99ce
ld a,(varbase+58)
and a
ret z
dec a
ld (varbase+58),a
cp 4
ret nc
and a
ld a,2 ;lets go sound
call z,sample
ld iy,datatab1
ld l,(iy+10)
ld h,(iy+11)
ld de,64
add hl,de
ld (iy+10),l
ld (iy+11),h
ld de,20
add iy,de
ld l,(iy+10)
ld h,(iy+11)
ld de,64
add hl,de
ld (iy+10),l
ld (iy+11),h
ret
; Does the Lemming Actions?
.L9910 ld iy,datatab1+120
ld a,(varbase+25)
ld hl,varbase+69
add a,(hl)
ld b,a
and a
jp z,La170
.L9921 push bc
bit 5,(iy+0)
jp nz,La955
.L9929 ld a,(iy+0) ;lemming type
and 31
jp z,L998d ;cp 0
cp 1
jp z,L99fd
cp 2
jp z,L9af1
cp 3
jp z,L9acd
cp 7
jp z,L9cbb
cp 10
jp z,Lad99
cp 8
jp z,L9d83
cp 12
jp z,La131
cp 9
jp z,La31d
cp 11
jp z,L9f36
cp 4
jp z,L9cda
cp 13
jp z,L9d6d
cp 14
jp z,L9a62
cp 5
jp z,Lab06
cp 17
jp z,Lab43
cp 15
jp z,L9c54
cp 16
jp z,La9ee
cp 19
jp z,Laa32
cp 18
jp z,L9999
.L998d pop bc
ld de,20
add iy,de
djnz L9921 ; (-116)
jp La170
.L9998 pop af
.L9999 ld a,(iy+12)
inc a
cp (iy+13)
jp nc,L99bb
ld (iy+12),a
ld l,(iy+10)
ld h,(iy+11)
ld d,0
ld e,(iy+15)
add hl,de
ld (iy+10),l
ld (iy+11),h
jp L998d
.L99bb ld (iy+12),1
ld l,(iy+8)
ld h,(iy+9)
ld (iy+10),l
ld (iy+11),h
jp L998d
.L99ce ld a,(iy+12)
inc a
cp (iy+13)
jp nc,L99ec
ld (iy+12),a
ld l,(iy+10)
ld h,(iy+11)
ld de,64
add hl,de
ld (iy+10),l
ld (iy+11),h
ret
.L99ec ld (iy+12),1
ld l,(iy+8)
ld h,(iy+9)
ld (iy+10),l
ld (iy+11),h
ret
.L99fd ld a,(iy+0)
and 64
jp nz,L9a6d
.L9a05 ld a,(iy+5)
ld l,(iy+3)
ld h,(iy+4)
call La13c
push af
and (hl)
jp nz,L9a3f
pop af
ld de,64
add hl,de
and (hl)
jp nz,L9a35
ld a,(iy+5)
inc a
inc a
inc (iy+19)
inc (iy+19)
.L9a2a cp 128
jp nc,L9a9c
ld (iy+5),a
jp L9999