Forums

Sega Master System / Mark III / Game Gear
SG-1000 / SC-3000 / SF-7000 / OMV
Home - Forums - Games - Scans - Maps - Cheats - Credits
Music - Videos - Development - Hacks - Translations - Homebrew

View topic - R-Type on Megadrive PowerBase Converter

Reply to topic
Author Message
  • Joined: 24 Mar 2021
  • Posts: 120
Reply with quote
R-Type on Megadrive PowerBase Converter
Post Posted: Sat Apr 10, 2021 7:27 am
Please forgive me if this was already known, but I spent a little while looking and didn't seem to find anyone talking about it.

As has been mentioned -
/forums/12093-ListOfIncompatibilitiesAmongSMSGamesHardware?start=100#87463
and
/forums/14084-PowerBaseConverterInfo#73889

R-Type doesn't always work on the Megadrive, and after hooking up a logic analyzer, I figured out why.

The game uses the byte from RAM $C000 in order to keep track of whether it's running from a MyCard or a cartridge, but on the Genesis there's no BIOS to initialize it. R-Type uses this byte to disable I/O in order to detect the FM card, and obligingly disables RAM by writing the value back to port $3E if the Genesis Z80 RAM powered up with a value telling it to do so.

I've attached a minimal patch that replaces the "ld a, (0C000h)" instruction with "ld a, 0ABh; nop" instructions and updates the checksum accordingly.

  View user's profile Send private message
  • Site Admin
  • Joined: 08 Jul 2001
  • Posts: 8644
  • Location: Paris, France
Reply with quote
Post Posted: Sat Apr 10, 2021 12:25 pm
Thanks! As I replied in https://www.smspower.org/forums/12093-ListOfIncompatibilitiesAmongSMSGamesHardwa... it would be good to start indexing those patches and encourage making the remaining ones (not too many I think).
  View user's profile Send private message Visit poster's website
  • Joined: 24 Mar 2021
  • Posts: 120
Reply with quote
Post Posted: Sun Apr 11, 2021 9:01 pm
A follow-up question that I found concerning was: of these games that care about the contents of $C000 on boot, why does R-Type seem to be particularly picky?

One answer is that R-Type writes a wrong value ($82) to VDP Mode Control 2. On my Genesis, this causes CSYNC and VSYNC to become idle high, and the HSYNC pin to emit an 8kHz square wave. However, nothing else clears that bit later on, and when other bits are set in this register video generation seems to operate normally. So I wonder what the specifics of this comment on the SMS wiki is:
Quote
Bit 2, while it doesn't seem to have any effect on either version of the SMS, will break compatibility with the Mega Drive hardware if set. It should always be set to 0, according to Sega's official documentation.


I looked more closely at After Burner, and after a bunch of power cycling, managed to get the same crash from disabling RAM. However, After Burner is self-correcting: it copies the byte from $C000 to $DFF0, clears the byte at $C000, and then uses the byte at $DFF0. So after a bad cold boot, the value will be good enough to permit operation on later boots.

Before I go through all 60-odd FM-using games to see if there are other games that are fragile in the same way R-Type is, can anyone else narrow down the list for me?
  View user's profile Send private message
  • Joined: 08 Dec 2005
  • Posts: 488
  • Location: Melbourne, Australia
Reply with quote
Post Posted: Mon Apr 12, 2021 2:26 pm
lidnariq wrote
[R-Type] uses the byte from RAM $C000 in order to keep track of whether it's running from a MyCard or a cartridge, but on the Genesis there's no BIOS to initialize it. R-Type uses this byte to disable I/O in order to detect the FM card, and obligingly disables RAM by writing the value back to port $3E if the Genesis Z80 RAM powered up with a value telling it to do so.

Are you using an official Sega Power Base Converter, or a third-party version?

The RAM will be disabled if the byte read from $c000 has bit 4 set. However, the official converter contains a tiny Boot ROM which should prevent this from happening - the code in the ROM both initializes the stack pointer and writes $00 to $c000 (via the mirror at $e000).
  View user's profile Send private message Visit poster's website
  • Joined: 24 Mar 2021
  • Posts: 120
Reply with quote
Post Posted: Mon Apr 12, 2021 6:43 pm
I'm using Raphnet's modern 3rd party clone.

I had read that disassembly but hadn't put 2 and 2 together to realize that the specific stack pointer was chosen so that the RST return address pushed is in the right place to clear that bit.

That's even more impressive.

For the longest time I was under the impression that the PLS program was only for games that relied on the BIOS initializing the stack pointer, but it's evident that a number of other games rely on it initializing the byte at $C000 too.

So that adds R-Type - and probably a lot of the other FM-supporting games - to the category of "really would like the boot ROM"
  View user's profile Send private message
  • Joined: 08 Dec 2005
  • Posts: 488
  • Location: Melbourne, Australia
Reply with quote
Post Posted: Tue Apr 13, 2021 2:00 am
lidnariq wrote
I had read that disassembly but hadn't put 2 and 2 together to realize that the specific stack pointer was chosen so that the RST return address pushed is in the right place to clear that bit.

That's even more impressive.

Same here - when I first read that thread I agreed that the code exists only to initialize the stack pointer. However, I misremembered and thought that it was only to initialize $c000. So when I read your post, I went back to the code and was surprised to find that it does both! The code's use of $e001 for the stack pointer rather than the easier-to-encode $dfxx was a little suspicious, and now we understand the reason for it.

To initialize $c000, initialize SP, and start the game in just 6 bytes (in fact, 6 * 7 bits) is indeed impressive.

lidnariq wrote
For the longest time I was under the impression that the PLS program was only for games that relied on the BIOS initializing the stack pointer, but it's evident that a number of other games rely on it initializing the byte at $C000 too.

So that adds R-Type - and probably a lot of the other FM-supporting games - to the category of "really would like the boot ROM"

Yes - when documenting which games are incompatible with the PBC, we should separate those which don't work at all from those which only work via the Boot ROM. It could be argued that the latter games are not at fault - the reason they don't work on the Genesis isn't because of flaws in the games, it's because of a flaw in third-party converters.
  View user's profile Send private message Visit poster's website
  • Joined: 05 Sep 2013
  • Posts: 3763
  • Location: Stockholm, Sweden
Reply with quote
Post Posted: Tue Apr 13, 2021 8:09 pm
RetroSpark wrote
However, the official converter contains a tiny Boot ROM [...].


why we no longer have that topic? :|
  View user's profile Send private message Visit poster's website
  • Site Admin
  • Joined: 19 Oct 1999
  • Posts: 14688
  • Location: London
Reply with quote
Post Posted: Tue Apr 13, 2021 9:15 pm
I’m not sure, it seems to have been deleted by accident.
  View user's profile Send private message Visit poster's website
  • Joined: 27 Jun 2020
  • Posts: 212
Reply with quote
Post Posted: Fri May 28, 2021 3:54 pm
lidnariq wrote
I'm using Raphnet's modern 3rd party clone.

I had read that disassembly but hadn't put 2 and 2 together to realize that the specific stack pointer was chosen so that the RST return address pushed is in the right place to clear that bit.

That's even more impressive.

For the longest time I was under the impression that the PLS program was only for games that relied on the BIOS initializing the stack pointer, but it's evident that a number of other games rely on it initializing the byte at $C000 too.

So that adds R-Type - and probably a lot of the other FM-supporting games - to the category of "really would like the boot ROM"


You've got to get my clone of the Mega SG one. Yeah baby. Many happy customers haha. No pinouts or map on that. they had a 4 layer board and the challenge was shrinking it down even smaller onto a dual layer. Mission accomplished on maximum smallness.

Used a multimeter on continuity for the entire thing and jotted it down before I knew about Raphnets and Db (he also has one with integrated sms FM module)
  View user's profile Send private message
  • Joined: 24 Mar 2021
  • Posts: 120
Reply with quote
Post Posted: Fri May 28, 2021 7:47 pm
L10N37 wrote
You've got to get my clone of the Mega SG one. Yeah baby. Many happy customers haha. No pinouts or map on that.
Actually I've been working on making Yet Another Converter. Ended up using two oldschool PALs - one for the boot ROM, one for FM support - because I was told that the ability to be assembled by hand was a priority.

Had some fun designing the filtering for the FM synth to knock out the 49kHz switching noise so that I could turn up the volume more without clipping.
  View user's profile Send private message
  • Joined: 27 Jun 2020
  • Posts: 212
Reply with quote
Post Posted: Sun May 30, 2021 8:04 am
That's awesome,
So you're making an adapter with FM sound like the Db one?
I will be your first customer if you make a batch!
I do have Tim's FM mod in a model 1 with the switchless region mod but I find real switches are better, you don't have to reset the system.

I'll be experimenting with a new gamegear audio board once some parts arrive. Class D amplifier in theory should draw less power than the original IC.
  View user's profile Send private message
  • Joined: 27 Jun 2020
  • Posts: 212
Reply with quote
Post Posted: Sat Jun 05, 2021 12:54 pm
Hi again Lidnariq

Rather than start a new thread I thought I would add something here as it's quite relevant


I was reading just before about incompatible games with the original hardware converter - and then thought about I could improve my converter and add compatibility so you don't need to do the quick swap.

Whilst reading around some sites I saw that Raphnet was adding a pause button and a way to have it boot all games without swapping shortly!

I was thinking you could probably do this with a PIC chip similar to how a playstation modchip works?

Anyway I was surprised to see Alien 3 was on the list!
I have Alien 3 working on my adapter, and hot swapping to R type I had R type work straight away -

After letting the console rest R - Type was usually not working or booting then crashing out.



Ok !! now the funny fix !!! Hold onto your seats guys lol

(Someone should try this on a real adapter !)

All I do to get Alien 3 working on a megadrive is hold my pause button in grounding B11 whilst i switch the system on, then release! This somehow gets something initialized that otherwise doesn't!

Details on the pause mod below, quoted from myself elswhere


"Some games require a pause button (not many, mainly to access menus and switch gear on RPG's)
This can be added to the megadrive console with a Pushbutton - SPST Momentary Action Switch (Cat #SP0711/ SP0710 @ Jaycar)

One side of the switch to ground, one side to B11 of the cart slot which is easily accessible under the board. B11 is the 11th pin in on the front row from left to right when facing the front of the console - be aware this changes when you flip the board upside down. It's a very easy modification requiring a hole to be drilled and 2 wires. Ground can be found around the edge of the board (the exposed copper area) or A1 on the cartridge connector which is the first pin on the top row left to right. This is the connection required for the other side of the switch."

L10N37 - THE DISCOVERY OF AN ALIEN 3 MASTER SYSTEM ON MEGADRIVE CONVERTER FIX

THANK YOU (after this you can turn on and off for a while and it will always boot without the pause)

**bows**

Also works on Shinobi (maybe it was still in residual from Alien 3 setting it up, hangs around way longer than i thought even with power plug out)

** Nope I can get shinobi working it just takes longer (more attempts), and im just using the pause button!, no swapping - someone more technical could probably figure out how this works! after this you can switch on and off and it will always work for a while

**confirming with aztec adventure shortly - yep, about 10 attempts but it fires up with no stack pointer initialization ... just the B11 to ground (unless it's my imagination and it would have worked with lots of tries, also once working will always work for a while after if switching on and off)

that's about the only games listed as needing swapping

**Last one - captain silver wouldn't boot, tried 6 times - then tried holding pause and switching on, booted first attempt
  View user's profile Send private message
  • Joined: 24 Mar 2021
  • Posts: 120
Reply with quote
Post Posted: Sat Jun 05, 2021 9:29 pm
L10N37 wrote
I was thinking you could probably do this with a PIC chip
I mean, that's what the original PLS153 is doing, as well as the atmega-based version that Raphnet made ( https://www.raphnet.net/programmation/md_sms_stack/index_en.php )

Quote
hold my pause button in grounding B11 whilst i switch the system on, then release! This somehow gets something initialized that otherwise doesn't!
In the SMS, the pause button is the Z80's /NMI input.

IF /NMI were level-triggered instead of edge—and it's not, but if it were—then holding down the pause button would cause the Z80 to repeatedly push values into the stack. Those values would be the return address, which would be the NMI handler address ($0066). Pertinently, both $00 and $66 do NOT have the $10s bit set, so if either were written to $E000 or $C000, it would cause SMS games that support FM to read the correct value to leave RAM enabled.

None of the registers in the Z80 are set to a known state on reset, so you only have the values that they usually hold on cold boot (most likely $FFFF, from what I've read). Subsequent reboots will just keep on counting down.

But still, this should require thousands of resets, not a small handful. I'll try taking a look with a logic analyzer later and see if I can reproduce.
  View user's profile Send private message
  • Joined: 27 Jun 2020
  • Posts: 212
Reply with quote
Post Posted: Sun Jun 06, 2021 4:08 am
Wonder boy III Monster Lair has some in game debugger type thing that pops up you can keep pushing the pause button and see values change (SP +0 +2 +4 +6) and even chunks of sprite rotate across the top

** can't get Alien 3 to NOT boot today, not sure what's changed. It's working everytime. Will try the other games.

Alien 3:
As mentioned it's analogue mega sg converter reverse engineered with a multimeter, shrunk down to the smallest I could to still have it fit the consoles on a 2 layer (there's is 4) - no idea why the official won't boot and this one does.




2:

Forcing shinobi to work with no stack pointer set up



Also doing a quick swap with a megadrive game (At least Wonderboy III Monster lair) will allow any master system game to boot - bar R type


(thought it had to be an SMS game)
  View user's profile Send private message
  • Joined: 27 Jun 2020
  • Posts: 212
Reply with quote
Post Posted: Tue Jun 15, 2021 10:44 am
Ive decided to attach an Arduino Nano to the adapter to initialise the stack pointer - I was wondering if there's anyway to add your patch to the sourcecode, so that it could patch R type on the fly if that game was plugged in...

I noticed in the source code you can just simulate pull ups and pull downs, so maybe theres a way to add wireless pause to these adapters that don't have one.

"pinMode(DataPin, INPUT);
pinMode(CmdPin, OUTPUT);
pinMode(AttPin, OUTPUT);
pinMode(ClockPin, OUTPUT);
pinMode(AckPin, INPUT);

//Set up SPI on Arduino (250 kHz, clock active when low, reading on falling edge of the clock)
SPCR = 0x7F;
clr = SPSR;
clr = SPDR;

digitalWrite(DataPin, HIGH); //Activate pullup resistor
digitalWrite(CmdPin, LOW);
digitalWrite(AttPin, HIGH);
digitalWrite(ClockPin, HIGH);
digitalWrite(AckPin, HIGH); //Activate pullup resistor"
  View user's profile Send private message
Reply to topic



Back to the top of this page

Back to SMS Power!