don't click here

SMPS2ASM and improved S&K Driver

Discussion in 'Engineering & Reverse Engineering' started by flamewing, Nov 5, 2011.

  1. Varion Icaria

    Varion Icaria

    He's waiting.... Tech Member
    1,019
    11
    18
    S4: Cybernetic Outbreak
    Sorry for the month bump. My S3K disassembly doesn't use AS it uses ASM68K. How would I go about incorporating this into mine?
     
  2. Cinossu

    Cinossu

    Administrator
    2,832
    44
    28
    London, UK
    Sonic the Hedgehog Extended Edition
    A four month bump? From an admin? Preposterous!

    ANYWAY :U I was wondering if you, flamewing, would consider releasing the actual converter tool you used (if you did) for songs into this format. I have interest in it for converting Knuckles Chaotix songs into this format, and have already got them working with the engine flawlessly (as it is essentially the same SMPS engine, including the co-ordination flag set, just with 4 channel PWM instead of DAC).

    As an additional question, and if there is no such tool/you are unwilling to release it, do you by any chance have a version of the Sonic 3 LE Credits medley (the one with the Sonic 3 and Sonic & Knuckles zone musics)?

    Yes, I know it's a bump for questions, but this project can always do with bumping for viewing purposes. :v:
     
  3. flamewing

    flamewing

    Emerald Hunter Tech Member
    1,161
    65
    28
    France
    Sonic Classic Heroes; Sonic 2 Special Stage Editor; Sonic 3&K Heroes (on hold)
    Yeah, I can release it. Let me just modify it so you can also dump S1/S2 songs in a more S3&K-format (as in, chained rests always print the rest note also) and undo the related bugfix (since at least SSZ song and the S3 miniboss song need it to work) and I will release it; it will probably be this weekend.

    FYI, the tool is still unmodified from the first post; I have neglected working on it.
     
  4. flamewing

    flamewing

    Emerald Hunter Tech Member
    1,161
    65
    28
    France
    Sonic Classic Heroes; Sonic 2 Special Stage Editor; Sonic 3&K Heroes (on hold)
    v3 is out. The changes are:
    • Due to its effects in some S3, S&K and S3D songs, I undid the following bugfix:
      • [bugfix] original S3/S&K/S3D driver could not correctly handle playing the sequence "<note>, <duration>, $80, <duration>, <duration>", and would play <note> again instead of a rest.
    • S1 and S2 songs that were affected by the previous change got a new version that explicitly puts a $80 before the duration of each rest;
    • The "_spms2asm_inc.asm" file now handles the differences in modulation flags that are explained in this post by ValleyBell;
    • I have made a release of the SMPS2ASM tool.
    For the SMPS2ASM tool, I am providing a Windows binary; for those of you that don't use Windows, I am also providing the source code; it is bundled with the source code of my S2 Special Stage editor, which you can nab here.

    Edit: FYI, SMPS2ASM is a command-line utility.
     
  5. kram1024

    kram1024

    Researcher / Hacker Oldbie
    63
    1
    6
    at home, duh
    Part of the new Team Revamped; Kraminator Special Series disassemblies; Sonic 3 Sound Driver porting guides; KENS 1.5; smps studio; various non-sonic related things
    sorry for the long time bump, but I got a very strange error when trying to compress it into a sonic1 rom:
    and what it is saying is impossible, the value is set higher than that:
    Code (Text):
    1.  
    2. Size_of_Snd_driver_guess = $1580
    3.         CPU 68000
    4.         padding off ; we don"t want AS padding out dc.b instructions
    5.         listing off ; we don"t need to generate anything for a listing file
    6.         supmode on  ; we don"t need warnings about privileged instructions
    7.        
    8.         include "sonic1.macrosetup.asm"
    9.  
     
  6. flamewing

    flamewing

    Emerald Hunter Tech Member
    1,161
    65
    28
    France
    Sonic Classic Heroes; Sonic 2 Special Stage Editor; Sonic 3&K Heroes (on hold)
    Is the constant being redefined to a lower value somewhere else?
     
  7. kram1024

    kram1024

    Researcher / Hacker Oldbie
    63
    1
    6
    at home, duh
    Part of the new Team Revamped; Kraminator Special Series disassemblies; Sonic 3 Sound Driver porting guides; KENS 1.5; smps studio; various non-sonic related things
    in hivebrain 2005 sonic 1 with some added macros from the hg sonic 3 disasm? I did a search and could not find any
     
  8. Cinossu

    Cinossu

    Administrator
    2,832
    44
    28
    London, UK
    Sonic the Hedgehog Extended Edition
    A big bump, and by an admin as well. What is the world coming to? :U

    A relevant one, though, as it's a question about said driver; I've (finally) got this lovely thing working in Sonic 1 (and have been extending its functionality, namely multi-bank PCM sample playing with the limited z80 knowledge I have), however the Special Stage music, which uses 6 FM Channels rather than 5 FM Channels and 1 DAC, refuses to have its 6th FM channel play anything at all.

    As previously mentioned, I have very limited z80 knowledge (at the moment, learning on the fly here) and wouldn't know where to start looking where to debug this. I have noticed that even though the Chaos Emerald sound in S3K uses the same thing (6 FM Channels) it sounds like it never played properly in the original ROM either. Is this a "feature" of the S3K Driver, or something that broke and is easily fixed?
     
  9. flamewing

    flamewing

    Emerald Hunter Tech Member
    1,161
    65
    28
    France
    Sonic Classic Heroes; Sonic 2 Special Stage Editor; Sonic 3&K Heroes (on hold)
    The S1 and S2 sound drivers both reserve enough space for 1 DAC + 6 FM + 3 PSG tracks in music. They update all tracks that are playing when needed, and initialize the FM6 or DAC channel as needed by the song.

    The S3&K driver, however, only sets aside enough RAM for 1 DAC + 5 FM + 3 PSG tracks in music. The DAC track is only ever updated as a DAC track, and never as an FM track; the DAC is toggled on/off if there is a DAC sample to be played or finished playing. You are correct that the Chaos Emerald song is broken in the sense that it does not play all tracks; track FM6 is overwritten by the PSG1 track during load. I had noticed it when I made my version of SMPS2ASM, but didn't think to mention it here (which would have saved you some trouble).

    The driver itself has precious little RAM left in the z80's 2KB RAM; it would take at last $60 bytes to add extra channels like in S1/S2 drivers, plus any needed code changes (which include disabling both DAC and FM6 channels from music in order to play track FM6 for SFX).

    Another less RAM-hungry possibility would be to add code to update the FM6/DAC channel selectively as an FM or DAC channel; the song would need to have the FM6 channel in place of the DAC channel (instead of having a stub DAC channel and 6 FM channels as the case for S1/S2 drivers) and there would be the need to differentiate the channel as being DAC or FM (maybe a bit flag).
     
  10. Tiddles

    Tiddles

    Diamond Dust Tech Member
    471
    0
    0
    Leicester, England
    Get in an accident and wake up in 1973
    One thing I did to get some free Z80 RAM back was to move all the music and SFX bank and pointer tables out of Z80 RAM, attaching them instead to the end of every music and sound bank in ROM, similar to the way the DAC pointers all sit at the top of every DAC bank. You can modify/add macros to splat that out fairly easily, though of course it means you have less space in each bank. I chose to locate them at $7D00 in each bank, which gives quite a bit of room to extend the number of pointers if you want to.
     
  11. I don't have the Sonic 3 driver on hand right now to test myself, but roughly how much ram does this save? For my current project, I need enough ram to implement the additional FM Channel as well as 4xPWM channels for the 32X
     
  12. Tiddles

    Tiddles

    Diamond Dust Tech Member
    471
    0
    0
    Leicester, England
    Get in an accident and wake up in 1973
    Difficult to say as a comparison to the original setup, as I have much bigger indexes than usual already, but looking at my output, I am using just shy of the entire $300 bytes I allocated in my end-of-bank clearout (which rather explains why expanding the sound index further wasn't working out!) so that's how much more I'd have to use in Z80 RAM if they weren't there.

    You will save somewhat less than that given non-bloated bank and pointer tables, but it's still a decent chunk - wish I could remember the original sizes of those to give more info. To clarify, the four things I moved are DAC bank pointers, SFX data pointers, music bank and data pointers. To some extent it depends what you want to do - if you need more space there are probably more tables you can move to duplicating in ROM banks.

    Guess I probably need to pull it back to $7C00 next time!
     
  13. Cinossu

    Cinossu

    Administrator
    2,832
    44
    28
    London, UK
    Sonic the Hedgehog Extended Edition
    With a fancy bit of my own shuffling around of things, I actually got this working fairly simply; the one problem I had (until I solved it this morning) was with pausing the FM6 and not killing the DAC when not in use.

    However, everything is all happy now. :> Yay, it's all working~

    .. now to see if I can get S1/2-style modulation toggleable.. portamentos.. making the coffee..
     
  14. flamewing

    flamewing

    Emerald Hunter Tech Member
    1,161
    65
    28
    France
    Sonic Classic Heroes; Sonic 2 Special Stage Editor; Sonic 3&K Heroes (on hold)
    This one has been a long time in the making; triple update time!

    New version of the sound driver is available: grab v2a here.
    New version of SMPS2ASM is available: grab v0.2 here.
    New version of the song pack is available: grab v4a here.

    Changes:
    • driver: now with support for playing songs with 6 FM channels and no DAC channels;
    • driver: universal voice bank (UVB) is now included in every music bank; while this reduces the space in banks, this allows much more freedom for expanding the sound driver;
    • driver: UVB has been SMPS2ASM'ed;
    • driver: all fixes and changes are now always on;
    • driver: driver makes use of local labels (instead of nameless temporaries) and uses S2-style memory management for the z80 RAM (instead of hard-coding everything);
    • driver: several new coordination flags and fixes based on other drivers from ValleyBell's research pack; specifically:
      • meta CF $FF08 (smpsChanTempoDiv) which works like CF $E5 in S1/S2 drivers;
      • meta CF $FF09 (smpsChanFMCommand) that allows sending FM commands to the appropriate YM2612 part for the current track;
      • meta CF $FF0A (smpsNoteFill) that works like $E8 did in S1/S2 drivers;
      • meta CF $FF0B (smpsPitchSlide) that allows you to do pitch slides (use smpsAlterPitch to set slide speed);
      • meta CF $FF0C (smpsSetLFO) that lets you enable/disable the LFO and set AMS and FMS.
    • SMPS2ASM: can now dump z80 banks given an offset to a pointer table within the bank;
    • SMPS2ASM: simple dataflow analysis added to propagate key displacement changes throughout a track; this is used to fix the handling of the maximum-frequency PSG note (since it is different in S1/S2 and S3/S&K/S3D drivers);
    • song pack: redumped all songs with the new SMPS2ASM;
    • song pack: S3, S&K and S3D songs (and SFX for S&K) now have two versions: the 1:1 versions with unused data and the "optimized" versions without it; the optimized versions also have ALZ song fixed.

    A warning: songs dumped with the new SMPS2ASM MUST be used with the "_smps2asm_inc.asm" file present on the sound driver file; earlier versions of the include file will fail. Moreover, I strongly recommend that you redump old songs so that they sound correct due to the PSG maximum-frequency note issue mentioned above.

    To use the driver, you will need to either use the constants for zQueueVariables, zMusicNumber, zSFXNumber0 and zSFXNumber1 like what is descriped in Alriightyman's guide to use it in S2 or use the exported symbols for these constants to reference the correct z80 variables.

    Edit: Note: the SMPS2ASM release is essentially a bugfix release; I have more things planned, but I wanted to get this out the door because it affects a lot of people.
     
  15. RetroKoH

    RetroKoH

    Member
    1,662
    22
    18
    Project Sonic 8x16
    I never noticed this in the past... I may look into this for use in my Sonic 1 hack. While knowing exactly how to convert sounds and stuff would be better for me personally, I love the idea of being able to backport something that is arguably superior.
     
  16. nineko

    nineko

    I am the Holy Cat Tech Member
    6,298
    475
    63
    italy
    I wonder how hard it would be to have a version without the UVB at all. While important for the songs from S3&K, it's a waste of space if one uses songs from S1/2 or custom songs for the most part. An alternative idea: a tool which runs through all the used songs, scanning for their instruments, to create a custom bank to be used instead of the standard UVB. I did something similar when I researched the Cube driver, which uses a global instrument bank similarly (except it's mandatory unlike the UVB), so I made that when you used songs from different Cube games, a new instrument bank was created (and instrument flags in the songs changed accordingly).
     
  17. flamewing

    flamewing

    Emerald Hunter Tech Member
    1,161
    65
    28
    France
    Sonic Classic Heroes; Sonic 2 Special Stage Editor; Sonic 3&K Heroes (on hold)
    The driver without the UVB is a simple matter of not including the UVB in any bank in which it is not used; if no songs use the UVB, you won't have to include it anywhere and it won't take up any space. Moreover, the new setup actually would allow custom "U"VBs for each bank — since each bank has its own copy of the UVB, you could make a voice bank shared by the bank's songs with all of their voices, include it in said bank instead of the UVB, and use it as if it were the UVB. You would still need to redo the FM channels to set the correct voices, though, as there currently* is no way to define voice banks to use.

    As for the songs that use the UVB: I suppose I could add a flag that dumps a song stripping its UVB dependency and including the relevant voices in the song itself.

    * I am working on changing that, as well as a load of similar things.
     
  18. nineko

    nineko

    I am the Holy Cat Tech Member
    6,298
    475
    63
    italy
    Oh wow that's good to know, sorry about my previous post, I made it from my phone without actually trying the thing and I didn't know it could work in such a way and the UVB inclusion isn't mandatory. Furthermore, that's actually a very interesting setup to have, with a different "CVB" (the "C" can stand for both "Custom" or "Common") per each song bank, I really think it's an operative mode worth pursuing, especially in cases where common instruments are shared amongst several custom songs (which is what most xm3smps / mid2smps users tend to do, afaik, choosing instruments from a selection of a few dozens in most cases). I can look into making such a "bank preparer" tool, since as I said I already did something similar for Cube once, and I guess it wouldn't be that hard to make something similar for SMPS. I imagine it as a window where you can drag a selection of songs and let the tool find out the needed instruments, fixing the instrument flags within each song accordingly (and setting the voice pointer in the header to... whatever value it should be set to). Sadly, since I suck at parsing SMPS, I'd probably make it support only the Sonic 1 SMPS format, so I'm not sure how useful it would be. Then again I can always open source the code so someone better than me can improve it. (Then again)² I'd write it in Visual Basic, making its source code useless to most people here who prefer other languages. I hate when I want to help, but I realise my skills aren't up to the game.
     
  19. MainMemory

    MainMemory

    Kate the Wolf Tech Member
    4,735
    334
    63
    SonLVL
    There's a version (not sure if it's publicly available yet) of Valley Bell's SMPSConv tool that will do that if you provide a UVB file and convert a song S3K-S3K.
     
  20. flamewing

    flamewing

    Emerald Hunter Tech Member
    1,161
    65
    28
    France
    Sonic Classic Heroes; Sonic 2 Special Stage Editor; Sonic 3&K Heroes (on hold)
    For what is worth, I was quite the accomplished VB6 hacker back in the day, to the point of being able to do things like splice in [url=inline assembly in VB6. So if you wrote it in VB6, I could use it as a base to translate into C++ without issue.