--***Preparation de la memoire ram
System.memclean()
collectgarbage()

--***Lancement des modules cpu necessaire
System.setHigh()
kernel_dossier=System.currentDirectory()
System.hook(kernel_dossier.."/EBOOT.PBP")

if System.doesFileExist(kernel_dossier.."/backup.sys") then ----test de retour à l'hb

--***Fond default
screen_default_pic=Image.load(kernel_dossier.."/WINDOWS/SYSTEM32/logo.png")
--***Fonctions primaire d'affichage
kernel={}
 
 
 
message_kernel={}
nb_k=0
function kernel:animScreen(message,temps)
nb_k=nb_k+1
message_kernel[nb_k]=message
screen:clear()
screen:blit(0,0,screen_default_pic)
for i=1,nb_k do
    screen:print(100,18+i*10,message_kernel[i],Color.new(255,255,255))
end
System.sleep(temps)
screen.flip()
screen.waitVblankStart()
end 
 
 
--***Chargement du kernel
dofile(kernel_dossier.."/WINDOWS/KERNEL/KERNEL.sys")
kernel:animScreen("Initialisation du kernel ...",300)
dofile(kernel_dossier.."/WINDOWS/KERNEL/KERNEL_DISPLAY.sys")
kernel:animScreen(" -Load display kernel ...OK",300)
kernel:animScreen(" -Load shell pictures ...OK",300)
kernel:animScreen(" -Load mouse kernel ...OK",300)
dofile(kernel_dossier.."/WINDOWS/KERNEL/KERNEL_WINDOWS.sys")
kernel:animScreen(" -Load windows kernel ...OK",300)
dofile(kernel_dossier.."/WINDOWS/KERNEL/KERNEL_WORK.sys")
kernel:animScreen(" -Load workspace kernel ...OK",300)
kernel:animScreen(" -Load user's configuration ...OK",300)
kernel:animScreen(" -Load home kernel ...OK",300)
kernel:animScreen(" -Load explorer kernel ...OK",300)
dofile(kernel_dossier.."/WINDOWS/KERNEL/KERNEL_CMD.sys")
kernel:animScreen(" -Load terminal kernel ...OK",300)
kernel:animScreen(" -Load default cmd ...OK",300)
kernel:animScreen(" -Load pad kernel ...OK",300)
kernel:animScreen(" -Load help kernel ...OK",300)
dofile(kernel_dossier.."/WINDOWS/KERNEL/KERNEL_HTML.sys")
kernel:animScreen(" -Load web kernel ...OK",300)
--***Chargement de la langue
dofile(kernel_dossier.."/LANGUES/francais.lang")
kernel:animScreen("",0)
kernel:animScreen("Load language file ...OK",300)
kernel:animScreen(" -language is "..language.." ...OK",300)
kernel:animScreen("Start MyWindows Fusion ...OK",0)
kernel:animScreen("www.mywindows-shell.fr.gd",0)
kernel:animScreen("",100)
kernel:animScreen("Press Start to begin ...",300)
kernel:animScreen("Press Select to Configure ...",0)
 while not Controls.read():start() do if Controls.read():select() then dofile(kernel_dossier.."/PRX/instal.sys") end end

ecran=Image.createEmpty(480,272)
--***Choix de session
dofile(kernel_dossier.."/WINDOWS/KERNEL/KERNEL_SESSION.sys")
--***Lavage memoire free
screen_default_pic=nil
screen_default_pic2=nil
collectgarbage()
 
 
--Position depard :
ecranx=0
ecrany=0
kernel:initHelpMsg(true)
kernel:initMsg("Bienvenue dans le kernel FUSION ")
 else
 start_t_t_t=false
 ecran=Image.createEmpty(480,272)
 kernel={}
 dofile(kernel_dossier.."/WINDOWS/KERNEL/KERNEL.sys")
dofile(kernel_dossier.."/WINDOWS/KERNEL/KERNEL_DISPLAY.sys")
dofile(kernel_dossier.."/WINDOWS/KERNEL/KERNEL_WINDOWS.sys")
dofile(kernel_dossier.."/WINDOWS/KERNEL/KERNEL_WORK.sys")
dofile(kernel_dossier.."/WINDOWS/KERNEL/KERNEL_CMD.sys")
dofile(kernel_dossier.."/WINDOWS/KERNEL/KERNEL_HTML.sys")
--***Chargement de la langue
dofile(kernel_dossier.."/LANGUES/francais.lang")
ecranx=0
ecrany=0
System.sleep(200)
System.removeFile("backup.sys")
 end
 
while true do
    blocage_mouse=false
    screen:clear()
    ecran:clear()
    pad = Controls.read()
    kernel:drawnWorkspace()
	---***Gestion des touches
	if pad:start() and pad~=oldpad then kernel:initStartSys(true) end
	if pad:square() and pad~=oldpad and winAct~=0 then Windows:close(winAct) end
    if pad:triangle() and pad~=oldpad and winAct~=0 then Windows:reduct() end
    if pad:circle() then kernel:InitLeft() end
    if pad:hold() then dofile(kernel_dossier.."/WINDOWS/VEILLE/star.vei") end
	if pad:select() then System.message(System.getFreeMemory(),0) dofile(kernel_dossier.."/WINDOWS/KERNEL/KERNEL_3D.sys") end
	---***Valeur kernel par default
	kernel:changeCursor(mousecurso)
	kernel:LeftInitTable(tbl_l_d)
	---***Affichage de la fenetre
	    if winAct~=0 then 
       if win[winAct]~=nil then coroutine.resume(win[winAct]) end
       if pad:right() then Windows:sizeChange(l_win[winAct]+4,h_win[winAct],x_win[num],y_win[num]) end
       if pad:left() then Windows:sizeChange(l_win[winAct]-4,h_win[winAct],x_win[num],y_win[num]) end
       if pad:up() then Windows:sizeChange(l_win[winAct],h_win[winAct]-4,x_win[num],y_win[num]) end
       if pad:down() then Windows:sizeChange(l_win[winAct],h_win[winAct]+4,x_win[num],y_win[num]) end
       end
	---***Affichage de l'ecran
    screen:blit(ecranx,ecrany,ecran)
    screen.flip()
    screen.waitVblankStart()
    oldpad=pad
    collectgarbage()
end 
