Page 1 of 1

My Troubleshooting ?

Posted: Sun Jul 09, 2006 2:47 am
by nineTENdo
Ive having problems loading my nametables and palletes and all the good stuff upon a reset. I heard its best to use a reset in your code when working with NMI's. I cant get those to work so I figured id start using resets. Well heres my code

Code: Select all

	.org $8000

RESET:  
   	sei
   	cld
	jmp WVB
	jmp CHECK
	JMP LDNT

NOTHINGAD
		JMP NOTHINGAD

WVB
	lda #%00001000  ; do the setup of PPU
	sta $2000       ; that we
	lda #%00011110  ; talked about
	sta $2001       ; on a previous day
	RTS

CHECK	
	ldx #$00    ; clear X
		
	lda #$3F    ; have $2006 tell
	sta $2006   ; $2007 to start
	lda #$00    ; at $3F00 (pallete).
	sta $2006

	loadpal:                ; this is a freaky loop
	lda tilepal, x  ; that gives 32 numbers
	sta $2007       ; to $2007, ending when
	inx             ; X is 32, meaning we
	cpx #32         ; are done.
	bne loadpal     ; if X isn't =32, goto "loadpal:" line.
	RTS
   	


LDNT
	lda #$20
  	sta $2006 ; give $2006 both parts of address $2020.
   	sta $2006
   	ldx #$00

loadNames1:
   lda ourMap, X
   sta $2007
   inx
   bne loadNames1

loadNames2:
   lda ourMap+$100, X
   sta $2007
   inx
   bne loadNames2

loadNames3:
   lda ourMap+$200, X
   sta $2007
   inx
   bne loadNames3

loadNames4:
   lda ourMap+$300, X
   sta $2007
   inx
   cpx #$80
   bne loadNames4

	RTS
Everything works fine if i take all the JMPs out. I just want to do resets like i see on everyelses demos, so i can focus on getting my NMI's to work.

Thanks for the Help,
EL

Posted: Sun Jul 09, 2006 3:04 am
by Memblers
So close to working. The problem is having a JMP followed by an RTS. It looks like you're wanting JSRs instead of JMPs. Except in the infinite loop at the end of course. RTS without a JSR before it will normally cause the program to freak out and crash (or what I'd call BRK dancing, step through it in a debugger and see, heheh), since JMP doesn't put a return address on the stack.

Posted: Sun Jul 09, 2006 3:10 am
by nineTENdo
*Does the forehead slap*

Posted: Sun Jul 09, 2006 3:18 am
by Memblers
Oh also, on a second look I noticed the screen (BG/SPR enable on $2001) is getting turned on before you load the nametable. You'll want to clear those bits until after the nametable is loaded, or it could get corrupted as the PPU fights for control of the VRAM address.

Posted: Sun Jul 09, 2006 3:30 am
by nineTENdo
Write it at the end after loading the nametable. Or just clear them after the nametable. If so how do i clear them? With a $#00? Also is it best to keep vblank in its own subroutine? When would be a good time to JSR to it during an NMI if at all during a sprite movement. I get mixed up in Vblanks an when to turn them on and off and setting the NMI on Vblank Routine. Also Also do i have to keep updating registers 2003, and 2004 when working with NMI's. If so do i have to keep updating the sprite info too.

Posted: Sun Jul 09, 2006 4:10 am
by Memblers
Normally the next instructions after SEI and CLD at reset, are LDA #$00 / STA $2000 / STA $2001 (and STA $4015 too, if you have sound). You won't want NMIs during initialization either, since usually the NMI code will be playing around with the VRAM address also.

Then for me personally, the very last thing I normally do before entering the main loop is to enable the final settings I want on $2000/$2001. Moving WVB below LDNT would do just that.

I tend to keep all my inside-vblank code right at the beginning of the NMI routine.

I'd advise against using the $2004 register at all, use $4014 instead to DMA sprites from RAM during vblank. Mainly because you can only safely use all those registers during vblank (time which you'll find is better used for scrolling nametable updates, or pattern table animation). DMA is very fast and then you can work with the sprite settings anytime just by using normal RAM.

Posted: Sun Jul 09, 2006 4:31 am
by nineTENdo
Memblers wrote:
I tend to keep all my inside-vblank code right at the beginning of the NMI routine.

I'd advise against using the $2004 register at all, use $4014 instead to DMA sprites from RAM during vblank.
The ol LDA#$98 STA $2000 thing right.

Im workin o n moving up to 4014 cause of exacatly what you said. My only questions are.. Can it be updated with a simple LDA #$ 7, STA 4016. And do i have to setup any sprite info inside the NMI or keep it a .zp. Ill be updating the X and Y position, but do i need the tile number too?

Posted: Sun Jul 09, 2006 3:09 pm
by Memblers
nineTENdo wrote: The ol LDA#$98 STA $2000 thing right.
I'm not sure what you mean (or rather, when). Besides the name table selection in $2000 during scrolling, only time I usually touch that reg is before entering the main loop.
Im workin o n moving up to 4014 cause of exacatly what you said. My only questions are.. Can it be updated with a simple LDA #$ 7, STA 4016. And do i have to setup any sprite info inside the NMI or keep it a .zp. Ill be updating the X and Y position, but do i need the tile number too?
Yeah, writing 7 to $4014 will transfer the RAM at $700-$7FF to sprite RAM. I'm not sure what you mean by .zp (zero-page?). I have 2 parts for handling sprites, first is initialization (in a simple demo, before entering the main loop. In a game, I'd have a routine to 'create' sprites and another to 'destroy' them as needed. These routines set the starting tile #s and attributes). Then in the main loop, it'll wait for an NMI to pass, then handle all the X/Y movements (and another routine to change tile #s for animations). The 2nd part could be done in the NMI just as well, after the spr-DMA and all video stuff is done. Yeah, that means the displayed sprite positions basically lag behind by one frame, but it doesn't matter too much really.

Posted: Mon Jul 10, 2006 12:52 am
by nineTENdo
Memblers wrote:
nineTENdo wrote: The ol LDA#$98 STA $2000 thing right.
I'm not sure what you mean (or rather, when). Besides the name table selection in $2000 during scrolling, only time I usually touch that reg is before entering the main loop.

Ive seen that used in some nmi routines on demos. What should use to nmi on Vblank i thought this did it.

Memblers wrote: Yeah, writing 7 to $4014 will transfer the RAM at $700-$7FF to sprite RAM. I'm not sure what you mean by .zp (zero-page?).
Ive seen in the ASM tutorial he uses this to set up his sprites for use in dma

Code: Select all

.org $0300 ; OAM Copy location $0300

Sprite1_Y:     .db  0   ; sprite #1's Y value
Sprite1_T:     .db  0   ; sprite #1's Tile Number
Sprite1_S:     .db  0   ; sprite #1's special byte
Sprite1_X:     .db  0   ; sprite #1's X value
But im wondering is this something you only have to do once and just refresh with a sprite update to #$7 in $4014 or in this case a #$3. How would you setup your sprite info?