Sonic 1 Disassembly

Discussion in 'Engineering & Reverse Engineering' started by Hivebrain, Dec 26, 2008.

  1. Hivebrain

    Hivebrain

    Administrator
    2,927
    66
    28
    53.4N, 1.5W
    HiveView
    Discuss changes here, particularly controversial changes. The disassembly builds a ROM which is almost identical to the original ROM. There is one instruction that had to be changed. It may be possible to correct this now that we're using asm68k.

    Here's a brief to-do list:
    - Split some more stuff.
    - Use more local labels in objects that don't have them.
    - Do text search for "loc_" and "locret_" and rename them better.
    - Use ids instead of object numbers, level numbers and game modes.
    - Implement ids in all files (already done for sonic.asm).
    - Macros for angle/trig object stuff.
    - Merge obRange and obRanges macros.
    - Add JP1 files with 0/1 variable to switch between them.
     
  2. Mind telling what this instruction was?
     
  3. drx

    drx

    mfw Researcher
    2,244
    320
    63
    :rolleyes:
    I'm guessing exg d0,d1
     
  4. Hivebrain

    Hivebrain

    Administrator
    2,927
    66
    28
    53.4N, 1.5W
    HiveView
    Line 133 in "_incObj\85 Boss - Final.asm"

    <!--g1--><div class='geshitop'>Syntax Highlighted Code: ASM</div><div class='codemain'><!--eg1--><pre class="asm">[color= #00bfff;]exg[/color] <span style="font-weight:bold;">d0</span>,<span style="font-weight:bold;">d1</span></pre><!--gc2--><!--ZXhnCWQwLGQx--><!--egc2--><!--g2--></div><!--eg2-->

    Swapping d0 and d1 has no effect on the output ROM.
     
  5. Sik

    Sik

    Sik is pronounced as "seek", not as "sick". Tech Member
    6,719
    0
    0
    being an asshole =P
    ...

    What the hell was rejecting that instruction? o_o;
     
  6. nineko

    nineko

    I am the Holy Cat Tech Member
    5,941
    125
    43
    italy
    Maybe I'm using an outdated disassembly so I don't know if this has been fixed, but right after Title_LoadText there is this line:
    Code (Text):
    1. move.w  #0,($FFFFFFF0).w; disable debug mode
    The comment is misleading, it should read "disable DEMO mode".
    I'll post more if I find them.
     
  7. drx

    drx

    mfw Researcher
    2,244
    320
    63
    :rolleyes:
    Assemblers tend to assemble exg d1,d0 into exg d0,d1. While those instructions do (almost) exactly the same, they have different opcodes.
     
  8. Hivebrain

    Hivebrain

    Administrator
    2,927
    66
    28
    53.4N, 1.5W
    HiveView
    Object ids are defined in "_inc\Object Pointers.asm". I've used them in sonic.asm, but they still need adding to all the smaller asm files where relevant.

    Could exg be redefined with a macro?
     
  9. FraGag

    FraGag

    Tech Member
    Thanks, I've been waiting for this for a while! I'll have to get used to your naming convention before I get started though. Speaking of which, we should decide whether we take your names or Xenowhirl's for Sonic 2, to make porting code between both games easier.
     
  10. Sik

    Sik

    Sik is pronounced as "seek", not as "sick". Tech Member
    6,719
    0
    0
    being an asshole =P
    So basically assembler developers love to make their life harder? Because implementing such a behaviour requires extra code, in fact >_>
     
  11. Overlord

    Overlord

    Now playable in Smash Bros Ultimate Moderator
    18,334
    420
    63
    Berkshire, England
    Learning Cymraeg
    For anyone still coding in assembly today voluntarily, that's probably true, to be honest =P

    Note I said voluntarily, before the legions of hack coders jump on me.
     
  12. Sik

    Sik

    Sik is pronounced as "seek", not as "sick". Tech Member
    6,719
    0
    0
    being an asshole =P
    And OS developers.

    Besides when proramming for very old (and hence slow) hardware trying to achieve for full speed, assembly is the only option. Now, if you try to do that with new hardware...
     
  13. Overlord

    Overlord

    Now playable in Smash Bros Ultimate Moderator
    18,334
    420
    63
    Berkshire, England
    Learning Cymraeg
    I thought most of modern-day OSes were written in C now?

    You're quite correct on the first sentence. The second - it's a bit ehhh. It's like Gentoo users who compile every app for their system - sure, it'll go faster, but is an app starting in 0.98 seconds really noticable over 1.0?
     
  14. Delta

    Delta

    Oldbie
    Ideally most of it would be written in C. However, at the very lowest levels of the OS, you'd eventually have to get into assembly because you simply can't directly interact with hardware in the same way you can with assembly. That said, you can create a higher-level C interface over some nitty-gritty asm and have the vast majority of the OS written in C/C++.

    Not that I'm an expert on OS design or anything, but that's how I understand it. :P

    Semi on-topicness: One of these days I should get into Genesis programming and 68k asm, and create/hack something awesome. Just that I'm already doing a ton of other stuff.

    I do love all the work that's gone into Sonic disassemblies; I can almost understand it, even without extensive knowledge of assembly.
     
  15. Sik

    Sik

    Sik is pronounced as "seek", not as "sick". Tech Member
    6,719
    0
    0
    being an asshole =P
    This. No matter what, some things are very processor specific, and those things have to be done in assembler because they aren't featured in any high-level language. They're often wrapped into functions, indeed, but still you need to use assembly, unless you're so crazy you create your own high-level language exclusively for the operating system. But then you're using assembly for the compiler, unless you're even crazier and compile directly into machine language X_X

    More to my point. There's little point programming in assembly for new hardware both because most likely it won't be noticeable, and actually there are so many different types of technology that what speeds up in one processor may slow down horribly in another one - even if newer. Sometimes it may even hurt (using RDTSC for timing fails miserably in any kind of multiprocessor or multicore enviroment). So no.
     
  16. Spanner

    Spanner

    The Tool Member
    3,313
    118
    43
    United Kingdom
    Sonic Hacking Contest
    *bump*
    Okay, I was thinking, wouldn't it be better if variables were used for the sounds? It would save issues for example, let's say you ported the Sonic 3 Sound Driver to S1. It may be unpopular due to how it works but sounds are practically everywhere and using variables in place of the audio $** request would probably be better. For example:
    <!--g1--><div class='geshitop'>Syntax Highlighted Code: ASM</div><div class='codemain'><!--eg1--><pre class="asm">audio [color= #ff0000;]$[/color][color= #ff0000;]8C[/color]</pre><!--gc2--><!--YXVkaW8gJiMwMzY7OEM=--><!--egc2--><!--g2--></div><!--eg2-->
    Would become:
    <!--g1--><div class='geshitop'>Syntax Highlighted Code: ASM</div><div class='codemain'><!--eg1--><pre class="asm">audio Music_Boss</pre><!--gc2--><!--YXVkaW8gTXVzaWNfQm9zcw==--><!--egc2--><!--g2--></div><!--eg2-->
    And if you wanted to change the music:
    <!--g1--><div class='geshitop'>Syntax Highlighted Code: ASM</div><div class='codemain'><!--eg1--><pre class="asm">Music_Boss = [color= #ff0000;]$[/color][color= #ff0000;]8C[/color] [color= #adadad; font-style: italic;]; change the $** to another music ID[/color]</pre><!--gc2--><!--TXVzaWNfQm9zcyA9ICYjMDM2OzhDIDsgY2hhbmdlIHRoZSAmIzAzNjsqKiB0byBhbm90aGVyIG11c2lj
    IElE--><!--egc2--><!--g2--></div><!--eg2-->
    Just saying.
     
  17. FraGag

    FraGag

    Tech Member
    I've implemented this in the Sonic 2 disassembly (in a more clever way, even, similar to how object IDs are currently defined) and it would indeed be a nice addition for this disassembly.
     
  18. Spanner

    Spanner

    The Tool Member
    3,313
    118
    43
    United Kingdom
    Sonic Hacking Contest
    It was in the Sonic 2 Split Disassembly, which was the inspiration for my post. Still, variables and equates are useful as long as you don't get over the top with them.
     
  19. Hivebrain

    Hivebrain

    Administrator
    2,927
    66
    28
    53.4N, 1.5W
    HiveView
    I will be doing this soon. IDs would be defined more like this though:

    <!--g1--><div class='geshitop'>Syntax Highlighted Code: ASM</div><div class='codemain'><!--eg1--><pre class="asm">bgm_Boss:[color= #00CC66;] equ[/color] <span style="">(</span>ptr_Music_Boss-Music_Index<span style="">)</span>/[color= #ff0000;]4[/color]</pre><!--gc2--><!--YmdtX0Jvc3M6IGVxdSAocHRyX011c2ljX0Jvc3MtTXVzaWNfSW5kZXgpLzQ=--><!--egc2--><!--g2--></div><!--eg2-->

    That's how I've been doing other IDs. Palette scripts and PLCs could probably do with being IDed as well.
     
  20. Sik

    Sik

    Sik is pronounced as "seek", not as "sick". Tech Member
    6,719
    0
    0
    being an asshole =P
    The Sonic 3D disasm also has this kind of IDs too - especially since the SFX ones aren't so obvious as you have to add $32 from what appears in the Sound Test =/