Hello! I'll like some clarifications about some code I wrote right now.
I followed the tutorial of the site https://book.famicom.party/chapters/05-6502assembly.html , and I copy pasted the program that simply changed the background and figured I'll get my hands dirty and decided to write a loop that will go over a bunch of different colors.
So anyway, this is the relevant piece of code:
The reason I have loop: and wait: is because, when I assembled the rom without those, I got a mess of colors in the emulator (Nestopia if its relevant):
I figured this is because the color is changing too fast, so I add the two nested loops to add a bunch of NOPS just to see if that was the reason and sure enough, now I get a nice, solid background that last for a few seconds.
So my question is: This feel incredibly hacky, how does one exactly wait a certain ammount of time for events to happen? I guess Ideally you'll be able to wait for certain ammount of frames to have passed? This is my first time programming for a console and coding with ASM, so I'm a little bit lost here.
I followed the tutorial of the site https://book.famicom.party/chapters/05-6502assembly.html , and I copy pasted the program that simply changed the background and figured I'll get my hands dirty and decided to write a loop that will go over a bunch of different colors.
So anyway, this is the relevant piece of code:
Code:
.proc main
LDA #$00
background:
LDX PPUSTATUS
ADC #$01
LDX #$3f
STX PPUADDR
LDX #$00
STX PPUADDR
STA PPUDATA
LDY #%00011110
STY PPUMASK
LDX #$FF
loop:
LDY #$FF
wait:
NOP
DEY
CPY #$00
BNE wait
NOP
DEX
CPX #$00
BNE loop
JMP background
LDA #$00
background:
LDX PPUSTATUS
ADC #$01
LDX #$3f
STX PPUADDR
LDX #$00
STX PPUADDR
STA PPUDATA
LDY #%00011110
STY PPUMASK
LDX #$FF
loop:
LDY #$FF
wait:
NOP
DEY
CPY #$00
BNE wait
NOP
DEX
CPX #$00
BNE loop
JMP background
The reason I have loop: and wait: is because, when I assembled the rom without those, I got a mess of colors in the emulator (Nestopia if its relevant):
I figured this is because the color is changing too fast, so I add the two nested loops to add a bunch of NOPS just to see if that was the reason and sure enough, now I get a nice, solid background that last for a few seconds.
So my question is: This feel incredibly hacky, how does one exactly wait a certain ammount of time for events to happen? I guess Ideally you'll be able to wait for certain ammount of frames to have passed? This is my first time programming for a console and coding with ASM, so I'm a little bit lost here.