I know I'm not the only attract mode geek here so I decided to brush up on my assembly skills by breaking down the attract mode code. I've always been kinda fascinated by the seemingly endless number of possible outcomes.
It turns out that it is incredibly simple, with only 28 lines of code to handle Jumpmans movements. The movements are completely hardcoded with no randomness and no barrel/fireball/ladder detection. However, the barrels and fireballs behave exactly like they do in a game, so that is where the variability comes from.
It only becomes interesting if Jumpman is able to grab the hammer and actually smash something because when the screen freezes during the smashes, the script keeps running and the variable number and timing of the smashes is what makes the many different outcomes possible.
The input sequence table starts at 21D1 and only has 15 different moves. The first byte is the input. The second byte is the duration of the FOLLOWING input.
I've expanded on Jeff Willms commenting.
21D1 80 FE ; jump
21D3 01 C0 ; run right for 254 frames
21D5 04 50 ; climb ladder for 192 frames( it only takes 54 frames to climb the short ladder so he pauses at the top for 138 frames)
21D7 02 10 ; run left for 80 frames
21D9 82 60 ; jump left for 16 frames
21DB 02 10 ; run left for 96 frames
21DD 82 CA ; jump left for 16 frames
21DF 01 10 ; run right for 202 frames
21E1 81 FF ; jump right for 16 frames (grabs hammer)
21E3 02 38 ; run left for 255 frames
21E5 01 80 ; run right for 56 frames
21E7 02 FF ; run left for 128 frames
21E9 04 80 ; up for 255 frames
21EB 04 60 ; up 128 frames
21ED 80 ; jump for 96 frames
The code that calls the inputs follows directly after it. It's interesting to note that Jumpman occasionally makes it further than the 15 inputs in the table at which point the code starts using itself as input data. It will take some more experimentation to define those inputs although #16 and #17 seem to make Jumpman run right for at least 220 frames or so.
21EE 11D121 LD DE,#21D1 ; load DE with #21D1 (address of start of input table data)
21F1 21CC63 LD HL,#63CC ; load HL with #63CC (63CC holds the sequence # of the current input)
21F4 7E LD A,(HL) ; load A with input sequence #
21F5 07 RLCA ; multiply A X 2
21F6 83 ADD A,E ; add A to E (E = hex D1/ decimal 209)
21F7 5F LD E,A ; put A into E (this returns DE to the address of the current input )
21F8 1A LD A,(DE) ; load A from the address of the current input from table
21F9 321060 LD (#6010),A ; output A to Jumpman
21FC 2C INC L ; increment HL by 1 to 63DC (63DC holds the number of frames remaining to execute the input)
21FD 7E LD A,(HL) ; load the # of frames remaining to execute into A
21FE 35 DEC (HL) ; decrement the # of frames remaining by 1
21FF A7 AND A ; clear carry flag
2200 C0 RET NZ ; return if A is not zero
2201 1C INC E ; if A is zero increment E by 1 (advances to next input duration)
2202 1A LD A,(DE) ; load A with input duration
2203 77 LD (HL),A ; store input duration into HL (address 63DC)
2204 2D DEC L ; decrement HL to address 63CC
2205 34 INC (HL) ; increment the input sequence #
2206 C9 RET ; return
Earlier we were discussing this is in the shoutbox and Chris P was doing some experimentation using invinciblity cheat and it seems that in order for Jumpman to make it to the third girder he has to smash exactly 3 objects AND be standing at the base of a ladder when the hammer expires.
Discuss, fellow attract mode geeks!