-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmap.asm
1548 lines (1322 loc) · 30.8 KB
/
map.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
; this file contains all map related sub routines
; sub routine that is going to decompress level data from rom
; and store it in ram at level_ptr
; At this point in time the level data are not compressed and will
; be used directly
; inputs:
; level_data_ptr -> ptr to ROM/SRAM location of compressed level
; level_ptr -> copy destination
; side effects:
; all registers and flags may be changed
; temp is written to
; disables sprite updating in game flags
decompress_level:
; clear tile position
lda #$00
sta tiles_to_clear
sta tiles_to_clear+1
lda game_flags
and #%10111111
sta game_flags ; disable sprite updating
lda #$FF
sta sprite_tile_size ; set invalid size
; save level data ptr
lda level_data_ptr
pha
lda level_data_ptr+1
pha
; to decompress a level we need to loop for a while
; until we find the terminating sequence of $FF $00
lda level_ptr
sta level_ptr_temp
lda level_ptr+1
sta level_ptr_temp+1
; lda #$01
; sta temp ; increment by 1 every time
@decompress_loop:
ldy #$00
ldx #$01 ; x is loop write counter
lda (level_data_ptr), y ; load first byte of data
cmp #$FF ; if it is a ff we can assume we need to decompress
bne @single_value ; if not ff it is a single value
jsr inc_level_data_ptr ; look for next byte
lda (level_data_ptr), y ; load next byte
tax ; a holds x index
cmp #$00 ; if it is 00 we have found $FF $00
beq @decompress_done ; we are done here
jsr inc_level_data_ptr ; next byte
lda (level_data_ptr), y ; a now holds tile
@single_value:
jsr write_decompressed_byte ; write byte
dex ; x is always at least 1
bne @single_value
; increment level
jsr inc_level_data_ptr ; next byte
jmp @decompress_loop ; always loop
@decompress_done:
; restore original level data ptr
pla
sta level_data_ptr
pla
sta level_data_ptr+1
rts
; increments level data ptr
; inputs:
; level_data_ptr -> pointing to compressed level
; side effects:
; a register and acarry flag are modified
; level_data_ptr is incremented
inc_level_data_ptr:
; 16 bit add
lda level_data_ptr
clc
adc #$01
sta level_data_ptr
lda level_data_ptr+1
adc #$00
sta level_data_ptr+1
rts
; writes the decompressed byte contained in a
; to level_ptr_temp
; inputs:
; level_ptr_temp pointing to the next byte location
; side effects:
; increments level_ptr_temp for each iteration
; y is set to 0
; start_x and y may be set
; tiles_to_clear may be incremented
; if tile is a sprite tile it may set up the ai for the map
write_decompressed_byte:
ldy #$00
sta (level_ptr_temp), y
pha ; store current value
; check tile id, between START and END value
cmp #CLEARABLE_TILES_START
bcc @not_clearable
cmp #CLEARABLE_TILES_END
bcs @not_clearable
lda tiles_to_clear
clc
adc #$01
sta tiles_to_clear
lda tiles_to_clear+1
adc #$00
sta tiles_to_clear+1
@not_clearable:
; 16 bit add
lda level_ptr_temp
clc
adc #$01
sta level_ptr_temp
lda level_ptr_temp+1
adc #$00
sta level_ptr_temp+1
pla ; restore tile value
rts
; this sub routine compresses a level
; it will follow the rules desribed in README
; inputs:
; level_data_ptr -> pointing to destination
; level_ptr -> pointing to uncompressed level in RAM/ROM
; side effects:
; all registers and flags may be changed
; temp, temp+1 and temp+2 are written to
compress_level:
; save level data ptr
lda level_data_ptr
pha
lda level_data_ptr+1
pha
; to compress a level we need to loop for a while
; until we reach LEVEL_SIZE bytes
lda level_ptr
sta level_ptr_temp
sta temp+1
lda level_ptr+1
sta level_ptr_temp+1
sta temp+2
; temp will hold the las tile read
lda #$00
sta temp
; pre-calculate end address of level
; temp+1 and +2 are holding the end address
; size is FF+FF+FF+C3
ldx #$03 ; do this 3 times
@end_calc_loop:
lda temp+1
clc
adc #$FF
sta temp+1
lda temp+2
adc #$00 ; add carry
sta temp+2
dex
bne @end_calc_loop
; add rest
lda temp+1
clc
adc #$C3 ; +1 since we break after
sta temp+1
lda temp+2
adc #$00 ; carry
sta temp+2
; loop until level_ptr_temp is the same as the end address
@compress_loop:
ldy #$00 ; used for indirect access
ldx #$01 ; start off at count 1
lda (level_ptr_temp), y ; get first tile for comparison
jmp @next_byte ; start loop
@count_repeates:
; sta temp ; store last tile, or if at start store first tile again
lda (level_ptr_temp), y ; get tile from ram
; check for different tile
cmp temp
bne @store_data
inx
cpx #$FF
beq @store_data
bne @next_byte
@store_data:
lda temp
jsr write_compressed_data
cpx #$FF ; if we did hit FF we need to go to next byte
bne @compress_loop ; if not ff continue on normall
@next_byte:
sta temp ; store last tile now
; increment pointer 16 bit math
lda level_ptr_temp
clc
adc #$01
sta level_ptr_temp
lda level_ptr_temp+1
adc #$00
sta level_ptr_temp+1
; compare to end pointer
lda level_ptr_temp
cmp temp+1
bne @not_done
lda level_ptr_temp+1
cmp temp+2
bne @not_done
beq @compress_done ; if both are equal we are done
@not_done:
cpx #$FF ; if $ff start over from start
beq @compress_loop
bne @count_repeates
@compress_done:
lda temp
jsr write_compressed_data ; add last data
lda #$FF
ldx #$01
; write FF at the end
jsr write_compressed_data
lda #$00
ldx #$01
; write 00 at the end
jsr write_compressed_data
; restore original level data ptr
pla
sta level_data_ptr
pla
sta level_data_ptr+1
rts
; this sub routine saves attributes from ppu
; memory to
; a location pointed to by attr_ptr
; inputs:
; attr_ptr -> pointing to attribute destination
; x -> the nametable
; side effects:
; registers and flags are modified
write_attr:
lda #$00
bit $2002 ; read PPU status to reset the high/low latch
; sta $2005
; sta $2005 ; no scrolling
lda #$23 ; write $23C0 to ppu as start address
cpx #$01
bne @no_add
; if x is 0 do not add, if 1 nt1 is needed
clc
adc #$04
@no_add:
sta $2006
lda #$C0
sta $2006 ; set up ppu for attribute transfer
lda $2007 ; do one invalid read before starting transfer
ldy #$00
@attr_loop:
lda $2007
sta (attr_ptr), y ; transfer
iny
cpy #ATTR_SIZE
bne @attr_loop
lda #$00
sta $2005
sta $2005
rts
; sub routine that writes compressed data to output pointer
; inputs:
; level_ptr -> the output ptr, gets incremented
; a -> the tile to write
; x -> tile count
; side effects:
; increments level_ptr by 1-3 bytes
write_compressed_data:
pha ; save tile state
; first determine what needs to be done
cpx #$03
bcc @single_values ; branch if less than
@compress:
; add an ff first
lda #$FF
sta (level_data_ptr), y
jsr inc_level_data_ptr
txa ; write amount
sta (level_data_ptr), y
jsr inc_level_data_ptr
pla ; get tile
sta (level_data_ptr), y ; store tile id
pha ; push it back since inc will destroy the value
jsr inc_level_data_ptr
pla ; get tile again
; ldx #$00
rts ; done
@single_values:
ldy #$00 ; index
sta (level_data_ptr), y
pha ; save a's state
jsr inc_level_data_ptr
pla
dex
bne @single_values
@done:
pla ; restore tile state
rts
; this sub routine loads all attributes for NT1
; inputs:
; attr_ptr -> pointing to attributes
; x -> decides start address based on nametable
load_attr:
bit $2002 ; read PPU status to reset the high/low latch
; lda #$00
; sta $2005
; sta $2005 ; no scrolling
lda #$23 ; write $23C0 to ppu as start address
cpx #$01
bne @no_add
; if x is 0 do not add, if 1 nt1 is needed
clc
adc #$04
@no_add:
sta $2006
lda #$C0
sta $2006 ; set up ppu for attribute transfer
ldy #$00
@attr_loop:
lda (attr_ptr), y
sta $2007 ; transfer
iny
cpy #ATTR_SIZE
bne @attr_loop
rts
; this sub routine loads a color palette
; inputs:
; palette_ptr -> ptr to palette
; side effects:
; modifies registers and flags
load_palette:
; sets up ppu for palette transfer
bit $2002 ; read PPU status to reset the high/low latch to high
; lda #$00
; sta $2005
; sta $2005 ; no scrolling
lda #$3F
sta $2006
lda #$00
sta $2006
ldy #$00
load_palette_loop:
lda (palette_ptr), y
sta $2007 ; write to PPU
iny
cpy #palette_data_end-palette_data
bne load_palette_loop
; no scrolling
lda #$00
sta $2005
sta $2005
rts
; clears color pallette
; to a certain color
; useful to hide flickering during loads
; by using it before load starts
; inputs:
; a -> color to clear to
clear_palette:
pha
bit $2002
lda #$3F
sta $2006
lda #$00
sta $2006
ldy #PALETTE_SIZE
pla
@loop:
sta $2007 ; write to ppu
dey
bne @loop
; no scrolling
lda #$00
sta $2005
sta $2005
rts
; this sub routine loads a level into NT1
; inputs:
; level_ptr -> pointing to level data
; x -> decides the start address based on nametable
load_level:
lda $2002 ; read PPU status to reset the high/low latch
; reset scroll
; lda #$00
; sta $2005
; sta $2005
lda #$20 ; $2000 = start of ppu address
cpx #$01
bne @no_add
; if nt is 0 we dont need to change the address
clc
adc #$04 ; add 4 to get start address of nt1
@no_add:
sta $2006
lda #$00
sta $2006 ; set up ppu for level transfer
; copy the pointer to
; save the original one
lda level_ptr
sta level_ptr_temp
lda level_ptr+1
sta level_ptr_temp+1
jsr load_level_iter
; same loop again, but add $FF to level ptr
jsr inc_level_temp_ptr
jsr load_level_iter
jsr inc_level_temp_ptr
jsr load_level_iter
jsr inc_level_temp_ptr
; last iteration is different so no jsr
ldy #$00 ; remainder
@load_level_loop:
lda (level_ptr_temp), y
sta $2007 ; write to ppu
iny
cpy #$C3
bne @load_level_loop
rts
; verifies draw coordinates
; inputs:
; get_tile_x, _y, draw_buffer_x, _y
; a -> get_tile coordinate, either x or y
; y -> max tile coordinates, either #31 for X or #29 for Y
; returns:
; a -> tiles to load
; y = %11000000 -> did overflow, x, y
; side effects:
; uses temp to store temporary y value
verify_draw_buffer:
sta temp+1 ; store coordinate
lda #$00
sta temp
lda get_tile_x
cmp #32
bcc @no_oob_x
lda #$00
sta get_tile_x
sta draw_buffer_x
lda #%10000000
sta temp ; y return value
@no_oob_x:
lda get_tile_y
cmp #30
bcc @no_oob_y
lda #$00
sta get_tile_y
sta draw_buffer_y
lda temp
ora #%01000000
sta temp ; y return value
@no_oob_y:
; decide how many tiles to load
tya ; max tiles in x
sec
sbc temp+1 ; if above VISIBILITY_RADIUS*2-1 adjust
cmp #VISIBILITY_RADIUS*2
bcc @no_adjust
lda #VISIBILITY_RADIUS*2-1
@no_adjust:
ldy temp ; y return value
rts
; loads the level only in the visible radius around the player
; the remainder of the level will remain undiscovered
; inputs:
; level_ptr -> pointing to level data
; x -> decides start address for nametable
; get_x and get_y -> initial position
load_level_part:
lda get_tile_x
sec
sbc #VISIBILITY_RADIUS
cmp #30
bcc @no_oob_x
lda #$00
@no_oob_x:
sta draw_buffer_x
sta get_tile_x
lda get_tile_y
sec
sbc #VISIBILITY_RADIUS
cmp #32
bcc @no_oob_y
lda #$00
@no_oob_y:
sta draw_buffer_y
sta get_tile_y
ldy #31 ; max tiles in x
lda get_tile_x
jsr verify_draw_buffer
sta temp ; store in temp
ldy #VISIBILITY_RADIUS*2
@draw_loop:
tya
pha
; first find out what address offset is needed to start
ldy temp ; holds max x-coordinate
jsr get_row
jsr draw_row
inc draw_buffer_y
inc get_tile_y
lda #$00
sta draw_buffer_len
ldy #30
cpy get_tile_y
beq @done ; out of bounds
pla
tay
dey
bne @draw_loop
rts
@done:
pla
rts
; gets a row of tiles from level_data
; inputs:
; get_x and get_y -> start tile
; y -> amount of bytes to load
; returns:
; fills draw_buffer with a row of tiles
get_row:
sty draw_buffer_len
jsr set_up_get_tile_address
ldy draw_buffer_len
@load_loop:
lda (src_ptr), y
sta draw_buffer, y
dey
cpy #$FF
bne @load_loop
inc draw_buffer_len
rts
; gets a col of tiles from level_data
; inputs:
; get_x and get_y -> start tile
; y -> amount of bytes to load into buffer
; returns:
; fills draw_buffer with a col of tiles
get_col:
sty draw_buffer_len
iny
sty temp ; needed for loop comparison
jsr set_up_get_tile_address
txa
pha ; save x value
ldx #$00
ldy #$00
@load_loop:
lda (src_ptr), y
sta draw_buffer, x
; 16 bit add for next address
lda src_ptr
clc
adc #32 ; 32 tiles per row
sta src_ptr
lda src_ptr+1
adc #$00 ; carry
sta src_ptr+1
inx
cpx temp
bne @load_loop
pla ; restore x value
tax
inc draw_buffer_len
rts
; this sub routine simply sets up
; the pointers for get_col and get_row
; inputs:
; get_tile_y and _x
; returns:
; src_ptr pointing to level_data + x and y coordinates
set_up_get_tile_address:
; get the address at x, y
ldy get_tile_y
lda tile_update_table_lo, y
clc
adc get_tile_x
sta src_ptr ; src ptr is used as ptr buffer
lda tile_update_table_hi, y
adc level_ptr+1
sta src_ptr+1
rts
; this sub routine sets up ppu for
; row/col updates
; inputs:
; draw_buffer_x, _y
; side effects:
; sets ppu address to corresponding values
set_up_get_tile_ppu:
lda $2002 ; read PPU status to reset the high/low latch
lda #$20 ; $2000 = start of ppu address
cpx #$01
bne @no_add
; if nt is 0 we dont need to change the address
clc
adc #$04 ; add 4 to get start address of nt1
@no_add:
ldy draw_buffer_y
clc
adc tile_update_table_hi, y
sta $2006
lda tile_update_table_lo, y
clc
adc draw_buffer_x
sta $2006 ; set up ppu for level transfer
rts
; draws a row of tiles
; inputs:
; x -> decides start address for nametable
; draw_buffer_x and draw_buffer_y -> start tile
; draw_buffer -> the tiles to draw (size = 2*VISIBILITY_RADIUS)
draw_row:
jsr set_up_get_tile_ppu
ldy #$00
@draw_loop:
lda draw_buffer, y
sta $2007
iny
cpy draw_buffer_len
bne @draw_loop
rts
; draws a col of tiles
; inputs:
; x -> decides start address for nametable
; draw_buffer_x and draw_buffer_y -> start tile
; draw_buffer -> the tiles to draw (size = 2*VISIBILITY_RADIUS)
draw_col:
lda #%00000100 ; col mode
sta $2000
jsr draw_row
lda #$00
sta $2000
rts
; draws a single hex buffer
; inputs:
; x -> decides nametable start address
; get_tile_x and get_tile_t -> start tile
; hex_buffer -> the number to draw
draw_hex_buffer:
lda $2002 ; read PPU status to reset the high/low latch
lda #$20 ; $2000 = start of ppu address
cpx #$01
bne @no_add
; if nt is 0 we dont need to change the address
clc
adc #$04 ; add 4 to get start address of nt1
@no_add:
ldy get_tile_y
clc
adc tile_update_table_hi, y
sta $2006
lda tile_update_table_lo, y
clc
adc get_tile_x
sta $2006 ; set up ppu for level transfer
lda hex_buffer+1
sta $2007
lda hex_buffer
sta $2007
rts
; sets a single tile
; inputs:
; x -> decides nametable start address
; get_tile_x and get_tile_t -> start tile
; a -> the tile
set_tile:
pha
lda $2002 ; read PPU status to reset the high/low latch
lda #$20 ; $2000 = start of ppu address
cpx #$01
bne @no_add
; if nt is 0 we dont need to change the address
clc
adc #$04 ; add 4 to get start address of nt1
@no_add:
ldy get_tile_y
clc
adc tile_update_table_hi, y
sta $2006
lda tile_update_table_lo, y
clc
adc get_tile_x
sta $2006 ; set up ppu for level transfer
pla
; sets a single tile skipping the ppu setup
set_tile_immediate:
sta $2007
rts
; this sub routine updates an attribute at the
; player's x/y position
; the chosen value is the player's tile index
; inputs:
; get_tile_x and get_tile_y location
; a -> attr value
; x -> nametable (TODO)
; side effects:
; updates ppu memory for nametable 0
; modfies registers and flags
; TODO make a color select register
; that counts from 0-3
; based on that and player location we can AND
; the correct value by reading ppu back and then writing again
; can use lookup table for every possible combination of location, amount
; of shifts and where to write to
set_attr:
pha
; temp holds pointer to ppu ram
lda #$C0
sta temp
lda #$23
sta temp+1
ldx get_tile_y
lda attr_update_table_y, x
clc
adc temp
sta temp
ldx get_tile_x
lda attr_update_table_x, x
clc
adc temp
sta temp
lda $2002 ; read PPU status to reset the high/low latch
; lda #$00
; sta $2005
; sta $2005 ; no scrolling
lda temp+1 ; write temp to ppu as start address
sta $2006
lda temp
sta $2006 ; set up ppu for tile transfer
; lda attr_value
pla
sta $2007 ; store in ppu
; no scrolling
lda #$00
sta $2005
sta $2005
rts
; loads menu background into nametable 1
; inputs:
; x -> menu type (same as game mode), sets up level_ptr
; side effects:
; changes registers
; overwrites level_ptr with a menu
; changes level data to menu (since it decompresses the level itself)
; therefore it should always be called before loading an actual level!
load_menu:
cpx #GAME_MODE_EDITOR_MENU
bne @not_editor
; load editor menu compressed tiles
lda #<editor_menu_gfx
sta level_data_ptr
lda #>editor_menu_gfx
sta level_data_ptr+1
; decompress location, same as level
lda #<level_data
sta level_ptr
lda #>level_data
sta level_ptr+1
jsr decompress_level
ldx #$01 ; load into nametable 1
jsr load_level
rts
@not_editor:
cpx #GAME_MODE_MENU
bne @not_main
; load editor menu compressed tiles
lda #<main_menu_gfx
sta level_data_ptr
lda #>main_menu_gfx
sta level_data_ptr+1
; decompress location, same as level
lda #<level_data
sta level_ptr
lda #>level_data
sta level_ptr+1
jsr decompress_level
ldx #$01 ; load into nametable 1
jsr load_level
rts
@not_main:
cpx #GAME_MODE_MESSAGE
bne @not_message
; load win menu compressed tiles
lda #<win_gfx
sta level_data_ptr
lda #>win_gfx
sta level_data_ptr+1
; copy palette early to avoid flickering
lda #<win_pal
sta palette_ptr
lda #>win_pal
sta palette_ptr+1
jsr load_palette
; decompress location, same as level
lda #<level_data
sta level_ptr
lda #>level_data
sta level_ptr+1
lda #<win_attr
sta attr_ptr
lda #>win_attr
sta attr_ptr+1
jsr decompress_level
jsr load_attr
ldx #$01 ; load into nametable 1
jsr load_level
rts
@not_message:
cpx #GAME_MODE_TITLE
bne @not_title
; copy palette early to avoid flickering
lda #<title_pal
sta palette_ptr
lda #>title_pal
sta palette_ptr+1
jsr load_palette
; load win menu compressed tiles
lda #<title_gfx
sta level_data_ptr
lda #>title_gfx
sta level_data_ptr+1
; decompress location, same as level
lda #<level_data
sta level_ptr
lda #>level_data
sta level_ptr+1
lda #<title_attr
sta attr_ptr
lda #>title_attr
sta attr_ptr+1
jsr decompress_level
jsr load_attr
ldx #$01 ; load into nametable 1
jsr load_level
rts
@not_title:
cpx #GAME_MODE_GAME_OVER
bne @not_game_over
; copy palette
lda #<game_over_pal
sta palette_ptr
lda #>game_over_pal
sta palette_ptr+1
jsr load_palette
; load win menu compressed tiles
lda #<game_over_gfx
sta level_data_ptr
lda #>game_over_gfx
sta level_data_ptr+1
; decompress location, same as level
lda #<level_data
sta level_ptr
lda #>level_data
sta level_ptr+1