How to operate Jman's Uncompressed PCM playback Z80 driver!

Discussion in 'Tutorials Archive' started by MarkeyJester, Feb 25, 2012.

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

    MarkeyJester ♡ ! Member

    Joined:
    Jun 27, 2009
    Messages:
    2,870
    In this tutorial, we look at using Jman2050's Z80 driver in Sonic 1, but with modifications to allow up to 5F samples.

    Step 01 - Removing the old Z80 software




    Because Jman's driver is capable of doing what the original Sonic 1 Driver can, we no longer need it, so we'll start by removing the incbin's in the source, open "sonic1.asm" and find the following code below:



    Code:
    Kos_Z80:	incbin	soundz80_1.bin
    
    		dc.w ((SegaPCM&$FF)<<8)+((SegaPCM&$FF00)>>8)
    
    		dc.b $21
    
    		dc.w (((EndOfRom-SegaPCM)&$FF)<<8)+(((EndOfRom-SegaPCM)&$FF00)>>8)
    
    		incbin	soundz80_2.bin
    
    		even


    Simply delete those lines, we no longer need them, the next thing to do is to go into the "sound" folder, and delete the following files:



    "z80_1.bin"

    "z80_2.bin"




    http://info.sonicret..._the_SEGA_Sound



    This will ensure that the 68k handles the SEGA playback rather than the Z80, so the SEGA sound will be of no trouble to us.




    http://mrjester.hapi...blic/KOSZ80.bin

    http://mrjester.hapi...blic/S1Kick.wav

    http://mrjester.hapi...lic/S1Snare.wav

    http://mrjester.hapi...c/S1Timpani.wav



    KOSZ80.bin is Jman's Z80 sound driver (with a table address modification I put in), and the .wav files are the Sonic 1 samples, all of the samples are; 8-bit, unsigned, mono, and can be opened with a sound player supplied with your operating system (i.e. they're just PCM samples with wave file format headers).






    Code:
    loc_71C84:
    
    		jsr	sub_71D40(pc)
    
    
    
    loc_71C88:
    
    		move.l	a4,4(a5)
    
    		btst	#2,(a5)
    
    		bne.s	locret_71CAA
    
    		moveq	#0,d0
    
    		move.b	$10(a5),d0
    
    		cmpi.b	#$80,d0
    
    		beq.s	locret_71CAA
    
    		btst	#3,d0
    
    		bne.s	loc_71CAC
    
    		move.b	d0,($A01FFF).l
    
    
    
    locret_71CAA:
    
    		rts	
    
    ; ===========================================================================
    
    
    
    loc_71CAC:
    
    		subi.b	#$88,d0
    
    		move.b	byte_71CC4(pc,d0.w),d0
    
    		move.b	d0,($A000EA).l
    
    		move.b	#$83,($A01FFF).l
    
    		rts	
    
    ; End of function sub_71C4E
    
    
    
    ; ===========================================================================
    
    byte_71CC4:	dc.b $12, $15, $1C, $1D, $FF, $FF
    
    
    
    ; ||||||||||||||| S U B	R O U T	I N E |||||||||||||||||||||||||||||||||||||||
    
    
    
    
    
    sub_71CCA:				; XREF: sub_71B4C


    Replace that code with:





    Code:
    loc_71C84:
    
    		jsr	sub_71D40(pc)
    
    
    
    loc_71C88:
    
    		move.l	a4,4(a5)
    
    		btst	#2,(a5)
    
    		bne.s	locret_71CAA
    
    		moveq	#$00,d0					; MJ: clear d0
    
    		move.b	$10(a5),d0				; MJ: load the note
    
    		cmpi.b	#$80,d0					; MJ: is it 80 (Null)?
    
    		beq.s	locret_71CAA				; MJ: if so, branch
    
    		moveq	#$FFFFFF81,d1				; MJ: prepare 81 (starting note ID)
    
    		sub.b	d1,d0					; MJ: minus 81 from note
    
    		move.b	d1,($A01FFF).l				; MJ: set to play sample 81
    
    		jmp	PCMTableLoad				; MJ: load the correct table for Z80 to read
    
    
    
    locret_71CAA:
    
    		rts						; MJ: return
    
    
    
    ; ===========================================================================
    
    
    
    sub_71CCA:


    Please be aware that "PCMTableLoad" doesn't exist "yet". Next, go down to "EndOfRom:" and just above that put in the following:





    Code:
    ; ===========================================================================
    
    ; ---------------------------------------------------------------------------
    
    ; MarkeyJester's PCM Table Switcher
    
    ; ---------------------------------------------------------------------------
    
    
    
    PCMTabLod:	include	"Z80/PCMTableLoad.asm"
    
    		even
    
    
    
    ; ===========================================================================


    This will be the include to my software, next up, in the folder "Z80" make a new asm file named "PCMTableLoad.asm" and inside that asm file you'll want to put this in:





    Code:
    ; ===========================================================================
    
    ; ---------------------------------------------------------------------------
    
    PCM:		macro	Pitch, Location
    
    		dc.w	(((((Location&$000000FF)<<$08)+((Location&$00007F00)>>$08))!$0080)&$FFFF)
    
    		dc.w	(((((((Location_End-$02)-Location)&$000000FF)<<$08)+((((Location_End-$02)-Location)&$00007F00)>>$08))/$02)&$FFFF)
    
    		dc.b	Pitch
    
    		dc.b	((Location&$00008000)>>$08)
    
    		dc.b	((Location&$003F0000)>>$10)
    
    		dc.b	$00
    
    		even
    
    				endm
    
    ; ---------------------------------------------------------------------------
    
    incpcm:		macro	File
    
    		if ((*+filesize("Z80/File.wav"))&$FF8000)>(*&$FF8000)
    
    			align $8000
    
    		endc
    
    		if (*+filesize("Z80/File.wav"))>($803A-$02)
    
    File:			incbin	"Z80/File.wav", $3A, $8000-$02
    
    			dc.b	$80,$80
    
    File_End:		even
    
    		else
    
    File:			incbin	"Z80/File.wav", $3A
    
    			dc.b	$80,$80
    
    File_End:		even
    
    		endc
    
    		endm
    
    NULL:
    
    NULL_End:
    
    ; ---------------------------------------------------------------------------
    
    ; ===========================================================================
    
    ; ---------------------------------------------------------------------------
    
    ; PCM Playback Driver (Z80)
    
    ; ---------------------------------------------------------------------------
    
    
    
    Kos_Z80:	incbin	"Z80/KOSZ80.bin"
    
    		even
    
    
    
    ; ===========================================================================
    
    ; ---------------------------------------------------------------------------
    
    ; Z80 Table Switcher Routine
    
    ; ---------------------------------------------------------------------------
    
    
    
    PCMTableLoad:
    
    		lea	PCM_Table(pc),a0			; MJ: load the PCM table address to a0
    
    		lea	($A00150).l,a1				; MJ: load the Z80 area to dump the table
    
    		lsl.w	#$03,d0					; MJ: multiply sample ID by 8
    
    		lea	(a0,d0.w),a0				; MJ: add to table address
    
    		move.b	(a0)+,(a1)+				; MJ: dump data to Z80 table
    
    		move.b	(a0)+,(a1)+				; MJ: ''
    
    		move.b	(a0)+,(a1)+				; MJ: ''
    
    		move.b	(a0)+,(a1)+				; MJ: ''
    
    		move.b	(a0)+,(a1)+				; MJ: ''
    
    		move.b	(a0)+,(a1)+				; MJ: ''
    
    		move.b	(a0)+,(a1)+				; MJ: ''
    
    		move.b	(a0)+,(a1)+				; MJ: ''
    
    		rts						; MJ: return
    
    
    
    ; ===========================================================================
    
    ; ---------------------------------------------------------------------------
    
    ; PCM Table Data
    
    ; ---------------------------------------------------------------------------
    
    
    
    PCM_Table:
    
    		PCM	$19, S1Kick				; 81 ; Beat
    
    		PCM	$04, S1Snare				; 82 ; Snare
    
    		PCM	$1B, S1Timpani				; 83 ; Timpani (low)
    
    		PCM	$00, NULL				; 84 ; Blank (Free)
    
    		PCM	$00, NULL				; 85 ; Blank (Free)
    
    		PCM	$00, NULL				; 86 ; Blank (Free)
    
    		PCM	$00, NULL				; 87 ; Blank (Free)
    
    		PCM	$12, S1Timpani				; 88 ; Timpani (hi)
    
    		PCM	$15, S1Timpani				; 89 ; Timpani (mid)
    
    		PCM	$1B, S1Timpani				; 8A ; Timpani (low)
    
    		PCM	$1D, S1Timpani				; 8B ; Timpani (lower)
    
    		PCM	$00, NULL				; 8C ; Blank (Free)
    
    		PCM	$00, NULL				; 8D ; Blank (Free)
    
    		PCM	$00, NULL				; 8E ; Blank (Free)
    
    		PCM	$00, NULL				; 8F ; Blank (Free)
    
    
    
    ; ===========================================================================
    
    ; ---------------------------------------------------------------------------
    
    ; includes
    
    ; ---------------------------------------------------------------------------
    
    
    
    		incpcm	S1Kick
    
    		incpcm	S1Snare
    
    		incpcm	S1Timpani
    
    
    
    ; ===========================================================================


    This software is designed to tell jman's player to play DAC sample ID 81, but it changes the table information so that ID 81 will play differently depending on the ID that the SMPS DAC channel gives out. That's it basically.




    • Make sure your sample is .wav

    • Make sure it is 8-bit, unsigned and mono

    • When giving it a name, make sure there are no spaces in it's name

    • Place it inside the "Z80" folder



    To include it and use it in the software, as an example, we'll pretend you named your wav file "BigDrum.wav":
    • Open up "PCMTableLoad.asm"

    • Go down to "; includes" and put in:



    Code:
       	 incpcm	BigDrum
    • Go to "PCM_Table:" and find a free slot (a.k.a. "PCM $00, NULL")

    • Change NULL to the name of your wav file (in our example it'll be BigDrum)

    • Change $00 to the pitch you want your sample to play at ($01 is the highest pitch, $FF is the lowest pitch)



    Code:
       	 PCM	$05, BigDrum		   	 ; 84 ; Big Drum


    From now on, if your SMPS track plays the ID 84 on the DAC channel, that sample will play. Another thing to note is that the table isn't limited to "8F" you can insert a new line on the end if you wanted to go higher:





    Code:
       	 PCM	$03, SlowScratch		   	 ; 90 ; Scratch
    
       	 PCM	$06, HiHat		   	 ; 91 ; Hi-Hat

    You're limit is "DF" (5F samples) because the SMPS engine doesn't allow notes higher than "DF" ("E0" to "FF" are flags, and "00" to "7F" are timers).


    Banking isn't required, the Macro instructions you see at the top will take care of aligning the PCM data correctly and including it properly without the WAV header info in the way.

    Step 02 - Sorting out the SEGA logo PCM




    Now because we have removed the old driver, the SEGA sound will no longer play, so it is recommended you follow the guide written by puto on Sonic Retro known as "how to Fix the SEGA sound", found here:



    Step 03 - Inserting the new driver




    Make a new folder in your disassembly and name it "Z80", this will be the place where we'll put the Z80 driver, the software and the drum samples. Once you have made the folder, put these files inside it:



    Step 04 - Inserting new software




    Now, this software is my software, I wrote this up to make it easy to use, and to bypass the 20 sample limit. Firstly, you'll need to open up "sonic1.asm" again and search for:



    Step 05 - How to use




    Using it is simple, if you want to insert a sample to it:
     
    Last edited by a moderator: Apr 22, 2012
  2. Pokepunch

    Pokepunch That guy who posts on occasion Member

    Joined:
    Aug 7, 2009
    Messages:
    270
    Location:
    UK
    As I said in BQ&A thank you.
     
  3. SSGD

    SSGD "I can't believe what cool boots you have on!" Member

    Joined:
    Nov 14, 2011
    Messages:
    125
    Location:
    Room 101
    I just wondering, would this aid in the use of creating voice samples in game as well? What I mean by this is for example, in Golden Axe when a enemy dies he/she will use a recorded scream sound that plays back from the use of the PCM, so could I also use a voice sample on say, when Robotnik is defeated in game or am I just wishful thinking?
     
  4. SoullessSentinel

    SoullessSentinel Newcomer Member

    Joined:
    Aug 18, 2007
    Messages:
    10
    I love this, I usually use the PCM Table Handler from the S2 Clone Driver, but this looks much easier to use, especially with the PCM macro. Good job as always.
     
  5. ProfessorRenderer

    ProfessorRenderer Certified Bear Scientist Member

    Joined:
    Sep 28, 2011
    Messages:
    102
    Location:
    Willoughby, Ohio
    My goodness, it's a MUST for me as soon as I fix a bug that shows no SEGA screen.
     
  6. amphobius

    amphobius spreader of the pink text Member

    Joined:
    Feb 24, 2008
    Messages:
    970
    Location:
    United Kingdom
    Oh my! Now this is something I can get behind. Will definitely be using this from now on - many thanks!
     
  7. Irixion

    Irixion Well-Known Member Member

    Joined:
    Aug 11, 2007
    Messages:
    670
    Location:
    Ontario, Canada
    <Insert buttsecks joke here>


    Seriously though, completely delicious. I love you, seriously. <3
     
  8. redhotsonic

    redhotsonic Also known as RHS Member

    Joined:
    Aug 10, 2007
    Messages:
    2,970
    Location:
    England
    Putting them two sentences in the same post isn't a good idea =P
     
  9. TheJeli

    TheJeli Umm... Member

    Joined:
    Jun 20, 2011
    Messages:
    245
    Location:
    West London
    I just wan't to tell you how fantastic you are.


    Seriously I've never followed a tutorial dealing with something as complicated as sound drivers before and it worked the first time. Now I can edit the drum samples.


    Thank you so much.


    P.S. Just a quick question, what program is best for converting .wav samples to 8-bit, unsigned and mono?

    and LOL.
     
    Last edited by a moderator: Feb 27, 2012
  10. MarkeyJester

    MarkeyJester ♡ ! Member

    Joined:
    Jun 27, 2009
    Messages:
    2,870
    Well, I generally use this:


    [​IMG]


    It has conversion properties which are useful.
     
  11. Animemaster

    Animemaster Lets get to work! Member

    Joined:
    Mar 20, 2009
    Messages:
    1,229
    Location:
    UK
    I beleive the program Audacity also can export to 8-bit mono PCM format and others.
     
  12. TheJeli

    TheJeli Umm... Member

    Joined:
    Jun 20, 2011
    Messages:
    245
    Location:
    West London
    Thanks I've got audacity working now.


    Another quick question, how do you replace the SEGA sound? (I kinda thought it was related)
     
    Last edited by a moderator: Mar 6, 2012
  13. EMK-20218

    EMK-20218 The Fuss Maker Exiled

    Joined:
    Aug 8, 2008
    Messages:
    1,068
    Location:
    Jardim Capelinha, São Paulo
    Just save another file in the same format of the original Sega sound, then it will be replaced with the new one.
     
  14. SonicVaan

    SonicVaan I'm a cyberpunk with a taste for guns Member

    Joined:
    Sep 12, 2008
    Messages:
    456
    Location:
    Germany, Cologne
    I hope this is a worthy bump, so..


    It seems that the macros don't work for me, because I get the following building errors:




    I followed every step here, but the macros don't seem to work. As for this:




    PCMTabLod: include "Z80PCMTableLoad.asm"


    even



    It didn't build for me previously, so I had to add "Z80" before "Z80PCMTableLoad.asm" so that it would build, because the ASM file is in the Z80 folder, obviously, but then I got the building errors above.
     
    Last edited by a moderator: Apr 20, 2012
  15. Irixion

    Irixion Well-Known Member Member

    Joined:
    Aug 11, 2007
    Messages:
    670
    Location:
    Ontario, Canada
    Could not open file means it can't access, whether through access restrictions or something.
     
  16. MarkeyJester

    MarkeyJester ♡ ! Member

    Joined:
    Jun 27, 2009
    Messages:
    2,870
    OK, it seems someone or something has changed my post and removed all of the backward slashes in the macro, hence why you got that error, I've put them back in, let's hope it was just a misunderstanding or a minor glitch that won't happen again.
     
Thread Status:
Not open for further replies.