don't click here

Hello (bra.w *+4)

Discussion in 'Engineering & Reverse Engineering' started by Ultima, Jan 9, 2007.

Thread Status:
Not open for further replies.
  1. Ultima

    Ultima

    Games Publisher Tech Member
    2,398
    1
    18
    London, England
    Publishing mobile games!
    Code (Text):
    1. bra.w   *+4
    What does this do?
     
  2. Agent ME

    Agent ME

    Void where prohibited Member
    26
    0
    0
    Where did you find it? What game?
     
  3. Xenowhirl

    Xenowhirl

    Tech Member
    175
    0
    0
    Branch to current program counter plus 4?
     
  4. Tweaker

    Tweaker

    Banned
    12,387
    2
    0
    Wouldn't it be pc+4 though, then? Correct me if I'm wrong, here.
     
  5. Aurochs

    Aurochs

    Единый, могучий Советский Союз! Tech Member
    2,343
    0
    0
    Whatever catches my fancy
    It basically just skips the next (word-wide) instruction. Dunno why one would do that with an unconditional branch, though.

    That would work too, but pretty much every assembler takes * to mean "program counter".
     
  6. Ultima

    Ultima

    Games Publisher Tech Member
    2,398
    1
    18
    London, England
    Publishing mobile games!
    It's in Sonic 2.

    Anyway, yeah, it just jumps ahead 2 bytes. Thing is, it's put it a completely useless place, and there's no reason for it to be there, because there's a label at the location it can jump to. There is no reason for it to be there except to break the code if anything is put between it and the next line. How strange.
     
  7. Aurochs

    Aurochs

    Единый, могучий Советский Союз! Tech Member
    2,343
    0
    0
    Whatever catches my fancy
    Yeah, there's some really weird code in Sonic 2.

    move.b 0(a0),d0
     
  8. Xenowhirl

    Xenowhirl

    Tech Member
    175
    0
    0
    This sounds like a problem with the disassembly, though. How could the Sonic 2 ROM tell the disassembler that this branch instruction isn't allowed to use the normal syntax for going to a label?
     
  9. drx

    drx

    mfw Researcher
    2,254
    350
    63
    :rolleyes:
    The whole thing jumps to 2 bytes after the instruction (6 bytes after the start of it).

    So, like:

    60 00 00 04 XX XX ______

    It jumps to _____ (4 bytes after the opcode, being 6000).

    I'm not sure whether *+4 makes the operand 0004 or 0002, but that's how it works anyway.

    In either way, this is caused by programming with macros. Programmers tend to use macros a lot, and they can't be arsed to check if there isn't a useless branch somewhere. Same with that move.b 0(a0) thing. What happened was that it was SOME_MACRO(a0) and SOME_MACRO got set to 0. That, or it's a disassembler bug.
     
  10. SMTP

    SMTP

    Tech Member
    No, Yuji is just a fag. :P
     
  11. Ultima

    Ultima

    Games Publisher Tech Member
    2,398
    1
    18
    London, England
    Publishing mobile games!
    It compiles to 0002
     
  12. Aurochs

    Aurochs

    Единый, могучий Советский Союз! Tech Member
    2,343
    0
    0
    Whatever catches my fancy
    Yeah, it's a macro thing that didn't get optimized out. The actual object code for move.b 0(a0),d0 as it appears in the binary is $1028 $0000 (the extension word holds the index, in this case 0). One wonders why they turned off that particular optimization, since indexed addressing is quite a bit slower than plain indirect addressing.

    The real problem is, AS DOES optimize zero-index addressing. To assemble the ROM into a (nearly) perfect replica of the retail version, I would have to turn off AS's optimization procedures, and Alfred Arnold tells me that this isn't possible, at least not at the moment.
     
  13. Ultima

    Ultima

    Games Publisher Tech Member
    2,398
    1
    18
    London, England
    Publishing mobile games!
    To me, making a perfect replica is only as a check that everything is working as it should - if you're sure it is anyway, there's really no need for it.
     
  14. Hivebrain

    Hivebrain

    Administrator
    3,049
    162
    43
    53.4N, 1.5W
    Github
    The assembled ROM doesn't need to be identical to the real ROM, but ideally all the data and code should be in the same place and have the same length.
     
  15. Aurochs

    Aurochs

    Единый, могучий Советский Союз! Tech Member
    2,343
    0
    0
    Whatever catches my fancy
    Which is precicely what I need to do. So hah.
     
Thread Status:
Not open for further replies.