Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- FCEUX LUA RNG Sample Testing Script
- -- by ZeroNoin
- -- This LUA script is heavily based on script by Omnigamer found here:
- -- http://pastebin.com/Qv6sw2j7
- -- This FCEUX script takes an RNG address and sets it to various values at the start of savestate loads.
- -- It counts the desired results found in other addresses from an event after the savestate load.
- -- Pause the emulator just before the RNG event, then run this script via File > Lua, then unpause the emulator.
- -- It can be difficult to find RNG in game assembly, and the RNG can shuffle in strange ways, so sample testing can help.
- -- The values given here were used in Blaster Master to test H drop rates.
- -- RNG RAM address, addresses showing result of RNG, number of result addresses, and value compared for RNG success.
- -- In the case of Blaster Master, an item drop (including an H drop) is labeled with a value of 0x35.
- -- There are 8 locations in the RAM where an item drop can be placed.
- RNG_ADDRESS = 0x0013
- RESULT_ADDRESSES = {0x0470,0x047E,0x048C,0x049A,0x04A8,0x04B6,0x04C4,0x04D2}
- RESULT_VALUE = 0x35
- -- Count of RNG successes, iterated value put in the RNG RAM, and length of RNG value iterations.
- -- Since only one 8-bit address holds the RNG value in Blaster Master, there are 0x100 (256) possible values, 0x00 through 0xFF.
- COUNT = 0
- CURRENT = 0x00
- ITERATIONS = 0x100
- -- Frames from the loaded savestate to give for the RNG event to occur.
- FRAMES = 15
- -- A savestate number assigned for the test (this save is separate from normal savestate slots in the emulator).
- -- The savestate must be created and stored as an object in order for this script to reference it.
- -- The savestate object does not contain a savestate until one is saved in it.
- SAVE_NUMBER = 1
- SAVE_STATE = savestate.create(SAVE_NUMBER)
- savestate.save(SAVE_STATE)
- -- Variables for placement of the displayed results.
- -- Pixels from the top left in X and Y distance, and pixels spacing the start of each line.
- DISPLAY_X = 16
- DISPLAY_Y = 32
- SPACING = 8
- -- Set the RNG at its specific address in the RAM to a given value.
- function set_rng(value)
- memory.writebyte(RNG_ADDRESS,value)
- end
- -- Compare the value at a resulting address with the value considered RNG success.
- function compare_result(address,value)
- if(memory.readbyte(address)==value) then
- return true
- else
- return false
- end
- end
- -- Check the results in the given addresses, and count the successes.
- -- Output (print) successful RNG values to the emulator LUA console.
- function check_result()
- for i=1,table.getn(RESULT_ADDRESSES),1 do
- if(compare_result(RESULT_ADDRESSES[i],RESULT_VALUE)) then
- COUNT = COUNT+1
- emu.print(string.upper(string.format("%02x",CURRENT)))
- break
- end
- end
- end
- -- Display the current results of the test in text.
- -- The "O" displays wide in FCEUX, so I decided to use "0" instead.
- function display_results()
- gui.text(DISPLAY_X,DISPLAY_Y,string.format("C0UNT %3d",COUNT))
- gui.text(DISPLAY_X,DISPLAY_Y+SPACING,string.format("CURRENT %3d",CURRENT))
- gui.text(DISPLAY_X,DISPLAY_Y+SPACING+SPACING,string.format("PERCENT %.2f%%",(COUNT/CURRENT)*100))
- end
- -- Advance the frames a given quantity for the event to occur.
- -- Also display the status of the results on each frame.
- function advance_frames(value)
- for i=0,value,1 do
- emu.frameadvance()
- display_results()
- end
- end
- -- Main script utilizing the above variables and functions.
- -- For all the RNG values, load the savestate, set the RNG, and advance the frames a given amount for the event.
- -- After the frames advance the event, check and count the result of the event in corresponding addresses in the RAM.
- -- When complete, output totals to the emulator LUA console and continually advance frames and display the results.
- while(CURRENT<ITERATIONS) do
- savestate.load(SAVE_STATE)
- set_rng(CURRENT)
- advance_frames(FRAMES)
- check_result()
- CURRENT = CURRENT+0x01
- end
- emu.print(string.format("COUNT %3d",COUNT))
- emu.print(string.format("CURRENT %3d",CURRENT))
- emu.print(string.format("PERCENT %.2f%%",(COUNT/CURRENT)*100))
- while(true) do
- advance_frames(1)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement