Page 2 of 2
Re: Need help with a loop that has 16 bit counter
Posted: Tue Sep 09, 2014 11:49 pm
by teamtempest
Well, #240 may have been a little high as a starting value for the X-register.
As for the code that didn't put down the initial 'H', I didn't see any initialization of the Y-register. Was it there and just left out of what you posted?
Re: Need help with a loop that has 16 bit counter
Posted: Wed Sep 10, 2014 1:06 am
by Movax12
What's wrong with #240 ?..
Oops.
Well this code was based off of just clearing the nametable with a single value..
This change should fix it:
Code: Select all
; replace symbol names with your names..
; PPU_NAMETABLEADDRESS - where you want to write
; p - your pointer
; myData - data you want to write
; PPU_ADDRESS ; $2006
; PPU_DATA ; $2007
; set PPU address
lda #>PPU_NAMETABLEADDRESS
sta PPU_ADDRESS ; $2006
lda #<PPU_NAMETABLEADDRESS
sta PPU_ADDRESS
; nametable is 32 x 30 = 960
; this loop is 240 x 4 = 960
lda #<mydata
sta p
lda #>mydata
sta p+1
ldy #0
ldx #240
loop:
lda (p), y
sta PPU_DATA
iny
lda (p), y
sta PPU_DATA
iny
lda (p), y
sta PPU_DATA
iny
lda (p), y
sta PPU_DATA
iny
bne skip
inc p+1
skip:
dex
bne loop
Though I am liking barrym95838's code more at this point.
This idea does work well if you are just setting the nametable to a certian value:
Code: Select all
; set PPU address
lda #>PPU_NAMETABLEADDRESS
sta PPU_ADDRESS ; $2006
lda #<PPU_NAMETABLEADDRESS
sta PPU_ADDRESS
; nametable is 32 x 30 = 960
; this loop is 240 x 4 = 960
lda #0
ldx #240
loop:
sta PPU_DATA
sta PPU_DATA
sta PPU_DATA
sta PPU_DATA
dex
bne loop
Re: Need help with a loop that has 16 bit counter
Posted: Wed Sep 10, 2014 8:20 am
by BigEd
Unfortunately [some] code didn't work. I just got a messed up mix of 0 and blank tiles (like usually when it doesn't work). I was hoping it would have worked tough.
It's not at all unusual when programming down in assembly language that code doesn't quite work. It's worth having some tactics ready to deal with this:
- a careful manual read-through, considering each instruction's effect on registers, flags, and memory.
- single-stepping using an emulator or machine code monitor.
- modifying the misbehaving code, producing output or writing to memory so as to leave some idea of what happened when.
There are surely others too!
Hope this helps
Ed
Re: Need help with a loop that has 16 bit counter
Posted: Wed Sep 10, 2014 9:46 am
by Tor
Single-stepping (on an emulator or the hardware, if the latter is possible) is actually fun when you get down to it. Look at the registers and important memory locations after each step, and soon you'll see what happens. Very rewarding when you figure it out.
-Tor
Re: Need help with a loop that has 16 bit counter
Posted: Mon Oct 06, 2014 8:48 am
by Baka94
Just letting you know that I got the 16 bit counter working. The reason why it looked like it didn't, was that I had the PPU turned on when I drew the background. Anyway, thanks for the help. I'm off to learn how to use NMI and VBlank.
