
num=1
iterations=1

x=0
y=200

while true do
	
	--also erases everything 
	screen:blit(0, 0, background,  false)
	--enableDebug()
	updateInputs(Controls.read())

	screen:print(5, 100, "X", white)
	screen:print(5, 120, inputTimePressed("cross"), white)
	if inputFirstPress("cross") then
		screen:print(5, 160, "1st", white)
	elseif inputLongPress("cross") then
		screen:print(5, 160, "L!", white)
	end
	if inputJustReleased("cross") then
		screen:print(5, 160, "off", white)
	end
	if inputIsPressed("cross") then
		screen:print(5, 140, "Y", white)
	end
	if inputIsRepeating("cross") then
		screen:print(5, 180, "R!", white)
	end
	
	screen:print(45, 100, "II", white)
	screen:print(45, 120, inputTimePressed("square"), white)
	if inputFirstPress("square") then
		screen:print(45, 160, "1st", white)
	elseif inputLongPress("square") then
		screen:print(45, 160, "L!", white)
	end
	if inputJustReleased("square") then
		screen:print(45, 160, "off", white)
	end
	if inputIsPressed("square") then
		screen:print(45, 140, "Y", white)
	end
	if inputIsRepeating("square") then
		screen:print(45, 180, "R!", white)
	end
	
	
	screen:print(85, 100, "O", white)
	screen:print(85, 120, inputTimePressed("circle"), white)
	if inputFirstPress("circle") then
		screen:print(85, 160, "1st", white)
	elseif inputLongPress("circle") then
		screen:print(85, 160, "L!", white)
	end
	if inputJustReleased("circle") then
		screen:print(85, 160, "off", white)
	end
	if inputIsPressed("circle") then
		screen:print(85, 140, "Y", white)
	end
	if inputIsRepeating("circle") then
		screen:print(85, 180, "R!", white)
	end
	
	
	screen:print(125, 100, "/\\", white)
	screen:print(125, 120, inputTimePressed("triangle"), white)
	if inputFirstPress("triangle") then
		screen:print(125, 160, "1st", white)
	elseif inputLongPress("triangle") then
		screen:print(125, 160, "L!", white)
	end
	if inputJustReleased("triangle") then
		screen:print(125, 160, "off", white)
	end
	if inputIsPressed("triangle") then
		screen:print(125, 140, "Y", white)
	end
	if inputIsRepeating("triangle") then
		screen:print(125, 180, "R!", white)
	end
	
	
	screen:print(165, 100, "L", white)
	screen:print(165, 120, inputTimePressed("l"), white)
	if inputFirstPress("l") then
		screen:print(165, 160, "1st", white)
	elseif inputLongPress("l") then
		screen:print(165, 160, "L!", white)
	end
	if inputJustReleased("l") then
		screen:print(165, 160, "off", white)
	end
	if inputIsPressed("l") then
		screen:print(165, 140, "Y", white)
	end
	if inputIsRepeating("l") then
		screen:print(165, 180, "R!", white)
	end
	
	
	screen:print(205, 100, "R", white)
	screen:print(205, 120, inputTimePressed("r"), white)
	if inputFirstPress("r") then
		screen:print(205, 160, "1st", white)
	elseif inputLongPress("r") then
		screen:print(205, 160, "L!", white)
	end
	if inputJustReleased("r") then
		screen:print(205, 160, "off", white)
	end
	if inputIsPressed("r") then
		screen:print(205, 140, "Y", white)
	end
	if inputIsRepeating("r") then
		screen:print(205, 180, "R!", white)
	end
	
	
	screen:print(245, 100, "sta", white)
	screen:print(245, 120, inputTimePressed("start"), white)
	if inputFirstPress("start") then
		screen:print(245, 160, "1st", white)
	elseif inputLongPress("start") then
		screen:print(245, 160, "L!", white)
	end
	if inputJustReleased("start") then
		screen:print(245, 160, "off", white)
	end
	if inputIsPressed("start") then
		screen:print(245, 140, "Y", white)
	end
	if inputIsRepeating("start") then
		screen:print(245, 180, "R!", white)
	end
	
	screen:print(285, 100, "sel", white)
	screen:print(285, 120, inputTimePressed("select"), white)
	if inputFirstPress("select") then
		screen:print(285, 160, "1st", white)
	elseif inputLongPress("select") then
		screen:print(285, 160, "L!", white)
	end
	if inputJustReleased("select") then
		screen:print(285, 160, "off", white)
	end
	if inputIsPressed("select") then
		screen:print(285, 140, "Y", white)
	end
	if inputIsRepeating("select") then
		screen:print(285, 180, "R!", white)
	end
	
	
	screen:print(325, 100, "^", white)
	screen:print(325, 120, inputTimePressed("up"), white)
	if inputFirstPress("up") then
		screen:print(325, 160, "1st", white)
	elseif inputLongPress("up") then
		screen:print(325, 160, "L!", white)
	end
	if inputJustReleased("up") then
		screen:print(325, 160, "off", white)
	end
	if inputIsPressed("up") then
		screen:print(325, 140, "Y", white)
	end
	if inputIsRepeating("up") then
		screen:print(325, 180, "R!", white)
	end
	
	screen:print(365, 100, "v", white)
	screen:print(365, 120, inputTimePressed("down"), white)
	if inputFirstPress("down") then
		screen:print(365, 160, "1st", white)
	elseif inputLongPress("down") then
		screen:print(365, 160, "L!", white)
	end
	if inputJustReleased("down") then
		screen:print(365, 160, "off", white)
	end
	if inputIsPressed("down") then
		screen:print(365, 140, "Y", white)
	end
	if inputIsRepeating("down") then
		screen:print(365, 180, "R!", white)
	end
	
	
	
	
	screen:print(405, 100, "<", white)
	screen:print(405, 120, inputTimePressed("left"), white)
	leftRepeat=inputIsRepeating("left")
	if inputFirstPress("left") or leftRepeat then
		x=x-10
	end
	if inputFirstPress("left") then
		screen:print(405, 160, "1st", white)
	elseif inputLongPress("left") then
		screen:print(405, 160, "L!", white)
	end
	if inputJustReleased("left") then
		screen:print(405, 160, "off", white)
	end
	if inputIsPressed("left") then
		screen:print(405, 140, "Y", white)
	end
	if leftRepeat then
		screen:print(405, 180, "R!", white)
	end
	
	
	
	screen:print(445, 100, ">", white)
	screen:print(445, 120, inputTimePressed("right"), white)
	rightRepeat=inputIsRepeating("right")
	if inputFirstPress("right") or rightRepeat then
		x=x+10
	end
	if inputFirstPress("right") then
		screen:print(445, 160, "1st", white)
	elseif inputLongPress("right") then
		screen:print(445, 160, "L!", white)
	end
	if inputJustReleased("right") then
		screen:print(445, 160, "off", white)
	end
	if inputIsPressed("right") then
		screen:print(445, 140, "Y", white)
	end
	if rightRepeat then
		screen:print(445, 180, "R!", white)
	end
	
	if inputAnalogIsTouched() then
		screen:print(220, 40, "Analog", white)
	end
	
	if inputLongPress("start") and inputLongPress("select") then
		break
	end
	
	--screen:blit(x, y, iconImages["ingame_cursor"],  true)
	
	
	itmess=iterations.." iter."
	screen:print(381, 231, itmess)
	screen:print(381, 229, itmess)
	screen:print(379, 231, itmess)
	screen:print(379, 229, itmess)
	screen:print(380, 230, itmess, white)
	
	mem=getMemoryInfo()
	screen:print(381, 246, mem)
	screen:print(381, 244, mem)
	screen:print(379, 246, mem)
	screen:print(379, 244, mem)
	screen:print(380, 245, mem, white)

	iterations=iterations+1
   	screen.waitVblankStart()
	screen.flip()
   	
end