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: 9
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: 8349
  • 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: 9
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: 484
  • 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: 9
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: 484
  • 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: 2908
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: 13650
  • 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
Reply to topic



Back to the top of this page

Back to SMS Power!