don't click here

S3K Lua Add Dynamic Object Script

Discussion in 'Engineering & Reverse Engineering' started by Cokie, Jan 29, 2022.

  1. Cokie

    Cokie

    C. Okie Member
    75
    22
    8
    Hello. I wanted to share two Lua functions I wrote for Sonic 3 and Knuckles.
    It can be used with the Emulator Gens Re-Record

    They find and return the first available address in Dynamic Object Ram. They
    are similar to Create_New_Sprite and Create_New_Sprite3. Create_New_Sprite
    finds the first slot after FFFFBODE and returns if it finds it. Create_New_Sprite3
    find the first slot after the slot your provide as a parameter. I use it for some testing
    When Exodus isn’t adequate.

    Here is the code:

    Code (Text):
    1.  
    2. -- similar to s3k Create_New_Sprite
    3. -- searches for the first available slot in dynamic object ram
    4. -- if it finds one it will return its address.
    5. -- it cannot find one it will return -1
    6. function Create_New_Sprite()
    7.  
    8. local object_size = 0x4A
    9. local Dynamic_object_RAM = 0xFFFFB0DE
    10. local Dynamic_object_RAM_end = 0xFFFFCAE2
    11.  
    12. local a1temp = Dynamic_object_RAM
    13. local d0temp = ( (Dynamic_object_RAM_end - Dynamic_object_RAM) / object_size )-1
    14.  
    15. i = d0temp
    16.  
    17. while i > 0 do
    18.  
    19. a1temp = a1temp + object_size
    20.     if memory.readlong(a1temp) == 0 then
    21.         return a1temp
    22.     end
    23.     i = i - 1
    24.     end
    25. return -1
    26. end
    27.  
    28.  
    29. -- similar to s3k Create_New_Sprite3
    30. -- searches for the first available slot in dynamic object ram
    31. -- after the address given in the parameter.
    32.  
    33. -- parameter adr - adr is the adress of the slot
    34. -- in dynamic object ram, that is before the slot
    35. -- where we begin checking for the first
    36. -- available slot.
    37. -- if addr is not in the range of dynamic object ram
    38. -- then it will return -1. This will also be the case
    39. -- if addr is not a long word type ( ie BODE OR FFBODE IS INVALID )
    40. -- if find one return its address
    41.  
    42. function Create_New_Sprite3(adr)
    43.  
    44. if adr < 0xFFFFB0DE or adr >= 0xFFFFCA98 then
    45.     return  -1
    46.     end
    47.  
    48. local object_size = 0x4A
    49.  
    50. local a1temp = adr
    51. local d0temp = (( 0xFFFFCAE2 - adr ) / object_size ) -1
    52.  
    53.  
    54. i = d0temp
    55.  
    56. while i > 0 do
    57.  
    58. a1temp = a1temp + object_size
    59.  
    60.  
    61.     if memory.readlong(a1temp) == 0 then
    62.         return a1temp
    63.     end
    64.  
    65.     i = i - 1
    66.  
    67.     end
    68.  
    69. return -1
    70.  
    71. end
    An example of writing object pointer code Obj_SOZ_Ghosts to the first available slot
    in Dynamic Object RAM:

    Obj_SOZ_Ghosts = 0x8EFC8
    Address = Create_New_Sprite()
    memory.writelong(Address,Obj_SOZ_Ghosts)

    An example of writing object pointer code Obj_FBZEggPrison
    to the first available that is after slot 0xFFFFB7CE in Dynamic Object RAM:

    Slot = 0x0xFFFFB7CE
    Obj_FBZEggPrison = 0x89AEC
    Address = Create_New_Sprite(Slot )
    memory.writelong(Address,Obj_FBZEggPrison)
     
    Last edited: Jan 29, 2022