Advertisement
Dugongue

RotTK2 - RNG advance

Dec 26th, 2019
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. RAM = {}
  2. for regY=5,0,-1 do
  3. RAM[0x98+regY] = memory.readbyte(0x98+regY)
  4. end
  5. RAM[0x9D] = memory.readbyte(0x9D)
  6. RAM[0x9D] = bit.bor(RAM[0x9D],0x01)
  7. for regY=5,0,-1 do
  8. RAM[0x9F+regY] = 0
  9. end
  10. for regY=5,0,-1 do
  11. RAM[0x73] = memory.readbyte(0xFC76 + regY)
  12. RAM[0x6C] = 0x08
  13. while RAM[0x6C] > 0 do
  14. carry = 0;
  15. for regX = 5,0,-1 do
  16. if bit.band(RAM[0x9F+regX],0x80)>0 then
  17. nextCarry = 1;
  18. else
  19. nextCarry = 0;
  20. end
  21. RAM[0x9F+regX] = bit.band(2*RAM[0x9F+regX]+carry,0xFF)
  22. carry = nextCarry;
  23. end
  24. if bit.band(RAM[0x73],0x80)>0 then
  25. carry = 1
  26. else
  27. carry = 0
  28. end
  29. RAM[0x73] = bit.band(2*RAM[0x73],0xFF)
  30. if carry~=0 then
  31. carry=0
  32. for regX=5,0,-1 do
  33. RAM[0x9F+regX] = RAM[0x9F+regX] + RAM[0x98+regX] + carry
  34. if RAM[0x9F+regX] > 0xFF then
  35. RAM[0x9F+regX] = bit.band(RAM[0x9F+regX],0xFF)
  36. carry = 1
  37. else
  38. carry = 0
  39. end
  40. end
  41. end
  42. RAM[0x6C] = RAM[0x6C] - 1
  43. end
  44. end
  45. carry = 1
  46. for regX=5,0,-1 do
  47. regA = XOR(RAM[0x9F+regX],0xFF) + carry
  48. if regA>0xFF then
  49. regA = bit.band(regA,0xFF)
  50. carry = 1
  51. else
  52. carry = 0
  53. end
  54. RAM[0x98+regX] = regA
  55. end
  56. RAM[0x67] = bit.band(RAM[0x98],0x7F)
  57. RAM[0x66] = RAM[0x99]
  58. emu.print(string.format("%x",RAM[0x66]) .. " " .. string.format("%x",RAM[0x67]))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement