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
0 user currently in Programming. | 3 guests
Acmlm's Board - I2 Archive - Programming - 65816 ASM issue | |
Add to favorites | "RSS" Feed | Next newer thread | Next older thread
User Post
Sukasa

Boomboom
Error 349857348734534: The system experienced an error.
Level: 57

Posts: 1691/1981
EXP: 1446921
For next: 39007

Since: 02-06-05
From: *Shrug*

Since last post: 6 days
Last activity: 1 day
Posted on 08-20-05 01:09 AM Link | Quote
I've been working on a particular block for use in an SMW hack, but the ASM for it seems to crash all the time, or do nothing. I wrote it in hex, working off of the "1 way left" block.

The original block bytecode:

AF 76 00 7E F0 07 A0 30 8C 93 A6 A0 01 69

That code works, here's the code with my additions:

08 AD AF 14 C9 00 F0 10 EA 28 AF 76 20 7E F0 07 A0 30 8C 93 16 A0 01 60 28 60

Basically, what it's supposed to do is check the on/off register, and then execute then code when the register is in the OFF state, or $00, making it an ON/OFF controlled 1 way left block. The PHP and PLP instructions are used since the original code seems to use the register state from previous code before the block's, so I used that to keep it. I've been going over this repeatedly, and with every change I make, the block either crashes the gameor does nothing.
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: 6397/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 08-20-05 02:47 AM Link | Quote
Er, it'd be a lot easier to help if you posted the actual ASM code, not just a bunch of hex.
Sukasa

Boomboom
Error 349857348734534: The system experienced an error.
Level: 57

Posts: 1694/1981
EXP: 1446921
For next: 39007

Since: 02-06-05
From: *Shrug*

Since last post: 6 days
Last activity: 1 day
Posted on 08-20-05 03:55 AM Link | Quote
I'm sure it would, but I'd written that in hex directly... Just a sec, I'll write it out by hand *pulls out 65816ref.hlp*


PHP
LDA $14AF
CMP #$00
BEQ end
NOP ;used earlier, not used now
PLP ;end my code segment, begin the original code
LDA $7E0076
BEQ end2 ;bne without a CMP statement (WTF?).
LDY #$30 ;...and LM said not to overwrite Y...
STY $1693 ;stare Y to somewhere
LDY #$01 ;and load Y again...
end2:
RTS ;this returns if the block had been executed
end:
PLP ;if the onoff was ON, this pulls the processor before returning
RTS
Euclid

Cheep-cheep
Level: 23

Posts: 188/193
EXP: 65528
For next: 2195

Since: 03-15-04
From: Australia

Since last post: 24 days
Last activity: 7 days
Posted on 08-20-05 04:26 PM Link | Quote
Originally posted by Sukasa
I'm sure it would, but I'd written that in hex directly... Just a sec, I'll write it out by hand *pulls out 65816ref.hlp*


PHP
LDA $14AF
CMP #$00
BEQ end
NOP ;used earlier, not used now
PLP ;end my code segment, begin the original code
LDA $7E0076
BEQ end2 ;bne without a CMP statement (WTF?).
LDY #$30 ;...and LM said not to overwrite Y...
STY $1693 ;stare Y to somewhere
LDY #$01 ;and load Y again...
end2:
RTS ;this returns if the block had been executed
end:
PLP ;if the onoff was ON, this pulls the processor before returning
RTS



bne checks if the Zero flag is on, in this case it will branch when $7E0076 is not 0 (so in this case, you don't even need to cmp #$00 before the beq.)

but other than that, it should work fine (assuming it's working with m=1), and i seriously don't think the PHP/PLP combo is needed though, try without them.
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: 6412/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 08-21-05 12:12 AM Link | Quote
PHY and PLY in place of PHP and PLP. You didn't change the processor status, so it needn't be saved, and you overwrote Y.
Sukasa

Boomboom
Error 349857348734534: The system experienced an error.
Level: 57

Posts: 1699/1981
EXP: 1446921
For next: 39007

Since: 02-06-05
From: *Shrug*

Since last post: 6 days
Last activity: 1 day
Posted on 08-21-05 09:39 AM Link | Quote
erm, the code overwriting Y isn't mine. It's whoever wrote the block's code. My code only adds the PHP/PLP instructions because the other code uses the processer status from before the block runs
Euclid

Cheep-cheep
Level: 23

Posts: 189/193
EXP: 65528
For next: 2195

Since: 03-15-04
From: Australia

Since last post: 24 days
Last activity: 7 days
Posted on 08-21-05 11:23 AM Link | Quote
Originally posted by Sukasa
erm, the code overwriting Y isn't mine. It's whoever wrote the block's code. My code only adds the PHP/PLP instructions because the other code uses the processer status from before the block runs


what kind of processor status, because your code isn't changing any (apart from the Zero and the Carry, but they're always changing)

and also is $14AF used for something else other than what you think it does? (i've played with a few snes roms before and they all use that area for dma uses, but i have no idea of SMW)
Sukasa

Boomboom
Error 349857348734534: The system experienced an error.
Level: 57

Posts: 1704/1981
EXP: 1446921
For next: 39007

Since: 02-06-05
From: *Shrug*

Since last post: 6 days
Last activity: 1 day
Posted on 08-23-05 12:41 AM Link | Quote
In my experience, 7E14AF is only used for the ON/OFF register. When the PHP/PLP is removed, the code simply does nothing. I really don't understand why not, though.
MathOnNapkins

Math n' Hacks
Level: 67

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

Since: 03-18-04
From: Base Tourian

Since last post: 1 hour
Last activity: 32 min.
Posted on 08-25-05 12:31 AM Link | Quote
Originally posted by Sukasa




PHP ; +1 byte on the stack

LDA $14AF
CMP #$00

BEQ END

NOP

PLP ; -1 byte on the stack

LDA $7E0076

BEQ END2 ; you don't need a CMP. If the above address contains zero when it's loaded to A, he Z flag will be set and the branch will occur. So yeah, CMP #$00 is a waste of time when you use BEQ.

LDY #$30
STY $1693

LDY #$01

END2:

RTS

END:

PLP ; -1 byte on the stack

RTS




I took a look at this and there doesn't appear to be any alignment issues with the code and the stack. I would guess the crashing would have more to do with what your code is doing. You should have this moved to the Romhacking forum. you'll get more people looking at it who know what they're doing. Or SMW forum possibly, since the variables you're using are probably more well known there, as well as custom block design.

[edit] however, a number of things could cause this to go awry. You need to know that this code is only being jumped into from its beginning, or the PLP's will misalign your stack. Also, have you made sure that the M and X flag are set when this is called? Otherwise those immediate mode instructions will totally kick your ass.


(edited by MathOnNapkins on 08-24-05 03:34 PM)
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: 6542/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 08-26-05 04:45 AM Link | Quote
Are you assembling this by hand? If so you should try using Super Sleuth to debug it. Search for the code in a hex editor (I assume this is a custom block, so you'll need to know where it is), convert the address to a SNES address, and set a breakpoint on it. Then you can step through the code and see what's wrong. It helped me figure out why my hand-assembled code didn't work - forgot that since I'm doing a 16-bit subtraction, the subtract instruction has a 16-bit parameter. Little things like that can really get you when you assemble by hand. (I usually don't, but I was running on an old Windows install with no assemblers. )
Sukasa

Boomboom
Error 349857348734534: The system experienced an error.
Level: 57

Posts: 1761/1981
EXP: 1446921
For next: 39007

Since: 02-06-05
From: *Shrug*

Since last post: 6 days
Last activity: 1 day
Posted on 08-26-05 10:34 AM Link | Quote
Yes, I did it by hand with notepad to insert the bytes I needed, and gold finger to edit them. My compiler doesn't understand the concept of imm8, only imm16. I don't have super sleuth, do you think geiger's SNES9x debugger would work? From the code, it seems to act like block 0x130, the concrete block, when 7E0076 is not 0, but I have no idea why it'd crash like that... I'll see what SNES9x says in the morning...
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: 6560/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 08-26-05 10:57 AM Link | Quote
Yeah, I guess that'd work too. I kinda forgot about it since it wouldn't work on my old computer all of a sudden.
MathOnNapkins

Math n' Hacks
Level: 67

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

Since: 03-18-04
From: Base Tourian

Since last post: 1 hour
Last activity: 32 min.
Posted on 08-26-05 04:05 PM Link | Quote
Yeah... well one thing you can do is after your PHP is use SEP #$30. The PLP will erase that modification anyways, if it was for some reason different before that.

You should definitely use Geiger's Debugger for this. Set a breakpoint the entry point, and breakpoints on both of the RTS's. If you get two consecutive breakpoints on the entry point, something is amiss. If you get two consecutive breakpoints on RTS's, something is very amiss. If you can't get breakpoints on any of those locations you are seriously doing something wrong.

Also, each time the entry point is reached, try step out to see if it returns to an expected location. If it returns to some garbage location, you'll know it's your PHPs and PLP's casuing the problem.

One more thing, if the code this is called from expects to have access to a zero result of LDA $14AF, or LDA $7E0076, you can see that the PLP will probably erase that result, unless the P register already had a Z flag set.


(edited by MathOnNapkins on 08-26-05 07:07 AM)
Sukasa

Boomboom
Error 349857348734534: The system experienced an error.
Level: 57

Posts: 1768/1981
EXP: 1446921
For next: 39007

Since: 02-06-05
From: *Shrug*

Since last post: 6 days
Last activity: 1 day
Posted on 08-26-05 10:03 PM Link | Quote
Well, the code calling the routine doesn't give a damn what goes on in the code, so long as Y isn't affected, or the block will remap. When it comes to execution breakpoints, how do you work them? The're the one thing in the debugger that doesn't make sense to me, because I can't figure out which format to use. I shouldn't worry about ME doing anything wrong though, becaue the code is inserted via an external progam made by jonwil. Getting two consectuve breakpoints on the entry would be a little difficult to detrmine, since the code would run every frame, which it's supposed to.
MathOnNapkins

Math n' Hacks
Level: 67

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

Since: 03-18-04
From: Base Tourian

Since last post: 1 hour
Last activity: 32 min.
Posted on 08-27-05 02:08 AM Link | Quote
Open the rom up in a hex editor and find where this code got mapped to. If there's a header subtract that off. Convert the resulting rom addresses into SNES addresses. That's what you use for the breakpoint. Short of sending me your rom I don't know what else I can tell you.


(edited by MathOnNapkins on 08-26-05 05:09 PM)
Sukasa

Boomboom
Error 349857348734534: The system experienced an error.
Level: 57

Posts: 1778/1981
EXP: 1446921
For next: 39007

Since: 02-06-05
From: *Shrug*

Since last post: 6 days
Last activity: 1 day
Posted on 08-28-05 06:54 AM Link | Quote
Thanks. I should I need to worry about subtracting the header though, since Lunar address takes that into consideration when converting PC and SNES addresses.
Add to favorites | "RSS" Feed | Next newer thread | Next older thread
Acmlm's Board - I2 Archive - Programming - 65816 ASM issue | |


ABII


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



Page rendered in 0.049 seconds.