Romhacking.net

Romhacking => Programming => Topic started by: Timaeus on July 04, 2022, 11:44:03 AM

Title: An issue regarding a custom 6502 assembly code
Post by: Timaeus on July 04, 2022, 11:44:03 AM
So, recently I am finally getting myself to create customized coding patterns for enemy behaviors (jumping, shooting, waiting, walking, etc.). I created some samples myself by studying, and one of them makes bosses wait still for an amount of time, determinated by the value I add. I am recreating my first released MM1 hack, basically overhaul it entirely with much more custom and better stuff. The following strategy of "waiting still" worked nicely for both Elecman's and Gutsman's replacements, but not for Bombman's. When the game reads the code, his bomb sprite on his hand vanishes and the sprites of a couple of weapons simply glitch out, swapping between alot of other sprites of the game. I assume it might be because Bombman always read two sprites, but I have a sample for jumping, and it worked perfectly with no sprite missing. The code is this one:

A9 2B 8D 01 04 = Reads the sprite 2b and call the sprite function
A9 00 8D 41 04 = Reads value 00 and call the hit state function
BD 40 06 = loads Objectfiredelay function with value 0
F0 09 = branch 9 bytes forward if equal
DE 40 06 = decrease 1 from the value for Objectfiredelay that will be set ahead
D0 09 = branch 9 bytes if not equal
A9 05 85 3E = Jumps to the boss strategy code number 5
A9 5C 9D 40 06 = add value 5C to Objectfiredelay (which equals around 2 seconds of delay for the boss to stay idle)
60 = rts

Can someone help me out on finding why this does not work for him? I actually do not need to load both sprites (Bombman and his bomb), so maybe disable the function that takes care of it should be better? I appreciate it.
Title: Re: An issue regarding a custom 6502 assembly code
Post by: Cyneprepou4uk on July 05, 2022, 09:14:11 PM
Despite that I'm able to read opcodes, it's a bad practice to post your code like this.

Anyway, this bit of code is not nearly enough to determine what's wrong with later events. The code itself looks ok I guess.
Title: Re: An issue regarding a custom 6502 assembly code
Post by: Timaeus on July 05, 2022, 10:06:26 PM
i do not get why the error happens either. It works fine for other bosses. Hum....what kind of way I should post them?
Title: Re: An issue regarding a custom 6502 assembly code
Post by: Bavi_H on July 06, 2022, 12:56:17 AM
I think most people would prefer to read the code as 6502 instruction set mnemonics (assembly language) instead of hex bytes (machine language). At the end of this post, I translated the hex bytes into 6502 assembly language. I added my comments interpreting the instructions in a JavaScript-like or C-like pseudocode. Then I added your comments with color coding explained above the code.

Questions
1. Is this code from the original game or is this something you added or modified?
2. Are you using some document that defines things like "sprite function", "hit state function", "Objectfiredelay", and "boss strategy code number"?
3. Can you provide the checksum or hash of the original game to confirm what version of the game you are using?
4. Can you provide the address where this code is located? (An NES file offset or a CPU address)

Color code: In your comments...
____________________________________________________________________________________________________________________________________
      A9 2B     LDA #$2B     ; \                          ; \ "Reads the sprite 2b and
      8D 01 04  STA $0401    ; / Mem[$401] = $2B          ; /    call the sprite function"
      A9 00     LDA #$00     ; \                          ; \ "Reads value 00 and call
      8D 41 04  STA $0441    ; / Mem[$441] = 0            ; /    the hit state function"
      BD 40 06  LDA $0640,X  ;   A = Mem[$640 + X]        ;   "loads Objectfiredelay function with value 0"
      F0 09     BEQ next     ;   If zero, goto "next"     ;   "branch 9 bytes forward if equal"
      DE 40 06  DEC $0640,X  ;   decrement Mem[$640 + X]  ;   "decrease 1 from the value for Objectfiredelay that will be set ahead"
      D0 09     BNE end      ;   If not zero, goto "end"  ;   "branch 9 bytes if not equal"
      A9 05     LDA #$05     ; \                          ; \ "Jumps to the boss
      85 3E     STA $3E      ; / Mem[$3E] = 5             ; /    strategy code number 5"
next: A9 5C     LDA #$5C     ; \                          ; \ "add value 5C to Objectfiredelay (which equals
      9D 40 06  STA $0640,X  ; / Mem[$640 + X] = $5C      ; /     around 2 seconds of delay for the boss to stay idle)"
end:  60        RTS          ;   Return                   ;   "rts"
____________________________________________________________________________________________________________________________________
Title: Re: An issue regarding a custom 6502 assembly code
Post by: Timaeus on July 06, 2022, 11:07:33 AM
1. It is a code I made myself. I am still learning, though.
2. Yes, bisqwit's Megaman 1 written disassembly.
3. I am using the USA version (the one without Megaman's big sprite in the title screen and just his name with black background).
4. I modified the location, since it is a custom code. It is only in the rom I have, sadly.

So there is better ways to build this up? Also, if you need, I can explain what each command you set in blue