Author Topic: Attract mode code breakdown  (Read 25609 times)

0 Members and 5 Guests are viewing this topic.

Offline JCHarrist

  • Spring Jumper
  • *
  • Posts: 643
    • Donkey Kong Forum
    • Awards
Attract mode code breakdown
« on: July 18, 2013, 09:25:16 pm »
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.

Code: [Select]
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. :o

Code: [Select]
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! ;D


« Last Edit: July 18, 2013, 09:27:40 pm by JCHarrist »
Member for 11 Years DKF Founder Former CK World Record Holder - Arcade CK Killscreener DK Killscreener

Offline marinomitch13

  • Spring Jumper
  • *
  • Posts: 1806
    • How to Play DK
    • Awards
Re: Attract mode code breakdown
« Reply #1 on: July 18, 2013, 09:54:52 pm »
Code: [Select]
21E9  04 80 ; up for 255 frames
21EB  04 60 ; up 128 frames
21ED  80 ; jump for 96 frames
So, based on this (the fact that there are no potential movements to the right after climbing to the third girder), it is impossible for Jumpman to get to the 4th girder... correct?
"Thou hast made us for Thyself, and our heart is restless until it finds its rest in Thee." -Augustine, Confessions.
Member for 11 Years IGBY 2015 DKF Team Member DK Killscreener Blogger Twitch Streamer

Offline JCHarrist

  • Spring Jumper
  • *
  • Posts: 643
    • Donkey Kong Forum
    • Awards
Re: Attract mode code breakdown
« Reply #2 on: July 18, 2013, 10:06:21 pm »
Code: [Select]
21E9  04 80 ; up for 255 frames
21EB  04 60 ; up 128 frames
21ED  80 ; jump for 96 frames
So, based on this (the fact that there are no potential movements to the right after climbing to the third girder), it is impossible for Jumpman to get to the 4th girder... correct?

Well, as I stated, after the #15th input, the code "overflows" out of the table data and starts reading inputs from the program code itself. It seems that #16 and #17 make him run to the right for around 220 frames, but that's as far as I've ever seen him survive.
Member for 11 Years DKF Founder Former CK World Record Holder - Arcade CK Killscreener DK Killscreener

corey.chambers

  • Guest
Re: Attract mode code breakdown
« Reply #3 on: July 18, 2013, 10:28:08 pm »
I used the invinsibility cheat along with the always climb cheat. I shut off the always climb while jumpman is half way up Pauline's ladder. He will climb to the top on his own, get to the top and stop. The rom literally stalls, it will not let you play the game. :)

Offline f_symbols

  • Spring Jumper
  • *
  • Posts: 835
  • wht u mean
    • Awards
Re: Attract mode code breakdown
« Reply #4 on: July 18, 2013, 10:34:07 pm »
I just realized that this is the only way to actually end the game next to Pauline
Member for 11 Years IGBY 2016 DKF Team Member Winner of a community event Former DK Remix World Record Holder DK Remix Killscreener IGBY 2015 DKF Team Member DK 1M Point Scorer IGBY 2014 DKF Team Member Blogger DK Killscreener Twitch Streamer

Offline alumbrada

  • Senior Member
  • *
  • Posts: 164
    • Awards
Re: Attract mode code breakdown
« Reply #5 on: July 18, 2013, 10:46:58 pm »
I used the invinsibility cheat along with the always climb cheat. I shut off the always climb while jumpman is half way up Pauline's ladder. He will climb to the top on his own, get to the top and stop. The rom literally stalls, it will not let you play the game. :)

A reliable source told me you were on 1.3M pace. Great job!
DK high score: 89,100
Member for 11 Years IGBY 2015 DKF Team Member Blogger Twitch Streamer

Offline ChrisP

  • Spring Jumper
  • *
  • Posts: 1764
  • I'm going to jump next to your leg.
    • Donkey Blog
    • Awards
Re: Attract mode code breakdown
« Reply #6 on: July 19, 2013, 12:35:43 am »
Using the "Always Climb" was a great idea, Corey.

Fascinating that the game stalls. Imagine if it kept going. Somebody could painstakingly put together a kill screen...

We finally got demo-Jumpman through the attract mode! Love it!
http://donkeykongblog.blogspot.com

4 Quarters :-* - 800K Avg. Per Qtr. :o - No Restarts 8) - No Proof :'(

7/26/2013   Coin 35,946   710,800   18-1
7/28/2013   Coin 35,947   903,700   22-1
8/16/2013   Coin 35,948   694,100   17-6
8/17/2013   Coin 35,949   893,100   22-1

3,201,700: the $1 World Record?
Member for 11 Years DK Masters - Rank D DKJR Killscreener IGBY 2016 DKF Team Member IGBY 2015 DKF Team Member IGBY 2014 DKF Team Member Blogger Twitch Streamer DK Killscreener CK Killscreener

Offline stella_blue

  • High Score Moderator
  • Spring Jumper
  • *
  • Posts: 1530
    • Awards
Re: Attract mode code breakdown
« Reply #7 on: July 19, 2013, 05:37:43 am »
I used the invinsibility cheat along with the always climb cheat. I shut off the always climb while jumpman is half way up Pauline's ladder. He will climb to the top on his own, get to the top and stop. The rom literally stalls, it will not let you play the game. :)

How do we end up with 9800 on the Bonus Timer?

DK High Score 
1,064,500
  (L22-1)
DK Level 1-1 
13,400
DK No Hammer 
535,300
  (L15-2)
Member for 11 Years Most Time Online DK 1M Point Scorer DK Killscreener Blogger Twitch Streamer

Offline mikegmi2

  • Elite Member
  • *
  • Posts: 431
    • Awards
Re: Attract mode code breakdown
« Reply #8 on: July 19, 2013, 05:46:57 am »
Yea 9800 bonus timer, wht da? Is that part of the invincibility cheat, it gives you extra time?

Pretty cool though.
Donkey Kong - 1,076,000 (arcade, KS)
Member for 11 Years DK 1M Point Scorer DK Killscreener Twitch Streamer

corey.chambers

  • Guest
Re: Attract mode code breakdown
« Reply #9 on: July 19, 2013, 06:42:04 am »
The bonus timer was an additional cheat, infinite bonus timer.

Offline LMDAVE

  • Spring Jumper
  • *
  • Posts: 639
    • Awards
Re: Attract mode code breakdown
« Reply #10 on: July 19, 2013, 06:48:38 am »
Code: [Select]
21E9  04 80 ; up for 255 frames
21EB  04 60 ; up 128 frames
21ED  80 ; jump for 96 frames
So, based on this (the fact that there are no potential movements to the right after climbing to the third girder), it is impossible for Jumpman to get to the 4th girder... correct?

Well, as I stated, after the #15th input, the code "overflows" out of the table data and starts reading inputs from the program code itself. It seems that #16 and #17 make him run to the right for around 220 frames, but that's as far as I've ever seen him survive.

That is very interesting, at least now I can see there is no programmed input beyond climbing to the 3rd girder, the run to right is strictly an overflow error like you said, but that almost always gets to that point. Maybe the programmer was jsut OK with that happening. But, when he does climb to the 3rd girder, if he ever managers to jump over the barrels, and there is a clear path....he'll run to the right but not fall off, or who knows what the next thing will do after the 220 frames to the right you said.

Would be neat to run the invisibility cheat without "always climb" and wait for him to climb to the 3rd girder and see what happens after the run to the right? You'd have to wait for about 15-20 screens through but should be able to do the fast forward.

BTW, not sure how always climb worked on the attact screen, does he always run in the right direction after climbing?
« Last Edit: July 19, 2013, 06:51:36 am by LMDAVE »
Donkey Kong (Arcade): 1,108,100

Donkey Kong 1-1: 12,900

http://twitch.tv/LMDAVE
Member for 11 Years DK 1.1M Point Scorer Winner of a community event Blogger DK 1M Point Scorer DK Killscreener Former DK Level 1-1 World Record Holder Twitch Streamer

Offline f_symbols

  • Spring Jumper
  • *
  • Posts: 835
  • wht u mean
    • Awards
Re: Attract mode code breakdown
« Reply #11 on: July 19, 2013, 06:55:59 am »
Dave, I believe that Chris said he runs off the right edge of the 3rd girder; apparently most of the "invincible" attract screens end with jump man on the bottom girder, due to survival after falling off the edges...

Perhaps the always climb cheat skips the bottom hammer?  Between the 13 other coded inputs and the overflow, it must've been enough
« Last Edit: July 19, 2013, 07:02:25 am by f_symbols »
Member for 11 Years IGBY 2016 DKF Team Member Winner of a community event Former DK Remix World Record Holder DK Remix Killscreener IGBY 2015 DKF Team Member DK 1M Point Scorer IGBY 2014 DKF Team Member Blogger DK Killscreener Twitch Streamer

Offline stella_blue

  • High Score Moderator
  • Spring Jumper
  • *
  • Posts: 1530
    • Awards
Re: Attract mode code breakdown
« Reply #12 on: July 19, 2013, 06:56:27 am »
Would be neat to run the invisibility cheat without "always climb" and wait for him to climb to the 3rd girder and see what happens after the run to the right?

How would we know that he's climbed to the 3rd girder, if we can't see him?

Just kidding, Dave.  I know what you meant.   :)

DK High Score 
1,064,500
  (L22-1)
DK Level 1-1 
13,400
DK No Hammer 
535,300
  (L15-2)
Member for 11 Years Most Time Online DK 1M Point Scorer DK Killscreener Blogger Twitch Streamer

Offline LMDAVE

  • Spring Jumper
  • *
  • Posts: 639
    • Awards
Re: Attract mode code breakdown
« Reply #13 on: July 19, 2013, 07:56:49 am »
Dave, I believe that Chris said he runs off the right edge of the 3rd girder; apparently most of the "invincible" attract screens end with jump man on the bottom girder, due to survival after falling off the edges...

Perhaps the always climb cheat skips the bottom hammer?  Between the 13 other coded inputs and the overflow, it must've been enough

You can't run off the edge of the 3 girder to the right.
Donkey Kong (Arcade): 1,108,100

Donkey Kong 1-1: 12,900

http://twitch.tv/LMDAVE
Member for 11 Years DK 1.1M Point Scorer Winner of a community event Blogger DK 1M Point Scorer DK Killscreener Former DK Level 1-1 World Record Holder Twitch Streamer

Offline JCHarrist

  • Spring Jumper
  • *
  • Posts: 643
    • Donkey Kong Forum
    • Awards
Re: Attract mode code breakdown
« Reply #14 on: July 19, 2013, 01:30:59 pm »
Now that I know what the numbers do, and since the barrels always do the same thing the first time through in MAME, it should be a simple matter to program Jumpman to make it to the top.   8)
Member for 11 Years DKF Founder Former CK World Record Holder - Arcade CK Killscreener DK Killscreener