in ,

Space Invaders, Hacker News


(LD) $ , A; Hold it 1610: FE (CP $) ********************************************************************************************************************************************************************************************************; Just one? A: C0 RET NZ; No keep going (B:) ****************************************************************************************************************************************************************************** 6B LD HL, $ B ; Set flag if … (E:) ****************************************************************************************************************************************************************

******************************************************************************************************************************************************************************** LD (HL), $ (********************************************************************************************************************************************************************************************************; … only one alien left 1611: C9 RET; Out

There is a huge empty area in the ROM between 0x0C (and 0x) FF (2K bytes but not on a 2K ROM chip boundary, which would have saved the cost of a chip). That’s 1 / 4th of the ROM empty, which leaves a lot of space for expansion. And yet it appears the developers felt they were running out of space! (Update … this area was for a diagnostics routine that got dropped)

The end of ROM beginning at 0x1E 00 contains an 8×8 pixel character set used to draw text on the screen. The area is filled out completely with characters, but some of them were not used in messages by the game. The developers reclaimed the space of these unused characters for other purposes (see 0x1F 52) rather than using the plentiful space at 0x0C 02. Very strange.

There is a hidden message in the Space Invaders code. You can get the message “TAITO COP”, with no “R” as in “CORP”, to appear at the top of the screen during the demo play. Wait for the demo play to start and hold down “2 Start”, “1 Fire”, “1 Left”, and “1 Right”. The order you press them and the timing does not matter as long as you get all the buttons down at the same time eventually.

That’s the first sequence. Then you have to hold down the second sequence: “1 Start”, “1 Fire”, “1 Left”. Again the timing does not matter. An easy way is to hold down the first sequence and just switch start buttons and let up on “1 Right”. You will see the message at the top of the screen in the “Flying Saucer” area (in red). The message will be erased when the demo finishes and you will have to reenter it every demo.

The MAME emulator has trouble with these simultaneous button presses. I was unable to reproduce the sequences in the emulator. I did patch the code to make a simpler sequence: “2 Start” then “1 Start”.

; ## - CheckHiddenMes  ; There is a hidden message "TAITO COP" (with no "R") in the game. It can only be  ; displayed in the demonstration game during the splash screens. You must enter  ; 2 seqences of buttons. Timing is not critical. As long as you eventually get all  ; the buttons up / down in the correct pattern then the game will register the  ; sequence.  ;  ; 1st: 2start (down) 1start (up) 1fire (down) 1left (down) 1right (down)  ; 2nd: 2start (up) 1start (down) 1fire (down) 1left (down) 1right (up)  ;  ; Unfortunately MAME does not deliver the simultaneous but ton presses correctly. You can see the message in  ; MAME by changing  (A6 to****************************************************************************************************************************************************************************************** and  (B1 to) ****************************************************************************************************************************************************************************************************. Then the 2start (down) is the only sequence.  ;   (A: 3A 1E) ********************************************************************************************************************************************************************************** (LD A, ($) ************************************************************************************************************** E); Has the 1st "hidden-message" sequence ...   D: A7 AND A; ... been registered?   (E: C2 AC)  JP NZ, $  AC; Yes ... go look for the 2nd sequence   (A1: DB) ****************************************************************************************************************************************************************************************************** (IN A, ($ 02; Get player inputs   A3: E6  AND $ 78;  _  Keep 2Pstart, 1Pstart , 1Pshot, 1Pleft, 1Pright   A5: D6  (SUB $) ;  _  0011 1st sequence: 2Pstart, 1Pshot, 1Pleft, 1Pright   A7: C0 RET NZ; Not first sequence ... out   A8: 3C INC A; Flag that 1st sequence ...   A9: 31 1E  LD E), A; ... has been entered   (AC: DB) ****************************************************************************************************************************************************************************************************** (IN A, ($ 02; Check inputs for 2nd sequence   (AE: E6) **************************************************************************************************************************************** AND $ 78;  _  Keep 2Pstart, 1Pstart , 1Pshot, 1Pleft, 1Pright   B0: FE 34 CP $ 037; 01  0100 2nd sequence: 1Pstart, 1Pshot, 1Pleft   B2: C0 RET NZ; If not second sequence ignore   (B3:

1B 2E LD HL, $ 2E1B; Screen coordinates B6: 0011 F7 0B LD DE, $ 0BF7; Message="TAITO COP" (no R) B9: 0E LD C, $ 0011; Message length (BB: C3 F3) ********************************************************************************************************************************************************************************************** (JP $) ********************************************************************************************************************************************************************************************* F3; Print message and out

There is a bug in the code, but it is very subtle. Here is a quick way to see it:

Shoot all the aliens but the one in the upper left. Try and stay to the left side of the screen as much as possible because you want to keep the aliens from shooting as much of your right shield as you can. Wait for this last alien to wiggle down the screen. Move to the far right side of the screen under the right edge of your right shield. The alien will turn green as it crosses the screen going from right to left above your shields. Just as it hits the left side of the screen and turns to eat your shields fire a shot into your shield. The game will think your shot hit the last alien and the next round will begin.

The timing is very critical, and it might take you several tries to see the bug. The best way to reproduce it is to play invaders in MAME and press Shift F7 when there is only one alien left. That will save the state of your game, and you can press F7 to reload that state if you miss the timing. Eventually you will see it.

The bug is documented in the code at 0x (********************************************************, but I'll explain it in detail here.

The aliens are all drawn relative to the bottom left alien in the rack. This is the "reference alien". Even if it has been shot it continues to move as the origin for all the others (see discussion on The Aliens below).

There is an algorithm in the code to convert a screen point to a column / row coordinate within the alien rack. Rows go from 0 (the bottom row) up to 4 (the top row). Columns go from 0 (the left column) up to 10 (the right column). The code uses a "count the s "algorithm to see how many 21 - pixels to add to the reference alien to get to (or just past the target point. There are separate counts for X and Y. Each alien consumes a (x) pixel area on the screen. If the player's shot hits any pixel within the alien rack, this algorithm will find the row / column coordinate of the alien that was hit.

The "count the s "algorithm does NOT do boundary checking at all. The caller must assure that the target point is within the alien rack or unexpected values ​​will result. If the target point is far to the right of the reference then the algorithm will produce a column number greater than the maximum th column. If the target point is left of the reference the results are a bit strange (see the code) and incorrect. Thus it is very important for the caller to make sure the target point is actually inside the alien rack.

The player-shot-collision code appears, at first glance, to check the boundary conditions correctly with some logical assumptions as follows:

The code first checks to see if the player's shot hit the saucer or exited the top of the screen. Next the code checks to see if the player's shot is above the Y coordinate of the reference alien. If the player's shot hits something below the saucer's zone and above the lowest alien point then it has to be inside the alien's x5 grid . What else could it be? No alien shots can be on the left or right of the grid. They can't be above it. Because the player's shot hit SOMETHING above the lowest alien point it must be a hit within the alien rack. Thus the "count s " algorithm will function correctly.

This assumption is the bug in the code. When the alien rack is down in the player's shield area then the player's shot can hit something outside the rack square - the shields.

Start a new game and watch the full alien rack as it hits the right side of the screen and moves left. Move so you are peaking out of the right edge of the right shield. Position yourself so your shots will just miss the edge of your shield. Notice that when the aliens turn at the left side of the screen your shots are missing the alien rack but would be hitting an extra column of aliens if there were one.

The key point here is that the right edge of the player's right shield is in the 14 th (invalid) column when the alien rack turns on the left side of the screen.

Now imagine all the aliens are dead except for the upper left. This alien is in row 4. Rows are numbered from 0 to 4 from bottom to top. This alien is in column 0. Columns are numbered from 0 to 10 from left to right.

The alien wiggles around and you shoot the right edge of your right shield when it makes its turn on the left into your screen row. The Y coordinate of your shot is below the alien. The game correctly calculates your shot hit row 3 (one below 4). The shot is outside the alien rack, but the code calculates the column anyway. It gets () (the (th column).

Aliens are numbered sequentially from 0 to 54 (

********************************** (Read More)*************************

What do you think?

Leave a Reply

Your email address will not be published. Required fields are marked *

GIPHY App Key not set. Please check settings

New “Chinachain” aims to connect hundreds of cities across China. Will it work?

The Mechanical Muse, Hacker News

The Mechanical Muse, Hacker News