--PSP HOMEBREW--
--+++++++++++++++++++++++++++++++++++++++++
-- TrailblazePSP Default SysMode bootScript
--+++++++++++++++++++++++++++++++++++++++++
local AUTHOR      = 'Dangee'           
local copyright   = 'dangee.net'
local LICENSE     = 'Lesser GPL variant,Homebrew,No Guarantee etc.'
local VERSION     = '1.1 (Alpha)'
local DATE        = 'Dec. 08'
local INTERPRETER = 'LuaPlayer 0.2'
--++++++++++++++++++++++++++++++++++++++++++++++
--[[
Description
-----------
Default BootScript for TrailblazePSP SysMode.
When TrailblazePSP movie mode boots or exits
with the L shoulder button held down, or if 
the folder /XBOOT is found in the eboot.pbp
folder, this is where SysMode initialises.
]]--
--++++++++++++++++++++++++++++++++++++++++++++++

--alias the VRAM feedback function
feedback = Ebpbp.msg

-- autolocate the EBOOT main folder
ebootDir,ebootFilename = Ebpbp.ebootId()
eblocStr = ebootFilename.." location is "..ebootDir

-- search for "revi.png"
rev1 = "REVI.PNG"
reviPath = ebootDir.."/"..rev1
rev1SearchResult = " found" 
if not System.fileFind(reviPath) then
  rev1SearchResult = " not"..rev1SearchResult
end
rev1SearchResult =  rev1..rev1SearchResult

--extract info file from Ebpbp
text = Ebpbp.readFile("STORIA.TXT")

--create the gimmick Sprite
gimmick = Sprite3.new()
gimmick:setColor(RED,1)    --give the sprite a red corner..
gimmick:setColor(BLUE,4)   -- ..and a blue corner

--draw the gimmick to the frame buffer
gimmick:draw3()

--swap VRAM<->Frame buffer
screen:flip()

--Gimmick rotation routine
degree = 1
Grotate = function()
  --rotate the gimmick by external degree
  gimmick:rotateZ(degree)
  --Draw the gimmick interlaced
  for interlace = 1,2 do
    gimmick:draw3()
    screen:waitVblankStart();screen:flip()
  end
end
  
--SysMode main loop
repeat

  --feedback ebootId info (var 2 = true forces CLRHOME)
  feedback(eblocStr,true)
  --feedback revi.png info
  feedback(rev1SearchResult)
  
  --prompt input
  feedback("\nCircle   : sOft rebOOt")
  feedback("Cross    : return to Xmb")
  feedback("Triangle : info")
  
  --Wait for OXT input & rotate the gimmick while waiting
  degree = -degree
  push(OXT,Grotate) ; reboot,xit,info = O(),X(),TR()

  --counter-rotate the gimmick while waiting for key release
  degree = -degree
  release(OXT,Grotate)
  
  if info then
    feedback("\n"..text)
    feedback("\nO : OK\n")
    push(OX,Grotate) ; xit = X()
    release(OX)
  end

  --exit
  if xit then System.Quit() end
  
until reboot

--reboot--