Skip to content

A Z80 sound driver for the Genesis with support for Sega CD, Sega 32X and Sega CD32X

License

Notifications You must be signed in to change notification settings

GenesisFan64/GEMA-drv

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GEMA Sound Driver (GEMA-drv)

A sound driver for the Genesis with support for Sega CD, Sega 32X and CD32X

FEATURES

  • Runs entirely on Z80, PCM and PWM playback is done through direct communication from Z80 to each add-on's specific CPU
  • All sound chips supported: PSG, YM2612, RF5C164 and PWM and can be used at the same time, a single track sequence can use up to 26 channels
  • Works on real hardware (ONLY tested Genesis and 32X, I don't have the Sega CD but it should work)

PSG

  • Can use Attack, Decay, Sustain and Release
  • Support for NOISE channel's frequency-steal mode

YM2612

  • FM3 Special mode with manual OP frequencies
  • DAC with Sample rate at 16000hz base, pitch controlled, can be looped, has quality protection when doing DMA

RF5C164 (Sega CD)

  • Sample rate at 16000hz base, can be looped.
  • Support for larger samples by streaming data on Sub-CPU (from SUB-CPU's memory to PCM memory)

PWM (Sega 32X)

  • Sample rate at 16000hz base, can be looped.
  • Supports STEREO samples
  • Samples are stored in either SDRAM (CD32X compatibilty) or ROM (Cartridge only)
  • For the samples stored at ROM: DMA protection when the RV bit is active (WIP, needs more testing)

REQUIREMENTS

HOW TO USE

Setting up the assembler

  • Pick your version: linux ("ubuntu") or win32
  • Go to /src/tools
  • Make the folder AS and extract the contents there

Building the sound tester

  • Music data is located at sound/seq and instruments/samples on sound/ins
  • The sequence list, instruments and DAC samples are located on sound/data.asm, PCM and PWM samples are stored separately.
  • Sub-beats are loaded externally, on this tester open src/game/code/sound_test.asm and go to the label exgema_beats, the sub-beats are sorted the same order as the sequence list. (I don't have the exact formula to convert to IT tempo, but the value 214 corresponds to IT's tempo 125)
  • OPTIONAL: on the same file but at the very top, there's 2 boolean settings: VIEW_GEMAINFO and VIEW_FAIRY, VIEW_GEMAINFO toggles the note playback status but causes a small loss of DAC quality and VIEW_FAIRY toggles the status fairies (in case you don't like those)
  • Run make_tester.sh on Linux or make_tester.bat on Windows
  • Output ROMS will be located at /bin, the rom_(system) rom are for real hardware and rom_emu_(system) for emulators, SegaCD/CD32X: the letters j, u, e represent the region.

The tester uses code a now-outdated copy of NikonaMD, the latest is located here: https://github.com/GenesisFan64/NikonaMD

Using this driver in your project

  • Build the Z80 binary by running make_driver.sh on Linux or make_driver.bat on Windows, output files will be located at /drvbin: The zdrv_(system) files are for real hardware and zdrv_emu_(system) for emulation, only difference is a few NOPs with the DAC playback.
    Currently the standard driver zdrv_md.bin / zdrv_emu_md.bin is the only one that can be used outside of this code, support for the PCM and PWM chips require special playback code on SCD's Sub-CPU and 32X's Slave SH2
    The gema_macros.asm file uses the variables MCD, MARS and MARSCD for detecting the current target system, if you are not using PCM and PWM you can delete the macros gInsPcm and gInsPwm, also the variables at gSmplData, gSmplRaw.

  • Include the Z80 binary including these labels:
    Z80_CODE: binclude "zdrv_md.bin" Z80_CODE_END:

  • Include the files sound/driver/gema.asm, sound/driver/gema_macros.asm in your code.
    If your assembler doesn't support dotted labels (ASM68k...) change the dots to @, uses

  • You can check the list of sound calls (Play, Stop, Fade) on gema.asm

If you can implement PCM and PWM manually, requires knowdage of both Sega CD and 32X:

  • PCM code is located at src/system/mcd/marscd.asm at CdSub_PCM_Process
  • PWM at: src/system/mars/sound.asm src/system/mars/main.asm (at s_irq_cmd) and src/system/mars/cache/cache_slv.asm (playback code loaded to SH2's Slave CACHE)

CURRENT ISSUES

  • YM2612: Changing FM Channel 3 Special to Normal might cause a click
  • w/32X: PWM sample volume is lower that the other chips

Documentation for the driver is located at /doc

About

A Z80 sound driver for the Genesis with support for Sega CD, Sega 32X and Sega CD32X

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages