aff_b_w=true
--***Preparation de la memoire ram
System.memclean()
collectgarbage()
kernel={}
kernel_dossier=System.currentDirectory()
dofile(kernel_dossier.."/WINDOWS/KERNEL/KERNEL.sys")
fond_ecran=Image.load(kernel:addWalpapper())
System.homePopup(0)
--***Lancement des modules cpu necessaire
System.setHigh()
System.hook(kernel_dossier.."/EBOOT.PBP")

if io.open(kernel_dossier.."/backup.sys","r") then ----test de retour a l'hb
start_t_t_t=false
 ecran=Image.createEmpty(480,272)

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.rename(kernel_dossier.."/backup.sys","last_back.sys")
System.removeFile(kernel_dossier.."/last_back.sys")
 else
 
--***Fond default
screen_default_pic=Image.load(kernel_dossier.."/WINDOWS/SYSTEM32/logo.png")
screen_load=Image.load(kernel_dossier.."/WINDOWS/SYSTEM32/loading.png")
--***Fonctions primaire d'affichage
 
 
 
message_kernel={}
nb_k=0
function kernel:animScreen(message,temps)
nb_k=nb_k+1
screen:clear()
screen:blit(0,0,fond_ecran)
screen:blit(0,0,screen_default_pic)
if nb_k==1 then

elseif nb_k>=4 and nb_k<9 then
screen:blit(88,173-65,screen_load,0,0,53,104)
elseif nb_k>=9 and nb_k<12 then
screen:blit(88,173-65,screen_load,0,0,107,104)
elseif nb_k>=12 and nb_k<16 then
screen:blit(88,173-65,screen_load,0,0,158,104)
elseif nb_k>=16 and nb_k<18 then
screen:blit(88,173-65,screen_load,0,0,216,104)
elseif nb_k>=18  then
screen:blit(88,173-65,screen_load)
end

System.sleep(temps)
screen.flip()
screen.waitVblankStart()
end 
 
 
--***Chargement du kernel
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("",100)
kernel:animScreen("Press Start to begin ...",300)
kernel:animScreen("Press Select to Configure ...",0)


ecran=Image.createEmpty(480,272)
mousex=480/2
mousey=272/2
screen:clear()
screen:blit(0,0,ecran)
ecran:clear()
ecran:blit(0,0,fond_ecran)
kernel:changeCursor(mousecharg)
kernel:displayedMouse(mousex,mousey,mouse_type)
screen:blit(0,0,ecran)
screen.flip()
screen.waitVblankStart()
System.sleep(1500)
temp=0
while temp<35 do
    pad=Controls.read()
    kernel:changeCursor(mousecharg)
    screen:clear()
    screen:blit(0,0,ecran)
    ecran:clear()
    kernel:displayedPic(0,0,fond_ecran)
    kernel:displayedMouse(mousex,mousey,mouse_type)
    kernel:mouse()

    screen.flip()
    screen.waitVblankStart()
	temp=temp+1
end
temp=nil
System.sleep(100)
--***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 ")
 end
 autoboot_my_fichiers()
 statut_barre_kernel={}
aff_b_w=true
while true do
if statut_barre_kernel[3] then
statut_barre_kernel[1]=false
statut_barre_kernel[2]=false
else
statut_barre_kernel[1]=true
statut_barre_kernel[2]=true
end
if etat_help_bul then 
statut_barre_kernel[2]=true
end
    kernel_clique_droit=false
	kernel_clique_gauche=false
    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() or kernel_clique_gauche==true then kernel:InitLeft() end
    if pad:hold() then dofile(kernel_dossier.."/WINDOWS/VEILLE/star.vei") end
	if pad:select() and nWin>0 then 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 
