From: 	"David Caldwell"<David_Caldwell@indigita.com>
Sent: 	Wednesday, June 18, 1997 5:40 PM
To: 	"Jerry Lawrence"<Jerry@eteklabs.com>
Subject: 	Re: Pac maze

At 10:05 AM 6/18/97 -0400, Jerry Lawrence wrote:
>Hey there.  I found your page... neat stuff..
>
>i was wondering how the maze in pacman was encoded in the roms... i found
>your executable, but being that it is in mac compressed format, and i'm on
a pc, 
>i can't decompress it.  

Well, I cant remember what offset it starts at off the top of my head (Im
at work). But I can send you the hacky code the made that executable. You
may be able to do something with it.... It displays the pacman maze on the
screen.
Other things I rmember: they only store half the maze (you xor the
characters with 1 to get mirror images of the graphics. In other words, you
draw half the maze normal, and the other half you xor the character-code
with 1 and then display the new character). The maze is Run-Length encoded:
If thers a section of the maze that looks like this:

-----------
| . . . . |
| . +-+ . |
| . +-+ . |
| . . . . |
-----------

then the data in memory would look like this:
-||||--4--1++1--1++1--4--||||-

thats starting at the top-left, going from top to bottom, then left to right.
The 4 means four dots in a row. the 1 means one dot in a row. Its stored
similar to that. All the walls are stored as the actual character code to
display them. The 4 would be an actual hex byte 04 in the data. Anyway, i
think thats most of the trickery. Apparently theres also a "color" map of
the maze and maybe a dot path. I dont have the format to those. I should be
getting some really good info on this shortly from I guy I met here on the
net. I'll be publishing this on my web page (since he doesn't have one) in
2-3 weeks hopefully. I've gotten some data from him already, but it wasn't
about the mazes. Keep checking.....

>i messed about with where i thought the maze was in the rom (on a regular
>pac man -- i've gotta walk before i run) and when i modified it, the way i 
>expected it to work, i found that it did not behave the way i thought 
>it would..

I have never modified the maze.

heres the important snippet of code that decodes the maze:

the "data" array holds the rom at 6j
the DrawCharacter function is defined as:
DrawCharacter(x,y,character_code);

x,s and ys are reversed in this. (All this vertical monitor orienting stuff
confuses me.)

{
	int x=0,y=0;

	c=0x437; // start of maze;

	while (1)

	{

		if (Button()) // cancel this if user hits mouse button

			break;



		if (c<=0xFFF && y<14)

		{

		    if (data[c] > 1 && data[c] < 0x30)// skip past this many

		        x+=data[c] -2;               // squares (dots go here)

		    else

		    {

		        DrawCharacter(27-y,x,(int)data[c]);
		        // the mirror image is obtained by xoring with 1

		        DrawCharacter(y,x,(int)data[c]^1);

		    }

				

		    if (++x >= 32) /* have we gone halfway? */

		        break;

		    c++;

		}

	}

}



Have fun, 
David


