Advertisement
LilPinkus

ancilla.lua

Jun 19th, 2019
257
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.45 KB | None | 0 0
  1. local type_to_name = { -- {{{
  2. -- 0x00
  3. '..',
  4. 'Somar Blast',
  5. 'Fire Shot',
  6. 'Unused',
  7. 'Beam Hit',
  8. 'Boom',
  9. 'Wall Hit',
  10. 'Bomb',
  11. 'Door Debr',
  12. 'Arrow',
  13. '*Wall Arrow',
  14. 'Ice Shot',
  15. 'Sword Beam',
  16. 'Sword Spark',
  17. 'Unused',
  18. 'Unused',
  19.  
  20. -- 0x10
  21. 'Unused',
  22. 'Ice Spread',
  23. 'Unused',
  24. '*Ice Sparkle',
  25. 'Unused',
  26. 'Jump Splash',
  27. 'Ham Stars',
  28. 'Shov Dirt',
  29. 'EtherFX',
  30. 'BombosFX',
  31. 'Torch/PowFX',
  32. 'Wall Sparks',
  33. 'QuakeFX',
  34. 'Bonk',
  35. 'BootDust',
  36. 'Hookshot',
  37.  
  38. -- 0x20
  39. 'Bed Spread',
  40. 'Zzzzs',
  41. 'Got Item',
  42. 'Bun/Capoof',
  43. 'Grave Moving',
  44. '???',
  45. 'Sword Spark',
  46. 'Bird',
  47. 'Pond Item',
  48. 'Pend/crystal',
  49. 'Spin Spark',
  50. 'Spin Spark2',
  51. 'Som Block',
  52. '???',
  53. '???',
  54. 'Torch flame',
  55.  
  56. -- 0x30
  57. 'Pre Byrna',
  58. 'Byrna Spark',
  59. 'Flame Blob',
  60. 'Expl Wall',
  61. 'SW Burn',
  62. 'MS Hurray',
  63. 'Flute Dig',
  64. 'WV Expl',
  65. 'Bird Flute',
  66. 'Som Plat Blast',
  67. 'SBomb Expl',
  68. 'Unused',
  69. '*Sword Spark',
  70. 'Item Splash',
  71. '3D Crystal',
  72. 'Bush Poof',
  73.  
  74. -- 0x40
  75. 'Dwarf Trans',
  76. 'Water @ Wishing & Swamp',
  77. 'Wishing Rupee',
  78. 'GT Seal Broken',
  79. } -- }}}
  80.  
  81. local TEXT_TOP = 70
  82.  
  83. -- UTIL
  84.  
  85. local function tohex(num)
  86. return string.format('%X', num)
  87. end
  88.  
  89. local function call_for_each_bank(address, fn, ...)
  90. for i = 0x00, 0x1F do
  91. fn(bit.lshift(i, 16) + address, unpack(arg))
  92. end
  93. fn(0x7E0000 + address, unpack(arg))
  94. end
  95.  
  96.  
  97. -- ANCILLA
  98.  
  99. local function get_ancillae()
  100. local ancillae = {}
  101. for i=0, 9 do
  102. local ancilla = {
  103. index = i,
  104. type = memory.readbyte(0x7E0C4A + i),
  105. x = bit.bor(memory.readbyte(0x7E0C04 + i), bit.lshift(memory.readbyte(0x7E0C18 + i), 8)),
  106. y = bit.bor(memory.readbyte(0x7E0BFA + i), bit.lshift(memory.readbyte(0x7E0C0E + i), 8)),
  107. }
  108. ancilla['name'] = type_to_name[ancilla['type'] + 1]
  109. table.insert(ancillae, ancilla)
  110. end
  111. return ancillae
  112. end
  113.  
  114. local function get_camera()
  115. return {
  116. ['x'] = memory.readwordsigned(0xe2),
  117. ['y'] = memory.readwordsigned(0xe8),
  118. }
  119. end
  120.  
  121.  
  122. -- LOGIC
  123. local function draw_ancilla(ancilla, camera)
  124. local pos = ancilla['index']
  125. gui.text(6, TEXT_TOP + 8 + 8 * pos, tohex(ancilla['index']) .. ': '.. ancilla['name'])
  126.  
  127. if ancilla['type'] > 0 then
  128. local x = ancilla['x'] - camera['x']
  129. local y = ancilla['y'] - camera['y']
  130. gui.text(x, y, tohex(ancilla['index']), 'red')
  131. end
  132. end
  133.  
  134. local function iterate_ancillae()
  135. local camera = get_camera()
  136.  
  137. local ancillae = get_ancillae()
  138. for i, ancilla in pairs(ancillae) do
  139. draw_ancilla(ancilla, camera)
  140. end
  141.  
  142. local sidx = memory.readbyteunsigned(0x7E03C4)
  143.  
  144. gui.text(6, TEXT_TOP - 8, tohex(memory.readbyte(0x7E0C5E)) .. ' ' ..
  145. tohex(memory.readbyte(0x7E0C5F)) .. ' ' ..
  146. tohex(memory.readbyte(0x7E0C60)) .. ' ' ..
  147. tohex(memory.readbyte(0x7E0C61)))
  148. gui.text(6, TEXT_TOP, 'I:' .. tohex(sidx) .. ' ' ..
  149. 'H:' .. tohex(memory.readbyte(0x7E039D)) .. ' ' ..
  150. 'E:' .. tohex(memory.readbyte(0x7E03A4)) .. ' ' ..
  151. 'D:' .. tohex(memory.readbyte(0x7E0C72)))
  152.  
  153. for i = 0, 5 do
  154. local addr = 0x7E0C54 + i
  155. gui.text(6, TEXT_TOP + 8 + 8 * 10 + 8 * i, tohex(memory.readbyte(addr)))
  156. end
  157. end
  158.  
  159.  
  160. -- EVENTS
  161.  
  162. function on_write(addr, size)
  163. if addr < 0x200000 then
  164. addr = bit.band(addr, 0xFFFF)
  165. addr = 0x7E0000 + addr
  166. end
  167.  
  168. val = size == 1 and memory.readbyte(addr) or memory.readword(addr)
  169. local line = "[" .. tohex(memory.getregister("pb"), 2) .. ":" .. tohex(memory.getregister("pc"), 4) .. "] "
  170. .. tohex(addr, 6) .. "[" .. tostring(size) .. "] = " .. tohex(val, size == 1 and 2 or 4)
  171. .. (size == 1 and " | " or " | ") .. " F=" .. emu.framecount()
  172. print(line)
  173. end
  174.  
  175. call_for_each_bank(0x0000, function (bank_only)
  176. memory.registerwrite(bank_only + 0xEE, 0x1, on_write)
  177. end)
  178.  
  179.  
  180. --[[
  181. local function addancilla()
  182. local y = bit.band(memory.getregister("y"), 0xFF)
  183. local a = bit.band(memory.getregister("a"), 0xFF)
  184. print('+ ancilla:', type_to_name[a+1], '(Y=' .. tohex(y) .. ', A=' .. tohex(a) .. ')')
  185. end
  186.  
  187. memory.registerexecute(0x1cf537, addancilla)
  188. ]]
  189.  
  190.  
  191. local function write_ancilla(addr, size)
  192. if addr < 0x200000 then
  193. addr = bit.band(addr, 0xFFFF)
  194. addr = 0x7E0000 + addr
  195. end
  196.  
  197. local slot = bit.band(addr, 0xFFFF) - 0x0C4A
  198. local val = size == 1 and memory.readbyte(addr) or memory.readword(addr)
  199. if val > 0 then
  200. print('+ slot[' .. tohex(slot) .. ']: ' .. type_to_name[val + 1] .. ' (' .. tohex(val) .. ')')
  201. else
  202. print('- slot[' .. tohex(slot) .. ']')
  203. end
  204. end
  205.  
  206. call_for_each_bank(0x0000, function (bank_only)
  207. memory.registerwrite(bank_only + 0x0C4A, 0xA, write_ancilla)
  208. end)
  209.  
  210.  
  211. -- memory.writebyte(0x7E03A4, 0x0)
  212. -- memory.writebyte(0x7E0C4A + 4, 0x03)
  213. -- memory.writebyte(0x7E0C4A + 3, 0x03)
  214. -- memory.writebyte(0x7E0C4A + 2, 0x03)
  215. -- memory.writebyte(0x7E0C4A + 1, 0x03)
  216.  
  217. while true do
  218. iterate_ancillae()
  219. snes9x.frameadvance()
  220. -- print('-- F: ' .. emu.framecount())
  221. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement