(* Bunch of junk here, i think totalextram needs to be fixed *)
(* Just detects certain things *)

unit detector;
interface

function  cputype   : string;
function  disktotal : longint;
function  diskfrees : longint;
function  totalbaseram : word;
function  totalextram  : word;
Procedure TimeSlice;
Procedure InitMulti;
function  whatos  : string;
function  whatver : string;

Type
  TaskRec = Record
    OS      : Word;
    Version : Word;
    Delay   : Word;
  End;

Const
  Task    : TaskRec = (
  OS      : 0;
  Version : 0;
  Delay   : 100
  );
implementation

uses dos,crt,genstr;

function  whatos  : string;
begin
case task.os of

   0 : whatos:='No MultiTasking';
   1 : whatos:='MS Windows 3.x';
   2 : whatos:='OS/2';
   3 : whatos:='DESQview';
   4 : whatos:='TopView';
   5 : whatos:='PC-MOS/386';
   6 : whatos:='Linux DOSEMU';
   7 : whatos:='OS/2 Warp';
   8 : whatos:='Win95';
   9 : whatos:='European MS-DOS';
  10 : whatos:='DoubleDOS';
  end;

end;

function  whatver : string;
begin
whatver:=strr(hi(task.Version))+ '.'+ strr(lo(task.Version));
end;

Procedure InitMulti;
Assembler;
Asm
  mov  Task. OS, 0
  mov  Task. Version, 0
  mov  AX, 4010h
  int  2fh
  cmp  AX, 4010h
  jne  @OS2
  push BX ; push DX
  push DS ; push SI
  mov  AX, 4A33h
  int  2fh
  pop  SI ; pop  DS
  pop  DX ; pop  BX
  cmp  AX, 0
  je   @Win95
  mov  AX, 160Ah
  Int  2Fh
  cmp  AX, 0
  je   @Windows
  mov  AX, 1022h
  mov  BX, 0000h
  Int  15h
  cmp  BX, 0
  jne  @DESQview
  mov  AH, 2BH
  mov  AL, 01h
  mov  CX, 4445h
  mov  DX, 5351h
  Int  21h
  cmp  AL, $FF
  jne  @TopView
  mov  AX, 3000h
  mov  BX, 3000h
  mov  CX, 3000h
  mov  DX, 3000h
  int  21h
  cmp  AL, 3
  je   @PC_MOS
  mov  AH, 87h
  mov  AL, 0
  int  21h
  cmp  AL, 0
  jne  @European
  mov  AX, $E400
  int  21h
  cmp  AL, 0
  jne  @DoubleDOS
  mov  AH, $35
  mov  AL, $E6
  int  21h
  mov  ES, AX
  cmp  AX, $F000
  jne  @Fin
  cmp  BX, $0E60
  jne  @Fin
  mov  AX, 0
  int  $E6
  cmp  AH, $AA
  jne  @Fin
  cmp  AL, $55
  je   @Linux
  jmp  @Fin
  @Windows:
  Mov  Task. OS, 1
  Mov  Task. Version, BX
  jmp  @Fin
  @OS2:
  Mov  Task. OS, 2
  cmp  AX, 0000h
  je   @Warp
  Mov  BH, AH
  XOr  AH, AH
  Mov  CL, 10
  Div  CL
  Mov  AH, BH
  Xchg AH, AL
  jmp  @OS2_done
  @Warp:
  mov  AH, 3
  mov  AL, 0
  mov  Task. OS, 7
  @OS2_done:
  Mov  Task. Version, AX
  jmp  @Fin
  @DESQview:
  mov  Task. OS, 3
  mov  Task. Version, BX
  jmp  @Fin
  @TopView:
  mov  Task. OS, 4
  mov  Task. Version, BX
  jmp  @Fin
  @PC_MOS:
  mov  Task. OS, 5
  mov  Task. Version, AX
  jmp  @Fin
  @Linux:
  mov  AH, 12h
  mov  BX, 20
  int  $E6
  mov  Task. OS, 6
  mov  Task. Version, BX
  jmp  @Fin
  @Win95:
  mov  AX, 160Ah
  Int  2Fh
  mov  Task. OS, 8
  mov  Task. Version, BX
  jmp  @Fin
  @European:
  mov  Task. OS, 9
  mov  Task. Version, 0400
  jmp  @Fin
  @DoubleDOS:
  mov  Task. OS, 10
  mov  Task. Version, 0100
  jmp  @Fin
  @Fin:
End;

Procedure TimeSlice;
Assembler;
Asm
  cmp  Task. OS, 0
  je   @Fin
  cmp  Task. OS, 1
  je   @Win
  cmp  Task. OS, 2
  je   @OS2
  cmp  Task. OS, 3
  je   @DV_TV
  cmp  Task. OS, 4
  je   @DV_TV
  cmp  Task. OS, 5
  je   @PC_MOS
  cmp  Task. OS, 6
  je   @Linux
  cmp  Task. OS, 7
  je   @OS2
  cmp  Task. OS, 8
  je   @Win95
  cmp  Task. OS, 9
  je   @European
  cmp  Task. OS, 10
  je   @DoubleDOS
  @DV_TV:
  mov  AX, 1000h
  Int  15h
  jmp  @Fin
  @Win:
  mov  AX, 1680h
  Int  2Fh
  jmp  @Fin
  @OS2:
  mov  ax,32
  mov  dx,0
  hlt
  db   35h, 0CAh
  jmp  @Fin
  @PC_MOS:
  int  28h
  jmp  @Fin
  @Linux:
  int  28h
  jmp  @Fin
  @Win95:
  mov  AX, 1680h
  Int  2Fh
  jmp  @Fin
  @European:
  mov  AH, 89h
  mov  CX, 55
  Int  2Fh
  jmp  @Fin
  @DoubleDOS:
  mov  AX, $EE01
  Int  21h
  jmp  @Fin
  @Fin:
End;

function totalbaseram:word;
const
  int15: longint = $f000f859;
var baseram:word;
begin
  asm
    int   12h
    mov   baseram,ax
    mov   ah,88h
  end;
totalbaseram:=baseram;
end;

function totalextram:word;
const
  int15: longint = $f000f859;
var extram:word;
begin
  asm
    pushf
    call  int15
    mov   extram,ax
  end;
totalextram:=extram;
end;

function  disktotal : longint;
var y:longint;
    x:byte;
begin
x:=0;
y:=0;
for x:=3 to 25 do
inc(y,(disksize(x) div 1000));
disktotal:=y;
end;

function  diskfrees : longint;
var z:longint;
    x:byte;
begin
z:=0;
for x:=3 to 25 do
inc(z,(diskfree(x) div 1000));
diskfrees:=z;
end;

 function cputype : string;
 begin
  if (Test8086 = 2) then
  asm
             inc    Test8086
             mov    bx, sp
             and    sp, not 3
    db $66;  pushf
    db $66;  pop    ax
    db $66;  mov    cx, ax
    db $66, $35; dd $40000
    db $66;  push   ax
    db $66;  popf
    db $66;  pushf
    db $66;  pop    ax
    db $66;  xor    ax, cx
             je @@1
             and    sp, not 3
    db $66;  push   cx
    db $66;  popf
             mov    sp, bx
             mov  Test8086, 4
    db $66;  mov    ax, cx
    db $66, $35; dd $200000
    db $66;  push   ax
    db $66;  popf
    db $66;  pushf
    db $66;  pop    ax
    db $66;  xor    ax, cx
             je @@1
    db $66;  xor    ax, ax
    db $f,$a2
    db $66;  cmp    ax, 1
             jl @@1
    db $66;  xor    ax, ax
    db $66;  inc    ax
    db $f,$a2
             and    ax, $f00
             shr    ax, 8
             mov    Test8086, al
   @@1:
  end;
   case test8086 of
   0: cputype:='8086';
   1: cputype:='286';
   2: cputype:='386';
   3: cputype:='386';
   4: cputype:='486';
   5: cputype:='Pentium/586';
   6: cputype:='Unknown';
   end;
 end;

begin
end.