Dual PCM - FlexEd

Discussion in 'Utilities' started by MarkeyJester, Apr 13, 2019.

  1. MarkeyJester

    MarkeyJester ♡ ! Member

    Joined:
    Jun 27, 2009
    Messages:
    2,867
    Welcome,

    Today I would like to release the new Dual PCM, code-named; "FlexEd" (Flexible Edition).



    [​IMG]



    This is an upgraded version of the original Dual PCM released in 2016.

    I have showcased versions of this new Dual PCM in a few videos on YouTube, unfortunately they are out of date. I showcased it's features here, this too is out of date, but it's similar to the final version.

    The plan was to make a tutorial on implementing it into Sonic 1, but the driver has become so complex that many routines had been rewritten, I don't think an "upgrade" is possible without headaches. I would also need a tutorial to upgrade from the previous version. So the plan has changed.

    Because of the complexity, I have written a manual for the driver instead (the download link for the sound driver is in the manual itself):

    Download PDF

    This is just the PCM driver though, there is no 68k driver, the manual explains how to control Dual PCM using the 68k, it is mostly for those who have a 68k driver and need a decent PCM driver to use.

    However, knowing many of you are not technically minded, I will at least release a version of Sonic 1 with Dual PCM implemented. Some of Sonic 1's music has been updated to play the Timpani's on the second channel, but there are also some new example music tracks I made to showcase the driver, you might have seen them in some of the YouTube videos I made? You'll also have a sound test to play with, as well as another standalone ROM built for testing Dual PCM with DMA transfers. Think of this as an "apology" for not releasing the driver sooner or supplying any form of easy guide~

    Sonic 1 Test Driver

    Something to keep in mind!, many emulators are inaccurate, and due to inaccurate Z80 <-> 68k access timings, Dual PCM does not play at the correct pitch on many emulators, some even switching pitches extremely fast causing VHS like effects. Regen and the Gens series of emulators for example do not slow the Z80 down properly when it tries to access the window. BlastEm also has this issue, but it is mentioned in the emulators' "To-Do" list that this will be fixed, so I look forward to that~ (as luck would have it, he made a update about 3 weeks ago which resolves this issue, so there you go, move to BlastEm d=) Kega is one of the few that gets it right, but probably by accident. Bottom line, the driver was designed to sound good on hardware, and if the emulator does not emulate the timings right, it won't sound as good on the emulator, but that is unfortunately out of my hands, all I can recommend is... get a better emulator? *shrugs*

    --- --- --- --- --- --- --- ---

    Unfortunately, I don't think many will understand the power and significance this driver has, but I also don't want to oversell it either. It's not without its flaws, limitations have hit hard, but it's also not without its advances, and there is room for improvement. The one thing it does have an advantage over other drivers on, is its ability to avoid quality loss caused by DMA transfers, I've noticed many cool sound drivers being showcased in videos, but I've also noticed that they've neglected to showcase these sound drivers while a game is running in the background, one that use DMA transfers, so it paints a rather painful picture. Many sound drivers that play more than one sample neglect any sort of pitch/volume control or are 68k based. So this sound driver does have a place somewhere, unfortunately it's difficult to advertise it where its features make sense, but also without sounding like a pretentious fuck about it. As always, you'll have to make up your own mind.

    One thing I will say...

    I have rewritten this driver many times, and this latest incarnation is written carefully enough that adding a tracker system with FM and PSG playback (with the two PCM playback channels and all the features this driver has) should now be possible, and that will be my next goal. To have an entirely Z80 functional driver, with these powerful PCM playback channels. I know it'll work, but how long it'll take is another question, real life gets in the way, ya know? But I am optimistic.

    Anyways, if you are able to use this driver, then have fun~

    (Natsumi hes released her own 68k driver here, it uses this version of Dual PCM as its PCM playback driver, so if you want another option to use Dual PCM with, that will be another for you).
     
    Last edited: Apr 29, 2019
  2. EMK-20218

    EMK-20218 The Fuss Maker Exiled

    Joined:
    Aug 8, 2008
    Messages:
    1,067
    Location:
    Jardim Capelinha, São Paulo
    Without a "how to implement"? It's bad, unfortunately. But you have a really amazing stuff there though, Markey. I'm really impressed with the number of new functions it comes with. I wonder if anyone will be able to make use of all these functions in a hack anyway. Exactly as I could expect from you, it's a very nice job. I'm curious to see what will come with the Natsumi's driver too.
     
  3. Kilo

    Kilo Foxy Fren Exiled

    Joined:
    Oct 9, 2017
    Messages:
    391
    Location:
    A warm and lovely place~
    Read the manual.
    Edit: Although it isn't guiding you through everything, it give the basic idea.
     
  4. Devon

    Devon Down you're going... down you're going... Member

    Joined:
    Aug 26, 2013
    Messages:
    1,372
    Location:
    your mom
    The driver does not work properly on my console, because the YM queue will just not function. Having the buffer ID check prevents the SMPS driver from running at all and only PSG and PCM playback work without that check, no FM. I've tried both the ROM that came in that "Sonic 1 Test Driver" link and my own ROM with the driver installed.

    My console is a US 60 Hz MK-1601.
     
    ProjectFM likes this.
  5. MarkeyJester

    MarkeyJester ♡ ! Member

    Joined:
    Jun 27, 2009
    Messages:
    2,867
    Natsumi has reported issues with her Japanese system, we were actually looking as to why it was happening.

    The closest we've got is to do with the Z80 and V-blank interruption, but we cannot be quite sure. Given that your "MK-1601" is referred to as the "Altered beast" version, I assume it's age is having exactly the same issue as Natsumi's original Japanese model.

    Bottom line, you'll have to wait until we can figure out exactly what the problem is, it's very console age specific, something that was fixed very early on in the Mega Drive's life span, unfortunately, I do not own a really, really, old model, so testing is gonna be slow.
     
  6. MarkeyJester

    MarkeyJester ♡ ! Member

    Joined:
    Jun 27, 2009
    Messages:
    2,867
    Double post; so we think we might have found the cause. I do not know if this is your issue, but this was hers, so there is a chance it'll be yours too.

    I didn't set the "im" (interrupt mode).

    The Z80 has three different modes, I was experimenting with them to allow quicker control over the interrupt routine, unfortunately, many emulators did not support modes 0 and 2, only 1. So the method works on my hardware, but not on many common emulators, so I had to ditch this method and find a different method.

    Most Mega Drive game sound drivers for the Z80 set the mode to 1. This mode causes the Z80 to perform an "rst 38h" instruction, basically forcing the Z80 to interrupt to offset 38 for its V-blank routine when the VDP triggers it. Setting the mode to 0 causes the Z80 to perform an instruction, but not the "rst 38h", instead it'll process whatever instruction a "interrupting device" will give to it, and in the Mega Drive's case, the Z80's "interrupting device" is the VDP. The VDP will give the Z80 the instruction "rst 38h" anyways, so setting the interrupt mode to 1 or 0 would cause the exact same effect.

    So common sense would say, why bother setting the interrupt mode to 1 and waste an instruction, might as well leave it as 0.

    Well it turns out that for the original Mega Drive models, their VDP does not give the Z80 this instruction at all, we can only assume that either the VDP gives the Z80 a byte instruction which happens to have little to no effect, or the Z80 is processing whatever byte happens to be there when the interrupt triggers, and again, it's having little to no effect. If V-blank does not run, then the YM2612 queue does not get processed (hence no FM), and the volume change mechanism isn't updated.

    So to fix the issue, simply put in an "im 1" right after the first "di" instruction, because of the alignments, this should not cause any address changes, so the addresses should remain the same for anyone following the pre-assembled manual. I'll update the drivers for download soon.

    Ralakimus, let me know if this fixes your issue, if it does, then this concludes that it's not just the original Japanese model.

    EDIT: It seems GerbilSoft has just now confirmed our theory here: http://sonicresearch.org/community/index.php?threads/hardware-emulator-quirks.4147/page-2#post-81688
     
    Last edited: Apr 16, 2019
    Devon and AURORA☆FIELDS like this.
  7. Devon

    Devon Down you're going... down you're going... Member

    Joined:
    Aug 26, 2013
    Messages:
    1,372
    Location:
    your mom
    Yup, it works great on my console now.
     
  8. Devon

    Devon Down you're going... down you're going... Member

    Joined:
    Aug 26, 2013
    Messages:
    1,372
    Location:
    your mom
    Edit: NEVERMIND I AM DUMB

    Perhaps, I should learn to actually look hard enough for things...
     
    Last edited: Apr 26, 2019
  9. MarkeyJester

    MarkeyJester ♡ ! Member

    Joined:
    Jun 27, 2009
    Messages:
    2,867
    An update~

    OK so, the volume table I supplied, although it's logarithmically (exponentially) calculated, it isn't 100% matched to the YM2612's FM volume logarithm.

    As you might be aware, I've been doing a lot of research and emulation practices with the YM2612, and have recently created a logarithmic table for emulating the YM2612's FM volume, and it is extremely accurate to real hardware. I've adapted the emulated table for Dual PCM's volume table to correct it.

    You can download the new volumes table here. Now the PCM volume will match the FM volume. Keep in mind, if you've written music and changing the volumes on the PCM channels as part of your music, you may need to adjust them again, as you've been basing them on the wrong logarithmic values. My apologies for that, but once you've adapted it to this new table, you'll never need to adapt it ever again since the table is practically 1:1 to hardware's FM logarithm.

    I will NOT update the driver examples, since the sample music is still based on the original volume table, and I don't have time to update those (some of the music is in binary, and I can't be bothered sifting through with a hex editor again).

    Also to keep in mind, the sound driver code I wrote, might be decreasing the PCM's volume such that the original logarithm works 100% perfectly aligned with FM, so the new table will break that. I don't remember exactly what I did, and I don't really have time to check. If you are using AMPS though, this new table will definitely work fine for your project (you still need to make adjustments to any music you've made where you use the volume heavily though).
     
    Last edited: Aug 1, 2019
    FохConED and ProjectFM like this.
  10. SMS Alfredo

    SMS Alfredo Compact Disc Enthusiast Member

    Joined:
    Sep 3, 2018
    Messages:
    27
    Location:
    Little Planet
    Maybe this is kind of a dumb question, but how would one go about installing this into AMPS?

    I would like to do that, but I have no idea what to replace. There isn't a single bin file in the driver. It's all asm.

    Sorry to bother you, but thanks for reading.
     
  11. Devon

    Devon Down you're going... down you're going... Member

    Joined:
    Aug 26, 2013
    Messages:
    1,372
    Location:
    your mom
    AMPS already uses Dual PCM.

    EDIT: Oops, I missed the context.
     
    Last edited: Aug 6, 2019
    AURORA☆FIELDS likes this.
  12. SMS Alfredo

    SMS Alfredo Compact Disc Enthusiast Member

    Joined:
    Sep 3, 2018
    Messages:
    27
    Location:
    Little Planet
    Oh sorry, I should have specified. I meant install the new volume table into the DualPCM within AMPS.
     
  13. AURORA☆FIELDS

    AURORA☆FIELDS so uh yes Exiled

    Joined:
    Oct 7, 2011
    Messages:
    759
    Go to driver/filters, and open Logarithmic.dat, copy and paste the new volume table over the old one, build & adjust the PCM volumes and fades to match.
     
    ProjectFM and AkumaYin like this.
  14. Devon

    Devon Down you're going... down you're going... Member

    Joined:
    Aug 26, 2013
    Messages:
    1,372
    Location:
    your mom
    Just something really small and probably rather insignificant, but while I was reading through the technical manual so that I can implement my own routines and stuff for a future project, I noticed that the example for writing to multiple YM registers in the queue has the address and data values swapped.
    [​IMG]
     
    AkumaYin likes this.
  15. MarkeyJester

    MarkeyJester ♡ ! Member

    Joined:
    Jun 27, 2009
    Messages:
    2,867
    Originally, the data and address bytes were in order "Part, Address, Data". But the data and address bytes were reversed to increase Z80 CPU speed, but the manual was not updated correctly.

    If you find any other issues, please PM me instead of making a post, minor manual issues are mild enough that I can clean them up without needing to emergency updating everyone.
     
    ProjectFM likes this.
  16. Devon

    Devon Down you're going... down you're going... Member

    Joined:
    Aug 26, 2013
    Messages:
    1,372
    Location:
    your mom
    Alrighty, I'll keep that last bit in mind. Sorry.
     
  17. MarkeyJester

    MarkeyJester ♡ ! Member

    Joined:
    Jun 27, 2009
    Messages:
    2,867
    Update:

    (I won't update this fix on the download, I've been ripping the driver appart and putting it back together in various ways, so it's difficult to keep track of what the release has and what the new version has).

    There is a minor fix you can perform, this fix will reduce the amount of pop that occurs when a sample starts or loops, it's a rare pop, but this should eliminate it for this instance.

    At "BreakPrep:", you will see:
    Code:
    		ld	a,011000111b|BreakLate		; 07	; prepare "rst" instruction
    		ld	(Int1_nop),a			; 13	; change instructions
    		ld	(Int2_nop),a			; 13	; ''
    		ld	(Int1_lda),a			; 13	; ''
    		ld	(Int2_lda),a			; 13	; ''
    		ld	(Int1_jp),a			; 13	; ''
    		ld	(Int2_jp),a			; 13	; ''
    		ld	(Int1_ldhl),a			; 13	; ''
    		ld	(Int2_ldhl),a			; 13	; ''
    Put this on the end:
    Code:
    		ld	(PCM1_ResQuo),a			; 13	; ''
    		ld	(PCM2_ResQuo),a			; 13	; ''
    Then at "BDMA_NoRestore:" (just before it), you will see:
    Code:
    		xor	a				; 04	; prepare "nop" instruction
    		ld	iyh,a				; 08	; clear restore mode
    		ld	(Int1_nop),a			; 13	; change instructions
    		ld	(Int2_nop),a			; 13	; ''
    		ld	a,07Eh				; 07	; prepare "ld  a,(hl)" instruction
    		ld	(Int1_lda),a			; 13	; change instructions
    		ld	(Int2_lda),a			; 13	; ''
    		ld	a,0C3h				; 07	; prepare "jp" instruction
    		ld	(Int1_jp),a			; 13	; change instructions
    		ld	(Int2_jp),a			; 13	; ''
    		ld	a,077h				; 07	; prepare "ld  (hl),a" instruction
    		ld	(Int1_ldhl),a			; 13	; change instrucitons
    		ld	(Int2_ldhl),a			; 13	; ''
    Put this on the end:
    Code:
    		ld	a,031h				; 07	; prepare "ld  sp,0????h" instruction
    		ld	(PCM1_ResQuo),a			; 13	; change instrucitons
    		ld	(PCM2_ResQuo),a			; 13	; ''
    I do have a few more updates, but they aren't worth sharing, they do however change the way the driver functions in minor ways. For example, the newest version will disable DAC and enable FM6 if no samples are played on either channel, but this requires a change of the 68k driver in a somewhat minor albeit annoyingly obtuse way. If there's enough demand for it, I will look into providing a full update for it, but I don't feel the need to waste time otherwise.
     
    ProjectFM and EMK-20218 like this.
  18. Devon

    Devon Down you're going... down you're going... Member

    Joined:
    Aug 26, 2013
    Messages:
    1,372
    Location:
    your mom
    Ooh, I'd certainly make use for it in my sound driver.
     
    ProjectFM likes this.
  19. breakthetargets

    breakthetargets Well-Known Member Member

    Joined:
    Aug 6, 2009
    Messages:
    180
    Yeah, that would actually be very useful.