Thank you vlad, it's been a while since the DAC drivers didn't got some love. Amazing work. Thanks again
Sonic 1 "Mega PCM" driver A new DAC driver for Sonic 1, version 1.1 is out!
#47
Posted 04 November 2014 - 09:44 AM
So, while working with my driver, I found myself making a pair of size optimisations that don't affect speed to Mega PCM's code:
While DPCM_DeltaArray's padding negates the space saved by the removal of the 'di's, the resulting binary's size is reduced from 210h bytes to 1EEh bytes. Size can also be reduced by compressing the binary file and making SoundDriverLoad decompress the data to Z80 RAM. Flamewing's koscmp works well for compressing.
EDIT: Actually, it seems I can take this even further:
At the end of both Process_PCM and Process_DPCM is this code:
It's the exact same between the two, and doesn't call back into their respective routines. So, we can make the driver use only one copy of this code, and we can make it occupy the space otherwise used by DPCM_DeltaArray's padding.
So, for example, above DPCM_DeltaArray, you can have this:
And, in Process_PCM/Process_DPCM, you can replace this:
...with this:
And you can delete both of these:
Doing this will reduce the driver's size from 1EEh bytes to 1E6h bytes.
EDIT2: Here's another optimisation. This improves the speed and size of LoadDAC.
Move this...
...above this:
And then make both that line, and the 'ld h,0h' use register b instead of using the 0h. Doing this should save space and cycles. Unfortunately, the space freed will be padded by the align, and the optimisation is not in a cycle-intensive area.
- Removed two of the three 'di' instructions at the beginning of the driver.
- Moved DPCM_DeltaArray from address 200h to 100h. This was done by moving DPCM_DeltaArray and its align to above InitBankSwitching. This reduces the amount of padding needed for the align.
While DPCM_DeltaArray's padding negates the space saved by the removal of the 'di's, the resulting binary's size is reduced from 210h bytes to 1EEh bytes. Size can also be reduced by compressing the binary file and making SoundDriverLoad decompress the data to Z80 RAM. Flamewing's koscmp works well for compressing.
EDIT: Actually, it seems I can take this even further:
At the end of both Process_PCM and Process_DPCM is this code:
; Quit playback loop + exx jp Event_EndPlayback
It's the exact same between the two, and doesn't call back into their respective routines. So, we can make the driver use only one copy of this code, and we can make it occupy the space otherwise used by DPCM_DeltaArray's padding.
So, for example, above DPCM_DeltaArray, you can have this:
; --------------------------------------------------------------- ; Quit playback loop (used by Process_PCM/Process_DPCM) ; --------------------------------------------------------------- QuitPlaybackLoop: exx jp Event_EndPlayback
And, in Process_PCM/Process_DPCM, you can replace this:
jp p,+++ ; 10 ; if yes, quit playback loop
...with this:
jp p,QuitPlaybackLoop ; 10 ; if yes, quit playback loop
And you can delete both of these:
; Quit playback loop + exx jp Event_EndPlayback
Doing this will reduce the driver's size from 1EEh bytes to 1E6h bytes.
EDIT2: Here's another optimisation. This improves the speed and size of LoadDAC.
Move this...
ld b,0h
...above this:
ld (hl),0h
And then make both that line, and the 'ld h,0h' use register b instead of using the 0h. Doing this should save space and cycles. Unfortunately, the space freed will be padded by the align, and the optimisation is not in a cycle-intensive area.
This post has been edited by Clownacy: 01 December 2014 - 06:44 PM


00