Cega
----
Cega is a cycle accurate emulator for the Sega SG-1000, Master System, and
Game Gear written specifically for The Jolly Good API.

Mega Drive emulation is in an experimental state.

This repository lives at https://gitlab.com/jgemu/cega

Compiling
---------
Make sure you have The Jolly Good API's header files installed. If you did
not install them, you will be required to include their path in CFLAGS.

Options:
  DISABLE_MODULE - Set to a non-zero value to disable building the module.
  ENABLE_STATIC_JG - Set to a non-zero value to build a static JG archive.
  USE_VENDORED_SPEEXDSP - Set to a non-zero value to use vendored SpeexDSP.

Linux:
  make

macOS:
  make

BSD:
  gmake

Windows (MSYS2):
  make

Cross Compile:
(For example compiling on Linux for MinGW)
  AR=x86_64-w64-mingw32-ar \
  CC=x86_64-w64-mingw32-cc \
  PKG_CONFIG=x86_64-w64-mingw32-pkg-config \
  STRIP=x86_64-w64-mingw32-strip \
  make

The build will be output to "cega/". This directory may be used as is
locally by copying it to your local "cores" directory, or may be installed
system-wide using the "install" target specified in the Makefile.

Input Devices
-------------
Cega supports the following input devices:

2 Button Control Pad (SG-1000, SMS)
3 Button Control Pad (MD)
6 Button Control Pad (MD)
Light Phaser (SMS)
Paddle Control (SMS)
Terebi Oekaki (SG-1000)

Settings
--------
bios = 0
0 = Disable, 1 = Enable

fmaudio = 1
0 = Disable, 1 = Enable

palette = 0
0 = SMS, 1 = TeaTime

rsqual = 3
N = Resampler Quality (0-10)

region = 0
0 = Auto, 1 = Japan, 2 = Americas, 3 = PAL

Auxiliary Files
---------------
SMS and Game Gear BIOS ROM images may be optionally loaded as auxiliary files.

Compatibility
-------------
 SG-1000
  100% Compatibility

 SMS
  100% Compatibility
  Sports Pad not yet supported.

 Game Gear
  100% Compatibility
  Gear to Gear Cable not yet supported.

 Mega Drive/Genesis
  Experimental

Accuracy/Caveats
----------------
Cega's Z80 CPU is emulated at cycle by cycle granularity (cycle stepped). The
VDP is executed on a cycle by cycle basis, but the operations of the VDP are
not 100% clear, so some things are not emulated exactly like real hardware.
The PSG is also executed on a cycle by cycle basis. Sound quality is extremely
high due to the processing of every single sample and the use of a high
quality resampler.

Since this emulator is still under development, the state format may break at
any time without warning. Do not rely on save states until the emulator has
become feature complete.

Porting
-------
Cega was written in standards compliant ISO C11 and should be extremely
portable. Though it was written for The Jolly Good API, it was done in a
manner that allows it to be used easily in multi-emulator frameworks or
standalone binaries for many potential platforms. If a new fork is created
with significant modifications, a clear indication that it is not officially
supported should be made, either by changing the name of the project or
by appending to it. Please be an honest person and respect the licenses that
apply to the software.

Copyright
---------
Cega (MPL-2.0)
  Copyright (c) 2021-2025, Rupert Carmichael
  See LICENSE

emu2413 (MIT)
  Copyright (c) 2001-2020 Mitsutaka Okazaki
  See src/emu2413/LICENSE (https://github.com/digital-sound-antiques/emu2413)

Musashi (MIT)
  Copyright (c) 1998-2019 Karl Stenerud
  See src/m68k/readme.txt (https://github.com/kstenerud/Musashi)
 
Speex Resampler (BSD-3-Clause)
  Copyright (c) 2003, 2007, 2008 Xiph.org Foundation
  See source files in deps/speex/ (https://github.com/xiph/speexdsp)

YMFM-C (BSD-3-Clause)
  Copyright (c) 2021 Aaron Giles
  Copyright (c) 2022 Rupert Carmichael
  See source files in src/ymfm

Z80 CPU Core (Zlib)
  Copyright (c) 2021 Andre Weissflog
  See src/z80.h (https://github.com/floooh/chips)

Extra Credits
-------------
A special thanks goes out to dinkc64 of FinalBurn Neo for technical advice
and moral support.
This emulator could not have been written without the extensive research and
documentation done by SMS Power!, and Charles MacDonald.

Trivia
------
The first game ever completed on this emulator was Phantasy Star.
