--Architecture psp
EarthEngine={l=255,
             h=191,
			 screen=2,
			 l2=32,
			 h2=24,
			 type="ds"}
			 
function EarthEngine.init()
     SCREEN_BOTTOM   = 0
     SCREEN_TOP      = 1
     BGTopBit8 = Screen.Load16BitBG()
     BGBotText = Screen.LoadTextBG()
     Screen.Initialize( SCREEN_TOP, BGTopBit8 )
     Screen.Initialize( SCREEN_BOTTOM, BGBotText )
end


  Font = {}
  function Font.load(filename) return nil end
  function Font.createMonoSpaced() return nil end
  function Font.createProportional() return nil end
  function Font:setCharSize(width, height, dpiX, dpiY) return  nil end
  function Font:setPixelSizes(width, height) return nil end
  function Font:getTextSize(string) return 0,0 end

  -- Color
  Color = {
    n=1,
    new = function (r,g,b)
	 n=n+1
	 BGTot8Bit:SetPaletteColor(n, r,g,b)
     	return n end
  }
  
  ----------------------------------
  
  
  Image = {
        createEmpty = function (width, height)
            local surf = SDL.SDL_CreateRGBSurface(SDL_SWSURFACE, width, height, define_bpp, 0, 0, 0, 0);
            local w = width
            local h = height
            return {
                blit = function (x, y, img, sourcex, sourcey, width, height)
                    
                end,
                clear = function (color)
                    
                end,
                fontPrint = function (font, x, y, txt, color)
                
                end,
                width = function () return w end,
                height = function () return h end,
	            fillRect= function(x, y, width, height, color)
                      
                end,
                pixel= function(x, y)
                     
                         end,
                   }
                 end,
                drawLine=function(x1,y1,x2,y2,couleur)
                    
                end
            }
        end,
        load = function (img)
            local file=io.open(img,"rb")
            return Image.LoadBMP( screen, x, y, "image" )
        end,
  }

  
  
  -------------------------------------
  

  --------------------------------------------
  
  
  
  Controls = {
    read = function ()
        return {
            up = function ()
                return Pads.Up()
            end,
            down = function ()
                return Pads.Down()
            end,
            left = function ()
                return Pads.Left()
            end,
            right = function ()
                return Pads.Right()
            end,
            circle = function ()
                return Pads.A()
            end,
            cross = function ()
                return Pads.B()
            end,
            square = function ()
                return Pads.Y()
            end,
            triangle = function ()
                return Pads.X()
            end,
            start = function ()
                return Pads.Start()
            end,
            select = function ()
                return Pads.Select()
            end,
            r = function ()
                return Pads.R()
            end,
            l = function ()
                return Pads.L()
            end,
            analogX = function () return 0 end,
            analogY = function () return 0 end,
        }
        end
  }

  -- screen
  screen = {}
  function screen.waitVblankStart () end
  function screen.flip ()
	collectgarbage()
  end
  function screen:blit (x,y,img,ox,oy,ow,oh)
    
  end
  function screen:print (x,y,txt,fg)
      BGTot8Bit:PrintXY(x,y,txt)
  end
  function screen:clear(color)
    
  end
  function screen:fillRect(x, y, width, height, color)
    
  end
  function screen:pixel(x, y,i)
     BGTopBit8:Plot( x, y, i )
  end
  
   function screen:drawLine(x1,y1,x2,y2,couleur)
     BGTot8Bit:Line(x1,y1,x2,y2,couleur)
  end
  function screen:fontPrint (font, x, y, txt, color)
      BGTot8Bit:PrintXY(x,y,txt)
  end

  -- Timer (complete)
  Timer = {
        new = function (starttime)
            local measuredTime = os.time()
            local offset = starttime or 0
            return {
                start = function ()
                    if (measuredTime>0) then
                        return os.time() - measuredTime + offset
                    else
                        measuredTime = os.time()
                        return offset
                    end
                end,
                time = function ()
                    if (measuredTime>0) then
                        return os.time() - measuredTime + offset
                    else
                        return offset
                    end
                end,
                stop = function ()
                    if (measuredTime>0) then
                        offset = os.time() - measuredTime + offset
                        measuredTime = 0
                    end
                    return offset
                end,
                reset = function (starttime)
                    local result = nil
                    if (measuredTime>0) then
                        result = os.time() - measuredTime + offset
                    else
                        result = offset
                    end
                    measuredTime = os.time()
                    offset = starttime or 0
                    return result
                end,
            }
        end
  }

  -- System
  System = {}
  function System.currentDirectory(path)
    if path~=nil then
        
    end
    return ""
  end
  function System.listDirectory(path)
    local result = {}
    local file = nil
    local path = path or lfs.currentdir()
    for file in lfs.dir(path) do
        if file ~= "." and file ~= ".." then
            local f = path..'/'..file
            local attr = lfs.attributes (f)
            assert (type(attr) == "table")
            local t={}
            t.name = file
            if attr.mode == "directory" then
                t.size = 0
                t.directory = true
            else
                t.size = attr.size
                t.directory = false
            end
            table.insert(result,t)
        end
    end
    return result
  end
