While contemplating what ZX81 program to write about this month, I completely forgot that I had created a Pitfall! Simulator. It began as a fun project to occupy my time during winter break. My initial goal was to recreate David Crane's LSFR (Linear Feedback Shift Register) in Z80. However, after learning more about its functionality, I took the project much further than I had originally intended.
# A Trip Down Memory Lane.
Pitfall! is a fun game that I enjoyed as a child, although I preferred the sequel, Pitfall II. The original game's linear progression felt underwhelming, and the jump timing was finicky. However, it was still a remarkable game that showcased the capabilities of the Atari VCS. It featured action, numerous changing rooms, and a sense of exploration. I particularly enjoyed figuring out how to best avoid those pesky logs, even though they slowed me down. Additionally, I appreciate that this is a game that my wife, who is not much of a gamer, also played. It is a shared piece of nostalgia for both of us.
Fun fact, I actually considered creating a Pitfall!-like game for the ZX81. I even went so far as to design the rooms and character graphics. However, I knew that working in BASIC, it would not be fast enough. Additionally, I did not understand how the original game was actually built. For my version, I was generating static rooms of content. I quickly realized, even at the age of 14, that I would run out of memory and abandoned the idea.
# Playing with the LSFR.
It should come as no surprise, then, that when I came across an article about Pitfall!, I was intrigued. The article discussed how David Crane managed to fit 255 rooms into Pitfall!. I thought it would be a fun programming challenge to get the LSFR working on the ZX81.
Since the article shared the original LSFR code, I used it as the basis for my version. I had to learn a little 6502 code to get the right bitwise operators, but I soon had a working version in z80 assembly. Below is the original LSFR for moving right.
; PITFALL! LFSR - move right!
; room' = room << 1 <pipe> (bit3 + bit4 + bit5 + bit7)
; input: d - holds the current room details
; output: a - holds the new room details
ld a,d ; load a with room
sla a ; could also be add a,a
xor a,d ; XOR with room
rl d ; rotate carry into room
ld a,d ; and make a the new room
; end move right
The simulator version is a lot more complex as I had to deal with the player being underground. That version uses a loop and has to check for walls. There is also a move left version that reverses the LSFR in that code.
Since the LSFR routine alone isn’t very useful, I added a print routine to show what is on each screen. Adding a little bit of logic, based on the rules set forth in the article, I had a working version of the opening sections.
Pitfall! Rooms, ZX81 Screenshot of the first 21 rooms, 2023 by Steven Reid
Sorry if the picture is a bit esoteric. The first is the room value in decimal. Next is the tree pattern. Then, the hazard (i.e. holes, tar pits, crocs, etc.) with wall or treasure (i.e. G is gold). Last is any objects such as logs, snake, or fire. This is the first 21 rooms moving right. And yes, moving left works as well.
# Making Something a Bit More Interesting.
After getting the code working, I wanted to make it something you could actually move through. My intention was not to create a game, but to simply get the look and feel of each room working. I called it a Pitfall! Simulator because that is what it is. It simulates the game's screen generations, including the ladders and underground corridors.
Pitfall! Simulator, ZX81 Screenshot of the Starting Room, 2023 by Steven Reid
It was also at this point that I realized the rules posted in the article were not 100% accurate, as things were not matching up. Digging around, I found a more complete version. Combining those, I soon had a working simulator for Pitfall!. The code logic was pretty complex now and I made no effort to optimize it.
To make sure things were working, I used a map link from the original article to verify that the simulator. Funny enough, I found some discrepancies there as well. I ended up finding actual footage of the rooms to validate the routines.
Pitfall! Simulator, ZX81 Screenshot of the Crocodile Hazard Room, 2023 by Steven Reid
This program is meant as an easy way to traverse the map, but without all the game play. However, if you do go underground, it does block your movement. This makes it easy to test out different paths and see what works. Obviously, the golden path to beat the game in under 20 minutes has long since been discovered. But you might find it fun to try out different paths without a timer or skill getting in the way.
Pitfall! Simulator, ZX81 Screenshot of Going the Wrong Way, 2023 by Steven Reid
All that was left at this point was adding in all the visual elements. It was a bit of a chore adding in all the hazards as they tended to overlap other elements. Although the player doesn’t really move in the simulator, I did have to simulate location, specifically which side of the map you are on based on direction of entry.
# Is there more?
Could I have made this into a game? Sure. Will I? Probably not. Pitfall! was an iconic game, and trying to convert it to the ZX81 would require so many compromises that it would not be worth it. I would have to significantly reduce the motion and screen size, and even then, trying to achieve a full screen with smooth motion would be difficult. There are games that already emulate it to some extent, and I would not be adding much.
Pitfall! Simulator, ZX81 Screenshot of the Gold Loot Room, 2023 by Steven Reid
Instead, I am sharing this for what it is: a realistic Pitfall! simulator. It is accurate to the game—perhaps the most accurate so far given what I have seen out there. Additionally, converting the LSFR to the Z80 might inspire others to do something with it. Heck, I might even find a use for it myself.