; jamesboyd@all-hail.freeserve.co.uk

.GetCPU

; Returns :

; 0 = 68000
; 1 = 68010
; 2 = 68020
; 3 = 68030
; 4 = 68040
; 6 = 68060

Function.b GetCPU {}

cpu.b=0

*e.ExecBase = Peek.l(4)

#AFF_68060=(1 LSL 7)

If *e\AttnFlags & #AFF_68010
  If *e\AttnFlags & #AFF_68020
    If *e\AttnFlags & #AFF_68030
      If *e\AttnFlags & #AFF_68040
        If *e\AttnFlags & #AFF_68060
          cpu=6
        Else cpu=4
        EndIf
      Else cpu=3
      EndIf
    Else cpu=2
    EndIf
  Else cpu=1
  EndIf
Else cpu=0
EndIf

Function Return cpu
End Function

;-----------------------------------------------------------------

.GetFPU

; Returns :

; 0 = No FPU
; 1 = 68881 FPU
; 2 = 68882 FPU
; 3 = 68040 FPU (no math emulation)
; 4 = 68040 FPU (math emulation)
; 5 = 68060 FPU (no math emulation)
; 6 = 68060 FPU (math emulation)

Function.b GetFPU {}

fpu.b=0

*e.ExecBase = Peek.l(4)

#AFF_68060=(1 LSL 7)

If *e\AttnFlags & #AFF_68881
  If *e\AttnFlags & #AFF_68882
    fpu=2
  Else fpu=1
  EndIf

  If *e\AttnFlags & #AFF_FPU40
    fpu=4                         ; 68040 FPU (math emulation)
    If *e\AttnFlags & #AFF_68060  ; check for 060...
      fpu=6                       ; 68060 FPU (math emulation)
    EndIf
  EndIf

Else fpu=0                        ; No 68881 or 68882

  If *e\AttnFlags & #AFF_FPU40    ; check if it's an 040 without 6888x emulation...
    fpu=3                         ; 68040 FPU (no math emulation)
    If *e\AttnFlags & #AFF_68060  ; check for 060...
      fpu=5                       ; 68060 FPU (no math emulation)
    EndIf
  EndIf

EndIf

Function Return fpu
End Function

; demo :

WBStartup

Select GetCPU{}
  Case 0
    cpu$="68000"
  Case 1
    cpu$="68010"
  Case 2
    cpu$="68020"
  Case 3
    cpu$="68030"
  Case 4
    cpu$="68040"
  Case 6
    cpu$="68060"
End Select

Select GetFPU{}
  Case 0
    fpu$="None"
  Case 1
    fpu$="68881"
  Case 2
    fpu$="68882"
  Case 3
    fpu$="68040 FPU (no math emulation)"
  Case 4
    fpu$="68040 FPU (math emulation)"
  Case 5
    fpu$="68060 FPU (no math emulation)"
  Case 6
    fpu$="68060 FPU (math emulation)"
End Select

r.b=RTEZRequest ("ShowCPU","CPU : "+cpu$+Chr$(10)+"FPU : "+fpu$,"Perfect!")
End

