@name Robotboy655's Operating System
@inputs CS:wirelink KB:wirelink RFIDReader:wirelink RFIDWriter:wirelink
@inputs Start Reset X Y Use
@outputs Power OS_X OS_Y
@persist Bios Loading Desktop Shutting_Down Fail Server_Info RFID_Reader RFID_Writer Notepad
@persist BiosError StartMenu ProgrammsMenu RFIDA RFIDB RFIDC RFIDD
@trigger all


# SHIT CODED, REWRITE USING EGP OR SOMETHING, DELETE THIS
#Made by robotboy655

#Customiable Variables
CBackground = 339
CBlack = 0

CBars = 555
CBarsOver = 777
CBarsText = 100

CStart = 50
CStartOver = 90
CStartText = 999

CWinTitle = 115
CWinBars = 666
CWinText = 999
CWinClose = 500
CWinCloseOver = 900
CButton = 111
CButtonOver = 333

CGood = 50
CBad = 500
#Customiable Variables

#Variables
OS_X = floor(X*30)
OS_Y = floor(Y*17)+1
#Variables

#Duped
if(duped())
{
    hint("Robotboy655: My chips are for personal use!",5)
    #selfDestruct()
}
#Duped

#First run
if(first())
{
    CS[2041] = 1 #Clear
    CS[2042] = 0 #Background

    Power = 0

    Bios = 0
    BiosError = 0

    Loading = 0
    Desktop = 0
    Shutting_Down = 0
    Fail = 0
    StartMenu = 0
    ProgrammsMenu = 0
    Server_Info = 0
    RFID_Reader = 0
    RFID_Writer = 0
    Notepad = 0
    RFIDA = 0
    RFIDB = 0
    RFIDC = 0
    RFIDD = 0
}
#First run

#Timers
if(clk("BiosLoading"))
{
    Bios = 0
    CS[2041] = 1
    CS[2042] = 0
    Loading = 1
}
if(clk("BiosFail"))
{
    Bios = 0
    BiosError = 0
    CS[2041] = 1
    CS[2042] = 0
    Fail = 1
}
if(clk("LoadingDesktop"))
{
    Loading = 0
    CS[2041] = 1
    CS[2042] = CBackground
    Desktop = 1
}
if(clk("Shutdown"))
{
    Bios = 0
    BiosError = 0
    Loading = 0
    Desktop = 0
    Shutting_Down = 0
    Fail = 0
    StartMenu = 0
    ProgrammsMenu = 0
    Server_Info = 0
    RFID_Reader = 0
    RFID_Writer = 0
    Notepad = 0
    RFIDA = 0
    RFIDB = 0
    RFIDC = 0
    RFIDD = 0
    Power = 0
    
    stoptimer("BiosLoading")
    stoptimer("BiosFail")
    stoptimer("LoadingDesktop")
    stoptimer("Shutdown")
    stoptimer("Reset")
    
    CS[2041] = 1
    CS[2042] = 0
}
if(clk("Restart"))
{
    Bios = 0
    BiosError = 0
    
    Loading = 0
    Desktop = 0
    Shutting_Down = 0
    Fail = 0
    StartMenu = 0
    ProgrammsMenu = 0
    
    Server_Info = 0
    RFID_Reader = 0
    RFID_Writer = 0
    Notepad = 0
    RFIDA = 0
    RFIDB = 0
    RFIDC = 0
    RFIDD = 0
    
    stoptimer("BiosLoading")
    stoptimer("BiosFail")
    stoptimer("LoadingDesktop")
    stoptimer("Shutdown")
    stoptimer("Reset")
    
    CS[2041] = 1
    CS[2042] = 0
    
    Bios = 1
}
#Timers

#Power
if(Start == 1)
{
    if(Power == 0)
    {
        CS[2041] = 1
        CS[2042] = 0
        Power = 1
        Bios = 1
        BiosError = 0
    }
    elseif(Power == 1 & Bios == 0 & BiosError == 0 & Loading == 0 & Desktop == 1 & Fail == 0 & Shutting_Down == 0)
    {
        CS[2041] = 1
        CS[2042] = 0
        Desktop = 0
        StartMenu = 0
        ProgrammsMenu = 0
        Server_Info = 0
        RFID_Reader = 0
        RFID_Writer = 0
        Notepad = 0
        RFIDA = 0
        RFIDB = 0
        RFIDC = 0
        RFIDD = 0

        stoptimer("BiosLoading")
        stoptimer("BiosFail")
        stoptimer("LoadingDesktop")
        stoptimer("Shutdown")
        stoptimer("Reset")

        Shutting_Down = 1
    }
}
if(Reset == 1)
{
    if(Power == 1)
    {
        timer("Restart",100)
    }
    else
    {
    }
}
#Power

#Operating system
if(Power == 1)
{
    #Bios
    if(Bios == 1)
    {
        CS:writeString("robotboy655's Operating System",0,0,9,0)
        
        CS:writeString("DEVICE TESTING",0,2,999,0)
        CS:writeString("------------------------------",0,3,999,0)
        CS:writeString("Monitor:",0,4,999,0)
        if(CS:isHiSpeed()){CS:writeString("    Installed",17,4,90,0)}else{CS:writeString("Not Installed",17,4,900,0),BiosError = 1}
        CS:writeString("Mouse:",0,5,999,0)
        if(X & Y){CS:writeString("    Installed",17,5,90,0)}else{CS:writeString("Not Installed",17,5,900,0)}
        CS:writeString("Keyboard:",0,6,999,0)
        if(KB:isHiSpeed()){CS:writeString("    Installed",17,6,90,0)}else{CS:writeString("Not Installed",17,6,900,0)}
        
        CS:writeString("MISC DEVICE TESTING",0,8,999,0)
        CS:writeString("------------------------------",0,9,999,0)
        CS:writeString("RFID Reader:",0,10,999,0)
        if(RFIDReader:isHiSpeed()){CS:writeString("    Installed",17,10,90,0)}else{CS:writeString("Not Installed",17,10,900,0)}
        CS:writeString("RFID Writer:",0,11,999,0)
        if(RFIDWriter:isHiSpeed()){CS:writeString("    Installed",17,11,90,0)}else{CS:writeString("Not Installed",17,11,900,0)}
        
        if(BiosError == 0)
        {
            timer("BiosLoading",2000)
        }
        elseif(BiosError == 1)
        {
            timer("BiosFail",10)
        }
    }
    #Bios
    
    #Loading
    if(Loading == 1)
    {
        CS:writeString("robotboy655's Operating System",0,0,9,0)
        
        CS:writeString("Loading...",10,9,999,0)
        
        timer("LoadingDesktop",5000)
    }
    #Loading
    
    #Desktop
    if(Desktop == 1)
    {
        CS:writeString("                              ",0,17,0,CBars)
        CS:writeString(time("hour")+2+":"+time("min"),25,17,CBarsText,CBars)
        CS:writeString("START",0,17,CStartText,OS_X >= 0 & OS_X <= 5 & OS_Y == 17 ? CStartOver : StartMenu == 1 ? CStartOver : CStart)
        #StartMenu
        if(OS_X >= 0 & OS_X <= 5 & OS_Y == 17 & Use == 1 & StartMenu == 0 ) #TODO: INCLUDE KB E INPUT
        {
                StartMenu = 1
        }
        elseif(OS_X >= 0 & OS_X <= 5 & OS_Y == 17 & Use == 1 & StartMenu == 1) #TODO: INCLUDE KB E INPUT
        {
                StartMenu = 0
                if(ProgrammsMenu == 1)
                {
                    ProgrammsMenu = 0
                }
        }
        
        CS:writeString("Robotboy655",0,14,StartMenu == 1 ? CStartText : CBackground,StartMenu == 1 ? CStart : CBackground)
        CS:writeString("Programms >",0,15,StartMenu == 1 ? CBarsText : CBackground,StartMenu == 1 ? OS_X >= 0 & OS_X <= 10 & OS_Y == 15 ? CBarsOver : CBars : CBackground)
        CS:writeString("Shutdown   ",0,16,StartMenu == 1 ? CBarsText : CBackground,StartMenu == 1 ? OS_X >= 0 & OS_X <= 10 & OS_Y == 16 ? CBarsOver : CBars : CBackground)
        
        if(OS_X >= 0 & OS_X <= 10 & OS_Y == 16 & Use == 1 & StartMenu == 1) #TODO: INCLUDE KB E INPUT
        {
            
            CS[2041] = 1
            CS[2042] = 0
            Desktop = 0
            StartMenu = 0
            ProgrammsMenu = 0
            Server_Info = 0
            RFID_Reader = 0
            RFID_Writer = 0
            Notepad = 0
            ShutdownMenu = 0
            RFIDA = 0
            RFIDB = 0
            RFIDC = 0
            RFIDD = 0

            stoptimer("BiosLoading")
            stoptimer("BiosFail")
            stoptimer("LoadingDesktop")
            stoptimer("Shutdown")
            stoptimer("Reset")

            Shutting_Down = 1
        }
        #StartMenu

        #ProgrammsMenu
        if(OS_X >= 0 & OS_X <= 10 & OS_Y == 15 & Use == 1 & StartMenu == 1 & ProgrammsMenu == 0) #TODO: INCLUDE KB E INPUT
        {
            ProgrammsMenu = 1
        }
        elseif(OS_X >= 0 & OS_X <= 10 & OS_Y == 15 & Use == 1 & StartMenu == 1 & ProgrammsMenu == 1) #TODO: INCLUDE KB E INPUT
        {
            ProgrammsMenu = 0
        }
        
        CS:writeString("Notepad    ",11,12,ProgrammsMenu == 1 ? CBarsText : Desktop == 0 ? CBlack : CBackground,ProgrammsMenu == 1 ? OS_X >= 10 & OS_X <= 21 & OS_Y == 12 ? CBarsOver : CBars : Desktop == 0 ? CBlack : CBackground)
        CS:writeString("Server Info",11,13,ProgrammsMenu == 1 ? CBarsText : Desktop == 0 ? CBlack : CBackground,ProgrammsMenu == 1 ? OS_X >= 10 & OS_X <= 21 & OS_Y == 13 ? CBarsOver : CBars : Desktop == 0 ? CBlack : CBackground)
        CS:writeString("RFID Reader",11,14,ProgrammsMenu == 1 ? CBarsText : Desktop == 0 ? CBlack : CBackground,ProgrammsMenu == 1 ? OS_X >= 10 & OS_X <= 21 & OS_Y == 14 ? CBarsOver : CBars : Desktop == 0 ? CBlack : CBackground)
        CS:writeString("RFID Writer",11,15,ProgrammsMenu == 1 ? CBarsText : Desktop == 0 ? CBlack : CBackground,ProgrammsMenu == 1 ? OS_X >= 10 & OS_X <= 21 & OS_Y == 15 ? CBarsOver : CBars : Desktop == 0 ? CBlack : CBackground)
        
        if(OS_X >= 10 & OS_X <= 21 & OS_Y == 13 & Use == 1 & StartMenu == 1 & ProgrammsMenu == 1)
        {
            CS[2041] = 1
            CS[2042] = CBackground
            Desktop = 0
            StartMenu = 0
            ProgrammsMenu = 0
            
            Server_Info = 1
        }
        if(OS_X >= 10 & OS_X <= 21 & OS_Y == 14 & Use == 1 & StartMenu == 1 & ProgrammsMenu == 1)
        {
            CS[2041] = 1
            CS[2042] = CBackground
            Desktop = 0
            StartMenu = 0
            ProgrammsMenu = 0
        
            RFID_Reader = 1
        }
        if(OS_X >= 10 & OS_X <= 21 & OS_Y == 15 & Use == 1 & StartMenu == 1 & ProgrammsMenu == 1)
        {
            CS[2041] = 1
            CS[2042] = CBackground
            Desktop = 0
            StartMenu = 0
            ProgrammsMenu = 0
        
            RFID_Writer = 1
        }
        if(OS_X >= 10 & OS_X <= 21 & OS_Y == 12 & Use == 1 & StartMenu == 1 & ProgrammsMenu == 1)
        {
            CS[2041] = 1
            CS[2042] = CBackground
            Desktop = 0
            StartMenu = 0
            ProgrammsMenu = 0
        
            Notepad = 1
        }
        #ProgrammsMenu
    }
    #Desktop
    
    #Shutting_Down
    if(Shutting_Down == 1)
    {
        CS:writeString("robotboy655's Operating System",0,0,9,0)
        
        CS:writeString("Shutting down...",7,9,999,0)
        
        timer("Shutdown",3000)
    }
    #Shutting_Down
    
    #Fail
    if(Fail == 1)
    {
        CS:writeString("robotboy655's Operating System",0,0,9,0)
        
        CS:writeString("FAIL",13,2,999,0)
        CS:writeString("A problem has been detected",0,3,999,0)
        CS:writeString("and robotboy655's OS has been",0,4,999,0)
        CS:writeString("shut down to prevent damage ",0,5,999,0)
        CS:writeString("to your computer.",0,6,999,0)
        
        CS:writeString("This message can be caused",0,8,999,0)
        CS:writeString("by next issues:",0,9,999,0)
        CS:writeString("1) Monitor is (was) not",0,10,999,0)
        CS:writeString("connected to your computer.",0,11,999,0)
        CS:writeString("2) Something wanted to do",0,12,999,0)
        CS:writeString("a restricted action.",0,13,999,0)
        
        CS:writeString("Please check if all devices",0,15,999,0)
        CS:writeString("connected propertly and",0,16,999,0)
        CS:writeString("restart your computer.",0,17,999,0)
    }
    #Fail
    
    #Server Info
    if(Server_Info == 1)
    {
        interval(100)
        
        CS:writeString("                              ",0,0,CWinTitle,CWinTitle)
        CS:writeString("Server Information",0,0,CWinText,CWinTitle)
        CS:writeString("X",29,0,999,OS_X >= 28 & OS_X <= 29 & OS_Y == 1 ? CWinCloseOver : CWinClose)
        
        CS:writeString(hostname(),1,3,CWinText,CBackground)
        CS:writeString(map(),1,4,CWinText,CBackground)
        CS:writeString(gamemode(),1,5,CWinText,CBackground)
        CS:writeString("Gravity: "+gravity()+" ",1,6,CWinText,CBackground)
        CS:writeString("Players: "+numPlayers()+"/"+maxPlayers()+" ",1,7,CWinText,CBackground)
        CS:writeString("Lan?: "+isLan()+" ",1,8,CWinText,CBackground)
        CS:writeString("SingePlayer?: "+isSinglePlayer()+" ",1,9,CWinText,CBackground)
        CS:writeString("Dedicated?: "+isDedicated()+" ",1,10,CWinText,CBackground)
        CS:writeString("Ping: "+owner():ping()+" ",1,11,CWinText,CBackground)
        CS:writeString("PlayerDamage?: "+playerDamage()+" ",1,12,CWinText,CBackground)
        CS:writeString("Date: "+time("day")+"/"+time("month")+"/"+time("year")+" ",1,13,CWinText,CBackground)
        CS:writeString("Time: "+(time("hour")+2)+":"+time("min")+":"+time("sec")+" ",1,14,CWinText,CBackground)

        CS:writeString("                              ",0,17,0,CWinBars)   
             
        if(OS_X >= 28 & OS_X <= 29 & OS_Y == 1 & Use == 1)
        {
            Server_Info = 0
            Desktop = 1
            StartMenu = 0
            ProgrammsMenu = 0
            CS[2041] = 1
            CS[2042] = CBackground
        }
    }
    #Server Info
    
    #RFID Reader
    if(RFID_Reader == 1)
    {
        interval(100)

        CS:writeString("                              ",0,0,CWinTitle,CWinTitle)
        CS:writeString("RFID Reader",0,0,CWinText,CWinTitle)
        CS:writeString("X",29,0,999,OS_X >= 28 & OS_X <= 29 & OS_Y == 1 ? CWinCloseOver : CWinClose)

        CS:writeString("A: "+RFIDReader["A",number]+" ",1,6,CWinText,CBackground)
        CS:writeString("B: "+RFIDReader["B",number]+" ",1,7,CWinText,CBackground)
        CS:writeString("C: "+RFIDReader["C",number]+" ",1,8,CWinText,CBackground)
        CS:writeString("D: "+RFIDReader["D",number]+" ",1,9,CWinText,CBackground)
        
        CS:writeString("State:",1,14,CWinText,CBackground)
        if(RFIDReader["State",number] == -1)
        {
            CS:writeString("Object without RFID found",1,15,900,CBackground)
        }
        elseif(RFIDReader["State",number] == 0)
        {
            CS:writeString("Waiting for object       ",1,15,CWinText,CBackground)
        }
        elseif(RFIDReader["State",number] == 1)
        {
            CS:writeString("Object with RFID found   ",1,15,90,CBackground)
        }

        CS:writeString("                              ",0,17,0,CWinBars) 

        if(OS_X >= 28 & OS_X <= 29 & OS_Y == 1 & Use == 1)
        {
            RFID_Reader = 0
            Desktop = 1
            StartMenu = 0
            ProgrammsMenu = 0
            CS[2041] = 1
            CS[2042] = CBackground
        }
    }
    #RFID Reader
    
    #RFID Writer
    if(RFID_Writer == 1)
    {
        interval(100)

        CS:writeString("                              ",0,0,CWinTitle,CWinTitle)
        CS:writeString("RFID Writer",0,0,CWinText,CWinTitle)
        CS:writeString("X",29,0,999,OS_X >= 28 & OS_X <= 29 & OS_Y == 1 ? CWinCloseOver : CWinClose)

        CS:writeString("A: "+RFIDA+" ",1,3,CWinText,CBackground)
        CS:writeString("+",27,3,CWinText,OS_X == 26 & OS_Y == 4 ? CButtonOver : CButton)
        CS:writeString("-",28,3,CWinText,OS_X == 27 & OS_Y == 4 ? CButtonOver : CButton)
        
        if(OS_X == 26 & OS_Y == 4 & Use == 1)
        {
            RFIDA += 1
        }
        if(OS_X == 27 & OS_Y == 4 & Use == 1)
        {
            RFIDA -= 1
        }
        
        CS:writeString("B: "+RFIDB+" ",1,4,CWinText,CBackground)
        CS:writeString("+",27,4,CWinText,OS_X == 26 & OS_Y == 5 ? CButtonOver : CButton)
        CS:writeString("-",28,4,CWinText,OS_X == 27 & OS_Y == 5 ? CButtonOver : CButton)
        
        if(OS_X == 26 & OS_Y == 5 & Use == 1)
        {
            RFIDB += 1
        }
        if(OS_X == 27 & OS_Y == 5 & Use == 1)
        {
            RFIDB -= 1
        }
        
        CS:writeString("C: "+RFIDC+" ",1,5,CWinText,CBackground)
        CS:writeString("+",27,5,CWinText,OS_X == 26 & OS_Y == 6 ? CButtonOver : CButton)
        CS:writeString("-",28,5,CWinText,OS_X == 27 & OS_Y == 6 ? CButtonOver : CButton)
        
        if(OS_X == 26 & OS_Y == 6 & Use == 1)
        {
            RFIDC += 1
        }
        if(OS_X == 27 & OS_Y == 6 & Use == 1)
        {
            RFIDC -= 1
        }
        
        CS:writeString("D: "+RFIDD+" ",1,6,CWinText,CBackground)
        CS:writeString("+",27,6,CWinText,OS_X == 26 & OS_Y == 7 ? CButtonOver : CButton)
        CS:writeString("-",28,6,CWinText,OS_X == 27 & OS_Y == 7 ? CButtonOver : CButton)
        
        if(OS_X == 26 & OS_Y == 7 & Use == 1)
        {
            RFIDD += 1
        }
        if(OS_X == 27 & OS_Y == 7 & Use == 1)
        {
            RFIDD -= 1
        }
        
        CS:writeString("        Reset Values        ",1,8,CWinText,OS_X >= 1 & OS_X <= 28 & OS_Y == 9 ? CButtonOver : CButton)
        
        if(OS_X >= 1 & OS_X <= 28 & OS_Y == 9 & Use == 1)
        {
            RFIDA = 0
            RFIDB = 0
            RFIDC = 0
            RFIDD = 0
        }
        
        CS:writeString("  Import Values From Reader ",1,10,CWinText,OS_X >= 1 & OS_X <= 28 & OS_Y == 11 ? CButtonOver : CButton)
        
        if(OS_X >= 1 & OS_X <= 28 & OS_Y == 11 & Use == 1)
        {
            RFIDA = RFIDReader["A",number]
            RFIDB = RFIDReader["B",number]
            RFIDC = RFIDReader["C",number]
            RFIDD = RFIDReader["D",number]
        }
        
        RFIDWriter["A",number] = RFIDA
        RFIDWriter["B",number] = RFIDB
        RFIDWriter["C",number] = RFIDC
        RFIDWriter["D",number] = RFIDD

        CS:writeString("             ",1,13,CWinText,OS_X >= 2 & OS_X <= 13 & OS_Y >= 13 & OS_Y <= 15 ? CButtonOver : CButton)
        CS:writeString("    Write    ",1,14,CWinText,OS_X >= 2 & OS_X <= 13 & OS_Y >= 13 & OS_Y <= 15 ? CButtonOver : CButton)
        CS:writeString("             ",1,15,CWinText,OS_X >= 2 & OS_X <= 13 & OS_Y >= 13 & OS_Y <= 15 ? CButtonOver : CButton)
        
        if(OS_X >= 2 & OS_X <= 13 & OS_Y >= 13 & OS_Y <= 15 & Use == 1)
        {
            RFIDWriter["Fire",number] = 1
        }
        else
        {
            RFIDWriter["Fire",number] = 0
        }
        
        CS:writeString("            ",17,13,CWinText,OS_X >= 17 & OS_X <= 28 & OS_Y >= 13 & OS_Y <= 15 ? CButtonOver : CButton)
        CS:writeString("   Remove   ",17,14,CWinText,OS_X >= 17 & OS_X <= 28 & OS_Y >= 13 & OS_Y <= 15 ? CButtonOver : CButton)
        CS:writeString("            ",17,15,CWinText,OS_X >= 17 & OS_X <= 28 & OS_Y >= 13 & OS_Y <= 15 ? CButtonOver : CButton)

        if(OS_X >= 17 & OS_X <= 28 & OS_Y >= 13 & OS_Y <= 15 & Use == 1)
        {
            RFIDWriter["Remove",number] = 1
        }
        else
        {
            RFIDWriter["Remove",number] = 0
        }

        CS:writeString("                              ",0,17,0,CWinBars) 

        if(OS_X >= 28 & OS_X <= 29 & OS_Y == 1 & Use == 1)
        {
            RFID_Writer = 0
            Desktop = 1
            StartMenu = 0
            ProgrammsMenu = 0
            CS[2041] = 1
            CS[2042] = CBackground
        }
    }
    #RFID Writer
    
    #Notepad
    if(Notepad == 1)
    {
        interval(100)

        CS:writeString("                              ",0,0,CWinTitle,CWinTitle)
        CS:writeString("Notepad",0,0,CWinText,CWinTitle)
        CS:writeString("X",29,0,999,OS_X >= 28 & OS_X <= 29 & OS_Y == 1 ? CWinCloseOver : CWinClose)

        CS:writeString("Notepad is not done yet!",3,9,CWinText,CBackground)

        CS:writeString("                              ",0,17,0,CWinBars) 

        if(OS_X >= 28 & OS_X <= 29 & OS_Y == 1 & Use == 1)
        {
            Notepad = 0
            Desktop = 1
            StartMenu = 0
            ProgrammsMenu = 0
            CS[2041] = 1
            CS[2042] = CBackground
        }
    }
    #Notepad
}
#Operating system
