don't click here

Problem with SonLVL (Sonic 2 GitHub disassembly)

Discussion in 'Engineering & Reverse Engineering' started by Trinitronity, Jan 25, 2016.

  1. So I was starting to make a small ROM hack of Sonic 2, and my first step was to change pallettes and names of Zones before going into the more meaty stuff.
    Now the problem is: Whenever I press "Build & Run" in order to test my hack in its current form, I get this error on the s2.log file:
    Code (Text):
    1. > > >s2.asm(26622): error: symbol undefined
    2. > > > Off_TitleCardLetters
    3. > > >   move.b  Off_TitleCardLetters(pc,d0.w),d0
    4. > > >s2.asm(26622): error: addressing mode not allowed here
    5. > > >   move.b  Off_TitleCardLetters(pc,d0.w),d0
    So I went to the offending place, and found this:
    Code (Text):
    1. LoadTitleCard:
    2.     bsr.s   LoadTitleCard0
    3.     moveq   #0,d0
    4.     move.b  (Current_Zone).w,d0
    5.     move.b  Off_TitleCardLetters(pc,d0.w),d0
    6.     lea TitleCardLetters(pc),a0
    7.     lea (a0,d0.w),a0
    8.     move.l  #vdpComm(tiles_to_bytes(ArtTile_LevelName),VRAM,WRITE),d0
    And to be honest: I really don't understand what's going on here, but it was like that in the original disassembly, so technically, it shouldn't give any problems.
    But it does... -_-
    So I would be glad if someone could tell me what going on here and how I could fix my problem. Thanks in advance!
     
  2. MainMemory

    MainMemory

    Kate the Wolf Tech Member
    4,735
    334
    63
    SonLVL
    OK, first off, this problem isn't even remotely related to SonLVL. Secondly, look below the LoadTitleCard routine, you should see something like this:
    Code (Text):
    1. ; byte_15820:
    2. Off_TitleCardLetters:
    3.     dc.b TitleCardLetters_EHZ - TitleCardLetters    ; 0
    4.     dc.b TitleCardLetters_EHZ - TitleCardLetters    ; 1
    5.     dc.b TitleCardLetters_EHZ - TitleCardLetters    ; 2
    6.     dc.b TitleCardLetters_EHZ - TitleCardLetters    ; 3
    7.     dc.b TitleCardLetters_MTZ - TitleCardLetters    ; 4
    8.     dc.b TitleCardLetters_MTZ - TitleCardLetters    ; 5
    9.     dc.b TitleCardLetters_WFZ - TitleCardLetters    ; 6
    10.     dc.b TitleCardLetters_HTZ - TitleCardLetters    ; 7
    11.     dc.b TitleCardLetters_HPZ - TitleCardLetters    ; 8
    12.     dc.b TitleCardLetters_EHZ - TitleCardLetters    ; 9
    13.     dc.b TitleCardLetters_OOZ - TitleCardLetters    ; A
    14.     dc.b TitleCardLetters_MCZ - TitleCardLetters    ; B
    15.     dc.b TitleCardLetters_CNZ - TitleCardLetters    ; C
    16.     dc.b TitleCardLetters_CPZ - TitleCardLetters    ; D
    17.     dc.b TitleCardLetters_DEZ - TitleCardLetters    ; E
    18.     dc.b TitleCardLetters_ARZ - TitleCardLetters    ; F
    19.     dc.b TitleCardLetters_SCZ - TitleCardLetters    ; 10
    20.     even
    21.  
    22.  ; temporarily remap characters to title card letter format
    23.  ; Characters are encoded as Aa, Bb, Cc, etc. through a macro
    24.  charset 'A',0  ; can't have an embedded 0 in a string
    25.  charset 'B',"\4\8\xC\4\x10\x14\x18\x1C\x1E\x22\x26\x2A\4\4\x30\x34\x38\x3C\x40\x44\x48\x4C\x52\x56\4"
    26.  charset 'a',"\4\4\4\4\4\4\4\4\2\4\4\4\6\4\4\4\4\4\4\4\4\4\6\4\4"
    27.  charset '.',"\x5A"
    28.  
    29. ; Defines which letters load for the continue screen
    30. ; Each letter occurs only once, and  the letters ENOZ (I.e. ZONE) aren't loaded here
    31. ; However, this is hidden by the titleLetters macro, and normal titles can be used
    32. ; (the macro is defined near SpecialStage_ResultsLetters, which uses it before here)
    33.  
    34. ; word_15832:
    35. TitleCardLetters:
    36.  
    37. TitleCardLetters_EHZ:
    38.     titleLetters    "EMERALD HILL"
    And so on. My best guess is that something you did removed or renamed the 'Off_TitleCardLetters' label.
     
  3. Well, I have this:
    Code (Text):
    1. ; byte_15820:
    2.     include "TitleCards_Setup.asm"
    3. ; word_15832:
    4. TitleCardLetters:
    Which was the result of me trying to change the level names with Selbi's text editor:
    http://info.sonicretro.org/Sonic_2_-_Text_Code_Generator
    If this is a bad thing, then tough luck, this is the only way for me to change zone names.
     
  4. MainMemory

    MainMemory

    Kate the Wolf Tech Member
    4,735
    334
    63
    SonLVL
    You were following the 2007 guide for zone title cards, you should have followed the Hg guide. The disassembly now on GitHub used to be hosted on a Mercurial (Hg) repository, and an SVN repository before that, so GitHub, Git, Hg, and SVN all refer to the same disassembly. Although it appears that Selbi only describes the setup for the letters to be loaded in Hg if you click on the "?" button in the editor, not in the setup guide.

    Just replace the 'include "TitleCards_Setup.asm"' with the part from the original disassembly that I posted earlier and type in the zone name below.
     
  5. Wait, HG guide? What do you mean?
    I hope you don't mean the one where I have to use SonMapEd or Flex in order to change level names, because I really cannot use those programs. I just can't.
     
  6. MainMemory

    MainMemory

    Kate the Wolf Tech Member
    4,735
    334
    63
    SonLVL
    No, in S2TCG, there are sections for 2007 and Hg. At least, there should be if it's recent enough.
     
  7. Ah, okay.
    I now replaced the old part with what you posted, and now I get this error:
    Code (Text):
    1. > > >s2.asm(20964): error: jump distance too big
    2. > > >   bsr.w   SingleObjLoad2
    So I took a look at the code again, and...
    Code (Text):
    1. ; loc_10372:
    2. Obj17_MakeHelix:
    3.     bsr.w   SingleObjLoad2
    4.     bne.s   Obj17_Main
    5.     addq.b  #1,subtype(a0)
    6.     move.w  a1,d5
    7.     subi.w  #Object_RAM,d5
    8.     if object_size=$40
    9.     lsr.w   #6,d5
    10.     else
    11.     divu.w  #object_size,d5
    12.     endif
    13.     andi.w  #$7F,d5
    14.     move.b  d5,(a2)+
    15.     move.b  #4,routine(a1)
    16.     _move.b d4,id(a1) ; load obj17
    17.     move.w  d2,y_pos(a1)
    18.     move.w  d3,x_pos(a1)
    19.     move.l  mappings(a0),mappings(a1)
    20.     move.w  #make_art_tile(ArtTile_ArtNem_GHZ_Spiked_Log,2,0),art_tile(a1)
    21.     bsr.w   Adjust2PArtPointer2
    22.     move.b  #4,render_flags(a1)
    23.     move.b  #3,priority(a1)
    24.     move.b  #8,width_pixels(a1)
    25.     move.b  d6,objoff_3E(a1)
    26.     addq.b  #1,d6
    27.     andi.b  #7,d6
    28.     addi.w  #$10,d3
    29.     cmp.w   x_pos(a0),d3
    30.     bne.s   +
    31.     move.b  d6,objoff_3E(a0)
    32.     addq.b  #1,d6
    33.     andi.b  #7,d6
    34.     addi.w  #$10,d3
    35.     addq.b  #1,subtype(a0)
    36. +   dbf d1,Obj17_MakeHelix ; repeat d1 times (helix length)
    Well, let's say I have absolutely no idea why I get the error...
    Would be glad if someone could help me.
     
  8. Clownacy

    Clownacy

    Tech Member
    1,053
    581
    93
  9. Hmm...but the thing is: I never added any new object. Heck, I didn't even change the level layouts yet, so why does it happen? I'm confused...
     
  10. Clownacy

    Clownacy

    Tech Member
    1,053
    581
    93
    Obj17, being a leftover from S1, is one of the first objects in the game's code; SingleObjLoad2 comes after the last object's code. In the Git disasm, between Obj17_MakeHelix and SingleObjLoad2, there're 10000 lines of code. The title cards/level results object sit right between them, around the 5000 mark. Your new sprite mappings are probably what increased that gap.
     
  11. Well, I checked, and the only thing changed between Obj17_MakeHelix and the SingleObjLoad2 after Obj17_MakeHelix' SingleObjLoad2 is word_15832, and even then the only thing I changed there are the names.
    Some of the new names are shorter than the old names, and some new names are longer than the old names.
    Anyway, how exactly do I increase the distance of the branches? Add empty code? And if yes, then where?
     
  12. AURORA☆FIELDS

    AURORA☆FIELDS

    The cute one here Tech Member
    216
    24
    18
    Finland
    AMPS
    read the link Clownacy gave earlier on the thread. It answers your question.
     
  13. I did read the link, and I found this:
    But the thing is: I don't know how to do that. Like, at all. Do I have to insert empty code somewhere in order to increase the distance of the branches or what?
     
  14. Clownacy

    Clownacy

    Tech Member
    1,053
    581
    93
    Read more, geez. Also,

    Well, there's your problem. The names count as data, too. You may have shortened some of them, but the longer ones probably took up whatever space you saved, and then some.
     
  15. Hmm, so I have to implement jumps by replacing the offending bsr with a jsr.
    Sadly, this gives me this message now:
    Code (Text):
    1. > > >s2.asm(20964): error: invalid operand size
    2. > > >   jsr.w   SingleObjLoad2
    Sorry if I'm asking stupid questions, but it's the first time I'm doing fullblown ASM, and it really takes me a while to understand certain things, so sorry.
     
  16. Then instead of going stairght into low language code start with the basics of learning programming and work with a higher level language first (C/C++, C#)
     
  17. Well, what I'm trying to do right now is actually basic as well, from what I have heard, yet I still get problems.
    Doesn't really make me look good right now, methinks...
     
  18. It's only basic if you have an understanding of it, which you have clearly established to being the contrary.
    As I said before, start learning the basics of programming and with a higher level language before nose-diving into an assembly language.
     
  19. But the thing is: I am already capable of programming basics.
    But how high should the level of the programming level be? I really don't want to wait until I can finally hack Sonic games.
     
  20. I listed C/C++ and C# as examples of higher level languages (and for the fact that you stated that you know the basics of programming yet didn't know what I meant by "higher level language" isn't helping you in that regard).
    This isn't something that you can just rush into. You have to take the time and effort in order to understand how this all works before going into it. If you're not willing to do that then stop bothering yourself. You need to practice and learn first.
    EDIT - typing on a touchscreen sucks at times :v: