Register | Login
Views: 19364387
Main | Memberlist | Active users | ACS | Commons | Calendar | Online users
Ranks | FAQ | Color Chart | Photo album | IRC Chat
11-02-05 12:59 PM
1 user currently in Rom Hacking: hukka | 2 guests
Acmlm's Board - I2 Archive - Rom Hacking - 6502 question | |
Add to favorites | "RSS" Feed | Next newer thread | Next older thread
User Post
Sokarhacd

Ball and Chain Trooper
Resistance is Futile
You Will Be Assimilated
Hab SoSlI' Quch
Level: 61

Posts: 543/1757
EXP: 1799888
For next: 76708

Since: 03-15-04

Since last post: 6 days
Last activity: 4 hours
Posted on 11-05-04 08:35 PM Link | Quote
I have a question about 6502 asm, im looking at the enemy health routine in Megaman 4, and I was wondering, if im looking at some specific routine, will it alwasy begin right after an RTS command, and end at an RTS? im asking because im not sure where the routine begins and ends, and also, i read some of the fceud tuts on dragoneyestudios and they all say to copy stuff beginning after an RTS above, to on below...im thinking im right but I just wanted to make sure.
Dish

Spiny
Level: 38

Posts: 166/596
EXP: 355646
For next: 14801

Since: 03-15-04
From: Disch

Since last post: 18 days
Last activity: 18 days
Posted on 11-05-04 09:23 PM Link | Quote
Usually, but not always. They may end with a JMP command, and a routine may contain several RTS commands (some of which may be skipped by branching). Typically though... for small routinse... yes, it'll end with an RTS and usually start right after an RTS. This is no real 'rule' though... it's just a common trend.
Sokarhacd

Ball and Chain Trooper
Resistance is Futile
You Will Be Assimilated
Hab SoSlI' Quch
Level: 61

Posts: 544/1757
EXP: 1799888
For next: 76708

Since: 03-15-04

Since last post: 6 days
Last activity: 4 hours
Posted on 11-05-04 09:27 PM Link | Quote
thanks, thats pretty much what I thought and it looks like this routine doesnt have any jumps, and its not that big really, but if I got it right it goes from $832A-$83BD I think. and theres a few bne's in there, but they dont go past the RTS, so I think thats the whole thing..


(edited by Dcahrakos on 11-05-04 12:31 PM)
MathOnNapkins

Math n' Hacks
Level: 67

Posts: 830/2189
EXP: 2495887
For next: 96985

Since: 03-18-04
From: Base Tourian

Since last post: 1 hour
Last activity: 32 min.
Posted on 11-05-04 09:42 PM Link | Quote
If you get a JSR or JMP to a routine, and you look behind the jump point and there is no RTS, it may be the case that the code you jumped too is part of a larger routine. Always try to be aware of that. And yeah the ends of routines can get complicated. I don't know if you'll encounter it but there are at least 4 ways to get out of a routine. One is a jump. The other is pulling numbers off the stack, putting some new ones on from a jump table, and then hitting RTS which will give a location other than the original return location. It's a crafty kind of jump table. There are also JSRs that never return, one of the most confusing things I encountered. What they do is jump to another routine that jumps somewhere else using the return address on the stack.
Sokarhacd

Ball and Chain Trooper
Resistance is Futile
You Will Be Assimilated
Hab SoSlI' Quch
Level: 61

Posts: 545/1757
EXP: 1799888
For next: 76708

Since: 03-15-04

Since last post: 6 days
Last activity: 4 hours
Posted on 11-05-04 10:12 PM Link | Quote
yeah, I expected them to get pretty complicated...and actually, looking at this one again, it actually is pretty big....I noticed it does this:
it has an RTS, but there is a beq up a little bit, that goes past the rts, and it goes into another part that has 2 JSR's....so its actually more complicated then I first thought...
here is what I copied from fceud.

$832A:BD 50 04 LDA $0450,X @ $0466 = #$02
$832D:38 SEC
$832E:E5 12 SBC $12 = #$01
$8330:9D 50 04 STA $0450,X @ $0466 = #$02
$8333:B0 05 BCS $833A
$8335:A9 00 LDA #$00
$8337:9D 50 04 STA $0450,X @ $0466 = #$02
$833A:A5 22 LDA $22 = #$07
$833C:C9 0B CMP #$0B
$833E: D0 10 BNE $8350
$8340:A5 F9 LDA $F9 = #$08
$8342:C9 13 CMP #$13
$8344: D0 0A BNE $8350
$8346:A9 02 LDA #$02
$8348: DD 50 04 CMP $0450,X @ $0466 = #$02
$834B:90 03 BCC $8350
$834D:9D 50 04 STA $0450,X @ $0466 = #$02
$8350:BD B8 05 LDA $05B8,X @ $05CE = #$00
$8353:29 80 AND #$80
$8355:09 08 ORA #$08
$8357:9D B8 05 STA $05B8,X @ $05CE = #$00
$835A:EC 46 01 CPX $0146 = #$00
$835D: D0 23 BNE $8382
$835F:AD 32 01 LDA $0132 = #$00
$8362:10 1E BPL $8382
$8364:BD 50 04 LDA $0450,X @ $0466 = #$02
$8367:85 BF STA $BF = #$00
$8369:BD B8 05 LDA $05B8,X @ $05CE = #$00
$836C:29 80 AND #$80
$836E:09 30 ORA #$30
$8370:9D B8 05 STA $05B8,X @ $05CE = #$00
$8373:BD 00 03 LDA $0300,X @ $0316 = #$8E
$8376:C9 9E CMP #$9E
$8378: D0 08 BNE $8382
$837A:BD 50 04 LDA $0450,X @ $0466 = #$02
$837D:18 CLC
$837E:69 0E ADC #$0E
$8380:85 BF STA $BF = #$00
$8382:BD 50 04 LDA $0450,X @ $0466 = #$02
$8385: D0 4B BNE $83D2
$8387:9D B8 05 STA $05B8,X @ $05CE = #$00
$838A:BC 00 03 LDY $0300,X @ $0316 = #$8E
$838D:20 00 DC JSR $DC00 //LOL missed this one also...gotta be more careful.
$8390:BD 28 05 LDA $0528,X @ $053E = #$90
$8393:29 FD AND #$FD
$8395:9D 28 05 STA $0528,X @ $053E = #$90
$8398:B9 E3 84 LDA $84E3,Y @ $84E4 = #$00
$839B:F0 21 BEQ $83BE
$839D:9D 00 03 STA $0300,X @ $0316 = #$8E
$83A0:A9 00 LDA #$00
$83A2:9D 08 04 STA $0408,X @ $041E = #$C0
$83A5:9D 68 04 STA $0468,X @ $047E = #$00
$83A8:9D 80 04 STA $0480,X @ $0496 = #$5D
$83AB:9D 98 04 STA $0498,X @ $04AE = #$00
$83AE:9D B0 04 STA $04B0,X @ $04C6 = #$00
$83B1:9D C8 04 STA $04C8,X @ $04DE = #$00
$83B4:9D E0 04 STA $04E0,X @ $04F6 = #$00
$83B7:9D F8 04 STA $04F8,X @ $050E = #$00
$83BA:9D 10 05 STA $0510,X @ $0526 = #$00
$83BD:60 RTS
$83BE:A9 19 LDA #$19
$83C0:20 46 F4 JSR $F446 // here
$83C3:A9 00 LDA #$00
$83C5:9D 08 04 STA $0408,X @ $041E = #$CD
$83C8:A9 9D LDA #$9D
$83CA:9D 00 03 STA $0300,X @ $0316 = #$3E
$83CD:A9 27 LDA #$27
$83CF:20 BE F6 JSR $F6BE //and here
$83D2:60 RTS

lol I missed 3 JSR's....I definently gotta pay more attention...so actually that routine is pretty damn big.




(edited by Dcahrakos on 11-05-04 01:14 PM)
(edited by Dcahrakos on 11-05-04 01:14 PM)
Dish

Spiny
Level: 38

Posts: 167/596
EXP: 355646
For next: 14801

Since: 03-15-04
From: Disch

Since last post: 18 days
Last activity: 18 days
Posted on 11-05-04 10:27 PM Link | Quote
Following up JSRs isn't really all that important.... at least not from my experience. The routine being jumped to will almost always return in one form or another (either by doing an RTS, or JMPing to another routine that RTS, or something similar). The only way a JSR routine wouldn't return is if the return address is pulled from the stack... something like:

JSR someroutine

someroutine:
PLA
PLA ;ditch return address
RTS

though code that does that isn't exactly common. So I wouldn't beat yourself up for not noticing JSRs. Chances are they won't affect the routine you're looking at.
Sokarhacd

Ball and Chain Trooper
Resistance is Futile
You Will Be Assimilated
Hab SoSlI' Quch
Level: 61

Posts: 547/1757
EXP: 1799888
For next: 76708

Since: 03-15-04

Since last post: 6 days
Last activity: 4 hours
Posted on 11-05-04 10:32 PM Link | Quote
well, I guess that isnt so bad then...well, I guess im off to see what i can do with this...thanks again.
MathOnNapkins

Math n' Hacks
Level: 67

Posts: 833/2189
EXP: 2495887
For next: 96985

Since: 03-18-04
From: Base Tourian

Since last post: 1 hour
Last activity: 32 min.
Posted on 11-06-04 12:35 AM Link | Quote
If the part after the JSR doesn't look like code that is a hint that you should follow that JSR, as the return address probably got pulled from the stack, otherwise, there's usually no need to worry.
HyperLamer
<||bass> and this was the soloution i thought of that was guarinteed to piss off the greatest amount of people

Sesshomaru
Tamaranian

Level: 118

Posts: 1988/8210
EXP: 18171887
For next: 211027

Since: 03-15-04
From: Canada, w00t!
LOL FAD

Since last post: 2 hours
Last activity: 2 hours
Posted on 11-06-04 08:29 AM Link | Quote
One thing you might find is that the routine is after data (uncommon in newer games), so above it is just garbage. Also, you might be partway into a routine. You described a JSR nearby that jumps just past the RTS, that probably means you're in part of a routine which is executed conditionally from the routine itself. (If you can understand what I mean... )
Add to favorites | "RSS" Feed | Next newer thread | Next older thread
Acmlm's Board - I2 Archive - Rom Hacking - 6502 question | |


ABII


AcmlmBoard vl.ol (11-01-05)
© 2000-2005 Acmlm, Emuz, et al



Page rendered in 0.017 seconds.