Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- NES Braidulator VERSION 1
- --(C) Antony Lavelle 2009 got_wot@hotmail.com http://www.the-exp.net
- -- A Lua script that allows 'Braid' style time reversal for Nes games being run in FCEUX
- --'Braid' is copyright Jonathan Blow, who is not affiliated with this script, but you should all buy his game because it's ace.
- --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 :)
- --Change these settings to adjust options
- --Which key you would like to function as the "rewind key"
- local rewindKey = 'W'
- --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)
- --Do not set to 0!
- local saveMax = 2500;
- funtimes = 0;
- txttime = 0;
- --The stuff below is for more advanced users, enter at your own peril!
- local saveArray = {};--the Array in which the save states are stored
- local saveCount = 1;--used for finding which array position to cycle through
- local save; -- the variable used for storing the save state
- local rewindCount = 0;--this stops you looping back around the array if theres nothing at the end
- local savePreventBuffer = 1;--Used for more control over when save states will be saved, not really used in this version much.
- timer = 0;
- saveinterval = 1;
- while (true) do
- timer = timer + 1;
- -- frozen = {}
- gui.pixel(0, 0, "clear");
- savePreventBuffer = savePreventBuffer-1;
- if savePreventBuffer==0 then
- savePreventBuffer = 1;
- end;
- joyput = input.get();
- if joyput[rewindKey] then
- frozen = {} -- unfreezes
- savePreventBuffer = 5;
- if rewindCount==0 then
- gui.text(0, 8, "NO REWIND POWER LEFT");
- --makes sure you can't go back too far could also include other things in here, left empty for now.
- else
- savestate.load(saveArray[saveCount]);
- saveCount = saveCount-1;
- rewindCount = rewindCount-1;
- if saveCount==0 then
- saveCount = saveMax-1;
- end;
- end;
- local HUDMATH = rewindCount / saveMax;--Making the rewind time a percentage.
- gui.text(220,24, string.format("%.2f%%", HUDMATH * 100));--Displaying the time onscreen.
- if HUDMATH > 0.25 or math.fmod(timer, 20) < 10 then
- rwy = 16;
- for rwarrow = -1, 7 do
- gui.line(220 + rwarrow, rwy - 1 - math.floor(rwarrow / 2), 220 + rwarrow, rwy + 1 + math.floor(rwarrow / 2), "black");
- gui.line(221 + rwarrow, rwy - 1 - math.floor(rwarrow / 2), 221 + rwarrow, rwy + 1 + math.floor(rwarrow / 2), "black");
- gui.line(229 + rwarrow, rwy - 1 - math.floor(rwarrow / 2), 229 + rwarrow, rwy + 1 + math.floor(rwarrow / 2), "black");
- gui.line(230 + rwarrow, rwy - 1 - math.floor(rwarrow / 2), 230 + rwarrow, rwy + 1 + math.floor(rwarrow / 2), "black");
- end;
- for rwarrow = 0, 7 do
- c1 = "white";
- if (rwarrow / 7) >= (HUDMATH / 0.9) then
- c1 = "red";
- end;
- c2 = "white";
- if (rwarrow / 7) > (HUDMATH - .90) * 10 then
- c2 = "red";
- end;
- gui.line(220 + rwarrow, rwy - math.floor(rwarrow / 2), 220 + rwarrow, rwy + math.floor(rwarrow / 2), c1);
- gui.line(229 + rwarrow, rwy - math.floor(rwarrow / 2), 229 + rwarrow, rwy + math.floor(rwarrow / 2), c2);
- end;
- -- gui.text(220, 8, "<<");
- end;
- end;
- if math.fmod(timer, saveinterval) == 0 and savePreventBuffer==1 then
- saveCount=saveCount+1;
- if saveCount==saveMax then
- saveCount = 1;
- end
- rewindCount = rewindCount+1;
- if rewindCount==saveMax-1 then
- rewindCount = saveMax-2;
- end;
- save = savestate.create();
- savestate.save(save);
- saveArray[saveCount] = save;
- end;
- keys = input.get();
- reset = 0;
- if keys['A'] then
- crap = true
- while crap do
- bang1 = math.random(0x0000, 0x07FF)
- if not (bang1 >= 0x100 and bang1 <= 0x1ff) then
- crap = false;
- end
- end;
- bang2 = math.random(0, 0xFF);
- memory.writebyte(bang1, bang2);
- funtimes = funtimes + 1;
- reset = 1;
- gui.text(220, 8, "RAM");
- -- print(string.format("%04X => %02X", bang1, bang2));
- end;
- if keys['D'] then
- crap = true
- while crap do
- bang1 = math.random(0x0000, 0x07FF)
- if not (bang1 >= 0x100 and bang1 <= 0x1ff) then
- crap = false;
- end
- end;
- bang2 = memory.readbyte(bang1) + (math.random(0, 1) * 2 - 1);
- memory.writebyte(bang1, bang2);
- funtimes = funtimes + 1;
- reset = 1;
- gui.text(220, 16, "INC");
- -- print(string.format("%04X => %02X", bang1, bang2));
- end;
- if keys['F'] then
- crap = true
- while crap do
- bang1 = math.random(0x0000, 0x07FF)
- if not (bang1 >= 0x100 and bang1 <= 0x1ff) then
- crap = false;
- end
- end;
- bang2 = memory.readbyte(bang1) - (math.random(0, 1) * 2 - 1);
- memory.writebyte(bang1, bang2);
- funtimes = funtimes + 1;
- reset = 1;
- gui.text(220 + 6 * 3, 16, "DEC");
- -- print(string.format("%04X => %02X", bang1, bang2));
- end;
- if keys['E'] then
- crap = true
- while crap do
- bang1 = math.random(0x0000, 0x07FF)
- if not (bang1 >= 0x100 and bang1 <= 0x1ff) then
- crap = false;
- end
- end;
- bang2 = memory.readbyte(bang1) / 0;
- memory.writebyte(bang1, bang2);
- funtimes = funtimes + 1;
- reset = 1;
- gui.text(220 - 6 * 6, 8, "NUL");
- -- print(string.format("%04X => %02X", bang1, bang2));
- end;
- -- if keys['T'] then
- --
- -- crap = true
- -- while crap do
- -- bang1 = math.random(0x0000, 0x07FF)
- -- if not (bang1 >= 0x100 and bang1 <= 0x1ff) then
- -- crap = false;
- -- end
- -- end;
- -- bang2 = (memory.readbyte(bang1));
- -- int = XOR(int(bang2));
- -- memory.writebyte(bang1, bang2);
- -- funtimes = funtimes + 1;
- -- reset = 1;
- -- gui.text(220 - 6 * 6, 16, "XOR");
- -- -- print(string.format("%04X => %02X", bang1, bang2));
- -- end;
- if keys['S'] then
- bang1 = math.random(0x6000, 0x7FFF)
- bang2 = math.random(0, 0xFF);
- memory.writebyte(bang1, bang2);
- funtimes = funtimes + 1;
- reset = 1;
- gui.text(220 + 6 * 3, 8, "SAV");
- -- print(string.format("%04X => %02X", bang1, bang2));
- end;
- if keys['G'] then
- crap = true
- while crap do
- bang1 = math.random(0x0000, 0x07FF)
- if not (bang1 >= 0x100 and bang1 <= 0x1ff) then
- crap = false;
- end
- end;
- bang2 = memory.readbyte(bang1) * (math.random(0x0000,0x07FF));
- memory.writebyte(bang1, bang2);
- funtimes = funtimes + 1;
- reset = 1;
- gui.text(220, 24, "MUL");
- -- print(string.format("%04X => %02X", bang1, bang2));
- end;
- if keys['H'] then
- crap = true
- while crap do
- bang1 = math.random(0x0000, 0x07FF)
- if not (bang1 >= 0x100 and bang1 <= 0x1ff) then
- crap = false;
- end
- end;
- bang2 = memory.readbyte(bang1) / (math.random(0x0001,0x07FF));
- memory.writebyte(bang1, bang2);
- funtimes = funtimes + 1;
- reset = 1;
- gui.text(220 + 6 * 3, 24, "DIV");
- -- print(string.format("%04X => %02X", bang1, bang2));
- end;
- if keys['V'] then
- loop = 0;
- while loop <= 16 do
- crap = true
- while crap do
- bang1 = math.random(0x0000, 0x07FF)
- if not (bang1 >= 0x100 and bang1 <= 0x1ff) then
- crap = false;
- end
- end;
- bang2 = memory.readbyte(bang1) * (math.random(0x0000,0x07FF));
- memory.writebyte(bang1, bang2);
- funtimes = funtimes + 1;
- -- print(string.format("%04X => %02X", bang1, bang2))
- loop = loop + 1;
- end;
- reset = 1;
- gui.text(220 - 6 * 3, 8, "16M");
- end;
- if keys['B'] then
- rloop = 0;
- while rloop <= 32 do
- crap = true
- while crap do
- bang1 = math.random(0x0000, 0x07FF);
- if not (bang1 >= 0x100 and bang1 <= 0x1ff) then
- crap = false;
- end
- end;
- bang2 = (math.random(0x0000,0x07FF)) * (math.random(0x0001,0x07FF));
- memory.writebyte(bang1, bang2);
- funtimes = funtimes + 1;
- -- print(string.format("%04X => %02X", bang1, bang2))
- rloop = rloop + 1;
- end;
- reset = 1;
- gui.text(220 - 6 * 3, 16, "32R");
- end;
- if keys['N'] then
- nloop = 0;
- while nloop <= 65536 do
- crap = true
- while crap do
- bang1 = math.random(0x0000, 0x07FF);
- if not (bang1 >= 0x100 and bang1 <= 0x1ff) then
- crap = false;
- end
- end;
- bang2 = (math.random(0x0001,0x07FF)) * (math.random(0x0001,0x07FF));
- memory.writebyte(bang1, bang2);
- funtimes = funtimes + 1;
- -- -- print(string.format("%04X => %02X", bang1, bang2))
- nloop = nloop + 1;
- end;
- reset = 1;
- gui.text(220 - 6 * 6, 24, "65536R");
- end;
- -- if keys['T'] then
- -- for i = 0, 0xF do
- -- bang1 = randmemory(0x0000, 0x07FF);
- -- if not (bang1 >= 0x100 and bang1 <= 0x1ff) then
- -- crap = false;
- -- end
- -- frozen[bang1] = memory.readbyte(bang1);
- -- funtimes = funtimes + 1;
- -- -- print(string.format("%04X => %02X", bang1, bang2));
- -- end;
- -- gui.text(0 + 6 * 2 - 2,16, "Freeze");
- -- reset = 1;
- -- end;
- -- if keys['Y'] then
- -- gui.text(0,16, "Unfreeze")
- -- frozen = {}
- -- end;
- -- if keys['M'] then
- -- gui.text(0, 24, "BYE");
- -- bang1 = math.random(0x0000, 0x07FF) /0
- -- bang2 = memory.readbyte(bang1);
- -- memory.writebyte(bang1, bang2);
- --
- -- end of key press
- -- end;
- if reset == 1 then
- txttime = 0;
- end;
- if txttime < 20 then
- gui.text(0, 8, string.format("%6d", funtimes));
- end;
- txttime = txttime + 1;
- if keys['M'] then
- funtimes = 0;
- gui.text(0, 8, "RESET TIME");
- end;
- FCEU.frameadvance();
- end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement