Subversion Repositories Kolibri OS

Rev

Rev 1164 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1164 hidnplayr 1
include 'macros.inc'
2
MEOS_APP_START
3
 
4
type_ethernet equ 1
5
 
6
CODE
7
	call draw_window
8
 
9
still:	mcall	10			; wait here for event
10
	dec	eax			; redraw request ?
11
	jz	red
12
	dec	eax			; key in buffer ?
13
	jz	key
14
	dec	eax			; button in buffer ?
15
	jz	button
16
	jmp	still
17
 
18
red:					; redraw
19
	mcall	9, Proc_Info, -1	; window redraw requested so get new window coordinates and size
20
	mov	eax, [Proc_Info.box.left]; store the window coordinates into the Form Structure
21
	mov	[Form + 2], ax		; x start position
22
	mov	eax, [Proc_Info.box.top];
23
	mov	[Form + 6], ax		; ystart position
24
	mov	eax, [Proc_Info.box.width]	;
25
	mov	[Form], ax		; window width
26
	mov	eax, [Proc_Info.box.height]	;
27
	mov	[Form + 4] ,ax		; window height
28
	call	draw_window		; go redraw window now
29
	jmp	still
30
 
31
key:					; key
32
	mcall	2			; just read it and ignore
33
	jmp	still
34
button: 				; button
35
	mcall	17			; get id
36
 
37
	cmp	ah, 1			; button id = 1 ?
38
	jne	@f
39
	mcall	-1			; close this program
40
       @@:
41
	cmp	eax,0x0000fe00
42
	jg	@f
43
 
44
	cmp	ah, 4
45
	je	hook
46
 
1192 hidnplayr 47
	cmp	ah, 5
48
	je	reset
49
 
50
	cmp	ah, 6
51
	je	unload
52
 
1164 hidnplayr 53
	jmp	still
54
       @@:
55
	shr	eax, 16
56
	mov	word [selected], ax
57
 
58
	call	load_drv
59
	call	draw_window
60
 
61
	jmp still
62
 
63
load_drv:
64
;        mov     ax , [selected]
65
	test	ax , ax
66
	jz	still
67
 
68
	mov	bl , 6			; get a dword
69
	mov	bh , ah     ; bus
70
	mov	ch , al     ; dev
71
	mov	cl , 0			; offset to device/vendor id
72
	mcall 62		      ; get ID's
73
 
74
	mov	word [PCI_Vendor], ax
75
	shr	eax, 16
76
	mov	word [PCI_Device], ax
77
	call	get_drv_ptr
78
 
79
	mov	ecx, eax
80
	mcall 68, 16
81
 
82
	mov	[IOCTL.handle], eax
83
 
84
	ret
85
 
86
hook:
87
	mov	ax , [selected]
88
	test	ax , ax
89
	jz	still
90
 
91
	mov	[hardwareinfo.pci_dev], al
92
	mov	[hardwareinfo.pci_bus], ah
93
 
94
	mov	[IOCTL.io_code], 1 ; SRV_HOOK
95
	mov	[IOCTL.inp_size], 3
96
	mov	[IOCTL.input], hardwareinfo
97
	mov	[IOCTL.out_size], 0
98
	mov	[IOCTL.output], 0
99
 
100
	mcall 68, 17, IOCTL
101
 
102
	mov	byte[drivernumber], al
103
 
1192 hidnplayr 104
reset:
105
	movzx	ebx, byte[drivernumber]
106
	mcall	73,,2
1164 hidnplayr 107
 
1192 hidnplayr 108
	ret
1164 hidnplayr 109
 
1192 hidnplayr 110
unload:
111
	movzx	ebx, byte[drivernumber]
112
	mcall	73,,3
1164 hidnplayr 113
 
1192 hidnplayr 114
	ret
115
 
1164 hidnplayr 116
draw_window:
117
	mcall	12, 1			; start of draw
118
	mcall	0, dword [Form], dword [Form + 4], 0x13ffffff, 0x805080d0, title
119
 
1192 hidnplayr 120
;        mcall   73, 1,
121
;        mov     ecx, eax
122
;        mcall   47, 1 shl 18, , 50 shl 16 + 10, 0x00000000
1164 hidnplayr 123
 
124
	call	Get_PCI_Info		; get pci version and last bus, scan for and draw each pci device
125
 
126
	cmp	edx, 20 shl 16 + 110
127
	je	.nonefound
128
 
129
	mcall	4, 20 shl 16 + 100, 1 shl 31 + 0x00000000 , caption
130
 
1192 hidnplayr 131
	mov	ax , [selected]
132
	test	ax, ax
133
	jz	.done
1164 hidnplayr 134
 
1192 hidnplayr 135
	mcall	8, 18 shl 16 + 100, 35 shl 16 + 18, 4, 0x00007f00
136
	mcall	,, 55 shl 16 + 18, 5, 0x0000007f
137
	mcall	,, 75 shl 16 + 18, 6, 0x007f0000
1164 hidnplayr 138
 
1192 hidnplayr 139
	mcall	4, 33 shl 16 + 42, 1 shl 31 + 0x00ffffff , btn_start
140
	mcall	, 33 shl 16 + 62, , btn_reset
141
	mcall	, 36 shl 16 + 82, , btn_stop
1164 hidnplayr 142
 
1192 hidnplayr 143
;        mcall   , 140 shl 16 + 62, 1 shl 31 + 0x00000000 , devicename
1164 hidnplayr 144
 
145
	jmp	.done
146
 
147
.nonefound :
148
	mcall	4, 20 shl 16 + 30, 1 shl 31 + 0x00ff0000 , nonefound
149
.done:
150
	mcall	12, 2			; end of draw
151
	ret
152
 
153
 
154
;------------------------------------------------------------------
155
;* Gets the PCI Version and Last Bus
156
Get_PCI_Info:
157
	mcall	62, 0
158
	mov	word [PCI_Version], ax
159
	mcall	62, 1
160
	mov	byte [PCI_LastBus], al
161
	;----------------------------------------------------------
162
	;* Get all devices on PCI Bus
163
	mov	edx, 20 shl 16 + 110  ; set start write position
164
	cmp	al , 0xff		 ; 0xFF means no pci bus found
165
	jne	Pci_Exists		;
166
	ret				; if no bus then leave
167
Pci_Exists:
168
	mov	byte [V_Bus], 0 	; reset varibles
169
	mov	byte [V_Dev], 0 	;
170
Start_Enum:
171
	mov	bl , 6			 ; get a dword
172
	mov	bh , byte [V_Bus]	 ; bus of pci device
173
	mov	ch , byte [V_Dev]	 ; device number/function
174
	mov	cl , 0			 ; offset to device/vendor id
175
	mcall	62			; get ID's
176
 
177
	cmp	ax, 0			; Vendor ID should not be 0 or 0xFFFF
178
	je	nextDev 		; check next device if nothing exists here
179
	cmp	ax, 0xffff		;
180
	je	nextDev 		;
181
 
182
	mov	word [PCI_Vendor], ax	; There is a device here, save the ID's
183
	shr	eax, 16 		;
184
	mov	word [PCI_Device], ax	;
185
	mov	bl , 4			 ; Read config byte
186
	mov	bh , byte [V_Bus]	 ; Bus #
187
	mov	ch , byte [V_Dev]	 ; Device # on bus
188
	mov	cl , 0x08		 ; Register to read (Get Revision)
189
	mcall	62			; Read it
190
	mov	byte [PCI_Rev], al	; Save it
191
	mov	cl , 0x0b		 ; Register to read (Get class)
192
	mcall	62			; Read it
193
 
194
	mov	byte [PCI_Class], al	; Save it
195
	mov	cl , 0x0a		 ; Register to read (Get Subclass)
196
	mcall	62			; Read it
197
	mov	byte [PCI_SubClass], al ; Save it
198
	mov	cl , 0x09		 ; Register to read (Get Interface)
199
	mcall	62			; Read it
200
	mov	[PCI_Interface], al	; Save it
201
	mov	cl , 0x3c		 ; Register to read (Get IRQ)
202
@@:	mcall	62			; Read it
203
	mov	[PCI_IRQ], al		; Save it
204
;
205
;        inc     byte [total]            ; one more device found
206
 
207
	cmp	byte [PCI_Class],2
208
	jne	nextDev
209
 
210
	call	Print_New_Device	; print device info to screen
211
nextDev:
212
	add	byte [V_Dev], 8 	; lower 3 bits are the function number
213
 
214
	jnz	Start_Enum		; jump until we reach zero
215
	mov	byte [V_Dev], 0 	; reset device number
216
	inc	byte [V_Bus]		; next bus
217
	mov	al , byte [PCI_LastBus]  ; get last bus
218
	cmp	byte [V_Bus], al	; was it last bus
219
	jbe	Start_Enum		; if not jump to keep searching
220
	ret
221
 
222
;------------------------------------------------------------------
223
;* Print device info to screen
224
Print_New_Device:
225
 
226
	push	edx			; Magic ! (to print a button...)
227
 
228
	mov	ebx, 18 shl 16
229
	mov	bx , [Form]
230
	sub	bx , 36
231
 
232
	mov	cx , dx
233
	dec	cx
234
	shl	ecx, 16
235
	add	ecx, 9
236
 
237
	movzx	edx, byte [V_Bus]
238
	shl	dx , 8
239
	mov	dl , byte [V_Dev]
240
 
241
	mov	esi, 0x0000c0ff        ; color: yellow if selected, blue otherwise
242
	cmp	word [selected], dx
243
	jne	@f
244
	mov	esi, 0x00c0c000
245
       @@:
246
 
247
	shl	edx, 8
248
	or	dl , 0xff
249
 
250
	mcall	8
251
	pop	edx
252
 
253
	xor	esi, esi		; Color of text
254
	movzx	ecx, word [PCI_Vendor]	; number to be written
255
	mcall	47, 0x00040100		; Write Vendor ID
256
 
257
	add	edx, (4*6+18) shl 16
258
	movzx	ecx, word [PCI_Device]	; get Vendor ID
259
	mcall				; Draw Vendor ID to Window
260
 
261
	add	edx, (4*6+18) shl 16
262
	movzx	ecx, byte [V_Bus]	; get bus number
263
	mcall	,0x00020100		; draw bus number to screen
264
 
265
	add	edx, (2*6+18) shl 16
266
	movzx	ecx, byte [V_Dev]	; get device number
267
	shr	ecx, 3			; device number is bits 3-7
268
	mcall				; Draw device Number To Window
269
 
270
	add	edx, (2*6+18) shl 16
271
	movzx	ecx, byte [PCI_Rev]	; get revision number
272
	mcall				; Draw Revision to screen
273
 
274
	add	edx, (2*6+18) shl 16
275
	movzx	ecx, [PCI_IRQ]
276
	cmp	cl , 0x0f		; IRQ must be between 0 and 15
277
	ja	@f
278
	mcall
279
@@:
280
;
281
	;Write Names
282
	movzx	ebx, dx 		; Set y position
283
	or	ebx, 230 shl 16 	; set Xposition
284
 
285
;------------------------------------------------------------------
286
; Prints the Vendor's Name based on Vendor ID
287
;------------------------------------------------------------------
288
	mov	edx, VendorsTab
289
	mov	cx , word[PCI_Vendor]
290
 
291
.fn:	mov	ax , [edx]
292
	add	edx, 6
293
	test	ax , ax
294
	jz	.find
295
	cmp	ax , cx
296
	jne	.fn
297
.find:	mov	edx, [edx - 4]
298
	mcall	4,, 0x80000000		; lets print the vendor Name
299
 
300
;------------------------------------------------------------------
301
; Get description based on Class/Subclass
302
;------------------------------------------------------------------
303
	mov	eax, dword [PCI_Class]
304
	and	eax, 0xffffff
305
	xor	edx, edx
306
	xor	esi, esi
307
.fnc:	inc	esi
308
	mov	ecx, [Classes + esi * 8 - 8]
309
	cmp	cx , 0xffff
310
	je	.endfc
311
	cmp	cx , ax
312
	jne	.fnc
313
	test	ecx, 0xff000000
314
	jz	@f
315
	mov	edx, [Classes + esi * 8 - 4]
316
	jmp	.fnc
317
@@:	cmp	eax, ecx
318
	jne	.fnc
319
	xor	edx, edx
320
.endfc: test	edx, edx
321
	jnz	@f
322
	mov	edx, [Classes + esi * 8 - 4]
323
@@:
324
	add	ebx, 288 shl 16
325
	mcall	4,, 0x80000000,, 32	; draw the text
326
	movzx	edx, bx 		; get y coordinate
327
	add	edx, 0x0014000A 	; add 10 to y coordinate and set x coordinate to 20
328
 
329
;------------------------------------------------------------------
330
; Print Driver Name
331
;------------------------------------------------------------------
332
	push	edx
333
	add	ebx, 120 shl 16
334
	push	ebx
335
 
336
	call	get_drv_ptr
337
	mov	edx, eax
338
	pop	ebx
339
	mcall	4,,0x80000000	       ; lets print the vendor Name
340
	pop	edx
341
	ret
342
 
343
get_drv_ptr:
344
	mov	eax, driverlist        ; eax will be the pointer to latest driver title
345
	mov	ebx, driverlist        ; ebx is the current pointer
346
	mov	ecx, dword[PCI_Vendor] ; the device/vendor id of we want to find
347
 
348
       driverloop:
349
	inc	ebx
350
 
351
	cmp	byte[ebx],0
352
	jne	driverloop
353
 
354
	inc	ebx		       ; the device/vendor id list for the driver eax is pointing to starts here.
355
 
356
       deviceloop:
357
	cmp	dword[ebx],0
358
	je	nextdriver
359
 
360
	cmp	dword[ebx],ecx
361
	je	driverfound
362
 
363
	add	ebx,4
364
	jmp	deviceloop
365
 
366
       nextdriver:
367
	add	ebx,4
368
 
369
	cmp	dword[ebx],0
370
	je	nodriver
371
 
372
	mov	eax,ebx
373
	jmp	driverloop
374
 
375
       nodriver:
376
	mov	eax, lbl_none	       ; lets print the vendor Name
377
	ret
378
 
379
       driverfound:
380
	ret
381
 
382
include 'VENDORS.INC'
383
include 'DRIVERS.INC'
384
;------------------------------------------------------------------
385
; DATA AREA
386
DATA
387
 
388
 
389
Form:	dw 800 ; window width (no more, special for 800x600)
390
	dw 100 ; window x start
391
	dw 220 ; window height
392
	dw 100 ; window y start
393
 
394
title	db 'Network Driver Control Center', 0
395
 
396
caption db 'Vendor Device Bus  Dev  Rev  IRQ   Company                                         Description         DRIVER',0
1192 hidnplayr 397
;lbl_1 db 'Hardware control',0
1164 hidnplayr 398
nonefound db 'No compatible devices were found!',0
1192 hidnplayr 399
btn_start db 'Start device',0
400
btn_reset db 'Reset device',0
401
btn_stop db 'Stop device',0
402
;lbl_hdw_addr db 'hardware address:',0
403
;lbl_type db 'type:',0
1164 hidnplayr 404
lbl_none db 'none',0
1192 hidnplayr 405
;lbl_unknown db 'unknown',0
406
;lbl_ethernet db 'ethernet',0
1164 hidnplayr 407
 
1192 hidnplayr 408
devicename     db 'test'
409
rb 64
410
		db 0
1164 hidnplayr 411
 
1192 hidnplayr 412
 
1164 hidnplayr 413
IOCTL:
414
   .handle	dd ?
415
   .io_code	dd ?
416
   .input	dd ?
417
   .inp_size	dd ?
418
   .output	dd ?
419
   .out_size	dd ?
420
 
421
drivernumber	db ?
422
MAC		dp ?
423
 
424
hardwareinfo:
425
   .type	db 1 ; pci
426
   .pci_bus	db ?
427
   .pci_dev	db ?
428
 
429
 
430
;------------------------------------------------------------------
431
; UNINITIALIZED DATA AREA
432
UDATA
433
 
434
type		db ?
435
selected	dw ?
436
V_Bus		db ?
437
V_Dev		db ?
438
PCI_Version	dw ?
439
PCI_LastBus	db ?
440
PCI_Vendor	dw ?
441
PCI_Device	dw ?
442
PCI_Bus 	db ?
443
PCI_Dev 	db ?
444
PCI_Rev 	db ?
445
; don`t change order!!!
446
PCI_Class	db ?
447
PCI_SubClass	db ?
448
PCI_Interface	db ?
449
PCI_IRQ 	db ?
450
 
451
Proc_Info	process_information
452
 
453
 
454
MEOS_APP_END