NESASM Nsf play code and Name Table load - NOOB problem

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
sdm
Posts: 315
Joined: Tue Apr 11, 2006 4:08 am
Location: Poland

NESASM Nsf play code and Name Table load - NOOB problem

Post by sdm »

I'm super mega noob with nes asm programming....

I need help with Nullslepp NSF play code:
http://www.nullsleep.com/treasure/nsf_cart_guide/

I try load SMB1 nsf file.... But without success :x

SMB NSF:
load address: C48D (-80 C40D)
init address: 34BE
play address: D0F2

Code: Select all

;-----------------------demo-------

	.inesprg 1
	.ineschr 1
	.inesmir 1
	.inesmap 0

	.org $8000
	.bank 0

	.org $c40d		; replace dashes with load address MINUS $80
	.incbin "demo.nsf"	; include NSF tune

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

Start:

	lda #%00001000
	sta $2000
	lda #%00011110
	sta $2001

	lda #$3F	;set ppu to start of palette
	sta $2006
	lda #$00
	sta $2006
	ldx #$00

loadpal:
	lda titlepal, x	;loads a 32 byte palette
	sta $2007
	inx
	cpx #$20	;gotta be one extra b/c of inx
	bne loadpal

vwait:
	lda $2002	;wait...
	bpl vwait

	lda #$20	;set ppu to start vram
	sta $2006
	lda #$20
	sta $2006

	lda #$01	;write pattern table tile numbers to the name table
	sta $2007
	lda #$02
	sta $2007
	lda #$03
	sta $2007
	lda #$01
	sta $2007
	lda #$02
	sta $2007
	lda #$03
	sta $2007
	lda #$01
	sta $2007
	lda #$03
	sta $2007
	lda #$00
	sta $2007
	lda #$00
	sta $2007
	lda #$00
	sta $2007
	lda #$00
	sta $2007
	lda #$00
	sta $2007
	lda #$00
	sta $2007
	lda #$00
	sta $2007
	lda #$00
	sta $2007
	lda #$00	;write pattern table tile numbers to the name table
	sta $2007
	lda #$00
	sta $2007
	lda #$00
	sta $2007
	lda #$00
	sta $2007
	lda #$00
	sta $2007
	lda #$00
	sta $2007
	lda #$00
	sta $2007
	lda #$00
	sta $2007
	lda #$00
	sta $2007
	lda #$00
	sta $2007
	lda #$00
	sta $2007
	lda #$02
	sta $2007
	lda #$02
	sta $2007
	lda #$01
	sta $2007
	lda #$01
	sta $2007
	lda #$01
	sta $2007



	ldx #$00	;set 2004 to the start SPRRAM
	stx $2003
	stx $2003

	lda #$00	;Y (w pionie)
	sta $2004
	lda #$00	;sprite pattern number (numer tilesa w pliku .SPR)
	sta $2004
	lda #%00000001
	sta $2004
	lda #$00	;X (w poziomie)
	sta $2004

	lda #$10
	sta $2004
	lda #$01
	sta $2004
	lda #%00000001
	sta $2004
	lda #$10
	sta $2004

; *** 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 $be34		; 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

titlepal:
	.incbin "demo.pal"	;palette data

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 $f2d0		; replace dashes with play address
	rti			; return from interrupt routine

IRQ_Routine:
	rti			; return from interrupt routine

	.bank 1
	.org	$FFFA
	.dw		0 ; NMI_Rutine
	.dw		Start ; Reset_Rutine
	.dw		0 ; IRQ_Rutine

	.bank 2
	.org $0000
	.incbin "demo.bkg"
	.incbin "demo.spr"

;-----------------------end----
Next:

How to load Name table from file (.map) ???

I try load name table using Gba Gay tutorial, lesson 13 "Making Background:
http://www.patatersoft.info/gbaguy/day13n.htm

But dont work...:/ I dont see any bkg tiles...:/
Last edited by sdm on Thu Jul 12, 2007 3:48 pm, edited 1 time in total.
tepples
Posts: 22345
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: NESASM Nsf play code and Name Table load - NOOB problem

Post by tepples »

sdm wrote:

Code: Select all

;-----------------------demo-------

	.inesprg 1
	.ineschr 1
	.inesmir 1
	.inesmap 0

	.org $8000
	.bank 0

	.org $c40d		; replace dashes with load address MINUS $80
	.incbin "demo.nsf"	; include NSF tune

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

Start:

	lda #%00001000
	sta $2000
	lda #%00011110
	sta $2001

	lda #$3F	;set ppu to start of palette
	sta $2006
	lda #$00
	sta $2006
	ldx #$00
You need to do the 2 vblank waits before you access $2003-$2007 for the first time.
How to load Name table from file (.map) ???
Have you heard of the "indirect indexed" addressing mode, which uses instructions of the following form?

Code: Select all

  lda (0),y
I try load name table using Gba Gay tutorial, lesson 13 "Making Background:
Freudian slip? This tutorial is generally considered deprecated in favor of "NES 101".

The reason you're not seeing any background could be that you aren't turning on the background:

Code: Select all

  lda #%00001010
  sta $2001
But make sure you do this after you have set up $2000 and $2005 for this frame.
sdm
Posts: 315
Joined: Tue Apr 11, 2006 4:08 am
Location: Poland

Post by sdm »

aghh... I cannot load nametable from file... :shock: What the...

I make simple code:

Code: Select all

	.inesprg 1
	.inesmap 0
	.inesmir 1
	.ineschr 1

	.bank 1     
	.org $FFFA
	.dw 0
	.dw Start
	.dw 0

	.bank 0
	.org $0000

	.org $8000
Start:

	lda #%10001000
	sta $2000
	lda #%00011110
	sta $2001

	lda #$3F
	sta $2006
	lda #$00
	sta $2006
	ldx #$00

loadpal:
	lda titlepal,x
	sta $2007
	inx
	cpx #$20
	bne loadpal

vwait:
	lda $2002	;wait...
	bpl vwait

	lda #$20	;set ppu to start vram
	sta $2006
	lda #$20
	sta $2006

nametable:

	lda names,x
	inx
	sta $2007
	cpx #64
	bne nametable

Loop:
	jmp Loop

titlepal:
	.incbin "demo.pal"

	.bank 2
	.org $0000
	.incbin "demo.bkg"
	.incbin "demo.spr"

names:
	.incbin "demo.map"
http://siudymus.w.interia.pl/demo.pal
http://siudymus.w.interia.pl/demo.spr
http://siudymus.w.interia.pl/demo.bkg
http://siudymus.w.interia.pl/demo.map


Nestopia says "CPU JAM!"... Please. let someone fix me that code.. :?

Image
atari2600a
Posts: 324
Joined: Fri Jun 29, 2007 10:25 pm
Location: Earth, Milkyway Galaxy, The Universe, M-Theory
Contact:

Post by atari2600a »

disable NMI on vblank on $2000 D7 & re-enable it after init.

EDIT: I also don't see any 2 vblank waiting before init

More EDIT: PLUS it doesn't look like you have your interrupts set. I don't know, maybe you did but I overlooked them, I'm too used to how I have my stuff set up. (seperate ASM file for ines, prg, chr in ACME syntax)

Code: Select all

          *=$0000
loop      JMP loop
          .eof
User avatar
Hamtaro126
Posts: 786
Joined: Thu Jan 19, 2006 5:08 pm

Re: NESASM Nsf play code and Name Table load - NOOB problem

Post by Hamtaro126 »

sdm wrote:I'm super mega noob with nes asm programming....

I need help with Nullslepp NSF play code:
http://www.nullsleep.com/treasure/nsf_cart_guide/

I try load SMB1 nsf file.... But without success :x

SMB NSF:
load address: C48D (-80 C40D)
init address: 34BE
play address: D0F2

Code: Select all

;-----------------------demo-------

	.inesprg 1
	.ineschr 1
	.inesmir 1
	.inesmap 0

	.org $8000
	.bank 0

	.org $c40d		; replace dashes with load address MINUS $80
	.incbin "demo.nsf"	; include NSF tune

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

Start:

	lda #%00001000
	sta $2000
	lda #%00011110
	sta $2001

	lda #$3F	;set ppu to start of palette
	sta $2006
	lda #$00
	sta $2006
	ldx #$00

loadpal:
	lda titlepal, x	;loads a 32 byte palette
	sta $2007
	inx
	cpx #$20	;gotta be one extra b/c of inx
	bne loadpal

vwait:
	lda $2002	;wait...
	bpl vwait

	lda #$20	;set ppu to start vram
	sta $2006
	lda #$20
	sta $2006

	lda #$01	;write pattern table tile numbers to the name table
	sta $2007
	lda #$02
	sta $2007
	lda #$03
	sta $2007
	lda #$01
	sta $2007
	lda #$02
	sta $2007
	lda #$03
	sta $2007
	lda #$01
	sta $2007
	lda #$03
	sta $2007
	lda #$00
	sta $2007
	lda #$00
	sta $2007
	lda #$00
	sta $2007
	lda #$00
	sta $2007
	lda #$00
	sta $2007
	lda #$00
	sta $2007
	lda #$00
	sta $2007
	lda #$00
	sta $2007
	lda #$00	;write pattern table tile numbers to the name table
	sta $2007
	lda #$00
	sta $2007
	lda #$00
	sta $2007
	lda #$00
	sta $2007
	lda #$00
	sta $2007
	lda #$00
	sta $2007
	lda #$00
	sta $2007
	lda #$00
	sta $2007
	lda #$00
	sta $2007
	lda #$00
	sta $2007
	lda #$00
	sta $2007
	lda #$02
	sta $2007
	lda #$02
	sta $2007
	lda #$01
	sta $2007
	lda #$01
	sta $2007
	lda #$01
	sta $2007



	ldx #$00	;set 2004 to the start SPRRAM
	stx $2003
	stx $2003

	lda #$00	;Y (w pionie)
	sta $2004
	lda #$00	;sprite pattern number (numer tilesa w pliku .SPR)
	sta $2004
	lda #%00000001
	sta $2004
	lda #$00	;X (w poziomie)
	sta $2004

	lda #$10
	sta $2004
	lda #$01
	sta $2004
	lda #%00000001
	sta $2004
	lda #$10
	sta $2004

; *** 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 $be34		; 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

titlepal:
	.incbin "demo.pal"	;palette data

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 $f2d0		; replace dashes with play address
	rti			; return from interrupt routine

IRQ_Routine:
	rti			; return from interrupt routine

	.bank 1
	.org	$FFFA
	.dw		0 ; NMI_Rutine
	.dw		Start ; Reset_Rutine
	.dw		0 ; IRQ_Rutine

	.bank 2
	.org $0000
	.incbin "demo.bkg"
	.incbin "demo.spr"

;-----------------------end----
Next:

How to load Name table from file (.map) ???

I try load name table using Gba Gay tutorial, lesson 13 "Making Background:
http://www.patatersoft.info/gbaguy/day13n.htm

But dont work...:/ I dont see any bkg tiles...:/
The problem is all of the above!

1: NSF code is too big for the ASM stuff to work (NESASM and X816 Programs have memory boundarys)

2: Do not use GBAguy's stuff! His ASM was terrible, outdated and obsolete and it is better to get a diffrent tutorial.

3: NESASM crashes and it SUCKS!

4: The code for the NSF is for X816 and is diffrent from NESASM code!
sdm
Posts: 315
Joined: Tue Apr 11, 2006 4:08 am
Location: Poland

Post by sdm »

Forget that first code...;)

I need know how fix second code and load nametable... :?

Code: Select all

	.inesprg 1
	.inesmap 0
	.inesmir 1
	.ineschr 1

	.bank 1     
	.org $FFFA
	.dw 0
	.dw Start
	.dw 0

	.bank 0
	.org $0000

	.org $8000
Start:

	lda #%10001000
	sta $2000
	lda #%00011110
	sta $2001

	lda #$3F
	sta $2006
	lda #$00
	sta $2006
	ldx #$00

loadpal:
	lda titlepal,x
	sta $2007
	inx
	cpx #$20
	bne loadpal

vwait:
	lda $2002	;wait...
	bpl vwait

	lda #$20	;set ppu to start vram
	sta $2006
	lda #$20
	sta $2006

nametable:

	lda names,x
	inx
	sta $2007
	cpx #64
	bne nametable

Loop:
	jmp Loop

titlepal:
	.incbin "demo.pal"

	.bank 2
	.org $0000
	.incbin "demo.bkg"
	.incbin "demo.spr"

names:
	.incbin "demo.map"
atari2600a
Posts: 324
Joined: Fri Jun 29, 2007 10:25 pm
Location: Earth, Milkyway Galaxy, The Universe, M-Theory
Contact:

Post by atari2600a »

Same problems I mentioned before still existent, although you can just keep NMI on vblank off for code like this...which you're not doing. The program is looping back to $0000 every 30th of a second, which is probably causing the CPU jam error message.

Code: Select all

          *=$0000
loop      JMP loop
          .eof
Post Reply