Advertisement
redslash

ctinfoscope20160823

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