How to make NES passwords

Everything related to the Nintendo Entertainment System.
Post Reply
David
The Prince of Persia
The Prince of Persia
Posts: 2846
Joined: December 11th, 2008, 9:48 pm
Location: Hungary

How to make NES passwords

Post by David »

I could not find any information on the web about how to make passwords for PoP1 NES.

So here is what I found out:

The password consists of 8 decimal digits:

Code: Select all

Digit #1: (minutes div 10 + digit #3) mod 10
Digit #2: ((level - 1) mod 4 + digit #3) mod 10
Digit #3: anything
Digit #4: (minutes mod 10 + digit #6) mod 10
Digit #5: checksum mod 10
Digit #6: anything
Digit #7: checksum div 10
Digit #8: ((level - 1) div 4 + digit #6) mod 10
How to calculate the checksum:
Start with 0, and then add the digits together from #1 to #8.
When you reach the checksum digits (#5 and #7), you need to use the *current* value of the checksum, mod or div 10!

Other points of interest:

* The hit points are not stored in the password. Instead they depend on the current level:

Code: Select all

Level       1  2  3  4  5  6  7  8  9 10 11 12 13 14
Hit points  3  3  3  3  3  4  4  4  4  5  5  5  4  5
These seem to match the guards' hitpoints on each level.

* The game accepts passwords for level 15 and 16.
These will load some garbage levels. Screenshots here: http://popuw.com/nes.html
On these levels, the D-pad doesn't work, but the A and B buttons do work.

* The level number is masked to four bits, so level 17 is level 1, level 18 is level 2, and so on.

* Minutes can be anything from 00 to 99, even though the game starts with 60 minutes left.

* The remaining seconds or ticks are not stored in the password.
Passwords with 0 minutes left sometimes immediately show the bad ending, sometimes the *same* password gives about half minutes of time.
Sometimes the bad ending appears while the prince is running towards the exit in the password room!

* The purpose of the "anything" digits is probably to make the structure of the password less apparent.

* There are at least five versions of the game: Europe (E), France (F), Germany (G), Spain (S), USA (U).
This information applies to all of them.

* The game considers the password 00000000 to be invalid, even though it would be a valid password for level 1 with 0 minutes left.

* The game decodes the level number in the following way:

Code: Select all

level_high := (digit #8 - digit #6 + 10) mod 10;
level_low := (digit #2 - digit #6 + 10) mod 10;
level := ((level_high * 4) or level_low) mod 16;
level := level + 1;
The important part is that it uses bitwise or instead of addition.
This is important only for custom-made passwords, because the game always makes passwords that result in level_high and level_low both to be within 0..3, and in that case, the two operations are equivalent.
User avatar
Norbert
The Prince of Persia
The Prince of Persia
Posts: 5743
Joined: April 9th, 2009, 10:58 pm

Re: How to make NES passwords

Post by Norbert »

I've posted a link to this thread in the Russian thread about NESPrincEd.
My reasoning is that maybe it's also interesting to some of the folks there.
David
The Prince of Persia
The Prince of Persia
Posts: 2846
Joined: December 11th, 2008, 9:48 pm
Location: Hungary

Re: How to make NES passwords

Post by David »

Norbert wrote: December 24th, 2017, 1:49 pm I've posted a link to this thread in the Russian thread about NESPrincEd.
My reasoning is that maybe it's also interesting to some of the folks there.
It seems that they already know how the passwords are made.
There is a password generator written in BASH, here: https://habrahabr.ru/post/193406/
That page also explains why we can't control the prince on the garbage levels, and how to fix it: set the RAM byte at address $0735 to $00.
AlexKuusk
Scholar Scribe
Scholar Scribe
Posts: 2
Joined: November 16th, 2019, 11:07 pm

Re: How to make NES passwords

Post by AlexKuusk »

I have put PoP NES password generator and decoder into one little webapp.
There is one million valid passwords. 00000000 is valid by algorithm, however it will kill you in the game.
I generated and validated them all and packed into a csv file along with level and time information.

https://prince-of-persia.kuused.eu/
AlexKuusk
Scholar Scribe
Scholar Scribe
Posts: 2
Joined: November 16th, 2019, 11:07 pm

Re: How to make NES passwords

Post by AlexKuusk »

Domain of the generator has changed a bit - https://prince-of-persia.kuusk.eu/
Post Reply