Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Terranigma RNG script, updated to work with BizHawk 1.11.7
- -- original author: unknown
- -- main change: mainmemory.readbyterange seems to work differently
- -- minor change: the two columns used by the original script don't overlap anymore
- -- Window properties
- local title = " RNG "
- local nr_rows = 16
- local nr_columns = 2
- local column_width = 8
- local text_size = 10;
- local targetxpos = 0
- local targetypos = 36
- local xpos = targetxpos
- local ypos = targetypos
- local getCollapsedWidth = function()
- return (math.max(column_width,string.len(title))+1)*4
- end
- local my_text = function(x,y,counter,rn)
- gui.drawText(x,y,string.upper(string.format('%02x:%02x',counter,rn)), 0xFFFFFFFF, text_size)
- -- console.writeline(string.upper(string.format('%02x: %02x',counter,rn)));
- end
- local my_display = function()
- -- Update the position of the RNG window
- if ypos<targetypos then
- ypos = ypos + 1
- elseif ypos>targetypos then
- ypos = ypos - 1
- end
- if xpos<targetxpos then
- xpos = xpos + 1
- elseif xpos>targetxpos then
- xpos = xpos - 1
- end
- -- Read the current state of the RNG
- local currentRNG = mainmemory.readbyterange(0x0408, 16)
- -- Render the title box
- --gui.drawBox (xpos,ypos-9,xpos+4*(string.len(title)+1) ,ypos-1,0xFF000000)
- gui.drawText(xpos+3,ypos-8,title, 0xFFFFFFFF, text_size)
- -- Render the RNG boxes
- for c=0,math.floor(nr_columns)-1 do
- local xcolumn = xpos+c*(column_width+5)*4*(1-math.abs(xpos/getCollapsedWidth()))
- --gui.drawBox (xcolumn, ypos, xcolumn+(column_width+1)*4 ,ypos+nr_rows*8+2,0x8000000000)
- for n=0,math.floor(nr_rows)-1 do
- -- Render the text
- my_text(xcolumn+3,ypos+(n)*8+2,currentRNG[15],currentRNG[0])
- -- Update the set of random numbers to predict the next one
- local carry = 0
- local temp
- for i=15,1,-1 do
- temp = currentRNG[i-1]+currentRNG[i]+carry
- currentRNG[i-1] = bit.band(temp,0xff)
- carry = (temp-bit.band(temp,0xff))/256
- end
- i=15
- repeat
- currentRNG[i]=bit.band(currentRNG[i]+1,0xff)
- i=i-1
- until i<0 or currentRNG[i+1]~=0
- --
- end
- end
- end
- -- FIXME, bizhawk does not seem to have something to register function like this
- -- Hook the display function to the GUI update
- -- local on_gui_update_old = gui.register()
- local function on_gui_update_new()
- if on_gui_update_old then
- on_gui_update_old()
- end
- my_display()
- end
- -- gui.register(on_gui_update_new)
- -- Create a public RNG object to interact with
- rng = {}
- rng.show = function() targetxpos = 0 end
- rng.hide = function() targetxpos = -(getCollapsedWidth()+1) end
- rng.set_title = function( new_title ) title = new_title end
- rng.set_text = function( new_text ) my_text = new_text end
- rng.set_nr_rows = function( new_nr_rows ) nr_rows = new_nr_rows end
- rng.set_nr_columns = function( new_nr_columns ) nr_columns = new_nr_columns end
- rng.set_column_width = function( new_column_width ) column_width = new_column_width end
- while true do
- my_display()
- emu.frameadvance()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement