Hacking 3D Ant Attack



3D Ant Attack is a home computer game from 1983, which pioneered the 3D isometric viewpoint. Find out all about it from Sandy White, the author of the game.

While tidying out the attic, I came across some old notes I made while hacking at Ant Attack on my wee Sinclair ZX Spectrum many years ago; here's the bulk of what I could actually read. No guarantees are made as to its completeness, presentation, or accuracy :) .

Pokes

POKE 32895,12: POKE 32897,4: POKE 32905,8

- Changes the rotation keys from M and Symbol-Shift to N and M; this makes rotating easier when running the game under certain emulators, notably the Psion Series 5 one.

POKE 35105,7: POKE 34068,1

- Allows you to jump while standing on the roof of a tall building (ie 6 blocks high). This may have unexpected side effects but I haven't seen any yet. For the technically minded, the first poke changes the maximum altitude you can jump to, and the second lets the engine draw sprites that high up.

POKE 34754,0: POKE 34758,255

- Grenades will paralyse ants rather than blow them up.

City Map

The city (shown here in all its glory) is mapped in the top 16k of memory. Each vertical column is represented by one byte - there are 128x128 columns of city space. On this map, the data starts at the left, runs along the top-left wall to the top, then repeats for the next row, until finally the last 128 bytes represent the front wall of the city.

Of each byte, the lower 6 bits indicate the presence of blocks at various heights - Bit 0 (LSB) is a block resting on the ground, Bit 5 is the highest block possible. I think Bit 7 (MSB) is a flag indicating that there is a sprite somewhere in this column. Further, the appropriate bit (it should always be bit 0!) is set in the city byte to indicate the presence of an ant, for collision-detection purposes.

Sprite Graphics

The image to the right is a graphical dump of game memery from 8000-BFFF. The sprite graphics are clearly visible. Each sprite is 16x16 pixels, represented by 64 bytes of data. For each pixel row (they're stored top-to-bottom), the four bytes are:

  1. Left half mask
  2. Left half data
  3. Right half mask
  4. Right half data

To display, the screen byte is AND'd with the mask then OR'd with the data, the put back on the screen.

The building blocks do not appear here because the byte values are poked directly by the machine code for speed.

The program does crunch some areas of data in memory while drawing the city, but I haven't looked at that part of the code in enough detail to know what's going on.

Memory Map

xxxx-7FFFBASIC Program etc.
8000-8FFFMachine code.
9000-97FFText messages.
9A00-9FFFGraphics for ammo box and girl.
A000-AFFFScreen buffer.
B000-B17F?
B180-B41FBuffer holding visible area of city.
B420-B449Data storage
B436-7 is the countdown timer.
B450-B47FErm... some kind of table of sprite graphic addresses?
B480-B48FSprite data for player.
B490-B49FSprite data for friend.
B4A0-B4AFSprite data for grenade/box.
B4B0-B4BFSprite data for ant 1.
B4C0-B4CFSprite data for ant 2.
B4D0-B4DFSprite data for ant 3.
B4E0-B4EFSprite data for ant 4.
B4F0-B4FFSprite data for ant 5.
B500-B6FFData for something?
B700-BFFFGraphics for boy, plane, grenade, explosion and ants.
C000-FFFFCity data.

Messages

One of the program's interesting features is the routine used to display messages during the game. It uses the ROM text printing routines, and can therefore use all the standard control codes for colour changes and cursor positioning. In addition, the routine uses code 125 to change the colour attribute of the whole view, code 126 to display the contents of a memory location in decimal, and codes 128 and above to produce sounds. The messages are:

1NASTY FALL!
2"HELP - I FELL!"
3(explosion) GOOD SHOT!
4Display ammo counter.
5Grenade detonation.
6SILLY! YOU BLEW YOURSELF UP! (death march)
7BITTEN!
8Display player life.
9HOW COULD YOU? AFTER ALL WE'VE BEEN THROUGH?
10"THEY GOT ME"
11Display friend life.
12"MY HERO! TAKE ME AWAY FROM ALL THIS!"
13CONGRATULATIONS!
14EATEN ALIVE
15"I'VE BEEN EATEN ALIVE"
16PARALYSED AN ANT!
17YOU ARE A REAL HERO (etc)

Sprite State Data

There are in fact only 8 sprite objects in the game; the player and friend, five ants, and a grenade (while not being used, it hides outside the city in the form of an ammo box).

This data is usually addressed by the game using the IX register.

OffsetPlayerFriendGrenade/BoxAnt
0Current X-coordinate (lower-left to upper-right on default view).
1Current Y-coordinate (upper-left to lower-right on default view).
2Current Z-coordinate (height).
3Pointer to graphics data.
4Current direction.
5Counts depth of fall.
6Sleep countdown; 255=forever (paralysed ant).
7Bit 0 = allows sprite to stand on other human sprite.
Bit 1 = jumping.
Bit 2 = walking.
Bit 3 = makes sprite immune to gravity.
Bit 4 = auto-jump when hitting an obstacle. Set for friend and grenade, works for player, sort-of works for ants.
8Sprite frame: 0=standing, 1=walking, 2=crouching, 3=laying, 4=falling.Sprite frame: 0=standing, 1=walking.
9Explosion frame counter.
AInitial X-coordinate.
BInitial Y-coordinate.
CInitial Z-coordinate (height).
D0=lost,1=found.Initial walking speed delay count.
EDistance from player while lost.Walking speed delay count.
FBit 0 = walking.
Bit 1 = fell too far.
Bit 2 = got bitten.
Bit 3 = blown up.

Web page by Tyrone C. | Back to homepage