don't click here

SpritePiece.asm for AS based disassemblies

Discussion in 'Engineering & Reverse Engineering' started by kram1024, Aug 27, 2017.

  1. kram1024

    kram1024

    Researcher / Hacker Oldbie
    63
    1
    6
    at home, duh
    Part of the new Team Revamped; Kraminator Special Series disassemblies; Sonic 3 Sound Driver porting guides; KENS 1.5; smps studio; various non-sonic related things
    I am planning to fork the main git tree for some totally new branches, but until then you can use this:
    Code (Text):
    1.  
    2. ; macro to declare a mappings table (taken from Sonic 2 Hg disassembly)
    3. mappingsTable macro {INTLABEL}
    4. __LABEL__ label *
    5. current_mappings_table = __LABEL__
    6.     endm
    7.  
    8. ; macro to declare an entry in a mappings table (taken from Sonic 2 Hg disassembly)
    9. mappingsTableEntry macro ptr
    10.     dc.ATTRIBUTE ptr-current_mappings_table
    11.     endm
    12.  
    13. spriteHeader macro {INTLABEL}
    14. __LABEL__ label *
    15.     if SonicMappingsVer=1
    16.     dc.b ((__LABEL___End-__LABEL__-1)/5)
    17.     elseif SonicMappingsVer=2
    18.     dc.w ((__LABEL___End-__LABEL__-2)/8)
    19.     else
    20.     dc.w ((__LABEL___End-__LABEL__-2)/6)
    21.     endif
    22.     endm
    23.  
    24. spritePiece macro xpos,ypos,width,height,tile,xflip,yflip,pal,pri
    25.     if SonicMappingsVer=1
    26.     dc.b    ypos
    27.     dc.b    (((width-1)&3)<<2)|((height-1)&3)
    28.     dc.b    ((pri&1)<<7)|((pal&3)<<5)|((yflip&1)<<4)|((xflip&1)<<3)|((tile&$700)>>8)
    29.     dc.b    tile&$FF
    30.     dc.b    xpos
    31.     elseif SonicMappingsVer=2
    32.     dc.w    ((ypos&$FF)<<8)|(((width-1)&3)<<2)|((height-1)&3)
    33.     dc.w    ((pri&1)<<15)|((pal&3)<<13)|((yflip&1)<<12)|((xflip&1)<<11)|(tile&$7FF)
    34.     dc.w    ((pri&1)<<15)|((pal&3)<<13)|((yflip&1)<<12)|((xflip&1)<<11)|((tile>>1)&$7FF)
    35.     dc.w    xpos
    36.     else
    37.     dc.w    ((ypos&$FF)<<8)|(((width-1)&3)<<2)|((height-1)&3)
    38.     dc.w    ((pri&1)<<15)|((pal&3)<<13)|((yflip&1)<<12)|((xflip&1)<<11)|(tile&$7FF)
    39.     dc.w    xpos
    40.     endif
    41.     endm
    42.  
    43. spritePiece2P macro xpos,ypos,width,height,tile,xflip,yflip,pal,pri,tile2,xflip2,yflip2,pal2,pri2
    44.     if SonicMappingsVer=1
    45.     dc.b    ypos
    46.     dc.b    (((width-1)&3)<<2)|((height-1)&3)
    47.     dc.b    ((pri&1)<<7)|((pal&3)<<5)|((yflip&1)<<4)|((xflip&1)<<3)|((tile&$700)>>8)
    48.     dc.b    tile&$FF
    49.     dc.b    xpos
    50.     elseif SonicMappingsVer=2
    51.     dc.w    ((ypos&$FF)<<8)|(((width-1)&3)<<2)|((height-1)&3)
    52.     dc.w    ((pri&1)<<15)|((pal&3)<<13)|((yflip&1)<<12)|((xflip&1)<<11)|(tile&$7FF)
    53.     dc.w    ((pri2&1)<<15)|((pal2&3)<<13)|((yflip2&1)<<12)|((xflip2&1)<<11)|(tile2&$7FF)
    54.     dc.w    xpos
    55.     else
    56.     dc.w    ((ypos&$FF)<<8)|(((width-1)&3)<<2)|((height-1)&3)
    57.     dc.w    ((pri&1)<<15)|((pal&3)<<13)|((yflip&1)<<12)|((xflip&1)<<11)|(tile&$7FF)
    58.     dc.w    xpos
    59.     endif
    60.     endm
    61.  
    62. dplcHeader macro {INTLABEL}
    63. __LABEL__ label *
    64.     if SonicMappingsVer=1
    65.     dc.b ((__LABEL___End-__LABEL__-1)/2)
    66.     elseif SonicMappingsVer=2
    67.     dc.w ((__LABEL___End-__LABEL__-2)/2)
    68.     else
    69.     dc.w ((__LABEL___End-__LABEL__-4)/2)
    70.     endif
    71.     endm
    72.  
    73. dplcEntry macro tiles,offset
    74.     if SonicMappingsVer=3
    75.     dc.w    ((offset&$FFF)<<4)|((tiles-1)&$F)
    76.     else
    77.     dc.w    (((tiles-1)&$F)<<12)|(offset&$FFF)
    78.     endif
    79.     endm
    80.  
    81. ; I don't know why, but S3K uses Sonic 2's DPLC format for players, and its own for everything else
    82. ; So to avoid having to set and reset SonicMappingsVer I'll just make special macros
    83. s3kPlayerDplcHeader macro {INTLABEL}
    84. __LABEL__ label *
    85.     dc.w ((__LABEL___End-__LABEL__-2)/2)
    86.     endm
    87.  
    88. s3kPlayerDplcEntry macro tiles,offset
    89.     dc.w    (((tiles-1)&$F)<<12)|(offset&$FFF)
    90.     endm
    91.  
    just note that the format of macro mappings is unchanged from the asm68k version, this is just for asw based disassemblies only.
     
  2. MainMemory

    MainMemory

    Kate the Wolf Tech Member
    4,735
    334
    63
    SonLVL
    Um. There's already a version of SpritePiece.asm for AS, in fact, it was the original, the ASM68K version was made later. Plus, IIRC my conversion program comes with both files included.
     
  3. kram1024

    kram1024

    Researcher / Hacker Oldbie
    63
    1
    6
    at home, duh
    Part of the new Team Revamped; Kraminator Special Series disassemblies; Sonic 3 Sound Driver porting guides; KENS 1.5; smps studio; various non-sonic related things
    Well, the fork is in progress (s1disasm-MapMacrosAS), by the way, thanks for letting me know about that file's existance, I can't believe how identical my version and yours are though, I guess I got the conversion right.

    Other branches I intend to add are ProjectSonic1TwoEightAS, MusicMacrosAS, and Unified (All branches as one) for sonic1 disasm, will do similar things for the s2disasm.

    MusicMacrosAS will use Flamewing's asm music format btw
     
  4. MainMemory

    MainMemory

    Kate the Wolf Tech Member
    4,735
    334
    63
    SonLVL
    You know, this is going to be an absolute nightmare to maintain.
     
  5. kram1024

    kram1024

    Researcher / Hacker Oldbie
    63
    1
    6
    at home, duh
    Part of the new Team Revamped; Kraminator Special Series disassemblies; Sonic 3 Sound Driver porting guides; KENS 1.5; smps studio; various non-sonic related things
    Not as much as you think. I will just maintain the fork, thus unofficial disassemblies, retro can maintain the official branches on official retro disassemblies. The real nightmare is initial merge, and once that is done, I just pull in upstream changes from official branches, i.e. MapMacrosAS just needs MapMacros changes from upstream and AS changes from upstream, I can use diff patches if needed and merge in .reject lumps if they come up. I have a lot of time on my hands.

    As a matter of fact, having these branches in my opinion actually can be helpful, i.e. you want MapMacros but do not have Windows and still want to hack the z80 sound driver too, MapMacrosAS would be perfect for you.
     
  6. MainMemory

    MainMemory

    Kate the Wolf Tech Member
    4,735
    334
    63
    SonLVL
    You are aware that practically nobody uses MapMacros, right?
     
  7. kram1024

    kram1024

    Researcher / Hacker Oldbie
    63
    1
    6
    at home, duh
    Part of the new Team Revamped; Kraminator Special Series disassemblies; Sonic 3 Sound Driver porting guides; KENS 1.5; smps studio; various non-sonic related things
    Even still, another issue is corrected by this: some disassemblies use asw and others use asm68k which means syntax issues but if all used as or all used asm68k, no issues, mine will all use asw.

    Another I intend to fix later, is symbol name conflicts, i.e. a symbol called one thing in sonic1 disasm, and another in sonic2 disasm. No more mess trying to port an object. Thus your strawman argument is meaningless in this context, besides, if nobody uses the branch, then why does it exist? I say at least enough people use it to warrant its existence and the small number would likely be because it doesn't play nice with a lot of hack projects. On the other hand if a change was made that did make it play a lot more nicely, then it might get used more.
     
  8. MainMemory

    MainMemory

    Kate the Wolf Tech Member
    4,735
    334
    63
    SonLVL
    It exists because I made it and use it, and nobody is bothered enough by its existence to remove it. If there was a time when programs supported the macros, I would probably petition for the branch to be merged into master, because there wouldn't be any reason not to.

    How, exactly, are you going to "fix" symbol name conflicts?
     
  9. kram1024

    kram1024

    Researcher / Hacker Oldbie
    63
    1
    6
    at home, duh
    Part of the new Team Revamped; Kraminator Special Series disassemblies; Sonic 3 Sound Driver porting guides; KENS 1.5; smps studio; various non-sonic related things
    I see, oh and how the conflicts will be fixed is by naming all symbols which point to identical code that serves the same purpose in one disasm, the same thing in the other, oh and by identical, I mean has to be close enough to tell that it is the same sub, function, or method. Alternatively, it can be similar code that works way different but still fulfills the same role, i.e. the sound driver init method.

    The result, as long as the function, sub, or, method being requested exists it will work since the name is the same, no more need to hunt around the code, it is either there, or it isn't and needs porting in your hack.

    We get rid of the meaningless work so that productivity can go towards more impressive things, such as a new custom boss.

    On another note, by your logic, I should drop all but the unified branch since it is everything added except things best done by the end user, though it is simpler if I pull in the AS branch official changes, merge them into the rest, merge other branch changes that don't break any branches or violate naming rules or strict choice of assembler, then merge in everything to unified.
     
  10. MainMemory

    MainMemory

    Kate the Wolf Tech Member
    4,735
    334
    63
    SonLVL
    Okay, which labels are you going to use? The ones from Sonic 1, or the ones from Sonic 2?