MEMPTR Snake ------------ Written for CSSCGC 2011 by Digital Prawn 31st March 2011 Intro music by Digital Prawn Instructions ------------ Use keys 'o' and 'p' to steer the snake onto the money. Do this six times to progress to the next level. To win the game, avoid hitting yourself, walls or MEMPTR bricks, which are created when the Z80 CPU exhibits non-standard MEMPTR register behaviour. To win the game, complete all four levels earning a score of 24. Thanks ------ To the authors of BEEPOLA and the PHASER engine, which allowed me to write the intro tune. To Boo-boo and Vladimir Kladov for the technical info on MEMPTR here:- http://www.dup.as/amstrad-cpc/doku.php?id=memptr&DokuWiki=082533b1cf43e26eed90cb007e71fa14 To all emulator authors out there! Memptr snake FAQ ---------------- Q. What is MEMPTR? A. It's an esoteric register of the Z80 CPU used internally for 16-bit addressing and operations. It's not meant to be known to the Z80 software developer by design and therefore not many emulators emulate it and even some real hardware clones of the Z80 CPU don't exhibit the same MEMPTR behaviours as the orginal Z80. It typically never appears in register diagrams of the Z80. However, it has been found that bits 11 and 13 from the MEMPTR register can be transferred to bits 3 and 5 of the Z80's flags register on executing certain instructions. Furthermore from this it was found that certain Z80 instructions can change the value of MEMPTR. Q. So what does it matter? A. It doesn't, since no correctly written Z80 machine code program would have any valid reason to check bits 3 or 5 of the flags register. However, it can be demonstrated that if a really contrived program is written (like this game), then the MEMPTR register can be used to affect the flow of program execution. Q. So what's the point of that? A. Nothing really, just a bit of fun for the Crap Game Compo, however it does give a rough indication of which emulators/systems are capable of exhibiting accurate MEMPTR behaviour. Q. So, this game is a reliable indicator of correct MEMPTR emulation? A. Not really, for that only a dedicated Z80 test suite should be used. First of all, this game which was put together in a couple of hours quite possibly has mistakes in the MEMPTR testing code. Secondly, it only tests a small set of possible MEMPTR-affecting instructions. Only LD, ADD, RLD and CPI are tested (one per game level). Also only a very small range of numeric values are tested in the MEMPTR register (only 4 values out of 65536). Q. So are you a proponent of true MEMPTR emulation? A. Yes and no. No, because it serves no useful purpose whilst slowing emulation down. It also creates extra work for emulator authors and no known code "in the wild" uses MEMPTR functionality apart from contrived programs live this and Z80 test suites. Yes, because for some irrational reason, it just feels good to have "perfect" emulation that can pass all test suites, even if the MEMPTR emulation feature can be turned on or off by the user. Q. So if this game says "MEMPTR BAD" on a given emulator, then MEMPTR emulation is unsupported? A. Quite possibly, or it could well be bugs in my own code. This game should not be trusted as a definitive indicator of MEMPTR emulation. It's just a bit of fun. Please use a dedicated Z80 test suite. Q. So if this game says "MEMPTR GOOD" on a given emulator, then MEMPTR emulation is supported? A. Very probably, but this game only tests a tiny fraction of possible MEMPTR behaviour. Again, use a dedicated Z80 test suite to perform a far more thorough test of all possible MEMPTR-affecting instructions. Q. So can this game be won on a system identified as "MEMPTR BAD"? A. Yes, but it's much, much tougher to beat than on a system identified as "MEMPTR GOOD". The reward for playing it on a system with "GOOD" MEMPTR behaviour is a far easier gameplaying experience, but even then it requires a bit of practice to avoid hitting the walls. Q. Which emulator can play this game without "MEMPTR BAD" bricks appearing? A. SpecEmu 2.7 for Windows by Mark Woodmass. I'm sure there are others although they are currently in the minorty. Q. Why does the MEMPTR status display sometimes flicker briefly from "MEMPTR BAD" to "MEMPTR GOOD" during gameplay? A. Sometimes through sheer coincidence, the bits in the flag register are the same as they would have been if MEMPTR emulation was implemented, even though it isn't. Q. Why does the MEMPTR status display sometimes flicker briefly from "MEMPTR GOOD" to "MEMPTR BAD" during gameplay? A. Admittedly I have seen this once in several hours of gameplay. It's surely a bug in this game's code and not a problem with the emulator. In short, trust the emulator, don't trust this game! Q. how often is the MEMPTR testing code executed in this game? A. Once for every iteration of the main game loop, so the MEMPTR status display is being updated constantly, even if it looks like it isn't changing. Q. Why do you keep writing simple character-based worm/snake games? A. I only do it when there's an underlying technical quirk to the game. 1. Snake (co-written with Einar Saukas) demonstarted a snake game in one line of Sinclair BASIC. 2. Commode Nybbler part deux demonstrated a snake game wirtten in 6502 machine-code running on a ZX Spectrum (Thanks to Jimmy's Twenty Commodes Emulator). 3. MEMPTR Snake demonstrates contrived abuse of the MEMPTR register. Besides, snake games are trivially easy to write when there's not much spare time available. Q. MEMPTR snake is riddled with bugs, can they be fixed? A. I always release my source code into the public domain to make bugs easier to find. If you find a bug then pleae tell me and I'll be sure to fix it in the next version! Q. What happens if this game is run on a real ZX Spectrum? A. I strongly suspect it would run in "MEMPTR GOOD" mode but as I no longer possess a real spectrum I don't know this with 100% certainty. If you find this out, please let me know! Q. What happens if this is run on a clone of a ZX Spectrum? A. Apparently results may vary as some Z80 CPU clones are not 100% faithful to the original. Q. Level 4 - testing the "CPI" instruction, doesn't this depend on correct MEMPTR behaviour of the "LD" instruction too? A. Indeed it does, which means on a given system, if level 1 is showing "MEMPTR BAD", then level 4 pretty much must also show "MEMPTR BAD" (Making the game very difficult to complete). Q. Why do the "Game Over" and "You Won" screens look familiar? A. I ripped them from "Sid Spanners 2: The Slackening". Q. Why have you got some UDGs defined in the source code that are never used? A. I ripped them from "Smiler in Arrow Land" and kept them in as placeholders in case I needed to redefine more UDGs than were actually needed.