Author [EN] [PL] [ES] [PT] [IT] [DE] [FR] [NL] [TR] [SR] [AR] [RU] [ID] Topic: Konami's NES demo plays were just simulated button mashing!  (Read 1469 times)

0 Members and 1 Guest are viewing this topic.

Offline TheouAegis

  • Amateur Auteur of GMvania
  • Master Hunter
  • *****
  • Posts: 1860
  • Gender: Male
  • Awards The Retro Gamer: Has a heated passion for the oldschool VG Titles. The Great Defender will always defend the object of his or her fandom. Hack Master makes creations out of CV parts. (S)he makes Dr. Frankenstein proud.
    • GMvania Developer's Blog
    • Awards
  • Likes:
Konami's NES demo plays were just simulated button mashing!
« on: December 12, 2012, 07:59:35 PM »
0
I didn't delve too deeply into this, although all I would have to do is change the debugger from reading byte $F1 to writing byte $F1, but while trying to see how Konami handled their secret codes, I opened Super C on the NES. Finding the addresses for the gamepad reads was easy -- I'm not sure if everyone just uses a code Nintendo provided or what, but just like movement codes, it's almost universal. I compared Super C's I/O code to S.C.A.T. (by Natsume) and the I/O code is different, so it seems Konami had and in-house code for the I/O. That makes it really easy to read since I familiarized myself with it in Castlevania 3. Reading the controller is pretty much universal code, but the variable storage is the signature technique. Konami uses four variables: current press, previous press, current hold, and previous hold. Previous press is the same as current press but can be used to check the last button pressed. Likewise, previous hold is the same as current hold but can be used to check the last button held down. Anyway, Super C used $F1, $F5, $F3 and $F7 respectively.

I tracked $F5, since obviously the code is based on key presses, not key holds. All it gave me were checks for Start ($F5 & #10) and Select ($F5 & #20). So I tried tracking $F1. While I was doing that, one of the attract mode demos kicked in. Now, I had told my emulator to only break when I press a key. I pressed right (#01), but when I looked at the debug window, it stopped with $F1=#02. I was like, "Did I press the wrong key?" So I cleared the key state and ran the game. Immediately the debugger froze the game. What the hell was going on? I looked at the debug window and it showed $F1=#0A. I scratched my head. Perhaps the variable had changed its usage and was not used for I/O during attract mode. When I ran the game again, I noticed out of the corner of my eye Lance went from walking left to walking diagonally up-left. In Konami code, left is #02 and up-left is #0A (#02|#08).

Like, oh my god! I was literally watching the game being played virtually by itself! ... Yeah, it all makes sense anyway. Why program an attract mode from scratch when you could just do virtual gameplay. Still, I thought it was neat.  :-X

And for those who want to know how Konami programmed the Konami code, it's so simple that even I picked up on it immediately at first glance.

00:A29C:A4 50     LDY $0050 = #$00  load byte 50 into Y
00:A29E:30 1C     BMI $A2BC  break if negative
00:A2A0:A5 F1     LDA $00F1 = #$01  load current IO press
00:A2A2:29 CF     AND #$CF  check if not Start or Select
00:A2A4:F0 16     BEQ $A2BC  break if it is
00:A2A6:D9 BD A2  CMP $A2BD,Y @ $A2BD = #$01  compare to expected IO press via array A2BD
00:A2A9:D0 0D     BNE $A2B8  jump to address $A2B8 if not
00:A2AB:C8        INY  increase Y
00:A2AC:84 50     STY $0050 = #$00  store Y in byte 50
00:A2AE:B9 BD A2  LDA $A2BD,Y @ $A2BD = #$01  check if at end of code
00:A2B1:D0 09     BNE $A2BC  break if code isn't complete
00:A2B3:A9 01     LDA #$01  set code as successful if routine not broken
00:A2B5:8D EC 07  STA $07EC = #$00  see previous line
00:A2B8:A9 FF     LDA #$FF  reset code if wrong button pressed
00:A2BA:85 50     STA $0050 = #$00  see previous line
00:A2BC:60        RTS  break the routine
//THE LINES BELOW ARE SUPER C'S SPECIAL CODE
00:A2BD:01        right
00:A2BE:02        left
00:A2BF:04        down
00:A2C0:08        up
00:A2C1:80        A
00:A2C2:40        B
00:A2C3:00        end of code
« Last Edit: December 12, 2012, 08:14:59 PM by TheouAegis »
Your mom has had more floppies put in her than a Commodore 64!


Follow my lack of progress on my game at my blog:
http://gmvania.blogspot.com

Tags: