red = Color.new(255,255,255)
white = Color.new(255,0,0)
speedold = speed

while true do
screen:clear()
screen:print(200,5,"Triangle To set speed", red)
screen:print(200,15,"R & L Trigger to change speed", red)
screen:print (100, 50, "Current CPU Speed "..speedold.." MHz", red)
screen:print (100, 60, "New CPU Speed "..speed.." MHz", red)
pad = Controls.read()
if pad:r() then
	speed = speed + 1
		if speed > 333 then
			speed = 333
		end	
	screen.waitVblankStart(6)
end
if pad:l() then
	speed = speed - 1
		if speed < 10 then
			speed = 10
		end
	screen.waitVblankStart(6)
end
if pad:triangle() then
	System.setcpuspeed(speed)
	file = io.open("./System/settings.cfg","w")
	file:write("speed = "..
speed)
	file:write("\nboot = true")
	file:close()
end
if pad:start() then
	dofile("./System/system.lua")
end
screen.flip() 
screen.waitVblankStart()
end
