Click And See

EMULib

by Marat Fayzullin

What is EMULib?

EMULib is a set of C library modules which I wrote to use in computer emulators. Some of this modules emulate various computer chips. Others are used to play sound, handle data files, and work with hardware. EMULib is available from

http://www.komkon.org/fms/EMUL8/

Be aware that EMULib is a work in progress. Every now and then I add new modules and extend existing ones. Documentation is incomplete and may not always be up to date. In this situation, the header files are your best friends. Check them out for fresh information on the libraries.

Copyright Notice

Both EMULib source code and documentation are copyrighted by me, Marat Fayzullin. Following restrictions apply to these materials:

How To Use EMULib?

Following chapters will cover various EMULib modules:

SN76489 Programmable Sound Generator

SN76489.h SN76489.c

This is an emulation for the 76489 Programmable Sound Generator (PSG) chip produced by National Semiconductors and Intel. In order to use this emulation, you should first write a play handler function
void PlayHandler(int Channel,int Frequency,int Volume)
which will be used to play sounds from the four PSG channels. The frequency is given in hertz while the volume may vary in 0..255 range. Channels 0-2 are melodic. Channel 3 should generate white noise around given base frequency. After implementing the PlayHandler() in your program, create the PSG context:
SN76489 PSG;
This structure contains all PSG registers and other data describing PSG state. You should then initialize it with
Reset76489(&PSG,&PlayHandler);
After that, you can write byte values into PSG chip by issuing
Write76489(&PSG,Value);
calls. These writes will be converted into calls to the PlayHandler(). There are two possible ways to do it though:


TMS9918/9928 Video Processor

TMS9918.h TMS9918.c DRV9918.c

To be documented.

Library for Handling GameBoy Cartridges (.GB)

GBCarts.h GBCarts.c

To be documented.

Library for Handling NES/Famicom Cartridges (.GB)

NESCarts.h

To be documented.

Sound Driver to Write MIDI Files

MIDI.h MIDI.c MIDIFreq.h

The MIDI library included into EMULib allows to create single-track MIDI files (.MID) based on the melodic sound data given as <Channel><Frequency><Volume> triplets. This library can be used for saving soundtrack from an emulator or converting various music formats into MIDI format. Your typical program should create a MIDI file in a following way:
FILE *F;
F=fopen(FileName,"wb");
InitMIDI(F,Channels,Ticks);
The Channels parameter should be set to the maximal number of sound channels you are going to use. The Ticks parameter is in hertz and sets the quantization frequency i.e. the smallest period of time between notes. After creating a MIDI file, it is time to set sound types for the channels. This is done by issuing
MIDISetSound(Channel,Type);
calls where Type may take values
SND_MELODIC  - Melodic sound
SND_NOISE    - White noise
SND_PERIODIC - Periodic noise
Now, you are ready to start generating some sound. This is done with
MIDISound(Channel,Frequency,Volume);
calls where Frequency is given in hertz and Volume varies in 0..255 range. This call alone is not enough though. The MIDI standard also requires timestamps to keep track of time. Writing a timestamp is done using
MIDITicks(Ticks);
call where Ticks is a number of ticks passed since the last call to MIDITicks(). Remember that a "tick" is a unit of time declared when you initialize MIDI with an InitMIDI() call. Additional functions which you may find useful are
MIDISetFreq(Channel,Frequency);
MIDISetVolume(Channel,Volume);
They are both special cases of a more universal MIDISound() function. After you are done with the MIDI file, it can be closed in a following fashion:
TrashMIDI();
fclose(F);

Sound Driver for MSDOS (OPL3 and SoundBlaster)

SndMSDOS.h SndMSDOS.c FMFreq.h

To be documented.

Sound Driver for Unix (/dev/audio and /dev/dsp)

SndUnix.h SndUnix.c

To be documented.

Sound Driver for Windows (midiOut and waveOut)

SndWin.h SndWin.c MIDIFreq.h

To be documented.

Miscellaneous Functions for MSDOS

LibMSDOS.h LibMSDOS.c

To be documented.

Miscellaneous Functions for Unix

LibUnix.h LibUnix.c

To be documented.

Miscellaneous Functions for Windows

LibWin.h LibWin.c

To be documented.

©1998 Copyright by Marat Fayzullin