Author [EN] [PL] [ES] [PT] [IT] [DE] [FR] [NL] [TR] [SR] [AR] [RU] [ID] Topic: Need help translating this to C or GML  (Read 769 times)

0 Members and 1 Guest are viewing this topic.

Offline TheouAegis

  • Amateur Auteur of GMvania
  • Master Hunter
  • *****
  • Posts: 1825
  • 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:
Need help translating this to C or GML
« on: February 26, 2012, 12:29:46 AM »
The NESdev forum doesn't look all that "happening" and I hate making forum accounts just to post one request, it feels noobish.

I've been tracing code one line at a time and trying to eyeball what each thing does. This snippet of code is, I'm pretty sure, part of the passcode decryption for CV3 (I'm having issues with the encryption, so I'm working on the decryption some more instead). The problem I'm having is how to handle all the branch operations and Return From Subroutine operations. I know in many cases it's a loop of some sort, but where loops start and end is confusing me.

01:B7F0:AD 8F 07  LDA $078F      //Retrieve the value of some variable
01:B7F3:0A        ASL      //Multiply it by 8 (each ASL is v<<1, so v<<3 which is v*2^3)
01:B7F4:0A        ASL   
01:B7F5:0A        ASL   
01:B7F6:6D 8F 07  ADC $078F      //Add the original value to the multiplied value
01:B7F9:85 00     STA $0000      //Save the maths to a variable
01:B7FB:A9 0F     LDA #$0F      //Sets A to 16 (the number of total cells)
01:B7FD:85 01     STA $0001      //Sets $0001 to 16, basically "var=16"
01:B7FF:A4 01     LDY $0001      //Y is set so you can do maths with it
01:B801:B9 90 07  LDA $0790,Y      //Retrieve the value of the grid, starting at 16
01:B804:29 03     AND #$03      //Find the icon value (blank, whip, cross, heart)
01:B806:F0 1F     BEQ $B827      //I think this would all be in a FOR loop and this line is "if !A then continue"
01:B808:A5 00     LDA $0000      //Whatever the hell I stored earlier is recalled
01:B80A:85 02     STA $0002      //Make another variable
01:B80C:A9 09     LDA #$09      //Set A to 9 (I think this is the max passWORD length)
01:B80E:85 03     STA $0003      //Set another variable to 9
01:B810:A4 02     LDY $0002      //Set Y to one of the variables
01:B812:B9 B2 B6  LDA $B6B2,Y      //Set A to some hard-coded variable (this shit is a pain and Konami does it a lot)
01:B815:20 E2 B7  JSR $B7E2      //No idea wtf this subroutine does but it does it a lot
01:B818:C4 01     CPY $0001      //Check if Y=1
01:B81A:F0 0B     BEQ $B827      //If yes, maybe "if Y==1 then continue"
01:B81C:E6 02     INC $0002      //Increase one of the variables by 1
01:B81E:C6 03     DEC $0003      //Decrease one of the variables by 1
01:B820:D0 EE     BNE $B810      //Check if the Z flag isn't set
01:B822:A9 02     LDA #$02      //Set A to 2
01:B824:4C D8 B7  JMP $B7D8      //Sets yet another variable, i haven't figured out what for yet
01:B827:C6 01     DEC $0001      //Decrease one of the variables by 1, this is also where the code jumps to
01:B829:10 D4     BPL $B7FF      //Check if that variable is greater than 1?
01:B82B:60        RTS      //Continue the torture

For starters, $0790 thru $079F are the passcode values the player has entered (see my latest blog post for clarification on the passcode system), so LDA $0790,Y will load into the accumulator the specified passcode cell (if Y is 5, then it will load $0795, which is cell $18 as described in my latest blog entry).

My biggest issue is how to deal with line B820. It says "if Z is 0, goto B810". The problem is, in Game Maker you don't work with flags. Z is set to 1 when a value is 0. Well, there are lots of values here. I can check A (the accumulator), $0002, or $0003; each of these was modified at some point in the code. (For the record, I can't take this up at GMC either cuz they got mad at me for asking about NES hacking.) Does Z get reset after each operation, meaning I would only need to check $0003? The last line would seem to suggest that, since it says to decrease $0001 and check if it's still greater than 0.

My branching problem comes from how branches and subroutines are handled. Here are the external subroutines called in the code above:

01:B7D8:0D 8B 07  ORA $078B   
01:B7DB:8D 8B 07  STA $078B    
01:B7DE:60        RTS

01:B7E2:48        PHA
01:B7E3:29 30     AND #$30
01:B7E5:4A        LSR
01:B7E6:4A        LSR
01:B7E7:85 07     STA $0007 = #$30
01:B7E9:68        PLA
01:B7EA:29 03     AND #$03
01:B7EC:05 07     ORA $0007 = #$30
01:B7EE:A8        TAY
01:B7EF:60        RTS

Those RTSes make shit jump all over the place and I don't know what to do with them.

Then there's the stupid crap like some math being done to the accumulator then they just replace the accumulator afterward (I'm guessing it has to do with setting the status flags).

I seriously hope someone here learned any sort of Assembly programming in school.
« Last Edit: February 26, 2012, 12:48:58 AM 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: