Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Convert EXP info from HEX 2 DEC
- local function loadExp(address)
- local exp = 0
- for n=0,2 do
- local expByte = memory.readbyte(address+n)
- exp = exp + (AND(expByte,0xf) + AND(expByte,0xf0)/0x10*10) * math.pow(100,n)
- end
- return exp
- end
- -- Detect ROM version
- local expTable = 0;
- local fps = 60;
- local expTableEU = 0x8db92a
- local expTableJPN = 0x8dba61--0x8db92a--
- if loadExp(expTableEU + 11*49) == 802435 then
- -- European ROM
- expTable = expTableEU
- fps = 50
- elseif loadExp(expTableJPN + 11*49) == 802435 then
- -- Japanese ROM
- expTable = expTableJPN
- fps = 60
- else
- error(string.format("Could not detect valid Terranigma ROM: %s",loadExp(expTableJPN + 11*1)))
- end
- -- Create exp timer
- --exp.xpos = 92
- --exp.ypos = 6
- local boxcolor = 0x00000080
- local activetextcolor = 0xFFFFFFFF
- local inactivetextcolor = 0x808080FF
- local timerIsActive = false
- local startFrame = 0
- local totalFrames = 0
- local startExp = 0
- local totalExp = 0
- local previousFrame = 0
- local levelUp = false
- local lostControl = false
- local smallHeight = 10
- local fullHeight = 2+8*4
- local currentHeight = fullHeight
- local targetHeight = fullHeight
- local xpos = 92
- local ypos = 2
- local hidden = false
- -- Function to render the timer
- local function my_display()
- if(currentHeight < targetHeight) then
- currentHeight = currentHeight + 1
- elseif(currentHeight > targetHeight) then
- currentHeight = currentHeight - 1
- end
- local level = memory.readbyte(0x7e0656)
- local currentExp = loadExp(0x7e0690)
- local targetExp = loadExp(expTable + 11*level)
- local currentFrame = emu.framecount()
- if(currentExp>targetExp and not levelUp) then
- levelUp = true
- lostControl = false
- end
- if levelUp then
- if lostControl then
- lostControl = memory.readbyte(0x7e097d)==0x80
- levelUp = lostControl
- if levelUp and timerIsActive and not (currentFrame==previousFrame) then
- startFrame = startFrame + 1
- end
- else
- lostControl = memory.readbyte(0x7e097d)==0x80
- end
- end
- if timerIsActive then
- totalExp = currentExp -startExp
- totalFrames = currentFrame-startFrame
- end
- local expSpeed
- if totalFrames==0 then
- expSpeed = 0
- else
- expSpeed = totalExp/totalFrames*fps
- end
- if hidden then
- return
- end
- gui.box(xpos,ypos,xpos+(17+1)*4,ypos+currentHeight,boxcolor)
- gui.text(xpos+3,ypos+2+8*0,string.format("EXP %13s", string.format("%i / %i",currentExp,targetExp)),textcolor)
- local timerTextColor
- if timerIsActive then timerTextColor = activetextcolor else timerTextColor = inactivetextcolor end
- if currentHeight>=16 then
- gui.text(xpos+3,ypos+2+8*1,string.format("GAIN %12s", string.format("%6i exp",totalExp)),timerTextColor)
- end
- if currentHeight>=24 then
- gui.text(xpos+3,ypos+2+8*2,string.format("TIME %12s", string.format("%6.1f sec",totalFrames/50)),timerTextColor)
- end
- if currentHeight>=32 then
- gui.text(xpos+3,ypos+2+8*3,string.format("SPEED %11s",string.format("%6.1f x/s",expSpeed)),timerTextColor)
- end
- previousFrame = currentFrame
- end
- -- 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)
- -- Public functions to control the timer
- exp_timer = {}
- function exp_timer.show() hidden = false end
- function exp_timer.hide() hidden = true end
- function exp_timer.start()
- totalExp = 0
- startExp = loadExp(0x7e0690)
- startFrame = emu.framecount()
- totalFrames = 0
- timerIsActive = true
- end
- function exp_timer.stop()
- timerIsActive = false
- end
- function exp_timer.toggle()
- if timerIsActive then
- exp_timer.stop()
- else
- exp_timer.start()
- end
- end
- function exp_timer.clear()
- totalExp = 0
- totalFrames = 0
- end
- function exp_timer.collapse()
- targetHeight = smallHeight
- end
- function exp_timer.expand()
- targetHeight = fullHeight
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement