1 ;-----------------------------------------------------------------------
\r
4 ; Hardware detection module
\r
10 ; ****** XLIB - Mode X graphics library ****************
\r
11 ; ****** ****************
\r
12 ; ****** Written By Themie Gouthas ****************
\r
14 ; egg@dstos3.dsto.gov.au
\r
15 ; teg@bart.dsto.gov.au
\r
16 ;-----------------------------------------------------------------------
\r
25 _MouseButtonCount dw 0
\r
51 PS2_CARDS db 0,1,2,2,4,3,2,5,6,2,8,7,8
\r
54 ;-----------------------------------------------------------------------
\r
55 ; PC Graphics detection routine. Returns graphics card type
\r
58 ; unsigned int x_graphics_card();
\r
62 proc _x_graphics_card
\r
63 push bp ; Preserve caller's stack frame
\r
65 mov ax,1A00h ; Try calling VGA Identity Adapter function
\r
67 cmp al,1Ah ; Do we have PS/2 video bios ?
\r
70 cmp bl,0Ch ; bl > 0Ch => CGA hardware
\r
71 jg @@is_CGA ; Jump if we have CGA
\r
74 mov al,cs:PS2_CARDS[bx] ; Load ax from PS/2 hardware table
\r
75 jmp short @@done ; return ax
\r
77 mov ax,CGA ; Have detected CGA, return id
\r
79 @@not_PS2: ; OK We don't have PS/2 Video bios
\r
80 mov ah,12h ; Set alternate function service
\r
81 mov bx,10h ; Set to return EGA information
\r
82 int 10h ; call video service
\r
83 cmp bx,10h ; Is EGA there ?
\r
84 je @@simple_adapter ; Nop!
\r
85 mov ah,12h ; Since we have EGA bios, get details
\r
88 or bh,bh ; Do we have colour EGA ?
\r
89 jz @@ega_color ; Yes
\r
90 mov ax,EGAMono ; Otherwise we have Mono EGA
\r
93 mov ax,EGAColor ; Have detected EGA Color, return id
\r
96 int 11h ; Lets try equipment determination service
\r
100 or al,al ; Do we have any graphics card at all ?
\r
101 jz @@done ; No ? This is a stupid machine!
\r
102 cmp al,3 ; Do We have a Mono adapter
\r
104 mov ax,MDA ; Have detected MDA, return id
\r
106 pop bp ;restore caller's stack frame
\r
108 _x_graphics_card endp
\r
111 ;-----------------------------------------------------------------------
\r
112 ; PC Processor detection routine
\r
115 ; unsigned int x_processor();
\r
122 xor ax,ax ; Clear AX
\r
123 push ax ; Push it on the stack
\r
124 popf ; Zero the flags
\r
125 pushf ; Try to zero bits 12-15
\r
126 pop ax ; Recover flags
\r
127 and ax,0F000h ; If bits 12-15 are 1 => i86 or i286
\r
132 mov ax,0FFFFh ; Set all AX bits
\r
133 mov cl,33 ; Will shift once on 80186
\r
134 shl ax,cl ; or 33 x on 8086
\r
138 mov ax,i86 ; 0 => 8086/8088
\r
142 mov ax,07000h ; Try to set bits 12-14
\r
147 and ax,07000h ; If bits 12-14 are 0 => i286
\r
151 ;; 386/486 resolution code taken from WHATCPU.ASM by
\r
157 mov ebx,eax ;Original CR0 into EBX
\r
159 mov cr0,eax ;Store it
\r
160 mov eax,cr0 ;Read it back
\r
161 mov cr0,ebx ;Restore CR0
\r
162 test al,10h ;Did it set?
\r
164 jz @@done ;Jump if 386SX
\r
166 ;*** Test AC bit in EFLAGS (386DX won't change)
\r
167 mov ecx,esp ;Original ESP in ECX
\r
168 pushfd ;Original EFLAGS in EBX
\r
170 and esp,not 3 ;Align stack to prevent 486
\r
171 ; fault when AC is flipped
\r
172 mov eax,ebx ;EFLAGS => EAX
\r
173 xor eax,40000h ;Flip AC flag
\r
176 pushfd ;Read it back
\r
178 push ebx ;Restore EFLAGS
\r
180 mov esp,ecx ;Restore ESP
\r
181 cmp eax,ebx ;Compare old/new AC bits
\r
184 is_486: ;Until the Pentium appears...
\r
194 ;-----------------------------------------------------------------------
\r
195 ; PC Numeric coprocessor detection routine
\r
198 ; unsigned int x_coprocessor();
\r
200 ; Based on an article in PC Tech Journal, Aug 87 by Ted Forgeron
\r
202 ; Returns 1 if coprocessor found, zero otherwise
\r
204 _x_coprocessor proc
\r
205 ARG control:word=StkSize
\r
210 fninit ; try to initialize the copro.
\r
211 mov [control],0 ; clear control word variable
\r
212 fnstcw control ; put control word in memory
\r
214 cmp ah,03h ; do we have a coprocessor ?
\r
215 je @@HaveCopro ; jump if yes!
\r
216 xor ax,ax ; return 0 since nothing found
\r
224 _x_coprocessor endp
\r
227 ;-----------------------------------------------------------------------
\r
228 ; PC Mouse Driver detection routine
\r
231 ; unsigned int x_mousedriver();
\r
234 ; Returns 1 if mouse driver found, zero otherwise
\r
235 _x_mousedriver proc
\r
238 mov ax,3533h ; Get int 33 interrupt vector
\r
240 xor cx,cx ; Clear "found" flag
\r
241 mov ax,es ; Is the vector null (ES==0 && BX==0) ?
\r
243 jz @@NoMouseDriver ; Yes! No mouse driver installed - Jump
\r
245 ; Just make absolutely sure the vector points to the mouse
\r
246 ; driver (just in case)
\r
248 xor ax,ax ; FUNC 0: Mouse Initialization
\r
250 or ax,ax ; Do we have an installed mouse driver ?
\r
251 jz @@NoMouseDriver; No ?
\r
252 mov [_MouseButtonCount],bx
\r
256 mov [_MouseVersion],bx
\r
257 mov [_MouseType],ch
\r
260 mov cx,1 ; Yes! set flag
\r
263 mov ax,cx ; Return "found" flag
\r
266 _x_mousedriver endp
\r