Points of Required Attention™
Please chime in on a proposed restructuring of the ROM hacking sections.
Views: 88,570,707
Main | FAQ | Uploader | IRC chat | Radio | Memberlist | Active users | Latest posts | Calendar | Stats | Online users | Search 05-10-24 01:32 PM
Guest: Register | Login

Main - Posts by bbitmaster


bbitmaster
Posted on 08-29-09 03:12 AM, in Help with hacking/disassembling the NES Mega Man games Link | Quote | ID: 114231

Newcomer
Level: 5

Posts: 1/3
EXP: 380
Next: 149

Since: 08-29-09

Last post: 5343 days
Last view: 5357 days
Consider yourself in luck.. well almost, I don't have Mega Man 4.

I've pretty much been out of the hacking community for several years now. I only ever look at this forum once every few months if ever, but I just happened to come by and see this request.

Basically, back when I designed FCEUXD's code/data logger (in 2004 no less), my whole dream for it was to create a program that would produce a nice formatted re-assembleable disassembly with code and data separated. I actually ended up creating a semi-working disassembler that did this. It was way too buggy and messy to ever share, but I got it to output a good disassembly for one game. That game was megaman 3.

At around the same time, a fellow named _hyde_ was coding his own emulator with similar logging capabilities, and a similar disassembler. He produced assemblies for about a dozen games... of those megaman 1 and 2 were included.

So basically, I have disassemblies of Megaman 1, 2, and 3. They should all re-assemble with CA65. The megaman 1, 2 disassemblies were done by _Hyde_, and the megaman 3 one was done by me.

I would post them here, but I'm unsure of the rules on this forum. Since, Technically you can create a 100% complete original working rom with them. So instead, I'll opt to send it to anyone who asks either via e-mail or PM. ( my e-mail is bbitmaster@gmail.com ). I usually hang out in #rom-hacking on irc.esper.net if anyone wants to come and talk about any of this.

jagfillit, check your pm, I am about to send you links.

bbitmaster

bbitmaster
Posted on 09-08-09 12:32 AM, in Help with hacking/disassembling the NES Mega Man games (rev. 3 of 09-08-09 12:53 AM) Link | Quote | ID: 114682

Newcomer
Level: 5

Posts: 2/3
EXP: 380
Next: 149

Since: 08-29-09

Last post: 5343 days
Last view: 5357 days
well, if you're trying to simulate the physics, I might as well give a really formal discussion of how this is handled in megaman 3.

All of the megaman games use a form of fixed point arithmetic to store all of the numbers. Basically one byte tells the whole number, and another byte tells the fraction. This gives a 8.8 fixed point precision.

So, if you have the number $0180 the whole number part would be $01 while the fraction part would be $80 so this would be 1.5

The whole number part tells the pixel location. So basically, this allows for things to move at fractional velocities. lets say I am at position $0000 moving at a velocity of $0040 on each frame. My position would go like

Frame 0: $0000 Frame 1: $0040 Frame 2: $0080 Frame 3: $00C0 Frame 4: $0100 Frame 5: $0140 Frame 6: $0180 Frame 7: $01C0 Frame 8: $0200

so basically with this velocity you will move 1 pixel every 4 frames.

These numbers also have a sign bit according to 2's complement so $0180 = 1.5 but $ff80 = -0.5 $ff00 = -1, $fe00 = -2 etc...

Anyway, now that that is out of the way... what the game does, is it has an 8.8 fixed point variable associated with megaman's position, and an 8.8 fixed point variable associated with his velocity. When you jump his velocity initially gets set to $04E5 via the below code (megaman 3):

Note: the high byte of his velocity is in $0460 and the low byte is in $0440
$CEB3: A9 E5 LDA #$E5
$CEB5: 9D 40 04 STA $0440,X @ $0440 = #$E5
$CEB8: A9 04 LDA #$04
$CEBA: 9D 60 04 STA $0460,X @ $0460 = #$FF

After this, gravity is simulated by subtracting $0040 from the velocity on each frame. The code to subtract is given below:
$F7F2: BD 40 04 LDA $0440,X @ $0440 = #$A5
$F7F5: 38 SEC
$F7F6: E5 99 SBC $99 = #$40
$F7F8: 9D 40 04 STA $0440,X @ $0440 = #$A5
$F7FB: BD 60 04 LDA $0460,X @ $0460 = #$04
$F7FE: E9 00 SBC #$00
$F800: 9D 60 04 STA $0460,X @ $0460 = #$04

As you can see from this code, the value $0040 is actually stored in ram at location $99. This is actually like a constant that is used for all objects in the game. If you change it, I am pretty certain that many enemies and things in the game will fall with a lower gravity.

Anyway, so basically what happens is on each frame the velocity is added to the position, and $0040 is subtracted from the velocity. I could throw together an excel spreadsheet to show exactly how his position will change with all of this going on, and to show exactly how many pixels up he will go with a given initial velocity. But it basically makes the familar parabola that you see when he jumps and lands. (It's also a nice cheap way of simulating newtonian physics in discrete time)

If you want to change the jump height, the best way is to change the value of the initial velocity boost. The $04e5 value.
the $04 is in the rom at location $03cec9 the $e5 is in the rom at location $03cec4
changing these offsets in megaman 3 should let you change his jump height.

Anyway, just thought I'd post this because SO MANY remakes and homebrew games get jump physics all wrong...

EDIT: What the heck... here's a excel spreadsheet simulating one of these jumps. I used decimal values in excel. so $04e5 became 4 + 229/256 = 4.89453125. I got a maximum height of about 50 pixels.

http://bbitmaster.com/misc/megaman3jump.xls

-bbitmaster

Main - Posts by bbitmaster

Acmlmboard 2.1+4δ (2023-01-15)
© 2005-2023 Acmlm, blackhole89, Xkeeper et al.

Page rendered in 3.952 seconds. (327KB of memory used)
MySQL - queries: 36, rows: 50/50, time: 3.949 seconds.