Advertisement
Guest User

wario.lua

a guest
Jul 21st, 2017
9
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 23.66 KB | None | 0 0
  1. --
  2. -- ░█▀▄░█▀█░█▀█░█▄█░░░░█░░░█░█░█▀█
  3. -- ░█▀▄░█░█░█░█░█░█░░░░█░░░█░█░█▀█
  4. -- ░▀▀░░▀▀▀░▀▀▀░▀░▀░▀░░▀▀▀░▀▀▀░▀░▀
  5. --
  6. --
  7. -- Fair warning: this code is about as bad as the things it does to games.
  8.  
  9. --Original NES Braidulator by Antony Lavelle 2009 got_wot@hotmail.com http://www.the-exp.net
  10.  
  11. --Change these settings to adjust options
  12.  
  13. --Which key you would like to function as the "rewind key"
  14.  
  15.     local rewindKey = 'W' -- Hold this to go back in time!
  16.  
  17. -- Keys. Feel free to change them to something convenient, because I have a weird keyboard layout
  18.  
  19.     randomkey       = "A"   -- Just your standard fare. One random WRAM byte.
  20.     plusminuskey    = "S"   -- +/- on one random WRAM byte. Probably the safest you can do which still has some effect.
  21.     powerkey        = "D"   -- Power corruption! 16 random bytes. The most fun key you can press.
  22.     highkey         = "F"   -- Level corruption.
  23.     vramkey         = "G"   -- Messes up vram (graphics). Purely visual - totally safe.
  24.  
  25.     freezekey       = "H" -- Freezes a random byte in memory indefinedly. May have totally different effects from regular corruption.
  26.     unfreezekey     = "J" -- Unfreezes every frozen byte. This also happens automatically when rewinding.
  27.      
  28.     savetileskey    = "K" -- Save current tiles.
  29.     restoretileskey = "L" -- Restore saved tiles. Purely visual, can be used to copy tiles from game to game etc.
  30.     savelevelkey    = "I" -- Save the level blockdata
  31.     restorelevelkey = "O" -- Restore the level blockdata
  32.     wrammap         = "Q" -- Display an interactive memory map, one pixel per byte.
  33.                           -- Opacity = value. Blue = byte changed this frame. Green = HRAM.
  34.                           -- Left: +1 Right: -1 Middle: set to $FF
  35.     selectkey       = "T" -- Level Select
  36.     freeroamkey     = "Y" -- Free roaming mode
  37.     writetileskey   = "U" -- Test tileset
  38.     nowaterkey      = "V" -- Remove water
  39.     rewindon        = "E"  -- Switches rewinding on and off. May save some 15%, depending on your computer.
  40.     debugkey        = "\\" -- Displays some boring CPU info.
  41.  
  42.  
  43.  
  44.     --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)
  45.     --Do not set to 0!
  46.     local saveMax = 2000;
  47.    
  48.     --The stuff below is for more advanced users, enter at your own peril!
  49.  
  50.     funtimes    = 0;
  51.     txttime     = 0;
  52.    
  53.     -- Memory Addresses
  54.    
  55.     mode_Demo       = 0xA8C6
  56.     mode_Debug      = 0xA8C7
  57.     mode_Game       = 0xA8C3
  58.     mode_Game2      = 0xA8C4
  59.     pause_Player    = 0xA908
  60.     pause_Enemy     = 0xA9A8
  61.    
  62.     player_X        = 0xA913 -- Word
  63.     player_Y        = 0xA911 -- Word
  64.     player_Action   = 0xA91A
  65.     camera_X        = 0xA902 -- Word
  66.     camera_Y        = 0xA900 -- Word
  67.     camera_Mode     = 0xA99D
  68.    
  69.     level_Id        = 0xA804
  70.     status_Hearts   = 0xA808
  71.     status_Lives    = 0xA809
  72.     status_Time     = 0xA964 -- Word, reverse bytes
  73.     player_Status   = 0xA80A
  74.    
  75.     blockdata_Start = 0xAD00
  76.     blockdata_Size  = 0x0200
  77.     leveldata_Start = 0xC000
  78.     leveldata_Size  = 0x2000
  79.    
  80.  
  81.     -- Values for Memory addresses (probably uses bits but whatever)
  82.     camera_Mode_Normal  = 0x00
  83.     camera_Mode_Train   = 0x01
  84.     camera_Mode_Free    = 0x10
  85.     camera_Mode_AutoR   = 0x30
  86.     camera_Mode_AutoL   = 0x31
  87.    
  88.     player_Action_Normal    = 0x00
  89.     player_Action_Walking   = 0x01
  90.     player_Action_Crouching = 0x02
  91.     player_Action_Climbing  = 0x03
  92.     player_Action_Swimming  = 0x04
  93.     player_Action_Air       = 0x05
  94.     player_Action_Unknown   = 0x06
  95.     player_Action_Damage    = 0x07
  96.     player_Action_Jump      = 0x08
  97.     player_Action_Death     = 0x09
  98.     player_Action_Ceiling   = 0x0A
  99.     player_Action_Dash      = 0x0B
  100.     player_Action_Hop       = 0x0C
  101.     player_Action_Dashjump  = 0x0D
  102.     player_Action_Fly       = 0x0E
  103.     player_Action_Death2    = 0x10 -- descend
  104.     player_Action_Quicksand = 0x11
  105.    
  106.     -- These also depend on mode_Game2. They are all guaranteed to work in a level (03)
  107.     mode_Game_LevelSelect   = 0x01
  108.     mode_Game_LevelStart    = 0x02
  109.     mode_Game_LevelMain     = 0x03
  110.     mode_Game_LevelClear    = 0x04
  111.     mode_Game_LevelExit     = 0x05
  112.     mode_Game_LevelClear2   = 0x06
  113.     mode_Game_TimeUp        = 0x07
  114.     mode_Game_GameOver      = 0x08
  115.     mode_Game_Ending        = 0x09 -- Uses other flags
  116.     mode_Game_LastDoor      = 0x09 -- Crashes if no valid door ID in RAM
  117.     mode_Game_TreasureGet   = 0x0B -- Will crash the game if called directly
  118.     mode_Game_LevelExit2    = 0x0C
  119.    
  120.    
  121.    
  122.    
  123.     -- Initialize other variables
  124.     player_Underwater = 0
  125.     player_Action_Previous  = player_Action_Normal
  126.     tmp_Action              = player_Action_Normal
  127.     tmp_freeroam    = false
  128.     dumbflag        = false
  129.     asdfg = 0
  130.     asdfg_corrupted = 0
  131.    
  132.     -- level blocks definitions
  133.     block_doors = {[0x48] = true, [0x4B] = true, [0x54] = true, [0x2E] = true}
  134.     block_death = {[0x3F] = true, [0x59] = true, [0x5A] = true, [0x5C] = true, [0x5D] = true, [0x5E] = true, [0x5F] = true}
  135.    
  136.     -- extra bg: 0x60,0x61,0x76,0x7B
  137.     -- Replacements for water (and lava) blocks
  138.     block_water     = {0x4A,0x4B,0x4C,0x4D,0x4E,0x4F,0x50,0x51,0x52,0x53,0x54,0x55,0x56,0x57,0x58,0x59,0x5A,0x5B,0x5C} -- last lava
  139.     block_nowater   = {0x49,0x48,0x7F,0x7F,0x7F,0x7F,0x2B,0x2C,0x2D,0x47,0x2E,0x7E,0x7E,0x7E,0x7E,0x5D,0x5D,0x7D,0x7F} -- 5A to 5D is temp
  140.    
  141.  
  142.     function rainbowcolor(ri)
  143.         freq = 0.15
  144.         r = math.sin(freq*ri)   * 127 + 128
  145.         g = math.sin(freq*ri+2) * 127 + 128
  146.         b = math.sin(freq*ri+4) * 127 + 128
  147.         return {r, g, b}
  148.     end
  149.      
  150.     function randmemory(from, to) -- gets a random memory offset, avoiding the stack
  151.         if gb then
  152.             while (true) do
  153.                 bang = math.random(from, to)
  154.                 if bang < sp or bang > stack then
  155.                 break
  156.             end
  157.         end
  158.         return bang
  159.     else
  160.         return math.random(from, to)
  161.         end
  162.     end
  163.    
  164.      
  165.     frozen      = {}
  166.     crashi      = 0
  167.      
  168.     --vram      = {}
  169.     wram        = {}
  170.     prevwram    = {}
  171.     s = {0xff, 0xff, 0x00, 0x00, 0xbb, 0xbb, 0x8b, 0x8b, 0x68, 0x68, 0x8b, 0x8b, 0xeb, 0xeb, 0x18, 0x18}
  172.      
  173.     stack = -1
  174.      
  175.     -- dumb format for speed/convenience
  176.     invalid_opcodes = {[0xd3]= true, [0xdb]= true, [0xdd]= true, [0xe3]= true, [0xe4]= true, [0xeb]= true, [0xec]= true, [0xed]= true, [0xfd]= true, [0xf4]= true}
  177.      
  178.     local saveArray         = {};   --the Array in which the save states are stored
  179.     local saveCount         = 1;    --used for finding which array position to cycle through
  180.     local save;                     -- the variable used for storing the save state
  181.     local rewindCount       = 0;    --this stops you looping back around the array if theres nothing at the end
  182.     local savePreventBuffer = 1;    --Used for more control over when save states will be saved, not really used in this version much.
  183.      
  184.     local saveFrequency     = 10;   -- look at me mom, I'm editing LIVE!
  185.     local timer             = -1;
  186.      
  187.     local rewind            = true
  188.    
  189.     print("Boom-W loaded!")
  190.  
  191.     while (true) do
  192.        
  193.         keys                = input.get();
  194.         joy                 = joypad.get(0);
  195.         timer               = timer + 1;
  196.         savePreventBuffer   = savePreventBuffer-1;
  197.         if savePreventBuffer==0 then
  198.             savePreventBuffer = 1;
  199.         end;
  200.        
  201.         -- WARIO LAND SPECIFIC
  202.        
  203.         -- Set these right away
  204.        
  205.         memory.writebyte(mode_Debug, 0x01);                 -- Debug Mode
  206.         memory.writeword(status_Time, 0x0004)               -- Infinite time (byte order: right, left)
  207.         memory.writebyte(status_Lives, 0x99)                -- Infinite lives
  208.        
  209.         -- Get current variables
  210.        
  211.         player_Action_Current   = memory.readbyte(player_Action)
  212.         player_X_Current        = memory.readword(player_X)
  213.         player_Y_Current        = memory.readword(player_Y)
  214.        
  215.         pause_Player_Current    = memory.readbyte(pause_Player)
  216.         pause_Enemy_Current     = memory.readbyte(pause_Enemy)
  217.         camera_Mode_Current     = memory.readbyte(camera_Mode)
  218.        
  219.         levelid     = memory.readbyte(level_Id)
  220.        
  221.         gamemode    = memory.readbyte(mode_Game)
  222.         gamemode2   = memory.readbyte(mode_Game2)      
  223.        
  224.         paused      = pause_Player_Current and pause_Enemy_Current
  225.        
  226.         --print (pause_Player_Current)
  227.        
  228.        
  229.         player_Dead = (player_Action_Current == player_Action_Death or player_Action_Current == player_Action_Death2)
  230.        
  231.        
  232.         --[[
  233.         --Hide WINDOW at the start of the level
  234.        
  235.         --if gamemode == mode_Game_LevelInit then
  236.             --memory.writebyte(0x0000FF4A, 0x98) -- Window Y
  237.         --end
  238.         ]]--
  239.  
  240.        
  241.         --[[ Welp
  242.         gui.text(1,8*0,string.format("A %02X",memory.getregister("a")), white, black)
  243.         gui.text(1,8*1,string.format("F %02X",memory.getregister("f")), white, black)
  244.         gui.text(1,8*2,string.format("B %02X",memory.getregister("b")), white, black)
  245.         gui.text(1,8*3,string.format("C %02X",memory.getregister("c")), white, black)
  246.         gui.text(1,8*4,string.format("D %02X",memory.getregister("d")), white, black)
  247.         gui.text(1,8*5,string.format("E %02X",memory.getregister("e")), white, black)
  248.         gui.text(1,8*6,string.format("H %02X",memory.getregister("h")), white, black)
  249.         gui.text(1,8*7,string.format("L %02X",memory.getregister("l")), white, black)
  250.         gui.text(1,8*8,string.format("SP %04X",memory.getregister("SP")), white, black)
  251.         gui.text(1,8*9,string.format("PC %04X",memory.getregister("PC")), white, black)
  252.        
  253.         end]]--
  254.        
  255.         --[[
  256.             Detect if we're underwater or not.
  257.             The game sets action 04 if you're underwater. You're marked as out of the water only if the value is then set 05 and vice versa.
  258.         ]]--
  259.         if player_Action_Current == player_Action_Swimming then
  260.             player_Underwater   = 1
  261.             tmp_Action          = player_Action_Swimming        -- To restore proper action if we're underwater or not
  262.         elseif player_Action_Current == player_Action_Air then
  263.             player_Underwater   = 0
  264.             tmp_Action          = player_Action_Jump
  265.         end
  266.  
  267.  
  268.        
  269.         -- Ignore if the game isn't paused (so you can go down in debug mode)
  270.         if pause_Player_Current == 0 then
  271.             if player_Y_Current == 0xF501 or player_Y_Current == 0xF601 then -- Check for only this specific Y coordinate so you can force yourself down further with debug mode
  272.                 memory.writeword(player_Y, 0xF001) -- 1 pixel higher
  273.                 memory.writebyte(player_Action, tmp_Action)
  274.             elseif player_Dead then
  275.                 memory.writebyte(player_Action, player_Action_Normal); -- Prevent death once unpaused if you're down that coordinate
  276.             end
  277.         end
  278.        
  279.         -- All of this block is a TEMP
  280.         -- As ideally you'd have a menu selection for this (or not)
  281.         if gamemode == mode_Game_LevelMain then
  282.             dumbflag = true
  283.             -- Jump to level select if you're in a level
  284.             -- The game is nice enough to set everything up for it
  285.             if keys[selectkey] then
  286.                 memory.writebyte(mode_Game, mode_Game_LevelSelect)
  287.             end
  288.            
  289.            
  290.             if keys[writetileskey] then
  291.                 --preliminary block writing in memory
  292.                 gui.text(1,0, "WAIT!")
  293.                
  294.                 blockCUR    = 0x00;
  295.                
  296.                 -- Empty block for two rows
  297.                 for layoutRAM = 0xC000, 0xC200 do
  298.                     memory.writebyte(layoutRAM, 0x7F);
  299.                 end
  300.                
  301.                 -- Write all blocks in the tileset sequentially
  302.                 layoutRAM = 0xC200;
  303.                 for blockCUR = 0x00, 0x80 do
  304.                     memory.writebyte(layoutRAM,blockCUR);
  305.                     layoutRAM = layoutRAM + 0x01;
  306.                 end
  307.                
  308.                 -- Write two rows and a half of empty blocks
  309.                 for layoutRAM = 0xC280, 0xC500 do
  310.                     memory.writebyte(layoutRAM, 0x7F);
  311.                 end
  312.                 -- Row of solid blocks
  313.                 for layoutRAM = 0xC500, 0xC600 do
  314.                     memory.writebyte(layoutRAM, 0x00);
  315.                 end
  316.                
  317.                 for layoutRAM = 0xC600, 0xC800 do
  318.                     memory.writebyte(layoutRAM, 0x7F);
  319.                 end
  320.                
  321.                 layoutRAM = 0xC800;
  322.                 for blockCUR = 0x00, 0x80 do
  323.                     memory.writebyte(layoutRAM,blockCUR);
  324.                     layoutRAM = layoutRAM + 0x01;
  325.                 end
  326.                
  327.                 for layoutRAM = 0xC880, 0xC900 do
  328.                     memory.writebyte(layoutRAM, 0x7F);
  329.                 end
  330.                
  331.                 for layoutRAM = 0xC900, 0xCA00 do
  332.                     memory.writebyte(layoutRAM, 0x00);
  333.                 end
  334.                
  335.                 -- Set player and camera at the top of the level
  336.                 memory.writeword(camera_X, 0x4000)
  337.                 memory.writeword(camera_Y, 0x4000)
  338.                 memory.writeword(player_X, 0x4000)
  339.                 memory.writeword(player_Y, 0x4000)
  340.                
  341.             end
  342.            
  343.             -- Display
  344.            
  345.             --[[ Used to fill the rest of the window
  346.             if paused == 1 then
  347.                 pausefill = 8
  348.             else
  349.                 pausefill = 0
  350.             end
  351.            
  352.             gui.box(0, 136, 159, 143, "red", "green")]]--
  353.            
  354.             -- UH OH
  355.             x1 = memory.readbyte(player_X)
  356.             x2 = memory.readbyte(player_X+1)
  357.             y1 = memory.readbyte(player_Y)
  358.             y2 = memory.readbyte(player_Y+1)
  359.  
  360.             if camera_Mode_Current == camera_Mode_Normal then
  361.                 scroll = "SEGSCRL"
  362.             elseif camera_Mode_Current == camera_Mode_Train then
  363.                 scroll = "TRAIN"
  364.             elseif camera_Mode_Current == camera_Mode_Free then
  365.                 scroll = "FREE"
  366.             elseif camera_Mode_Current == camera_Mode_AutoL then
  367.                 scroll = "AUTO L"
  368.             elseif camera_Mode_Current == camera_Mode_AutoR then
  369.                 scroll = "AUTO R"
  370.             else
  371.                 scroll = "UNKNOWN"
  372.             end
  373.            
  374.            
  375.             gui.text(0, 137, string.format("ID %02X - X %02X%02X - Y %02X%02X - %s", levelid, x1,x2,y1,y2, scroll), "black", "white")
  376.            
  377.             if paused == 1 then
  378.                 gui.text(136, 137, "PAUSED", "black", "white")
  379.             end
  380.             gui.text(1, 0, string.format("Level blocks corrupted: %d", asdfg_corrupted), "black", "white");
  381.             if keys[freeroamkey] then
  382.                 tmp_freeroam = true
  383.                 gui.text(1,137, "FREE ROAMING SET!")
  384.             end
  385.         end
  386.        
  387.         -- lols
  388.         if tmp_freeroam then
  389.             --memory.writebyte(camera_Mode, camera_Mode_AutoR);
  390.             memory.writebyte(camera_Mode, camera_Mode_Free);
  391.             --tmp_freeroam = false
  392.         end
  393.  
  394.         -- Rest of the original boom-plus code here
  395.            
  396.         --keys = input.get();
  397.         if keys[rewindKey] then
  398.             savePreventBuffer = 5;
  399.  
  400.  
  401.             if rewindCount == 0 then
  402.                 --makes sure you can't go back too far could also include other things in here, left empty for now.
  403.             else
  404.                 savestate.load(saveArray[saveCount]);
  405.                 saveCount       = saveCount-1;
  406.                 rewindCount     = rewindCount-1;
  407.                 if saveCount == 0 then
  408.                     saveCount   = saveMax-1;
  409.                 end;
  410.             end;
  411.             local HUDMATH = rewindCount / saveMax; -- Making the rewind time a percentage.
  412.             gui.text(1,0, string.format("%.2f%%", HUDMATH * 100)); -- Displaying the time onscreen.
  413.             if math.fmod(timer, 30) <= 15 then
  414.                 gui.text(138,8*2, "<<"); -- picky, picky
  415.             end;
  416.         end;
  417.        
  418.         if rewind and savePreventBuffer==1 and math.fmod(timer, saveFrequency) == 0 then
  419.             -- gui.text(80,15,"");
  420.             saveCount = saveCount + 1;
  421.             if saveCount == saveMax then
  422.                 saveCount = 1;
  423.             end
  424.             rewindCount = rewindCount+1;
  425.             if rewindCount == saveMax-1 then
  426.                 rewindCount = saveMax-2;
  427.             end;
  428.            
  429.             --save = savestate.create();
  430.             --savestate.save(save);
  431.             --saveArray[saveCount] = save;
  432.         end;
  433.        
  434.         pc          = memory.getregister('pc')
  435.         op          = memory.readbyte(pc)
  436.         is_invalid  = invalid_opcodes[op]
  437.         sp          = memory.getregister('sp')
  438.        
  439.         if crashi <= 1 then
  440.        
  441.             if stack == -1 and sp < 0xe000 and sp >= 0xc000 then
  442.                 stack = (math.ceil(sp / 0x10) * 0x10)-1
  443.                 print(string.format("sp=%04X, stack detected at %04X", sp, stack))
  444.                
  445.             elseif sp > 0xFF00 then
  446.                 --print("Stack detected in HRAM, restart?")
  447.                 stack = -1
  448.             end
  449.            
  450.         end
  451.        
  452.         if keys[debugkey] then
  453.             debugtext = string.format("pc=%04X sp=%04X", pc, sp)
  454.             gui.text(160-(string.len(debugtext)*4),0, debugtext, 'green');
  455.             debugtext = string.format("opcode %02X", op)
  456.             gui.text(160-(string.len(debugtext)*4),8, debugtext, 'green');
  457.         end
  458.        
  459.         if pc >= 0x8000 or sp < 0x8000 or is_invalid or pc == 0x39 then
  460.             crashi = crashi + 1
  461.             if crashi >= 2 then
  462.                 gui.text(1,8, crashi, 'red');
  463.                
  464.                 if crashi > 10 then
  465.                     info = "Crashed"
  466.                 else
  467.                     info = "Clinical death"
  468.                 end
  469.                
  470.                 crashtext = string.format(info.." pc=%04X sp=%04X", pc, sp)
  471.                 gui.text(160-(string.len(crashtext)*4),0, crashtext, 'red');
  472.                 crashtext = ""
  473.                
  474.                 if is_invalid then
  475.                     crashtext = string.format("Invalid opcode %02X", op)
  476.                 elseif pc == 0x39 then
  477.                     crashtext = string.format("Stuck in rst 38", op)
  478.                 end
  479.                 gui.text(160-(string.len(crashtext)*4),8, crashtext, 'red');
  480.             end
  481.         else
  482.             crashi = 0
  483.         end
  484.         -- print(string.format('%04X', memory.getregister('pc')))
  485.        
  486.         if (keys[nowaterkey] and gamemode == mode_Game_LevelMain) then
  487.             for i = leveldata_Start, leveldata_Start + leveldata_Size do
  488.                 val = memory.readbyte(i);
  489.                 -- Account for MSB
  490.                 if val > 0x7F then
  491.                     tmp_msb = 0x80
  492.                     val = val - tmp_msb
  493.                 else
  494.                     tmp_msb = 0x00
  495.                 end
  496.                
  497.                 for j,v in pairs(block_water) do
  498.                     if v == val then
  499.                         memory.writebyte(i, block_nowater[j] + tmp_msb)
  500.                         break
  501.                     end
  502.                 end
  503.                
  504.             end
  505.         end
  506.        
  507.         if keys[randomkey] then
  508.             gui.text(1,137, "Random bytes"); -- picky, picky
  509.             bang1 = randmemory(0x9800, 0xFEFF)
  510.             bang2 = math.random(0, 0xFF);
  511.             memory.writebyte(bang1, bang2);
  512.             --print(string.format("%04X => %02X", bang1, bang2));
  513.         end;
  514.        
  515.         if keys[plusminuskey] then
  516.             bang1 = randmemory(0x9800, 0xFEFF)
  517.             bang2 = AND(memory.readbyte(bang1) + math.random(-1, 1), 0xFF);
  518.             memory.writebyte(bang1, bang2);
  519.             gui.text(1,137, string.format("%04X +/- 1", bang1)); -- picky, picky
  520.             --print(string.format("%04X => %02X", bang1, bang2));
  521.         end;
  522.          
  523.         -- KABLOOEY
  524.         if keys[powerkey] then
  525.             gui.text(1,137, "Power corruption!", rainbowcolor(timer)); -- picky, picky
  526.             for i = 0, 0xF do
  527.                 bang1 = randmemory(0xA000, 0xFEFF)
  528.                 bang2 = math.random(0x00, 0xFF);
  529.                 memory.writebyte(bang1, bang2);
  530.                 --print(string.format("%04X => %02X", bang1, bang2));
  531.             end;
  532.         end;
  533.          
  534.         -- KABLOOEY
  535.         if keys[highkey] then
  536.             for i = 0, 0xF do
  537.                 gui.text(1,137, "Level map corruption!"); -- picky, picky
  538.                 bang1 = randmemory(leveldata_Start, leveldata_Start+leveldata_Size)
  539.                 -- door
  540.                 if memory.readbyte(bang1) == 0x48 then
  541.                     bang1 = bang1+0x01
  542.                 end
  543.                
  544.                 -- oh god
  545.                 bang2 = 0x2B; --0x7F --0x3F
  546.                 while (bang2 == 0x3F or bang2 == 0x59 or bang2 == 0x5A or bang2 == 0x5C or bang2 == 0x5D or bang2 == 0x5E or bang2 == 0x5F) do
  547.                     bang2 = math.random(0, 0x7F);
  548.                 end
  549.                
  550.                 memory.writebyte(bang1, bang2);
  551.                 asdfg_corrupted = asdfg_corrupted + 1
  552.             end;
  553.         elseif false and gamemode == mode_Game_LevelMain then
  554.             if asdfg == 15 then
  555.                 bang1 = randmemory(leveldata_Start, leveldata_Start+leveldata_Size)
  556.                 -- door
  557.                
  558.                 val = memory.readbyte(bang1)
  559.                 -- Don't check for values before the level data
  560.                 if (bang1 > leveldata_Start+0x0100) then
  561.                     val_up = memory.readbyte(bang1-0x0100)
  562.                 else
  563.                     val_up = 0x00
  564.                 end
  565.                 -- what is an array
  566.                 if (block_doors[val] or block_doors[val_up]) then
  567.                     bang1 = bang1+0x01
  568.                 end
  569.                
  570.                 -- oh god
  571.                 bang2 = 0x3F --0x47 --0x7F --0x3F
  572.                 while (block_death[bang2]) do
  573.                     bang2 = math.random(0, 0x7F);
  574.                 end
  575.  
  576.                
  577.                 memory.writebyte(bang1, bang2);
  578.                 asdfg = 0
  579.                 asdfg_corrupted = asdfg_corrupted + 1
  580.             else
  581.                 asdfg = asdfg + 1
  582.             end
  583.         end
  584.          
  585.         if keys[vramkey] then
  586.             rand = math.random(0, 16)
  587.             if rand >= 3 then
  588.                 gui.text(1,137, "Trashing VRAM");
  589.                 bang1 = math.random(0x8000, 0x9FFF)
  590.                 bang2 = math.random(0, 0xFF);
  591.                 memory.writebyte(bang1, bang2);
  592.             --elseif rand >= 3 then -- I hate you vba
  593.             -- gui.text(1,137, "Trashing palettes");
  594.             -- bang1 = math.random(0, 0xFF);
  595.             -- bang2 = math.random(0, 0xFF);
  596.             -- memory.writebyte(0xFF68, bang1);
  597.             -- memory.writebyte(0xFF69, bang2);
  598.             elseif rand >= 1 then
  599.                 gui.text(1,137, "Mixing up tiles");
  600.                 bang1 = math.random(0x8000, 0x9700)
  601.                 tile = memory.readbyterange(bang1, 0x10)
  602.                 bang2 = math.random(0x8000, 0x9700)
  603.                
  604.                 for i,byte in pairs(tile) do
  605.                     memory.writebyte(bang2+i, byte)
  606.                 end
  607.                
  608.                 memory.writebyte(bang1, bang2);
  609.             else
  610.                 gui.text(1,137, "Trashing OAM");
  611.                 bang1 = math.random(0xFE00, 0xFE90)
  612.                 bang2 = math.random(0, 0xFF);
  613.                 memory.writebyte(bang1, bang2);
  614.             end
  615.            
  616.            
  617.             rand2 = math.random(0, 10000)
  618.             if rand2 == 0 then
  619.                 bang = math.random(0x8000, 0x9700)
  620.                 bang = AND(bang, 0xfff0)
  621.                 for i,byte in pairs(s) do
  622.                     memory.writebyte(bang-1+i, byte)
  623.                 end
  624.                 gui.text(1,137, "4");
  625.             end;
  626.             --print(string.format("%04X => %02X", bang1, bang2));
  627.         end
  628.          
  629.         if keys[freezekey] then
  630.             gui.text(1,137, "Freeze"); -- picky, picky
  631.             for i = 0, 0xF do
  632.                 bang1 = randmemory(0xC000, 0xDFFF)
  633.                 --bang2 = math.random(0x00, 0xFF);
  634.                 frozen[bang1] = memory.readbyte(bang1);
  635.                 --print(string.format("%04X => %02X", bang1, bang2));
  636.             end;
  637.         end;
  638.        
  639.         if keys[unfreezekey] or keys[rewindKey] then
  640.             gui.text(1,137, "Unfreeze")
  641.             frozen = {}
  642.         end
  643.          
  644.         if keys[savetileskey] then
  645.             gui.text(1,137, "Saved tiles"); -- picky, picky
  646.             vram    = memory.readbyterange(0x8000, 0x1800)
  647.             blocks  = memory.readbyterange(blockdata_Start, blockdata_Size) -- Come on, you want to save the blockdata too :|
  648.         end
  649.        
  650.         if keys[restoretileskey] then
  651.             if vram then
  652.                 gui.text(1,137, "Restored tiles")
  653.                 for i,v in pairs(vram) do
  654.                     memory.writebyte(0x8000-1+i, v);
  655.                 end
  656.                 for i,v in pairs(blocks) do
  657.                     memory.writebyte(blockdata_Start-1+i, v);
  658.                 end
  659.             else
  660.                 gui.text(1,137, "Couldn't restore tiles")
  661.             end
  662.         end
  663.        
  664.         if keys[savelevelkey] then
  665.             gui.text(1,137, "Saved level"); -- picky, picky
  666.             level   = memory.readbyterange(leveldata_Start, leveldata_Size)
  667.         end
  668.         if keys[restorelevelkey] then
  669.             if level then
  670.                 gui.text(1,137, "Restored level")
  671.                 for i,v in pairs(level) do
  672.                     memory.writebyte(leveldata_Start-1+i, v);
  673.                 end
  674.             else
  675.                 gui.text(1,137, "Couldn't restore the level")
  676.             end
  677.         end
  678.          
  679.         if keys[rewindon] and not lastkeys[rewindon] then
  680.             rewind = not rewind
  681.         end
  682.        
  683.         if keys[rewindon] then
  684.             if rewind then
  685.                 text = "Rewind ON!"
  686.             else
  687.                 text = "Rewind OFF!"
  688.             end
  689.             gui.text(1,137, text)
  690.         end
  691.        
  692.         xmouse, ymouse, left, right, middle = keys['xmouse'], keys['ymouse'], keys['leftclick'], keys['rightclick'], keys['middleclick']
  693.                
  694.         if keys[wrammap] and not lastkeys[wrammap] then
  695.             showwram = not showwram;
  696.         end
  697.        
  698.         if showwram then
  699.             --gui.text(1,137, "Live WRAM")
  700.             wram = memory.readbyterange(0xC000, 0x2000)
  701.             for k,v in pairs(memory.readbyterange(0xFF00, 0xFF)) do
  702.                 wram[0x2000+k] = v
  703.             end
  704.            
  705.             width = 64
  706.  
  707.             for i,v in pairs(wram) do
  708.                 --memory.writebyte(0x8000-1+i, v);
  709.                 if prevwram[i] ~= wram[i] then
  710.                     color = {0, 0, 255, v}
  711.                 elseif frozen[0xC000+i-1] then
  712.                     color = {0, 255, 255, v}
  713.                 elseif i > 0x2000 then
  714.                     color = {0, 255, 0, v}
  715.                 else
  716.                     color = {255, 0, 0, v}
  717.                 end
  718.                 gui.pixel((i-1)%width, math.floor((i-1)/width), color)
  719.             end
  720.            
  721.             prevwram = wram
  722.             --xmouse, ymouse, left, right, middle = keys['xmouse'], keys['ymouse'], keys['leftclick'], keys['rightclick'], keys['middleclick']
  723.            
  724.             if left or right or middle and xmouse <= width then
  725.                 offset = 0xC000 + (xmouse%width) + (ymouse*width)
  726.                 if left then
  727.                     memory.writebyte(offset, AND(memory.readbyte(offset) + 1, 0xFF))
  728.                 elseif right then
  729.                     memory.writebyte(offset, AND(memory.readbyte(offset) - 1, 0xFF))
  730.                 else
  731.                     memory.writebyte(offset, 0xff)
  732.                 end
  733.             end
  734.         end
  735.        
  736.         for i,v in pairs(frozen) do
  737.             memory.writebyte(i, v);
  738.         end
  739.        
  740.         -- Click on the screen to move
  741.         if left then --gamemode == mode_Game_LevelMain and
  742.            
  743.             new_X1 = memory.readbyte(camera_X)
  744.             new_X2 = memory.readbyte(camera_X+1)+xmouse-0x50
  745.            
  746.             new_Y1 = memory.readbyte(camera_Y)
  747.             new_Y2 = memory.readbyte(camera_Y+1)+ymouse-0x40
  748.            
  749.  
  750.             -- Due to how memory.readword works and the way values are laid out in memory, we have to do this mess. S I G H
  751.             if new_X2 > 0xFF then
  752.                 new_X2 = new_X2 - 0xFF
  753.                 new_X1 = new_X1 + 0x01
  754.             end
  755.             if new_Y2 > 0xFF then
  756.                 new_Y2 = new_Y2 - 0xFF
  757.                 new_Y1 = new_Y1 + 0x01
  758.             end
  759.             if new_X2 < 0x00 then
  760.                 new_X2 = new_X2 + 0xFF
  761.                 new_X1 = new_X1 - 0x01
  762.             end
  763.             if new_Y2 < 0x00 then
  764.                 new_Y2 = new_Y2 + 0xFF
  765.                 new_Y1 = new_Y1 - 0x01
  766.             end
  767.             --gui.text(1,8*0,string.format("X %02X%02X", new_X1, new_X2), white, black)
  768.             --gui.text(1,8*1,string.format("Y %02X%02X", new_Y1, new_Y2), white, black)
  769.            
  770.             memory.writebyte(player_X, new_X1)
  771.             memory.writebyte(player_X+1, new_X2)
  772.             memory.writebyte(player_Y, new_Y1)
  773.             memory.writebyte(player_Y+1, new_Y2)
  774.  
  775.         end
  776.        
  777.         lastkeys = keys
  778.        
  779.         player_Action_Previous  = player_Action_Current
  780.         emu.frameadvance();
  781.     end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement