MasterGear
version 1.3
Contents
Disclaimers
- Mark3, MasterSystem, GameGear, SG1000, and SC3000 are all
registered trademarks of SEGA.
- GameGenie is a registered trademark of Galoob.
- The author is in no way affiliated with SEGA.
- The author is in no way affiliated with any pirate group out there.
- The author cannot and will not provide you with
any MasterSystem, GameGear, or other games.
- The author cannot be held responsible for anything this program
will do to your computer, brains, free time, housemates, pets, or
family members.
New in This Version
- Documentation converted to HTML.
- Added game state saving/loading.
- Fixed a bug in the Z80 BIT opcode, thanks to Zoop.
- Multiple fixes to the VDP emulation.
- Complete TMS9918 emulation (SG1000/SC3000).
- Added seperate SC3000 emulation option.
- Added SC3000 keyboard emulation.
- Sound in MG-Unix fixed to work on some buggy OSS versions.
- Added speed control to MG-Unix.
- MG-Unix runs in a resizable window now.
- Fixed IPC key allocation bug in MG-Unix.
- MG-Windows uses multimedia timer to sync screen refresh.
- Added size/position snapshotting to MG-Windows.
- Added keyboard bindings to MG-Windows.
History
New in MG 1.2
- Documentation expanded.
- Added emulation for Japanese SG1000/SC3000 systems which were
predecessors to the MasterSystem.
- Fixed Japanese/English switch.
- Even more accurate VRAM read/write emulation (multiple minor
glitches fixed).
- Fixed VBlank control bits in VDP.
- VBlank interrupts are persistent now (Samurai Spirits and
Robocop 3).
- Added multi-phase VBlank processing (Smash TV, Spiderman).
- Memory is initialized to 00h not FFh now (done by bootup ROM?)
(Shanghai 2).
- Windows version has got a "Sync to Timer" option to control
emulation speed.
New in MG 1.1
- Windows version is now ready and available for sale. You can
register it online with a credit card.
- VPeriod/HPeriod are counted in the CPU cycles instead of CPU
opcodes.
- Fixed bug preventing RainbowIslands from running.
- Fixed bug which caused trash to appear on display in Galaxy Force.
- Changed VRAM read/write code which fixed glitches in Surfing Ninjas
and many other games using inappropriate VRAM access modes.
- Changed -delay option so that Astro Warrior, Mah Jong, and several
other games run without glitches.
- Changed sound chip base frequency to make it sound correctly.
- Changed keyboard assignments (see documentation).
- Unix version runs in 8bpp, 16bpp, 32bpp, and 24bpp X11 modes
(24bpp not on all servers though).
- Music is saved in the MIDI format. No conversion needed.
Introduction
MasterGear (MG) is a portable emulator of several 8bit videogame
consoles produced by SEGA: Mark3, MasterSystem, handheld GameGear, and
their predecessors SG1000 and SC3000. MG allows to run most of the
software written for these consoles on a personal computer, as well as
debug this software. As MG is written in a portable C programming
language, it runs on many different platforms and operating systems.
You can always get latest MG binaries and support files from
http://www.komkon.org/fms/MG/
Currently, MG is able to run about 98% of the SMS/GG/SG1000 carts I
have. With the help from friends I hope to make it as close to original
machines as possible and emulate some exotic peripherals such as light
gun, sports pad, SG1000 keyboard, GameGear on-cart sound chips, and
GameGenie. Following is a list of features supported by MG at this
moment:
- Hardware
- CPU (Z80)
- MasterSystem Video Processor
- GameGear Video Processor
- SG1000/SC3000 Video Processor (TMS9918)
- Programmable Sound Generator (SN76489)
- 32kB Internal RAM in SC3000
- 8kB Internal RAM in SMS/GG
- 16kB Internal VRAM
- SC3000 Keyboard
- Cartridges
- Bank switching
- Cartridge RAM
- Battery Backed RAM
- Localization switch between English/Japanese modes
- Automatic localization for GameGear ROMs
- Other
- Emulation State Saving and Loading
- Automatic Handling of GZIPped ROMs
- Soundtrack Logging into MIDI Files
- Built-In Debugger (Unix port only)
- Resizable Window (Windows and Unix ports)
- Loadable Background Frames (MSDOS port only)
- Screen Snapshots (MSDOS port only)
MG Ports
Because of its portability, MG can be compiled on a wide variety of
platforms: Unix, Amiga, Macintosh, MSDOS, Windows, etc. Unfortunately, it
looks that for each person geniunely interested in hardware hacking and
revival of the old videogame experience there is a dozen of adolescent
gremlins hungry for a quick fun of playing pirated SEGA games on their PCs.
Because of that, I decided against making MG source code publicly available
and producing free versions of MG for MSDOS or Windows. I do not want to
provide free entertainment for the vermin. I do feel it necessary to
apologize for inconvinience created to all the intended users of MG. The
complete up-to-date list of MG ports can be obtained from the MG
distribution site. Following are the major ports of MG available at the
moment:
Unix
-
MG-Unix is available freely in binary form for various flavors of Unix
from the MG distribution site. I am always trying to compile it on as many
different Unices as I have handy at the moment.
MacOS
-
The Macintosh version of MG is being developed by John Stiles. It is
available from him as a shareware and can be found at the MG distribution
site.
Windows CE
-
The WindowsCE version of MG is being developed by Jimmy Software. It is
available as a shareware and can be found at the MG distribution site.
Windows 95/98/NT
-
The Windows version of MG is available from me, Marat Fayzullin, for
$35US. This fee ensures that you will get you the latest full version of
MG-Windows with sound and joystick support, saved preferences, and free
updates via email as long as MG-Windows is being updated. For more
information about it, take a look at
http://www.komkon.org/fms/MG/MGWindows.html
I do not feel very good about maintaining the Windows version because
people pirate it a lot and most Windows users appear to be mentally
underdeveloped (judging from their email, anyway). If you do want
to see Windows version being developed, please, register it by one of the
following methods:
- ORDER BY MAIL
-
Send $35US in cash, money order, or a US bank check to:
Marat Fayzullin
6304 Hampton Place
Elkridge, MD 21075
USA
Don't forget to include your email address and mention that you want
MG-Windows, as I'm selling several other products as well. The software
will be emailed to you as soon as I receive the money.
- ORDER BY PHONE
-
Call one of the following numbers in US:
1-800-242-4775 (extension 15673)
1-713-524-6394 (extension 15673)
and refer to product #15673 (MG-Windows). This service is provided by
Public Software Library (PSL). You can pay them with a credit card. Don't
forget to give them your email address. The software will be emailed to
you as soon as I receive the notification from PSL.
- ORDER ON THE WEB
-
Tell your WWW browser to go to
http://www.pslweb.com/cgi-win/psl_ord.exe/ITEM15673
and use the online form to register MG-Windows. You can pay with a credit
card. They take MasterCard, Visa, Amex, or Discover. The software will be
emailed to you as soon as I receive the notification from PSL.
MSDOS
-
You may find older versions of MG (<=1.1) for MSDOS on the Net, but
there are no newer versions currently available, neither freeware
nor shareware. Please, do not mail me asking for it: I won't answer to
you. I won't allow anyone to do an MSDOS port of MG either. See above for
the reasons why.
Linux
-
Currently, MG-Linux (ELF, GLIBC, X11) is compiled from the same source
as all other Unix versions. You can get it for free from the MG
distribution site. Please, do not ask me for an SVGALib version though:
I do not consider SVGALib as a viable standard and will not develop for
it.
Registered Users
If you registered MG-Windows, please do not give your copy to
anybody. And I do mean anybody. There was a couple of cases when
registered users gave MG away to their friends, relatives, or just "KeWl"
guys on the Net, and then I found it pirated, put onto WWW pages, and even
posted to USENET newsgroups. If I find your personalized copy of
MG being spread around, your registration gets automatically cancelled
which means no support and no more updates.
I understand that the previous paragraph may sound threating to some
people, but this kind of piracy really hurts my profits and feelings. I've
put a lot of effort into MG, and can only continue working on it if
people do not try to cheat on me.
It may also be a good idea to buy a real cartridge for each cartridge
image you use with the emulator. SEGA software is copyrighted, but as
long as you own the real cartridge, you are protected by the law allowing
customers to backup bought software.
What is Included
Following files are included into the distribution:
mg - MG executable file (Unix. mg -help for options)
mg-debug - MG with debugger (Unix. mg-debug -help for options)
mg.exe - MG executable file (Windows)
MG.html - This documentation
What is not Included
Absolutely no ROM images of SEGA games are included. These games
are still copyrighted by the companies who produced them, and therefore, I
cannot distribute any of them. I'm also unable to tell you where to find
these games, so do not send me email asking for them. You will have to
look for them on your own.
Buttons
When using SC3000 keyboard, press [CONTROL]+[KEY]
to access
the special function of a [KEY]
, if it also performs a
keyboard function.
[SPACE] - FIRE-A button (also: [LALT],A,S,D,F,G,H,J,K,L)
[LCONTROL] - FIRE-B button (also: Z,X,C,V,B,N,M)
[ENTER] - START button (only in GameGear mode)
[TAB] - RESET button (only in MasterSystem mode)
[BACKSPC] - PAUSE button (only in MasterSystem mode)
[ESC] - Quit emulation (also: [F12])
[F11] - Reset hardware
[F2] - Turn soundtrack log on/off
[F3] - Toggle FIRE-A autofire on/off
[F4] - Toggle FIRE-B autofire on/off
[F6] - Save emulation state (*.STA)
[SHIFT] and [CAPSLOCK] switch between MasterSystem joypads
When compiled with #define SOUND:
[1]-[4] - Toggle sound channels on/off
[0] - Toggle all sound on/off
[-] - Decrease sound volume
[+] - Increase sound volume
When compiled with #define DEBUG:
[F1] - Go into built-in debugger
When compiled with #define MSDOS:
[F8] - Toggle joystick 1 on/off
[F9] - Toggle joystick 2 on/off
[F10] - Make a screen snapshot (SNAPxxxx.GIF)
Command Line Options
These options only work in MG-Unix and other MG ports with the
command line interface. MG-Windows takes no command line options,
just a file name.
-verbose <level> - Select debugging messages [5]
0 - Silent 1 - Startup messages
2 - Illegal accesses 4 - Illegal Z80 ops
8 - Bank switching 16 - Sound
32 - VDP registers 64 - VRAM accesses
-hperiod <period> - Number of CPU cycles per HBlank [215]
-vperiod <period> - Number of CPU cycles per VBlank [65000]
-uperiod <period> - Number of VBlanks per screen update [3]
-help - Print this help page
-sc3000/-sms/-gg - Run in SC3000/MasterSystem/GameGear mode [-sms]
(overrides .SC/.SMS/.GG file extensions)
-engl/-jap - Run in English/Japanese mode [-engl]
(overrides country code in GG carts)
-autoa/-noautoa - Autofire/No autofire for button A [-noautoa]
-autob/-noautob - Autofire/No autofire for button B [-noautob]
-delay/-nodelay - Delay/Don't delay VRAM reads [-nodelay]
-logsnd <filename> - Write soundtrack to a MIDI file [LOG.MID]
When compiled with #define DEBUG:
-trap <address> - Trap execution when PC reaches address [FFFFh]
When a keyword 'now' is used in place of the
<address>, execution will trap immediately.
When compiled with #define SOUND:
-sound [<quality>] - Sound emulation quality [0]
0 - Off 1 - Adlib (MSDOS)
Values >8191 are treated as wave synthesis
frequencies. Default frequency is 22kHz.
-nosound - Same as '-sound 0'
When compiled with #define UNIX:
-shm/-noshm - Use/don't use MIT SHM extensions for X [-shm]
-saver/-nosaver - Save/don't save CPU when inactive [-saver]
-sync <frequency> - Sync screen updates to <frequency> [0]
-nosync - Same as '-sync 0'
-scale <factor> - Scale window by <factor> [1]
When compiled with #define MSDOS:
-back <filename> - Use <filename> as background picture [MG.GIF]
-vsync/-novsync - Sync/Don't sync screen updates [-novsync]
Frequently Asked Questions
- I WANNA PLAY GAMES!!!! WHERE DO I GET GAMES???????
I do not know. I can't give you any due to both legal and moral reasons.
Please, do not mail me asking for games. I will delete your mail right
away, and you won't get an answer.
- How do I copy games from cartridges to a computer?
You can use a special device called cartridge copier. Pascal Felber has
made such a copier. Its schematics and software are available at
http://lsewww.epfl.ch/~felber/IO-56/
You can also buy this copier from Pascal, either in parts or as a
pre-built kit.
- What is MasterSystem/GameGear? How its hardware works?
Over years, SEGA has produced several different 8bit videogame consoles.
They all had similar hardware built around a generic Z80 CPU, TMS9918
video chip, and SN76489 sound chip.
The oldest members of the family, SG1000 and SC3000, had an original
TMS9918 VDP and apparently weren't sold outside of Japan. Some of these
machines came with a keyboard and BASIC in ROM.
The MasterSystem, widely sold in the US, had an additional screen mode
not available in the standard TMS9918 VDP. Most MasterSystem games relied
on this screen mode. The compatibility with TMS9918 screen modes was
retained though, so MasterSystem could play SG1000/SC3000 games.
The GameGear only had the MasterSystem native screen mode truncated to
fit smaller screen, but not TMS9918 screen modes. It also had an extended
color palette of 2x16-out-of-512 colors, as compared to MasterSystem's
2x16-out-of-64 colors.
SEGA machines have no BIOS ROM as in MSX or ColecoVision. Instead, they
have a small bootup ROM which initializes the hardware and then switches
itself off, passing control to the cartridge.
- How system selection and localization work?
MG works with "raw" ROM images, and therefore the default file extension
is .ROM. It may be a wise idea to use .SMS and .GG extensions to
distinguish between MasterSystem and GameGear ROMs though. Since version
0.6, MG checks the file extension and forces emulation into MasterSystem or
GameGear mode if extension is .SMS or .GG.
For SG1000 and SC3000 ROMs, it is sufficient to use the .SMS extension,
as the MasterSystem is backward compatible with both machines.
In the MasterSystem mode, MG defaults to the US/Europe localization (-engl).
In the GameGear mode, MG checks the country code. If the cartridge is either
for Japan or US/Europe only, the localization switch is forced into an
appropriate state. It may be overridden by giving a localization option
(-engl/-jap).
- There is no version of MG for my Unix!
I am trying to compile Unix binaries for as many flavors of Unix as
possible, but as I do not have access to many machines, do not expect
immediate support for every Unix flavor out there. Don't mail me asking
for the source either: MG source code is no longer publicly distrbutable,
as much as I regret to say this :(.
- Where do I get MG for MSDOS?
This is explained in the beginning of this document.
- Game comes up with wrong colors and trash on the screen.
This may happen when you are trying to run a MasterSystem or SG1000 game
in the GameGear mode or vice versa. By default, MG will try to recognize
game type by .SMS/.GG extensions. If your files have different extensions,
you can use -sms/-gg options in MG-Unix or "GameGear Mode" option in the
setup window of MG-Windows.
- My favorite game doesn't work on MG. What do I do?
There may be several reasons why a game has problems running on MG
or does not run at all:
- Why is MG so slow on my machine?
Because your machine is too slow to run MG. My experience shows that
you need at least a Pentium/90 machine with fast video to run MG at a
reasonable speed. Following are the ways to speeds thing up:
- Increase UPeriod. The picture will get more jerky, but MG will
become faster.
- On Unix, always use MIT Shared Memory Extension for X (MITSHM). This,
of course, means that you have to run MG locally.
- On Unix, run X in 256-color mode.
- On Windows and Unix, use 1:1 window to achieve the highest speed.
- On Windows, use MIDI sound, as wave synthesis takes quite a lot of
CPU time.
- MG is too fast on my machine! How do I slow it down?
Frankly, when I started writing MG, I never expected that it will be
too fast on any machine :). But times change...
- Decrease UPeriod to 2 or even to 1. The emulation will become much
slower, but smoother.
- On Unix, ue
-sync
option to tie screen updates to
the certain frequency (usually, 60Hz/UPeriod).
- On Windows, use "Sync To..." option in the setup window to tie
screen updates to a certain frequency (usually, 60Hz/UPeriod).
- On Windows and Unix, double or triple the window size.
- What is that EMUTools package and where do I get it?
EMUTools is a set of utilities which may be useful for both emulator
authors and users. They allow to list and verify different ROM images,
convert music files, disassemble and compare ROMs. EMUTools can be
obtained from MG WWW site.
- Do I need to unpack GZIPped ROM images to run them on MG?
No, unless your copy of MG has been compiled without #define ZLIB.
MG-Windows and most versions of MG-Unix are compiled with this option.
It allows MG to recognize and automatically unpack GZIPped and singular
PKZIPped files. To find out whether your MG-Unix supports this feature,
run it with -help option and see if there is anything said about GZIP
support.
- When starting MG-Unix, ld says that libz library isn't found.
Some MG-Unix binaries are compiled with #define ZLIB option to make
them automatically recognize and unpack GZIPped files. This option
requires ZLib library which can be obtained from
http://www.cdrom.com/pub/infozip/zlib/zlib.html
- I entered registration code into MG-MacOS and now it says I pirated it!
MG-MacOS will lock up if you try to "register" it without paying for
registration and using the correct registration code. It will then refuse
to work on your computer. If you think that you have been mistreated
for a simple typing error, contact John Stiles for help.
- When starting MG-Unix, ld says that some library isn't found.
This may happen if the versions of your shared libraries are older than
the ones for which MG has been compiled. A decent way to deal with this
is to upgrade your Unix. A quick and dirty way is to make a symbolic link
from the existing library to a name required by MG.
- When starting MG-Unix, I get X_ShmAttach error.
You are probably trying to run MG-Unix on a remote Xterminal while it
attempts to use shared memory for interfacing with X. Use -noshm option to
tell it not to use shared memory.
- When starting MG-Unix, I get X_PutImage error.
MG-Unix version currently needs 8bit, 16bit, or 32bit X. Neither
2-color nor 16-color Xterminals will work. 24bit Xterminals may work,
but don't count on it.
- When starting MG-Unix, the window stays black.
Some other X application took over all available colors so that the
emulation could not allocate any for itself. Check if you run XV,
Netscape, or something similar.
- The sound is distorted in the MG-Windows. How do I fix it?
The wave-synthetized sound in MG-Windows may become distorted on slow or
highly loaded machines (no graphics acceleration, for example). There are
several ways you can improve sound:
- Use MIDI sound instead. It has both advantages and disadvantages
though.
- Make MG window smaller to decrease the load on the CPU. 1:1 is
the optimal size.
- Decrease the sampling frequency (in Setup Panel). The sound may
become tinkier, but less distorted.
- Increase the number of wave buffers (in Setup Panel). This may
cause sound to fall a second or two behind the screen action, but
the sound quality will become better.
- Does MG-Windows support joystick? My joystick doesn't work!
MG-Windows supports joystick. If your joystick does not work, go into
Windows Control Panel to see if it is configured and calibrated properly.
Also, some new joysticks working in esoteric standards (like GRiP) are
known to have problems.
- MG-Windows starts, but then quits immediately!
Check the pathname to wherever your MG is located. It should not contain
spaces. For example, "C:\Program Files\MG" is a bad place for MG, while
"C:\MG" will work. This bug is caused by an old version of C compiler I am
using. I hope to get rid of it when I switch to a new compiler.
- Colors are all screwed up in MG-Windows!
When running Windows in 256-color mode, it will try to approximate
colors to existing ones, but it won't always get an exact match. I'm
working on fixing this. For now, switch Windows into 16bit or better
graphics to get perfect colors.
- Black window in MG-Windows!
If you are running Windows in 256-color mode, then this is most
likely the cause of a problem. Try switching Windows into 16bit or
better screen mode.
- Command line options don't work in MG-Windows!
They shouldn't. The demo version of MG-Windows supports no command
line interface at all. The full version will only accept the ROM file
name at the command line, but no options. All configuration is done via
Setup Panel and MG.INI file.
- Volume control works strangely in MG-Windows!
It is a result of the volume control being shared between MG and other
Windows applications. You can usually restore normal volume by leaving MG
window and then activating it again.
- Will MG-Windows work on Windows 3.xx?
It may, but I can't guarantee it. MG-Windows has never been tested on
Windows 3.xx. Maybe it is time to upgrade.
- I'm a registered MG-Windows user and some games no longer run!
It is quite possible that your MG.INI file no longer works with the
new version of MG. It is my suggestion to delete MG.INI every time you
get a new version of MG. You can still use some ASCII editor (Notepad or
DOS Editor) to migrate some of your old settings into new MG.INI.
- What is SC3000 mode and how do I use it?
In SC3000 mode, MG will emulate SC3000 keyboard and also provide 32kB of
RAM. This allows to run BASIC Level 3, Music Editor, and other SC3000
programs. Following is list of non-obvious keyboard equivalents for
SC3000 keys:
SC3000 MasterGear
-------------------------
[SHIFT] [SHIFT]
[CONTROL] [CONTROL]
[ALT] [ALT]
[FUNCTION] [TAB]
[GRAPHLOCK] [CAPSLOCK]
[DEL/INS] [BS]
[CLS/HOME] [HOME]
[YEN] [`]
[PI] [END]
[^] [=]
[@] [\]
[:] [']
Take notice that all special MG functions accessed with the keys used
by SC3000 keyboard (such as [0]
..[4]
) are still
accessible if you press these keys with [CONTROL]
.
- How do I save and load the machine state during the game?
The machine state can be saved by pressing [F6] button. The resulting
data file will have the same name as your cartridge file, but its extension
is going to be .STA. This state file will be loaded automatically next time
you start MG. The same state file is not guaranteed to work for versions
of MG running on a different hardware. State saving is not perfect yet,
so for some games state may not be correctly saved.
Thanks
I would like to thank Richard Aplin, Chris Shay, Neil Harding, who
helped with invaluable technical information about MasterSystem and
GameGear. Thanks also go to (alphabetically):
- Gershon Elber, author of GIFLib.
- Marcel de Kogel, who helped me with the MSDOS port.
- Alex Krasivsky, the initial author of Adlib sound driver on
which MG-DOS sound is based.
- Juan Luis Lario for the pictures of GameGear.
- James McKay, author of 'Massage'.
- Authors of ZLib and Markus Oberhumer, who told me about ZLib.
- Charles Scheffold and other authors of PMODE/W.
- Ian Spielman, who wrote the enchanced Unix/X drivers for MG.
- John Stiles, author of the MG port to Macintosh.
- Unknown guy from .BR who showed me how to handle PC joystick.
- Many other people who helped with information, bug reports,
and cart images for testing.
© Copyright by
Marat Fayzullin
(fms@cs.umd.edu)