Advertisement
Blazephlozard

Kirby Tilt and Tumble lua 2

Jul 2nd, 2020
973
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.35 KB | None | 0 0
  1. memory.usememorydomain("System Bus")
  2. AddrXBig        = 0xFFA5;
  3. AddrXSmall      = 0xFFA6;
  4. AddrXSub        = 0xFFA7;
  5. AddrXSpd        = 0xFFD2; --big endian 16
  6. AddrYBig        = 0xFFA8;
  7. AddrYSmall      = 0xFFA9;
  8. AddrYSub        = 0xFFAA;
  9. AddrYSpd        = 0xFFD4; --big endian 16
  10. AddrZBig        = 0xFFAB;
  11. AddrZSmall      = 0xFFAC;
  12. AddrZSub        = 0xFFAD;
  13. AddrZSpd        = 0xFFD6; --big endian 16
  14.  
  15. --C134,135,136 are the 3 digits of the timer
  16. AddrFrameTimer  = 0xC137;
  17.  
  18. PrevX = 0
  19. XDiff = 0
  20. PrevY = 0
  21. YDiff = 0
  22. PrevZ = 0
  23. ZDiff = 0
  24. PrevFrameTimer = -1
  25. PrevFrame = -1
  26.  
  27.  
  28. XPosTable = {}
  29. YPosTable = {}
  30.  
  31. XColor = "white"
  32. XDiffColor = "white"
  33. XSpdColor = "white"
  34.  
  35. --gui.defaultPixelFont("gens")
  36. gui.defaultPixelFont("fceux")
  37.  
  38. while true do
  39.     emu.frameadvance();
  40.     --Position
  41.     XSmall=memory.readbyte(AddrXSmall);
  42.     XBig=memory.readbyte(AddrXBig);
  43.     X=XBig*256+XSmall;
  44.    
  45.     XSub=memory.readbyte(AddrXSub);
  46.     X = (X + (XSub/256))
  47.    
  48.     XDiff = X - PrevX;
  49.     PrevX = X;
  50.    
  51.     --in this game vertical travel is what needs to be compared, generally
  52.     --[[if (XPosTable[emu.framecount()] == null or XPosTable[emu.framecount()] == X) then
  53.         XPosTable[emu.framecount()] = X;
  54.         XColor = "white";
  55.     elseif (XPosTable[emu.framecount()] < X) then
  56.         XPosTable[emu.framecount()] = X;
  57.         XColor = "green";
  58.     else
  59.         XColor = "red";
  60.     end]]
  61.     --[[if XDiff>1.5 then
  62.         XDiffColor = "green"
  63.     elseif XDiff<1.5 then
  64.         XDiffColor = "red"
  65.     else
  66.         XDiffColor = "white"
  67.     end]]
  68.    
  69.     YSmall=memory.readbyte(AddrYSmall);
  70.     YBig=memory.readbyte(AddrYBig);
  71.     Y=YBig*256+YSmall;
  72.     YSub=memory.readbyte(AddrYSub);
  73.     Y = (Y + (YSub/256))
  74.    
  75.     YDiff = Y - PrevY;
  76.     PrevY = Y;
  77.    
  78.     if (YPosTable[emu.framecount()] == null or YPosTable[emu.framecount()] == Y) then
  79.         YPosTable[emu.framecount()] = Y;
  80.         YColor = "white";
  81.     elseif (YPosTable[emu.framecount()] > Y) then
  82.         YPosTable[emu.framecount()] = Y;
  83.         YColor = "green";
  84.     else
  85.         YColor = "red";
  86.     end
  87.    
  88.     -- negative 2 pixels per frame is the target speed
  89.     if YDiff<-2 then
  90.         YDiffColor = "green"
  91.     elseif YDiff>-2 then
  92.         YDiffColor = "red"
  93.     else
  94.         YDiffColor = "white"
  95.     end
  96.    
  97.     ZSmall=memory.readbyte(AddrZSmall);
  98.     ZBig=memory.readbyte(AddrZBig);
  99.     Z=ZBig*256+ZSmall;
  100.     ZSub=memory.readbyte(AddrZSub);
  101.     Z = (Z + (ZSub/256))
  102.    
  103.     ZDiff = Z - PrevZ;
  104.     PrevZ = Z;
  105.    
  106.     --the speed variables are not proving useful/accurate compared to diff
  107.     --Speed
  108.     --XSpd=memory.read_s16_be(AddrXSpd)/256;
  109.     --YSpd=memory.read_s16_be(AddrYSpd)/256;
  110.     --ZSpd=memory.read_s16_be(AddrZSpd)/256;
  111.    
  112.     gui.pixelText(3, 2, string.format("% 9.3f",X),XColor)
  113.     --gui.pixelText(10, 18, string.format("% 9.3f",XSpd),XSpdColor)
  114.     gui.pixelText(3, 11, string.format("% 9.3f",XDiff),XDiffColor)
  115.    
  116.     gui.pixelText(58, 2, string.format("% 9.3f",Y),YColor)
  117.     --gui.pixelText(65, 18, string.format("% 9.3f",YSpd))
  118.     gui.pixelText(58, 11, string.format("% 9.3f",YDiff),YDiffColor)
  119.    
  120.     gui.pixelText(113, 2, string.format("% 7.3f",Z))
  121.     --gui.pixelText(120, 18, string.format("% 9.3f",ZSpd))
  122.     gui.pixelText(113, 11, string.format("% 7.3f",ZDiff))
  123.    
  124.     --Determine Lag
  125.     FrameTimer = memory.readbyte(AddrFrameTimer);
  126.     if (FrameTimer == PrevFrameTimer and PrevFrame ~= emu.framecount()) then
  127.         --Check if all our diffs are 0, but positions are not
  128.         if (XDiff == 0 and YDiff == 0 and ZDiff == 0 and (X ~= 0 or Y ~= 0 or Z ~= 0)) then
  129.             tastudio.setlag(emu.framecount(),true)
  130.         end
  131.     end
  132.     PrevFrameTimer = FrameTimer
  133.     PrevFrame = emu.framecount()
  134.    
  135. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement