-
-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathvideo.asm
1424 lines (1381 loc) · 23.9 KB
/
video.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
PALETTE_CACHE .rs 32 ; temporary memory for palette, for dimming
; cursors target coordinates
SPRITE_0_X_TARGET .rs 1
SPRITE_1_X_TARGET .rs 1
SPRITE_Y_TARGET .rs 1
; variables for game name drawing
TEXT_DRAW_GAME .rs 2
TEXT_DRAW_ROW .rs 1
SCROLL_LINES .rs 2 ; current scroll line
SCROLL_LINES_MODULO .rs 1 ; current scroll line % 30
LAST_LINE_MODULO .rs 1
LAST_LINE_GAME .rs 2
SCROLL_FINE .rs 1 ; fine scroll position
SCROLL_LINES_TARGET .rs 2 ; scrolling target
STAR_SPAWN_TIMER .rs 1 ; stars spawn timer
STAR_SPAWN_COUNTER .rs 1 ; stars spawn counter
; for build info
CHR_RAM_SIZE .rs 1 ; CHR RAM size 8*2^xKB
LAST_ATTRIBUTE_ADDRESS .rs 1 ; to prevent duplicate writes
SCHEDULE_PRINT_FIRST .rs 1
SCHEDULE_PRINT_LAST .rs 1
; flag to lock scrolling at zero
SCROLL_LOCK .rs 1
; flag that save warning message is active
SAVE_WARNED .rs 1
; constants
CHARS_PER_LINE .equ 32
LINES_PER_SCREEN .equ 15
SPRITE_0_Y .equ SPRITES + 0
SPRITE_0_TILE .equ SPRITES + 1
SPRITE_0_ATTR .equ SPRITES + 2
SPRITE_0_X .equ SPRITES + 3
SPRITE_1_Y .equ SPRITES + 4
SPRITE_1_TILE .equ SPRITES + 5
SPRITE_1_ATTR .equ SPRITES + 6
SPRITE_1_X .equ SPRITES + 7
waitblank:
pha
tya
pha
txa
pha
bit PPUSTATUS ; reset vblank bit
.loop:
lda PPUSTATUS ; load A with value at location PPUSTATUS
bpl .loop ; if bit 7 is not set (not VBlank) keep checking
; updating sprites
jsr sprite_dma_copy
lda <SCHEDULE_PRINT_FIRST
beq .first_not_scheduled
jsr print_first_name
lda #0
sta <SCHEDULE_PRINT_FIRST
.first_not_scheduled:
lda <SCHEDULE_PRINT_LAST
beq .last_not_scheduled
jsr print_last_name
lda #0
sta <SCHEDULE_PRINT_LAST
.last_not_scheduled:
jsr scroll_fix
; scrolling
lda <SCROLL_LOCK
bne .skip_scrolling
jsr move_scrolling
.skip_scrolling:
; moving cursors
jsr move_cursors
; reading controller
jsr read_controller
; stars on the background
.if STARS!=0
jsr stars
.endif
pla
tax
pla
tay
pla
rts
waitblank_simple:
pha
bit PPUSTATUS
.loop:
lda PPUSTATUS ; load A with value at location PPUSTATUS
bpl .loop ; if bit 7 is not set (not VBlank) keep checking
pla
rts
waitblank_x:
; for for v-blank X times
cpy #0
bne .loop
rts
.loop:
jsr waitblank
dex
bne .loop
rts
scroll_fix:
pha
tya
pha
; scrolling reset
bit PPUSTATUS
; X coordinate always 0
lda #0
sta PPUSCROLL
ldy <SCROLL_LOCK
beq .need_to_scroll
; scolling is locked
sta PPUSCROLL
ldy #%00001000 ; first nametable
sty PPUCTRL ; set base nametable
jmp .scroll_done
.need_to_scroll:
lda <SCROLL_LINES_MODULO
cmp #LINES_PER_SCREEN
bcc .first_screen
sec
sbc #LINES_PER_SCREEN ; substracting otherwise
ldy #%00001010 ; second nametable
jmp .set_nametable
.first_screen:
ldy #%00001000 ; first nametable
.set_nametable:
sty PPUCTRL ; set base nametable
; calculating Y coordinate
asl A
asl A
asl A
asl A
clc
adc <SCROLL_FINE
sta PPUSCROLL
.scroll_done
pla
tay
pla
rts
scroll_line_down:
lda <SCROLL_LINES
clc
adc #1
sta <SCROLL_LINES
lda <SCROLL_LINES+1
adc #0
sta <SCROLL_LINES+1
inc <SCROLL_LINES_MODULO
lda <SCROLL_LINES_MODULO
cmp #LINES_PER_SCREEN * 2
bcc .modulo_ok
lda #0
sta <SCROLL_LINES_MODULO
.modulo_ok:
lda <LAST_LINE_GAME
clc
adc #1
sta <LAST_LINE_GAME
lda <LAST_LINE_GAME+1
adc #0
sta <LAST_LINE_GAME+1
inc <LAST_LINE_MODULO
lda <LAST_LINE_MODULO
cmp #LINES_PER_SCREEN * 2
bcc .modulo_ok2
lda #0
sta <LAST_LINE_MODULO
.modulo_ok2:
;jsr print_last_name
inc SCHEDULE_PRINT_LAST
rts
scroll_line_up:
lda <SCROLL_LINES
sec
sbc #1
sta <SCROLL_LINES
lda <SCROLL_LINES+1
sbc #0
sta <SCROLL_LINES+1
dec <SCROLL_LINES_MODULO
bpl .modulo_ok
lda #LINES_PER_SCREEN * 2 - 1
sta <SCROLL_LINES_MODULO
.modulo_ok:
lda <LAST_LINE_GAME
sec
sbc #1
sta <LAST_LINE_GAME
lda <LAST_LINE_GAME+1
sbc #0
sta <LAST_LINE_GAME+1
dec <LAST_LINE_MODULO
bpl .modulo_ok2
lda #LINES_PER_SCREEN * 2 - 1
sta <LAST_LINE_MODULO
.modulo_ok2:
;jsr print_first_name
inc SCHEDULE_PRINT_FIRST
rts
screen_wrap_down:
jsr wait_scroll_done
lda #0
sta <SELECTED_GAME
sta <SELECTED_GAME+1
lda #0
sta <SCROLL_LINES_TARGET
sta <SCROLL_LINES_TARGET+1
sta <SCROLL_LINES
sta <SCROLL_LINES+1
sta <LAST_LINE_GAME
sta <LAST_LINE_GAME+1
jsr set_cursor_targets
ldx #LINES_PER_SCREEN
.lines_loop
; draw lines and update screen
jsr waitblank_simple
jsr print_last_name
jsr sprite_dma_copy
jsr scroll_fix
jsr move_cursors
.if STARS!=0
jsr stars
.endif
cpx #0
beq .end
; increment everything
inc <SCROLL_LINES_MODULO
lda <SCROLL_LINES_MODULO
cmp #LINES_PER_SCREEN * 2
bcc .modulo_ok
lda #0
sta <SCROLL_LINES_MODULO
.modulo_ok:
inc <LAST_LINE_MODULO
lda <LAST_LINE_MODULO
cmp #LINES_PER_SCREEN * 2
bcc .modulo_ok2
lda #0
sta <LAST_LINE_MODULO
.modulo_ok2:
inc <LAST_LINE_GAME
; next line?
dex
jmp .lines_loop
.end:
rts
screen_wrap_up:
jsr wait_scroll_done
; some weird math
lda #LOW(GAMES_COUNT - 1)
sta <SELECTED_GAME
lda #HIGH(GAMES_COUNT - 1)
sta <SELECTED_GAME+1
lda #LOW(GAMES_COUNT + 4)
sta <SCROLL_LINES
lda #HIGH(GAMES_COUNT + 4)
sta <SCROLL_LINES+1
lda #LOW(GAMES_COUNT - 11)
sta <SCROLL_LINES_TARGET
lda #HIGH(GAMES_COUNT - 11)
sta <SCROLL_LINES_TARGET+1
lda #LOW(GAMES_COUNT + 4)
sta <LAST_LINE_GAME
lda #HIGH(GAMES_COUNT + 4)
sta <LAST_LINE_GAME+1
jsr set_cursor_targets
ldx #LINES_PER_SCREEN
.lines_loop:
; decrement everything
dec <SCROLL_LINES_MODULO
bpl .modulo_ok
lda #LINES_PER_SCREEN * 2 - 1
sta <SCROLL_LINES_MODULO
.modulo_ok:
dec <LAST_LINE_MODULO
bpl .modulo_ok2
lda #LINES_PER_SCREEN * 2 - 1
sta <LAST_LINE_MODULO
.modulo_ok2:
lda <SCROLL_LINES
sec
sbc #1
sta <SCROLL_LINES
lda <SCROLL_LINES+1
sbc #0
sta <SCROLL_LINES+1
; draw lines and update screen
jsr waitblank_simple
jsr print_first_name
jsr sprite_dma_copy
jsr scroll_fix
jsr move_cursors
.if STARS!=0
jsr stars
.endif
; next line?
dex
bne .lines_loop
rts
load_base_chr:
; loading CHR
lda #BANK(chr_data) / 2 ; bank with CHR
jsr select_prg_bank
lda #LOW(chr_data)
sta COPY_SOURCE_ADDR
lda #HIGH(chr_data)
sta COPY_SOURCE_ADDR+1
jsr load_chr
rts
preload_palette:
; loading palette into palette cache
ldy #0
.loop:
lda [COPY_SOURCE_ADDR], y
sta PALETTE_CACHE, y
iny
cpy #32
bne .loop
rts
preload_base_palette:
; loading palette into palette cache
lda #BANK(tilepal) / 2 ; bank with palette
jsr select_prg_bank
lda #LOW(tilepal)
sta COPY_SOURCE_ADDR
lda #HIGH(tilepal)
sta COPY_SOURCE_ADDR+1
jsr preload_palette
rts
; loading palette from cache to PPU
load_palette:
jsr waitblank_simple
lda #LOW(PALETTE_CACHE)
sta <COPY_SOURCE_ADDR
lda #HIGH(PALETTE_CACHE)
sta <COPY_SOURCE_ADDR+1
lda #$3F
sta $2006
lda #$00
sta $2006
ldy #$00
ldx #32
.loop:
lda [COPY_SOURCE_ADDR], y
sta $2007
iny
dex
bne .loop
jsr scroll_fix
rts
;load_base_pal:
; loading palette into $3F00 of PPU
;lda #$3F
;sta PPUADDR
;lda #$00
;sta PPUADDR
;ldx #$00
;.loop:
;lda tilepal, x
;sta PPUDATA
;inx
;cpx #32
;bne .loop
;rts
dim:
; dimming preloaded palette
ldx #0
.loop:
lda PALETTE_CACHE, x
sec
sbc #$10
bpl .not_minus
lda #$1D
.not_minus:
cmp #$0D
bne .not_very_black
lda #$1D
.not_very_black:
sta PALETTE_CACHE, x
inx
cpx #32
bne .loop
rts
; dimming base palette in
dim_base_palette_in:
;lda BUTTONS
;bne .done ; skip if any button pressed
.if ENABLE_DIM_IN!=0
.if DIM_IN_DELAY <= 0
.fail DIM_IN_DELAY must be > 0
.endif
jsr preload_base_palette
jsr dim
jsr dim
jsr dim
jsr load_palette
ldx #DIM_IN_DELAY
jsr waitblank_x
;lda BUTTONS
;bne .done ; skip if any button pressed
jsr preload_base_palette
jsr dim
jsr dim
jsr load_palette
ldx #DIM_IN_DELAY
jsr waitblank_x
;lda BUTTONS
;bne .done ; skip if any button pressed
jsr preload_base_palette
jsr dim
jsr load_palette
ldx #DIM_IN_DELAY
jsr waitblank_x
.endif
.done:
jsr preload_base_palette
jsr load_palette
jsr waitblank
rts
; dimming base palette out in
dim_base_palette_out:
.if ENABLE_DIM_OUT!=0
.if DIM_OUT_DELAY <= 0
.fail DIM_OUT_DELAY must be > 0
.endif
jsr preload_base_palette
jsr dim
jsr load_palette
ldx #DIM_OUT_DELAY
jsr waitblank_x
jsr preload_base_palette
jsr dim
jsr dim
jsr load_palette
ldx #DIM_OUT_DELAY
jsr waitblank_x
jsr preload_base_palette
jsr dim
jsr dim
jsr dim
jsr load_palette
ldx #DIM_OUT_DELAY
jsr waitblank_x
.endif
jsr load_black
jsr waitblank
rts
; loading empty black palette into $3F00 of PPU
load_black:
; waiting for vblank
; need even if rendering is disabled
; to prevent lines on black screen
jsr waitblank_simple
lda #$3F
sta PPUADDR
lda #$00
sta PPUADDR
ldx #$00
lda #$3F ; color
.loop:
sta PPUDATA
inx
cpx #32
bne .loop
rts
; nametable cleanup
clear_screen:
lda #$20
sta PPUADDR
lda #$00
sta PPUADDR
lda #$00
ldx #0
ldy #$10
.loop:
sta PPUDATA
inx
bne .loop
dey
bne .loop
rts
; clear all sprites data
clear_sprites:
lda #$FF
ldx #0
.loop:
sta SPRITES, x
inx
bne .loop
rts
; DMA sprites loading
sprite_dma_copy:
pha
lda #0
sta OAMADDR
lda #HIGH(SPRITES)
sta OAMDMA
pla
rts
; loading header (image on the top), first part
draw_header1:
lda #BANK(nametable_header) / 2 ; bank with header
jsr select_prg_bank
ldx #0
ldy #$40
.loop:
lda nametable_header, x
sta PPUDATA
inx
dey
bne .loop
rts
; loading header (image on the top), second part
draw_header2:
lda #BANK(nametable_header) / 2 ; bank with header
jsr select_prg_bank
ldx #$40
ldy #$40
.loop:
lda nametable_header, x
sta PPUDATA
inx
dey
bne .loop
rts
; loading footer (image on the bottom), first part
draw_footer1:
lda #$06
jsr select_prg_bank
ldx #0
ldy #$40
.loop:
lda nametable_footer, x
sta PPUDATA
inx
dey
bne .loop
rts
; loading footer (image on the bottom), second part
draw_footer2:
lda #$06
jsr select_prg_bank
ldx #$40
ldy #$40
.loop:
lda nametable_footer, x
sta PPUDATA
inx
dey
bne .loop
rts
; printing game name on the top
print_first_name:
pha
lda <SCROLL_LINES
sta <TEXT_DRAW_GAME
lda <SCROLL_LINES+1
sta <TEXT_DRAW_GAME+1
lda <SCROLL_LINES_MODULO
sta <TEXT_DRAW_ROW
jsr print_name
pla
rts
; printing game name on the bottom
print_last_name:
pha
lda <LAST_LINE_GAME
sta <TEXT_DRAW_GAME
lda <LAST_LINE_GAME+1
sta <TEXT_DRAW_GAME+1
lda <LAST_LINE_MODULO
sta <TEXT_DRAW_ROW
jsr print_name
pla
rts
print_name:
pha
tya
pha
txa
pha
; when there are not so many games we need offset
.if GAMES_COUNT <= 10
lda TEXT_DRAW_GAME
cmp #2
bcc .padding_end
cmp #(GAMES_COUNT + 2)
beq .padding_footer_1
cmp #(GAMES_COUNT + 3)
beq .padding_footer_2
lda <TEXT_DRAW_ROW
clc
adc #(6 - GAMES_COUNT / 2 - GAMES_COUNT % 2)
sta <TEXT_DRAW_ROW
jmp .padding_end
.padding_footer_1:
lda #13
sta <TEXT_DRAW_ROW
jmp .padding_end
.padding_footer_2:
lda #14
sta <TEXT_DRAW_ROW
.padding_end:
.endif
lda <TEXT_DRAW_ROW
; detecting target nametable and PPU address
cmp #LINES_PER_SCREEN
bcc .first_screen
; second
sec
sbc #LINES_PER_SCREEN
lsr A
lsr A
clc
adc #$2C
bit PPUSTATUS
sta PPUADDR
lda <TEXT_DRAW_ROW
sec
sbc #LINES_PER_SCREEN
asl A
asl A
asl A
asl A
asl A
asl A
sta PPUADDR
jmp .print_start
; first
.first_screen:
lsr A
lsr A
clc
adc #$20
bit PPUSTATUS
sta PPUADDR
lda <TEXT_DRAW_ROW
asl A
asl A
asl A
asl A
asl A
asl A
sta PPUADDR
.print_start:
; is it header lines?
lda <TEXT_DRAW_GAME+1
bne .not_header ; no
lda <TEXT_DRAW_GAME
beq .header1
cmp #1
beq .header2
jmp .not_header
.header1:
jsr draw_header1
jsr set_line_attributes
jmp .end
.header2:
jsr draw_header2
jsr set_line_attributes
jmp .end
.not_header:
; we need to substract 2 from game number
lda <TEXT_DRAW_GAME
sec
sbc #2
; store game number to TMP and TMP+1
sta <TMP
lda <TEXT_DRAW_GAME+1
sbc #0
sta <TMP+1
; is it footer?
lda <TMP+1
cmp #HIGH(GAMES_COUNT)
bne .not_footer_1
lda <TMP
cmp #LOW(GAMES_COUNT)
bne .not_footer_1
jsr draw_footer1
jsr set_line_attributes
jmp .end
.not_footer_1:
lda <TMP+1
cmp #HIGH(GAMES_COUNT + 1)
bne .not_footer_2
lda <TMP
cmp #LOW(GAMES_COUNT + 1)
bne .not_footer_2
jsr draw_footer2
jsr set_line_attributes
jmp .end
.not_footer_2:
lda <TMP
sec
sbc #LOW(GAMES_COUNT)
lda <TMP+1
sbc #HIGH(GAMES_COUNT)
bcs .end
lda <TMP+1
jsr select_prg_bank
lda #LOW(game_names)
clc
adc <TMP
sta <COPY_SOURCE_ADDR
lda #HIGH(game_names)
adc #0
sta <COPY_SOURCE_ADDR+1
; x2 (because address two bytes length)
lda <COPY_SOURCE_ADDR
clc
adc <TMP
sta <COPY_SOURCE_ADDR
lda <COPY_SOURCE_ADDR+1
adc #0
sta <COPY_SOURCE_ADDR+1
ldy #0
lda [COPY_SOURCE_ADDR], y
sta <TMP
iny
lda [COPY_SOURCE_ADDR], y
sta <COPY_SOURCE_ADDR+1
lda <TMP
sta <COPY_SOURCE_ADDR
; spaces on the left
ldx #GAME_NAMES_OFFSET+1
.print_blank:
lda #$00
sta PPUDATA
dex
bne .print_blank
; text
ldx #GAME_NAMES_OFFSET+1
ldy #0
lda #1
.next_char:
cmp #0 ; after zero we are not printing letters but printing spaces
beq .end_of_line
lda [COPY_SOURCE_ADDR], y
.end_of_line:
sta PPUDATA
iny
inx
cpx #CHARS_PER_LINE
bne .next_char
.print_name_end:
; clear second line
ldy #CHARS_PER_LINE
lda #0
.clear_2nd_line_loop:
sta PPUDATA
dey
bne .clear_2nd_line_loop
jsr set_line_attributes
.end:
pla
tax
pla
tay
pla
rts
set_line_attributes:
; maybe this line already drawned?
lda <TEXT_DRAW_ROW
and #%11111110
cmp <LAST_ATTRIBUTE_ADDRESS
bne .set_attribute_address
rts
.set_attribute_address:
lda #BANK(header_attribute_table) / 2
jsr select_prg_bank
; calculating attributes address
lda <TEXT_DRAW_ROW
cmp #LINES_PER_SCREEN
bcc .first_screen
; second nametable
lda #1
sta TMP ; remember nametable #
lda #$2F
sta PPUADDR
lda <TEXT_DRAW_ROW
sec
sbc #LINES_PER_SCREEN
jmp .nametable_detect_end
; first nametable
.first_screen:
lda #0
sta TMP ; remember nametable #
lda #$23
sta PPUADDR
lda <TEXT_DRAW_ROW
.nametable_detect_end:
; one byte for 4 rows
and #%11111110
asl A
asl A
clc
adc #$C0
sta <LAST_ATTRIBUTE_ADDRESS
sta PPUADDR
; now writing attributes, need to calculate them too
ldx #8
ldy #0
lda <TEXT_DRAW_GAME+1
cmp #HIGH(GAMES_COUNT + 3)
bne .not_footer
lda <TEXT_DRAW_GAME
cmp #LOW(GAMES_COUNT + 3)
beq .footer
jmp .maybe_header_or_game_0
.not_footer:
cmp #0
bne .only_text_attributes
.maybe_header_or_game_0:
lda <TEXT_DRAW_GAME+1
bne .only_text_attributes
lda <TEXT_DRAW_GAME
cmp #0
beq .header_0
cmp #1
beq .header_1
cmp #2
beq .game_0
jmp .only_text_attributes
.header_0
lda TEXT_DRAW_ROW
eor TMP
lsr A
bcc .only_header_attributes
.header_0_loop:
lda header_attribute_table, y
asl A
asl A
asl A
asl A
ora #$0F
sta PPUDATA
iny
dex
bne .header_0_loop
rts
.header_1
lda TEXT_DRAW_ROW
eor TMP
lsr A
bcs .only_header_attributes
.header_1_loop:
lda header_attribute_table, y
lsr A
lsr A
lsr A
lsr A
ora #$F0
sta PPUDATA
iny
dex
bne .header_1_loop
rts
.game_0:
lda TEXT_DRAW_ROW
eor TMP
lsr A
bcc .only_text_attributes
jmp .header_1_loop
.footer:
lda TEXT_DRAW_ROW
eor TMP
lsr A
bcs .only_text_attributes
jmp .header_0_loop
.only_header_attributes:
lda header_attribute_table, y
sta PPUDATA
iny
dex
bne .only_header_attributes
rts
.only_text_attributes:
lda #$FF
.only_text_attributes_loop:
sta PPUDATA
dex
bne .only_text_attributes_loop
rts
move_cursors:
pha
; fine cursor scrolling
lda <SPRITE_1_X_TARGET
cmp SPRITE_1_X
beq .sprite_1x_target_end
bcs .sprite_1x_target_plus
lda SPRITE_1_X
sec
sbc #4
sta SPRITE_1_X
jmp .sprite_1x_target_end
.sprite_1x_target_plus:
lda SPRITE_1_X
clc
adc #4
sta SPRITE_1_X
.sprite_1x_target_end:
lda <SPRITE_Y_TARGET
cmp SPRITE_0_Y
beq .sprite_0y_target_end
bcs .sprite_0y_target_plus
lda SPRITE_0_Y
sec
sbc #4
sta SPRITE_0_Y
.if ENABLE_RIGHT_CURSOR!=0
sta SPRITE_1_Y
.endif
jmp .sprite_0y_target_end
.sprite_0y_target_plus:
lda SPRITE_0_Y
clc
adc #4
sta SPRITE_0_Y
.if ENABLE_RIGHT_CURSOR!=0
sta SPRITE_1_Y
.endif
.sprite_0y_target_end:
pla
rts
; fine scrolling to target line
move_scrolling:
; determining scroll speed
lda <SCROLL_LINES
clc
adc #2
sta <TMP
lda <SCROLL_LINES+1
adc #0
sta <TMP+1
lda <SCROLL_LINES_TARGET
sec
sbc <TMP
lda <SCROLL_LINES_TARGET+1
sbc <TMP+1
bcs .move_scrolling_fast_down
lda <SCROLL_LINES_TARGET
clc
adc #2
sta <TMP
lda <SCROLL_LINES_TARGET+1
adc #0
sta <TMP+1
lda <SCROLL_LINES
sec
sbc <TMP
lda <SCROLL_LINES+1
sbc <TMP+1
bcs .move_scrolling_fast_up
; slow scrolling
jsr .move_scrolling_real
rts
; fast scrolling
.move_scrolling_fast:
jsr .move_scrolling_real
jsr .move_scrolling_real
jsr .move_scrolling_real
jsr .move_scrolling_real
rts
.move_scrolling_fast_up:
jmp scroll_line_up
.move_scrolling_fast_down: