Advertisement
Guest User

boom-plus.lua

a guest
Jul 21st, 2017
7
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 9.29 KB | None | 0 0
  1. -- NES Braidulator VERSION 1
  2. --(C) Antony Lavelle 2009       got_wot@hotmail.com      http://www.the-exp.net
  3. -- A Lua script that allows 'Braid' style time reversal for Nes games being run in FCEUX
  4. --'Braid' is copyright Jonathan Blow, who is not affiliated with this script, but you should all buy his game because it's ace.
  5. --This is my first ever time scripting in Lua, so if you can improve on this idea/code please by all means do and redistribute it, just please be nice and include original credits along with your own :)
  6.  
  7.  
  8.  
  9. --Change these settings to adjust options
  10.  
  11.  
  12. --Which key you would like to function as the "rewind key"
  13.  
  14. local rewindKey = 'W'
  15.  
  16. --How much rewind power would you like? (The higher the number the further back in time you can go, but more computer memory is used up)
  17. --Do not set to 0!
  18.  
  19. local saveMax = 2500;
  20.  
  21.  
  22.  
  23. funtimes = 0;
  24. txttime = 0;
  25.  
  26.  
  27.  
  28. --The stuff below is for more advanced users, enter at your own peril!
  29.  
  30.  
  31.  
  32. local saveArray = {};--the Array in which the save states are stored
  33. local saveCount = 1;--used for finding which array position to cycle through
  34. local save; -- the variable used for storing the save state
  35. local rewindCount = 0;--this stops you looping back around the array if theres nothing at the end
  36. local savePreventBuffer = 1;--Used for more control over when save states will be saved, not really used in this version much.
  37.  
  38. timer           = 0;
  39. saveinterval    = 1;
  40. while (true) do
  41.     timer = timer + 1;
  42. --  frozen = {}
  43.     gui.pixel(0, 0, "clear");
  44.    
  45.     savePreventBuffer = savePreventBuffer-1;
  46.     if savePreventBuffer==0 then
  47.         savePreventBuffer = 1;
  48.     end;
  49.     joyput  = input.get();
  50.     if joyput[rewindKey] then
  51.         frozen = {}  -- unfreezes
  52.         savePreventBuffer = 5;
  53.         if rewindCount==0 then
  54.             gui.text(0, 8, "NO REWIND POWER LEFT");
  55.             --makes sure you can't go back too far could also include other things in here, left empty for now.
  56.         else   
  57.             savestate.load(saveArray[saveCount]);
  58.             saveCount = saveCount-1;
  59.             rewindCount = rewindCount-1;
  60.             if saveCount==0 then       
  61.                 saveCount = saveMax-1;
  62.             end;
  63.         end;
  64.         local HUDMATH = rewindCount / saveMax;--Making the rewind time a percentage.
  65.         gui.text(220,24, string.format("%.2f%%", HUDMATH * 100));--Displaying the time onscreen.
  66.        
  67.         if HUDMATH > 0.25 or math.fmod(timer, 20) < 10 then
  68.        
  69.             rwy = 16;
  70.            
  71.             for rwarrow = -1, 7 do
  72.                 gui.line(220 + rwarrow, rwy - 1 - math.floor(rwarrow / 2), 220 + rwarrow, rwy + 1 + math.floor(rwarrow / 2), "black");
  73.                 gui.line(221 + rwarrow, rwy - 1 - math.floor(rwarrow / 2), 221 + rwarrow, rwy + 1 + math.floor(rwarrow / 2), "black");
  74.                 gui.line(229 + rwarrow, rwy - 1 - math.floor(rwarrow / 2), 229 + rwarrow, rwy + 1 + math.floor(rwarrow / 2), "black");
  75.                 gui.line(230 + rwarrow, rwy - 1 - math.floor(rwarrow / 2), 230 + rwarrow, rwy + 1 + math.floor(rwarrow / 2), "black");
  76.  
  77.             end;
  78.             for rwarrow = 0, 7 do
  79.                 c1  = "white";
  80.                 if (rwarrow / 7) >= (HUDMATH / 0.9) then
  81.                     c1  = "red";
  82.                 end;
  83.                 c2  = "white";
  84.                 if (rwarrow / 7) > (HUDMATH - .90) * 10 then
  85.                     c2  = "red";
  86.                 end;
  87.                
  88.                 gui.line(220 + rwarrow, rwy - math.floor(rwarrow / 2), 220 + rwarrow, rwy + math.floor(rwarrow / 2), c1);
  89.                 gui.line(229 + rwarrow, rwy - math.floor(rwarrow / 2), 229 + rwarrow, rwy + math.floor(rwarrow / 2), c2);
  90.             end;
  91. --          gui.text(220, 8, "<<");
  92.         end;
  93.     end;
  94.     if math.fmod(timer, saveinterval) == 0 and savePreventBuffer==1 then
  95.         saveCount=saveCount+1;
  96.         if saveCount==saveMax then
  97.             saveCount = 1;
  98.         end
  99.         rewindCount = rewindCount+1;
  100.         if rewindCount==saveMax-1 then
  101.             rewindCount = saveMax-2;
  102.         end;
  103.         save = savestate.create();
  104.         savestate.save(save);
  105.         saveArray[saveCount] = save;
  106.     end;
  107.    
  108.    
  109.     keys    = input.get();
  110.     reset   = 0;
  111.     if keys['A'] then
  112.  
  113.         crap    = true
  114.         while crap do
  115.             bang1   = math.random(0x0000, 0x07FF)
  116.             if not (bang1 >= 0x100 and bang1 <= 0x1ff) then
  117.                 crap = false;
  118.             end
  119.         end;
  120.         bang2   = math.random(0, 0xFF);
  121.         memory.writebyte(bang1, bang2);
  122.         funtimes    = funtimes + 1;
  123.         reset       = 1;
  124.         gui.text(220, 8, "RAM");
  125.         -- print(string.format("%04X => %02X", bang1, bang2));
  126.     end;
  127.     if keys['D'] then
  128.  
  129.         crap    = true
  130.         while crap do
  131.             bang1   = math.random(0x0000, 0x07FF)
  132.             if not (bang1 >= 0x100 and bang1 <= 0x1ff) then
  133.                 crap = false;
  134.             end
  135.         end;
  136.         bang2   = memory.readbyte(bang1) + (math.random(0, 1) * 2 - 1);
  137.         memory.writebyte(bang1, bang2);
  138.         funtimes    = funtimes + 1;
  139.         reset       = 1;
  140.         gui.text(220, 16, "INC");
  141.         -- print(string.format("%04X => %02X", bang1, bang2));
  142.     end;
  143.     if keys['F'] then
  144.  
  145.         crap    = true
  146.         while crap do
  147.             bang1   = math.random(0x0000, 0x07FF)
  148.             if not (bang1 >= 0x100 and bang1 <= 0x1ff) then
  149.                 crap = false;
  150.             end
  151.         end;
  152.         bang2   = memory.readbyte(bang1) - (math.random(0, 1) * 2 - 1);
  153.         memory.writebyte(bang1, bang2);
  154.         funtimes    = funtimes + 1;
  155.         reset       = 1;
  156.         gui.text(220 + 6 * 3, 16, "DEC");
  157.         -- print(string.format("%04X => %02X", bang1, bang2));
  158.     end;
  159.     if keys['E'] then
  160.  
  161.         crap    = true
  162.         while crap do
  163.             bang1   = math.random(0x0000, 0x07FF)
  164.             if not (bang1 >= 0x100 and bang1 <= 0x1ff) then
  165.                 crap = false;
  166.             end
  167.         end;
  168.         bang2   = memory.readbyte(bang1) / 0;
  169.         memory.writebyte(bang1, bang2);
  170.         funtimes    = funtimes + 1;
  171.         reset       = 1;
  172.         gui.text(220 - 6 * 6, 8, "NUL");
  173.         -- print(string.format("%04X => %02X", bang1, bang2));
  174.     end;
  175.    
  176. --  if keys['T'] then
  177. --
  178. --      crap    = true
  179. --      while crap do
  180. --          bang1   = math.random(0x0000, 0x07FF)
  181. --          if not (bang1 >= 0x100 and bang1 <= 0x1ff) then
  182. --              crap = false;
  183. --          end
  184. --      end;
  185. --      bang2   = (memory.readbyte(bang1));
  186. --      int = XOR(int(bang2));
  187. --      memory.writebyte(bang1, bang2);
  188. --      funtimes    = funtimes + 1;
  189. --      reset       = 1;
  190. --      gui.text(220 - 6 * 6, 16, "XOR");
  191. --      -- print(string.format("%04X => %02X", bang1, bang2));
  192. --  end;
  193.     if keys['S'] then
  194.  
  195.         bang1   = math.random(0x6000, 0x7FFF)
  196.         bang2   = math.random(0, 0xFF);
  197.         memory.writebyte(bang1, bang2);
  198.         funtimes    = funtimes + 1;
  199.         reset       = 1;
  200.         gui.text(220 + 6 * 3, 8, "SAV");
  201.  
  202.         -- print(string.format("%04X => %02X", bang1, bang2));
  203.     end;
  204.     if keys['G'] then
  205.  
  206.         crap    = true
  207.         while crap do
  208.             bang1   = math.random(0x0000, 0x07FF)
  209.             if not (bang1 >= 0x100 and bang1 <= 0x1ff) then
  210.                 crap = false;
  211.             end
  212.         end;
  213.         bang2   = memory.readbyte(bang1) * (math.random(0x0000,0x07FF));
  214.         memory.writebyte(bang1, bang2);
  215.         funtimes    = funtimes + 1;
  216.         reset       = 1;
  217.         gui.text(220, 24, "MUL");
  218.         -- print(string.format("%04X => %02X", bang1, bang2));
  219.     end;
  220.         if keys['H'] then
  221.  
  222.         crap    = true
  223.         while crap do
  224.             bang1   = math.random(0x0000, 0x07FF)
  225.             if not (bang1 >= 0x100 and bang1 <= 0x1ff) then
  226.                 crap = false;
  227.             end
  228.         end;
  229.         bang2   = memory.readbyte(bang1) / (math.random(0x0001,0x07FF));
  230.         memory.writebyte(bang1, bang2);
  231.         funtimes    = funtimes + 1;
  232.         reset       = 1;
  233.         gui.text(220 + 6 * 3, 24, "DIV");
  234.         -- print(string.format("%04X => %02X", bang1, bang2));
  235.     end;
  236.     if keys['V'] then
  237.         loop    = 0;
  238.         while loop <= 16 do
  239.             crap    = true
  240.             while crap do
  241.                 bang1   = math.random(0x0000, 0x07FF)
  242.                 if not (bang1 >= 0x100 and bang1 <= 0x1ff) then
  243.                     crap = false;
  244.                 end
  245.             end;
  246.             bang2   = memory.readbyte(bang1) * (math.random(0x0000,0x07FF));
  247.                 memory.writebyte(bang1, bang2);
  248.             funtimes    = funtimes + 1;
  249.         -- print(string.format("%04X => %02X", bang1, bang2))
  250.             loop    = loop + 1;
  251.             end;
  252.         reset       = 1;
  253.         gui.text(220 - 6 * 3, 8, "16M");
  254.     end;
  255.     if keys['B'] then
  256.         rloop   = 0;
  257.         while rloop <= 32 do
  258.             crap    = true
  259.             while crap do
  260.                 bang1   = math.random(0x0000, 0x07FF);
  261.                 if not (bang1 >= 0x100 and bang1 <= 0x1ff) then
  262.                     crap = false;
  263.                 end
  264.             end;
  265.             bang2   = (math.random(0x0000,0x07FF)) * (math.random(0x0001,0x07FF));
  266.                 memory.writebyte(bang1, bang2);
  267.             funtimes    = funtimes + 1;
  268.         -- print(string.format("%04X => %02X", bang1, bang2))
  269.             rloop   = rloop + 1;
  270.             end;
  271.         reset       = 1;
  272.         gui.text(220 - 6 * 3, 16, "32R");
  273.     end;
  274.  
  275.     if keys['N'] then
  276.         nloop   = 0;
  277.         while nloop <= 65536 do
  278.             crap    = true
  279.             while crap do
  280.                 bang1   = math.random(0x0000, 0x07FF);
  281.                 if not (bang1 >= 0x100 and bang1 <= 0x1ff) then
  282.                     crap = false;
  283.                 end
  284.             end;
  285.             bang2   = (math.random(0x0001,0x07FF)) * (math.random(0x0001,0x07FF));
  286.                 memory.writebyte(bang1, bang2);
  287.             funtimes    = funtimes + 1;
  288. --      -- print(string.format("%04X => %02X", bang1, bang2))
  289.             nloop   = nloop + 1;
  290.             end;
  291.         reset       = 1;
  292.         gui.text(220 - 6 * 6, 24, "65536R");
  293.     end;
  294.  
  295.  
  296. --    if keys['T'] then
  297.  
  298. --          for i = 0, 0xF do
  299. --          bang1    = randmemory(0x0000, 0x07FF);
  300. --              if not (bang1 >= 0x100 and bang1 <= 0x1ff) then
  301. --                  crap = false;
  302. --              end
  303. --              frozen[bang1] = memory.readbyte(bang1);
  304. --              funtimes    = funtimes + 1;
  305. --              -- print(string.format("%04X => %02X", bang1, bang2));
  306. --          end;
  307. --          gui.text(0 + 6 * 2 - 2,16, "Freeze");
  308. --          reset       = 1;
  309. --      end;
  310.        
  311. --  if keys['Y'] then
  312. --      gui.text(0,16, "Unfreeze")
  313. --       frozen = {}
  314. --  end;
  315.    
  316. --  if keys['M'] then
  317. --      gui.text(0, 24, "BYE");
  318. --      bang1   = math.random(0x0000, 0x07FF) /0
  319. --      bang2   = memory.readbyte(bang1);
  320. --      memory.writebyte(bang1, bang2);
  321. --
  322. --      end of key press
  323. --  end;
  324.  
  325.     if reset == 1 then
  326.         txttime = 0;
  327.     end;
  328.     if txttime < 20 then
  329.         gui.text(0, 8, string.format("%6d", funtimes));
  330.     end;
  331.  
  332.     txttime = txttime + 1;
  333.    
  334.     if keys['M'] then
  335.         funtimes = 0;
  336.         gui.text(0, 8, "RESET TIME");
  337.     end;
  338.     FCEU.frameadvance();
  339. end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement