@name W64-R_OS
@inputs Processor:entity On
@outputs
@persist Graphic:entity Sound:entity Interface:entity
@persist E:entity Screen:wirelink ScrW ScrH Version:string
@persist SP1:entity SP2:entity GTABLE:gtable
@trigger 
@model models/expression 2/cpu_controller.mdl

if (first() | duped()){
    E = entity()
    Graphic = Processor["Graphic", entity]
    Sound = Processor["Sound", entity]
    Interface = Processor["Interface", entity]
    Screen = Graphic["Screen", wirelink]
        
    GTABLE = gTable("CONSOLE_CAKE",1)    
    
    ScrW = Graphic["ScrW", number]
    ScrH = Graphic["ScrH", number]
        
    Screen:egpScale(vec2(0, ScrW), vec2(0, ScrH))
    Screen:egpClear()  
    
    SP1 = Sound["Speaker1", entity]
    SP2 = Sound["Speaker2", entity]
    SP1["Play", number] = 0
    SP2["Play", number] = 0
    GTABLE["startup",number] = 0
    
}

if (On && ~On){
    Screen:egpCircle(1, vec2((ScrW / 2), (ScrH / 2)), vec2(ScrW / 4, ScrH / 4))
    Screen:egpColor(1, vec(150, 0, 0))
    Screen:egpMaterial(1, "expression 2/cog")
    
    Screen:egpText(2, "Wiremod 64", vec2(ScrW / 2, ScrH * 0.15) )
    Screen:egpFont(2, "Arial", 60)
    Screen:egpColor(2, vec(150, 0, 0))
    Screen:egpAlign(2, 1, 1)
    
    Screen:egpText(3, "Insert Game Cartridge", vec2(ScrW / 2, ScrH / 2) )
    Screen:egpFont(3, "Arial", 60)
    Screen:egpColor(3, vec(255, 255, 255))
    Screen:egpAlign(3, 1, 1)
    
}

if (!On && ~On){
    Screen:egpClear()
    SP1["Play", number] = 0
    SP2["Play", number] = 0
    E["Started", number] = 0
}

interval(100)

if (!entity(Processor["Game", number])["Started", number]){
    if (Processor["Game", number]){
        Game = entity(Processor["Game", number])
        Screen:egpSetText(3, "Game: " + Game["Name", string])
        
        if(GTABLE["startup",number] == 0){
            GTABLE["startup",number] = 1 
            print("once")  
        }
        
    }else{
        Screen:egpSetText(3, "Insert game")
        GTABLE["startup",number] = 0
    }
}

Screen:egpAngle(1, curtime() * 90)


