User File #60045844721779290

Upload All User Files

#60045844721779290 - Battle Kid series lua complete

Battle_Kid.lua
526 downloads
Uploaded 12/18/2019 3:56 AM by Fortranm (see all 102)
Battle Kid v2.0 sprite support added by caitsith2 For Bizhawk
-- Battle Kid 2: Mountain of Torment
-- Written by CaitSith2
-- Oct 8, 2013
-- Displays Hitboxes, Enemy HP, and various stats on screen

enable_info = 1
current_run_direction = 0

--1: Battle Kid v1.x; 2: Battle Kid 2; 3:Battle Kid v2.0
local version = 1
local demo = false
local stuffSet = {0x0300, 0x0400, 0x0440}
local stuffMax = {15, 15, 11}
local timmyshotsSet = {0x0290, 0x0598, 0x0400}
local shotsexistSet = {0x0295, 0x059F, 0x0400}
local shotsexistvalueSet = {0xF8, 0xF8, 0x00}
local roomcollisionSet = {0x500, 0x0300, 0x0300}
local solidSet = {1, 0x10, 128}
local instKillSet = {2, 0x03, 32}
local flashingSpikeSType = {22, 0, 12}
local flashingSpikeSet = {102, 0, 0x10}
local flashingSpikePhaseOne = {12, 0, 15}
local flashingSpikePhaseTwo = {13, 0, 14}
local iceSet = {0, 0x11, 0x81}
local leftconveyorSet = {0, 0x12, 0x82}
local rightconveyorSet = {0, 0x13, 0x83}
local wallgripSet = {0, 0x14, 0x84}
local destroyableSet = {0, 0x15, 0x85}
local xlocSet = {0x1E, 0x31, 0x3A}
local ylocSet = {0x1D, 0x30, 0x39}
local aliveSet = {0x20, 0x70, 0x93}
local hpSet = {0, 0x82, 0x6E}
local jleftSet = {0x4D, 0x78, 0x83}
local jtotalSet = {0x4E, 0x77, 0x84}
local accelSet = {0, 0x59, 0x4E}
local runspeedSet = {0, 0x58, 0x4E}

local function line(x1,y1,x2,y2,color)
		if (enable_info == 1) then
			gui.drawLine(x1,y1+8,x2,y2+8,color)
		end
end
local function box(x1,y1,x2,y2,color)
	line(x1,y1,x1,y2,color)
	line(x1,y1,x2,y1,color)
	line(x2,y1,x2,y2,color)
	line(x1,y2,x2,y2,color)
end
local function selectivebox(x1,y1,x2,y2,color,left,right,top,bottom)
	if (left == 1) then
		line(x1,y1,x1,y2,color)
	end
	if (top == 1) then
		line(x1,y1,x2,y1,color)
	end
	if (right == 1) then
		line(x2,y1,x2,y2,color)
	end
	if (bottom == 1) then
		line(x1,y2,x2,y2,color)
	end
end
local function text(x,y,str)
	if (x >= 0 and x < 255 and y >= 0 and y < 240) then
	  xm = client.screenwidth() / 256
		ym = client.screenheight() / 224
		if (enable_info == 1) then
			gui.text(x*xm,(y)*ym,str)
		end
	end
end

enable_tas_info = 0
infinite_loop = 1
end_avi = 197000

function battlekidloop()

	framecounter = emu.framecount()
	local enable_extended_info = 1
	local enable_hud_info = 1
	local enable_debug_code = 1
	--local force_wall_grip	-- obsoleted by 3 line game genie code, YATVXN + ELYTUY + ELTVVY
	
	local info_frames = 300
	local info_1 = 1200
	local info_1_string = "Unfair 100%"
	local info_1_author = "CaitSith2"
	local info_2 = 1800
	local frame_rate = 60.098769685745869044
	local frames_per_minute = frame_rate * 60
	text(1,1,"")

	stuff = stuffSet[version];
	timmy = {0, 0, 0, 0}
	if (version == 1) then	
		if (demo == true) then
			timmy[0] = 0x0030
			timmy[1] = 0x0031
			timmy[2] = 0x0032
			timmy[3] = 0x0033
		else
			timmy[0] = 0x0031
			timmy[1] = 0x0032
			timmy[2] = 0x0033
			timmy[3] = 0x0034
		end
	elseif (version ==2) then
		if (demo == true) then
			timmy[0] = 0x005B
			timmy[1] = 0x005C
			timmy[2] = 0x005A
			timmy[3] = 0x005D
		else
			timmy[0] = 0x0054
			timmy[1] = 0x0055
			timmy[2] = 0x0056
			timmy[3] = 0x0057
		end
	else
		timmy[0] = 0x0069
		timmy[1] = 0x006B
		timmy[2] = 0x006A
		timmy[3] = 0x006C
	end
	
	timmyshots = timmyshotsSet[version]
	roomcollision = roomcollisionSet[version]
	
	timmyOffset = 24
	if (version == 3) then
		timmyOffset = 40
	end
	x1 = memory.readbyte(timmy[0])
	x2 = memory.readbyte(timmy[1])
	y1 = memory.readbyte(timmy[2]) + timmyOffset
	y2 = memory.readbyte(timmy[3]) + timmyOffset
	alive = memory.readbyte(aliveSet[version])
	hp = memory.readbyte(hpSet[version])	
	if (demo == true) then
		if (version==1) then
			alive = memory.readbyte(0x1F)
		else
			alive = memory.readbyte(0x76)
			hp = memory.readbyte(0x88)
		end
	end
	if (version==1) then
		hp = 1
		if((memory.readbyte(0) == 136) and (memory.readbyte(1) <= 10)) then
			gameaction = 1
		else
			gameaction = 0
		end
	else
		if((memory.readbyte(0x20) == 0) and (memory.readbyte(0x21) == 0)) then
			gameaction = 0
		else
			gameaction = 1
		end
	end
	
	if ((enable_extended_info == 1) and (gameaction == 1)) then

		--spritetype is structured bitwise as follows, ffffbbdd
		--ffff = flags. 0001 = box backs off one color on sprites 3-15.
		--			 0010 =
		--bb = box color. 00 = red, 01 = yellow, 10 = green, 11 = no box.
		--dd = display info. 00 = All info, 01 = no info, 10 = HP, 11 = Phase
		local spritetype = {{    0x00,0x00,0x00,0x00,0x00, 0x00,0x08,0x00,0x02,0x00,
                  0x09,0x00,0x04,0x00,0x01, 0x00,0x0A,0x00,0x08,0x00,
                  0x00,0x00,0x00,0x00,0x02, 0x00,0x08,0x00,0x00,0x00,
                  0x41,0x00,0x05,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,
                  0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x04,0x00,

                  0x14,0x00,0x08,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,
                  0x00,0x00,0x02,0x00,0x00, 0x00,0x0D,0x00,0x02,0x00,
                  0x41,0x00,0x01,0x00,0x00, 0x00,0x20,0x00,0x03,0x00,
                  0x40,0x00,0x42,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,
                  0x08,0x00,0x41,0x00,0x00, 0x00,0x41,0x00,0x08,0x00,

                  0x01,0x00,0x09,0x00,0x00, 0x00,0x41,0x00,0x00,0x00,
                  0x00,0x00,0x08,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,
                  0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,
                  0x08,0x00,0x01,0x00,0x01, 0x00,0x05,0x00,0x00,0x00,
                  0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,

                  0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,
                  0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,
                  0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,
                  0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,
                  0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,
   
                  0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,
                  0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,
                  0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,
                  0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,
                  0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,

                  0x00,0x00,0x00,0x00,0x00, 0x00,
		},{		 0x0D, 0x02, 0x09, 0x0D, 0x0D,	0x0D, 0x0C, 0x01, 0x00, 0x0D,
						0x0C, 0x02, 0x02, 0x09, 0x00,	0x00, 0x00, 0x00, 0x00, 0x00,
						0x00, 0x00, 0x0E, 0x00, 0x0D,	0x00, 0x09, 0x0D, 0x02, 0x00,
						0x00, 0x00, 0x03, 0x00, 0x00,	0x0D, 0x00, 0x00, 0x00, 0x02,
						0x00, 0x00, 0x00, 0x09, 0x09,	0x09, 0x00, 0x00, 0x00, 0x00,

						0x03, 0x00, 0x00, 0x00, 0x00,	0x00, 0x00, 0x00, 0x00, 0x00,
						0x00, 0x00, 0x00, 0x07, 0x09,	0x00, 0x00, 0x00, 0x0D, 0x00,
						0x00, 0x00, 0x00, 0x00, 0x00,	0x00, 0x00, 0x00, 0x00, 0x0D,
						0x00, 0x00, 0x00, 0x00, 0x00,	0x00, 0x00, 0x00, 0x00, 0x00,
						0x00, 0x00, 0x09, 0x09, 0x00,	0x00, 0x00, 0x00, 0x00, 0x00,
		},{    0x0D,0x00,0x00,0x00,0x00, 0x00,0x08,0x00,0x02,0x00,
                  0x09,0x00,0x04,0x00,0x01, 0x00,0x0A,0x00,0x08,0x00,
                  0x00,0x00,0x00,0x00,0x02, 0x00,0x08,0x00,0x00,0x00,
                  0x41,0x00,0x05,0x00,0x00, 0x00,0x00,0x00,0x04,0x00,
                  0x05,0x00,0x00,0x00,0x04, 0x00,0x00,0x00,0x06,0x00,

                  0x17,0x00,0x08,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,
                  0x02,0x00,0x01,0x00,0x01, 0x00,0x02,0x00,0x00,0x00,
                  0x40,0x00,0x00,0x00,0x01, 0x00,0x20,0x00,0x02,0x00,
                  0x40,0x00,0x42,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,
                  0x03,0x00,0x47,0x00,0x01, 0x00,0x40,0x00,0x42,0x00,

                  0x02,0x00,0x02,0x00,0x00, 0x00,0x42,0x00,0x00,0x00,
                  0x00,0x00,0x08,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,
                  0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,
                  0x08,0x00,0x01,0x00,0x01, 0x00,0x05,0x00,0x00,0x00,
                  0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,

                  0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,
                  0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,
                  0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,
                  0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,
                  0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,
   
                  0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,
                  0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,
                  0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,
                  0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,
                  0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,

                  0x00,0x00,0x00,0x00,0x00, 0x00,
		}};

		--draw room collision zones

		for i=0,12 do
			toprow = 24
			bottomrow = 39
			if (i == 0) then
				toprow = 36
			end
			for j=0,15 do
				top = 1
				bottom = 1
				left = 1
				right = 1
				blocktype = memory.readbyte(roomcollision + (i*16) + j)
				if(i ~= 0) then
					if (blocktype == memory.readbyte(roomcollision + ((i-1)*16) + j)) then
						top = 0
					end
				end
				if(i ~= 12) then
					if (blocktype == memory.readbyte(roomcollision + ((i+1)*16) + j)) then
						bottom = 0
					end
				end
				if(j ~= 0) then
					if (blocktype == memory.readbyte(roomcollision + (i*16) + (j-1))) then
						left = 0
					end
				end
				if(j ~= 15) then
					if (blocktype == memory.readbyte(roomcollision + (i*16) + (j+1))) then
						right = 0
					end
				end

				if(blocktype == instKillSet[version]) then		--Instant Kill Object
					selectivebox(j*16,toprow+(i*16),15+(j*16),bottomrow+(i*16),"red",left,right,top,bottom)
					line(j*16,toprow+(i*16),15+(j*16),bottomrow+(i*16),"red")
					line(15+(j*16),toprow+(i*16),j*16,bottomrow+(i*16),"red")
				elseif(blocktype == flashingSpikeSet[version] and version ~= 2) then		--Blinking spike in its Off state (BK1)
					selectivebox(j*16,toprow+(i*16),15+(j*16),bottomrow+(i*16),"yellow",left,right,top,bottom)
					line(j*16,toprow+(i*16),15+(j*16),bottomrow+(i*16),"yellow")
					line(15+(j*16),toprow+(i*16),j*16,bottomrow+(i*16),"yellow")
				elseif(blocktype >= solidSet[version]) then		--Solid Object
					selectivebox(j*16,toprow+(i*16),15+(j*16),bottomrow+(i*16),"cyan",left,right,top,bottom)
					if(blocktype > solidSet[version] and version ~= 1) then		--BK2
						if(blocktype == iceSet[version]) then	--Ice
							line(j*16,toprow+(i*16),(j*16)+8,(toprow+(i*16))+8,"cyan")
							line((j*16)+8,toprow+(i*16),(j*16)+15,(toprow+(i*16))+8,"cyan")
						elseif(blocktype == leftconveyorSet[version]) then	--conveyer belt <<<
							line(j*16,toprow+8+(i*16),15+(j*16),bottomrow+(i*16),"cyan")
							line(15+(j*16),toprow+(i*16),j*16,bottomrow-8+(i*16),"cyan")
						elseif(blocktype == rightconveyorSet[version]) then	--conveyer belt >>>
							line(j*16,toprow+(i*16),15+(j*16),bottomrow-8+(i*16),"cyan")
							line(15+(j*16),toprow+8+(i*16),j*16,bottomrow+(i*16),"cyan")
						elseif(blocktype == wallgripSet[version]) then	--Wallgrip objects
							line(j*16,toprow+(i*16),15+(j*16),bottomrow+(i*16),"cyan")
							line(15+(j*16),toprow+(i*16),j*16,bottomrow+(i*16),"cyan")
						elseif(blocktype == destroyableSet[version]) then	--Rune spectre destroyable blocks
							line((j*16)+8,toprow+(i*16),(j*16)+8,bottomrow+(i*16),"cyan")
							line(j*16,toprow+(i*16)+8,(j*16)+15,toprow+(i*16)+8,"cyan")
							line((j*16)+8,toprow+(i*16),(j*16)+15,(toprow+(i*16))+8,"cyan")
							line((j*16)+8,bottomrow+(i*16),(j*16)+15,(toprow+(i*16))+8,"cyan")
							line((j*16)+8,toprow+(i*16),j*16,(toprow+(i*16))+8,"cyan")
							line((j*16)+8,bottomrow+(i*16),j*16,(toprow+(i*16))+8,"cyan")
						end		
					end
				end
			end
		end

		--text(x1,y1-8,string.format("%03d,%03d",x1,y1))
		if (alive == 0 and hp > 0) then
			box(x1,y1,x2,y2,"green")
		elseif (version > 1 and hp > 0) then --Invincibility time
			box(x1,y1,x2,y2,"yellow")
			line(x1,y1,x2,y2,"yellow")
			line(x1,y2,x2,y1,"yellow")
		else
			box(x1,y1,x2,y2,"red")
			line(x1,y1,x2,y2,"red")
			line(x1,y2,x2,y1,"red")
		end
		
		shotsleft=3
		for i=0,2 do
			if (version == 3) then
				timmyshotexists = memory.readbyte(shotsexistSet[version]+(i*16))
			else
				timmyshotexists = memory.readbyte(shotsexistSet[version]+(i*8))
			end
			if(timmyshotexists ~= shotsexistvalueSet[version]) then
                if (version == 3) then
                    x1 = memory.readbyte(timmyshots+5+(i*16))
				    x2 = memory.readbyte(timmyshots+7+(i*16))
				    y1 = memory.readbyte(timmyshots+6+(i*16)) + 40
				    y2 = memory.readbyte(timmyshots+8+(i*16)) + 40
                else
				    x1 = memory.readbyte(timmyshots+1+(i*8))
				    x2 = memory.readbyte(timmyshots+2+(i*8))
				    y1 = memory.readbyte(timmyshots+3+(i*8)) + 24
				    y2 = memory.readbyte(timmyshots+4+(i*8)) + 24
                end
				shotsleft = shotsleft - 1
				box(x1,y1,x2,y2,"green")
			end
		end
		text(35,8,string.format("Shots:%d/3",shotsleft))
		
		for i=0,stuffMax[version] do --enemy sprites
			if (version == 2) then
                stype = memory.readbyte(stuff+(i*16)) / 2
			else
				stype = memory.readbyte(stuff+(i*16));
			end
			if(spritetype[version][stype+1] == nil) then
                text(88,32,string.format("Failed to get spritetype for Version:%d stype:%d",version,stype))
				break	--Invalid sprite type.  Game has very likely crashed
				--As such, there is no point in running the rest of this script section.
			end
			spritedisplay = bit.band(spritetype[version][stype+1],3)
			spritebox = bit.band(spritetype[version][stype+1],12)
			spriteflags = bit.band(spritetype[version][stype+1],240)
			spriteexists = memory.readbyte(stuff+8+(i*16))
			if (bit.band(spriteflags,0x10) == 0x10) then
				if (i >= 3) then
					spritebox = spritebox - 4
					if (spritebox < 0) then
						spritebox = 12
					end
				end
			end
			if (bit.band(spriteflags,0x20) == 0x20) then
				if (i >= 3) then
					spritedisplay = 1
				end
			end

------------------------------ COMMON VARIABLES ---------------------------------------------------
		if (version < 3) then
			phase = memory.readbyte(stuff+1+(i*16))
			x1 = memory.readbyte(stuff+2+(i*16))
			x2 = memory.readbyte(stuff+3+(i*16))
			y1 = memory.readbyte(stuff+4+(i*16)) + 24
			y2 = memory.readbyte(stuff+5+(i*16)) + 24
		else
			phase = memory.readbyte(stuff+4+(i*16))
			x1 = memory.readbyte(stuff+5+(i*16))
			x2 = memory.readbyte(stuff+7+(i*16))
			y1 = memory.readbyte(stuff+6+(i*16)) + 40
			y2 = memory.readbyte(stuff+8+(i*16)) + 40
		end

		if (version == 2) then --Battle Kid 2: Mountain of Torment
		
------------------------------ BOSS HANDLERS ------------------------------------------------------
			if (stype == 18) then	--Boss/minigame/locked door spawner
				spawntype = memory.readbyte(stuff+11+(i*16))
				if(spawntype == 0x42) then
					timer = memory.readbyte(stuff+13+(i*16))
					text(x1,y1+8,timer)
					break;
				end
			end

			if (stype == 55) then	--Handle Night Mission Boss
				if(i == 1) then
					spritedisplay = 0
					ZeddState = memory.readbyte(stuff+11+(i*16))
					if ((ZeddState == 0) or (ZeddState <= 6)) then
						text(90,32,"Tossing Electric Sparks")
					elseif ((ZeddState >= 8) and (ZeddState <= 10)) then
						text(90,32,"Last Spark")
					elseif ((ZeddState >= 12) and (ZeddState <= 14)) then
						text(90,32,"Charging up")
					elseif ((ZeddState >= 16) and (ZeddState <= 20)) then
						text(90,32,"Dashing Across Room")
					elseif ((ZeddState >= 22) and (ZeddState <= 26)) then
						text(90,32,"Staying in one spot")
					end
				end
				spritebox = 12
				box(x1,y1,x2,y2,"red")
				
			end

			if ((stype == 42) or (stype == 83)) then	--Hantairei'mos
				spritebox = 12
				box(x1,y1,x2,y2,"red")
				if(i==0) then
					spritedisplay = 3
				end
			end
			
			if ((stype == 53) or (stype == 85)) then	--Misha
				spritebox = 12
				box(x1,y1,x2,y2,"red")
				--if(i==0) then
				--	spritedisplay = 3
				--end
			end

			if ((stype == 54) or (stype == 86)) then	--Helga Kraftie, Power station version
				spritebox = 12
				box(x1,y1,x2,y2,"red")
			end

			if ((stype == 56) or (stype == 87)) then	--Doppleganger either being constructed or dying
				if (i == 0) then	--Doppleganger constructor phase
					hp = memory.readbyte(stuff+6+(i*16))
					if ((hp == 13) or (hp == 12)) then
						text(24,72,"One doppleganger clone, no abilities")
					elseif (hp == 11) then
						text(24,72,"Two doppleganger clones, no abilities")
					elseif (hp == 10) then
						text(24,72,"Three doppleganger clones, Jump")
					elseif (hp == 9) then
						text(24,72,"Five doppleganger clones, Jump")
					elseif (hp == 8) then
						text(24,72,"Six doppleganger clones, Jump")
					elseif (hp == 7) then
						text(24,72,"Five doppleganger clones, Jump, Feather")
					elseif (hp == 6) then
						text(24,72,"Six doppleganger clones, Jump, Feather")
					elseif (hp == 5) then
						text(24,72,"Three doppleganger clones, Jump lust")
					elseif (hp == 4) then
						text(24,72,"Six doppleganger clones, Jump lust")
					elseif (hp == 3) then
						text(24,72,"Three doppleganger clones, Double Jump")
					elseif (hp == 2) then
						text(24,72,"Two doppleganger clones, Double Jump, 5HP")
					elseif (hp == 1) then
						text(24,72,"Two doppleganger clones, Attack shots, 5HP")
					elseif (hp == 0) then
						text(24,64,"One doppleganger clone")
						text(24,72,"Attack Shots, 5HP, Jump")
					else
						text(24,72,"The TIMMY :)")
					end
				end
				spritebox = 12
				spritedisplay = 3
				if (phase < 12) then
					box(x1,y1,x2,y2,"yellow")
				elseif (phase == 12) then
					box(x1,y1,x2,y2,"red")
				elseif (phase == 34) then
					box(x1,y1,x2,y2,"red")
					spritedisplay = 1
				else
					spritedisplay = 1
				end
			end;
			
			if (stype == 57) then	--Doppleganger in action
				spritebox = 0
				spritedisplay = 2
			end;

			if (stype == 58) then	--The Timmy :)
				spritebox = 12
				if (i ~= 1) then
					spritedisplay = 1
				end
				box(x1,y1,x2,y2,"red")
			end;

			if (stype == 69) then	--Doppleganger exploding
				spritebox = 12
				spritedisplay = 1
			end

			if (stype == 68) then
				spritebox = 12
				if (i==0) then
					stype = memory.readbyte(stuff+0+16)/2
					ZeddState = memory.readbyte(stuff+11+(16))
					if ((stype == 19) or (stype == 80)) then	--Handle Golem Boss
						spritedisplay = 0
						if ((ZeddState == 18) or (ZeddState <= 2)) then
							text(90,32,"Manipulate Luck Now")
						elseif ((ZeddState >= 4) and (ZeddState <= 6)) then
							text(90,32,"Group of 3 Balls")
						elseif ((ZeddState >= 8) and (ZeddState <= 10)) then
							text(90,32,"Targeting Blue Balls")
						elseif (ZeddState == 12) then
							text(90,32,"End of Blue Balls")
						elseif ((ZeddState >= 14) and (ZeddState <= 16)) then
							text(90,32,"Yellow Goop")
						end
						spritebox = 12
						box(x1,y1,x2,y2,"red")
					end
					if ((stype == 31) or (stype == 81)) then		--Verdigrime
						
						if (ZeddState == 0) then
							text(90,32,"Waiting phase - Open fire")
						elseif (ZeddState == 2) then
							text(90,32,"End of Waiting phase")
							text(90,40,"Manipulate Luck during Attacks")
						elseif ((ZeddState >= 4) and (ZeddState <= 8)) then
							text(90,32,"Targeted Eye Slime Attack")
						elseif ((ZeddState >= 10) and (ZeddState <= 16)) then
							text(90,32,"Mouth Slime spray attack")
						elseif ((ZeddState >= 18) and (ZeddState <= 22)) then
							text(90,32,"Ceiling Slime Attack")
						end
						box(x1,y1,x2,0x8F+24,"red")
					end
					if ((stype == 34) or (stype == 82)) then	--Ivan 2
						if (ZeddState <= 4) then
							text(90,32,"Making Ice column")
						elseif ((ZeddState >= 6) and (ZeddState <= 14)) then
							text(90,32,"Shooting Ice Ghost")
						elseif((ZeddState >= 16) and (ZeddState <= 30)) then
							text(90,32,"Shooting Icicles")
						elseif((ZeddState >= 32) and (ZeddState <= 44)) then
							text(90,32,"Shooting Ice bullet spread")
						end
						box(x1,y1,x2,0xAF+24,"red")
					end
				else
					box(x1,y1,x2,y2,"red")
				end
			end

			if (stype == 84) then	--Lobstor bot
				spritebox = 12
				box(x1,y1,x2,y2,"red")
				for j=0,15 do
					stype = memory.readbyte(stuff+(j*16))
					if (stype == 68) then
						x1 = memory.readbyte(stuff+2+(j*16))
						x2 = memory.readbyte(stuff+3+(j*16))
						y1 = memory.readbyte(stuff+4+(j*16)) + 24
						y2 = memory.readbyte(stuff+5+(j*16)) + 24
						box(x1,y1,x2,y2,"red")
					end
				end
			end

			if (stype == 70) then	--Muckswimmer
				spritebox = 12
				if(phase ~= 4) then
					spritedisplay = 1
				else
					box(x1,y1,x2,y2,"red")
				end
			end

			if (stype == 96) then	--Pinkface
				dirchange = memory.readbyte(0x6BC)
				current_suit = memory.readbyte(0x6E5)
				spritebox = 12
				box(x1,y1,x2,y2,"red")
				if(current_suit == 0) then
					text(16,32,"Current suit is Hearts")
				elseif (current_suit == 1) then
					text(16,32,"Current suit is Diamonds")
				elseif (current_suit == 2) then
					text(16,32,"Current suit is Spades")
				else
					text(16,32,"Current suit is Clubs")
				end
				text(16,40,string.format("Direction change in %d suit changes",dirchange))

				for j=0,15 do
					stype = memory.readbyte(stuff+(j*16))
					if (stype == 68) then
						x1 = memory.readbyte(stuff+2+(j*16))
						x2 = memory.readbyte(stuff+3+(j*16))
						y1 = memory.readbyte(stuff+4+(j*16)) + 24
						y2 = memory.readbyte(stuff+5+(j*16)) + 24
						timer1 = memory.readbyte(stuff+13+(j*16))
						timer2 = memory.readbyte(stuff+14+(j*16))
						if(current_suit == 0) then
							if(timer2 > 0) then
								box(x1,y1,x2,y2,"yellow")
								text(x1,y1+8,timer2)
							else
								box(x1,y1,x2,y2,"red")
								text(x1,y1+8,timer1)
							end
						elseif (current_suit == 3) then
							box(x1,y1,x2,y2,"red")
							line(0,y1,255,y1,"yellow")
							line(0,y2,255,y2,"yellow")
						end
					end
				end
			end


------------------------------ END OF BOSS HANDLERS -----------------------------------------------


------------------------------ SPRITE HANDLERS ----------------------------------------------------
			if (stype == 3) then	--Dying sprite
				spritebox = 12
				spritedisplay = 1
			end

			if (stype == 4) then	--Shot Cannons
				timeleft = memory.readbyte(stuff+14+(i*16))
				for j=0,7 do
					stype2 = memory.readbyte(stuff+0+(j*16)) / 2
					x2 = memory.readbyte(stuff+2+(j*16))
					y2 = memory.readbyte(stuff+4+(j*16)) + 24
					timeleft2 = memory.readbyte(stuff+14+(j*16))
					if((x1 == x2) and (y1 == y2) and (timeleft2 < timeleft) and (stype2 == 4)) then
						if(j < i) then
							break
						end
						timeleft = timeleft2
					end
					if (j==7) then
						text(x1,y1+8,timeleft)
						box(x1,y1,x1+7,y1+7,"yellow")
					end
				end
			end

			if ((stype == 5) or  (stype == 6) or (stype == 9)) then	--shots
				if ((x2 ~=0) or ((y2-24) ~= 0)) then
					box(x1,y1,x2,y2,"red")
				end;
			end

			if (stype == 12) then	--Eye Sniper
				timeleft = memory.readbyte(stuff+14+(i*16))
				text(x1,y1+8,timeleft)
			end

			if (stype == 14) then	--Lock Blocks
				spritebox = 12
				spritedisplay = 1
				keyrequired = memory.readbyte(stuff+6+(i*16))
				keys = memory.readbyte(0x89)
				if(bit.band(keys,keyrequired) == keyrequired) then
					box(x1,y1,x2,y2,"red")
				end
			end

			if (stype == 15) then	--Pickaxe Chuck
				spritedisplay = 2
				timer = memory.readbyte(stuff+13+(i*16))
				if(phase == 2) then
					text(x1,y1+8,timer+30)
				elseif (phase == 4) then
					text(x1,y1+8,timer)
				elseif (phase == 6) then
					text(x1,y1+8,timer+86)
				elseif (phase == 8) then
					text(x1,y1+8,timer+70)
				end
			end

			if (stype == 16) then	--Boss Door
				spritedisplay = 1
			end

			if (stype == 21) then	--Sqlungy
				spritedisplay = 2
				updown = memory.readbyte(stuff+1+(i*16))
				if (updown < 8) then
					line(x1+6,y1,x1+6,0,"yellow")
					--line(x1+7,y1,x1+7,0,"yellow")
					--line(x1+8,y1,x1+8,0,"yellow")
					line(x1+9,y1,x1+9,0,"yellow")
				else
					line(x2-6,y2,x2-6,240,"yellow")
					--line(x2-7,y2,x2-7,240,"yellow")
					--line(x2-8,y2,x2-8,240,"yellow")
					line(x2-9,y2,x2-9,240,"yellow")
				end
			end

			if (stype == 22) then	--shots
				if (i<8) then
					timeleft = memory.readbyte(stuff+13+(i*16))
					for j=0,7 do
						stype2 = memory.readbyte(stuff+0+(j*16))/2
						timeleft2 = memory.readbyte(stuff+13+(j*16))
						x3 = memory.readbyte(stuff+2+(j*16))
						y3 = memory.readbyte(stuff+4+(j*16)) + 24
						if((x1 == x3) and (y1 == y3) and (timeleft2 < timeleft) and (stype2 == 22)) then
							if(j<i) then
								break
							end
							timeleft = timeleft2
						end
						if(j==7) then
							box(x1,y1,x1+15,y1+15,"yellow")
							text(x1,y1+8,timeleft)
						end
					end
				else
					box(x1,y1,x2,y2,"red")
				end
			end

			if (stype == 24) then	--Turbine
				type = memory.readbyte(stuff+1+(i*16))
				if (type < 9) then
					box(x1,y1,x2,y2,"red")
					line(x1,y1,x2,y2,"red")
					line(x1,y2,x2,y1,"red")
					timeleft = memory.readbyte(stuff+13+(i*16))
					if (type == 8) then
						text(x1,y1+8,timeleft+90)
					elseif (type == 2) then
						text(x1,y1+8,timeleft+30)
					else
						text(x1,y1+8,timeleft)
					end
				end
			end
			if (stype == 25) then	--megaman style disappearing blocks
				spritedisplay = 1
				spritebox = 12
				type = memory.readbyte(stuff+12+(i*16))
				timer = memory.readbyte(stuff+13+(i*16))
				if(phase < 8) then
					box(x1,y1,x2,y2,"yellow")
					if(type == 17) then	--Ice
						line(x1,y1,x1+8,y1+8,"yellow")
						line(x1+8,y1,x2,y1+8,"yellow")
					elseif(type == 18) then	--conveyer belt
						line(x2,y1,x1,y1+8,"yellow")
						line(x2,y2,x1,y1+8,"yellow")
					elseif(type == 19) then	--conveyer belt
						line(x1,y1,x2,y1+8,"yellow")
						line(x1,y2,x2,y1+8,"yellow")
					elseif(type == 20) then	--Wallgrip objects
						line(x1,y1,x2,y2,"yellow")
						line(x1,y2,x2,y1,"yellow")
					end
				end
				text(x1,y2,timer)
			end

			if (stype == 26) then	--Timmy's breath bubbles.
				spritebox = 12
			end

			if (stype == 27) then	--Immortal Jelly
				hp = memory.readbyte(stuff+6+(i*16))
				timer = memory.readbyte(stuff+13+(i*16))
				if(phase <= 8) then
					box(x1,y1,x2,y2,"red")
					text(x1,y1,hp)
				elseif(phase == 10) then
					text(x1,y1+8,timer+147)
				elseif(phase == 12) then
					text(x1,y1+8,timer+27)
				elseif(phase == 14) then
					text(x1,y1+8,((hp-1)*3)+timer)
				end
				
			end

			if (stype == 28) then		--Squeex
				direction = memory.readbyte(stuff+11+(i*16))
				timer = memory.readbyte(stuff+13+(i*16))
				shots = memory.readbyte(stuff+14+(i*16))
				if(phase == 4) then
					text(x1,y1+8,39)
				elseif(phase >= 6) then
					if(shots == 3) then
						timer = timer + 7 + 7 + 21
					end
					if(shots == 2) then
						timer = timer + 7 + 21
					end
					if (shots == 1) then
						timer = timer + 21
					end
					text(x1,y1+8,timer)
				end
				if(direction == 1) then
					line(x1,y1+7,255,y1+7,"yellow")
					line(x1,y2-1,255,y2-1,"yellow")
				else
					line(0,y1+7,x2,y1+7,"yellow")
					line(0,y2-1,x2,y2-1,"yellow")
				end
			end

			if(stype == 29) then	--spirit conjurer/stalking spirit
				spritedisplay = 1
				hp = memory.readbyte(stuff+6+(i*16))
				timer1 = memory.readbyte(stuff+13+(i*16))
				timer2 = memory.readbyte(stuff+14+(i*16))
				if(phase == 2) then
					text(x1,y1+8,timer1+36)
				elseif(phase == 4) then
					text(x1,y1+8,((timer1-1)+((timer2-1)*6))+1)
				end
				if(phase <= 6) then
					text(x1,y1,hp)
				end
			end

			if(stype == 30) then	--Orbit Drone
				spritedisplay = 1
			end

			if(stype == 32) then	--Bone spears
				spritebox = 12
				spritedisplay = 1
				timer = memory.readbyte(stuff+13+(i*16))
				if(phase < 16) then
					text(x1,y2,timer)
				else
					text(x1,y1-8,timer)
				end
				if((phase == 2) or (phase == 16)) then
					box(x1,y1,x2,y2,"yellow")
				else
					box(x1,y1,x2,y2,"red")
				end
			end;	

			if (stype == 35) then	--Eletric Barriers
				count1 = memory.readbyte(stuff+11+(i*16))
				count2 = memory.readbyte(stuff+13+(i*16))
				if(count1 > 0) then
					text(x1,y1+8,((count1-1)*10)+count2)
				else
					box(x1,y1,x2,y2,"red")
				end
			end

			if (stype == 37) then	--Voltsphere
				spritebox = 12
				spritedisplay = 2
				box(x1,y1,x2,y2,"red")
				timer1 = memory.readbyte(stuff+13+(i*16))
				timer2 = memory.readbyte(stuff+11+(i*16))
				timer3 = 3 - ((phase / 2) - 1)
				if(phase <= 8) then
					text(x1,y1+8,((timer2-1)*4)+timer3+21)
				elseif (phase == 10) then
					text(x1,y1+8,timer1)
				elseif (phase == 12) then
					text(x1,y1+8,timer1+30+48+21)
				elseif (phase == 14) then
					text(x1,y1+8,timer1+48+21)
				elseif (phase == 16) then
					text(x1,y1+8,timer1+48+21)
				end
			end

			if (stype == 38 and demo == false) then	--To'skuuth
				spritebox = 12
				spritedisplay = 2
				count = memory.readbyte(stuff+13+(i*16))
				if((phase >= 8) and (phase <= 14)) then
					box(x1,y1,x2,y2,"red")
				else
					box(x1,y1,x2,y2,"yellow")
				end;
				local countoffset = { 28, count, count - 1, 36, 21, 1, 0, count + 70, count + 69, 70, 69 }
				text(x1,y1+8,count+countoffset[phase/2])
			end

			if (stype == 39) then	--Rune Spectre
				count1 = memory.readbyte(stuff+15+(i*16))
				count2 = memory.readbyte(stuff+13+(i*16))
				x2 = memory.readbyte(timmy[0])
				y2 = memory.readbyte(timmy[2]) + 24
				if (phase == 10) then
					line(x1+8,y1,x2+7,y2+7,"green")
				elseif ((phase == 12) or (phase == 14)) then
					line(x1+8,y1,x2+7,y2+7,"red")
				else
					line(x1+8,y1,x2+7,y2+7,"yellow")
				end
				if(phase <= 8) then
					if((phase == 2) or (phase == 6)) then
						offset = 1
					else
						offset = 0
					end
					text(x1,y1+8,((count1-1)*4)+count2+offset)
				elseif (phase == 10) then
					text(x1,y1+8,count2)
				end
			end

			if (stype == 41) then	--Timed Sprite spawner
				spritebox = 12
				timer1 = memory.readbyte(stuff+12+(i*16))
				timer2 = memory.readbyte(stuff+13+(i*16))
				if(phase < 6) then
					x1 = memory.readbyte(stuff+2+((i+1)*16))
					y1 = memory.readbyte(stuff+4+((i+1)*16)) + 24
					box(x1,y1,x1+15,y1+15,"yellow")
					text(x1,y1,((timer1-1)*60)+timer2)
				end
			end
			
			if (stype == 47) then	--Yeti
				spritebox = 12
				box(x1,y1,x2,y2,"red")
				if(phase == 14) then
					spritedisplay = 2
				end
			end

			if (stype == 50) then	--Spiked Crusher
				spritebox = 12
				type = memory.readbyte(stuff+15+(i*16))
				x3 = memory.readbyte(stuff+11+(i*16))
				y3 = memory.readbyte(stuff+12+(i*16)) + 24
				line(x3,y3,x3+15,y3+15,"yellow")
				line(x3+15,y3,x3,y3+15,"yellow")
				if ((type == 2) or (type == 6)) then
					line(x3,36,x3,y3,"yellow")
					line(x3,y3+15,x3,240,"yellow")
					line(x3+15,36,x3+15,y3,"yellow")
					line(x3+15,y3+15,x3+15,240,"yellow")
				end
				if ((type == 4) or (type == 6)) then
					line(0,y3,x3,y3,"yellow")
					line(x3+15,y3,256,y3,"yellow")
					line(0,y3+15,x3,y3+15,"yellow")
					line(x3+15,y3+15,256,y3+15,"yellow")
				end
				box(x1,y1,x2,y2,"red")
			end

			if (stype == 51) then	--Binary Zap minigame
				spritebox = 12
				if(i > 0) then
					local bdigits = { 0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01 }
					if(bit.band(memory.readbyte(stuff+12),bdigits[i]) == bdigits[i]) then
						box(x1,0x50+24,x2,0xA0+24,"yellow")
						for j=0,4 do
							line(x1,0x50+24+(j*16),x2,0x60+24+(j*16),"yellow")
							line(x2,0x50+24+(j*16),x1,0x60+24+(j*16),"yellow")
						end
					end
					box(x1,y1,x2,y2,"red")
				end
			end

			if (stype == 64) then	--Portals
				spritebox = 12
				dx = memory.readbyte(stuff+11+(i*16))
				dy = memory.readbyte(stuff+12+(i*16))
				if((dx == 0x19) and (dy == 0)) then
					box(x1,y1,x2,y2,"red");	--This is the land of pointy things, at 25,00. don't want to go here :)
				else
					box(x1,y1,x2,y2,"green")
				end
			end

			if (stype == 65) then	--Simon says minigame
				spritebox = 12
				spritedisplay = 1
				if(i>=3) then
					correct_corner_offset = memory.readbyte(stuff+12+(2*16))
					corner = memory.readbyte(stuff+11+(i*16))
					if(corner == memory.readbyte(0x708 + correct_corner_offset)) then
						box(x1,y1,x2,y2,"green")
					else
						box(x1,y1,x2,y2,"red")
					end
				end
			end

			if (stype == 72) then	--Icicle
				spritedisplay = 1
				spritebox = 12
				box(x1,y1,x2,y2,"red")
				direction = memory.readbyte(stuff+12+(i*16))
				if(bit.band(direction,0xC0) == 0x00) then
					line(x1,y2,x1,240,"yellow")
					line(x2,y2,x2,240,"yellow")
				elseif(bit.band(direction,0xC0) == 0x40) then
					line(x2,y1,256,y1,"yellow")
					line(x2,y2,256,y2,"yellow")
				elseif(bit.band(direction,0xC0) == 0x80) then
					line(x1,y1,x1,40,"yellow")
					line(x2,y1,x2,40,"yellow")
				elseif(bit.band(direction,0xC0) == 0xC0) then
					line(x1,y1,0,y1,"yellow")
					line(x2,y2,0,y2,"yellow")
				end
			end

			if (stype == 98) then	-- This is only present in the Demo version.  In the full version, this sprite type
						-- does absolutely nothing, as it never leaves phase 0.
				if(phase > 0) then
					text(8,200,"Next room to the left will end this demo")
				end
			end
------------------------------ END OF SPRITE HANDLERS ----------------------------------------------------
			
		elseif (version == 1) then	--Battle Kid: Fortress of Peril Version 1.0 / 1.1
		
------------------------------ BOSS HANDLERS ------------------------------------------------------		
         if ((stype == 36) or (stype == 110) or (stype == 138)) then   --Handle Lotus Gaurdian   (and Petunia of pain)
            if ((i==0) or (i==2)) then
               spritebox = 12
               box(x1,y1,x2,y2,"red");
            end;
         end;
         if ((stype == 114) or (stype == 70)) then   --Handle OwlBot
            if ((i == 4) or (i == 0)) then
               spritedisplay = 0;
            end;
            if (i == 4) then
               line(x2+1,y2,x2+1,224,"yellow");
               line(x2,y2,x2,224,"yellow");
            end;
            if (i == 1) then
               spritedisplay = 0;
               spritebox = 12;
               box(0,40,88,200,"red")
            end;
         end;
         if ((stype == 116) or (stype == 76)) then   --Handle Cleo
            if (i==0) then
               spritebox = 12
               box(x1,y1,x2,y2,"red");
            end;
            cleo = memory.readbyte(stuff + 15);
            if(cleo == 0) then
               text(128,8,"Red")
            end;
            if(cleo == 1) then
               text(128,8,"Blue")
            end;
            if(cleo == 2) then
               text(128,8,"Purple")
            end;
            if(cleo == 3) then
               text(128,8,"Pink")
            end;
            if(cleo == 4) then
               text(128,8,"Yellow")
            end;
            if(cleo == 5) then
               text(128,8,"Green")
            end;
         end;
         if (stype == 80) then   --Handle nagaconda displaying specifically.
            nagaconda = memory.readbyte(stuff+10+(i*16))
            if (i == 1) then
               spritebox = 12;
            end;
            if((i >= 2)) then
               spritedisplay = 1;
            end;
            if (i == 5) then
               spritedisplay = 3;
            end;
            if (i == 12) then
               if (nagaconda == 3) then
                  spritedisplay = 2;
               end;
            end;
         end;
         if (stype == 92) then   --Handle Seahorse Turret.
            seahorsenext = {2,3,1,0,0}
            seahorsefire = memory.readbyte(stuff+13)
            seahorsetimer = memory.readbyte(stuff+12)
            seahorsebullets = memory.readbyte(stuff+14)
            j = 0;
            if(seahorsebullets == 0) then
               seahorsefire = 3;
            end;
            while((j < 4) and (seahorsefire < 4)) do
               hp = memory.readbyte(stuff+5+((seahorsenext[seahorsefire+1]+1)*16))
               --text(128,24+(8*seahorsefire),hp);
               if (memory.readbyte(stuff+5+((seahorsenext[seahorsefire+1]+1)*16))==0) then
                  seahorsefire = seahorsefire - 1;
                  if(seahorsefire < 0) then
                     seahorsefire = 3;
                  end;
               else
                  break;
               end;
               j = j + 1;
            end;
            if(seahorsefire < 4) then   --Check that there is at least one seahorse turret still alive.
               spritezero = memory.readbyte(stuff)
               if (spritezero == 92) then
                  text(128,8,seahorsebullets/4);
               end;
               --text(128,8,seahorsefire);
               --text(128,16,seahorsenext[seahorsefire+1]);
               if ((i >= 1) and (i <= 5)) then
                  spritedisplay = 2;
               end;
               if ((i-1) == (seahorsenext[seahorsefire+1])) then
                  spritebox = 4;
                  text(x1,y1+10,seahorsetimer);
               else
                  spritebox = 0;
               end;
            end;
         end;
         if (stype == 96) then   --Handle Amethyst Angel
            if(i == 0) then
               spritedisplay = 0
            end;
            if(i == 1) then
               spritebox = 12;
            end;
            if(i == 2) then
               box(x1,y1,x2,y2,"red");
               corner = memory.readbyte(stuff+12+(i*16));
               x1 = 0
               y1 = 0
               x2 = 60
               y2 = 17
               if (corner == 0) then
                  box(x1+15,y1+84,x2+15,y2+84,"red");
               end;
               if (corner == 4) then
                  box(x1+180,y1+84,x2+180,y2+84,"red");
               end;
               if (corner == 8) then
                  box(x1+15,y1+148,x2+15,y2+148,"red");
               end;
               if (corner == 12) then
                  box(x1+180,y1+148,x2+180,y2+148,"red");
                  --box((11*16)+4,(8*16)+24-4,15*16,(9*16)+24-2,"red");
               end;
            end;
         end;
         if ((stype == 100) or (stype == 126)) then   --Handle Zedd
            if(i == 0) then
               spritedisplay = 0
               ZeddState = memory.readbyte(stuff+7+(i*16));
               if ((ZeddState >= 32) and (ZeddState <= 50)) then
                  --Freeze attack in middle of room
                  text(90,0,"Freeze Attack");
                  text(90,8,"Middle of Room");
                  box(112,32,143,169,"green")
               end;
               if ((ZeddState >= 88) and (ZeddState <= 102)) then
                  --Side to Side hopping
                  text(90,0,"Side to Side");
                  text(90,8,"hopping");
                  box(0,70+24,255,121+24,"green")
               end;
               if ((ZeddState >= 2) and (ZeddState <= 20)) then
                  --Teleporting
                  spriteone = memory.readbyte(stuff+8+(14*16))
                  spritetwo = memory.readbyte(stuff+8+(15*16))
                  if ((spriteone == 248) and (spritetwo == 248)) then
                     text(90,0,"Teleporting");
                  else
                     text(90,0,"Teleport Attack");
                  end;
               end;
               if ((ZeddState >= 56) and (ZeddState <= 84)) then
                  --Freeze Attack at end of room
                  text(90,0,"Freeze Attack");
                  text(90,8,"Side of Room");
                  x1 = memory.readbyte(stuff+2+(14*16));
                  x2 = memory.readbyte(stuff+3+(14*16));
                  y1 = memory.readbyte(stuff+4+(14*16)) + 24;
                  y2 = memory.readbyte(stuff+5+(14*16)) + 24;
                  x3 = memory.readbyte(stuff+2+(15*16));
                  x4 = memory.readbyte(stuff+3+(15*16));
                  y3 = memory.readbyte(stuff+4+(15*16)) + 24;
                  y4 = memory.readbyte(stuff+5+(15*16)) + 24;
                  spriteone = memory.readbyte(stuff+8+(14*16))
                  spritetwo = memory.readbyte(stuff+8+(15*16))
                  if ( (y2-y3) < 32 ) then
                     if ((spriteone < 248) and (spritetwo < 248)) then
                        box(1,32,255,y3-1,"green");
                     end;
                  else
                     box(1,y4+1,255,y1-1,"green");
                  end;
               end;
               if (ZeddState == 22) then
                  text(90,0,"Thinking");
               end;
            end;
            spritebox = 12
            box(x1,y1,x2,y2,"red");
            
         end;
         if ((stype == 106) or (stype == 128)) then   --Handle TY-524A4ET
            if(i == 0) then
               tyrantalive = memory.readbyte(stuff+8+(1*16))
               spritedisplay = 0
               if (tyrantalive < 248) then
                  TyrantState = memory.readbyte(stuff+7+(i*16));
                  pauseemu = true
                  if ((TyrantState >= 38) and (TyrantState <= 44)) then
                     pauseemu = false
                     missiles = memory.readbyte(stuff+13+(i*16)) + 1
                     if(missiles == 256) then
                        missiles = 0;
                     end;
                     text(90,0,"Missile Attack");
                     text(90,8,string.format("Missiles Left:%d",missiles));
                  end;
                  if ((TyrantState >= 0) and (TyrantState <= 4)) then
                     pauseemu = false
                     text(90,0,"Thinking - Manipulate");
                     text(90,8,"Luck Now");
                  end;
                  if ((TyrantState >= 6) and (TyrantState <= 18)) then
                     pauseemu = false
                     text(90,0,"Mass Laser");
                     text(90,8,"Flood Attack");
                  end;
                  if ((TyrantState >= 30) and (TyrantState <= 36)) then
                     pauseemu = false
                     text(90,0,"Bullet Attack");
                     bullets = memory.readbyte(stuff+13+(i*16));
                     text(90,8,string.format("Bullets Left: %d",bullets));
                  end;
                  if ((TyrantState >= 46) and (TyrantState <= 54)) then
                     pauseemu = false
                     text(90,0,"Fireball Attack");
                     if (TyrantState < 50) then
                        bullets = memory.readbyte(stuff+13+(i*16));
                        text(90,8,string.format("FireBalls Left: %d",bullets));
                     else
                        bullets = memory.readbyte(stuff+14+(i*16));
                        text(90,8,string.format("FireBalls Left: %d",bullets));
                     end;
                  end;
                  if ((TyrantState >= 20) and (TyrantState <= 28)) then
                     pauseemu = false
                     text(90,0,"Electric Spark Attack");
                     bullets = memory.readbyte(stuff+13+(i*16));
                     text(90,8,string.format("Sparks Left: %d",bullets));
                     for j=12,15 do
                        sparkexists = memory.readbyte(stuff+8+(j*16))
                        if (sparkexists < 248) then
                           sparktype = memory.readbyte(stuff+1+(j*16))
                           x1 = memory.readbyte(stuff+2+(j*16));
                           x2 = memory.readbyte(stuff+3+(j*16));
                           y1 = memory.readbyte(stuff+4+(j*16)) + 24;
                           y2 = memory.readbyte(stuff+5+(j*16)) + 24;
                           if ((sparktype == 24)) then
                              if (x1 == 202) then
                                 line(1,y2,255,y2,"yellow");
                              else
                                 line(x2-2,32,x2-2,223,"yellow");
                              end;
                           end;
                           if ((sparktype == 26) or (sparktype == 28))then
                              line(x2-2,32,x2-2,223,"yellow");
                           end;
                           if ((sparktype == 30) or (sparktype == 32)) then
                              line(1,y2,255,y2,"yellow");
                           end;
                        end;
                     end;
                  end;
                  if (pauseemu) then
                     --FCEU.pause();
                  end;
               end;
            end;
         end;
--End of Bosses


         if (stype == 4) then   --Lethal Lemons and Life Stealin Limes
            if (i<3) then
               subtype = memory.readbyte(stuff+1+(i*16));
               if (subtype < 8) then
                  line(x1+3,y1,x1+3,248,"yellow");
                  line(x2+3,y1,x2+3,248,"yellow");
               else
                  line(x1+3,y2,x1+3,40,"yellow");
                  line(x2+3,y2,x2+3,40,"yellow");
               end;
            end;
         end;
         if (stype == 38) then   --Sniper Snail
            line(1,y2,255,y2,"yellow");
            line(1,y1+1,255,y1+1,"yellow");
         end;
         if (stype == 60) then   --Homing Drone
            sstate = memory.readbyte(stuff+1+(i*16));
            if (sstate == 2) then
               line(x2,y2,x2-(224-y2)/2,224,"yellow");
               line(x1,y2,x1+(224-y2)/2,224,"yellow");
               line(x2,y1,x2-((y1-32)/2),32,"yellow");
               line(x1,y1,x1+((y1-32)/2),32,"yellow");
            else
               line(1,y2,255,y2,"yellow");
            end;
         end;
         if (stype == 48) then   --Handle the spawn points.
            spritebox = 12
            for j=3,15 do
               x3 = memory.readbyte(stuff+2+(j*16));
               x4 = memory.readbyte(stuff+3+(j*16));
               y3 = memory.readbyte(stuff+4+(j*16)) + 24;
               y4 = memory.readbyte(stuff+5+(j*16)) + 24;
               if ((x1 == x3) and (x2 == x4) and (y1 == y3) and (y2 == y4)) then
                  timer = memory.readbyte(stuff+12+(j*16));
                  text(x1+4,y1+4,timer);
                  box(x1,y1,x1+16,y1+16,"yellow");
               end;
            end;
         end;   
         if (stype == 78) then   -- spike traps (todo, get official name)
            subtype = memory.readbyte(stuff+11+(i*16));
            if (subtype == 0) then   --Horizontal
               line(1,y1,255,y1,"yellow");
               line(1,y2,255,y2,"yellow");
            else   --Vertical
               line(x1,32,x1,224,"yellow");
               line(x2,32,x2,224,"yellow");
            end;
         end;
----------------------------------------------------------------------------------------------
        else  --Battle Kid: Fortress of Peril Version 2.0
------------------------------ BOSS HANDLERS ------------------------------------------------------	
         if ((stype == 150) or (stype == 180)) then    --Minimech
           minimech = memory.readbyte(stuff+12)
           spritedisplay = 2;
           spritebox = 12;
           box(x1,y1,x2,0xC7,"red")
           if((minimech >= 0x04) and (minimech <= 0x0A)) then
               text(128,8,"Running across the room")
           end
           if((minimech >= 0x20) and (minimech <= 0x2C)) then
               text(128,8,"Electric Spark Attack")
           end
           if((minimech >= 0x0E) and (minimech <= 0x1E)) then
               text(128,8,"Moon beam attack")
           end
         end
         if ((stype == 56) or (stype == 58)) then --Bullets
           spritedisplay = 1;
           spritebox = 12;
           box(x1,y1,x2,y2,"red")
         end
         if (stype == 8) then
           spritedisplay = 1;
           spritebox = 12;
           box(x1,y1,x2,y2,"red")
         end
         if ((stype == 110) or (stype == 162) or (stype == 162)) then   --Handle Lotus Gaurdian   (and Petunia of pain)
            spritebox = 12
            box(x1,y1,x2,y2,"red")
         end;
         if (stype == 112) then
           spritebox = 0
         end
         if ((stype == 114) or (stype == 164)) then   --Handle OwlBot
            spritedisplay = 1;
            spritebox = 12;
            if ((i == 0) or (i > 3)) then
              spritedisplay = 0
            end
            box(x1,y1,x2,y2,"red")
         end;
         if ((stype == 116) or (stype == 116)) then --OwlBot laser
           spritedisplay = 1
           spritebox = 12
           box(x1,y1,x2,y2,"red")
         end
         if ((stype == 178) or (stype == 178)) then --Chester "Chet" Donavan
           spritedisplay = 2
           spritebox = 12
           box(x1,y1,x2,y2,"red")
         end
         if ((stype == 118) or (stype == 166)) then   --Handle Cleo
            if (i==0) then
               spritebox = 12
               spritedisplay = 0
               box(x1,y1,x2,y2,"red");
            end;
            --Cannot determine color in this version, although the game makes it obvious by flashing which one it is.
         end;
         if ((stype == 120) or (stype == 168)) then   --Handle nagaconda displaying specifically.
            spritebox = 12
            spritedisplay = 2
            box(x1,y1,x2,y2,"red");
         end;
         if (stype == 126) then   --Handle Seahorse Turret.
            seahorsemin = 255
            seahorsenext = 0
            for j=1,4 do
               if((memory.readbyte(stuff+12+(j*16)) == 2) and (memory.readbyte(stuff+14+(j*16)) < seahorsemin)) then
                 seahorsemin = memory.readbyte(stuff+14+(j*16))
                 seahorsenext = j
               end
            end
            spritebox = 12
            spritedisplay = 2
            box(x1,y1,x2,y2,"red")
            if (i == seahorsenext) then
              box(x1+1,y1+1,x2-1,y2-1,"red")
              box(x1+2,y1+2,x2-2,y2-2,"red")
              box(x1+3,y1+3,x2-3,y2-3,"red")
            end
         end;
         if ((stype == 128) or (stype == 172)) then   --Handle Amethyst Angel
            angel = memory.readbyte(stuff+12)
            if ((angel <= 0x1A) or (angel >= 0x4A)) then
              spritebox = 12
              spritedisplay = 3
            else
              spritebox = 0
              spritedisplay = 0
            end
         end;
         if ((stype == 130) or (stype == 174)) then   --Handle Zedd
            if(i == 0) then
               spritedisplay = 0
               spritebox = 12
               box(x1,y1,x2,y2,"red")
               ZeddState = memory.readbyte(stuff+12+(i*16));
               if ((ZeddState >= 0x06) and (ZeddState <= 0x28)) then
                  --Freeze attack in middle of room
                  text(90,8,"Freeze Attack");
                  text(90,16,"Middle of Room");
                  box(112,32,143,169,"green")
               end;
               if ((ZeddState >= 0x74) and (ZeddState <= 0x8C)) then
                  --Side to Side hopping
                  text(90,8,"Side to Side");
                  text(90,16,"hopping");
                  box(0,70+24,255,121+24,"green")
               end;
               if ((ZeddState >= 0x58) and (ZeddState <= 0x72)) then
                  --Teleporting
                  spriteone = memory.readbyte(stuff+8+(10*16))
                  spritetwo = memory.readbyte(stuff+8+(11*16))
                  if ((spriteone == 248) and (spritetwo == 248)) then
                     text(90,8,"Teleporting");
                  else
                     text(90,16,"Teleport Attack");
                  end;
               end;
               if ((ZeddState >= 0x2A) and (ZeddState <= 0x56)) then
                  --Freeze Attack at end of room
                  text(90,8,"Freeze Attack");
                  text(90,16,"Side of Room");
                  x3 = memory.readbyte(stuff+5+(10*16));
                  x4 = memory.readbyte(stuff+7+(10*16));
                  y3 = memory.readbyte(stuff+6+(10*16)) + 20;
                  y4 = memory.readbyte(stuff+8+(10*16)) + 20;
                  x5 = memory.readbyte(stuff+5+(11*16));
                  x6 = memory.readbyte(stuff+7+(11*16));
                  y5 = memory.readbyte(stuff+6+(11*16)) + 20;
                  y6 = memory.readbyte(stuff+8+(11*16)) + 20;
                  spriteone = memory.readbyte(stuff+0+(10*16))
                  spritetwo = memory.readbyte(stuff+0+(11*16))
                  
                  if ( (y4-y5) < 32 ) then
                     if ((spriteone == 56) and (spritetwo == 56)) then
                        box(1,32,255,y5-1,"green");
                     end;
                  else
                     box(1,y6+1,255,y3-1,"green");
                  end;
               end;
               if ((ZeddState >= 0x8E) and (ZeddState <= 0x9E)) then
                  text(90,8,"Finishing Teleport")
               end
               if ((ZeddState == 0x04) or ((ZeddState >= 0xA0) and (ZeddState <= 0xA2))) then
                  text(90,8,"Thinking");
               end;
            end;
            spritebox = 12
            box(x1,y1,x2,y2,"red");
            
         end;
         if ((stype == 132) or (stype == 176)) then   --Handle TY-524A4ET
            if(i == 0) then
               tyrantalive = memory.readbyte(stuff+8+(1*16))
               spritedisplay = 0
               spritebox = 12
               box(x1,y1,x2,y2,"red")
               if (tyrantalive < 248) then
                  TyrantState = memory.readbyte(stuff+12+(i*16));
                  pauseemu = true
                  if ((TyrantState >= 0x14) and (TyrantState <= 0x24)) then
                     pauseemu = false
                     missiles = memory.readbyte(stuff+15+(i*16))
                     text(90,8,"Missile Attack");
                     text(90,16,string.format("Missiles Left:%d",missiles));
                  end;
                  if ((TyrantState >= 0) and (TyrantState <= 4)) then
                     pauseemu = false
                     text(90,8,"Thinking - Manipulate");
                     text(90,16,"Luck Now");
                  end;
                  if ((TyrantState >= 0x44) and (TyrantState <= 0x5C)) then
                     pauseemu = false
                     text(90,8,"Mass Laser");
                     text(90,16,"Flood Attack");
                  end;
                  if ((TyrantState >= 0x38) and (TyrantState <= 0x42)) then
                     pauseemu = false
                     text(90,8,"Bullet Attack");
                     bullets = memory.readbyte(stuff+15+(1*16));
                     text(90,16,string.format("Bullets Left: %d",bullets));
                  end;
                  if ((TyrantState >= 0x26) and (TyrantState <= 0x36)) then
                     pauseemu = false
                     text(90,8,"Fireball Attack");
                     if (TyrantState < 0x2E) then
                        bullets = memory.readbyte(stuff+15+(i*16));
                        text(90,16,string.format("FireBalls Left: %d",bullets));
                     else
                        bullets = memory.readbyte(stuff+15+(i*16));
                        text(90,16,string.format("FireBalls Left: %d",bullets));
                     end;
                  end;
                  if ((TyrantState >= 0x06) and (TyrantState <= 0x12)) then
                     pauseemu = false
                     text(90,8,"Electric Spark Attack");
                     bullets = memory.readbyte(stuff+15+(i*16)) + 1;
                     if (bullets == 256) then
                         bullets = 0
                     end
                     text(90,16,string.format("Sparks Left: %d",bullets));
                     for j=8,11 do
                        sparkexists = memory.readbyte(stuff+11+(j*16))
                        if (sparkexists > 0) then
                           sparktype = memory.readbyte(stuff+12+(j*16))
                           x1 = memory.readbyte(stuff+5+(j*16));
                           x2 = memory.readbyte(stuff+7+(j*16));
                           y1 = memory.readbyte(stuff+6+(j*16)) + 40;
                           y2 = memory.readbyte(stuff+8+(j*16)) + 40;
                           text(40,j*8,string.format("Spark Type: %d, x1: %d, y1: %d, x2: %d, y2: %d", sparktype,x1,x2,y1,y2))
                           
                           if ((sparktype == 0x00) or (sparktype == 0x04))then
                              line(x2-2,32,x2-2,223,"yellow");
                           end;
                           if ((sparktype == 0x80) or (sparktype == 0xFC)) then
                              line(1,y2,255,y2,"yellow");
                           end;

                        end;
                     end;
                  end;
                  if (pauseemu) then
                     --FCEU.pause();
                  end;
               end;
            end;
         end;
--End of Bosses


         if (stype == 0x3E) then   --Lethal Lemons and Life Stealin Limes
            if (i<3) then
               subtype = memory.readbyte(stuff+4+(i*16));
               if (subtype < 8) then
                  line(x1+1,y1,x1+1,248,"yellow");
                  line(x2-1,y1,x2-1,248,"yellow");
               else
                  line(x1+1,y2,x1+1,40,"yellow");
                  line(x2-1,y2,x2-1,40,"yellow");
               end;
            end;
         end;
         if (stype == 0x42) then
             spritebox = 0
         end;
         if (stype == 70) then   --Sniper Snail
            line(1,y2,255,y2,"yellow");
            line(1,y1+1,255,y1+1,"yellow");
         end;
         if (stype == 0x50) then   --Homing Drone
            homingdrone = memory.readbyte(stuff+9+(i*16))
            if(homingdrone <= 0x0C) then
              line(x1,40,x1,248,"yellow")
              line(x2,40,x2,248,"yellow")
            end
            if ((homingdrone <= 0x06) or (homingdrone >= 0x0E)) then
              line(1,y1,255,y1,"yellow")
              line(1,y2,255,y2,"yellow")
            end
         end;
         if (stype == 48) then   --Handle the spawn points.
            spritebox = 12
            for j=3,15 do
               x3 = memory.readbyte(stuff+2+(j*16));
               x4 = memory.readbyte(stuff+3+(j*16));
               y3 = memory.readbyte(stuff+4+(j*16)) + 24;
               y4 = memory.readbyte(stuff+5+(j*16)) + 24;
               if ((x1 == x3) and (x2 == x4) and (y1 == y3) and (y2 == y4)) then
                  timer = memory.readbyte(stuff+12+(j*16));
                  text(x1+4,y1+4,timer);
                  box(x1,y1,x1+16,y1+16,"yellow");
               end;
            end;
         end;   
         if (stype == 90) then	--Spiked Crusher
				spritebox = 12
                if (memory.readbyte(stuff+9+(i*16)) < 0x08) then
                  spritedisplay = 1
                end
				type = memory.readbyte(stuff+13+(i*16))
				line(x1,y1,x2,y2,"yellow")
				line(x2,y1,x1,y2,"yellow")
				if ((type == 4) or (type == 6)) then
					line(x1,36,x1,y1,"yellow")
					line(x1,y2,x1,240,"yellow")
					line(x2,36,x2,y1,"yellow")
					line(x2,y2,x2,240,"yellow")
				end
				if ((type == 2) or (type == 6)) then
					line(0,y1,x1,y1,"yellow")
					line(x2,y1,256,y1,"yellow")
					line(0,y2,x1,y2,"yellow")
					line(x2,y2,256,y2,"yellow")
				end
				box(x1,y1,x2,y2,"red")
			end
         
         if (stype == 92) then  --Air blowing fans
           line(1,y1,255,y1,"yellow");
           line(1,y2,255,y2,"yellow");
         end
         
         if (stype == 50) then
           spritebox = 12
           box(x1,y1,x2,y2,"yellow")
         end
         
         if (stype == 82) then -- Slimes
           if (memory.readbyte(stuff+1+(i*16)) > 0) then
             spritedisplay = 0
           end
         end
         
---------------------------------------------------------------------------------------------------------
		end;	--end of version branching
		
		limit = 8
		if (version == 1) then
			limit = 3
		end
		if((spriteexists < 248) or (i < limit)) then
				if ((spriteexists == 248) and (i < limit)) then
					spriteexists = memory.readbyte(stuff+7+(i*16))
				end
				if((spriteexists < 248)) then
					-- if((stype ~= 15) and (stype ~= 40) and (stype ~= 41)) then
					if(bit.band(spriteflags,0x40) ~= 0x40) then
						if (x2 <= x1) then
							x2 = x1 + 15
						end
						if (y2 <= x1) then
							y2 = y1 + 15
						end
					end
					
					if (enable_debug_code == 1) then
						if (stype>0) then
							text(1,  24+(i*8),stype);	--Debug info on sprite identifier.
							text(26, 24+(i*8),spritedisplay)
							text(34, 24+(i*8),spritebox)
						end
					end
					
					if (stype == flashingSpikeSType[version] and version ~= 2) then --Blinking spike room, display the phase counters in a visible spot.
        			  phase = memory.readbyte(stuff+flashingSpikePhaseOne[version]+(i*16));
        			  text(128,8,phase);
        			  phase = memory.readbyte(stuff+flashingSpikePhaseTwo[version]+(i*16));
        			  text(128,16,phase);
        		    end;
					
					if ((spritedisplay == 0) or (spritedisplay == 2)) then
						if (version < 3) then
							hp = memory.readbyte(stuff+6+(i*16))
						else
							hp = memory.readbyte(stuff+10+(i*16))
						end
						if (hp > 0) then
							text(x1+1,y1+1,hp)
						end
					end
					if ((spritedisplay == 0) or (spritedisplay == 3)) then
						if (version == 2) then
							timer = memory.readbyte(stuff+13+(i*16))
							if(timer > 0) then
								text(x1,y1+8,timer)
							end
                        elseif (version == 3) then
                            timer = memory.readbyte(stuff+14+(i*16))
                            if(timer > 0) then
                                text(x1,y1+8,timer)
                            end
						else
							if(stype == 74) then   --Colormancers use 14/12 for their attack counters.
								phase = memory.readbyte(stuff+14+(i*16))
							else
								phase = memory.readbyte(stuff+12+(i*16));
							end;
							if(phase > 0) then
								text(x1,y1+8,phase);
							end;
							if(phase == 0) then
								if(stype == 74) then
									phase = memory.readbyte(stuff+12+(i*16))
								else
									phase = memory.readbyte(stuff+13+(i*16));
								end;
								if(phase > 0) then
									text(x1,y1+8,phase);
								end;
							end;
						end
					end
					if(spritebox == 0) then
						box(x1,y1,x2,y2,"red")
					end
					if(spritebox == 4) then
						box(x1,y1,x2,y2,"yellow")
					end
					if(spritebox == 8) then
						box(x1,y1,x2,y2,"green")
					end
					--if((enable_debug_code == 1) and (spritebox == 12)) then
					--	box(x1,y1,x2,y2,"red")
					--	box(x1+1,y1+1,x2-1,y2-1,"green")
					--end
				end
			end
		end	
	end

	if ((enable_hud_info == 1) and (gameaction == 1)) then
			
		xlocAddr = xlocSet[version]
		ylocAddr = ylocSet[version]
		jleftAddr = jleftSet[version]
		jtotalAddr = jtotalSet[version]
		if (demo == true) then
			xlocAddr = xlocAddr - version
			ylocAddr = ylocAddr - version
			jleftAddr = jleftAddr - version
			jtotalAddr = jtotalAddr - version
		end		
		
		xloc = memory.readbyte(xlocAddr)
		yloc = memory.readbyte(ylocAddr) / 2
		text(210,8,string.format("Room:%02d,%02d ",xloc,yloc))
				
		jumpsleft = memory.readbyte(jleftAddr)
		jumpstotal = memory.readbyte(jtotalAddr)		
		if (demo == false or version == 1) then
			text(35,16,string.format("Jumps:%d/%d",jumpsleft,jumpstotal))
		end
		
		if (version == 1) then
			portals = memory.readbyte(0x8A)
			if (bit.band(portals,0x01) == 0x01) then
				PortalA = 0x31
			else
				PortalA = 0x5F
			end;
			if (bit.band(portals,0x02) == 0x02) then
				PortalB = 0x32
			else
				PortalB = 0x5F
			end;
			if (bit.band(portals,0x04) == 0x04) then
				PortalC = 0x33
			else
				PortalC = 0x5F
			end;
			if (bit.band(portals,0x08) == 0x08) then
				PortalD = 0x34
			else
				PortalD = 0x5F
			end;
			if (bit.band(portals,0x10) == 0x10) then
				PortalE = 0x35
			else
				PortalE = 0x5F
			end;
			text(88,8,string.format("TP:%c%c%c%c%c",PortalA,PortalB,PortalC,PortalD,PortalE))
		elseif (version == 2) then
			accelAddr = accelSet[version]
			runspeedAddr = runspeedSet[version]
			if (demo == true) then
				accelAddr = 0x5F
				runspeedAddr = 0x5E
			end		
			acceleration = memory.readbyte(accelAddr)
			runspeed = memory.readbyte(runspeedAddr)
			if(acceleration > 127) then
				acceleration = bit.band(bit.bnot(acceleration),0xFF) + 1
				text(88,8,string.format("Fall Rate:-%d pixels/frame",acceleration))
			else
				text(88,8,string.format("Fall Rate: %d pixels/frame",acceleration))
			end
			if((runspeed >= 0) and (runspeed <= 127)) then
				current_run_direction = 0
			elseif (runspeed > 127) then
				runspeed = bit.band(bit.bnot(runspeed),0xFF) + 1
				current_run_direction = 1
			end
			if(current_run_direction == 1) then
				text(88,16,string.format("Run speed:-%d pixels/frame",runspeed))
			else
				text(88,16,string.format("Run speed: %d pixels/frame",runspeed))
			end
		end

		--hidden for now
		--[[
		timer_msec = memory.readbyte(0xC2)
		timer_sec = memory.readbyte(0xC3)
		timer_min = memory.readbyte(0xC4)
		timer_hour = memory.readbyte(0xC5)

		local msec_timer = { 0,1,3,5,6,8,
					10,11,13,15,16,18,
					20,21,23,25,26,28,
					30,31,33,35,36,38,
					40,41,43,45,46,48,
					50,51,53,55,56,58,
					60,61,63,65,66,68,
					70,71,73,75,76,78,
					80,81,83,85,86,88,
					90,91,93,95,96,98,
					99,}

		if (enable_tas_info ~= 1) then	--No point in showing this in a TAS, as we won't be dying. :)
			deaths = memory.readbyte(0x72) + (memory.readbyte(0x73) * 256)
			text(108,8,string.format("DEATHS: %d",deaths))
		end
		if ((timer_msec + timer_sec + timer_min + timer_hour) > 0) then
			text(108,16,string.format("%.2d:%.2d:%.2d:%.2d",timer_hour,59-timer_min,59-timer_sec,msec_timer[60-timer_msec+1]))
		end
		--]]
		
	end

	if ((enable_tas_info == 1) and (movie.isloaded())) then
		if(framecounter >= end_avi) then
			FCEU.pause()
		end
		if((framecounter >= info_1) and (framecounter <= (info_1+info_frames))) then
			text(32,32,"Battle Kid 2: Mountain of Torment")
			movie_frames = (movie.length() % frame_rate)
			movie_seconds = ((movie.length() % frames_per_minute) - movie_frames) / frame_rate
			movie_minutes = (movie.length() - (movie.length() % frames_per_minute)) / frames_per_minute
			text(32,40,string.format("%s in %02d:%02d.%02d by %s",info_1_string,movie_minutes,movie_seconds,(movie_frames*100)/60,info_1_author))
			text(32,48,string.format("%d Rerecords",movie.rerecordcount()))
		end

		if((framecounter >= info_2) and (framecounter <= (info_2+info_frames))) then
			text(32,32,"This is a Tool Assisted Recording.")
			text(32,40,"For more Info, Go to TASVideos.org")
		end
		if((framecounter >= movie.length()) and (framecounter <= (movie.length() + info_frames))) then
			text(8,200,"Movie Finished Playing")
		end
	end
end

--version detection
memory.usememorydomain("PRG ROM");
local cart = memory.readbyte(0x01)
memory.usememorydomain("RAM");
if (cart == 133) then
	version = 1
	demo = true
elseif (cart == 168) then
	version = 1
	demo = false
elseif (cart == 24) then
	version = 2
	demo = true
elseif (cart == 128) then
	version = 2
	demo = false
else 
	version = 3
end

if(movie.isloaded() and (enable_tas_info == 1)) then
	movie.playbeginning()
end

while (true) do
	battlekidloop()
	emu.frameadvance()
end;