-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrfk.asm
2894 lines (2640 loc) · 138 KB
/
rfk.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
.inesprg 2 ; 1x 16KB PRG code
.ineschr 1 ; 1x 8KB CHR data
.inesmap 0 ; mapper 0 = NROM, no bank swapping
.inesmir 1 ; background mirroring
;;;;;;;;;;;;;;;
;; DECLARE SOME VARIABLES HERE
.rsset $0000 ;;start variables at ram location 0
gamestate .rs 1 ; .rs 1 means reserve one byte of space
buttons1 .rs 1 ; player 1 gamepad buttons, one bit per button
buttons2 .rs 1 ; player 2 gamepad buttons, one bit per button
nmicounter .rs 1 ; constant NMI counter for rng seeding purposes
titledrawn .rs 1 ; Has the title screen been drawn yet?
nkis .rs 1 ; Count of non-kitten-objects
nkiones .rs 1 ; ones digit of NKIs for title screen
nkitens .rs 1 ; tens digit of NKIs for title screen
lockup .rs 1 ; Lock the up direction
lockdown .rs 1 ; Lock the down direction
lockright .rs 1 ; Lock the right direction
lockleft .rs 1 ; Lock the left direction.
multtemp .rs 1 ; Temp storage for multiplication
checkx .rs 1 ; x position for movement checking
checky .rs 1 ; y position for movement checking
founditem .rs 1 ; nki/kitten id bumped into
tmpx .rs 1; nki checking storage
tmpy .rs 1; nki checking storage
rngbuf .rs 14; buffer to make rng0 $0020
rng0 .rs 1; random number generator output
rng1 .rs 1; random number generator output
rng2 .rs 1; random number generator output
rng3 .rs 1; random number generator output
rng4 .rs 1; random number generator output
rng5 .rs 1; random number generator output
rng6 .rs 1; random number generator output
rng7 .rs 1; random number generator output
rng8 .rs 1; temp byte for rng manipulation
rngbuf2 .rs 7; 0020 for rng only
stringlist .rs 1 ; Which string list to use.
stringitself .rs 1; Which string to use
nkistrings .rs 63 ; Assign a string to the nki
nkislist .rs 63 ; Assign a list to the nki
linebuffer .rs 96 ; Took too long to do the conversion on the fly. So we're doing this.
displayingline .rs 1 ; Are we displaying a line? Lock out everything if we are.
buffertemp .rs 1 ; Using to tighten up the buffer display loop.
gameovercounter .rs 1 ; Counting gameover NMIs
gameoverstage .rs 1 ; Keeping track of what state we're in with the gameover animation.
;; DECLARE SOME CONSTANTS HERE
STATETITLE = $00 ; displaying title screen
STATEPLAYING = $01 ; move paddles/ball, check for collisions
STATEGAMEOVER = $02 ; displaying game over screen
MOVEDELAY = $1A ; NMI between moves
; Button codes and combinations
BUTRIGHT =$1
BUTLEFT =$2
BUTDOWN =$4
BUTUP =$8
BUTSTART =$10
BUTSELECT =$20
BUTB =$40
BUTA =$80
;;;;;;;;;;;;;;;;;;
; start with bank 0
.bank 0
; indirect addressing must be in the zero page
.org $0080
addrLO: .db 0 ; make "variable"s for our indirect addressing
addrHI: .db 0
; Our real bank 0 starts here
.org $8000
RESET:
SEI ; disable IRQs
CLD ; disable decimal mode
LDX #$40
STX $4017 ; disable APU frame IRQ
LDX #$FF
TXS ; Set up stack
INX ; now X = 0
STX $2000 ; disable NMI
STX $2001 ; disable rendering
STX $4010 ; disable DMC IRQs
vblankwait1: ; First wait for vblank to make sure PPU is ready
BIT $2002
BPL vblankwait1
clrmem:
TXA
AND #$F0
CMP #$20
BEQ clrmem2 ; skip 0020s (rng)
LDA #$00
STA $0000, x
clrmem2:
LDA #$00
STA $0100, x
STA $0300, x
STA $0400, x
STA $0500, x
STA $0600, x
STA $0700, x
LDA #$FE
STA $0200, x
INX
BNE clrmem
vblankwait2: ; Second wait for vblank, PPU is ready after this
BIT $2002
BPL vblankwait2
LoadPalettes:
LDA $2002 ; read PPU status to reset the high/low latch
LDA #$3F
STA $2006 ; write the high byte of $3F00 address
LDA #$00
STA $2006 ; write the low byte of $3F00 address
LDX #$00 ; start out at 0
LoadPalettesLoop:
LDA palette, x ; load data from address (palette + the value in x)
; 1st time through loop it will load palette+0
; 2nd time through loop it will load palette+1
; 3rd time through loop it will load palette+2
; etc
STA $2007 ; write to PPU
INX ; X = X + 1
CPX #$20 ; Compare X to hex $10, decimal 16 - copying 16 bytes = 4 sprites
BNE LoadPalettesLoop ; Branch to LoadPalettesLoop if compare was Not Equal to zero
; if compare was equal to 32, keep going down
JSR first_seed
;;:Set starting game state. We want to start at title
LDA #STATETITLE
STA gamestate
LDA #$20 ; Default number of nkis
STA nkis
;JSR turn_screen_on
LDA #%10010000 ; enable NMI, sprites from Pattern Table 0, background from Pattern Table 1
STA $2000
LDA #%00011110 ; enable sprites, enable background, no clipping on left side
STA $2001
Forever:
JMP Forever ;jump back to Forever, infinite loop, waiting for NMI
NMI:
STA tmpx
LDA #$00
STA $2003 ; set the low byte (00) of the RAM address
LDA #$02
STA $4014 ; set the high byte (02) of the RAM address, start the transfer
LDA displayingline
BNE skipnmi
JSR random_number ; for randomness
;;This is the PPU clean up section, so rendering the next frame starts properly.
;LDA #%10010000 ; enable NMI, sprites from Pattern Table 0, background from Pattern Table 1
;STA $2000
;LDA #%00011110 ; enable sprites, enable background, no clipping on left side
;STA $2001
;;;all graphics updates done by here, run game engine
JSR ReadController1 ;;get the current button data for player 1
JSR ReadController2 ;;get the current button data for player 2
INC nmicounter
GameEngine:
LDA gamestate
CMP #STATETITLE
BEQ EngineTitle ;;game is displaying title screen
LDA gamestate
CMP #STATEGAMEOVER
BNE dj1
JMP EngineGameOver ;;game is displaying ending screen
dj1:
LDA gamestate
CMP #STATEPLAYING
BNE dj2
LDA #$DE
STA $0500
JMP EnginePlaying ;;game is playing
dj2:
GameEngineDone:
JSR UpdateSprites ;;set ball/paddle sprites from positions
skipnmi:
LDA tmpx
RTI ; return from interrupt
;;;;;;;;
first_seed:
LDA #0
CMP rng0
BNE first_seed_end
CMP rng1
BNE first_seed_end
CMP rng2
BNE first_seed_end
CMP rng3
BNE first_seed_end
LDA #$FF
CMP rng4
BNE first_seed_end
CMP rng5
BNE first_seed_end
CMP rng6
BNE first_seed_end
CMP rng7
BNE first_seed_end
;;;Set some initial ball stats
; seed rng
LDA #$69
STA rng0
LDA #$00
STA rng1
LDA #$34
STA rng2
LDA #$56
STA rng3
LDA #$78
STA rng4
LDA #$9A
STA rng5
LDA #$BC
STA rng6
LDA #$DF
STA rng7
first_seed_end:
RTS
EngineTitle:
LDA titledrawn ; Check to see if the title is done displaying. If not, keep going, otherwise skip the drawing.
BNE DoneDisp
LDA $2002 ; read PPU status to reset the high/low latch to high
LDA #$3F
STA $2006 ; write the high byte of $3F10 address
LDA #$1D
STA $2006 ; write the low byte of $3F10 address
LDA #$2D
STA $2007
LDA #$00
;STA $2005
;STA $2005
JSR turn_screen_off
;LDX #$40
;STX $4017 ; disable APU frame IRQ
;LDX #$FF
;TXS ; Set up stack
;INX ; now X = 0
;STX $2000 ; disable NMI
;STX $2001 ; disable rendering
;STX $4010 ; disable DMC IRQs
ldx #0
lda #$20 ; set the destination address in PPU memory
sta $2006 ; should be $2000
stx $2006
lda #low(title) ; put the high and low bytes of the address "title"
sta addrLO ; into the variables so we can use indirect addressing.
lda #high(title)
sta addrHI
ldx #4 ; number of 256-byte chunks to load
ldy #0
bgloop:
lda [addrLO],y
sta $2007 ; load 256 bytes
iny
bne bgloop
;--------------------
inc addrHI ; increment high byte of address title to next 256 byte chunk
dex ; one chunk done so X = X - 1.
bne bgloop ; if X isn't zero, do again
jsr turn_screen_on
lda #$01
sta titledrawn
DoneDisp:
LDA #$00 ;;tell the ppu there is no background scrolling
STA $2005
STA $2005
; We're done displaying the title. Start polling for the buttons to increase/decrease nkis and start to start
LDA buttons1
AND #BUTSTART
BEQ NoStart
LDA #STATEPLAYING
STA gamestate
; seed rng
;LDA nmicounter
JSR clear_screen
JSR SpriteSetup
JSR nkiPageSel
;LDA #$20 ; static kitteh for testing
;STA $0205 ; kitteh tile
;LDA #3 ; kitteh palette
;STA $0206 ; kitteh tile
JMP GameEngineDone
; Start not pushed, check for up and increment nkis if need be
NoStart:
LDA buttons1
AND #BUTUP
BEQ NoUp
LDA nmicounter
AND #%00000111
BNE NoUp
INC nkis
LDA nkis
CMP #$40 ; Prevent nkis from going over 63.
BNE notmax
LDA #$3F
STA nkis
notmax:
; Up not pushed, decrement nkis
NoUp:
LDA buttons1
AND #BUTDOWN
BEQ NoDown
LDA nmicounter
AND #%00000111
BNE NoDown
DEC nkis
LDA nkis
CMP #$00 ; Prevent nkis from going below 0 (underflow to 255)
BNE notmin
LDA #$01
STA nkis
notmin:
; Down not pushed, go on with life.
NoDown:
LDX #$00
STX nkiones ; Blank out ones temp
STX nkitens ; Blank out tens temp
; Routine to convert the hex nkis to decimal output for the screen display.
IncOnes:
INX
CPX nkis
BEQ IncDone
LDA nkiones
CLC
ADC #$01
STA nkiones
CMP #$0A
BEQ IncTens
JMP IncOnes
IncTens:
LDA #$00
STA nkiones
LDA nkitens
CLC
ADC #$01
STA nkitens
JMP IncOnes
IncDone:
LDA nkiones
STA nkiones
LDA nkitens
STA nkitens
LDA #$8F
STA $0200
LDA nkitens
CLC
ADC #$10
STA $0201
LDA #%00000011
STA $0202
LDA #$A4
STA $0203
LDA #$8F
STA $0204
LDA nkiones
CLC
ADC #$10
; Write the values to the sprites in the right spot.
STA $0205
LDA #%00000011
STA $0206
LDA #$AC
STA $0207
JMP GameEngineDone
;;;;;;;;;
;;; GAMEOVERNMI HERE
EngineGameOver:
LDA gameoverstage
CMP #$0A
BEQ animdone
INC gameovercounter
LDA gameovercounter
CMP #$40
BEQ incgameoverstage
JMP nostage
incgameoverstage:
INC gameoverstage
LDA #00
STA gameovercounter
nostage:
LDA gameoverstage
CMP #$01
BNE nostep1
JMP step1
nostep1:
CMP #$03
BNE nostep2
JMP step2
nostep2:
CMP #$05
BNE nostep3
JMP step3
nostep3:
CMP #$07
BNE nostep4
JMP step4
nostep4:
CMP #$09
BNE nostep5
JMP step5
nostep5:
step6:
JMP SkipHere
animdone:
; Checking for Start pushed
LDA buttons1
AND #BUTSTART
BEQ NoGOStart
LDA #$01
STA multtemp
JMP SkipHere
NoGOStart:
; Once start pushed and then released, return to title screen.
LDA multtemp
BEQ SkipHere
JMP RESET
; Win/game over will go here.
SkipHere:
JMP GameEngineDone
;;;;;;;;;;;
EnginePlaying:
; mark current position
LDA $0200
STA checky
LDA $0203
STA checkx
;LDA $2002 ; read PPU status to reset the high/low latch to high
;LDA #$3F
;STA $2006 ; write the high byte of $3F10 address
;LDA #$1D
;STA $2006 ; write the low byte of $3F10 address
;LDA #$11
;STA $2007
;-------------------UP--------------------------
LDA buttons1
AND #BUTUP
BEQ NoRUp
LDA lockup
CMP #0
BNE NoRUpLocked
LDA $0200
; CMP #$27
; BEQ NoRUpLocked
SEC
SBC #$08 ; Actually reducing the location
; A contains destination y
STA checky
; STA $0200
LDA #MOVEDELAY ;
STA lockup
JMP NoRUpLocked
NoRUp:
LDA #$00
STA lockup
JMP RDown
NoRUpLocked:
LDA lockup
SEC
SBC #1
STA lockup
;-------------------DOWN------------------------
RDown:
LDA buttons1
AND #BUTDOWN
BEQ NoRDown
LDA lockdown
CMP #0
BNE NoRDownLocked
LDA $0200
; CMP #$DF
; BEQ NoRDownLocked
CLC
ADC #$08
; A contains destination y
STA checky
; STA $0200
LDA #MOVEDELAY
STA lockdown
JMP NoRDownLocked
; JMP GameEngineDone
NoRDown:
LDA #$00
STA lockdown
JMP RRight
NoRDownLocked:
LDA lockdown
SEC
SBC #1
STA lockdown
;-------------------RIGHT-----------------------
RRight:
LDA buttons1
AND #BUTRIGHT
BEQ NoRRight
LDA lockright
CMP #0
BNE NoRRightLocked
LDA $0203
; CMP #$F8
; BEQ NoRRightLocked
CLC
ADC #$08
STA checkx
; STA $0203
LDA #MOVEDELAY
STA lockright
; JMP GameEngineDone
JMP NoRRightLocked
NoRRight:
LDA #$00
STA lockright
JMP RLeft
NoRRightLocked:
LDA lockright
SEC
SBC #1
STA lockright
;-------------------LEFT------------------------
RLeft:
LDA buttons1
AND #BUTLEFT
BEQ NoRLeft
LDA lockleft
CMP #0
BNE NoRLeftLocked
LDA $0203
; CMP #$00
; BEQ NoRLeftLocked
SEC
SBC #$08
STA checkx
; STA $0203
LDA #MOVEDELAY
STA lockleft
; JMP GameEngineDone
JMP NoRLeftLocked
NoRLeft:
LDA #$00
STA lockleft
JMP RChecks
NoRLeftLocked:
LDA lockleft
SEC
SBC #1
STA lockleft
RChecks:
LDA checkx
CMP $0203
BNE CheckControls
LDA checky
CMP $0200
BNE CheckControls
JMP EndControls
CheckControls:
JSR CheckBoundsAndCollisions
EndControls:
JMP GameEngineDone
CheckBoundsAndCollisions:
; Lower Bounds
LDA checkx
CMP #$00 ; x minimum
BEQ CBACCchecky ; on the line is in
BCC EndOfCheckBounds ; not possible when xmin is 0
CBACCchecky:
LDA checky
CMP #$28
BEQ CBACCcheckupy
BCC EndOfCheckBounds
CBACCcheckupy:
; UpperBounds
CMP #$D9
BEQ CBACCcheckupx
BCS EndOfCheckBounds
CBACCcheckupx:
LDA checkx
CMP #$F8
BEQ CBACCLoopSetup
BCS EndOfCheckBounds
CBACCLoopSetup:
; Collisions
LDX #0 ; compare vs nkis
LDY #0 ; increases by 4 per nki loop
CBACCLoop:
; loop through all nkis, checking y then x and bailing with a double match.
CPX nkis
BEQ CheckedOutCanMove
LDA checky
CMP $0204,y
BEQ CBACCyMatch
JMP CBACCNoMatch
CBACCyMatch:
LDA checkx
CMP $0207,y
BEQ FoundMatch
CBACCNoMatch:
;doesn't match, increment and loop
INX
INY
INY
INY
INY
JMP CBACCLoop
FoundMatch:
; X = item which might be kitten
STX founditem
;STX $D0
JMP HandleItem
CheckedOutCanMove:
; move robot here, to checkx,checky
LDA checky
STA $0200
LDA checkx
STA $0203
EndOfCheckBounds:
RTS
HandleItem:
; display message correlating with X register'd item
LDA founditem
CMP #0 ; kitten!
BEQ GameOver
JSR DispLine
RTS
GameOver:
; Blank out line for displaying win animation
; JSR LineBlank
LDA #$01
STA displayingline
LDA #$20
STA buffertemp
LDY #$00
JSR LineStart
LDA $2002 ; read PPU status to reset the high/low latch
LDA #$23
STA $2006 ; write the high byte of $23C0 address
LDA #$C0
STA $2006 ; write the low byte of $23C0 address
;LDA #%01010101
LDX $0206
LDA #$00
CPX #$00
BEQ KittenColor
DEX
LDA #$55
CPX #$00
BEQ KittenColor
DEX
LDA #$AA
CPX #$00
BEQ KittenColor
LDA #$FF
KittenColor:
STA $2007
STA $2007 ; write to PPU
STA $2007 ; write to PPU
STA $2007 ; write to PPU
STA $2007 ; write to PPU
STA $2007 ; write to PPU
STA $2007 ; write to PPU
STA $2007 ; write to PPU
;LDA $2002 ; read PPU status to reset the high/low latch to high
LDA #$3F
STA $2006 ; write the high byte of $3F10 address
LDA #$0D
STA $2006 ; write the low byte of $3F10 address
LDA #$13
STA $2007
LDA #$00
STA multtemp
STA gameoverstage
STA gameovercounter
LDA #STATEGAMEOVER
STA gamestate
GameOverLock:
JMP GameOverLock ; forever FIXME
UpdateSprites:
; Updating robot sprite
;;update paddle sprites
RTS
ReadController1:
LDA #$01
STA $4016
LDA #$00
STA $4016
LDX #$08
ReadController1Loop:
LDA $4016
LSR A ; bit0 -> Carry
ROL buttons1 ; bit0 <- Carry
DEX
BNE ReadController1Loop
RTS
ReadController2:
LDA #$01
STA $4016
LDA #$00
STA $4016
LDX #$08
ReadController2Loop:
LDA $4017
LSR A ; bit0 -> Carry
ROL buttons2 ; bit0 <- Carry
DEX
BNE ReadController2Loop
RTS
turn_screen_on:
; Setup the PPU
;LDA #%10010111 ; enable NMI, sprites from Pattern Table 0, background from Pattern Table 1
LDA #%10000000 ; enable NMI, sprites from Pattern Table 0, background from Pattern Table 1
STA $2000
LDA #%00011110 ; enable sprites, enable background, no clipping on left side
STA $2001
rts
turn_screen_off:
LDX #$00 ; now X = 0
STX $2000 ; disable NMI
STX $2001 ; disable rendering
STX $4010 ; disable DMC IRQs
rts
clear_screen:
BIT $2002
BNE clear_screen
LDA $2002 ; read PPU status to reset the high/low latch to high
LDA #$3F
STA $2006 ; write the high byte of $3F10 address
LDA #$1D
STA $2006 ; write the low byte of $3F10 address
LDA #$12
STA $2007
ldx #0
lda #$20 ; set the destination address in PPU memory
sta $2006 ; should be $2000
stx $2006
jsr turn_screen_off
ldx #4 ; number of 256-byte chunks to load
ldy #0
clrloop:
lda #$00
sta $2007 ; load 256 bytes
iny
bne clrloop
;--------------------
dex ; one chunk done so X = X - 1.
bne clrloop ; if X isn't zero, do again
; Reset the Attribute table for strings
LoadAttribute:
LDA $2002 ; read PPU status to reset the high/low latch
LDA #$23
STA $2006 ; write the high byte of $23C0 address
LDA #$C0
STA $2006 ; write the low byte of $23C0 address
LDX #$00 ; start out at 0
LDA #%11111111
LoadAttributeLoop:
STA $2007 ; write to PPU
INX ; X = X + 1
CPX #$40 ; Compare X to hex 64. Copying lots of bytes.
BNE LoadAttributeLoop
jsr turn_screen_on
RTS
;;;;;;;;;;;;;;
SpriteSetup:
jsr turn_screen_off
CLC
roby:
JSR random_number
AND #$F8 ; (multiples of 8)
;AND #$38 ; (for testing)
STA $0200
CLC
ADC #$29 ; Y-offset 1 pixel + one tile width (drawing from the bottom left) + 3 tile widths for info
BCS roby ; -- >FF is a rejection; could handle here or earlier with another CMP
CMP #$D7 ; limit to usable tiles (y cutoff)
BCS roby
;ADC #$28
;CLC
;ADC #1 ; y offset
STA $0200
LDA #$B0
STA $0201
LDA #$00
STA $0202
CLC
robx:
JSR random_number
AND #$F8 ; reduce random bits to 0-31
CMP #$F1 ; x cutoff
BCS robx
STA $0203
;CMP #$1f ; n8-- = xmax? was $17 (ymax?)
;BCS robx
; LDX #$07
;xmult:
; ADC $0203
; DEX
; CPX #$00
; BNE xmult
; ROL $0203
; ROL $0203
; ROL $0203
;SBC #$0E
;CLC
;ADC #2 ; x adjustment
;STA $0203
LDX #$00
LDY #$00
RandSpritesLoop:
;LDA #$AD
;STA $0503
nkiy:
CLC
JSR random_number
;STA $0164,x -- debug logging in memory
AND #$F8 ; (multiples of 8)
;STA $0165,x -- debug logging in memory
CLC
ADC #$29 ; Y-offset 1 pixel + one tile width (drawing from the bottom left) + 3 tile widths for info
BCS nkiy ; -- >FF is a rejection; could handle here or earlier with another CMP
CMP #$D7 ; limit to usable tiles (y cutoff)
BCS nkiy
STA $0204,x ; y coord
nkiTile:
JSR random_number
AND #$7F
BEQ nkiTile ; no zeros
CMP #$03
BNE nkiTileRow
CLC
ADC #1 ; fix #'s to $'s
nkiTileRow:
STA $0205,x ; tile number
AND #$70
CMP #$70 ; make row 7 row 6
BNE nkiGotTile
LDA $0205,x
AND #$6F
STA $0205,x ; tile number
nkiGotTile:
JSR random_number
;LDA #$00
AND #03 ; random palette
STA $0206,x ; attributes
nkix:
CLC
JSR random_number
SEC
SBC #1 ; range should really be 0-254 than 1-255
;STA $0160,x ; debug
AND #$F8
;STA $0161,x ; debug
;CLC
;ADC #$1 ; one pixel
;STA $0162,x ; debug
;BCS nkix
CMP #$F1 ; x cutoff
BEQ nkix0