Advertisement
Blazephlozard

Tengen Tetris next piece viewer

Feb 22nd, 2020
346
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.37 KB | None | 0 0
  1. --Tengen Tetris Lua by Blazephlozard and Spikestuff
  2. --If you want to use this for something other than "30 lines" and need help
  3. --feel free to message me on Discord: Blazephlozard#8042
  4.  
  5. upcomingBlocks = {}
  6.  
  7. upcomingTotals = { 0, 0, 0, 0, 0, 0, 0 }
  8.  
  9. longestDrought = 0
  10. currentDrought = 0
  11.  
  12. --[[
  13. 1 - I
  14. 2 - T
  15. 3 - O
  16. 4 - J
  17. 5 - L
  18. 6 - S
  19. 7 - Z
  20. ]]
  21.  
  22. names = { "I", "T", "O", "J", "L", "S", "Z" }
  23. drawings = {"####", "###\n # ", "##\n##", "###\n  #", "###\n#", " ##\n##", "##\n ##"}
  24. drawingBoxes = {
  25.     { 1, 1, 1, 1,
  26.       0, 0, 0, 0},
  27.       {1, 1, 1, 0,
  28.       0, 1, 0, 0},
  29.       {1, 1, 0, 0,
  30.       1, 1, 0, 0},
  31.       {1, 1, 1, 0,
  32.       0, 0, 1, 0},
  33.       {1, 1, 1, 0,
  34.       1, 0, 0, 0},
  35.       {0, 1, 1, 0,
  36.       1, 1, 0, 0},
  37.       {1, 1, 0, 0,
  38.       0, 1, 1, 0}
  39. }
  40.  
  41. -- https://en.wikipedia.org/wiki/X11_color_names these work
  42. colors = { "firebrick", "gold", "royalblue", "orange", "violet", "limegreen", "darkcyan" }
  43.  
  44. prevRNG = 0
  45. initialBlocks = 0
  46. allowScript = true
  47.  
  48. --Brute force make a list of 80 upcoming blocks (80 blocks = 320 blocks = 32 lines worth)
  49. function makeList()
  50.     savestate.saveslot(0)
  51.     if (tastudio.engaged()) then tastudio.setplayback(50) end
  52.    
  53.     for i=1,7 do
  54.         initialBlocks = initialBlocks + memory.readbyte(0x0052+i)
  55.     end
  56.    
  57.     client.speedmode(6399) --maximum?
  58.     client.unpause()
  59.    
  60.     local maxPieces = 80
  61.     for counter=1,maxPieces do
  62.         prevRNG = memory.read_u16_le(0x005C)
  63.        
  64.         curPiece = memory.readbyte(0x0066)
  65.         upcomingBlocks[counter] = curPiece
  66.         upcomingTotals[curPiece] = upcomingTotals[curPiece] + 1
  67.        
  68.         --I drought
  69.         if (curPiece ~= 1) then
  70.             currentDrought = currentDrought + 1
  71.             if (currentDrought > longestDrought) then longestDrought = currentDrought end
  72.         --I drought ended
  73.         else
  74.             print("drought of " .. currentDrought)
  75.             currentDrought = 0
  76.         end
  77.        
  78.         while (true) do
  79.             memory.write_u8(0x0060, 25)
  80.             curRNG = memory.read_u16_le(0x005C)
  81.             if (prevRNG ~= curRNG) then
  82.                 break
  83.             end
  84.             prevRNG = curRNG
  85.             gui.drawText(175, 120, counter .. "/" .. maxPieces, null, 0x00000000, 16, "Courier New")
  86.             emu.frameadvance()
  87.         end
  88.     end
  89.    
  90.     --Forcibly clear the greenzone, because our cheat can linger in tastudio states
  91.     if (tastudio.engaged()) then
  92.         tastudio.submitinsertframes(40,1)
  93.         tastudio.submitdeleteframes(40,1)
  94.         tastudio.applyinputchanges()
  95.     end
  96.    
  97.     savestate.loadslot(0)
  98.     client.speedmode(100)
  99.    
  100.     print("Block totals:")
  101.     for i=1,7 do
  102.         print(names[i] .. ": " .. upcomingTotals[i])
  103.     end
  104.     print("Longest I-piece drought: " .. longestDrought)
  105.    
  106.     client.pause()
  107. end
  108.  
  109. function doTheDraw(block, xpos, ypos)
  110.    
  111.     for i=1,8 do
  112.         if (drawingBoxes[block][i] == 1) then
  113.         local theColor = colors[block]
  114.         local theX = xpos
  115.         local theY = ypos
  116.         if (i >= 5) then theY = theY + 6 end
  117.         --special I-block x and y shifting
  118.         if (block == 1) then
  119.             theX = theX - 3
  120.             theY = theY + 3
  121.         end
  122.         gui.drawRectangle(theX + ((i-1)%4)*6,theY,5,5,theColor,theColor)
  123.         end
  124.     end
  125.    
  126. end
  127.  
  128. --allowScript = false
  129. makeList()
  130. --for testing
  131. --[[for counter=1,80 do
  132.     upcomingBlocks[counter] = counter%7 + 1
  133. end]]
  134.  
  135. while (allowScript) do
  136.     --003D = 64 when not in menus, as far as we can tell
  137.     if (memory.readbyte(0x003D) == 64 or memory.readbyte(0x003D) == 6) and (memory.readbyte(0x067C) ~= 30) then
  138.         --Cover up where we're putting info
  139.         gui.drawRectangle(112,80,30,144,"black","black")
  140.         gui.drawRectangle(112,200,60,24,"black","black")
  141.        
  142.         --spikestuff stuff (border line, NEXT text, cover up base game next
  143.         gui.drawBox(160,65,240,224,"black","black");
  144.         gui.drawLine(16,65,96,65,"red");
  145.         gui.pixelText(112,80,"NEXT","red","clear");
  146.         gui.drawBox(16,16,49,39,"black","black");
  147.         --
  148.         local totalBlocks = -initialBlocks + 1
  149.         for i=1,7 do
  150.             totalBlocks = totalBlocks + memory.readbyte(0x0052+i)
  151.             gui.drawText(160, 80+(i-1)*15, names[i] .. ": " .. memory.readbyte(0x0052+i), null, 0x00000000, 16, "Courier New")
  152.         end
  153.         --[[test
  154.         for i=1,7 do
  155.             gui.text(55+(i*50),40,drawings[i], colors[i])
  156.         end]]
  157.        
  158.         for i=1,10 do
  159.             temp = totalBlocks+i-1
  160.             if (temp <= 80 and temp > 0) then
  161.                 num = upcomingBlocks[temp]
  162.                 --gui.text(55+(i*50),40,drawings[num], colors[num])
  163.                
  164.                 local xpos = 120
  165.                 local ypos = 87+(i-1)*24
  166.                
  167.                 if (i >= 7) then
  168.                     xpos = 124 + (i-6)*24
  169.                     ypos = 87 + 5*24
  170.                 end
  171.                 doTheDraw(num, xpos, ypos)
  172.                 --gui.drawRectangle(55+(i*50),40,10,10,"red","red")
  173.             end
  174.         end
  175.     end
  176.     emu.frameadvance()
  177.    
  178. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement