Advertisement
redslash

ctinfoscope20160829

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