@name Computer Test
@inputs Keyboard EGP:wirelink SubKeyboard
@outputs MEM:array
@outputs [PTXT TXTBREAK SUBTXTP SCRMDT5 RUNT10]:array [TXT SUBTXT SCRMDT4 GLON RUNP PCODE RUNT8 RUNT9 RUNT11]:string A SCRMD INITKILL FREM
@outputs DirT RUN SCRMDT1 SCRMDT2 SCRMDT3 RUNT1 RUNT2 RUNT3 RUNT4 RUNT5 RUNT6 RUNT7
if(SCRMD==7|SCRMD==9){
    interval(20)
}elseif(SCRMD==8){
    interval(10)
}else{
    interval(100)
}
if(first()){
    EGP:egpClear()
    FREM=1
    GLON=glonEncode(array("hi.exe","clr"
    +toChar(13)+"echo Hi."
    +toChar(13)+"end"))
    MEM[1028,string]=GLON
}
if(INITKILL==0){
    EGP:egpText(1,"Initializing",vec2(5,5))
    EGP:egpText(2,"Working",vec2(5,17))
    EGP:egpText(3,"Loading done!",vec2(5,29))
}


if(MEM[1,number]>36){
    MEM[1,number]=-4
    EGP:egpClear()
    INITKILL=1
}

TXTBREAK=TXT:explode("")

if(SCRMD==0&!RUN){
    EGP:egpText(4+MEM[1,number],"Writer: "+TXT,vec2(5,42+(MEM[1,number]*12)))

    if(TXTBREAK[1,string]=="a"&TXTBREAK[2,string]=="d"&TXTBREAK[3,string]=="d"&Keyboard==13){
        SCRMD=2
    }
    if(TXTBREAK[1,string]=="s"&TXTBREAK[2,string]=="u"&TXTBREAK[3,string]=="b"&Keyboard==13){
        SCRMD=3
    }
    if(TXTBREAK[1,string]=="m"&TXTBREAK[2,string]=="u"&TXTBREAK[3,string]=="l"&Keyboard==13){
        SCRMD=4
    }
    if(TXTBREAK[1,string]=="d"&TXTBREAK[2,string]=="i"&TXTBREAK[3,string]=="v"&Keyboard==13){
        SCRMD=5
    }
    if(TXT=="input"&Keyboard==13){
        SCRMD=6
    }
    if(TXT=="dir"&Keyboard==13){
        SCRMD=7
    }
    if(TXT=="format"&Keyboard==13){
        SCRMD=8
    }
    if(TXTBREAK[1,string]=="l"&TXTBREAK[2,string]=="o"&TXTBREAK[3,string]=="a"&TXTBREAK[4,string]=="d"&&Keyboard==13){
        for(SCRMDT1=1,TXTBREAK:count()-5){
            SCRMDT4=SCRMDT4+TXTBREAK[SCRMDT1+5,string]
        }   
        SCRMD=9
    }








    TXT=""
    if(changed(Keyboard)&Keyboard!=0&Keyboard!=154){
        if(Keyboard!=127|Keyboard!=13){
            PTXT[PTXT:count()+1,string]=toChar(Keyboard)
        }
        if(Keyboard==13){
            MEM[1,number]=MEM[1,number]+1
            PTXT:clear()
        }
        if(Keyboard==127){
            PTXT:pop()
            PTXT:pop()
        }
    }
    if(Keyboard==148){
        PTXT:clear()
    }
    for(A=1,PTXT:count()){
        TXT=TXT+PTXT[A,string]
    } 
    
    
    
    
    
    
    
    
    
    
    
    
    
    
      

}




















TXTBREAK=TXT:explode("")


















if(SCRMD==2&!RUN){
    TXT=""
    PTXT:clear()
    MEM[2,number]=MEM[2,number]+(toByte(TXTBREAK[5,string])-48)*100
    MEM[2,number]=MEM[2,number]+(toByte(TXTBREAK[6,string])-48)*10
    MEM[2,number]=MEM[2,number]+(toByte(TXTBREAK[7,string])-48)
    MEM[3,number]=MEM[3,number]+(toByte(TXTBREAK[9,string])-48)*100
    MEM[3,number]=MEM[3,number]+(toByte(TXTBREAK[10,string])-48)*10
    MEM[3,number]=MEM[3,number]+(toByte(TXTBREAK[11,string])-48)
    MEM[4,number]=MEM[2,number]+MEM[3,number]
    EGP:egpText(4+MEM[1,number],"<CMD>: You added "+MEM[2,number]+" and "+MEM[3,number]+" and got "+MEM[4,number]+".",vec2(5,42+(MEM[1,number]*12)))
    MEM[1,number]=MEM[1,number]+1
    SCRMD=0
    MEM[2,number]=0
    MEM[3,number]=0
    MEM[4,number]=0
}

if(SCRMD==3&!RUN){
    TXT=""
    PTXT:clear()
    MEM[2,number]=MEM[2,number]+(toByte(TXTBREAK[5,string])-48)*100
    MEM[2,number]=MEM[2,number]+(toByte(TXTBREAK[6,string])-48)*10
    MEM[2,number]=MEM[2,number]+(toByte(TXTBREAK[7,string])-48)
    MEM[3,number]=MEM[3,number]+(toByte(TXTBREAK[9,string])-48)*100
    MEM[3,number]=MEM[3,number]+(toByte(TXTBREAK[10,string])-48)*10
    MEM[3,number]=MEM[3,number]+(toByte(TXTBREAK[11,string])-48)
    MEM[4,number]=MEM[2,number]-MEM[3,number]
    EGP:egpText(4+MEM[1,number],"<CMD>: You used "+MEM[1025,number]+" and subtracted "+MEM[1026,number]+" and got "+MEM[1027,number]+".",vec2(5,42+(MEM[1,number]*12)))
    MEM[1,number]=MEM[1,number]+1
    SCRMD=0
    MEM[2,number]=0
    MEM[3,number]=0
    MEM[4,number]=0
}

if(SCRMD==4&!RUN){
    TXT=""
    PTXT:clear()
    MEM[2,number]=MEM[2,number]+(toByte(TXTBREAK[5,string])-48)*100
    MEM[2,number]=MEM[2,number]+(toByte(TXTBREAK[6,string])-48)*10
    MEM[2,number]=MEM[2,number]+(toByte(TXTBREAK[7,string])-48)
    MEM[3,number]=MEM[3,number]+(toByte(TXTBREAK[9,string])-48)*100
    MEM[3,number]=MEM[3,number]+(toByte(TXTBREAK[10,string])-48)*10
    MEM[3,number]=MEM[3,number]+(toByte(TXTBREAK[11,string])-48)
    MEM[5,number]=MEM[2,number]*MEM[3,number]
    EGP:egpText(4+MEM[1,number],"<CMD>: You multiplied "+MEM[1025,number]+" and "+MEM[1026,number]+" and got "+MEM[1027,number]+".",vec2(5,42+(MEM[1,number]*12)))
    MEM[1,number]=MEM[1,number]+1
    SCRMD=0
    MEM[2,number]=0
    MEM[3,number]=0
    MEM[4,number]=0
}

if(SCRMD==5&!RUN){
    TXT=""
    PTXT:clear()
    MEM[2,number]=MEM[2,number]+(toByte(TXTBREAK[5,string])-48)*100
    MEM[2,number]=MEM[2,number]+(toByte(TXTBREAK[6,string])-48)*10
    MEM[2,number]=MEM[2,number]+(toByte(TXTBREAK[7,string])-48)
    MEM[3,number]=MEM[3,number]+(toByte(TXTBREAK[9,string])-48)*100
    MEM[3,number]=MEM[3,number]+(toByte(TXTBREAK[10,string])-48)*10
    MEM[3,number]=MEM[3,number]+(toByte(TXTBREAK[11,string])-48)
    MEM[1027,number]=MEM[1025,number]/MEM[1026,number]
    EGP:egpText(4+MEM[1,number],"<CMD>: You divided "+MEM[1025,number]+" by "+MEM[1026,number]+" and got "+MEM[1027,number]+".",vec2(5,42+(MEM[1,number]*12)))
    MEM[1,number]=MEM[1,number]+1
    SCRMD=0
    MEM[1025,number]=0
    MEM[1026,number]=0
    MEM[1027,number]=0
    
}

if(SCRMD==6&!RUN){
    TXT=""
    PTXT:clear()
    if(FREM){
        EGP:egpText(4+MEM[1,number],"<SubKBRD>: Now accepting input, press (DEL) on main to quit.",vec2(5,42+(MEM[1,number]*12)))
        FREM=0
        MEM[1,number]=MEM[1,number]+1
    }
    SUBTXT=""
    if(changed(SubKeyboard)&SubKeyboard!=0&SubKeyboard!=154){
        if(SubKeyboard!=127|SubKeyboard!=13){
            SUBTXTP[SUBTXTP:count()+1,string]=toChar(SubKeyboard)
        }
        if(SubKeyboard==13|SubKeyboard==12|SubKeyboard==25|SubKeyboard==127|SubKeyboard==255){
            MEM[1,number]=MEM[1,number]+1
            SUBTXTP:clear()
        }
    }
    if(SubKeyboard==148){
        SUBTXTP:clear()
    }
    for(A=1,SUBTXTP:count()){
        SUBTXT=SUBTXT+SUBTXTP[A,string]
    }
    EGP:egpText(4+MEM[1,number],"<SubKBRD>: "+SUBTXT,vec2(5,42+(MEM[1,number]*12)))
    if(Keyboard==148){
        SCRMD=0
        MEM[1,number]=MEM[1,number]+1
        EGP:egpText(4+MEM[1,number],"<SubKBRD>: Exited.",vec2(5,42+(MEM[1,number]*12)))
        MEM[1,number]=MEM[1,number]+1
        FREM=1
    }
}

if(SCRMD==7&!RUN){
    TXT=""
    PTXT:clear()
    EGP:egpText(4+MEM[1,number],"<CMD>: Checking 1025 to 2048. Currently checking at "+(DirT+1025)+".",vec2(5,42+(MEM[1,number]*12)))
    if(!MEM[DirT+1025,string]){
        DirT++
    }else{
        MEM[1,number]=MEM[1,number]+1
        EGP:egpText(4+MEM[1,number],"<CMD>:  -----"+glonDecode(MEM[DirT+1025,string])[1,string]+" at "+(DirT+1025)+".",vec2(5,42+(MEM[1,number]*12)))
        MEM[1,number]=MEM[1,number]+1
        DirT++
    }
    if(DirT+1025==2049){
        MEM[1,number]=MEM[1,number]+1
        EGP:egpText(4+MEM[1,number],"<CMD>: Check ended.",vec2(5,42+(MEM[1,number]*12)))
        MEM[1,number]=MEM[1,number]+1
        SCRMD=0
        DirT=0
    }
    if(Keyboard==148){
        MEM[1,number]=MEM[1,number]+1
        EGP:egpText(4+MEM[1,number],"<CMD>: Check stopped.",vec2(5,42+(MEM[1,number]*12)))
        MEM[1,number]=MEM[1,number]+1
        SCRMD=0
        DirT=0
    }
}

if(SCRMD==8&!RUN){
    TXT=""
    PTXT:clear()
    
    MEM[1,number]=-4
    EGP:egpClear()
    INITKILL=1
    
    EGP:egpText(4+MEM[1,number],"<CMD>: Formatting... "+(round(DirT/(2048/100)*10)/10)+"%.",vec2(5,42+(MEM[1,number]*12)))
    DirT++
    MEM[DirT,number]=0
    if(DirT==2049){
        MEM[1,number]=MEM[1,number]+1
        EGP:egpText(4+MEM[1,number],"<CMD>: Format complete.",vec2(5,42+(MEM[1,number]*12)))
        MEM[1,number]=MEM[1,number]+1
        SCRMD=0
        DirT=0
    }
}


if(SCRMD==9&!RUN){

    EGP:egpText(4+MEM[1,number],"<CMD>: Looking for program "+SCRMDT4+".",vec2(5,42+(MEM[1,number]*12)))
    if(glonDecode(MEM[DirT+1025,string])[1,string]!=SCRMDT4){
        DirT++
    }elseif(glonDecode(MEM[DirT+1025,string])[1,string]==SCRMDT4){
        MEM[1,number]=MEM[1,number]+1
        EGP:egpText(4+MEM[1,number],"<CMD>: Found and running!",vec2(5,42+(MEM[1,number]*12)))
        for(SCRMDT1=1,glonDecode(MEM[DirT+1025,string]):count()-1){
            PCODE=PCODE+glonDecode(MEM[DirT+1025,string])[SCRMDT1+1,string]
        }
        for(SCRMDT1=1,PCODE:explode(toChar(13)):count()){
            SCRMDT5[SCRMDT1,string]=PCODE:explode(toChar(13))[SCRMDT1,string]
        }
        RUN=DirT
    }
    if(DirT+1025==2049){
        MEM[1,number]=MEM[1,number]+1
        EGP:egpText(4+MEM[1,number],"<CMD>: File not found. Be sure the name is right.",vec2(5,42+(MEM[1,number]*12)))
        MEM[1,number]=MEM[1,number]+1
        SCRMD=0
        DirT=0
    }   

}

if(RUN){
    
    
    RUNT1++
    
    
    if(SCRMDT5[RUNT1,string]:explode(" ")[1,string]=="echo"){
        RUNT2=0
        RUNT8=""
        for(RUNT2=1,SCRMDT5[RUNT1,string]:explode(" "):count()-1){
            if(SCRMDT5[RUNT1,string]:explode(" ")[RUNT2+1,string]=="var3"){
                RUNT8=RUNT8+RUNT3+" "
            }elseif(SCRMDT5[RUNT1,string]:explode(" ")[RUNT2+1,string]=="var4"){
                RUNT8=RUNT8+RUNT4+" "
            }elseif(SCRMDT5[RUNT1,string]:explode(" ")[RUNT2+1,string]=="var5"){
                RUNT8=RUNT8+RUNT5+" "
            }elseif(SCRMDT5[RUNT1,string]:explode(" ")[RUNT2+1,string]=="var6"){
                RUNT8=RUNT8+RUNT6+" "
            }elseif(SCRMDT5[RUNT1,string]:explode(" ")[RUNT2+1,string]=="var7"){
                RUNT8=RUNT8+RUNT7+" "
            }elseif(SCRMDT5[RUNT1,string]:explode(" ")[RUNT2+1,string]=="var9"){
                RUNT8=RUNT8+RUNT9+" "
            }elseif(SCRMDT5[RUNT1,string]:explode(" ")[RUNT2+1,string]=="var11"){
                RUNT8=RUNT8+RUNT9+" "
            }else{
                RUNT8=RUNT8+SCRMDT5[RUNT1,string]:explode(" ")[RUNT2+1,string]+" "
            }
        }
        EGP:egpText(4+MEM[1,number],"<"+SCRMDT4+">: "+RUNT8,vec2(5,42+(MEM[1,number]*12)))
        MEM[1,number]=MEM[1,number]+1
    }
    
    
    if(SCRMDT5[RUNT1,string]:explode(" ")[1,string]=="clr"){
        MEM[1,number]=-4
        EGP:egpClear()
        INITKILL=1
    }
    
    
    
    if(SCRMDT5[RUNT1,string]=="end"){
        EGP:egpText(4+MEM[1,number],"<CMD>: Returning to prompt....",vec2(5,42+(MEM[1,number]*12)))
        MEM[1,number]=MEM[1,number]+1
        RUN=0
        SCRMD=0
        RUNT1=0
        SCRMDT4=""
        SCRMDT1=0
        RUNT2=0
        RUNT3=0
        RUNT4=0
        RUNT5=0
        RUNT6=0
        RUNT7=0
        RUNT8=""
        RUNT9=""
        RUNT10:clear()
    }
}
