don't click here

Machine Code Monitor Programming Guide

Discussion in 'Engineering & Reverse Engineering' started by Sonic 65, Oct 25, 2004.

  1. Sonic 65

    Sonic 65

    Tech Member
    I made a guide that tells you the location of parts of monitor code and what those parts do. Not much, but hey. Updates coming later.
     

    Attached Files:

  2. But you're talking about S1, right? It can't be S2 because monitor code in that game is at a higher address. Eggman monitor does nothing in S1, so it isn't too hard to figure out what a jump to "4E 75" does. :P

    Try to put in the next update info on how to have unused monitors to do something.
     
  3. Hivebrain

    Hivebrain

    Administrator
    3,047
    154
    43
    53.4N, 1.5W
    Github
    Wouldn't it be better to look at a disassembly if you want to know how things work?
     
  4. LOst

    LOst

    Tech Member
    4,891
    8
    18
  5. Hayate

    Hayate

    Tech Member
    LOst, do you have a machine code to ASM table anywhere? That would help me out a lot more than this other stuff...
     
  6. Sonic 65

    Sonic 65

    Tech Member
    I made a little machine-code-to-ASM text file sometime ago. The only problem is that it hasn't seen an update in ages. I'll update it a little and edit this post to have it attached.

    Oh yeah, and Erik JS, the Eggman code is more than a jump to 4E 75.

    addq.b #2, $24(a0) ;???
    move.w #$1D, $1E(a0) ;???
    move.b $1C (a0) ,d0 ;???
    cmpi.b #1 , d0 ;Does monitor contain Eggman?
    bne.s loc_A384 ;If not, branch
    rts ;4E 75

    NOTE: Actually, my file is ASM-to-machine code, but it can also be used vice-versa.
     

    Attached Files:

  7. Rika Chou

    Rika Chou

    Tech Member
    5,276
    169
    43
    Very good, Sonic 65, I can tell you have put a lot of time into this.
     
  8. Sonic 65

    Sonic 65

    Tech Member
    Thanks. Making a machine code guide isn't nearly as hard if you have a disassembly. :D
     
  9. Quickman

    Quickman

    be attitude for gains Tech Member
    5,595
    18
    18
    :x
    omg porjcet
    Or you could just use the documentation Motorola give. That's how I learned ASM.

    EDIT:

    addq.b #2, $24(a0) ; advance to next object routine
    move.w #$1D, $1E(a0) ; set collision size for object to $1D
    move.b $1C (a0) ,d0 ; load animation frame into d0
    cmpi.b #1 , d0 ; Subtract one from animation frame number (frame 1 is Eggman)
    bne.s loc_A384 ; If not equal to 0 (I.e. if frame is not Eggman), continue to other frame checks
    rts ; We'll reach here if it IS equal to 0 - nothing happens
     
  10. Hivebrain

    Hivebrain

    Administrator
    3,047
    154
    43
    53.4N, 1.5W
    Github
    Isn't $1E(a0) something to do with animation? IIRC, $1A-$1E(a0) are used by the animation subroutines.
     
  11. Hayate

    Hayate

    Tech Member
    Sonic 65: Sorry to sound annoying, but it doesn't have all of the commands, like ADD or BEQ (now that's useful)...

    Edit: S65 for Tech Member! :D
     
  12. Quickman

    Quickman

    be attitude for gains Tech Member
    5,595
    18
    18
    :x
    omg porjcet
    I was going by MY document on the SST, hosted by drx on the Hacking CulT.
     
  13. Hivebrain

    Hivebrain

    Administrator
    3,047
    154
    43
    53.4N, 1.5W
    Github
    That document is inaccurate. And exactly how much of the information on it did you find yourself?
     
  14. Quickman

    Quickman

    be attitude for gains Tech Member
    5,595
    18
    18
    :x
    omg porjcet
    I have no idea. I've long since lost the original to check (it was on my old hard drive before I got my computer which for the moment doesn't suck).
     
  15. Sonic Hachelle-Bee

    Sonic Hachelle-Bee

    Taking a Sand Shower Tech Member
    806
    200
    43
    Lyon, France
    Sonic 2 Long Version
    You've just asked for it. :(

    Flags:
    N: Negative. Set to 1 if result negative.
    Z: Zero. Set to 1 if result is 0 (false).
    V: Overflow. Set to 1 if overflow (Pos + Pos = Neg or Neg + Neg = Pos)
    C: Carry.
    X: Like C, Carry.

    Assembly <-> Hexadecimal

    MOVE.B <-> 11 FC 12 34 AB CD (Store byte 34 at RAM $ABCD)
    MOVE.L <-> 21 FC 12 34 56 78 AB CD (Store long 12345678 at RAM $ABCD)
    MOVE.W <-> 31 FC 12 34 AB CD (Store word 1234 at RAM $ABCD)

    CMPI.B <-> 0C 38 12 34 AB CD (compare byte 34 at data from RAM $ABCD)
    CMPI.W <-> 0C 78 12 34 AB CD (compare word 1234 at data from RAM $ABCD)
    CMPI.L <-> 0C B8 12 34 56 78 AB CD (compare long 12345678 at data from RAM $ABCD)

    BRA.S <-> 60 11 (Branch always, jump 11 bytes)
    BSR.S <-> 61 11 (Branch under sub-routine)
    BHI.S <-> 62 11 (Branch if C=0 and Z=0)
    BLS.S <-> 63 11 (Branch if C=1 or Z=1)
    BCC.S <-> 64 11 (Branch if Carry clear, C=0)
    BCS.S <-> 65 11 (Branch if Carry set, C=1)
    BNE.S <-> 66 11 (Branch if non equal, Z=0 (false))
    BEQ.S <-> 67 11 (Branch if equal, Z=1 (true))
    BVC.S <-> 68 11 (Branch if Overflow clear, V=0)
    BVS.S <-> 69 11 (Branch if Overflow set, V=1)
    BPL.S <-> 6A 11 (Branch if result plus, N=0)
    BMI.S <-> 6B 11 (Branch if result minus, N=1)
    BGE.S <-> 6C 11 (Branch if greater or equal to, N=V)
    BLT.S <-> 6D 11 (Branch if lower than, N is not the same as V)
    BGT.S <-> 6E 11 (Branch if greater than, N=V and Z=0)
    BLE.S <-> 6F 11 (Branch if lower or equal to, N is not the same as V or Z=1)

    ADD <-> 52 38 AB CD (Add 1 at value in RAM $ABCD)
    ADD <-> 54 38 AB CD (Add 2 at value in RAM $ABCD)

    JMP <-> 4E F9 11 11 11 11 (Jump at ROM $11111111)
    JSR <-> 4E B9 11 11 11 11 (Jump at sub-routine at ROM $11111111)

    NOP <-> 4E 71 (Non operation, do nothing and continue)
    RTS <-> 4E 75 (Return to sub-routine)

    EDIT: Examples:

    RAM $FE10: Level loaded.
    RAM $ FE 11: Act loaded.
    RAM $ EE 00: Camera X position.
    RAM $ EE 04: Camera Y position.
    RAM $ F64A: Water Y height.

    0C 78 04 01 FE 10 67 10
    If Metropolis zone 2 (level 04 01) is loaded, jump 10 bytes.

    0C 78 0E 00 EE 00 6F 08
    If Camera X position is lower or equal to 0E 00, jump 08 bytes.

    0C 78 15 00 EE 00 6F 10 31 FC 02 00 F6 4A
    If Camera X position is greater than 15 00, set water Y height to 02 00.
    Else, jump 10 bytes.

    Helpful? There might be some errors, I haven't a 68K disassembly program for Mac, then I found this myself. ;)
     
  16. Sonic 65

    Sonic 65

    Tech Member
    ... :blink:

    You. are. god.
     
  17. Icy Guy

    Icy Guy

    Hedgehog. Sonic the Hedgehog. Member
    776
    0
    0
    California
    GoldenEye 007 level hack
    Very nice, SHB, very nice, although I noticed one small error:

    0C 78 15 00 EE 00 6F 10 31 FC 02 00 F6 4A ("If Camera X position is greater than 0E 00, set water Y height...") should be 0C 78 0E 00 EE 00 6F 10 31 FC 02 00 F6 4A.
     
  18. Sonic Hachelle-Bee

    Sonic Hachelle-Bee

    Taking a Sand Shower Tech Member
    806
    200
    43
    Lyon, France
    Sonic 2 Long Version
    Yeah...
    Damn copy and paste... :D