Addressed Music

Discussion in 'Tutorials Archive' started by MarkeyJester, Apr 22, 2012.

Thread Status:
Not open for further replies.
  1. MarkeyJester

    MarkeyJester ♡ ! Member

    Joined:
    Jun 27, 2009
    Messages:
    2,867
    OK, so, I remember someone saying to me about music and sound limits, and they believed the highest value they could get their ID's up to were 80 - 7F, today I wanted to remove that limit, so I did.


    Here is a disassembly of Sonic 1 that has been altered to read the location of music rather than an ID:


    Download


    Here's how it works, originally, if you wanted to play a music track, you would do this:



    Code:
    Music
    
    
    
    		move.b	#$81,d0
    
    		bsr	PlaySound


    That ID can only be from 80 to 7F, that leaves you with 100 slots for music, sfx and control. In the one above, you would do this instead:





    Code:
    Music
    
    
    
    		move.l	#Music81,d0
    
    		bsr	PlayMusic


    Here, you simply move the location of the music (no matter where it is) to d0, and call the routine, There are 4 types to use:





    Code:
    Music
    
    
    
    		move.l	#Music81,d0
    
    		bsr	PlayMusic
    
    
    
    		move.l	#SoundA0,d0
    
    		bsr	PlaySound
    
    
    
    		move.l	#SoundD0,d0
    
    		bsr	PlayAdvance
    
    
    
    		move.l	#Sound_E0,d0
    
    		bsr	PlayControl

    PlayMusic for BGM music, PlaySound for SFX, PlayAdvance for advance SFX of ID D0 and higher, and PlayControl for the special E0 - E4 software sound manipulation (fading, stopping, speed change, SEGA sound, etc).


    There are now no ID limits, only the limit of the ROM, if you wish to apply it to your disassembly rather than having to build off of the one above, search for "; MJ:" I have tagged all of the changes made.


    There SHOULD be no bugs, but even the best of us make mistakes, good luck and enjoy.
     
  2. kramlat

    kramlat Newcomer Member

    Joined:
    Feb 21, 2009
    Messages:
    12
    Location:
    home
    is it okay to use this code in homebrew?
     
  3. MarkeyJester

    MarkeyJester ♡ ! Member

    Joined:
    Jun 27, 2009
    Messages:
    2,867
    I can't see why not, I wouldn't have made it public otherwise.
     
  4. EMK-20218

    EMK-20218 The Fuss Maker Exiled

    Joined:
    Aug 8, 2008
    Messages:
    1,067
    Location:
    Jardim Capelinha, São Paulo
    I'm a bit confused. Let me see if I understood it. So with this I can add how many songs I want in the hack? It's completely unlimited just because it reads the music pointer directly?
     
  5. MarkeyJester

    MarkeyJester ♡ ! Member

    Joined:
    Jun 27, 2009
    Messages:
    2,867
    Exactly my point EK, the same goes for SFX, and music control routines, the only limit is the ROM size limit.
     
  6. DarkLeach

    DarkLeach Well-Known Member Member

    Joined:
    Jul 3, 2011
    Messages:
    193
    Location:
    In the middle of desert heat
    What is the ROM size limit exactly? I remembered that S&K would reject a cart that would make the total larger than 4MB right? Or am I mistaken?
     
  7. EMK-20218

    EMK-20218 The Fuss Maker Exiled

    Joined:
    Aug 8, 2008
    Messages:
    1,067
    Location:
    Jardim Capelinha, São Paulo
    This is all I've always wanted. This is really impressive. For the most awesomeness, it's really easy to implement.. Thank you very much for this!

    it's 5MB. But every SMPS rarely reaches 4KB of size, so thousands of songs and sound effects are needed to reach all the ROM space. I'm sure that no one will have courage to do this.
     
    Last edited by a moderator: Apr 27, 2012
  8. amphobius

    amphobius spreader of the pink text Member

    Joined:
    Feb 24, 2008
    Messages:
    970
    Location:
    United Kingdom
    While I'm certain this is a great advantage, surely there's a few disadvantages, right?
     
  9. MarkeyJester

    MarkeyJester ♡ ! Member

    Joined:
    Jun 27, 2009
    Messages:
    2,867
    There is only 1 disadvantage I can think of, and it's not one the community would consider a disadvantage, SEGA surely did seem very concerned when it came to memory usage, which explains why every data in the ROM is kept as small as possible (i.e. everything is stored as bytes and reads up through a table of the large data), it's why the PCM samples in most SEGA games are ADPCM, and why they tend to reuse certain data over and over.


    The disadvantage caused by this is that you'll be moving a long-word of data to a data register instead of a byte, so the ROM will be 3 bytes bigger for every music/sound call in the ROM, I would've considered the actually routine for saving the long-word a disadvantage as it takes a little longer, but this is compensated when the sound driver doesn't need to unpack the ID like it used to, so it's about the same speed overall.
     
  10. DanielHall

    DanielHall Well-Known Member Member

    Joined:
    Jan 18, 2010
    Messages:
    860
    Location:
    North Wales
    5MB? Isn't it 4MB?
     
  11. vladikcomper

    vladikcomper Well-Known Member Member

    Joined:
    Dec 2, 2009
    Messages:
    415
    Actually, yes. All the official game cartridges were limited to 4 MB of ROM size, so do most of emulators, including Regen. The only known exception is Super Street Fighter II, which was 5 MB. However, addressed ROM space was still limited to 4 MB, and the game used the mapper to overpass this limitation. Mapper allowed the game to 'map' unreachable portions of ROM (after the 4th MB) into a visible address space. Addressing space was divided into 512 KB ROM banks and the mapper allowed to map 512 KB chunks of actual ROM chip to these banks.


    However, even this 4 MB limitation is cartridges' fault, not hardware's. The hardware is actually capable of addressing more than 4 MB of ROM data. It can work with 8 MB and even 10 MB ROMs. But the way cartridge board is designed doesn't allow to access addresses part 4th MB -- the processor will freeze waiting for the bus. I don't know exactly about the details of this 'design' and what exactly leads to this limitation (as I'm pretty unexperienced in how hardware works). I learned all this from HardwareMan's post -- this guy actually made a cartridge with extended adressed ROM space. Unfortunately, I can't seem to find his post now.
     
Thread Status:
Not open for further replies.