Sonic and Sega Retro Message Board: Debugging misaligned read/write - Sonic and Sega Retro Message Board

Jump to content

Hey there, Guest!  (Log In · Register) Help
  • 4 Pages +
  • ◄ First
  • 2
  • 3
  • 4
    Locked
    Locked Forum

Debugging misaligned read/write Or how to get your hack to work on Regen/Kega/real hardware

#46 User is offline redhotsonic 

Posted 23 February 2012 - 06:38 AM

  • Also known as RHS
  • Posts: 1128
  • Joined: 31-January 05
  • Gender:Male
  • Location:United Kingdom
  • Project:Sonic 2 Recreation
  • Wiki edits:24
I'm not sure if half of them are words or not, so I will put an "even" in front anyway. There's no harm in doing it and I won't have to worry it ever being unaligned.

#47 User is offline Chilly Willy 

Posted 23 February 2012 - 03:48 PM

  • Posts: 746
  • Joined: 10-April 09
  • Gender:Male
  • Project:Doom 32X
You have to be very aware of how the code uses bytes... for example, here's a case where two byte variables MUST be aligned...

    move.w var1,d0 ; get both var1 and var2 at the same time

...
var1:
    dc.b 10
var2:
    dc.b 10


If var1 isn't evenly aligned, the above with blow up.

    move.w var1,d0 ; get both var1 and var2 at the same time

...
    even
var1:
    dc.b 10
var2:
    dc.b 10


But now let's say I get crazy with the evens and do this

    move.w var1,d0 ; get both var1 and var2 at the same time

...
    even
var1:
    dc.b 10
    even
var2:
    dc.b 10


Oopsi! I just made the code fail in a hard to trace manner because the code is trying to load both vars at once, but that second even pushes var2 off a byte so that it won't load with that move.w. So you just can't stick evens EVERYWHERE or you may break the code. Such is the joy and fun of assembly! :v:

#48 User is offline redhotsonic 

Posted 23 February 2012 - 07:02 PM

  • Also known as RHS
  • Posts: 1128
  • Joined: 31-January 05
  • Gender:Male
  • Location:United Kingdom
  • Project:Sonic 2 Recreation
  • Wiki edits:24

View PostChilly Willy, on 23 February 2012 - 03:48 PM, said:

You have to be very aware of how the code uses bytes... for example, here's a case where two byte variables MUST be aligned...

    move.w var1,d0 ; get both var1 and var2 at the same time

...
var1:
    dc.b 10
var2:
    dc.b 10


If var1 isn't evenly aligned, the above with blow up.

    move.w var1,d0 ; get both var1 and var2 at the same time

...
    even
var1:
    dc.b 10
var2:
    dc.b 10


But now let's say I get crazy with the evens and do this

    move.w var1,d0 ; get both var1 and var2 at the same time

...
    even
var1:
    dc.b 10
    even
var2:
    dc.b 10


Oopsi! I just made the code fail in a hard to trace manner because the code is trying to load both vars at once, but that second even pushes var2 off a byte so that it won't load with that move.w. So you just can't stick evens EVERYWHERE or you may break the code. Such is the joy and fun of assembly! :v:


So I found out earlier. The HUD screwed up and etc when I put an even before it. So if anything ever goes wrong, I will mess around with evens there.

#49 User is offline redhotsonic 

Posted 25 March 2013 - 04:41 PM

  • Also known as RHS
  • Posts: 1128
  • Joined: 31-January 05
  • Gender:Male
  • Location:United Kingdom
  • Project:Sonic 2 Recreation
  • Wiki edits:24
Okay, HUGE bump here, but it looks like flamewing's question never got answered. Does his error report work on real hardware? Yes.


A while ago, I asked ChillyWilly to try my Sonic 2 Recreation out on real hardware. Right at the beginning of the ROM, an error occurred, reported by flamewing's report (which the error never happens on emulators). I've fixed it now and my hack works 100% on real hardware. But in conclusion, yes, flamewing's report works on real hardware. Thanks to ChillyWilly for testing.

  • 4 Pages +
  • ◄ First
  • 2
  • 3
  • 4
    Locked
    Locked Forum

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users