stuck

Are you new to 6502, NES, or even programming in general? Post any of your questions here. Remember - the only dumb question is the question that remains unasked.

Moderator: Moderators

User avatar
nineTENdo
Posts: 223
Joined: Sun Mar 19, 2006 12:37 am
Location: San ANto, TX
Contact:

stuck

Post by nineTENdo »

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
" If I have seen further it is by standing on the shoulders of giants" - Issac Newton, in a letter to Robert Hooke.
User avatar
Bregalad
Posts: 8036
Joined: Fri Nov 12, 2004 2:49 pm
Location: Caen, France

Post by Bregalad »

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.
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]
Useless, lumbering half-wits don't scare us.
User avatar
nineTENdo
Posts: 223
Joined: Sun Mar 19, 2006 12:37 am
Location: San ANto, TX
Contact:

Post by nineTENdo »

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: Select all

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.
" If I have seen further it is by standing on the shoulders of giants" - Issac Newton, in a letter to Robert Hooke.
User avatar
Bregalad
Posts: 8036
Joined: Fri Nov 12, 2004 2:49 pm
Location: Caen, France

Post by Bregalad »

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.
Useless, lumbering half-wits don't scare us.
User avatar
nineTENdo
Posts: 223
Joined: Sun Mar 19, 2006 12:37 am
Location: San ANto, TX
Contact:

Post by nineTENdo »

thanks again. good mourning and good night.
" If I have seen further it is by standing on the shoulders of giants" - Issac Newton, in a letter to Robert Hooke.
User avatar
tokumaru
Posts: 12106
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Post by tokumaru »

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.
User avatar
nineTENdo
Posts: 223
Joined: Sun Mar 19, 2006 12:37 am
Location: San ANto, TX
Contact:

Post by nineTENdo »

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: Select all


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.
" If I have seen further it is by standing on the shoulders of giants" - Issac Newton, in a letter to Robert Hooke.
albailey
Posts: 177
Joined: Thu Jul 13, 2006 3:15 pm

Post by albailey »

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
tepples
Posts: 22345
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Post by tepples »

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).
User avatar
tokumaru
Posts: 12106
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Post by tokumaru »

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).
User avatar
nineTENdo
Posts: 223
Joined: Sun Mar 19, 2006 12:37 am
Location: San ANto, TX
Contact:

Post by nineTENdo »

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: Select all

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.
" If I have seen further it is by standing on the shoulders of giants" - Issac Newton, in a letter to Robert Hooke.
User avatar
nineTENdo
Posts: 223
Joined: Sun Mar 19, 2006 12:37 am
Location: San ANto, TX
Contact:

Post by nineTENdo »

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)
" If I have seen further it is by standing on the shoulders of giants" - Issac Newton, in a letter to Robert Hooke.
User avatar
nineTENdo
Posts: 223
Joined: Sun Mar 19, 2006 12:37 am
Location: San ANto, TX
Contact:

Post by nineTENdo »

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: Select all

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???
" If I have seen further it is by standing on the shoulders of giants" - Issac Newton, in a letter to Robert Hooke.
User avatar
nineTENdo
Posts: 223
Joined: Sun Mar 19, 2006 12:37 am
Location: San ANto, TX
Contact:

Post by nineTENdo »

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
" If I have seen further it is by standing on the shoulders of giants" - Issac Newton, in a letter to Robert Hooke.
User avatar
blargg
Posts: 3717
Joined: Mon Sep 27, 2004 8:33 am
Location: Central Texas, USA
Contact:

Post by blargg »

nineTENdo wrote:

Code: Select all

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.
Post Reply