' Gambas module file

' Copyright(C) 2011-2014, Michał Głowienka aka eloaders <eloaders@linux.pl>
'
' This program is free software; you can redistribute it and/or modify
' it under the terms of the GNU General Public License as published by
' the Free Software Foundation; either version 3 of the License, or
' (at your option) any later version.
'
' This program is distributed in the hope that it will be useful,
' but WITHOUT ANY WARRANTY; without even the implied warranty of
' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
' GNU General Public License for more details.
'
' You should have received a copy of the GNU General Public License
' along with this program. If not, see <http://www.gnu.org/licenses/>.

Public Logs As New Logger
Public HTT As String
Public X86_X64 As String
Public VIRT As String
Public instructions As String
Public Sub _init()
 Dim OneFlag As String
 Finfosys.ToolButton2.Picture = Picture["Data/check_false.png"]
 Finfosys.ToolButton1.Picture = Picture["Data/check_false.png"]
 X86_X64 = "False"
 HTT = "False"
 VIRT = "False"
 For Each OneFlag In Split(Finfosys.CPU_FLAGS[CFloat(Finfosys.ComboBox1.Index)], " ", "%%")
  Select Case OneFlag
   Case "mmxext"
    instructions &= "MMX(+), "
   Case "mmx"
    instructions &= "MMX, " 
   Case "3dnowext"
    instructions &= "3DNow!(+), "
   Case "sse"
    instructions &= "SSE, " 
   Case "3dnow"
    instructions &= "3DNow!, "
   Case "sse2"
    instructions &= "SSE2, "
   Case "pni"
    instructions &= "SSE3, "
   Case "ssse3"
    instructions &= "SSSE3, "
   Case "sse4_2"
    instructions &= "SSE4.2, "
   Case "sse4_1"
    instructions &= "SSE4.1, "
   Case "sse4a"
    instructions &= "SSE4a, "
   Case "nx"
    If Finfosys.CPU_VENDOR_ID[CFloat(Finfosys.ComboBox1.Index)] Like "*Intel*" Then
     instructions &= "XD-Bit, "
    Else
     instructions &= "NX-Bit, "
    Endif
   Case "lm"
    Finfosys.ToolButton1.Picture = Picture["Data/check_true.png"]
    X86_X64 = "True"
   Case "vmx"
    Finfosys.ToolButton2.Picture = Picture["Data/check_true.png"]
    VIRT = "True"
   Case "svm"
    Finfosys.ToolButton2.Picture = Picture["Data/check_true.png"]
    HTT = "True"
   Case "ht"
    If Finfosys.CPU_VENDOR_ID[CFloat(Finfosys.ComboBox1.Index)] Like "*AMD*" Then
     Finfosys.ToolButton3.Picture = Picture["Data/check_true.png"]
     Finfosys.Label99.Text = "Hyper-Transport:"
    Endif
   Case "lm"
    Finfosys.ToolButton1.Picture = Picture["Data/check_true.png"]
    X86_X64 = "True"
  End Select
 Next

 If Exist("/dev/kvm") = True Then
  Finfosys.ToolButton4.Picture = Picture["Data/check_true.png"]
 Else
  Finfosys.ToolButton4.Picture = Picture["Data/check_false.png"]
 Endif
 ht()
End

Public Sub ht()
  Dim NUMLOG, NUMPHY As Float
  'CString(Finfosys.CPU_PROCESSOR.Count)
  Try NUMPHY = Finfosys.CPU_PROCESSOR.Count
  Try NUMLOG = CFloat(Finfosys.CPU_CPU_CORES[CFloat(Finfosys.ComboBox1.Index)])
  
  If NUMLOG = Null Then
   Logs("CPU Cores is Null", Logger.Info)
  Else
     If NUMPHY = NUMLOG Then
        Finfosys.ToolButton3.Picture = Picture["Data/check_false.png"]
        Logs("Not detect HT", Logger.Info)
        HTT = "False"
        Else
        Finfosys.ToolButton3.Picture = Picture["Data/check_true.png"]
        Logs("Detected HT", Logger.Info)
        HTT = "True"
     Endif
  Endif
End
