'===========================================================================
' Subject: DETECT COMPUTER PROCESSOR UNIT     Date: 02-03-96 (00:00)       
'  Author: Thomas Gohel                       Code: PB                     
'  Origin: comp.lang.basic.misc             Packet: DOS.ABC
'===========================================================================
'*************************************************************************
'
'  PBCPU.BAS:  Ermitteln des Prozessortyps in PowerBASIC 3.0/3.2
'              / CPU-Detection with PowerBASIC 3.0/3.2
'
'  entwickelt von Thomas Gohel  Fido:      2:2410/301.12
'  Version: 1.01                InterNet:  author@pbsound.snafu.de
'  Stand  : 02.03.1996          Homepage:  http://www.snafu.de/~pbsound/
'
'  unter Verwendung einiger Sourcen aus dem Jahre 1994 aus der ASM86.GER
'
' --------------------------------------------------------------------------
'
' Beschreibung: Das Programm fängt beim Status Prozessor = 8086 an und
' überprüft, ob jeweils die Statusregister-Bits des nächst höheren
' Prozessors gesetzt werden können.
' Bei Erkennung der Unterstützung des CPUID-Befehls wird der Prozessortyp
' aus der 'Familykennung' ermittelt. Neuere CPU's sollten diesen Befehl
' unterstützen, ebenso zukünftige Prozessorgenerationen.
'
'     Bedeutung der Variable Prozessor?:
'     0   = 8086/8088
'     1   = 80186
'     2   = 80286
'     3   = 80386
'     4   = 80486
'     5   = 80586 (Pentium)
'     6   = 80686 (Pentium Pro)
'     7   = nächste CPU-Generationen :-))
'     255 = V20/V30
'
'***************************************************************************

$COMPILE EXE
PRINT "ermittelter Prozessortyp: "; CPUTyp$
END

FUNCTION CPUTyp$ public
        LOCAL Prozessor?
        DIM Vendor AS STRING * 12

        ! pushf
        ! mov     ax, &h0000
        ! push    ax
        ! popf
        ! pushf
        ! pop     ax
        ! and     ax, &hF000
        ! cmp     ax, &hF000
        ! jnz     Teste286

        ! mov     ax, &hFFFF
        ! mov     cl, &h21
        ! shl     ax, cl
        ! jnz     Setze186
        ! mov     Prozessor?, &h00
        ! popf

        ! xor     ax, ax
        ! mov     al, &h40
        ! mul     al
        ! jz      SetzeNEC
        ! jmp     CPUEnde

        Setze186:
        ! mov     Prozessor?, &h01
        ! popf
        ! jmp     CPUEnde

        SetzeNEC:
        ! mov     Prozessor?, &hFF
        ! jmp     CPUEnde

        Teste286:
        ! mov     ax, &h7000
        ! push    ax
        ! popf
        ! pushf
        ! pop     ax
        ! and     ax, &h7000
        ! jnz     Teste386
        ! mov     Prozessor?, &h02
        ! popf
        ! jmp     CPUEnde

        Teste386:
        ! mov     bx, sp
        ! and     sp, &hFFFC
        ! db      &h66
        ! pushf
        ! db      &h66
        ! pop     ax
        ! db      &h66
        ! mov     cx, ax
        ! db      &h66
        ! xor     ax, &h0000
        ! dw      &h0004
        ! db      &h66
        ! push    ax
        ! db      &h66
        ! popf
        ! db      &h66
        ! pushf
        ! db      &h66
        ! pop     ax
        ! db      &h66
        ! xor     ax, cx
        ! mov     Prozessor?, &h03
        ! mov     sp, bx
        ! jz      CPUEnde
        ! and     sp, &hFFFC
        ! db      &h66
        ! push    cx
        ! db      &h66
        ! popf
        ! mov     sp, bx

        Teste486:
        ! mov     Prozessor?, &h04
        ! db      &h66
        ! mov     ax, cx
        ! db      &h66
        ! xor     ax, &h0000
        ! dw      &h0020
        ! db      &h66
        ! push    ax
        ! db      &h66
        ! popf
        ! db      &h66
        ! pushf
        ! db      &h66
        ! pop     ax
        ! db      &h66
        ! xor     ax, cx
        ! je      CPUEnde

        TesteCPUID:
        ! db      &h66
        ! xor     ax, ax
        ! inc     ax
        ! dw      &hA20F
        ! and     ah, &h0F
        ! mov     Prozessor?, ah
        ! xor     ax, ax
        ! dw      &hA20F
        ! db      &h66
        ! mov     Vendor$[00], bx
        ! db      &h66
        ! mov     Vendor$[04], dx
        ! db      &h66
        ! mov     Vendor$[08], cx

        CPUEnde:
        SELECT CASE Vendor$
            CASE "GenuineIntel": Manufacturer$ = "Intel "
            CASE "AuthenticAMD": Manufacturer$ = "AMD "
            CASE "NexGenDevice": Manufacturer$ = "NexGen "
            'CASE "UMC UMC UMC ": Manufacturer$ = "??? "
            CASE ELSE          : Manufacturer$ = "Intel "
        END SELECT
        SELECT CASE Prozessor?
            CASE 0  : CPUTyp$ = "Intel 8088/8086"
            CASE 1  : CPUTyp$ = "Intel 80186"
            CASE 2  : CPUTyp$ = "Intel 80286"
            CASE 3  : CPUTyp$ = "Intel 80386"
            CASE 4  : CPUTyp$ = Manufacturer$ + "80486"
            CASE 5  : CPUTyp$ = Manufacturer$ + "Pentium"
            CASE 6  : CPUTyp$ = Manufacturer$ + "Pentium Pro"
            CASE 255: CPUTyp$ = "NEC V20/V30"
            CASE ELSE:
                      CPUTyp$ = "Intel 80" + CHR$(Prozessor? + 48) + "86"
        END SELECT
END FUNCTION
