-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.asm
6072 lines (5709 loc) · 186 KB
/
main.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
MAPCHAR '-', 0
MAPCHAR ' ', $5b
MAPCHAR '*', $5d
MAPCHAR '.', $5e
MAPCHAR '%', $60
MAPCHAR '0', $61
MAPCHAR '1', $62
MAPCHAR '2', $63
MAPCHAR '3', $64
MAPCHAR '4', $65
MAPCHAR '5', $66
MAPCHAR '6', $67
MAPCHAR '7', $68
MAPCHAR '8', $69
MAPCHAR '9', $6A
MAPCHAR ':', $6B
MAPCHAR '/', $6C
MAPCHAR '_', $6D
osrdch = $ffe0
osword = $fff1
osbyte = $fff4
; ** Zero-page **
zCOMPLETION_FRACTION = $0b
zCOMPLETION_PERCENT = $0c
zCORE = $17 ; $17=top left, $18=top middle ... $1e=bottom middle, $1f = bottom right. 9 bytes of zero page - each byte is the item index of that core piece
zSCORE0 = $46
zSCORE1 = $47
zSCORE2 = $48
zLIVES = $49
; Hold's Blob's screen position etc at the point he entered the room
zSAVED_BLOB_LO = $5a
zSAVED_BLOB_HI = $5b
zSAVED_BLOB_FRAME = $5c
zSAVED_HOVERPAD_FLAG = $5d
; Blob's screen address
zBLOB_LO = $70
zBLOB_HI = $71
zBLOB_FRAME = $72 ; index of which Blob sprite is current. 0-7=left, 8-15=right
zGRAVITY_INDEX = $73
zBLOB_ROOMBUF_ADDR_LO = $74
zBLOB_ROOMBUF_ADDR_HI = $75
zHOVERPAD_FLAG = $76 ; 0=is on hoverpad, 1=not on hoverpad
zROOM_LO = $7e
zROOM_HI = $7f
zCORE_ITEMS_FOUND = $9f
ROOMS_VISITED = $0380
; The current room contents are represented in a #LOw-res buffer that has one byte per 4x2 pixels. It is used
; for #HIt-testing at Blob moves around
;ROOM_BUFFER = $0440 (to be confirmed)
; Conventions:
;
; .ALLCAPS - for the start of #LOgical units, e.g. subroutines
; .lowercase - for labels within a #LOgical unit, e.g. #LOcal branches
; The teleport and cheops screens use a random palette. This shared code
; clears the screen and sets up the random palette.
.INIT_TEXT_SCREEN jsr CLEAR_SCREEN_AND_FLUSH
; $93 = random number from 0 to 4
.get_rand_colour1 jsr RAND
and #$07
cmp #$05
bcs get_rand_colour1
sta $93
; $95 = a different random number from 0 to 4
.get_rand_colour2 jsr RAND
and #$07
cmp $93
beq get_rand_colour2
cmp #$05
bcs get_rand_colour2
adc #$01
; Increment so $93 and $95 both hold different random numbers between 1 and 5 inclusive
sta $95
inc $93
; Set the palette
jsr $7f00
; "Tchonk" sound - used when you enter teleport and a couple of other places
.PLAY_TCHONK_SOUND ldx #LO(TCHONK_SOUND)
ldy #HI(TCHONK_SOUND)
jmp PLAY_SOUND_WITH_ENV
.SHOW_TELEPORT_SCREEN
; Copy the code for the current teleport into the screen text buffer
ldx #$00
ldy $f5
.L0e2f lda TELEPORTERS-8,y
sta teleport_code,x
iny
inx
cpx #$05
bne L0e2f
; Clear the screen and randomize the palette
jsr INIT_TEXT_SCREEN
; Draw a teleport on the screen
; ($8c) = $6124 = Teleport graphic
lda #LO(TELEPORT)
sta $8c
lda #HI(TELEPORT)
sta $8d
lda #$d0
sta $8e
lda #$6f
sta $8f
ldx #$04
ldy #$03
jsr DRAW_OBJECT
; Draw text
ldx #LO(TELEPORT_TEXT)
ldy #HI(TELEPORT_TEXT)
jsr DRAW_TEXT
; Initialize char-pressed index to 0
lda #$00
sta $86
; Wait for user to press a key from A - Z
.wait_for_key jsr osrdch
and #$5f
cmp #$41
bcc wait_for_key
cmp #$5b
bcs wait_for_key
; Store the pressed character in the text buffer
ldx $86
sta $0f90,x
;
sta $0f95
ldx #$95
ldy #$0f
jsr DRAW_TEXT
; Play a sound
ldx #LO(KEYPRESS_SOUND)
ldy #HI(KEYPRESS_SOUND)
jsr PLAY_SOUND
; Increment the char index, #LOop back if not reached 5 chars.
inc $86
lda $86
cmp #$05
bne wait_for_key
; See if the code the user entered matches a code in the teleporters table
ldy #$08 ; offset into teleporters table (+8)
.compare_code ldx #$00
.compare_char lda TELEPORTERS-8,y
cmp $0f90,x
bne try_next_code
iny
inx
cpx #$05
bne compare_char
beq matched_teleport_code
.try_next_code tya
clc
adc #$08
and #$f8
tay
bpl compare_code
; Y overflowed indicating we went through all 15 codes (that's why it starts at 8! Clever!)
jsr PLAY_SHRILL_NOISE
; Code not recognized takes same path as teleporting does, you just
; 'teleport' to same place you're already in :-)
lda $f5 ; offset into TELEPORTERS of current teleport
pha
ldx #LO(code_not_recognized_text)
bne leave_teleport
.matched_teleport_code
tya
and #$f8
pha
ldx #$59
ldy #$04
jsr PLAY_SOUND_WITH_ENV
ldx #LO(now_teleporting_text)
.leave_teleport
; Init counter to 213 (counter counts *up* to zero, so 42 frames at 50Hz)
lda #$d5
sta $86
stx $7e ; save #LOw byte of text message to show
.flash_message
; Cycle the message text through all 4 colours
lda $86
and #$03
ora #$80
sta now_teleporting_text
sta code_not_recognized_text
; Draw the "CODE NOT RECOGNIZED" or the "NOW TELEPORTING" message
ldx $7e
ldy #$0f
jsr DRAW_TEXT
; *FX 19 : wait for vsync
lda #$13
jsr osbyte
; Increment counter and #LOop back if not done
inc $86
bne flash_message
; Pull the destination teleport offset off the stack
pla
tay
; Each teleporter record is 8 bytes. Bytes 6 and 7 encode Blob's new screen address and room index:
; RRRRRRRR | YYYYXXXR where Y = Blob Y, X = Blob X, and R = room index (9 bits!)
; Get the 4-bit Y, multiply it by 2 and add a screen page offset.
lda TELEPORTERS-8+7,y
lsr a
lsr a
lsr a
lsr a
sta $8e
; Multiply by 3 (each row of objects is 3 character rows #HIgh)
asl a
adc $8e
adc #$6e; // game screen starts at $6d00 iirc
sta zBLOB_HI
; Get Blob's new X position from bits 1,2, and 3.
lda TELEPORTERS-8+7,y
lsr a; #LOse bit 8 of the room index
; Multiply by 32 (the width of a room object)
asl a
asl a
asl a
asl a
asl a
; Subtract one column (4 pixels wide) so Blob is correctly positioned within the teleport
sec
sbc #$08
sta zBLOB_LO
; Set Blob's current frame to be facing right, rightmost.
lda #$0b
sta zBLOB_FRAME
; Get 9-bit room address
lda TELEPORTERS-8+6,y
sta zROOM_LO
lda TELEPORTERS-8+7,y
and #$01
sta zROOM_HI
.CLEAR_SCREEN_AND_FLUSH
jsr CLEAR_SCREEN
jmp FLUSH_BUFFERS
; *** END OF TELEPORT CODE ****
.PLAY_SHRILL_NOISE
ldx #LO(SHRILL_NOISE)
ldy #HI(SHRILL_NOISE)
jmp PLAY_SOUND_WITH_ENV
.KEYPRESS_SOUND
EQUB $10, $00, $f1, $00, $01, $00, $01, $00
.TELEPORT_TEXT
EQUB $81
EQUB $1f, $03, $07
EQUS "YOU HAVE ENTERED"
EQUB $1f, $13, $09
EQUS "TELEPORT"
EQUB $1f, $0a, $0b
EQUS "CODE : "
EQUB $83
.teleport_code
EQUS "(C)KP" ; these chars are never seen, theyre a placeholder for the current teleport's code
EQUB $1f, $0c, $0e
EQUB $82
EQUS "ENTER TELEPORTAL"
EQUB $1f, $0c, $10
EQUS "DESTINATION CODE"
EQUB $1f, $1a, $13
EQUB $83
EQUS "_ _ _ _ _"
EQUB $81, $1f, $1a, $13, $0d
EQUB $00, $00, $00, $00, $00
.L0f95 EQUB $5b, $5b, $0d
.code_not_recognized_text
EQUB $81
EQUB $1f, $05, $15
EQUS "CODE NOT RECOGNISED"
EQUB $0d
.now_teleporting_text
EQUB $81
EQUB $1f, $0e, $15
EQUS "NOW TELEPORTING"
EQUB $0d
.SHRILL_NOISE
; Envelope
EQUB $04, $01, $0a, $14, $1e, $01, $01, $01, $7e, $00, $00, $82, $7e, $7e
; Sound
EQUB $11, $00, $04, $00, $c0, $00, $1e, $00
.CHEOPS_TEXT
EQUB $1f, $0e, $08, $82
EQUS "CHEOPS PYRAMID"
EQUB $1f, $0e, $0c, $81
EQUS "EXCHANGE FOR"
EQUB $1f, $06, $0e
EQUS "1. 2. 3. 4. 5."
EQUB $0d
.TCHONK_SOUND ; This is used on the start screen when you select 1,2, or 3; also
; when you enter a teleport and when you eat a bonus.
; Envelope data : 14 bytes
EQUB $04, $01, $f6, $f1, $ec, $04, $04, $04, $7e, $fa, $f3, $dc, $7e, $5a
; Sound data : 8 bytes
EQUB $02, $00, $04, $00, $78, $00, $02, $00
.SHOW_CHEOPS_SCREEN jsr INIT_TEXT_SCREEN
ldx #LO(CHEOPS_TEXT)
ldy #HI(CHEOPS_TEXT)
jsr DRAW_TEXT
.L1034 jsr RAND
and #$03
tay
lda $000f,y
beq L1034
sty $80
sta $89
lda #$03
sta $8e
.L1047 jsr RAND
cmp #$09
bcs L1047
tay
lda $0017,y
cmp #$80
bcs L1047
ldx $8e
and #$1f
sta $85,x
dec $8e
bpl L1047
ldx #$ff
ldy #$00
lda #$90
sta $8e
lda #$72
sta $8f
lda $89
jsr $0bb3
lda #$18
sta $8e
lda #$76
sta $8f
lda #$00
sta $81
.L107d ldy $81
lda $0085,y
ldx #$ff
ldy #$00
jsr $0bb3
sec
lda $8e
sbc #$d0
sta $8e
lda $8f
sbc #$01
sta $8f
inc $81
lda $81
cmp #$05
bne L107d
lda #$0f
ldx #$00
jsr osbyte
.L10a5 jsr osrdch
sec
sbc #$31
bcc L10a5
cmp #$05
bcs L10a5
pha
tay
lda $0085,y
ldy $80
sta $000f,y
sta $87
pla
asl a
asl a
asl a
asl a
sta $86
asl a
adc $86
adc #$18
sta $86
jsr PLAY_SHRILL_NOISE
lda #$32
sta $88
lda #$00
sta $89
.L10d6
; Wait for vsync (*FX 19)
lda #$13
jsr osbyte
lda $86
sta $8e
lda #$76
sta $8f
lda $89
eor #$ff
sta $89
tax
ldy #$00
lda $87
jsr $0bb3
dec $88
bne L10d6
tay
sta ($53),y
iny
sta ($53),y
rts
.L10fc ; this data gets overwritten by code in 7f00. Think it's palette data.
EQUB $07, $17, $47, $57, $27, $37, $67, $77
EQUB $87, $97, $c7, $d7, $a7, $b7, $e7, $f7
EQUB $07, $17, $47, $57, $26, $36, $66, $76
EQUB $85, $95, $c5, $d5, $a0, $b0, $e0, $f0
.INIT_GAME ; NB: Only called from one place.
; Reset bit 2 in 5 bytes of unknown data...
ldy #$09
.L111e lda $61c3,y
and #$fd
sta $61c3,y
dey
dey
bpl L111e
; Initial screen pos = $7780, midpoint of game screen
lda #$80
sta zBLOB_LO
lda #$77
sta zBLOB_HI
; Reset score to zero
lda #$00
sta zSCORE0
sta zSCORE1
sta zSCORE2
; Start with 5 lives
lda #$05
sta zLIVES
; Clear two entire pages of RAM... no idea what for
ldy #$00
tya
.L1141 sta $0c00,y
sta $0d00,y
iny
bne L1141
; Clear ROOMS_VISITED (1 bit per room)
.L114a sta ROOMS_VISITED,y
iny
bpl L114a
ldy #$07
.L1152 tya
and #$04
sta $000f,y
dey
bpl L1152
jsr S20a0
; Reset completion %age
lda #$00
sta zCOMPLETION_FRACTION
sta zCOMPLETION_PERCENT
; Set ($88) to $0c00
sta $88
lda #$0c
sta $89
; Think this is getting a random byte...
.L116a jsr RAND
sta $8e
jsr RAND
asl a
asl a
asl a
asl a
ora $8e
sta $8e
; $8A = RAND(3)
jsr RAND
and #$03
sta $8a
; 8F = 6 or 7
lsr a
ora #$06
sta $8f
; At this point ($8E) is a random byte address between $0600 and $07FF.
; This could be room states?
; If room byte is not zero (i.e. already contains something) then try again
ldy #$00
lda ($8e),y
bne L116a
; Set room byte to 1
lda #$01
sta ($8e),y
lda $8e
tax
; Map the room byte address into another buffer at $37c0
clc
adc #$c0
sta $8e
lda $8f
adc #$31
sta $8f
; Read a byte from this buffer... it might be controlling where items can go?
lda ($8e),y
sta $8d
and #$3f
cmp #$30
bcs L116a ; if #LOw 6 bits are 49-63, try again...
sta $8c
txa
sta ($88),y
; $8B = ($8D >> 6) + 1 (i.e. $8b will hold 1,2,3, or 4)
lda $8d
and #$c0
asl a
rol a
rol a
adc #$01
sta $8b
; RAND(3) until we get value smaller than $8b
.L11b8 jsr RAND
and #$03
cmp $8b
bcs L11b8
adc $8c
; Rotate 8A (which holds a random 0 to 3) so those bits are in top
lsr $8a
ror $8a
ror $8a
ora $8a
ldy #$01
sta ($88),y
; Advance ($88) by two bytes and #LOop back if we've not reached $0e00
inc $88
inc $88
bne L116a
inc $89
lda $89
cmp #$0e
bne L116a
lda #$00
sta zBLOB_FRAME
sta $22
sta zCORE_ITEMS_FOUND
lda #$01
sta zHOVERPAD_FLAG
sta $7a
; Initialize zCORE to be all the original core graphics.
ldy #11 ; index of first core item in ITEMS
.L11ed tya
sta zCORE-11,y
iny
cpy #20
bne L11ed
; Replace 4 zCORE elements with randomly-chosen non-core bits (chips etc)
lda #4
sta $8e
.random_core_bit
; Choose a random non-core bit (item index range 20 to 29)
jsr RAND
cmp #10
bcs random_core_bit
adc #20
; If this bit is in the core already, choose again
ldy #8
.L1205 cmp zCORE,y
beq random_core_bit
dey
bpl L1205
; Save the non-core bit we've selected
pha
; Choose a random #LOcation in the core to place it
.random_core_loc jsr RAND
cmp #9
bcs random_core_loc
tax
lda zCORE,x
; If this #LOcation already has a non-core item, try again
cmp #20
bcs random_core_loc
; Place the non-core item in the core
pla
sta zCORE,x
dec $8e
bpl random_core_bit
lda #$00
sta $8c
sta $8d
sta $8b
.L122b jsr RAND
and #$02
clc
adc $8c
tay
lda $61cd,y
ldx $8d
sta $0528,x
lda $61ce,y
pha
pha
and #$01
sta $0529,x
pla
asl a
asl a
asl a
asl a
and #$e0
ora #$08
ora $0529,x
sta $0529,x
pla
and #$70
lsr a
lsr a
lsr a
sta $8e
lsr a
adc $8e
adc #$6e
sta $052a,x
lda $8b
cmp #$0b
bcs L1275
tay
lda $0015,y
sta $052b,x
jmp L1288
.L1275 jsr RAND
lda $9b
and #$1f
cmp #$13
bcs L1275
clc
adc #$0b
ldx $8d
sta $052b,x
.L1288 clc
lda $8c
adc #$04
sta $8c
lda $8d
adc #$04
sta $8d
inc $8b
lda $8b
cmp #$01
beq L12a1
cmp #$03
bne L12b2
.L12a1 sec
lda $8d
sbc #$04
sta $8d
jsr RAND
and #$01
beq L1288
.L12af jmp L122b
.L12b2 lda $8b
cmp #$16
bne L12af
lda #$09
sta $052b
lda #$0a
sta $052f
; Starting room is at 8,0 on the map, i.e. index 8
lda #$08
sta zROOM_LO
lda #$00
sta zROOM_HI
sei
sta $23
inc $23
sta $24
sta $25
cli
sta $9e
sta $35
sta $37
sta $39
lda #$0f
sta $31
lda #$10
sta $3f
lda #$06
sta $3d
lda #$ff
sta $3e
jsr S2560
.L12ef
; Set Blob's screen position etc to whatever it was when he entered the room
lda zSAVED_BLOB_LO
sta zBLOB_LO
lda zSAVED_BLOB_HI
sta zBLOB_HI
lda zSAVED_BLOB_FRAME
sta zBLOB_FRAME
lda zSAVED_HOVERPAD_FLAG
sta zHOVERPAD_FLAG
; Decrement the lives counter
sed
sec
lda zLIVES
sbc #$01
sta zLIVES
cld
bcs L130b ; SBC is weird... think this means if it *didn't* overflow
rts
.L130b lda #$10
sta $3b
lda $3d
ora #$01
sta $3d
lda #$ff
sta $3c
sta $3a
.L131b lda #$03
sta $29
sta $27
.L1321 jsr FLUSH_BUFFERS
jsr S2560
lda $80
pha
ldy #$2f
.L132c lda $0188,y
tax
lda $0158,y
sta $0188,y
txa
sta $0158,y
dey
bpl L132c
jsr S20a0
; Calculate byte index into ROOMS_VISITED by dividing the 9-bit room index by 8.
lda zROOM_HI
lsr a
lda zROOM_LO
ror a
lsr a
lsr a
tay
; Calculate the bit we are interested within the ROOMS_VISITED byte
lda #$00
sta $8f
lda zROOM_LO
and #$07
tax
sec
.L1353 rol $8f
dex
bpl L1353
; Has this room been visited?
lda ROOMS_VISITED,y
and $8f
bne L137d ; Yes, jump fwd
; No, mark the room as having been visited
lda ROOMS_VISITED,y
ora $8f
sta ROOMS_VISITED,y
; Score += 25
ldy #$02
ldx #$50
jsr SCORE_ADD
; Adventure complete += ((100/512)*255) = 49.8 ~= 50
clc
lda zCOMPLETION_FRACTION
adc #$32
sta zCOMPLETION_FRACTION
lda zCOMPLETION_PERCENT
sed
adc #$00
cld
sta zCOMPLETION_PERCENT
.L137d ldx zROOM_LO
ldy zROOM_HI
jsr S25f0
jsr S2571
ldx zBLOB_LO
ldy zBLOB_HI
jsr SCREENADDR_TO_ROOMBUF_ADDR
stx zBLOB_ROOMBUF_ADDR_LO
sty zBLOB_ROOMBUF_ADDR_HI
lda #$00
sta zGRAVITY_INDEX
pla
sta $80
jsr S23d4
lda $2e
sta $2c
lda $2f
sta $2d
lda $26
cmp zROOM_LO
bne L13bb
lda $27
cmp $7f
bne L13bb
lda $2a
sta $2e
lda $2b
sta $2f
jmp L1430
.L13bb jsr RAND
ora #$10
sta $2e
jsr RAND
and #$01
ora #$02
sta $2f
ldy #$2f
lda #$00
.L13cf sta $0188,y
dey
bpl L13cf
lda $7f
beq L1430
lda #$26
sta $8e
.L13dd dec $8e
dec $8e
bmi L1430
ldy $8e
lda $6185,y
cmp zROOM_LO
bne L13dd
lda $6186,y
pha
and #$f8
sta $2332
pla
and #$03
sta $8e
ldy #$00
.L13fc sty $8f
jsr RAND
adc #$08
sta $2336
jsr RAND
and #$01
tax
lda $233e,x
sta $2335
ldy $8f
ldx #$00
.L1416 lda $2332,x
sta $0188,y
inx
iny
cpx #$0c
bcc L1416
lda $2332
adc #$1f
sta $2332
dec $2f
dec $8e
bpl L13fc
.L1430 lda #$01
sta $0d
jsr S2eb6
jsr S2366
ldy #$00
.L143c lda $0028,y
sta $0026,y
iny
cpy #$08
bne L143c
lda zROOM_LO
sta $28
lda zROOM_HI
sta $29
lda zROOM_HI ; unnecessary!
bne L1461
lda zROOM_LO
cmp #$c7
beq L1464
cmp #$c6
bne L1461
lda #$ff
sta $2e
.L1461 jmp L15ec
.L1464 lda #$01
jsr S2eb6
lda #$6d
sta $8e
lda #$06
sta $8f
ldx #$06
.L1473 ldy #$05
.L1475 lda #$18
sta ($8e),y
dey
bpl L1475
clc
lda $8e
adc #$20
sta $8e
bcc L1487
inc $8f
.L1487 dex
bne L1473
jsr S3563
lda #$00
ldx #$73
jsr S3587
jsr $7f00
lda #$00
sta $84
.L149b ldy $84
lda $000f,y
ldy #$08
.L14a2 cmp $0017,y
beq L14ad
dey
bpl L14a2
jmp L1506
.L14ad sta $83
sty $85
sta $81
lda #$0f
sta $86