Nullsleep's NSF playback code + displaying a sprite

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

Post Reply
mcfiredrill
Posts: 9
Joined: Sun May 13, 2007 8:36 pm
Contact:

Nullsleep's NSF playback code + displaying a sprite

Post by mcfiredrill »

Well I got X816 to work with DOSBox, so I got the playback code working. But now I am trying to display a sprite, I took some code from GBA Guy's tutorial (I got the code from Day 5 to assemble with NESASM), and tried to combine it with the playback code. Obviously, I don't know what the hell I am doing, but if anyone is bored and feels like steering me in the right direction, what I should work on understanding, go ahead and help me out, I would really appreciate it. Here's da code:

Code: Select all


; *** X816 SETTINGS ***
	.mem 8			; 8-bit memory mode
	.index 8		; 8-bit index mode
	.opt on			; address optimize
	
	.org $8000		; replace dashes with load address MINUS $80
	.incbin "nomryi.nsf"	; include NSF tune 
	.incbin "our.bkg"  ; empty background first

	.incbin "our.spr"  ; our sprite pic data

	
Reset_Routine:
	cld			; clear decimal flag
	sei			; disable interrupts
	lda #%00000000		; disable vblank interrupts by clearing
	sta $2000		; the most significant bit of $2000
	
		:****graphix!****
	
	Start:  

	lda #%00001000  ; do the setup of PPU

	sta $2000       ; that we

	lda #%00011110  ; talked about

	sta $2001       ; on a previous day
	

	
	;supermario clouds code


 	lda #$3F ; NES background palette location
	sta $2006
	lda #$00
	sta $2006

	lda #$21 ;background [powder blue]
	sta $2007
	lda #$30 ;cloud inside [white]
	sta $2007
	lda #$11 ; highlight [blue]
	sta $2007
	lda #$0d ;outline [black]
	sta $2007

	
	;end supermario clouds code



waitblank:         ; this is the wait for VBlank code from above

	lda $2002  ; load A with value at location $2002

	bpl waitblank  ; if bit 7 is not set (not VBlank) keep checking



	lda #$00   ; these lines tell $2003

	sta $2003  ; to tell

	lda #$00   ; $2004 to start

	sta $2003  ; at $0000.



	lda #100  ; load Y value

	sta $2004 ; store Y value

	lda #$00  ; tile number 0

	sta $2004 ; store tile number

	lda #$00 ; no special junk

	sta $2004 ; store special junk

	lda #100  ; load X value

	sta $2004 ; store X value

	; and yes, it MUST go in that order.
	
	;****end graphix code****


	
; *** WAIT 2 VBLANKS ***
WaitV1:	
	lda $2002		; give the PPU a little time to initialize
	bpl WaitV1		; by waiting for a vblank
WaitV2:	
	lda $2002		; wait for a second vblank to be safe
	bpl WaitV2		; and now the PPU should be initialized
	
; *** CLEAR SOUND REGISTERS ***
	lda #$00		; clear all the sound registers by setting
	ldx #$00		; everything to 0 in the Clear_Sound loop
Clear_Sound:
	sta $4000,x		; store accumulator at $4000 offset by x
	inx			; increment x
	cpx #$0F		; compare x to $0F
	bne Clear_Sound		; branch back to Clear_Sound if x != $0F

	lda #$10		; load accumulator with $10
	sta $4010		; store accumulator in $4010
	lda #$00		; load accumulator with 0
	sta $4011		; clear these 3 registers that are 
	sta $4012		; associated with the delta modulation
	sta $4013		; channel of the NES
	
; *** ENABLE SOUND CHANNELS ***
	lda #%00001111		; enable all sound channels except
	sta $4015		; the delta modulation channel
	
; *** RESET FRAME COUNTER AND CLOCK DIVIDER ***
	lda #$C0		; synchronize the sound playback routine 
	sta $4017		; to the internal timing of the NES
	
; *** SET SONG # & PAL/NTSC SETTING ***
	lda #$00		; replace dashes with song number
	ldx #$00		; replace with $00 for NTSC or $01 for PAL
	jsr $8000		; replace dashes with init address
	
; *** ENABLE VBLANK NMI ***
	lda #%10000000		; enable vblank interrupts by setting the 
	sta $2000		; most significant bit of $2000
	


Loop:
	jmp Loop		; loop loop loop loop ...
	
NMI_Routine:
	lda $2002		; read $2002 to reset the vblank flag
	lda #%00000000		; clear the first PPU control register  
	sta $2000		; writing 0 to it
	lda #%10000000		; reenable vblank interrupts by setting
	sta $2000		; the most significant bit of $2000
	jsr $8003		; replace dashes with play address
	rti			; return from interrupt routine
	
IRQ_Routine:
	rti			; return from interrupt routine

.pad $FFFA
	.dw	NMI_Routine	; setup the NMI vector at $FFFA
	.dw	Reset_Routine	; setup the Reset vector at $FFFC
	.dw	IRQ_Routine	; setup the IRQ vector at $FFFE

	
User avatar
Memblers
Site Admin
Posts: 3902
Joined: Mon Sep 20, 2004 6:04 am
Location: Indianapolis
Contact:

Post by Memblers »

Don't worry, GBA Guy didn't really know what he was doing either, heheh. Using the $2004 reg like that will probably fail on a real NES. I can't see why it's not showing up on an emulator though, it looks OK at first glance.

Really, noone ever uses the $2004 register at all. It's better to use sprite-DMA, put all your sprites in a page of RAM (like $200-$2FF) then write $02 to the $4014 reg early in your NMI code to transfer that page.
User avatar
never-obsolete
Posts: 403
Joined: Wed Sep 07, 2005 9:55 am
Location: Phoenix, AZ
Contact:

Post by never-obsolete »

does the sprite get refreshed every nmi? i'm not sure if that would matter on an emulator, but as said, $4014 is the way to go.
. That's just like, your opinion, man .
mcfiredrill
Posts: 9
Joined: Sun May 13, 2007 8:36 pm
Contact:

Post by mcfiredrill »

Oh man...I understand even less than I thought :(
!!
mcfiredrill
Posts: 9
Joined: Sun May 13, 2007 8:36 pm
Contact:

Post by mcfiredrill »

better read some more docs... ;)
User avatar
Disch
Posts: 1848
Joined: Wed Nov 10, 2004 6:47 pm

Post by Disch »

also:

Use $0F for black. $0D is the forbidden "blacker than black" and will distort the image on TV displays.
tepples
Posts: 22345
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Post by tepples »

I wonder if it's possible to emulate this $0D distortion.
User avatar
Disch
Posts: 1848
Joined: Wed Nov 10, 2004 6:47 pm

Post by Disch »

doesn't the NTSC filter? I guess I just assumed it did
Post Reply