Welcome, deltnis.
I am reluctant to just upload fixed files. But I will show what to do. You were probably adding the correct code to your program to make a song play. But the only instrument you are using does not have a volume effect attached to it. Famitone seems to play instruments without a volume effect as silent. Here is an image showing how to add this:
Attachment:
add volume effect.gif [ 262.63 KiB | Viewed 1807 times ]
Then export the text, and use text2data.exe as you did before to create a new ShanghaiTea.asm.
After that, add the following code somewhere in bank 0.
Code:
.include "famitone2.asm"
.include "ShanghaiTea.asm"
Add these lines before you allow NMIs and enable the display of sprites and the BG.
Code:
ldx #LOW(ShanghaiTea_music_data)
ldy #HIGH(ShanghaiTea_music_data)
lda #$80;This sets Famitone to use NTSC mode.
jsr FamiToneInit
lda #0;Play first subsong
jsr FamiToneMusicPlay
;The below lines are already there. Here for context.
; Initialize PPU controling register
lda #%00011110 ; enable the display of sprite and BG
sta $2001
In your NMI routine (VBlank interrupting handler), add this:
Code:
NOTHINGdown:
jsr setSprite2
;This needs to be run every frame to play the song.
;It is best to do it last
jsr FamiToneUpdate;Other lines here for context
rti
Now, in famitone2.asm, uncomment these lines at the top:
Code:
FT_BASE_ADR = $0400 ;page in the RAM used for FT2 variables, should be $xx00
;-------------------------------------
;Note that FT_BASE_ADR has been changed from
;$0300 to $0400. Your sprites use $0300 so you
;must change this to make Famitone use
;different RAM
'----------------------------------
FT_TEMP = $00 ;3 bytes in zeropage used by the library as a scratchpad
;-----------------------------------------
;FT_TEMP has not been changed, since
;you are not using any zero page ($0000-$00FF) RAM
;in your program. If you were, you would need
;to make sure Famitone did not conflict with it
;by changing FT_TEMP.
;-----------------------------------------
FT_DPCM_OFF = $c000 ;$c000..$ffc0, 64-byte steps
; FT_SFX_STREAMS = 4 ;number of sound effects played at once, 1..4
; FT_DPCM_ENABLE ;undefine to exclude all DMC code
; FT_SFX_ENABLE ;undefine to exclude all sound effects code
; FT_THREAD ;undefine if you are calling sound effects from the same thread as the sound update call
; FT_PAL_SUPPORT ;undefine to exclude PAL support
FT_NTSC_SUPPORT ;undefine to exclude NTSC support
With those changes your program will play your song in any emulator that ran the program before. The rest of the post recommends things that will make your game run better on real hardware.Your program does not do much initialization, and may behave strangely on real hardware.
You are already waiting one frame before you start your program. It is good to wait at least two, because the PPU needs to warm up.
Code:
lda $2002;These makes sure the 7th bit of $2002 is
;clear for the loop below
waitVSync:
lda $2002
bpl waitVSync ; wait while 7th bit of $2002 is 1 (VBlank occuring)
waitVSync2:
lda $2002
bpl waitVSync2 ; wait once more for safety
I am not sure how familiar you are with the stack (It uses $0100-$01FF going backwards), but setting it up is a good idea. It is actually not
required, but it allows you to safely use some of the bottom of the RAM reserved for the stack for your program.
Code:
waitVSync2:
lda $2002
bpl waitVSync2 ; wait once more for safety
ldx #$FF
txs;Set up stack
NES does not begin with all RAM set to zero like many emulators do. Your sprites are drawn from RAM, so you may have random sprites on screen if you don't initialize it. Adding the code below will avoid that.
Code:
cpx #32;These lines are already in your program
bne loadPal;They are here for context
ldx #$00
clearram:
;lda #$00
;sta $0000,x
;sta $0100,x
;sta $0200,x
lda #$FF;#$FF is a Y position below the screen
;So writing it to every value in your sprite RAM
;at the beginning ensures no sprites you do not
;want are on screen.
sta $0300,x;Store #$FF to sprite page.
;lda #$00
;sta $0400,x
;sta $0500,x
;sta $0600,x
;sta $0700,x
inx
bne clearram
In addition, uncommenting the other ldas and stas will set all RAM that is not the sprite RAM to zero. This is not
required, as long as you always initialize RAM before you use it. Note that you are not initializing Sprite1_T, Sprite1_S, and Sprite2_T. So after doing the above, you will need to add some code so the sprites you have will display correctly:
Code:
lda X_Pos_Init
sta Sprite1_X
lda Y_Pos_Init
sta Sprite1_Y
lda #%00000000
sta Sprite1_S;
lda #$00
sta Sprite1_T
jsr setSprite2
lda #%01000000
sta Sprite2_S
lda #$00
sta Sprite2_T
As it was, your sprites were unlikely to work on real hardware.
The NES also does not initialize the background before power on, so whatever random things were there before power on will still be there unless you change them. You do not have different background tiles yet, but the below will set all of the background to zero.
Code:
lda #$00;This line was recommended above
sta Sprite2_T;Here for context.
clearnametables:
lda #$20;The first nametable (background) begins at $2000
sta $2006
lda #$00
sta $2006
ldy #$00;This loops through all background data
;writing tile zero and palette zero to it
ldx #$0C
clearnext:
sta $2007
iny
bne clearnext
dex
bne clearnext
With all of those changes, your game is also very likely to work on the real console. Good luck! Also, your song is very catchy.
Edit: I totally had to look up the song.
A cover of a thing from here. Neat!