Showing posts with label space harrier. Show all posts
Showing posts with label space harrier. Show all posts

Sunday, March 08, 2020

Space Harrier: The protection strikes back!

This is a guest post from Adrian Smethurst. 

It was back in January 2015 when I first started looking into the Space Harrier code on reports of a ‘bug’ which gave the player ‘extra' lives when they lost a life.  This ‘bug' only affected the game when played in either MAME, on an Enduro Racer converted board or a bootleg Space Harrier board.  It turns out that it wasn’t a bug but rather a time delayed protection mechanism created by Sega to try and hit the arcade operators, who bought bootleg Space Harrier boards back in the mid 80’s, in the pocket.  You can read more about that here.

Space Harrier PCB with Intel 8751 Microcontroller

Fast forward 5 years and a conversation I was having with respected indie game dev and creator of Fortress Craft, Adam Sawkins (ex. Criterion and Codemasters) about Space Harrier, at Arcade Club Leeds.  He asked me why, after the game had been powered up for a while, the enemy shots would start to come at the player faster and faster, to the point where you’d need lightning quick reflexes to simply avoid them.  He also told me that a reboot of the game would reset the enemy shot speed back to normal again, for a short while.  Hearing this news immediately sent my mind drifting off to a time 5 years previously when I’d investigated (and presumably fully defeated) the time delayed protection in Space Harrier.

So that night I went home and stated looking further into the Space Harrier code…

The heart of the protection is built around the ‘in-game’ timer.  This is a 6-byte timer located at address $40020 in main CPU address space.  The first 4 bytes of the timer represent the ‘seconds’ of in-game time played and the final 2 bytes represent the sub-second (frame) timer.  The timer is reset to zero at the start of each new game.  The timer is only incremented during normal gameplay, attract mode gameplay doesn’t increment the timer.  Every vertical blank the sub-second timer is incremented and compared with a value of 61 (yes, it’s a bug!).  If the sub-second timer is greater than 61 then it’s reset to zero and the ‘seconds’ part of the timer is incremented.  This means that, due to the bug, 1 second on the ‘in-game’ timer is actually 62 frames of gameplay, rather than 60.  The code that increments the ‘in-game’ timer is at address $1514 (it also updates the power-on timer located at memory address $40000 at the same time).

During every frame of normal gameplay code at address $4aae checks if the ‘in-game’ timer is at a multiple of $200 (this should, in theory, have been every 512 seconds but due to the bug mentioned above is actually every 529 seconds) and if it is the following code is executed :-

004ACC: move.w  $12444e.l, D0   
004AD2: move.w  $404ee.l, D1
; d0 and d1 never seems to contain a value other than 0 after many hours of gameplay testing
004AD8: eor.w   D1, D0          ; d0 = d1 XOR d0               
004ADA: cmp.w   $40090.l, D0    ; compare d0 with value at $40090.w
004AE0: blt     $4af0           ; branch if d0 < contents of $40090.w

If the 'branch less than’ condition is false (i.e. IF d0 < contents of the word memory @ $40090) then

004AE4: addq.w  #1, $4008e.l    ; trigger ‘previously unknown’ protection
004AEA: addq.w  #1, $400f0.l    ; trigger the 'increase lives' protection

When I was investigating the protection routine 5 years ago I completely failed to consider the first of these 2 instructions and only concentrated my efforts on investigating the second one.  This is because, at the time, I’d only been made aware of the ‘increasing lives’ issue.  So at the time I worked backwards from the ‘number of lives' counter to find out what was increasing the number of lives.  From there my investigations led me back to the instruction at address $4aea.  At that point I wrongly assumed that the ‘increasing lives’ issue was the only side effect of the protection routine.

How wrong I was…

The word value at address $4008e is directly related to the game difficulty.  It’s a value that's set initially by the boot-up code reading the ‘difficulty’ settings from dip switch B and is set as follows :-

EASY/MEDIUM     0
HARD            1
HARDEST         2

The code which does this is at address $2d7c.  This value is then subsequently used as part of the calculations in the routine which handles the enemy shots at address $b9d2.  It’s easy to tell that that routine handles enemy shots as if you change the first word of the routine from $08ed to $4e75 (RTS) the enemies will no longer fire shots at the player during gameplay.  The higher the value at address $4008e, the faster the enemy shots head towards the player.

Ordinarily the difficulty value at address $4008e would NEVER change after boot, assuming the game code is running on a genuine Space Harrier board with the 8751 MCU present.

However, as you can see from above, the instruction that I completely ignored 5 years ago, INCREMENTS that value (and hence the difficulty level) every 529 seconds of in-game play.

What this effectively means is this - if you power up the board from cold, ensure the difficulty setting on dip switch B is set to EASY and complete the game (assuming roughly 18 minutes for a full playthrough, although I have seen people complete the game in around 17 minutes) then the difficulty will be at the HARDEST level by the time the game completes.

And it will keep getting harder for each 529 seconds of completed ‘in-game’ time.  This is because the value at $4008e is only reset by either rebooting the game or dropping in and out of service mode.  It ISN’T reset at the start of each new game.

It’s very easy to see the results of a higher value at address $4008e by simply changing it via the MAME debugger and playing the game.  Values of 6 and above (which would represent just 3 or 4 full playthroughs from starting on EASY difficulty) make the game almost impossible to play as the enemy shots head towards the player with such high velocity..

Taking a step back, I feel it’s likely that the 8751 MCU probably exposes a value of 1 at address $40090 (it could in theory be any value between 1 and $7fff for the conditional branch instruction at address $4ae0 to pass but 1 is the most likely value, IMHO).  The updated patch has been added to the Sega Enhanced package here.

I hope that this finally lays to rest the protection in Space Harrier.

Tuesday, February 25, 2020

Space Harrier Bootleg Cabs

It's always fun to see the effort bootleggers went to, to completely reproduce an entire arcade game. Here are two rare, and different, examples of a Space Harrier upright. 


Here's the first. Note the unique marquee and dubious side art. The Space Harrier logo is incomplete. The Sega logo is completely missing. The shading details are omitted.  Presumably this was converted to Enduro Racer at some stage, hence the handlebars.


Here's the second. This sports a Sega logo and the side-art is much more accurate. But there are many cabinet design differences from a genuine upright. For example, the screen bezel is completely different. The marquee is a different size, clipping the artwork. 






Here are the PCB stack and internals. Those familiar with the original boardset will note the additional daughter boards to replace various Sega customs. Overall, a lot of effort went into this reproduction. 







You can see other bootleg Sega cabs here. 

Wednesday, March 21, 2018

The Space Harrier prototype featuring a Harrier Jet!

It's common knowledge that Space Harrier was originally intended to feature a harrier jet. However, technical limitations regarding the rotation of the jet sprite meant that this idea was dropped late into development. Recently, some screen captures surfaced from a video showing the prototype machine in action at the Amusement Show in Japan. 

The side-art and marquee are different. However, the colour palette and general aesthetic appear similar in the screenshots. 





The above cabinet design is similar to the prototype drawing that appears in Yu Suzuki's GameWorks Vol 1.


Of course, it was too late to change all aspects of the design, and Space Harrier still launched with an aircraft inspired control panel. The jet idea was fully realized two years and two hardware cycles later when Sega released the X-Board hardware with AfterBurner. Custom maths hardware, and extra sprite data enabled Yu Suzuki's original vision to be executed competently by this point. 



Sources: 1, 2 

Thursday, January 18, 2018

Build your own Space Harrier cab: Dorimaga papercraft model

Thanks to Sean Tagg for scanning the Space Harrier papercraft model included with Dorimaga magazine.




Sean mentions, "I enlarged the sheet to A3 and laminated it. I have used this to then make a model from balsa wood. The screen is a photo keychain. The seat is fabric too! Just need to add the coin tower."



Here's the finished article, now with coin tower:


Finally, a link to the scan if you want to build one yourself.

...and yes, I need to scan my Dorimaga OutRun magazine at some point soon. I've misplaced it for the time being, but it will show up somewhere! 

Wednesday, January 25, 2017

Out Run: Early Cabinet Screenshot

Here's an early photo of an OutRun Deluxe cabinet. [source]


If you look closely at the screen, you will spot that there are a number of differences from the released version. This must be running an early prototype version of the game.
  • Timer is using the font from Space Harrier. This font is in the OutRun ROMs but not used anywhere. Now we know it was used in an earlier prototype version.
  • Sign art is different in a number of places from release.
  • Debug information above speed on left hand side.
  • No rev counter
  • kp/h graphic is different
  • No route map




This Space Harrier also has some differences from the released version:
  • A step built into the base at the front which was later removed.
  • The side art is different; the underbelly of the dragon and his hair are orange on this version and yellow on the final art.
  • Different rear art, that also extends beneath the seat
  • Different instruction plate
  • Different 'Warning!' stickers on the base
  • Sega logo size on the rear panel and title screen
  • Missing the sliver/red bezel stickers



Monday, January 05, 2015

Space Harrier Protection Mechanism

The Sega Enhanced package has been updated with a fix for a protection issue when running the game on Enduro Racer hardware. Sega protected the original game code, to prevent it from running on hardware without the i8751 microcontroller.

It was previously thought that the protection was defeated, however an interesting bug surfaced. Interestingly, MAME did not correctly support the protection either. This resulted in Space Harrier being flawed on MAME, with the life counter incorrectly incremented.

More details from the UKVAC post are below:

This all came to light when Space Harrier world champion and fine upstanding member of the UKVAC community Jodo mentioned in the discussion that there was a *bug* in Space Harrier when played on Enduro Racer hardware whereby occasionally your lives remaining would NOT decrease when you got hit by an enemy, or in some cases your lives remaining would actually *increase* when you got hit by an enemy.  He posted a video of it in action and I then also confirmed that the issue existed using both patched and unpatched SH roms in MAME.

Well this fascinated me and, as I've become rather adept at fixing Sega code bugs in the past few years, I thought I'd look into it deeper to hopefully resolve it.

As you may be aware it's possible to play Space Harrier on an Enduro Racer board set.  The only difference between an SH board set and an ER board set is the inclusion of an i8751 protection MCU on SH.

It was originally thought that the only purpose of the MCU was to check the main cpu roms at boot time, generate a vblank interrupt for the main cpu and process analog inputs/pass them to the main cpu.

It now turns out that this is not the case and the MCU does further protection on the game code.  This is the *bug* (it isn't actually a bug, it's protection code).

The protection routine starts at address $4aae in the main cpu code.  It works by querying the in-game timer (the timer that starts when you start a new game) and if the timer is a multiple of $200 (512) seconds it adds 1 to the word value @ $400f0 in memory.

This value is then copied, every vblank, to $124306 (in shared ram) by the code @ $4e86.  This is the trigger for bad things to start happening.

The value at $124306 is queried whenever you lose a life by the code @ $75ca and the following happens, based on the value held in that memory location at that time :-

if the value is 0 then nothing further happens (this is what the value should ALWAYS be)

if the value is 1 (i.e. after 512 seconds of gameplay) then the in-game frame counter is ANDed with a value of 1 and the result is ADDED to your lives remaining count.  The routine which subtracts 1 from your lives remaining count is then called and the game continues.  What this means, in effect, is that, after 512 seconds of gameplay, you've got a 50/50 chance of NOT losing a life when you get hit by a bad guy.

if the value is 2 (i.e. after 1024 second of gameplay) then the in-game frame counter is ANDed with a value of 3 and the result is ADDED to your lives remaining count.  The routine which subtracts 1 from your lives remaining count is then called and the game continues.  What this means, in effect, is that, after 1024 seconds of gameplay, you've got a 25% chance of losing a life, a 25% chance of NOT losing a life, a 25% chance of GAINING a life or a 25% chance of GAINING 2 lives, when hit by a bad guy.

if the value is 3 or higher (i.e. after 1536 seconds of gameplay) then the in-game frame counter is ANDed with a value of 7 and the result is ADDED to your lives remaining count.  The routine which subtracts 1 from your lives remaining count is then called and the game continues.  What this means, in effect, is that you're now swimming in extra lives, to the point that the game will eventually crash if you keep getting hit by the bad guys (as you've accumulated so many lives by this point).


Long serving and well respected MAME dev team member Chris Hardy (Junofirstman on here) has confirmed my initial findings.  He believes the MCU writes a value of zero to address $400f0 every vblank, so the absence of this simulated code in SH running on ER hardware or in MAME meant that the above phenomenon was happening after 512 seconds of gameplay.

Chris has updated the MAME driver and submitted it and also suggested a patch to the roms for playing on ER hardware which will eliminate the problem.

So, taking a step back, I think this was a pretty crafty protection scheme by Sega.  Time delayed protections are usually very effective and the most difficult to find as they often don't start kicking in until a long time after the game has booted (as is the case here, ~8.5 minutes of gameplay until the effect is noticed).  This means that the bootleggers may have thought that they'd overcome the MCU protection if they managed to clone the functionality of it sufficiently to get the game to boot.  They may not then have proceeded to test it sufficiently long enough to notice the time delayed protection effects kicking in.

What this would mean though is that, if SH was bootlegged and the bootleggers didn't overcome the time based protection and arcade operators bought a bootleg board instead of a genuine Sega board then the operators would likely have been losing money as the players would have been getting much longer gameplay for their 10/20p due to all the extra lives they'd have been getting.  So Sega's idea was to hit the operators where it hurt, in the pocket.

Thanks go out to Chris Hardy, Jodo, Mark Haysman and Ordyne for all chipping in with info and to Sega for making awesome games with semi-awesome protection. 

Wednesday, August 06, 2014

Sega Enhanced (formerly OutRun Enhanced Edition)

The OutRun Enhanced Edition pack has evolved and is now a multi-pack supporting additional Sega titles. Adrian Smethurst created a patch for Super Hang-On and Limited Edition Hang-On to improve free play mode.

Originally, with free play mode selected by the dip switches, the game would never enter attract mode. It immediately went to the class selection screen when a game was over. If unattended, it would time out and go to the music selection screen. If still unattended, it would time out and start a game; the game (and music) would play until the game timer expired, after which the cycle would start again at the class selection screen.

Improved free play mode DOES allow attract mode (no automatic credit is given). To begin a game in free play mode, simply press the START button whenever it is flashing. This "coins up" the game, and proceeds to the class selection screen.

In addition, the OutRun Enhanced patches can now be applied to the original Japanese rom set with the alternate track layouts.

The patches to run Enduro Racer on the Space Harrier hardware are also included for convenience.

Download the package from here. 

Tuesday, February 19, 2013

Space Harrier Easter Egg (Dev Credits)

Whilst you're patiently waiting for me to finish force feedback support in Cannonball (it's going well), here's a Space Harrier Easter Egg for you to try.

It's similar to the OutRun egg, in that it provides a Yu Suzuki development credit, along with the development date. Interestingly November 1985 was around the date the AM2 team started OutRun, which probably explains why the team used the Space Harrier code as a framework to work from.


Like most AM2 titles, the egg is somewhat tricky to activate. You need to enter the code during the death / respawn sequence; therefore after the character collides and flips upwards or is flashing.

The code is:
  • Press button 3 (typically mapped to space on MAME) six times. 
  • Press the start button eight times. 
  • Then finally, press button 3 again. You should see the message.
You can enter the code over multiple iterations of this death sequence. So you can start after the first time you die, and complete it the second time you die. However, any error in input resets the code, so go carefully.

Monday, December 24, 2012

Space Harrier Wiwi Jumbo Music Data In OutRun?

Whilst creating Cannonball, I uncovered a large section of unused YM2151 music data in the Z80 program code. Initially, I was excited - could this be an unreleased Hiroshi Kawaguchi classic? 

Unfortunately, after hacking the code to play the data it sounded like garbage. I wasn't sure if this was a problem with MAME's emulation, so I asked Alex of the OutRun bootloader project to play the sound on hardware. He sent me the results, which you can download here as an MP3. 

It still sounded wrong, so at this stage I stopped investigating. It wasn't until later that night when I randomly happened to be playing the Space Harrier soundtrack on vinyl, that I came across the following composition:



I wonder if this is the Space Harrier Wiki Jumbo track embedded, but playing incorrectly due to other modifications to the sound code? It's a shame, because otherwise we could have hacked OutRun to have an additional tune. Perhaps it's still possible with some additional work...

This maybe isn't a big surprise, we've already uncovered other segments of Space Harrier in the OutRun code.  

Cannonball news - I'm implementing a nice front-end menu, with lots of cool configuration options. Expect a new version after Christmas. 

Tuesday, September 06, 2011

Space Harrier: Enduro Racer Edition

This is a customized version of Space Harrier, modified to run on Enduro Racer hardware.


This means that the game is fully playable on the Enduro boardset without the programmed security i8751 CPU.

Normally, if you try to run Space Harrier on Enduro Racer hardware, the game controls will not function and therefore the game is unusable.

I'd like to thank Mark at retroclinic.com for performing the hardware testing. Without him, this wouldn't have been possible as I don't own either boardset. Please note that currently this requires Enduro Racer hardware with the earlier YM2203 sound board.

Download here: sega_enhanced_v203.zip

Version 2.0.3: Space Harrier: Protection Fix #2 (Enemy shots getting faster over time)
Version 2.0.1:
Incorporated into Sega Enhanced package. Fixed lives bug. 
Version 1.0.1: JunoMan from Sega Resurrection suggested a more elegant solution. Results should be the same. Thanks! 
Version 1.0.0: Initial Release


Please note that no portions of the original game code are included in this package.