Code: Select all
Rand:
LDA seed ; get seed
ASL A
BCC NoEOR ; branch if no carry
EOR #$CF ; else EOR with #$value
NoEOR:
STA seed ; save number as next seed
RTS
Code: Select all
LoadBackground:
LDA $2002 ; read PPU status to reset the high/low latch
LDA #$20
STA $2006 ; write the high byte of $2000 address
LDA #$00
STA $2006 ; write the low byte of $2000 address
STA count1 ; reset count indices
STA count2
LoadBackgroundLoop:
JSR Rand ; run RNG
STA $2007 ; write tile to PPU
INC count1 ;Background is 32x30 ($20 x $1E) sprites, so use nested loops to fill 960 bytes
LDA count1
CMP #$E0
BNE LoadBackgroundLoop
INC count2
LDA #$00
STA count1
LDA count2
CMP #$01
BNE LoadBackgroundLoop
RTS
FYI, the seed var is set to #$01 prior to LoadBackground, which is only called once. And I'm using NESASMv3.1