This page is a mirror of Tepples' nesdev forum mirror (URL TBD).
Last updated on Oct-18-2019 Download

Famitracker driver and DPCM collission problem.

Famitracker driver and DPCM collission problem.
by on (#67479)
For a change I've decided to try my hand at NES programming. So, the first thing I've done is display a static screen with a graphic centered in the middle. Also, I have a DPCM player and a famitracker driver installed.

The problem is that either one disables the other depending on the configuration of the code, but if I run the DPCM player code after the Famitracker init, the DPCM sample plays fine on top of the music. However, I don't want that. I want the DPCM sample to play before the Famitracker driver starts playing.

I just haven't been able to figure out what the problem is. I wonder if you guys have any suggestions. I've also tried hacking the Famitracker binary NSF code as well. Here is the code configuration that I'm using.

Code:

Initialize both players

    JSR DPCM_PLAY    ; Play DPCM sample.
    LDA #$01         ; A failed attempt at waiting for
    STA TIMER        ; 01 frames for the Famitracker driver to play.
    JSR FRAMEWAIT    ; Wait for x number of frames.
    LDA #$01         ; Enable the play routine in the NMI.
    STA MUSICCHECK
    LDA #$00         ; Load A with tune number
    JSR $AC00        ; Call Famitracker driver init code.

END:
    JMP END          ; Continuous end loop at the end of reset.

FRAMEWAIT:           ; Wait for x amount of frames depending on what
    CLC              ; the variable "TIMER" contains.
    ADC TIMER
FRAMEWAIT_WAIT:
    CMP TIMER
    BNE FRAMEWAIT_WAIT
    RTS

DPCM_PLAY:           ; Basic unrolled code to play the
      LDA #$09       ; DPCM sample.
      STA $4010
      LDA #$40
      STA $4011
      LDA #$00
      STA $4012
      LDA #$A0
      STA $4013
      LDA #$0F
      STA $4015
      LDA #$1F
      STA $4015
      RTS
Re: Famitracker driver and DPCM collission problem.
by on (#67487)
The frame waiting code you used satisfies the condition immediately, and has no method of actually waiting for an entire frame. Unfortunately, even if it did work, one frame is probably not long enough to wait before the Famitracker music engine starts playing, which will cause the DPCM sample to play on top of the music.

If you want the music to play after the sample, what you should do is something like this:

Code:

    JSR DPCM_PLAY    ; Play DPCM sample.
s_end_wait:
    LDA $4015
    AND #%00010000   ;If sample is still playing, bit 4 will be set.
    BNE s_end_wait
    LDA #$01         ; Enable the play routine in the NMI.
    STA MUSICCHECK
    LDA #$00         ; Load A with tune number
    JSR $AC00        ; Call Famitracker driver init code.


by on (#67488)
Good call. After installing that code, it worked perfectly. It didn't ocurr to me last night to do it like that. Thanks a lot.