silver = Color.new(192,192,192)
red = Color.new(255,0,0)
green = Color.new(0, 255, 0)
blue = Color.new(0, 0, 255)
black = Color.new(0, 0, 0)
white = Color.new(255, 255, 255)
gray = Color.new(128, 128, 128)
cyan = Color.new(100, 255, 255)

val = 0
oldpad = Controls.read()
logo = Image.createEmpty(128, 64)
logo:clear(gray)
logo:print(20, 20, "LuaPlayer", black)
logo:print(10, 40, "   HM    ", black)

cube = {
	{0, 0, red, -1, -1,  1},  -- 0
	{2, 0, red, -1,  1,  1},  -- 4
	{2, 2, red,  1,  1,  1},  -- 5

	{0, 0, red, -1, -1,  1},  -- 0
	{2, 2, red,  1,  1,  1},  -- 5
	{0, 2, red,  1, -1,  1},  -- 1

	{0, 0, red, -1, -1, -1},  -- 3
	{2, 0, red,  1, -1, -1},  -- 2
	{2, 2, red,  1,  1, -1},  -- 6

	{0, 0, red, -1, -1, -1},  -- 3
	{2, 2, red,  1,  1, -1},  -- 6
	{0, 2, red, -1,  1, -1},  -- 7

	{0, 0, green,  1, -1, -1},  -- 0
	{2, 0, green,  1, -1,  1},  -- 3
	{2, 2, green,  1,  1,  1},  -- 7

	{0, 0, green,  1, -1, -1},  -- 0
	{2, 2, green,  1,  1,  1},  -- 7
	{0, 2, green,  1,  1, -1},  -- 4

	{0, 0, green, -1, -1, -1},  -- 0
	{2, 0, green, -1,  1, -1},  -- 3
	{2, 2, green, -1,  1,  1},  -- 7

	{0, 0, green, -1, -1, -1},  -- 0
	{2, 2, green, -1,  1,  1},  -- 7
	{0, 2, green, -1, -1,  1},  -- 4

	{0, 0, blue, -1,  1, -1},  -- 0
	{2, 0, blue,  1,  1, -1},  -- 1
	{2, 2, blue,  1,  1,  1},  -- 2

	{0, 0, blue, -1,  1, -1},  -- 0
	{2, 2, blue,  1,  1,  1},  -- 2
	{0, 2, blue, -1,  1,  1},  -- 3

	{0, 0, blue, -1, -1, -1},  -- 4
	{2, 0, blue, -1, -1,  1},  -- 7
	{2, 2, blue,  1, -1,  1},  -- 6

	{0, 0, blue, -1, -1, -1},  -- 4
	{2, 2, blue,  1, -1,  1},  -- 6
	{0, 2, blue,  1, -1, -1},  -- 5
}

plane = {
	{blue, -8, -3,  0},
	{cyan, 8,  3,  0},
	{blue,  8,  -3,  0},
	{cyan, 8, 3,  0},
	{blue, -8,  -3,  0},
	{cyan,  -8,  3,  0},
}
macadd = Adhoc.getMac()
nickname = System.nickName()
System.sleep(100)
usb = true
sysver = System.playerVer()
cfwver = System.cfwVersion()
model = System.getModel(1)
devid = "ms0:"
mssize = System.getFreeSpace(devid)
mssize = (mssize/1024)
mssize = (mssize/1024)
totalsize = System.getTotalSize(devid)
totalsize = (totalsize/1024)
totalsize = (totalsize/1024)
dev = 5
api = System.getapi()
while true do
hprmr = Hprm.remote()
hpad = Hprm.read()
hmic = Hprm.mic()
hheadphone = Hprm.headphone()
cpu = System.getCpuSpeed()
bus = System.getBusSpeed()
--fps = System.autoCpu()
charge = System.powerIsBatteryCharging()
if charge == true then
	charge = "true"
end
if charge == false then
	charge = "false"
end
	screen:clear()
	Gu.start3d()

	-- clear screen
	Gu.clearDepth(0);
	Gu.clear(Gu.COLOR_BUFFER_BIT+Gu.DEPTH_BUFFER_BIT)

	-- setup projection and view matrices

	Gum.matrixMode(Gu.PROJECTION)
	Gum.loadIdentity()
	Gum.perspective(75, 16/9, 0.5, 1000)

	Gum.matrixMode(Gu.VIEW)
	Gum.loadIdentity()

	-- setup matrix for triangle
	Gum.matrixMode(Gu.MODEL)
	Gum.loadIdentity()
	Gum.translate(0, 0, -3);

	-- draw triangle without texture

	Gu.disable(Gu.TEXTURE_2D)
	Gum.drawArray(Gu.TRIANGLES, Gu.COLOR_8888+Gu.VERTEX_32BITF+Gu.TRANSFORM_3D, plane)

	-- setup texture

	Gu.enable(Gu.BLEND)
	Gu.blendFunc(Gu.ADD, Gu.SRC_ALPHA, Gu.ONE_MINUS_SRC_ALPHA, 0, 0)
	Gu.enable(Gu.TEXTURE_2D);
	Gu.texImage(logo)
	Gu.texFunc(Gu.TFX_MODULATE, Gu.TCC_RGBA)
	Gu.texEnvColor(white)
	Gu.texFilter(Gu.LINEAR, Gu.LINEAR)
	Gu.texScale(1, 1)
	Gu.texOffset(0, 0)
	Gu.ambientColor(white)

	-- setup matrix for cube

	Gum.matrixMode(Gu.MODEL)
	Gum.loadIdentity()
	Gum.translate(0, 0, -3.5);
	Gum.rotateXYZ(val * 0.79 * (Gu.PI/180), val * 0.98 * (Gu.PI/180.0), val * 1.32 * (Gu.PI/180.0))

	-- draw cube

	Gum.drawArray(Gu.TRIANGLES, Gu.TEXTURE_32BITF+Gu.COLOR_8888+Gu.VERTEX_32BITF+Gu.TRANSFORM_3D, cube)

	Gu.end3d()

	val = val + 1.34 
	hour = System.getTime(1) 
	min = System.getTime(2) 
	sec = System.getTime(3)
	pmam = System.getTime(5)
	year = System.getDate(1) 
	month = System.getDate(2) 
	day = System.getDate(3) 
	screen:print(110,10,"LuaPlayer HM Wifi Tester",white)
	screen:print(1,30,"press Triagle for Wifi Test",red)
	screen:print(1,50,"press Square for Ad-Hoc Test",red)
	screen:print(1,70,"press Circle for LuaPlayer Version",red)
	screen:print(1,90,"Select to cycle Device free space",red)
	screen:print(1,110,"press L to Test Message",red)
	screen:print(1,130,"press R to Usb function",red)
	screen:print(1,150,"Up to Suspend the PSP",red)
	screen:print(1,170,"Down to Shutdown the PSP",red)
	screen:print(1,190,"Left to Test Eboot.pbp Mp3me and ISO",red)
	screen:print(1,210,"Right to Test UMD GAME",red)
	screen:print(230,230,"Nickname is "..nickname,red)
	screen:print(230,250,"Macaddress "..macadd,red)
	screen:print(1,250,"LuaPlayerHM Ver "..sysver,red)
	screen:print(1,230,"CFW Firmware Ver "..cfwver,red)
	screen:print(230,210,"PSP Type "..model,red)
	screen:print(350,190,System.usbState(3,1),red)
	screen:print(260,170,devid.." "..mssize.." / "..totalsize.."Mb",red)
	screen:print(260,150,hour..":"..min..":"..sec.." "..pmam.." Date: "..year.."/"..month.."/"..day,red)
	screen:print(260,130,"Start to rip UMD to ISO",red)
	screen:print(260,110,"CPU: "..cpu.." BUS: "..bus,red)
	screen:print(280,90,"HPRM REMOTE EXSIST "..hprmr,red)
	screen:print(280,70,"HPRM REMOTE BUTTON "..hpad,red)
	screen:print(280,50,"HPRM MIC "..hmic,red)
	screen:print(280,30,"HPRM HEADPHONE "..hheadphone,red)

	pad = Controls.read()
	if pad:select() and not oldpad:select() then
		dev = dev + 1
		if dev == 2 then
			devid = "flash1:"
			mssize = System.getFreeSpace(devid)
			mssize = (mssize/1024)
			mssize = (mssize/1024)
			totalsize = System.getTotalSize(devid)
			totalsize = (totalsize/1024)
			totalsize = (totalsize/1024)
		end
		if dev == 3 then
			devid = "flash2:"
			mssize = System.getFreeSpace(devid)
			mssize = (mssize/1024)
			mssize = (mssize/1024)
			totalsize = System.getTotalSize(devid)
			totalsize = (totalsize/1024)
			totalsize = (totalsize/1024)
		end
		if dev == 4 then
			devid = "flash3:"
			mssize = System.getFreeSpace(devid)
			mssize = (mssize/1024)
			mssize = (mssize/1024)
			totalsize = System.getTotalSize(devid)
			totalsize = (totalsize/1024)
			totalsize = (totalsize/1024)
		end
		if dev == 5 then
			devid = "ms0:"
			mssize = System.getFreeSpace(devid)
			mssize = (mssize/1024)
			mssize = (mssize/1024)
			totalsize = System.getTotalSize(devid)
			totalsize = (totalsize/1024)
			totalsize = (totalsize/1024)
		end
		if dev == 6 then
			devid = "Ram"
			if model=="PHAT" then
				totalsize = 20
			else
				totalsize = 50
			end
			mssize = System.getFreeMemory()
			mssize = (mssize/1024)
			mssize = (mssize/1024)
		end
		if dev == 7 then
			totalsize = 0
			isok = UMD.checkDisk()
			if isok == 1 then
			devid = "disk0:"
			mssize = UMD.getSize()
			mssize = (mssize/1024)
			mssize = (mssize/1024)
			end
			if isok == 0 then
				dev = 8
			end
		end
		if dev == 8 then
			devid = "VRam"
			totalsize = 2
			mssize = System.getVram()
			mssize = (mssize/1024)
			mssize = (mssize/1024)
		end
		if dev > 8 then
			dev = 1
		end
		if dev == 1 then
			devid = "flash0:"
			totalsize = 0
			mssize = System.getFreeSpace(devid)
			mssize = (mssize/1024)
			mssize = (mssize/1024)
			totalsize = System.getTotalSize(devid)
			totalsize = (totalsize/1024)
			totalsize = (totalsize/1024)
		end
	end
	if pad:start() and not oldpad:start() then
	scorex = 200
	scorey = 30
	data = 12345
	score = tostring("x="..scorex.."y="..scorey.."score="..data)
	System.startGameSave("Alex","Alex save","Lol it worked",score,"HMGAME111")
	System.sleep(300)
	data = System.startGameLoad("HMGAME111")
	System.sleep(300)
	System.message(data,0)
	--System.runeboot("ms0:/PSP/GAME380/LUAPLAYERHM6/webbrowser.PBP")
	--dofile("./System/irda.lua")
	isok = UMD.checkDisk()
	if isok==1 then
		nameiso = System.startOSK("ms0:/ISO/*.ISO","Delete * and Enter ISO name")
		umdsize = UMD.getSize()
		mssize = System.getTotalSize("ms0:")
		if mssize > umdsize then
			UMD.ripISO(nameiso)
		else
			System.message("Not enought space on Memory Stick",0)
		end
	else
		System.message("No UMD disk Present",0)
	end
	end
	if pad:r() then
		System.message(usbstat.."Enable Yes, Disable No",1)
		butpress = System.buttonPressed(1)
		if butpress == "yes" then
			System.usbDiskModeActivate()
			usb = false
			usbstat = "  Currently Enabled\n"
		end
		if butpress == "no" then
			System.usbDiskModeDeactivate()
			usb = false
			usbstat = "  Currently Disabled\n"
		end
	end
	if pad:l() then
		--Wlan.startGameShare("ms0:/PSP/GAME380/LuaPlayerHM6/webbrowser.PBP","HMNETaaa")
		--txtmsg = System.startOSK("Enter Name","Enter Name")
		--System.message(txtmsg,0)
		--System.webbrowser("ms0:/PSP/GAME380/LuaPlayerHM6","http://luaplayerhm.xtreemhost.com/")
		dofile("./System/irda.lua")
	end
	if pad:triangle() then
		dofile("./System/update.lua")
	end
	if pad:square() then
		screen:clear()
		screen:flip()
		screen:clear()
		screen:flip()
		Adhoc.init()
		dofile("./system/connectadhoc.lua")
	end
	if pad:circle() then
		System.madeby(0)
	end
	if pad:up() then
		System.suspend()
	end
	if pad:down() then
		System.shutdown()
	end
	if pad:right() then
		System.startUMD()
	end
	if pad:left() then
		dofile("./system/filebrowse.lua")
	end

	
	screen.flip()
	screen.waitVblankStart()
	oldpad = pad
end
