Offline
WOW MAN!

To avoid confusion and to give this discussion it's own thread, can a moderator move it to a topic called "Audio Programming" or something similar? Or tag it onto the end of Nick's original chord program thread.

Thanks

Offline
Tacoma WA
neilbaldwin wrote:

To avoid confusion and to give this discussion it's own thread, can a moderator move it to a topic called "Audio Programming" or something similar? Or tag it onto the end of Nick's original chord program thread.

Thanks


Done!
Split topic and retitled.

Offline
rochester, ny

in an effort to further understand nintendo sav files, i thought i would modify one of No Carrier's tutorial programs to be able to save info. i used his sprite program - http://socialmovement.org/playpower/TUT … sprite.zip

first, i added two variables for the horizontal and vertical positions of the sprite right after the variables that were already listed:

buttons EQU $20                 ; variables for the buttons
oldbuttons EQU $22
justpressed EQU $24

v_position EQU $6000
h_position EQU $6001

then i modified the rom header information to support the MMC1 mapper.

        .ORG $7ff0              ; start at $7ff0 - 16 byte .NES header (iNES format)
Header:                         ; this is used only for emulators
    .db "NES", $1a
    .db $02
    .db $01
    .db %00000010
    .db %00000000
        .db $00
        .db $00
        .db $00
        .db $00
        .db $00
        .db $00
        .db $00

easy enough so far. next step, i'll make it so when you press start, it saves the vertical and horizontal positions of the sprite to the two variables i created earlier.

CheckStart:
    LDA #%00001000
    AND justpressed
    BEQ CheckB

    lda $0500
    sta v_position

    lda $0503
    sta h_position

and now i'll make it so when you press select, it will store the info from the variables into the horizontal and vertical positions of the sprite.

CheckSel:
    LDA #%00000100
    AND justpressed
    BEQ CheckStart


    lda v_position
    sta $0500

    lda h_position
    sta $0503

and that's it! open the program, move the sprite around, save it's position, close / reopen the program, then when you press select it will move the sprite to wherever you had saved it. works perfect. aside from those few changes, the code is exactly the same as what's in the zip file i linked before.

this is pretty basic but i'm really excited that i've figured it out. does everything look like it's supposed to? any other tips?

here's a link to download my modified version of the sprite program - http://www.box.net/shared/5seixkoha1

Last edited by nickmaynard (Jan 16, 2011 11:53 pm)

Offline
WOW MAN!

Looks like you've got a grasp of it smile

Reading and writing to the .sav file is pretty straightforward. One of the big advantages of using them is that it massively expands the available RAM. You can treat it like all the other RAM in the NES - just remember that any variables you put in there will be restored to the last saved value, unlike 'normal' RAM which is volatile.

Offline
rochester, ny
neilbaldwin wrote:

Looks like you've got a grasp of it smile

Reading and writing to the .sav file is pretty straightforward. One of the big advantages of using them is that it massively expands the available RAM. You can treat it like all the other RAM in the NES - just remember that any variables you put in there will be restored to the last saved value, unlike 'normal' RAM which is volatile.

woo! next step - adding this feature to my music programs. smile

Offline
rochester, ny

hey neil, if you've got a second i have a quick question.

i want to include some dpcm samples in one of my programs. so, i checked out the source code of no carrier's program "lickshot" - http://www.no-carrier.com/index.php?/lickshot/

it seems pretty easy to understand and i was able to get it working in my program just fine. but here's my problem. no carrier's code starts off by writing #$00 to $4015. this ends up muting whatever other audio i have going on in my program at that point.

i was working on a simple program where the buttons of the first player controller would play chords and single notes on the pulse and triangle channels, while the buttons of the second player controller would play drum sounds on the noise and dpcm channels. so, if the first player wants to hold a note out for an extended period of time, it gets silenced whenever the second player triggers one of the samples.

i was wondering what you'd suggest in this instance. i'm probably missing something extremely obvious. thanks for the help in advance!

Offline
WOW MAN!

$4015 is the voice enable register and uses bits 0 to 4 to enable Pulse 1, Pulse 2, Triangle, Noise and DCM respectively.

Binary    Hex Voice
%00000001 $01 Pulse 1
%00000010 $02 Pulse 2
%00000100 $04 Triangle
%00001000 $08 Noise
%00010000 $10 DCM

To figure out the value to write to $4015 just add up the values. For example, to enable the two Pulse voices, you write $03 to $4015 ($01 + $02). The APU is generally initialised with a value of $0F which enables the first four voices ($01 + $02 +$04 +$08 = $0F).

DCM differs slightly in that it requires you to turn the voice off and back on again to actually play the sample. In Don's code, he's not using any of the other voices so he doesn't need to turn them on, hence the $00 write (and probably $10 somewhere further down the code to start the sample playing).

So for you, instead of writing #$00 to $4015, write #$0F. This leaves the first four voices on but clears the enable bit for DCM, as is required. Then to start the sample write #$1F to $4015.

Make sense?

Offline
rochester, ny
neilbaldwin wrote:

$4015 is the voice enable register and uses bits 0 to 4 to enable Pulse 1, Pulse 2, Triangle, Noise and DCM respectively.

Binary    Hex Voice
%00000001 $01 Pulse 1
%00000010 $02 Pulse 2
%00000100 $04 Triangle
%00001000 $08 Noise
%00010000 $10 DCM

To figure out the value to write to $4015 just add up the values. For example, to enable the two Pulse voices, you write $03 to $4015 ($01 + $02). The APU is generally initialised with a value of $0F which enables the first four voices ($01 + $02 +$04 +$08 = $0F).

DCM differs slightly in that it requires you to turn the voice off and back on again to actually play the sample. In Don's code, he's not using any of the other voices so he doesn't need to turn them on, hence the $00 write (and probably $10 somewhere further down the code to start the sample playing).

So for you, instead of writing #$00 to $4015, write #$0F. This leaves the first four voices on but clears the enable bit for DCM, as is required. Then to start the sample write #$1F to $4015.

Make sense?

yes, that makes perfect sense. i'll try it out and post my results.

and seriously, thank you so much for helping me out.

Offline
WOW MAN!
nickmaynard wrote:

yes, that makes perfect sense. i'll try it out and post my results.

and seriously, thank you so much for helping me out.

No worries Nick smile

Offline
San Francisco

wow. thank you 2 for this public conversation. i have no idea what just happend but maybe when i learn more coding i will figure this out and actually post something relevant.

Offline

Neil and Nick sitting in a tree...
tongue

Offline
Toronto, Ontario, Canada
tRasH cAn maN wrote:

Neil and Nick sitting in a tree...
tongue

...N - E - S - and - D - M -G!

Offline
WOW MAN!

I'm like Mister Miyagi and Nick is Daniel-san...  smile

"DMC off! DMC on! DMC off! DMC on!"

Offline
San Francisco

lol

Offline
rochester, ny

quick question.

i know you can export .bin files from famitracker, but how do you use that in your assembly code? is there a web page somewhere with a tutorial or code examples?

Offline
WOW MAN!

If the question is aimed at me Nick, I know very little about Famitracker.