Advertisement
redslash

ctinfoscope20160902

Sep 3rd, 2016
425
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 35.27 KB | None | 0 0
  1. --Chrono Trigger Infoscope for Snes9x(1.51-rr) AND Bizhawk 1.11.5
  2. -- 2016/09/02 Redslash
  3.  
  4. -- Features:
  5.     -- Top: timing from Title Screen (with 60.09fps vs 59.94fps offset); framecount below
  6.     -- Bottom: RNG "Timeline" with markers for jumps
  7.     -- Left: Treasure counter, Battle Speed, Crit value (color-coded to match RNG chart)
  8.     -- Right Side: Room timing -> these are posted to the Lua console
  9.     --     out-of-menu + in-menu = total time
  10.     -- Battle: HP, ATB, Damage Dealt (easier to check damage numbers), Runaway counter (120 frames = escape)
  11.     -- Pause+Select: Hitboxes/triggers, w/ Object IDs (optional); Input Display shows press vs held
  12.  
  13. -- HOW TO USE:
  14. -- 1. get specific emulator http://tasvideos.org/EmulatorResources/Snes9x.html (top link)
  15. -- 2. download this pastebin (as .LUA file), and open it from Bizhawk or Snes9x: File > Lua Scripting > New Lua Script Window
  16.  
  17. -- OPTIONS ( 1=enable, 0=disable )
  18. local dispObjectID = 1  -- view Object IDs (on/off)
  19. local dispCronoBox = 0  -- view PC hitboxes (on/off)
  20. local AUTO_TEXT    = 10 -- hold button to auto-close text (see Buttons below; 1 = 'R', 10 = 'Select')
  21. local roomtimefile = "roomtime1.csv"
  22.  
  23. -- older versions:
  24. -- 2016/06/10 http://pastebin.com/eL3Dqrz4 (coords)
  25. -- 2016/05/23 http://pastebin.com/RgWyzGpR
  26. -- 2016/02/02 http://pastebin.com/epGpuMy0
  27. -- 2015/10/30 http://pastebin.com/J0C5kDnF
  28.  
  29.  
  30. local button = {'R','L','X','A','right','left','down','up','start','select','Y','B'}
  31. local BIZ = false
  32. function emutest() gui.pixel(0,0,"#000000") end
  33. function newbiztest() gui.pixelText(0,0,0x00000000) end
  34. if pcall(emutest) ~= true then
  35.     BIZ = true
  36.     button = {'P1 R','P1 L','P1 X','P1 A','P1 Right','P1 Left','P1 Down','P1 Up','P1 Start','P1 Select','P1 Y','P1 B'}
  37.     memory.usememorydomain("CARTROM")
  38. end
  39. local BIZ_Ver = "new"
  40. if BIZ then
  41.     if pcall(newbiztest) ~= true then
  42.         BIZ_Ver = "old"
  43.     end
  44. end
  45. function ReadByte(i)
  46.     if BIZ then return mainmemory.read_u8(i)
  47.     else return memory.readbyte(0x7e0000 + i) end
  48. end
  49. function ReadWord(i)
  50.     if BIZ then return mainmemory.read_u16_le(i)
  51.     else return memory.readword(0x7e0000 + i) end
  52. end
  53. function ReadByte_ROM(i)
  54.     if BIZ then return memory.read_u8(i)
  55.     else return memory.readbyte(0xc00000 + i) end
  56. end
  57. function ReadWord_ROM(i)
  58.     if BIZ then return memory.read_u16_le(i)
  59.     else return memory.readword(0xc00000 + i) end
  60. end
  61. function DrawPixel(x,y,color)
  62.     if BIZ then return gui.drawPixel(x,y,color)
  63.     else return gui.pixel(x,y,fixColor(color)) end
  64. end
  65. function DrawBox(x1,y1,x2,y2,color,fill)
  66.     if BIZ then return gui.drawBox(x1,y1,x2,y2,color,fill)
  67.     else return gui.box(x1,y1,x2,y2,fixColor(color),fixColor(fill)) end
  68. end
  69. function DrawText(x,y,text,color,back)
  70.     if BIZ then
  71.         if back == "shadow" then back = nil end
  72.         if BIZ_Ver == "new" then
  73.             return gui.pixelText(x,y,text,color,back)
  74.         else return gui.text(x,y,text,color,back) end
  75.     else return gui.text(x,y,text,fixColor(color),fixColor(back)) end
  76. end
  77. function Pause()
  78.     if BIZ then return client.pause()
  79.     else return emu.pause() end
  80. end
  81. local s9xcolor = {
  82.     ["red"]     ="#FF0000", ["darkred"]     ="#a00000",
  83.     ["green"]   ="#00FF00", ["darkgreen"]   ="#008000",
  84.     ["blue"]    ="#0000FF", ["navy"]        ="#2020FF",
  85.     ["yellow"]  ="#FFFF00", ["goldenrod"]   ="#808000",
  86.     ["cyan"]    ="#00FFFF", ["darkcyan"]    ="#008080",
  87.     ["magenta"] ="#FF00FF", ["darkmagenta"] ="#a000a0",
  88.     ["white"]   ="#FFFFFF", ["silver"]      ="#a0a0a0",
  89.     ["gold"]    ="#ffd700", ["darkorange"]  ="#FF950E",
  90.     ["gray"]    ="#808080", ["darkgray"]    ="#404040",
  91.     ["brown"]   ="#a52a2a",
  92.     ["none"]    ="#00000000",["shadow"]="#00000080"}
  93. function fixColor(c)
  94.     if type(c) == "number" then
  95.         alpha = math.floor(c/1000000)
  96.         return (c%0x1000000)*0x100 + alpha
  97.     else return s9xcolor[c] end
  98. end
  99.  
  100. local lowfade = 0x20000000
  101. local infade = 0x80000000
  102. local outfade = 0xc0000000
  103. local nofade = 0xff000000
  104. local dispy = 191
  105. local yoffset = 168
  106. local xoffset = 70  -- 89 = button display centered
  107.  
  108. local inputs = joypad.get()
  109. local btnlabel= {'  r','l','X','A','>','<','v','^','S','-','Y','B'}
  110. local xcoords = { 8.6, 0.4, 9,10, 2, 0, 1, 1, 6, 4, 8, 9}
  111. local ycoords = {  1,   1,  2, 3, 3, 3, 4, 2, 3, 3, 3, 4}
  112. local press =   {  0,   0,  0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
  113. local unpress = {  0,   0,  0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
  114. local turbo   = {  0,   0,  0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
  115. local selectheld = 0
  116.  
  117.  
  118. local CT_Ver = "J" -- determine "U" or "J" to subtract Title Screen
  119. if ReadWord_ROM(0x0C650B) == 0xBEB1 then CT_Ver = "U" end
  120.  
  121. local CT_button = {["10"]=button[1],["20"]=button[2],["40"]=button[3],["80"]=button[4],
  122.                     ["1"]=button[9],["2"]=button[10],["4"]=button[11],["8"]=button[12]}
  123.  
  124. local MENU_POS = 0x00ec
  125. local BATTLE_FLAG = 0x0117
  126. local battleflag = 0
  127. local battlecopy = 0
  128.  
  129. local FACING = 0x1600
  130. local MOVING = 0x1680
  131. local facing = {}
  132. local moving = {}
  133. local faceoffset = 5    -- experimental
  134. local MAP_X = 0x1800
  135. local MAP_Y = 0x1880
  136. local mapx = {}
  137. local mapy = {}
  138. local mapoffsetx = 0
  139. local mapoffsety = 0
  140. local SCREEN_X = 0x0A00
  141. local SCREEN_Y = 0x0A80
  142. local mainsprite = 0
  143. local farsprite = 0
  144. local xsign,ysign = "",""
  145. local xcolor,ycolor = 0,0
  146.  
  147.  
  148. local CHAR_ID = 0x2980  -- 3 in-party then 6 reserve (e.g. for 1-on-1 bosses)
  149. local CHAR_WEAP = 0x2629
  150. local CHAR_HELM = 0x2627
  151. local CHAR_VEST = 0x2628
  152. local CHAR_ACC = 0x262A
  153. local crits =   "0737062067712743017053012106621026206760245002737143667207070014"..
  154.                 "1101674231747620560305126422403270125313166113731602620666773021"..
  155.                 "1714114244363074011420427072702021156152710015037100071773030063"..
  156.                 "3110560024303132144471071671003163600200333701061633241110004006"..
  157.                 "0737062067" --wrap-around
  158. local critcolor = {"gray","gray","darkgreen","magenta",
  159.                 "cyan","green","darkorange","white"}
  160.  
  161. local LOCATION = 0x0100
  162. local loc = ReadWord(LOCATION)
  163. local loc_Prev = ReadWord(LOCATION+5)
  164. local door = ""
  165. local roomname = {"Load","CH2","CH1","LH2","LH1","LS1","Gato","LSp","LSo","LH3","LHo","","Tn+","","","","","","","GF+","GFo","Throne+","King+","","GK+","GN+","GB1","Court","GJb","GJa","","","","Me1","Me2","","Diner","","","","MH1","MH2","Pyra","CWx","LSx","DMx","MFx","HCb","HC1","HCa","Pm1","","","","","","","Shrine","","","MLx","Cr+","Cn+","WC+","SK+","NR1","NR2","","","","","GJ1","GJ2","NR3","","GJc","","","","","","","ED","FF2","","","","","TheD","","","","","","","","BZ4","BW1","BW2","BE0","BE1","BE2","","","","","","BZb","Expl","GC6","GC3","GC5","TC1","TCo","","","Tn1","Tn2","","GF-","Throne-","King-","Queen-","GK-","GN-","ML5","GD3","GDa","GDc","YC1","YC2","YC4","YCa","ZBR","","Zenan","Dr","De","Dn","Dm","CW1","CW2","DM2","DMa","DM6","DM1","DM3","DM4","DM7","DM8","DM5","DMb","Tata","Pt2","Pe-","Pc-","Pn-","Pm-","Fiona","SD0","SD1","SD2","","FC0","FC1","ML0","ML1","MF2","MF4","ML3","MF1","ML4","MLb","ML6","MFb","MF6","MF3","OF0","OF2","OFa","OFb","OFc","","OF1","OF3","","Cr-","","Cn-","","","SK-","","","","GC1","GC4","GCb","YCb","YC3","YCc","YCw","YCe","YCd","GFb","DMc","GFa","","BDo","BDs","TD0","TDs","16W","16E","AD1","AD3","AD2","AD4","ADs","ADb","","ADa","","32W","32R","32E","PD1","PDo","FR1","FRa","FRb","FR2","FR3","FR4","FR5","FRc","SA1","SA2","","","","KD","KD2","KD3","DP1","DP2","DPa","DP4","GD1","GD2","GD4","SPb","","","","SK#","GD5","","","FR6","DP6","TLc","DP5","DP3","DPc","DS1","","GDd","GDb","","","spec","MMo","MM1","MM2","Ayla","","","","Soup2","Soup1","","FM","RL1","RL2","RL3","RL4","RL5","RLa","RLb","","","LR","DN1","DN2","DN3","GCa","GC2","TL4","TL1","TLa","TLb","TL3","TL6","TL7","TL5","","TLo","BX1","BX2","BX3","BX4","BX5","BF1","BF2","BOs","BY1","BY2","BY3","BY4","BW3","BW4","BYa","BYb","BZ1","BZ2","BZ3","SKP","ZP3","ZPa","ZP4","ZP5","ZPb","ZPc","","","L2","S1","","","","","","","ADc","","Lg","Ldt","Lhec","Lzom","Lmm","12Ko","L3","L1","S2","","S3","Kaj1","","","","","","BBa","BB2","","BB3","BBc","","BB5","","BB1","","","BB6","","BB4","BBb","","","EB1","","EBe","","","","EB0","","Beast","ZT","","","MW2","MW3","MW1","MW4","","MW5","","","","ZP1","ZP2","","OP1","OP2","OP3","OP4","OP5","OP6","OP7","OE1","OP8","OPa","OPb","OPc","OE2","","OE3","","","","BZa","OPd","LVC","LV1","LVs","","NC","DS2","TL2","","EM#","Title","ToH","","FF1","FR6","CRb","LS2","GB2","CRa","","","","","MF5","MLa","","BX0","BZ5","BZ6","","","","","Lniz","Lm","Lbt","Lgg","","","","","EoT","Spek","1999","Shell","QT-","ML2","MFa","","AMF","EM&","ILa","ILb","","EMF","BB7","ILc","KT-","BBR","","","","","KT+","QT+","CR0","GJ3","","","","EBR","FoZ","DPb","M1000","M600","M2300","M65m","M12k","MZeal","MFall","M1999","","","","","","","",""}
  166.  
  167. local frameInc = 0
  168. local locStart = 0
  169. local menuTime = 0
  170. local timeEnd,menuEnd = 0,0
  171. local recentload = 1
  172. local segCount = 0
  173. local segTotalTime = 0
  174. local MENU_INDICATOR = 0x06fe
  175. local menu_state = 0
  176. local totalSec,menuSec,diffSec = 0,0,0
  177.  
  178. local f = io.open(roomtimefile,"a")
  179.     f:write("New Session\n")
  180.     f:close()
  181.    
  182. function OutputTime()
  183.     loc0 = roomname[loc_Prev+1]
  184.     loc1 = roomname[loc+1]
  185.     loc2 = ReadWord(LOCATION)
  186.     outSegTime = ""
  187.     if loc ~= loc2 then
  188.         loc2 = loc1..","..string.format("%03X",loc)
  189.         outSegTime = string.format("%06.2f",segTotalTime/60)
  190.     else loc2 = loc1..","..string.format("%03X",loc).."("..segCount..")" end
  191.     if recentload == 1 then loc2 = "*"..loc2 end
  192.     recentload = 0
  193.  
  194.     totalSec = timeEnd / 60
  195.     menuSec = menuEnd / 60
  196.     diffSec = (timeEnd - menuEnd) / 60
  197.     print(string.format("%6d",timeEnd-menuEnd).."\t"..
  198.         string.format("%6d",menuEnd).."\t"..
  199.         string.format("%6d",timeEnd).."\t"..
  200.         loc2.."\t->"..string.format("%6.2f",totalSec))
  201.     outstring = string.format("%6d",timeEnd-menuEnd)..";"..
  202.         string.format("%6d",menuEnd)..";"..
  203.         string.format("%6d",timeEnd)..";"..
  204.         loc2..";"..os.date("%Y%m%d_%H:%M")..";"..segTotalTime
  205.     f = io.open(roomtimefile,"a")
  206.     f:write(outstring.."\n")
  207.     f:close()
  208. end
  209.  
  210. function displayTime()
  211.     frameInc = frameInc + 1
  212.  
  213. --Catch menu state change
  214.     menu_ind = ReadByte(MENU_INDICATOR)
  215.     if (menu_state == 0 and (menu_ind == 0xA3 or menu_ind == 0x84 or menu_ind == 0xA6 )) then
  216.         menu_state = 1
  217.     end
  218.     if (menu_state == 1 and
  219.         (menu_ind == 0xA9 or menu_ind == 0xB9 or menu_ind == 0xD1 )) then
  220.         menu_state = 0
  221.     end
  222.     if (menu_state == 1) then menuTime = menuTime + 1 end
  223.  
  224. --catch change in Battleflag or Location
  225.     if loc ~= ReadWord(LOCATION) or battleflag ~= ReadByte(BATTLE_FLAG) % 2 then
  226.         timeEnd = frameInc - locStart
  227.         menuEnd = menuTime
  228.         menuTime = 0
  229.         segTotalTime = segTotalTime + timeEnd
  230.  
  231.         OutputTime()
  232.         locStart = frameInc
  233.         if battleflag ~= ReadByte(BATTLE_FLAG) % 2 then
  234.             segCount = segCount + 1
  235.         else
  236.             segCount = 0
  237.             segTotalTime = 0
  238.         end
  239.     end
  240.     battleflag = ReadByte(BATTLE_FLAG) % 2
  241.     loc = ReadWord(LOCATION)
  242.     loc_Prev = ReadWord(LOCATION+5)
  243.     door =  ";"..string.format("%02X",ReadByte(LOCATION+2))..
  244.             "/"..string.format("%02X",ReadByte(LOCATION+3))..""
  245.  
  246.     p_y = 1
  247.     if (ReadByte(MENU_POS) == 0) then p_y = 189 end
  248.     DrawText(223,p_y,"  "..string.format("%6.2f",diffSec),"silver","shadow")   
  249.     DrawText(223,p_y+8,"  "..string.format("%6.2f",menuSec),"silver","shadow") 
  250.     DrawText(223,p_y+16,"  "..string.format("%6.2f",totalSec),"silver","shadow")
  251. end
  252.  
  253. local redbox = {}
  254. redbox[0x70] = {0x14,0x2e,0x30,0x32,0x28}
  255. redbox[0x77] = {0x32,0x34,0x3c,0x3e,0x28,0x2a,0x46,0x1c,0x1e}
  256. redbox[0x91] = {0x14,0x16}
  257. redbox[0x8c] = {0x20,0x22,0x24,0x2e,0x30,0x1e,0x1a} --3 frogs are friendly
  258. redbox[0x1d5] = {0x1c,0x26}
  259. redbox[0xb0] = {0x20,0x22}
  260. --redbox[0xa8] = {0x14,0x16,0x18,0x1a,0x1c,0x1e} --ozzie pits
  261. redbox[0x8e] = {0x24}
  262. redbox[0x92] = {0x10,0x18}
  263. redbox[0x93] = {0x10,0x18,0x1a}
  264. redbox[0x96] = {0x10}
  265. redbox[0x90] = {0x10,0x12,0x1a}
  266. redbox[0x94] = {0x10,0x12}
  267. redbox[0x8f] = {0x28,0x2a,0x1c,0x2c}
  268. redbox[0x82] = {0x3c,0x44,0x40,0x26,0x28,0X32,0x38,0x24,0x30,0x34,0x36,0x10,0x16,0x18}
  269. redbox[0x83] = {0x66,0x68,0x5e,0x1c,0x2c,0x32,0x40,0x4c,0x4e,0x50}
  270. redbox[0x84] = {0x1a,0x1c,0x1e,0x20,0x22,0x24,}
  271. redbox[0x78] = {0x16}
  272. redbox[0x13] = {0x1c,0x24,0x26,0x28,0x2a,0x2c,0x2e,0x30,0x3c,0x3e,0x40}
  273. redbox[0x1C] = {0x4}
  274. redbox[0x15] = {0x22}
  275. redbox[0xd4] = {0x24,0x26,0x28,0x2a,0x3a,0x3c,0x3e,0x40,0x42,0x12,0x14,0x16,0x18,0x1a,0x1c}
  276. redbox[0xd7] = {0x10,0x12,0x14,0x16,0x18,0x1a,0x1c}
  277. redbox[0xd9] = {0x20,0x22,0x24,0x26,0x18,0x1a,0x1c,0x1e,0x14,0x16}
  278. redbox[0xe4] = {0x16,0x18,0x1a}
  279. redbox[0x1d1] = {0x20,0x22,0x24,0x26,0x28}
  280. redbox[0x112] = {0x12,0x14,0x16,0x18,0x1c,0x1e,0x22,0x24,0x26,0x28,0x2a,0x2c}
  281. redbox[0x11a] = {0x2a,0x2c,0x2e,0x30,0x32,0x34,0x36,0x38}
  282. redbox[0x11d] = {0x20,0x22}
  283. redbox[0x11e] = {0x10}
  284. redbox[0x11f] = {0x1a,0x1c,0x1e,0x20,0x22,0x24}
  285. redbox[0x120] = {0x14,0x16,0x18}
  286. redbox[0x11c] = {0x12,0x14,0x16,0x18}
  287. redbox[0xa4] = {0x16,0x18,0x1a}
  288. redbox[0x7d] = {0x12,0x22,0x1e}
  289. redbox[0x1be] = {0x24,0x26,0x28,0x2a,0x2c,0x2e}
  290. redbox[0x1bf] = {0x30,0x32,0x34,0x36,0x38,0x3a}
  291. redbox[0x125] = {0x18,0x1a,0x1c,0x1e,0x22,0x24,0x28,0x2c,0x26,0x30}
  292. redbox[0x126] = {0x16,0x1a,0x1c,0x28}
  293. redbox[0x12a] = {0x22,0x24,0x26,0x28,0x2c,0x2e,0x30,0x3e,0x42,0x40,0x5c,0x5e,0x60,0x62,0x6e,0x70,0x72}
  294. redbox[0x12b] = {0x14,0x12,0x16,0x18}
  295. redbox[0x131] = {0x10,0x12,0x14,0x1c,0x24,0x20}
  296. redbox[0x130] = {0x12,0x14}
  297. redbox[0x12f] = {0x1a,0x18}
  298. redbox[0xdb] = {0x10,0x12}
  299. redbox[0xa0] = {0x02,0x04,0x06,0x08,0x0a}
  300. redbox[0xa1] = {0x20}
  301. redbox[0xec] = {0x1c,0x36,0x3c,0x22,0x24,0x26,0x3e,0x46,0x28,0x16,0x18,0x14}    --sewer
  302. redbox[0xed] = {0x2c}   --sewer
  303. redbox[0x18a]= {0x16}   --woe
  304. redbox[0x188]= {0x32,0x34}  --woe
  305. redbox[0x189]= {0x2c}   --woe
  306. redbox[0x195]= {0x14,0x16,0x1e,0x20,0x2a,0x18,0x1a,0x1c}    --op
  307. redbox[0x196]= {0x14,0x1a,0x1c,0x2e,0x30,0x32,0x36,0x38,0x3a}   --op
  308. redbox[0x197]= {0x1c,0x1e,0x30,0x36,0x24,0x2a}  --op
  309. redbox[0x198]= {0x0e,0x10,0x12} --op
  310. redbox[0x199]= {0x26,0x28,0x2a,0x2c,0x30,0x32,0x34,0x36}    --op
  311. redbox[0x19a]= {0x0e,0x10}  --op
  312. redbox[0x171]= {0x1e}   --blackbird
  313. redbox[0x16b]= {0x30,0x32,0x34,0x36,0x38,0x3a}   -- giant's claw
  314. redbox[0xc3] = {0x1c,0x1e}   -- giant's claw
  315. redbox[0x139]= {0x10,0x18,0x1e,0x26,0x28,0x2a,0x2c,0x2e}     -- omen
  316. redbox[0x13a]= {0x10,0x12,0x14,0x1a,0x1c,0x1e,0x24,0x2c,0x2e,0x30,0x32,0x34,0x36,0x38,0x3e,0x40,0x42,0x44,0x46,0x48,0x4a}    -- omen
  317. redbox[0x13d]= {0x1a,0x26,0x28,0x2a,0x2c}
  318. redbox[0x142]= {0x10,0x12,0x14,0x2a,0x2c,0x2e}
  319. redbox[0x143]= {0x12,0x14} -- gigamute
  320. redbox[0x144]= {0x1a,0x1c}
  321. redbox[0xf5]= {0x10,0x12,0x14,0x16,0x18} -- deathpeak
  322. redbox[0xf6]= {0x16,0x12,0x14,0x1a,0x1c} -- deathpeak
  323. redbox[0x107]= {0x10,0x12,0x14} -- deathpeak
  324. redbox[0x108]= {0x16,0x18,0x14,0x20} -- deathpeak
  325. redbox[0x104]= {0x10,0x12,0x14,0x16,0x18,0x1a,0x1c,0x1e} -- deathpeak
  326. redbox[0x1a]= {0x18} -- yakra13
  327. redbox[0x1b8]= {0x1a,0x1c} -- yakra13
  328.  
  329. local trigger = {}
  330. trigger[0xc6] = {0x010d,0x020d,0x030d,0x040d,0x050d,0x060d,0x070d,0x080d,0x090d,0x0a0d,0x0b0d,0x0c0d,0x0d0d}
  331. trigger[0xd4] = {0x0c34,0x0d34,0x0e34,0x0f34,0x1034,
  332.                  0x0c33,0x0d33,0x0e33,0x0f33,0x1033,
  333.                  0x0c32,0x0d32,0x0e32,0x0f32,0x1032,
  334.                  0x0c31,0x0d31,0x0e31,0x0f31,0x1031,
  335.                  0x0c30,0x0d30,0x0e30,0x0f30,0x1030,
  336.                  0x1727,0x1827,0x1927,
  337.                  0x0714,0x0715,0x0716,0x0717,0x0718,0x0719,0x071a,0x071b,0x071c}
  338. trigger[0xd5] = {0x2622,0x2623,0x2624,0x2625,0x2626,
  339.                  0x2d37,0x2d38,0x2d39,0x2d3a,0x2d3b,
  340.                  0x2e31,0x2e30,
  341.                  0x3925,0x3a25,0x3b25,0x3c25,0x3d25,
  342.                  0x3437,0x3438,0x3439,0x343a,0x343b}
  343. trigger[0xda] = {0x352a,0x362a,0x372a,0x382a,0x392a,0x3a2a}
  344. trigger[0xe2] = {0x3424,0x3524,0x3624,0x3724,0x3824,0x3924,0x3a24,
  345.                  0x3423,0x3523,0x3623,0x3723,0x3823,0x3923,0x3a23,0x3b23,
  346.                  0x3422,0x3522,0x3622,0x3722,0x3822,0x3922,0x3a22,0x3b22,
  347.                  0x3421,0x3521,0x3621,0x3721,0x3821,0x3921,0x3a21}
  348. trigger[0xe6] = {0x1323,0x1324,0x1325,0x1326,
  349.                  0x0d23,0x0d24,0x0d25,0x0d26,0x0431,0x0d3d,0x0d3c}
  350. trigger[0x30] = {0x0914,0x0915,0x0916,0x0917,0x0918,0x0919,0x091a}
  351. trigger[0x31] = {0x1f2f,0x202f,0x212f,0x222f,0x232f,0x242f,0x252f,0x262f,0x272f,
  352.                  0x1f30,0x1f31,0x1f32,0x1f33,0x1f34,
  353.                  0x122b,0x122c,0x122d,0x122e,0x122f}
  354. trigger[0x2f] = {0x3235,0x3335,0x3435,0x3535,0x3635,0x3735,0x3835,0x3935,0x3a35,0x3b35,0x3c35,
  355.                  0x2933,0x2932,0x2931,0x2833,0x2832,0x2831,0x2a33,0x2a32,0x2a31,
  356.                  0x102c,0x0f2c,0x0e2c,0x0d2c,0x0c2c,0x0b2c,
  357.                  0x301f,0x311f,0x321f,0x331f,0x341f,0x351f,0x361f,0x371f,0x381f,0x391f}
  358. trigger[0x87] = {0x3308,0x3309,0x330a,0x2a07,0x2a08,0x2a09,0x2a0a}
  359. trigger[0x91] = {0x0e02,0x0e03,0x0e04,0x0e05,0x0d05,0x0c05,0x0b05,0x0a05,0x0905}
  360. trigger[0x8e] = {0x0518,0x0618,0x0418,0x0318,0x0218}
  361. trigger[0x2a] = {0x0712,0x0612,0x0512,0x0812,0x1012,0x0912}
  362. trigger[0xa8] = {0x320a,0x3310,0x390f,0x390c,0x3a08,0x3c0b,
  363.                  0x320b,0x3311,0x3910,0x390d,0x3a09,0x3c0c,
  364.                  0x330a,0x3410,0x3a0f,0x3a0c,0x3b08,0x3d0b,
  365.                  0x330b,0x3411,0x3a10,0x3a0d,0x3b09,0x3d0c}
  366. trigger[0x124] = {0x080e,0x090e,0x0a0e,0x0b0e,0x070e,0x060e,0x050e,0x030e,0x020e,0x010e,0x000e,0x0d0e,0x0e0e}
  367. trigger[0x12e] = {0x0f0d,0x0f0e,0x0f0f,0x0f10,0x0f11}
  368. trigger[0xa0] = {0x0e10,0x0d10,0x0c10,0x0b10,0x0a10,0x0910,0x0f10,0x1010,0x1110,0x1210,0x1310,0x1410,0x1510,
  369.                  0x0909,0x090a,0x090b,0x090c,0x090d,0x090e,0x090f}
  370. trigger[0x1d6] = {0x252e,0x262e,0x272e,0x282e,0x292e,
  371.                  0x2522,0x2622,0x2722,0x2822,0x2922,
  372.                  0x2516,0x2616,0x2716,0x2816,0x2916,
  373.                  0x250a,0x260a,0x270a,0x280a,0x290a,0x2705}              
  374. trigger[0xe0] = {0x0707,0x0708,0x0709,0x070a,0x070b,0x070c,0x070d,0x1d0a,0x1d0b,0x1d0c,0x1d0d}
  375. trigger[0x184]= {0x072f,0x062f,0x052f,0x082f,0x092f,0x0a2f,
  376.                  0x061d,0x051d,0x041d,0x031d,
  377.                  0x0811,0x0911,0x0a11,0x0b11} --beasts
  378. trigger[0x18a]= {0x232d,0x242d,0x252d,0x262d,0x272d,0x282d,0x292d}
  379. trigger[0x188]= {0x2407,0x2408,0x2409,0x240a,0x240b,
  380.                  0x0f13,0x1013,0x1113,0x1213,0x1313,0x1413,
  381.                  0x3210,0x3211,0x3212,0x3213,0x3214,0x3215,0x3216,
  382.                  0x2e1e,0x2e1f,0x2e20,0x2e21,0x2e22,0x2e23,0x2e24,0x2e25,
  383.                  0x302d,0x302d,0x302e,0x302f,0x302d,0x3030,0x3031,0x3032,0x3033,0x3034,0x3035,0x3036,0x3037,0x3038,0x3039}
  384. trigger[0x189]= {0x0c29,0x0d29,0x0e29,0x0f29,0x1029,0x1129,0x1229,
  385.                  0x1911,0x1912}
  386. trigger[0x199]= {0x010d,0x020d,0x030d,0x040d,0x050d,0x060d,0x070d,0x080d,0x090d,0x0a0d,0x0b0d,0x0c0d,0x0d0d,0x0e0d,
  387.                  0x116d,0x126d,0x136d,0x146d,0x156d,0x166d,0x176d,0x186d,0x196d,0x1a6d,0x1b6d,0x1c6d,0x1d6d,0x1e6d}
  388. trigger[0x19b]= {0x0013,0x0113,0x0213,0x0313,0x0413,0x0513,0x0613,0x0713,0x0813,0x0913,0x0a13,0x0b13,0x0c13,0x0d13,0x0e13,0x0f13}
  389. trigger[0x16b]= {0x1019,0x0f19,0x0e19,0x0d19,0x0c19} -- giant's claw
  390. trigger[0xc4] = {0x163a,0x163b,0x163c,0x0a3a,0x0a3b,0x0a3c} -- giant's claw
  391. trigger[0x128]= {0x3338,0x3438,0x3538,0x3638,0x3738,0x3838} -- giant's claw
  392. trigger[0x6d] = {0x1c0d,0x1c0e,0x1c0f,0x1c10,0x1c11} -- giant's claw
  393. trigger[0xc5] = {0x0b29,0x0c29,0x0d29} -- giant's claw
  394. trigger[0xb7] = {0x2128,0x2228,0x2328,0x2428,0x2528,0x2628,0x2728,0x2828,0x2928,0x2a28,0x2b28,0x2c28,0x2d28} -- ozzie
  395. trigger[0xb2] = {0x1411,0x1511,0x1611,0x1711,0x1811,0x1911,0x1a11} -- ozzie
  396. trigger[0xb8] = {0x2128,0x2228,0x2328,0x2428,0x2528,0x2628,0x2728,0x2828,0x2928,0x2a28,0x2b28,0x2c28,0x2d28} -- ozzie
  397. trigger[0xb3] = {0x0124,0x0224,0x0324,0x0824,0x0924,0x0a24,0x0b24,0x0c24,0x0d24} -- ozzie
  398. --final ozzie
  399. trigger[0x13e]= {0x1808,0x1809,0x180a,0x180b,0x180c,0x1b08,0x1b09,0x1b0a,0x1b0b,0x1b0c, -- omen
  400.                  0x3508,0x3509,0x350a,0x350b,0x350c,0x3808,0x3809,0x380a,0x380b,0x380c}
  401.  
  402. local warning = {}
  403. warning[0x92] = {0x081b}
  404. warning[0x70] = {0x0d09,0x0c09,0x0b09,0x0e09,0x0712,0x0912,0x0812,0x0b0d,0x0c0d}
  405. warning[0x7a] = {0x30,0x32,0x34}
  406. warning[0x48] = {0x1211,0x1212,0x1213,0x1207,0x1208,0x1209}
  407. warning[0x8e] = {0x1235,0x0f35,0x0e35,0x0d35,
  408.                  0x1234,0x1134,0x1034,0x0f34,0x0d34}
  409. warning[0x120] ={0x0622,0x0623,0x0624,0x0625,0x0626,0x0627,0x0628,0x0629,0x062a,0x062b,0x062c,0x062d,0x062e,0x062f,0x0630,0x0631,0x0632,
  410.                  0x0722,0x0723,0x0724,0x0725,0x0726,0x0727,0x0728,0x0729,0x072a,0x072b,0x072c,0x072d,0x072e,0x072f,0x0730,0x0731,0x0732,
  411.                  0x0822,0x0823,0x0824,0x0825,0x0826,0x0827,0x0828,0x0829,0x082a,0x082b,0x082c,0x082d,0x082e,0x082f,0x0830,0x0831,0x0832,
  412.                  0x0436,0x0536,0x0636,0x0736,
  413.                  0x0437,0x0537,0x0637,0x0737,
  414.                  0x0438,0x0538,0x0638,0x0738}
  415. warning[0x196]= {0x240a,0x240b,0x240c,0x240d,0x240e,0x240f,0x2410}
  416. warning[0x135]= {0x0727,0x0827,0x0927,0x0a27,0x0627,0x0628,0x0629,0x062a,0x062b,0x062c,0x062d,0x071b,0x081b} --omen
  417. warning[0x137]= {0x071a,0x081a,0x0706,0x0806} --omen
  418. warning[0x138]= {0x061e,0x061d,0x061c,0x071e,0x071d,0x071c,0x081e,0x081d,0x081c,0x091e,0x091d,0x091c,0x0a1e,0x0a1d,0x0a1c,0x0b1d,0x0b1c,
  419.                  0x031f,0x041f,0x051f,0x061f,0x071f,0x081f,0x091f,0x0a1f,0x0b1f,
  420.                  0x0320,0x0420,0x0520,0x0620,0x0720,0x0820,0x0920,0x0a20,0x0b20,0x0c20, --omen
  421.                  0x0421,0x0521,0x0621,0x0721,0x0821,0x0921,0x0a21,0x0b21,0x0c21,0x0d21, --omen
  422.                  0x0522,0x0622,0x0722,0x0822,0x0922,0x0a22,0x0b22,0x0c22,0x0d22,0x0e22, --omen
  423.                  0x0623,0x0723,0x0823,0x0923,0x0a23,0x0b23,0x0c23,0x0d23,0x0e23, --omen
  424.                  0x0724,0x0824,0x0924,0x0a24,0x0b24,0x0c24,0x0d24,0x0e24, --omen
  425.                  0x0825,0x0925,0x0a25,0x0b25,0x0c25,0x0d25,0x0e25,
  426.                  0x0926,0x0a26,0x0b26,0x0c26,0x0d26,
  427.                  0x0927,0x0a27,0x0b27}
  428. warning[0x13f]= {0x3735,0x3835,0x3636,0x3736,0x3836,0x3936,0x3637,0x3737,0x3837,0x3937} -- omen
  429. warning[0xf4]= {0x3731,0x3732,0x3820,0x3821} -- deathpeak
  430.  
  431. function displayHitbox()
  432.  
  433.     for i = 1,64 do
  434.         mapx[i] = math.floor(ReadWord(MAP_X + 2*(i-1))/16)
  435.         mapy[i] = math.floor(ReadWord(MAP_Y + 2*(i-1))/16)
  436.         facing[i] = ReadByte(FACING + 2*(i-1))
  437.         if ReadByte(MOVING + 2*(i-1)) > 0 then
  438.             moving[i] = 1
  439.         else moving[i] = 0 end
  440.     end
  441.    
  442.     spritex = {}
  443.     spritey = {}
  444.     mainsprite = 0
  445.     farsprite = 0
  446.     for i = 1,16 do     -- get one sprite to compare
  447.         spritex[i] = ReadWord(SCREEN_X + 2*(i-1))
  448.         spritey[i] = ReadWord(SCREEN_Y + 2*(i-1))
  449.         if loc == 0xa0 then mainsprite = 7
  450.         elseif loc == 0xa1 then mainsprite = 8
  451.         elseif mainsprite == 0 and spritex[i] > 0 and spritey[i] > 0 and mapx[i] ~= 0xFF0 and
  452.             (mapy[i] ~= 0xff0 and mapx[i] ~= 0x178) and
  453.             (mapy[i] ~= 0xff0 and mapx[i] ~= 0x088) and
  454.             (mapy[i] ~= 0xff0 and mapx[i] ~= 0x298) and
  455.             (mapy[i] ~= 0xff0 and mapx[i] ~= 0x368) and
  456.             (mapy[i] ~= 0xff0 and mapx[i] ~= 0x268) and
  457.             (mapy[i] ~= 0xff0 and mapx[i] ~= 0x2b8) and
  458.             (mapy[i] ~= 0xff0 and mapx[i] ~= 0x0c8) and
  459.             (mapy[i] ~= 0xff0 and mapx[i] ~= 0xff8) then
  460.                 mainsprite = i
  461.         end
  462.     end
  463.     if mainsprite ~= 0 then
  464.         mapoffsetx = mapx[mainsprite] - spritex[mainsprite]
  465.         mapoffsety = mapy[mainsprite] - spritey[mainsprite]
  466.     end
  467.  
  468.     if warning[loc] ~= nil then
  469.         if table.getn(warning[loc]) ~= nil then
  470.             for j = 1,table.getn(warning[loc]) do
  471.                 screenx = math.floor(warning[loc][j] / 0x100)*0x10 - mapoffsetx
  472.                 screeny = (warning[loc][j] % 0x100)*0x10 - mapoffsety
  473.                 DrawBox(screenx,screeny,screenx+16,screeny+16,0x20ffff00,outfade+0xffff00) --outfade
  474.             end
  475.         end
  476.     end
  477.     if mainsprite ~= 0 and trigger[loc] ~= nil then
  478.         special = 0
  479.         if loc == 0xa8 then special = 8 end
  480.         if table.getn(trigger[loc]) ~= nil then
  481.             for j = 1,table.getn(trigger[loc]) do
  482.                 screenx = math.floor(trigger[loc][j] / 0x100)*0x10 - mapoffsetx --+ special
  483.                 screeny = (trigger[loc][j] % 0x100)*0x10 - mapoffsety
  484.                 DrawBox(screenx,screeny,screenx+15,screeny+7,infade+0x404040,outfade+0x404040)
  485.                 if screenx -1 < spritex[mainsprite] then
  486.                     DrawBox(screenx,screeny,screenx+7,screeny+7,infade+0xff0000,outfade+0xff0000)
  487.                 else DrawBox(screenx+8,screeny,screenx+15,screeny+7,infade+0xff0000,outfade+0xff0000) end
  488.             end
  489.         end
  490.     end
  491.     boxlimit = 64
  492.     if loc == 0xa8 then boxlimit = 8 end
  493.     for i = 1,boxlimit do
  494.         isred = 0
  495.         screenx = mapx[i] - mapoffsetx - 8
  496.         screeny = mapy[i] - mapoffsety - 16
  497.         if screenx < 260 and screeny < 216 then
  498.             if i < 9 then color = nofade+0x0000ff else color = nofade+0x00ff00 end
  499.             if redbox[loc] ~= nil then
  500.                 if table.getn(redbox[loc]) ~= nil then
  501.                     for j = 1,table.getn(redbox[loc]) do
  502.                         if i == redbox[loc][j]/2+1 then
  503.                             color = infade+0xff0000
  504.                             isred = 1
  505.                         end
  506.                     end
  507.                 end
  508.             end
  509.             if isred == 1 or dispCronoBox == 1 then
  510.                 screenx2 = screenx + 15
  511.                 screeny2 = screeny + 15
  512.                 if     facing[i] == 0 then --up
  513.                     screeny = screeny - faceoffset*moving[i]
  514.                     screeny2= screeny2- faceoffset
  515.                 elseif facing[i] == 1 then --down
  516.                     screeny = screeny + faceoffset
  517.                     screeny2= screeny2+ faceoffset*moving[i]
  518.                 elseif facing[i] == 2 then --left
  519.                     screenx = screenx - faceoffset*moving[i]
  520.                     screenx2= screenx2- faceoffset
  521.                 elseif facing[i] == 3 then  --right
  522.                     screenx = screenx + faceoffset
  523.                     screenx2= screenx2+ faceoffset*moving[i]
  524.                 end
  525.            
  526.                 DrawBox(screenx-7,screeny-7,screenx2+7,screeny2+7, lowfade+0x408040,outfade+0xC0C040)
  527.                 DrawBox(screenx,screeny,screenx2,screeny2,color,outfade+0xff0000)
  528.             end
  529.             if (dispObjectID == 1) then
  530.                 DrawText(screenx+faceoffset, screeny+faceoffset, string.format("%x",2*(i-1)),"white","shadow")
  531.             end
  532.         end
  533.     end
  534.     DrawBox(0,211,256,224,"none")
  535. end
  536.  
  537.  
  538. local BATTLE_VALUE = 0x0026
  539. local BATTLE_STORE = 0x29AD
  540. local CRIT_VALUE = 0xB3E6
  541. local MENU_TIME = 0x0D00
  542. local loadmenuTime = 0
  543. local menuopen = 0
  544. local CHAR_ID = 0x2980  -- 3 in-party, 6 reserve
  545. local chars = {}
  546. local ATB = 0xAFAB
  547. local atb = {}
  548. for i = 0,10 do atb[i] = ReadByte(ATB+i) end
  549.  
  550. local windowname = {}
  551.     windowname[0] = {"00","01","02","05","07","09","11","14","18","23","26","28","33","36","39","41"}
  552.     windowname[1] = {"00","01","02","05","09","12","15","16","19","22","25","28","31","35","39","42"}
  553.     windowname[2] = {"00","02","03","05","07","11","15","16","18","20","24","28","32","35","39","41"}
  554.  
  555. local battlewindow = {} --set of windows for 0, 1, and 2 empty characters
  556.     battlewindow[0] = { 0,0x09,0x0d,0x1d,0x2e,0x37,0x3e,0x58,0x61,0x88,0x98,0xab,0xb9,0xdc,0xe3,0xfb,256}
  557.     battlewindow[1] = { 0,0x0d,0x12,0x17,0x35,0x40,0x5c,0x67,0x6a,0x88,0x8f,0xad,0xb3,0xd0,0xe4,0xfd,256}
  558.     battlewindow[2] = { 0,0x0b,0x18,0x1d,0x2c,0x33,0x64,0x66,0x6d,0x79,0x85,0xa7,0xb6,0xd3,0xe6,0xf7,256}
  559.  
  560. local bvrec = {}
  561. local bvrecsav = {}
  562. local bvprev = 0
  563.  
  564. bvreccolor = {}
  565. for i = 0,255 do bvreccolor[i] = 8 end
  566. rulecolors={"darkred","red",
  567.             "darkgreen","green",
  568.             "blue","navy",
  569.             "silver","white",
  570.             "darkmagenta","magenta",
  571.             "goldenrod","yellow",
  572.             "darkcyan","cyan",
  573.             "darkgray","gray"}
  574.  
  575. function getValues()
  576.    
  577. --Catch the BV copy
  578.     if battlecopy == 0 and battleflag == 1 and ReadByte(BATTLE_VALUE) == ReadByte(BATTLE_STORE) then
  579.             battlecopy = 1
  580.     elseif battleflag == 0 then
  581.         battlecopy = 0
  582.     end
  583.  
  584. --Get the active PCs
  585.     mtchars = 0
  586.     for i = 1,3 do
  587.         chars[i] = ReadByte(CHAR_ID+i-1)
  588.         if chars[i] >= 0x07 then mtchars = mtchars + 1 end
  589.     end
  590.    
  591. --Value is at different address for in-battle, out-of-battle, & load menu:
  592.     if battlecopy == 1 then
  593.         bv = ReadByte(BATTLE_VALUE)
  594.         cv = ReadByte(CRIT_VALUE)
  595.     else
  596.         if (ReadByte(MENU_TIME) > 0 and ReadByte(BATTLE_STORE) == 0 and mtchars == 0) then
  597.         --menuTime is for ALL menus, BV is 0 for entire beginning... but load menu has "3 Crono's" (000000)
  598.             bv = ReadByte(MENU_TIME)
  599.             bvrec = {}
  600.         else bv = ReadByte(BATTLE_STORE) end
  601.         cv = bv
  602.     end
  603.  
  604.     --overwrite interval between each BV change
  605.     if bv > bvprev then
  606.         for i = bvprev+1,bv-1 do bvrec[i] = 0 end
  607.         bvrec[bv] = 1
  608.         bvprev = bv
  609.         bvreccolor[bv] = 8
  610.     elseif bv < bvprev then
  611.         for i = bvprev+1,255 do bvrec[i] = 0 end
  612.         for i = 0,bv-1 do bvrec[i] = 0 end
  613.         bvrec[bv] = 1
  614.         bvprev = bv
  615.         bvreccolor[bv] = 8
  616.     end
  617.  
  618.     --catch ATB reset to determine whose action it was (for color-coding)
  619.     newatb = {}
  620.     for i = 0,10 do
  621.         newatb[i] = ReadByte(ATB+i)
  622.         if atb[i] == 0 and newatb[i] ~= 0 and newatb[i] ~= 0x80 then
  623.             if bvreccolor[bv] == 8 then
  624.                 if i < 3 then
  625.                     bvreccolor[bv] = chars[i+1]
  626.                 else
  627.                     bvreccolor[bv] = 7
  628.                 end
  629.             end
  630.         end
  631.         atb[i] = newatb[i]
  632.     end
  633. end
  634.  
  635.  
  636. local charcolor = {"gold","blue","darkred","gray","darkgreen","brown","gray","gray","gray"}
  637. function displayValues()
  638.  
  639.     rulecolor = 1
  640.     for j = 1,16 do
  641.         if bv >= battlewindow[mtchars][j] and bv < battlewindow[mtchars][j+1] then
  642.             rulecolor = j
  643.         end
  644.     end
  645.     DrawText(bv-3,dispy+26,string.format("%02x",bv),rulecolors[rulecolor],"none")
  646.     DrawText(bv-259,dispy+26,string.format("%02x",bv),rulecolors[rulecolor],"none") --wrap-around
  647.    
  648.     for i = 0,255 do
  649.         for j = 1,16 do
  650.             if i >= battlewindow[mtchars][j] and i < battlewindow[mtchars][j+1] then
  651.                 rulecolor = j
  652.             end
  653.         end
  654.  
  655.         DrawPixel(i,dispy+24,rulecolors[rulecolor])
  656.         if i%4 == 0 then DrawPixel(i,dispy+25,rulecolors[rulecolor]) end
  657.         if i%16 == 0 then
  658.             DrawPixel(i,dispy+26,rulecolors[rulecolor])
  659.             DrawPixel(i,dispy+27,rulecolors[rulecolor]) end
  660.         if bvrec[i] == 1 then
  661.             DrawPixel(i,dispy+23,charcolor[bvreccolor[i]+1])
  662.             if bvreccolor[i] < 7 then
  663.                 DrawPixel(i,dispy+22,charcolor[bvreccolor[i]+1])
  664.             end
  665.         end
  666.     end
  667.     DrawPixel(bv,dispy+21,charcolor[bvreccolor[bv]+1])
  668.     DrawPixel(bv,dispy+22,charcolor[bvreccolor[bv]+1])
  669.     DrawPixel(bv,dispy+23,charcolor[bvreccolor[bv]+1]) 
  670. end
  671.  
  672.  
  673.  
  674. local emuframe = 0
  675. local moviedata = {}
  676. local movieoffset = 0
  677.  
  678. function ReadSMV()
  679.  
  680.     emuframe = emu.framecount() + 1
  681.  
  682. --Read in movie file:
  683.     if movie.mode() == "playback" and movieoffset == 0 then
  684.         f = io.open(movie.name(), "rb")
  685.         byte = f:read(1)
  686.         while byte ~= nil do
  687.             byte = string.byte(byte)
  688.             table.insert(moviedata, byte)
  689.             byte = f:read(1)
  690.         end
  691.         f:close()
  692.         for i = 0,3 do
  693.             movieoffset = movieoffset + moviedata[0x1C+1+i]*(0x100^i)
  694.         end
  695.         movielen = (table.getn(moviedata) - movieoffset) / 2
  696.     end
  697.    
  698.     --Get inputs either from movie or user:
  699.     if movie.mode() == "playback" and emuframe < movielen then
  700.         word = moviedata[movieoffset + emuframe*2 + 1] + moviedata[movieoffset + emuframe*2]*0x100
  701.         word = math.floor(word / 16)  --discard 4 lowest bits; Lua uses all doubles (floating point)
  702.         for i = 1, 12 do
  703.             if word % 2 == 1 then
  704.                 inputs[ button[i] ] = true
  705.             else inputs[ button[i] ] = nil end
  706.             word = math.floor(word / 2)
  707.         end
  708.     end
  709. end
  710.  
  711. function displayJoypad()
  712.    
  713. --Draw each button (color it based on hold duration):
  714.     for i = 1, 12 do
  715.         if inputs[button[i]] then
  716.             if unpress[i] > 0 then
  717.                 press[i] = 0
  718.                 if unpress[i] == 6 then
  719.                     turbo[i] = 1
  720.                 else
  721.                     turbo[i] = 0
  722.                 end
  723.                 unpress[i] = 0
  724.             end
  725.             if press[i] < 240 then
  726.                 press[i] = press[i] + 6
  727.             end
  728.         else
  729.             if unpress[i] ~= 0 then -- i.e. was pressed in previous frame
  730.                 turbo[i] = 0
  731.             end
  732.             if unpress[i] < 240 then
  733.                 unpress[i] = unpress[i] + 6
  734.             end
  735.         end
  736.  
  737.         shoulder = 0
  738.         if i == 1 or i == 2 then shoulder = 1 end
  739.        
  740.         buttontext = 0xc0000000
  741.         buttoncolor = 0
  742.         if inputs[button[i]] then
  743.             buttoncolor = 0xa0000000 + (0xF0-press[i])*0x10000 + 0xff80
  744.         elseif press[i] > 0 then
  745.             buttoncolor = (160-math.floor(unpress[i]*2/3))*0x1000000 + press[i]*0x10000 + 0 + (0xF0-press[i])
  746.         end
  747.         if turbo[i] == 1 then
  748.             buttontext = outfade+0xff0000
  749.             buttoncolor = 0xa0ffffff
  750.         end
  751.  
  752.         bx = 10
  753.         by = 8
  754.         DrawBox(
  755.             xoffset+xcoords[i]*bx, yoffset+ycoords[i]*by,
  756.             xoffset+xcoords[i]*bx+bx +shoulder*bx, yoffset+ycoords[i]*by+by -shoulder*3, buttoncolor, buttoncolor)
  757.         DrawText(xoffset+xcoords[i]*bx+4, yoffset+ycoords[i]*by+0,btnlabel[i],buttontext,0)
  758.     end
  759. end
  760.  
  761.  
  762. local BATTLES_X = 0x975a
  763. local BATTLES_Y = 0x9765
  764. local HP = 0x5e30
  765. local DAMAGE_SIGN = 0xb328  -- 7eb354
  766. local DAMAGE_ABS = 0xad9c
  767.  
  768. function displayHP()
  769.     for i = 3, 10 do
  770.         atb2 = ReadByte(ATB+i)
  771.         if (atb2 < 100) then
  772.             DrawText(ReadByte(BATTLES_X+i)+12,ReadByte(BATTLES_Y+i)+4,
  773.             atb2,"gray","shadow")
  774.             DrawText(ReadByte(BATTLES_X+i)-18,ReadByte(BATTLES_Y+i)+4,
  775.             string.format("%5d",ReadWord(HP+0x80*i)),"silver","shadow")
  776.         end
  777.     end
  778.     for i = 0, 2 do
  779.         atb2 = ReadByte(ATB+i)
  780.         if (atb2 < 100) then
  781.             DrawText(xoffset+177,19+12*i+(yoffset-16)*ReadByte(MENU_POS),
  782.             string.format("%2d",ReadByte(ATB+i)),"gray","shadow")
  783.         end
  784.     end
  785.     for i = 0, 10 do
  786.         dcolor = "red"
  787.         dabs = ReadWord(DAMAGE_ABS+i*4)
  788.         if (dabs ~= 0 and dabs < 0x8000) then
  789.             if (ReadWord(DAMAGE_SIGN+i*4) > 32768) then dcolor = "green" end
  790.             DrawText(ReadByte(BATTLES_X+i)-18,ReadByte(BATTLES_Y+i)-4,
  791.                 string.format("%5d",dabs),dcolor,"shadow")
  792.         end
  793.     end
  794. end
  795.  
  796.  
  797. local ran = 0
  798. local rundisp = 0
  799. local run_got = 0x99cd
  800. local run_count = 0x99cf
  801. local battle_end = 0x020c   -- "Ran away!" message called
  802. function displayRunaway()
  803.     if (ReadByte(battle_end) ~= 8) then
  804.         ran = ReadByte(run_got)
  805.         rundisp = ReadByte(run_count)
  806.     end
  807.     runcolor = "gray"
  808.     if (ran > 0) then
  809.         rundisp = ran+120
  810.         runcolor = "green"
  811.     end
  812.     DrawText(120,yoffset+37,string.format("%3d",rundisp),runcolor,"shadow")
  813. end
  814.  
  815. function TreasureCount()
  816.     ccount = 0
  817.     for i = 1,20 do
  818.         chest = ReadByte(0x10000+i)
  819.         for j = 1,8 do
  820.             if chest%2 == 1 then
  821.                 ccount = ccount + 1
  822.                 chest = chest-1
  823.             end
  824.             chest = chest/2
  825.         end
  826.     end
  827.     return ccount
  828. end
  829.  
  830. function displayFrameCount()
  831.     eframe = emuframe + 1
  832.     if (eframe > 188) and CT_Ver == "U" then eframe = eframe - 189 end
  833.     if (eframe > 138) and CT_VER == "J" then eframe = eframe - 139 end 
  834.     t0 = eframe * 60/60.098813
  835.     t_fr = ""..string.format("%.1d",(t0 % 60)/6)
  836.     t_sec = ""..string.format("%02d",(t0/60) % 60)
  837.     t_min = ""..string.format("%02d",(t0/3600) % 60)
  838.     t_hr = ""..string.format("%02d",(t0/216000))
  839.     DrawText(1,0,string.lower(CT_Ver),"silver")
  840.     DrawText(7,0,t_hr,"silver")
  841.     DrawText(14,0,":","silver")
  842.     DrawText(17,0,t_min,"silver")
  843.     DrawText(24,0,":","silver")
  844.     DrawText(27,0,t_sec,"silver")
  845.     DrawText(34,0,".","silver")
  846.     DrawText(37,0,t_fr,"silver")
  847.     DrawText(42,0,string.format("|%02d",t0%60),"silver")   
  848.     DrawText(56,0,string.format("-%d",math.abs(t0-eframe*60/59.94)),"silver")
  849.     DrawText(1,8,emuframe,"silver")
  850. end
  851.  
  852.  
  853. function Saving()
  854. --  bvrecsav = bvrec
  855. --  battleflagsav = battleflag
  856. --  locsav = loc
  857. --  framesav = frame
  858. --  locstsav = locStart
  859. --  batstartsav = batstart
  860. --  menusav = menuTime
  861. --  menu_statesav = menu_state
  862. end
  863. if BIZ then event.onsavestate(Saving)
  864. else savestate.registersave(Saving) end
  865. -- for room timing, only works with MOST RECENT state
  866.  
  867. function Reload()
  868.     bvrec = bvrecsav
  869.     battleflag = ReadByte(BATTLE_FLAG) % 2
  870.     if battlecopy == 0 and battleflag == 1 then
  871.         battlecopy = 1
  872.     elseif battleflag == 0 then
  873.         battlecopy = 0
  874.     end
  875.     loc = ReadWord(LOCATION)
  876.     loc_Prev = ReadWord(LOCATION+5)
  877.     frameInc = 0
  878.     locStart = 0
  879.     segCount = 0
  880.     segTotalTime = 0
  881.     menuTime = 0
  882.     recentload = 1
  883. end
  884. if BIZ then event.onloadstate(Reload)
  885. else savestate.registerload(Reload) end
  886.  
  887. local PAUSE = 0x0407
  888. local dispbox = 4
  889.  
  890. while true do
  891.  
  892.     emuframe = emu.framecount()
  893.     inputs = joypad.get()
  894.     getValues()
  895.  
  896.     pause = ReadByte(PAUSE)
  897.     --Catch <select> pressed
  898.     if inputs[button[10]] then
  899.         if selectheld == 0 then
  900.             selectheld = 1
  901.             if pause == 0xF5 or pause == 0xFF then -- toggle if Paused
  902.                 if dispbox == 4 then
  903.                     dispbox = 1
  904.                 else dispbox = dispbox + 1 end
  905.             end
  906.         end
  907.     else selectheld = 0 end
  908.  
  909.     if inputs[button[AUTO_TEXT]] and ReadByte(0x0129) == 7 then
  910.         confirm_button = CT_button[string.format("%x",ReadByte(0x2993))]
  911.         joypad.set( {[confirm_button]=true} )
  912.     end
  913.  
  914.     if loadmenuTime ~= ReadByte(MENU_TIME) then
  915.         if menuopen == 0 then
  916.             menuopen = 1 end
  917.     else menuopen = 0 end
  918.     loadmenuTime = ReadByte(MENU_TIME)
  919.  
  920. --Display all
  921.     if dispbox < 3 and loc < 0x1F0
  922.         and menuopen == 0 and battleflag == 0 then
  923.         displayHitbox()
  924.     end
  925.     if dispbox % 2 > 0 then
  926.         if BIZ == false then ReadSMV() end
  927.         displayJoypad()
  928.     end
  929.     if battlecopy == 1 then
  930.         displayHP()
  931.         displayRunaway()
  932.     end
  933.     if mtchars < 3 then
  934.         displayValues()
  935.         displayTime()
  936.     --Crit Value
  937.         DrawText(1,yoffset+37,string.format("%02x",cv),critcolor[tonumber(crits:sub(cv+1,cv+1))+1],"shadow")
  938.     --BattleSpeed
  939.         DrawText(1,yoffset+29,"bs"..ReadByte(0x2990)%8+1,"gray","shadow")
  940.         DrawText(1,yoffset+21,"t"..TreasureCount(),"gray","shadow")
  941.     end
  942.     displayFrameCount()
  943.    
  944.     emu.frameadvance()
  945. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement