hello,
hope someone can help. i cant seem to get a flicker on my demo to to stop. im switching between different nametables within my NMI. the new name table works fine. it loads without any problem but there seems to be a flicker right after i load it. it also happens when i write individual values in my VRAM I/O reg ($2007). im trying to over come my 8 sprite scan line and figured it out by just writing to the $2007. but it flickers when i imprint(write) a sprite (Nametable Number).
i figure its has to with $2002, but im wondering "Can i write to the PPU safely within my NMI"? or do i have to port my PPU pokes in my main loop after my VBLANK has occurred. polling? i would us my main loop but NESASM sucks and i can seem to get anything to run in there, so thats why ive just been using NMI's which have worked until i run across this scenario.
please help o wise ones,
thanks
el
Quote:
figure its has to with $2002, but im wondering "Can i write to the PPU safely within my NMI"?
Yes, for a limited amount of time.
Quote:
Or do i have to port my PPU pokes in my main loop after my VBLANK has occurred.
It doesn't matter where the code that writes to PPU is placed, it only matters when it's executed. You can only write to PPU either it you turned rendering off (which I recommand for wirting a whole nametable) or during VBlank, which is usually done in NMI routine, but doesn't have to technically.[/quote]
Quote:
You can only write to PPU either it you turned rendering off
what is this you speak of how do i do it?
basically hears the layout
Code:
button pressed
|
|----NAMETABLE1
lda #$00
sta $2000
sta $2001
jsr NT_1
lda #100100
sta $2000
lda #1011110
sta $2001
RTS
|---
should i not desable the NMI before i load a new nametable.
thanks for being on the other side of the earth at this point in time.
Quote:
what is this you speak of how do i do it?
Write 0 to $2001.
But typically, you'd want to load your nametables in a first step with rendering off, and once you're done turn it on and do the actual logic you want to do, only writing to $2000 and not dealing with $2001 anymore.
thanks again. good mourning and good night.
Yeah, if you are switching between 2 screens, it's best that you keep rendering off after botting up, draw the 2 screens completelly, and then enable rendering. Switching between them is just a metter of selecting what NT is displayed, no redrawing.
However, if you need more than 2 screens, you need to draw them as necessary. And if want to switch between them without disabling rendering and blanking the screen for a frame or two, you'll have to use Vblank time. Since this time is not enough to update a whole NT, you'll need to break up the drawing process into 4 or 8 smaller tasks, and execute them for a few consecutive frames before displaying the new screen.
ill still seeing a glich. i figured it was just to much to loading at one time so i omited the nametable load from each screen swap and just left the sprites to load. everything loads without a problem. i then just wrote a single tile to the exisiting nametable using $2007 and still a glich. i seem to only get a glich whenever i write to $2007. heres the full routine
Code:
joyread
lda joypad
...................
cmp #$10
bne JOY_L
inc NT_SWAP
lda NT_SWAP
and #$03
sta NT_SWAP
jsr SWAP_NAMETABLES
jmp ENDJOY
.................
SWAP_NAMETABLES
lda NT_SWAP
cmp #$00
bne NameT_1
jsr NT0
jmp ENDSWAP
NameT_1 cmp #$01
bne NameT_2
jsr NT1
jmp ENDSWP
NameT_2 cmp #$02
bne NameT_3
jsr NT2
jmp ENDSWP
NameT_3 cmp #$03
bne ENDSWAP
jsr NT3
ENDSWAP RTS
NT0
lda #$00
sta $2000
sta $2001
jsr CLR_SPRT_DMA
jsr LD_SPRTS_0 <---*view note below
jsr NT_0
lda #%10010000
sta $2000
lda #%10111100
sta $2001
RTS
*seems to only work when the nametable load is performed after loading the sprites.
but like i said everything works expect for the glich when i write to $2007.
sprites load up perfectly without a problem.
I dont really trust my code, but I also reset the PPU address and scrolling before turning back on rendering.
LDA $2002 ; resets the latches
LDA #$00
STA $2005
STA $2005
STA $2006
STA $2006
Let me know if this helps (or not)
Al
You don't need to write to $2006. I'd recommend writing to $2000 once (to set bit 8 of both coordinates), $2005 twice (to set bits 0-7 of X and Y), and $2001 once (to turn on rendering).
Most documents refer to the lower 2 bits of $2000 as "name table selection" bits, but it really is easier to master scrolling if you think of them as the highest bits of each coordinate, and the lower 8 bits of them is what is written to $2005.
So, like tepples said, there is no need at all to mess with $2006 to adjust the scrolling, as long as it's done during Vblank (to fully set the scroll outside of VBlank you have to use $2006).
tepples wrote:
You don't need to write to $2006. I'd recommend writing to $2000 once (to set bit 8 of both coordinates), $2005 twice (to set bits 0-7 of X and Y), and $2001 once (to turn on rendering).
in one of my routines i have a sprite that moves over locations and if i want to set the sprite down i press B. everytime the location changes the PPU address changes respectively. for example. i move over two, 3,4..etc spaces i use this:
Code:
lda move_sprite_vrt (inc move_sprite with joy presses vertically)
asl a
asl a
asl a
asl a
asl a x32
clc
adc #$e9 (base nametable PPU address)
sta VRAM_LOW
Lda VRAM_HI
sta $2006
Lda VRAM_LOW
sta $2006
lda #$45 (what ever tile i want to write to nametable)
sta $2007
i works ok without any problems except for the glich.
after looking back im realizing that i might be using the word nametable in the wrong connotation. what i mean is pattern tables. i switch between pattern tables ( ie. a .nam file that created as my backround)
ok i tried to see to what exactly is the problem by checking the $2002 before i load my pattern table to see what is going on.
Code:
WAITVB LDA #$2002
BPL WAITVB
STA TEST
JSR LD_NT1
..............................
..............................
when i look in the HEX Editor in FCE i get a #$1E (11110) Value. its seems there might be something hitting a sprite 0 value, beasue there are is no clipping occuring in the 8 sprite scanline when read $2002. any idess???
albailey wrote:
I dont really trust my code, but I also reset the PPU address and scrolling before turning back on rendering.
LDA $2002 ; resets the latches
LDA #$00
STA $2005
STA $2005
STA $2006
STA $2006
Let me know if this helps (or not)
Al
nope same thing
nineTENdo wrote:
Code:
WAITVB LDA #$2002
BPL WAITVB
STA TEST
JSR LD_NT1
..............................
..............................
Why don't you paste the actual code you're assembling? And before anyone says it is, look carefully at the first line.
Might as well just post a
link to your entire source file(s), since these fragments won't help us find errors that aren't in them.
the actual source file is about 50 pages long and i only pasted what problems i was i was actually having. a huge file or post with all the code would just be time consuming and bad for the eyes to debug. i even hate debuging it sometimes. but pretty much the only going wrong is what i have listed. i ususlly debug for about a few hours before i come to post here, unlike my olden dayzzz.
after trying to actully figure it out ive only been able to minimize the glich. i seems if i change to entirely different nametable there is little glich but i get a big glitch if i change to a different nametable with the same backround.
Maybe a better description (or even a screenshot) of the glitch would help. And sometimes it's hard to tell where a bug is... you may think it's in a piece of code you posted, but it may very well be caused by something completely different, and that piece might just be what makes the bug evident, not what causes it.
tokumaru wrote:
you may think it's in a piece of code you posted, but it may very well be caused by something completely different, and that piece might just be what makes the bug evident, not what causes it.
Completely true. A lot of the time, the problem is quite simple, like a typo. But the typo could be anywhere. Use the process of elimination to determine where your bug has to be. By testing code under different circumstances, you can usually get to the bottom of it fairly quickly.
welp i figured out. i just needed a simple dual reset of the $2005 at the beginning of the NMI and the end.