SNESDev - MSU-1 Hacking - Lag before song plays

Discuss technical or other issues relating to programming the Nintendo Entertainment System, Famicom, or compatible systems. See the NESdev wiki for more information.

Moderator: Moderators

Post Reply
ReverendSA
Posts: 36
Joined: Wed Mar 23, 2016 12:27 pm

SNESDev - MSU-1 Hacking - Lag before song plays

Post by ReverendSA »

Hi,

Does anyone know what could cause the rom to lag when playing a PCM track?

Yesterday I hacked Zelda to play PCM tracks instead of spc tracks (It can fallback as well).

I ported the code over to Kyuuyaku MEGAMI tensei but the odd thing is the game lags before loading and playing the track.

I did exactly as I did on Zelda - find the address where music is set, jsl to unused space, validate MSU presence, play MSU and RTL (if msu exists) else play spc and RTL.

Worked perfectly for Zelda but there is nasty lag with Kyuuyaku before the PCM plays. Not sure why, maybe I chose a bad spot to put my msu code? Basically I found a bunch of free FFs around $4FDB60.

I dont think that's the issue though because I can JSL to that area, run the original code, RTL and there is no lag.

I don't have access to my PC now but do you think maybe there's too much of a big load on the cpu that's causing the lag? Maybe I could find the JSL prior to the real music code and instead JSL to my new area then fill it up?

I don't really understand how CPU cycles work but if it gets to high is this what causes lag or would it just break the game instead?

If anyone is wondering, the point of interest in kyuuyaku is

$01EC16

A5 FC
8D 40 21

This loads $00FC and stores it into $2140. Then the music goes off. This is the code that I changed to JSL to my new area at $4FDB60.
tepples
Posts: 22708
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: SNESDev - MSU-1 Hacking - Lag before song plays

Post by tepples »

The docs imply that when you write to $2004-$2005, the MSU1 needs time to seek to the desired track and spin up the decoder. It sets the "audio busy" flag (bit 6 of the status port at $2000) until seeking has finished. On hypothetical CD-based implementations of the MSU1, seeking might take a half second.
ReverendSA
Posts: 36
Joined: Wed Mar 23, 2016 12:27 pm

Re: SNESDev - MSU-1 Hacking - Lag before song plays

Post by ReverendSA »

tepples wrote:The docs imply that when you write to $2004-$2005, the MSU1 needs time to seek to the desired track and spin up the decoder. It sets the "audio busy" flag (bit 6 of the status port at $2000) until seeking has finished. On hypothetical CD-based implementations of the MSU1, seeking might take a half second.
lda #$FF
sta MSU_VOLUME
ldx #$0001
stx MSU_TRACK
lda #$01
sta MSU_CONTROL

Need to fix my code it seems. Above is from that doc, and below is what I have:

lda #$FF
sta MSU_VOLUME
lda #$01
sta MSU_TRACK

lda #$01
sta MSU_CONTROL

Though I doubt that would fix the lag I guess. I see what you are saying. This type of hack is clearly not practical for sound modding, but just music modding where although lag will always be present, at least it will be masked by the fade out screens (right)?

I have reduced some of my lag using JMPs instead, but there are a few sections where I music will change at the push of a button, and the lag is still noticeable.


I actually do not understand the below too much. Only the bottom, that seems to create those $2000-$2007 addresses for MSU. Maybe these values should be altered for Kyuuyaku Megami Tensei as well but I would not know what to change. It seems to work fine using the default xml file.

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<cartridge region="NTSC">

	<!-- This part depends on the ROM -->
	<rom>
		<map mode="linear" address="00-7f:8000-ffff"/>
		<map mode="linear" address="80-ff:8000-ffff"/>
	</rom>

	<ram size="0x2000">
		<map mode="linear" address="20-3f:6000-7fff"/>
		<map mode="linear" address="a0-bf:6000-7fff"/>
		<map mode="linear" address="70-7f:0000-ffff"/>
		<map mode="linear" address="f0-ff:0000-ffff"/>
	</ram>

	<!-- This is the important bit -->
	<msu1>
		<map address="00-3f:2000-2007"/>
		<map address="80-bf:2000-2007"/>
	</msu1>

</cartridge>
ReverendSA
Posts: 36
Joined: Wed Mar 23, 2016 12:27 pm

Re: SNESDev - MSU-1 Hacking - Lag before song plays

Post by ReverendSA »

Turns out that the computer I was using this morning was slow af. I'm using it on my home PC and the lag nearly almost negligible. That was also after changing it around to use a JMP instead of a JSL.
Post Reply