Giter Club home page Giter Club logo

clownmdemu's Introduction

Overview

This is clownmdemu, a Sega Mega Drive (a.k.a. Sega Genesis) emulator.

It is currently in the very early stages of development: it can run some games, but many standard features of the Mega Drive are unemulated (see TODO.md for more information).

Frontends

To actually run software with clownmdemu, you will need to use a frontend. Currently there are two official frontends:

Design

clownmdemu's code adheres to the following principles, emphasising minimalism and portability:

  • Use C89. This is required in order to support as many compilers as possible. Ideally, the code should be valid C++ as well, in order to support both C and C++ compilers.

  • Use integer-only logic. The Sega Mega Drive/Sega Genesis had no support for floating point types. Therefore, emulating it should not require floating point types. Additionally, floating point types are prone to rounding error and other precision issues, so I do not trust them. I am also concerned about their performance compared to integers, especially on lower-end hardware.

    • There is one exception to this rule: functions relating to generating 'constant' data. The reasoning for this is that platforms with poor floating-point support can have this data be computed at build-time and embedded into the executable.
  • Do not use dynamic memory. Memory allocation is slow, will cause memory leaks when not correctly freed, and can cause software to fail mid-execution when memory is exhausted, which is more effort to account for than it is worth.

  • Use no global state. All state should be kept in a struct which functions access through a pointer, allowing for such things as simple fast save-state support as well as the possibility of running multiple instances of the emulator at once. Note that the state must not contain pointers, so that it is relocatable and position-independent. Likewise, the state must not depend on outside state, so that it is useable across multiple executions of the emulator.

  • Operate within the guarantees of the C standard: no undefined behaviour and no implementation-defined behaviour.

    • Do not depend on integer type sizes. 'char', 'short', 'int', and 'long' may be different sizes on different platforms, so do not rely on their ability to hold (or not hold) values larger than their standard capacities:

      • -127 to 127 for 'signed char'.
      • 0 to 255 for 'unsigned char'.
      • -32767 to 32767 for 'short' and 'int'.
      • 0 to 65535 for 'unsigned short' and 'unsigned int'.
      • -2147483647 to 2147483647 for 'long'.
      • 0 to 4294967295 for 'unsigned long'.
    • Do not assume that 'char' is always signed by default: it is not. For instance, it is unsigned by default on ARM CPUs.

    • Do not rely on C language extensions.

    • Do not rely on endianness. Code should work correctly on both little-endian and big-endian CPUs.

    • Do not rely on signed number representation. That is to say, do not assume that negative numbers are represented in binary as two's complement.

  • Use original code. No emulation components should be taken from other emulators or libraries. For example, rather than use something like Musashi, the 68000 emulation core is custom. Likewise, a custom YM2612 emulation core is used instead of Nuked-OPN2.

clownmdemu itself is implemented as a library, with all platform-specific logic being relegated to a separate frontend program.

clownmdemu attempts to balance correctness with performance, acting as a more high-level emulator than accuracy-focussed alternatives may.

clownmdemu exposes a relatively low-level interface: audio from the FM and PSG are output separately at their native sample rates, and video is output a single scanline at a time in its native indexed format. This is to give the frontend the most flexibility in how it can process the data for delivery to the user. For instance, if the platform can play multiple separate audio streams at once, then the frontend can skip the expensive steps of audio resampling and mixing.

Compiling

clownmdemu can be built using CMake, however it should not be hard to make it use a different build system if necessary as the emulator's build process is not complicated.

Be aware that this repo uses Git submodules: use git submodule update --init to pull in these submodules before compiling.

Licence

clownmdemu is free software, licensed under the AGPLv3 (or any later version). See LICENCE.txt for more information.

clownmdemu's People

Contributors

clownacy avatar devon-artmeier avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

clownmdemu's Issues

Memory access delays

The CPU interpreters currently do not support delays of any form. However, I know of many that occur on real Mega Drives:

  • Work RAM delays
  • 68k being delayed when accessing its memory bus during a VDP Transfer.
    • Z80 accessing the 68k bus during this.
  • 68k writing to the VDP while its FIFO is full.
    • 68k reading from the VDP while its FIFO is empty?
  • The mysterious so-called "DRAM refreshes" (I think the Overdrive II document explains this one).
  • Z80 cycle-stealing.

Sonic Crackers shows bugged title card + other strange oddities

Yesterday I decided to try this game, and did a video showing it on YouTube, and I decided that I'd bring it here since another person also found the same issue;

The title card on levels bug out, it causes dots on World 2s background in attractions, and it causes some of the tether graphics to become black squares which carry over into the field stages (though they show up fine there if you start on them via "SELECT".)

The Z80 sound driver also doesn't seem to cause the game to crash (the problematic line) Ala inaccurate emulators.

A weird strip of 3 white squares will also show up in the "SELECT" menu if you can manage to trigger the alternative SEGA screen as shown in this screenshot; [screenshot]
(found out it was in the original game, disregard this part.

Here's a video comparison of the title card..

Bugged:

clownmdemutest.mp4

The intended result (using BlastEm):

2024-01-31_13-39-40.mp4

Games that hit a black screen at some point

  • Ms Pac-Man (on boot)
  • Star Cruiser (on boot)
  • Demolition Man (on boot)
  • Lemmings 2 (on boot)
  • Ultracore (on boot - has music, at least)
  • Shadow of the Beast (immediately after EA logo)
  • El Viento (after hitting "Game Start")
  • Super Street Fighter II (a red screen on boot. Almost certainly related to its special 5MB mapper)

KDebug Debug Features

This is something that Vladikcomper has brought up a few times: Gens KMod and BlastEm support the KDebug API, which allows emulated software to call into the emulator for a handful of uses, such as debug logging. On a real Mega Drive, using this API is harmless since it is done by accessing unused VDP registers. Though, I wonder about buggy games and homebrew that just access these registers accidentally: the last thing I need is to try to print garbage data as a zero-terminated string.

Some documentation can be found here: https://github.com/vladikcomper/md-modules/blob/master/modules/errorhandler/docs/how-to/Use_KDebug_integration.md

Decremented writes to CRAM aren't inverted

So you remember that fix you did for Jim Power? This is basically that for CRAM, but with no commercial examples as far as I'm aware.
For a text printing routine I've made, I used a longword decrement write to CRAM via the data ports, to save a few bytes. Abbreviated code below:

	lea	vdpctrl,a5
	lea	(a5),a4		; dec to data port
	move.l	#vdpComm(0,CRAM_WRITE),(a5)
	move.l	d2,-(a4)	; dec to data port (written values are word-inverted)

On real hardware and all other emulators I've tested, this results in the word values in d2 being written out of order, or "word-inverted". The only other thing I know that shares this behaviour is the AtGames Firecore of all things. Here's a rom to test this on

Adventures of Batman and Robin - lots of graphical corruption

The first scene of the intro cutscene features graphics that don't load in correctly:
image
image

Compared to real hardware and most emulators: Video

Stage 2 is missing the entire foreground layer, and one sprite palette gets corrupted as you walk to the right. There's also some graphical corruption in the HUD:
image

Further stages are not any better:
image

There's a code to warp to the next stage, should be useful for testing: Start, B, A, Down, B, A, Down, Left, Up, C.

N64 WiiU WIP Core Blog.

I'm sorry to post this here since it has nothing to so with Clowndemu :P
I did leave a msg on your Blog bit it didn't display after I sent it?

I just want to thank you for looking into N64 for the WiiU. your Blog post was an interesting read. You seem to have gotten really far even getting the Core to compile and run something :)
While I'm less than useless when it comes to coding and things like that M4xw could have saved you some time debugging, he's the maintainer of the Retroarch Mupen64 Core :)

How far are you planning on taking this N64 core? I see you primary goal is the OpenGL ES 2.0 renderer?
but honestly I hope you can make the N64 Core a reality. We have a reasonable PS1 Core 90% of games are running perfectly fine but some are still under performing, I'm hoping the OpenGL ES 2.0 will help there if you continue your work.

I see your work on the Core is with Aroma in mind? Tho I think it should be able to work on the Tiramisu environment too (that's what Retroarch currently runs on)
You mention that the Retrorach port is going through a messy refactor (which is true) but the old Tiramisu Isn't broken, your Core should be able to run on that just fine.

I hope you continue your port, even just for the OpenGL ES 2.0 work, I know Gary is still working on his ANGLE port but the more the merrier :D
M4xw is working on an aot recompiler that likely can be reworked to run on WiiU so if combined with your work could produce a working (fullspeed hopes) N64 Core for WiiU.

Again sorry for posting this here, I would have posted this on you Blog, but my last message didn't got through and you don't seem to be a member of GBAtemp and I couldn't find you on Discord.. I did find you on Sonic Retro but I couldn't send a PM :p
I'll delete this if its inappropriate.

Thank you for even looking into brining new (3D) Cores to WiiU. Its very much appreciated.

68000 STOP Instruction

Used by Malachi's hack. The 68k should indeed stop, but interrupts should resume it. STOP can be used for implementing WaitForVInt.

Hellfire has invisible sprites.

Hello! Great emulator, here I am playing on a Linux-based OS running Debian 11, and I built manually the 0.5.1 version.

As I was testing several games, I came across Hellfire (USA) version that, for some reason, has invisible sprites for both the ship and the enemies!

I am leaving a savestate, though it seems any version may encounter this bug during emulation? (ignore the .zip naming, that was just a way for me to upload the file containing the relevant info surrounding this game)
hellfirebug.zip

Change Region Based on the ROM's Header

As a simple usability improvement, the emulator should change region to suit the loaded game. This would prevent games with region locking from being unplayable until the user changes the emulated console's region in the settings.

Windows 10 Defender Issues

This may not be your fault, but Windows 10 H2 will detect clownmdemu as Trojan:Win32/Wacatac.H!ml, I haven't tested Windows 11

Issues with EA games

I didn't test every EA game - there are lots - but here's what I happened to run into:

  • Crue Ball - boots to black screen with music
  • The Immortal, Jungle Strike, Marble Madness (US) - EA logo has corruption but otherwise fine.
  • Road Rash, Road Rash II, Road Rash III, Skitchin' - EA logo has corruption, game crashes once a race starts. Pretty sure all of these games use the same engine so it should be the same fix for all of them.

Attempted to read invalid Z80 address

Hi, I have a problem when I launch any game from SGDK or sample assembly :

ERROR: Attempted to read invalid Z80 address 0x55EA
ERROR: Attempted to read invalid Z80 address 0x55EB
ERROR: Attempted to read invalid Z80 address 0x55EC
ERROR: Attempted to read invalid Z80 address 0x55ED
ERROR: Attempted to read invalid Z80 address 0x55EE
ERROR: Attempted to read invalid Z80 address 0x55EF
ERROR: Attempted to read invalid Z80 address 0x55F0
ERROR: Attempted to read invalid Z80 address 0x55F1
ERROR: Attempted to read invalid Z80 address 0x55F2
ERROR: Attempted to read invalid Z80 address 0x55F3
ERROR: Attempted to read invalid Z80 address 0x55F4
ERROR: Attempted to read invalid Z80 address 0x55F5
ERROR: Attempted to read invalid Z80 address 0x55F6
ERROR: Attempted to read invalid Z80 address 0x55F7
ERROR: Attempted to read invalid Z80 address 0x55F8
ERROR: Attempted to read invalid Z80 address 0x55F9

The problem occurs when restarting the Z80:

move.w $000,($A11200)

I hope you can fix this issue.

H-blank Bit

To quote Malachi...

I found the problem code. Basically at the end of my H_Int routine I had this
; a5 = vdp control reg
-    move.w    (a5),d0    ; wait until it's out of Hblank
    andi.w    #1<<2,d0
    bne.s    -
-    move.w    (a5),d0    ; now wait until it's in
    andi.w    #1<<2,d0
    beq.s    -

The first one was the problem, my assumption is that the register is always set to be in Hblank. Thankfully, that check was actually useless for this routine, so now you can play Sonic 2 as god inten-

Missing 68K file

At one point, m68k.c references m68k/gen.c, which does not appear to exist. I take it m68k/generator.c was meant?

Sonic 1 - Sound

I know it's not implemented but i through this info will help.

This is the output of Sonic 1

ERROR: Unimplemented instruction IM used at 0x23
ERROR: 68k attempted to access Z80 memory/YM2612 ports without Z80 bus at 0x72776
ERROR: 68k attempted to access Z80 memory/YM2612 ports without Z80 bus at 0x7278E
ERROR: 68k attempted to access Z80 memory/YM2612 ports without Z80 bus at 0x72740
ERROR: 68k attempted to access Z80 memory/YM2612 ports without Z80 bus at 0x72758

Earthworm Jim - Samples play at the wrong pitch

Every audio sample in the game plays too slowly. Noticeable as soon as the Sega logo.

Couldn't find a real hardware video, but this emulator capture seems about right: Video

This also affects Earthworm Jim 2, and probably other GEMS games?

Audio issues - one giant list

I booted up a bunch of games and looked into anything that sounded off. (I also knew beforehand of a few games that tend to give emulators trouble in the sound department.) A lot of these have to do with known unemulated YM2612 features (SSG-EG, extended CH3 mode, LFO, CSM). I know you said sound emulation wasn't a priority at the moment, but I figured it was better to document all this in advance, rather than just sit on it. Hopefully this doesn't keep you up at night.

(By the way, I want to commend you for writing your own sound emulation. A lot of projects just use the Nuked cores - which is fine, but it's neat to see someone do it the hard way. The PSG noise emulation already seems to be a better match for Sega's SN7 clone than BlastEm, which sounds more like a main-brand one.)

I also found quite a few non-audio bugs while testing random games' audio... expect more bug reports to be made soon. Sorry about that.

SSG-EG

Extended CH3

  • Streets of Rage 1 and 2 - a bunch of sound effects use it.
  • Devilish - Track 05 (Waterfalls) uses it on the lead instrument to play three notes across two channels.
  • Gauntlet IV - "Sortie" and "Retribution" use it according to this
  • Demolition Man - supposedly uses it a lot for percussion (according to this) but the game doesn't boot so I can't check.

CSM
As far as I know, only tech demos have used this.

Misc
Most of these will probably fix themselves as the FM emulation gets built out, but I thought I'd include them just in case they turn out to be unique bugs:

  • Scooby-Doo Mystery - Hi-hat in intro sounds obnoxious. I checked on real hardware, and it's almost inaudible.
  • Comix Zone, track 5 - Same deal.
  • Rocket Knight Adventures - FM patch used throughout OST sounds like a hihat instead of a bass drum.
  • Mega Turrican - Tracks 03/05/09/11/21 all have what sounds like the same wrong instrument. I know this game uses SSG-EG somewhere, but I don't know if this is that or something else.
  • Boogerman - The toms in Stage 1 (about :30 in).
  • Ecco 1 and 2 - #25. Also, both games sound slightly wrong on boot (Ecco 1 has an overly brash instrument for the first notes of the intro, and Ecco 2 has some scratching noises).
  • Mick & Mack - SFX used in the intro cutscene, as well as the one that plays when you start the level.
  • Greendog - Sound effect used in the intro when he kicks his legs around.
  • Contra Hard Corps - FM kick drum used in most tracks sounds like a wet "glug".
  • Wiz n' Liz, Alien 3 - Basically every instrument is weird. Some sounds have the wrong timbre, while some sound like they're getting cut off too early. Some sound fine for one note and wrong for the next.
  • Earthworm Jim - First level's music has a weird instrument about 20 seconds in. The explosion sound (plays when you die or use a gun powerup) sounds like a hiss rather than a rumble.

Most of these are less "audio bugs" and moreso "bugs that affect the audio":

  • #18; affects both Earthworm Jim games, Cool Spot, Mick & Mack, Greendog, and others. Doesn't affect Comix Zone for some reason, even though it uses the same sound driver.
  • Beavis and Butthead - Samples don't play.
  • After Burner II - Plays samples by writing to the PSG channels, which doesn't work. Mutes the percussion and most sound effects.
  • Zoop - Whole game is silent.
  • Jim Power - The Piko Interactive logo has a glitchy sample playing over it; it's silent on real hardware.
  • Fantastic Dizzy - Audio glitches can occur when opening and closing the ingame menu.

===

If you're ever looking to check a music track against real hardware without pulling out the real thing, DUSTINODELLOFFICIAL and Random VGMs on YT are good sources.

Z80 Interrupts Should Not Be 'Sticky'

vladikcomper — Today at 18:21
Hi, I have another bug report on Clownmdemu, this time quite serious~

Looks like timing of Z80 interrupts is quite buggy. From my observations, your emulator may trigger Z80's VInt mid-frame or even by the end of the frame; at any moment in time really, if interrupts were previously disabled or if Z80 was stopped. This should never happen and it may mess up some Z80 drivers in unexpected ways.

On real hardware, there's a time window of ~171 Z80 cycles since the start of VBlank when interrupt will be acknowledged. If Z80 is stopped during this time or interrupts are disabled, VInt should be missed. In Clownmdemu, however, interrupt request "sticks" and will fire whenever interrupts are re-enabled or Z80 starts again, which may happen mid-frame.
vladikcomper — Today at 18:28
... This is somewhat related to my issue with Z80<->68k access delays. You see, I attempted to implement a "calibration" check by measuring 68k ROM vs Z80 RAM access time (number of reads before VBlank) to detect and calibrate Mega PCM 2 loops for inaccurate emulators.

In inaccurate emulators ROM and RAM read count per frame match (while on real hardware ROM access is 24% slower), so it mostly worked well... Expect for Clownmdemu, which often refuses to properly calibrate, because it fires the first VBlank at arbitrary times :)

vladikcomper — Today at 18:57
There isn't much information available on the interrupts, so I gained some of this knowledge from various people or emulator's source code.

That 171 cycle window for VBlank I originally discovered in Blastem's source code. I then found it in at least one more source, so it should be really accurate:
#define Z80_INT_PULSE_MCLKS 2573 //measured value is ~171.5 Z80 clocks

When VBlanking period starts, INT pin is triggered on Z80 for roughly 171 cycles. If interrupts are enabled, Z80 disables them and executes VInt routine at 38h (I won't mention other modes useless on the MD).
If your VInt routine is shorter than 171 cycles or you re-enable interrupts (ei) immediately, the interrupt will be triggered again in the very same frame. This is why INT signal only lasts for 171 cycles and not the entire VBlank.

You can port these Sonic's games AND movian application to Wii U?

Do you think it would be possible for you to port these three Sonic games:

Sonic 3 A.I.R
Sonic Nexus
Sonic Robo Blast 2
The Sonic 3 A.I.R has its source code on github, just google it and I think there is a port for Switch.

The Sonic Nexus decompile is in the Rubberduckycooly repository and is also based on RSDK so it can be ported to the Wii U.

Sonic Robo Blast 2 has its source code on its website and it would be interesting to see the port of the latest version of SRB2 on Wii U.

Finally, I wanted to ask you if it is possible if you can compile and adapt to Wii U, the movian application. It is a multimedia center that is for PS3 and PC and an attempt was made a long time ago to make a port for Wii. Maybe you can use the Wii port source code to make the Wii U port, especially since streaming services on Wii U are going to end soon.

You can find the Movian Wii source code in the wikiblog0 github repository. And the original source code on the movian website.

Link: https://github.com/wikiblog0/movian-wii-wiiu
I appreciate your contributions to the Wii U scene.

Greetings

Gauntlet IV - button presses don't register consistently

This is an odd one. Any inputs (even in the menu) are extremely sluggish and buggy. It's like the game only successfully reads the controller 10% of the time. The success rate seems to vary depending on CPU load - you can at least move between menu options, but once the game starts you're functionally immobile.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.