DonHodges.com Logo

 

Defender Logo

Defender's Extra Life Bonanza

by Don Hodges
Posted June 9, 2008
Last updated 8/14/2015

Hear Defender's extra life sound

If a very skilled player manages to reach 990,000 points in the 1980 video game, Defender, the game begins to award extra ships and smart bombs at an incredible rate.  This occurs due to a bug in the algorithm that awards extra lives and smart bombs.  Here we will dissect the algorithm to explain why this behavior occurs.

A subroutine that checks for extra lives & smart bombs is called every time the player scores points.  This subroutine is concerned with values of the following variables.  I give each of them variable names in capital letters.

1.  Player's current score (SCORE)
2.  The score needed for the next extra life. (NEXT)
3.  The score needed for each extra life.  Normally this is set to 10,000 points. (EACH)
4.  The number of player's lives (LIVES)
5.  The number of player's smart bombs (BOMBS)

Here is pseudo code of the algorithm used:

IF SCORE >= NEXT THEN {
	NEXT := NEXT + EACH ;
	LIVES++ ;
	BOMBS++ ;
	CALL (Play_Extra_Life_Sound);
}

Assuming the factory setting of an extra life and smart bomb every 10,000 points, when a Defender game begins the score for next extra life is set to 10,000.  When the player reaches or exceeds 10,000 points, an extra life and smart bomb are awarded, and the score for next extra life is increased by the set value of 10,000.  So now this value is 10,000 + 10,000 = 20,000.

The problem occurs when the player's score reaches 990,000 or higher.  When the player reaches this point, the score for next extra life is computed to be 990,000 + 10,000 = 1,000,000.  But this value is only stored using 6 bytes, and thus rolls over to zero.  This is where the bug begins.

Now while the player's score is 990,000 or higher, and until he reaches 1,000,000 and flips his score back to zero, the player's score is always greater than what is needed for the next extra life.  Therefore, every scoring event during this period will award an extra life and smart bomb.  But the score needed for the next extra life is increased each time as well.

So, for example, if a player shoots 47 enemies during this period, he will earn 47 extra lives and smart bombs, but his next extra life won't be awarded until he reaches 470,000 points.  So, this extra life bonanza is really more of an advance on extra lives and bombs, not just free extras.

However, if the player is able to shoot 100 or more enemies during this period, the score needed for an extra life will roll over to zero again.  If a skillfull player earns exactly 100 extras, his next extra will be awarded at 10,000 points and he will get to keep all of the extra stuff that he was awarded during the bonanza.

It is only possible to earn 100 or more extras if the player deliberately gets himself shot many times by the enemies' fire, because each of these will only award 25 points.  While this kills a ship, an extra one is awarded to compensate and an extra smart bomb is awarded as well.  Assuming an average of 200 points for each enemy shot during this period, after shooting about 50 enemies the score will roll over from 990,000 to zero.  If instead, the player crashes into enemies' fire 57 times, earning 1425 points, and shoots 43 enemies at an average of 200 points each, earning 8600 points, he will have earned 100 extra ships and new ships will be awarded again at 10,000 points.  The player will have 100 extra smart bombs and 43 extra ships.

There was a previous rumor that earning 256 ships during this period would also allow for extra ships to be awarded again right away after the score turns over to zero, but this is not true.  As we have seen, if 256 were earned then the next extra would be awarded at 560,000 points.

From examining the source code, we can see that no rollover checks are done when extra lives and smart bombs are awarded.  So, if a player has 255 extra lives in reserve and wins another one, he will find himself with zero extra lives and his game will be over if he dies before earning another extra.  The same is true for extra smart bombs; if a player has 255 and then earns another one, it will roll over to zero and the player will have zero smart bombs.

Here is the assembly code of Defender that I analyzed to discover this information.  My comments follow the disassembly.

D39E: 8D 2A 	BSR $D3CA 	; Call sub below. Is score high enough for next extra life?
D3A0: 25 23 	BCS $D3C5 	; If no, jump ahead and return to program.
D3A2: A6 21 	LDA $1,Y 	; Yes, Load A with the LSB of NEXT
D3A4: 9B AC 	ADDA $AC 	; Add the value of the LSB of EACH
D3A6: 19 	DAA 		; Decimal adjust
D3A7: A7 21 	STA $1,Y 	; Store answer back
D3A9: A6 A4 	LDA ,Y 		; Load A with MSB of NEXT
D3AB: 99 AB 	ADCA $AB 	; Add with Carry the MSB of EACH
D3AD: 19 	DAA 		; Decimal adjust
D3AE: A7 A4 	STA ,Y 		; Store back
D3B0: 6C 06 	INC $6,X 	; Award extra life
D3B2: 6C 08 	INC $8,X 	; Award extra smart bomb
D3B4: BD D6 29 	JSR $D629 	; Update lives on screen
D3B7: BD D6 80 	JSR $D680 	; Update smart bombs on screen
D3BA: CC D4 B0 	LDD #$D4B0 	; Load extra life sound
D3BD: BD D5 4D 	JSR $D54D 	; Play sound
...
; The following subroutine is called from the first line, above. [D39E]
; It checks if score is enough for an extra life
D3CA: 34 06 	PSHS B,A 	; Save A and B
D3CC: EC 84 	LDD ,X 		; Load D with MSB of SCORE
D3CE: 10 A3 A4 	CMPD ,Y 	; Compare with MSB of NEXT
D3D1: 26 04 	BNE $D3D7 	; If not equal, return
D3D3: A6 02 	LDA $2,X 	; Else load A LSB of SCORE 
D3D5: A1 22 	CMPA $2,Y 	; Compare with the LSB of NEXT
D3D7: 35 86 	PULS A,B,PC 	; Restore A and B and return
 

It turns out that Stargate also has this bug

Addendum: 6/10/2008 Stargate has this bug, too. However, players will not see it until they reach 99,990,000 points. Since the world record for Stargate (as of 6/10/2008, according to Twin Galaxies) is "only" 47,473,400, no one has ever been able to see it in action. Using a MAME cheat to set the score = 99,980,000 and NEXT = 99,990,000, we observe that the same bug exists. All Stargate scores between 99,990,000 and 99,999,999 will award extra life, extra smart bomb and extra inviso. The source code for the extra life checking is almost exactly the same as Defender, except that all scores are saved as 4 bytes instead of 3. This fact also makes it impossible to gain any advantage by winning over 100 extra ships during this period. The NEXT variable will NOT rollover at this point. You would need to earn 10,000 extra ships for that to happen, and that is simply not possible in the 10,000 points scoring window.

 

Comments and Conclusions

When Defender was introduced, it was considered to be so difficult that no one imagined that a score of 1 million points was even possible to achieve.  Thus, it is forgivable that this bug was not detected during play testing.

With a few extra lines of code, this bug could be fixed.   The program would have to check for rollovers in the variables, as well as for the certain condition when the score is about to roll over after the amount needed for NEXT has already rolled over.  I will not attempt this coding feat here; it is left as an exercise for the reader.

Coming Next:  A fix for Galaga's Stage 256 anomalies.

 

 

In accordance with Title 17 U.S.C. Section 107, some of the material on this site is distributed without profit to those who have expressed a prior interest in receiving the included information for research and educational purposes. For more information go to: http://www.law.cornell.edu/uscode/17/107.shtml. If you wish to use copyrighted material from this site for purposes of your own that go beyond 'fair use', you must obtain permission from the copyright owner.

 

All content Copyright © 2015 Don Hodges
Various logos are trademarks of their respective companies.
Send Email to Don Hodges