Subversion Repositories Kolibri OS

Rev

Rev 5014 | Rev 5019 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 5014 Rev 5018
1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
;;                                                              ;;
2
;;                                                              ;;
3
;; Copyright (C) KolibriOS team 2004-2014. All rights reserved. ;;
3
;; Copyright (C) KolibriOS team 2004-2014. All rights reserved. ;;
4
;; Distributed under terms of the GNU General Public License    ;;
4
;; Distributed under terms of the GNU General Public License    ;;
5
;;                                                              ;;
5
;;                                                              ;;
6
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
6
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7
 
7
 
8
format MS COFF
8
format MS COFF
9
 
9
 
10
DEBUG = 1
10
DEBUG = 1
11
 
11
 
12
__DEBUG__ = 1
12
__DEBUG__ = 1
13
__DEBUG_LEVEL__ = 1
13
__DEBUG_LEVEL__ = 1
14
 
14
 
15
node equ ftdi_context
15
node equ ftdi_context
16
node.next equ ftdi_context.next_context
16
node.next equ ftdi_context.next_context
17
 
17
 
18
include '../../proc32.inc'
18
include '../../proc32.inc'
19
include '../../imports.inc'
19
include '../../imports.inc'
20
include '../../fdo.inc'
20
include '../../fdo.inc'
21
include '../../struct.inc'
21
include '../../struct.inc'
22
 
22
 
23
public START
23
public START
24
public version
24
public version
25
 
25
 
26
; USB constants
26
; USB constants
27
DEVICE_DESCR_TYPE           = 1
27
DEVICE_DESCR_TYPE           = 1
28
CONFIG_DESCR_TYPE           = 2
28
CONFIG_DESCR_TYPE           = 2
29
STRING_DESCR_TYPE           = 3
29
STRING_DESCR_TYPE           = 3
30
INTERFACE_DESCR_TYPE        = 4
30
INTERFACE_DESCR_TYPE        = 4
31
ENDPOINT_DESCR_TYPE         = 5
31
ENDPOINT_DESCR_TYPE         = 5
32
DEVICE_QUALIFIER_DESCR_TYPE = 6
32
DEVICE_QUALIFIER_DESCR_TYPE = 6
33
 
33
 
34
CONTROL_PIPE     = 0
34
CONTROL_PIPE     = 0
35
ISOCHRONOUS_PIPE = 1
35
ISOCHRONOUS_PIPE = 1
36
BULK_PIPE        = 2
36
BULK_PIPE        = 2
37
INTERRUPT_PIPE   = 3
37
INTERRUPT_PIPE   = 3
38
 
38
 
39
; USB HID constants
39
; USB HID constants
40
HID_DESCR_TYPE      = 21h
40
HID_DESCR_TYPE      = 21h
41
REPORT_DESCR_TYPE   = 22h
41
REPORT_DESCR_TYPE   = 22h
42
PHYSICAL_DESCR_TYPE = 23h
42
PHYSICAL_DESCR_TYPE = 23h
43
 
43
 
44
 
44
 
45
; LibUSB constatnts
45
; LibUSB constatnts
46
LIBUSB_REQUEST_TYPE_STANDARD = (0x00 shl 5)
46
LIBUSB_REQUEST_TYPE_STANDARD = (0x00 shl 5)
47
LIBUSB_REQUEST_TYPE_CLASS = (0x01 shl 5)
47
LIBUSB_REQUEST_TYPE_CLASS = (0x01 shl 5)
48
LIBUSB_REQUEST_TYPE_VENDOR = (0x02 shl 5)
48
LIBUSB_REQUEST_TYPE_VENDOR = (0x02 shl 5)
49
LIBUSB_REQUEST_TYPE_RESERVED = (0x03 shl 5)
49
LIBUSB_REQUEST_TYPE_RESERVED = (0x03 shl 5)
50
 
50
 
51
LIBUSB_RECIPIENT_DEVICE = 0x00
51
LIBUSB_RECIPIENT_DEVICE = 0x00
52
LIBUSB_RECIPIENT_INTERFACE = 0x01
52
LIBUSB_RECIPIENT_INTERFACE = 0x01
53
LIBUSB_RECIPIENT_ENDPOINT = 0x02
53
LIBUSB_RECIPIENT_ENDPOINT = 0x02
54
LIBUSB_RECIPIENT_OTHER = 0x03
54
LIBUSB_RECIPIENT_OTHER = 0x03
55
 
55
 
56
LIBUSB_ENDPOINT_IN = 0x80
56
LIBUSB_ENDPOINT_IN = 0x80
57
LIBUSB_ENDPOINT_OUT = 0x00
57
LIBUSB_ENDPOINT_OUT = 0x00
58
 
58
 
59
; FTDI Constants
59
; FTDI Constants
60
FTDI_DEVICE_OUT_REQTYPE = (LIBUSB_REQUEST_TYPE_VENDOR or LIBUSB_RECIPIENT_DEVICE or LIBUSB_ENDPOINT_OUT)
60
FTDI_DEVICE_OUT_REQTYPE = (LIBUSB_REQUEST_TYPE_VENDOR or LIBUSB_RECIPIENT_DEVICE or LIBUSB_ENDPOINT_OUT)
61
FTDI_DEVICE_IN_REQTYPE = (LIBUSB_REQUEST_TYPE_VENDOR or LIBUSB_RECIPIENT_DEVICE or LIBUSB_ENDPOINT_IN)
61
FTDI_DEVICE_IN_REQTYPE = (LIBUSB_REQUEST_TYPE_VENDOR or LIBUSB_RECIPIENT_DEVICE or LIBUSB_ENDPOINT_IN)
62
 
62
 
63
; Requests
63
; Requests
64
;Definitions for flow control
64
;Definitions for flow control
65
SIO_RESET         =0  ;Reset the port
65
SIO_RESET         =0  ;Reset the port
66
SIO_MODEM_CTRL    =1  ;Set the modem control register 
66
SIO_MODEM_CTRL    =1  ;Set the modem control register 
67
SIO_SET_FLOW_CTRL =2  ;Set flow control register
67
SIO_SET_FLOW_CTRL =2  ;Set flow control register
68
SIO_SET_BAUD_RATE =3  ;Set baud rate
68
SIO_SET_BAUD_RATE =3  ;Set baud rate
69
SIO_SET_DATA      =4  ;Set the data characteristics of the port
69
SIO_SET_DATA      =4  ;Set the data characteristics of the port
70
 
70
 
71
SIO_RESET_REQUEST            =SIO_RESET
71
SIO_RESET_REQUEST            =SIO_RESET
72
SIO_SET_BAUDRATE_REQUEST     =SIO_SET_BAUD_RATE
72
SIO_SET_BAUDRATE_REQUEST     =SIO_SET_BAUD_RATE
73
SIO_SET_DATA_REQUEST         =SIO_SET_DATA
73
SIO_SET_DATA_REQUEST         =SIO_SET_DATA
74
SIO_SET_FLOW_CTRL_REQUEST    =SIO_SET_FLOW_CTRL
74
SIO_SET_FLOW_CTRL_REQUEST    =SIO_SET_FLOW_CTRL
75
SIO_SET_MODEM_CTRL_REQUEST   =SIO_MODEM_CTRL
75
SIO_SET_MODEM_CTRL_REQUEST   =SIO_MODEM_CTRL
76
SIO_POLL_MODEM_STATUS_REQUEST=0x05
76
SIO_POLL_MODEM_STATUS_REQUEST=0x05
77
SIO_SET_EVENT_CHAR_REQUEST   =0x06
77
SIO_SET_EVENT_CHAR_REQUEST   =0x06
78
SIO_SET_ERROR_CHAR_REQUEST   =0x07
78
SIO_SET_ERROR_CHAR_REQUEST   =0x07
79
SIO_SET_LATENCY_TIMER_REQUEST=0x09
79
SIO_SET_LATENCY_TIMER_REQUEST=0x09
80
SIO_GET_LATENCY_TIMER_REQUEST=0x0A
80
SIO_GET_LATENCY_TIMER_REQUEST=0x0A
81
SIO_SET_BITMODE_REQUEST      =0x0B
81
SIO_SET_BITMODE_REQUEST      =0x0B
82
SIO_READ_PINS_REQUEST        =0x0C
82
SIO_READ_PINS_REQUEST        =0x0C
83
SIO_READ_EEPROM_REQUEST      =0x90
83
SIO_READ_EEPROM_REQUEST      =0x90
84
SIO_WRITE_EEPROM_REQUEST     =0x91
84
SIO_WRITE_EEPROM_REQUEST     =0x91
85
SIO_ERASE_EEPROM_REQUEST     =0x92
85
SIO_ERASE_EEPROM_REQUEST     =0x92
86
 
86
 
87
 
87
 
88
SIO_RESET_SIO=0
88
SIO_RESET_SIO=0
89
SIO_RESET_PURGE_RX=1
89
SIO_RESET_PURGE_RX=1
90
SIO_RESET_PURGE_TX=2
90
SIO_RESET_PURGE_TX=2
91
 
91
 
92
SIO_DISABLE_FLOW_CTRL=0x0
92
SIO_DISABLE_FLOW_CTRL=0x0
93
SIO_RTS_CTS_HS =(0x1 shl 8)
93
SIO_RTS_CTS_HS =(0x1 shl 8)
94
SIO_DTR_DSR_HS =(0x2 shl 8)
94
SIO_DTR_DSR_HS =(0x2 shl 8)
95
SIO_XON_XOFF_HS=(0x4 shl 8)
95
SIO_XON_XOFF_HS=(0x4 shl 8)
96
 
96
 
97
SIO_SET_DTR_MASK=0x1
97
SIO_SET_DTR_MASK=0x1
98
SIO_SET_DTR_HIGH=( 1 or ( SIO_SET_DTR_MASK  shl 8))
98
SIO_SET_DTR_HIGH=( 1 or ( SIO_SET_DTR_MASK  shl 8))
99
SIO_SET_DTR_LOW =( 0 or ( SIO_SET_DTR_MASK  shl 8))
99
SIO_SET_DTR_LOW =( 0 or ( SIO_SET_DTR_MASK  shl 8))
100
SIO_SET_RTS_MASK=0x2
100
SIO_SET_RTS_MASK=0x2
101
SIO_SET_RTS_HIGH=( 2 or ( SIO_SET_RTS_MASK shl 8 ))
101
SIO_SET_RTS_HIGH=( 2 or ( SIO_SET_RTS_MASK shl 8 ))
102
SIO_SET_RTS_LOW =( 0 or ( SIO_SET_RTS_MASK shl 8 ))
102
SIO_SET_RTS_LOW =( 0 or ( SIO_SET_RTS_MASK shl 8 ))
103
 
103
 
104
SIO_RTS_CTS_HS =(0x1 shl 8)
104
SIO_RTS_CTS_HS =(0x1 shl 8)
105
 
105
 
106
;FTDI chip type
106
;FTDI chip type
107
TYPE_AM=0
107
TYPE_AM=0
108
TYPE_BM=1
108
TYPE_BM=1
109
TYPE_2232C=2
109
TYPE_2232C=2
110
TYPE_R=3
110
TYPE_R=3
111
TYPE_2232H=4
111
TYPE_2232H=4
112
TYPE_4232H=5
112
TYPE_4232H=5
113
TYPE_232H=6
113
TYPE_232H=6
114
TYPE_230X=7
114
TYPE_230X=7
115
 
115
 
116
;strings
116
;strings
117
my_driver       db      'usbother',0
117
my_driver       db      'usbother',0
118
nomemory_msg    db      'K : no memory',13,10,0
118
nomemory_msg    db      'K : no memory',13,10,0
119
 
119
 
120
; Structures
120
; Structures
121
struct ftdi_context
121
struct ftdi_context
122
chipType                db      ?
122
chipType                db      ?
123
baudrate                dd      ?
123
baudrate                dd      ?
124
bitbangEnabled          db      ?
124
bitbangEnabled          db      ?
125
readBufChunkSize        dd      ?
125
readBufChunkSize        dd      ?
126
writeBufChunkSize       dd      ?
126
writeBufChunkSize       dd      ?
-
 
127
maxPacketSize           dd      ?
127
interface               dd      ?
128
interface               dd      ?
128
index                   dd      ?
129
index                   dd      ?
129
inEP                    dd      ?
130
inEP                    dd      ?
130
outEP                   dd      ?
131
outEP                   dd      ?
131
nullP                   dd      ? 
132
nullP                   dd      ? 
132
lockPID                 dd      ?
133
lockPID                 dd      ?
133
next_context            dd      ?
134
next_context            dd      ?
134
ends
135
ends
135
 
136
 
136
struct IOCTL
137
struct IOCTL
137
handle                  dd      ?
138
handle                  dd      ?
138
io_code                 dd      ?
139
io_code                 dd      ?
139
input                   dd      ?
140
input                   dd      ?
140
inp_size                dd      ?
141
inp_size                dd      ?
141
output                  dd      ?
142
output                  dd      ?
142
out_size                dd      ?
143
out_size                dd      ?
143
ends
144
ends
144
 
145
 
145
struct usb_descr
146
struct usb_descr
146
bLength                 db      ?
147
bLength                 db      ?
147
bDescriptorType         db      ?
148
bDescriptorType         db      ?
148
bcdUSB                  dw      ?
149
bcdUSB                  dw      ?
149
bDeviceClass            db      ?
150
bDeviceClass            db      ?
150
bDeviceSubClass         db      ?
151
bDeviceSubClass         db      ?
151
bDeviceProtocol         db      ?
152
bDeviceProtocol         db      ?
152
bMaxPacketSize0         db      ?
153
bMaxPacketSize0         db      ?
153
idVendor                dw      ?
154
idVendor                dw      ?
154
idProduct               dw      ?
155
idProduct               dw      ?
155
bcdDevice               dw      ?
156
bcdDevice               dw      ?
156
iManufacturer           db      ?
157
iManufacturer           db      ?
157
iProduct                db      ?
158
iProduct                db      ?
158
iSerialNumber           db      ?
159
iSerialNumber           db      ?
159
bNumConfigurations      db      ?
160
bNumConfigurations      db      ?
160
ends
161
ends
161
 
162
 
162
struct conf_packet
163
struct conf_packet
163
bmRequestType           db      ?
164
bmRequestType           db      ?
164
bRequest                db      ?
165
bRequest                db      ?
165
wValue                  dw      ?
166
wValue                  dw      ?
166
wIndex                  dw      ?
167
wIndex                  dw      ?
167
wLength                 dw      ?
168
wLength                 dw      ?
168
ends
169
ends
169
 
170
 
170
section '.flat' code readable align 16
171
section '.flat' code readable align 16
171
; The start procedure.
172
; The start procedure.
172
proc START stdcall, .reason:DWORD
173
proc START stdcall, .reason:DWORD
173
 
174
 
174
        xor     eax, eax        ; initialize return value
175
        xor     eax, eax        ; initialize return value
175
        cmp     [.reason], 1    ; compare the argument
176
        cmp     [.reason], 1    ; compare the argument
176
        jnz     .nothing                
177
        jnz     .nothing                
177
        stdcall RegUSBDriver, my_driver, service_proc, usb_functions
178
        stdcall RegUSBDriver, my_driver, service_proc, usb_functions
178
 
179
 
179
.nothing:
180
.nothing:
180
        ret
181
        ret
181
endp
182
endp
182
 
183
 
183
 
184
 
184
proc AddDevice stdcall uses ebx esi, .config_pipe:DWORD, .config_descr:DWORD, .interface:DWORD
185
proc AddDevice stdcall uses ebx esi edi, .config_pipe:DWORD, .config_descr:DWORD, .interface:DWORD
185
        
186
        
186
        stdcall USBGetParam, [.config_pipe], 0
187
        stdcall USBGetParam, [.config_pipe], 0
187
        mov     edx, eax
188
        mov     edx, eax
188
        DEBUGF 1,'K : Device detected Vendor: %x\n', [eax+usb_descr.idVendor]
189
        DEBUGF 1,'K : Detected device vendor: %x\n', [eax+usb_descr.idVendor]
189
        cmp     word[eax+usb_descr.idVendor], 0x0403
190
        cmp     word[eax+usb_descr.idVendor], 0x0403
190
        jnz     .notftdi
191
        jnz     .notftdi
191
        DEBUGF 1,'K : FTDI USB device detected\n'
-
 
192
        movi    eax, sizeof.ftdi_context
192
        movi    eax, sizeof.ftdi_context
193
        call    Kmalloc
193
        call    Kmalloc
194
        test    eax, eax
194
        test    eax, eax
195
        jnz     @f
195
        jnz     @f
196
        mov     esi, nomemory_msg
196
        mov     esi, nomemory_msg
197
        call    SysMsgBoardStr
197
        call    SysMsgBoardStr
198
        jmp     .nothing
198
        jmp     .nothing
199
  @@:
199
  @@:
200
        DEBUGF 1,'K : Adding struct to list %x\n', eax
200
        DEBUGF 1,'K : Adding struct to list %x\n', eax
201
        call    linkedlist_add
201
        call    linkedlist_add
202
        
202
        
203
        mov     ebx, [.config_pipe]
203
        mov     ebx, [.config_pipe]
204
        mov     [eax + ftdi_context.nullP], ebx
204
        mov     [eax + ftdi_context.nullP], ebx
205
        mov     [eax + ftdi_context.index], 0
205
        mov     [eax + ftdi_context.index], 0
206
        mov     [eax + ftdi_context.lockPID], 0
206
        mov     [eax + ftdi_context.lockPID], 0
-
 
207
        mov     [eax + ftdi_context.maxPacketSize], 64       
207
        mov     [eax + ftdi_context.readBufChunkSize], 64
208
        mov     [eax + ftdi_context.readBufChunkSize], 64
208
        mov     [eax + ftdi_context.writeBufChunkSize], 64
209
        mov     [eax + ftdi_context.writeBufChunkSize], 64
209
        
210
        
-
 
211
        mov     cx, [edx+usb_descr.bcdDevice]
210
        cmp     [edx+usb_descr.bcdDevice], 0x400
212
        cmp     cx, 0x400
211
        jnz     @f
213
        jnz     @f
-
 
214
        mov     [eax + ftdi_context.chipType], TYPE_BM
212
        mov     [eax + ftdi_context.chipType], TYPE_BM
215
        jmp     .slow
213
  @@:      
216
  @@:      
214
        cmp     [edx+usb_descr.bcdDevice], 0x200
217
        cmp     cx, 0x200
215
        jnz     @f
218
        jnz     @f
-
 
219
        mov     [eax + ftdi_context.chipType], TYPE_AM
216
        mov     [eax + ftdi_context.chipType], TYPE_AM
220
        jmp     .slow
217
  @@:     
221
  @@:     
218
        cmp     [edx+usb_descr.bcdDevice], 0x500
222
        cmp     cx, 0x500
219
        jnz     @f
223
        jnz     @f
-
 
224
        mov     [eax + ftdi_context.chipType], TYPE_2232C 
220
        mov     [eax + ftdi_context.chipType], TYPE_2232C        
225
        jmp     .slow
221
  @@:      
226
  @@:      
222
        cmp     [edx+usb_descr.bcdDevice], 0x600
227
        cmp     cx, 0x600
223
        jnz     @f
228
        jnz     @f
-
 
229
        mov     [eax + ftdi_context.chipType], TYPE_R
224
        mov     [eax + ftdi_context.chipType], TYPE_R
230
        jmp     .slow
225
  @@:      
231
  @@:      
226
        cmp     [edx+usb_descr.bcdDevice], 0x700
232
        cmp     cx, 0x700
227
        jnz     @f
233
        jnz     @f
-
 
234
        mov     [eax + ftdi_context.chipType], TYPE_2232H
228
        mov     [eax + ftdi_context.chipType], TYPE_2232H
235
        jmp     .fast
229
  @@:      
236
  @@:      
230
        cmp     [edx+usb_descr.bcdDevice], 0x900
237
        cmp     cx, 0x900
231
        jnz     @f
238
        jnz     @f
-
 
239
        mov     [eax + ftdi_context.chipType], TYPE_232H
232
        mov     [eax + ftdi_context.chipType], TYPE_232H
240
        jmp     .fast
233
  @@:      
241
  @@:      
234
        cmp     [edx+usb_descr.bcdDevice], 0x1000
242
        cmp     cx, 0x1000
235
        jnz     @f
243
        jnz     .slow
236
        mov     [eax + ftdi_context.chipType], TYPE_BM
244
        mov     [eax + ftdi_context.chipType], TYPE_230X
237
  @@:
245
        jmp     .fast
-
 
246
        
238
  
247
  .fast:
-
 
248
        add     [eax + ftdi_context.maxPacketSize], 512-64
239
        DEBUGF 1,'K : Open first pipe\n'
249
  .slow:    
240
        mov     ebx, eax
250
        mov     ebx, eax
-
 
251
        stdcall USBOpenPipe, [.config_pipe],  0x81,  [ebx + ftdi_context.maxPacketSize],  BULK_PIPE, 0
-
 
252
        test    eax, eax
241
        stdcall USBOpenPipe, [.config_pipe],  0x81,  0x40,  BULK_PIPE, 0
253
        jz      .nothing
-
 
254
        mov     [ebx + ftdi_context.inEP], eax
242
        mov     [ebx + ftdi_context.inEP], eax
255
        stdcall USBOpenPipe, [.config_pipe],  0x02,  [ebx + ftdi_context.maxPacketSize],  BULK_PIPE, 0
243
        DEBUGF 1,'K : Open second pipe\n'
256
        test    eax, eax
244
        stdcall USBOpenPipe, [.config_pipe],  0x02,  0x40,  BULK_PIPE, 0
257
        jz      .nothing
245
        mov     [ebx + ftdi_context.outEP], eax
258
        mov     [ebx + ftdi_context.outEP], eax
246
        mov     eax, ebx
259
        mov     eax, ebx
247
        ret        
260
        ret        
248
           
261
           
249
  .notftdi:
262
  .notftdi:
250
        DEBUGF 1,'K : Skipping not FTDI device\n'
263
        DEBUGF 1,'K : Skipping not FTDI device\n'
251
  .nothing:        
264
  .nothing:        
252
        xor     eax, eax
265
        xor     eax, eax
253
        ret
266
        ret
254
endp
267
endp
255
 
268
 
256
 
269
 
257
handle     equ  IOCTL.handle
270
handle     equ  IOCTL.handle
258
io_code    equ  IOCTL.io_code
271
io_code    equ  IOCTL.io_code
259
input      equ  IOCTL.input
272
input      equ  IOCTL.input
260
inp_size   equ  IOCTL.inp_size
273
inp_size   equ  IOCTL.inp_size
261
output     equ  IOCTL.output
274
output     equ  IOCTL.output
262
out_size   equ  IOCTL.out_size
275
out_size   equ  IOCTL.out_size
263
 
276
 
264
align 4
277
align 4
265
proc service_proc stdcall uses ebx esi edi, ioctl:DWORD
278
proc service_proc stdcall uses ebx esi edi, ioctl:DWORD
266
locals
279
locals
267
ConfPacket  rb  8
280
ConfPacket  rb  8
268
EventData   rd  3
281
EventData   rd  3
269
endl
282
endl
270
        mov     edi, [ioctl]
283
        mov     edi, [ioctl]
271
        mov     eax, [edi+io_code]
284
        mov     eax, [edi+io_code]
272
        DEBUGF 1,'K : FTDI got the request: %d\n', eax
285
        DEBUGF 1,'K : FTDI got the request: %d\n', eax
273
        test    eax, eax           ;0
286
        test    eax, eax           ;0
274
        jz      .version
287
        jz      .version
275
        dec     eax                 ;1
288
        dec     eax                 ;1
276
        jz      .ftdi_get_list
289
        jz      .ftdi_get_list
277
        
290
        
278
        push    eax
291
        push    eax
279
        mov     esi, [edi+input]
292
        mov     esi, [edi+input]
280
        mov     eax, [esi+4]
293
        mov     eax, [esi+4]
281
        call    linkedlist_isvalid
294
        call    linkedlist_isvalid
282
        test    eax, eax
295
        test    eax, eax
283
        pop     eax        
296
        pop     eax        
284
        jnz     .endswitch
297
        jnz     .endswitch
285
        
298
        
286
        dec     eax
299
        dec     eax
287
        jz      .ftdi_lock      ;2
300
        jz      .ftdi_lock      ;2
288
        dec     eax
301
        dec     eax
289
        jz      .ftdi_unlock    ;3
302
        jz      .ftdi_unlock    ;3
290
        
303
        
291
        mov     ebx, [esi+4]
304
        mov     ebx, [esi+4]
292
        mov     ecx, [ebx + ftdi_context.lockPID]     
305
        mov     ecx, [ebx + ftdi_context.lockPID]     
293
        cmp     ecx, [esi]
306
        cmp     ecx, [esi]
294
        jz      .pid_ok
307
        jz      .pid_ok
295
        mov     esi, [edi+output]
308
        mov     esi, [edi+output]
296
        mov     dword[esi], 'LCKD'
309
        mov     dword[esi], 'LCKD'
297
        jmp     .endswitch
310
        jmp     .endswitch
298
        
311
        
299
  .pid_ok:  
312
  .pid_ok:
-
 
313
        dec     eax
-
 
314
        jz      .ftdi_get_wchunksize    ;5
-
 
315
        dec     eax
-
 
316
        jz      .ftdi_get_rchunksize    ;7        
-
 
317
        
-
 
318
        mov     edi, [edi+input]
-
 
319
        
-
 
320
        dec     eax
-
 
321
        jz      .ftdi_set_rchunksize    ;6
-
 
322
        dec     eax
-
 
323
        jz      .ftdi_set_wchunksize    ;4
-
 
324
  
300
        push    eax edi
325
        push    eax edi
301
        mov     ecx, 0x80000000
326
        mov     ecx, 0x80000000
302
        cmp     eax, 17
327
        cmp     eax, 17
303
        je     .bulkevent
328
        je      .bulkevent
304
        cmp     eax, 18
329
        cmp     eax, 18
305
        je      .bulkevent
330
        je      .bulkevent
306
        xor     ecx, ecx
331
        xor     ecx, ecx
307
  .bulkevent:                
332
  .bulkevent:                
308
        xor     esi, esi
333
        xor     esi, esi
309
        call    CreateEvent        
334
        call    CreateEvent        
310
        mov     [EventData], eax
335
        mov     [EventData], eax
311
        mov     [EventData+4], edx
336
        mov     [EventData+4], edx
312
        pop     edi eax 
337
        pop     edi eax
313
        
338
        
314
        dec     eax                 ;4
339
        dec     eax                 ;8
315
        jz      .ftdi_set_bitmode
340
        jz      .ftdi_set_bitmode
316
        dec     eax                 ;5
341
        dec     eax                 ;9
317
        jz      .ftdi_setrtshigh   
342
        jz      .ftdi_setrtshigh   
318
        dec     eax                 ;6
343
        dec     eax                 ;10
319
        jz      .ftdi_setrtslow  
344
        jz      .ftdi_setrtslow  
320
        dec     eax                 ;7
345
        dec     eax                 ;11
321
        jz      .ftdi_setdtrhigh
346
        jz      .ftdi_setdtrhigh
322
        dec     eax                 ;8
347
        dec     eax                 ;12
323
        jz      .ftdi_setdtrlow
348
        jz      .ftdi_setdtrlow
324
        dec     eax                 ;9
349
        dec     eax                 ;13
325
        jz      .ftdi_usb_reset
350
        jz      .ftdi_usb_reset
326
        dec     eax                 ;10
351
        dec     eax                 ;14
327
        jz      .ftdi_setflowctrl
352
        jz      .ftdi_setflowctrl
328
        dec     eax                 ;11
353
        dec     eax                 ;15
329
        jz      .ftdi_set_event_char
354
        jz      .ftdi_set_event_char
330
        dec     eax                 ;12
355
        dec     eax                 ;16
331
        jz      .ftdi_set_error_char
356
        jz      .ftdi_set_error_char
332
        dec     eax                 ;13
357
        dec     eax                 ;17
333
        jz      .ftdi_set_latency_timer
358
        jz      .ftdi_set_latency_timer
334
        dec     eax                 ;14
359
        dec     eax                 ;18
335
        jz      .ftdi_get_latency_timer
360
        jz      .ftdi_get_latency_timer
336
        dec     eax                 ;15
361
        dec     eax                 ;19
337
        jz      .ftdi_read_pins
362
        jz      .ftdi_read_pins
338
        dec     eax                 ;16
363
        dec     eax                 ;20
339
        jz      .ftdi_poll_modem_status
364
        jz      .ftdi_poll_modem_status
340
        dec     eax                 ;17
365
        dec     eax                 ;21
341
        jz      .ftdi_write_data
366
        jz      .ftdi_write_data
342
        dec     eax                 ;18
367
        dec     eax                 ;22
343
        jz      .ftdi_read_data
368
        jz      .ftdi_read_data
344
        dec     eax                 ;19
369
        dec     eax                 ;23
345
        jz      .ftdi_set_baudrate
370
        jz      .ftdi_set_baudrate
346
        dec     eax                 ;20
371
        dec     eax                 ;24
347
        jz      .ftdi_set_line_property
372
        jz      .ftdi_set_line_property
348
        dec     eax                 ;21
373
        dec     eax                 ;25
349
        jz      .ftdi_purge_rx_buf
374
        jz      .ftdi_purge_rx_buf
350
        dec     eax                 ;22
375
        dec     eax                 ;26
-
 
376
        jz      .ftdi_purge_tx_buf
351
        jz      .ftdi_purge_tx_buf
377
        jmp     .error
-
 
378
                  
-
 
379
  .version:     
-
 
380
        jmp     .endswitch
-
 
381
  .error:
-
 
382
        mov     esi, [edi+output]
352
                
383
        mov     [esi], dword 'ERR0'
353
  .version:     
384
        or      [esi], eax
354
  .endswitch:
385
  .endswitch:
355
        xor     eax, eax
386
        xor     eax, eax
356
	    ret 
387
	    ret
-
 
388
        
-
 
389
  .eventdestroy:
-
 
390
        mov     eax, [EventData]
-
 
391
        mov     ebx, [EventData+4]
-
 
392
        call    DestroyEvent
-
 
393
        jmp     .endswitch
-
 
394
        
-
 
395
  .ftdi_out_control_transfer_withinp:               
-
 
396
        mov     dx, word[edi+8]                
357
        
397
        mov     word[ConfPacket+2], dx 
358
  .ftdi_out_control_transfer:
398
  .ftdi_out_control_transfer_noinp:
359
        mov     ebx, [edi]
399
        mov     ebx, [edi+4]
360
        mov     cx, word[ebx + ftdi_context.index]
400
        mov     cx, word[ebx + ftdi_context.index]
361
        mov     word[ConfPacket+4], cx
401
        mov     word[ConfPacket+4], cx
362
        xor     cx, cx
402
        xor     cx, cx
363
        mov     word[ConfPacket+6], cx
403
        mov     word[ConfPacket+6], cx
364
  .own_index:
404
  .own_index:
365
        mov    ebx, [edi+4]
405
        mov     ebx, [edi+4]
366
        DEBUGF 1,'K : ConfPacket %x %x\n', [ConfPacket], [ConfPacket+4]          
406
        DEBUGF 1,'K : ConfPacket %x %x\n', [ConfPacket], [ConfPacket+4]          
367
        lea     esi, [ConfPacket]
407
        lea     esi, [ConfPacket]
368
        lea     edi, [EventData]        
408
        lea     edi, [EventData]        
369
        stdcall USBControlTransferAsync, [ebx + ftdi_context.nullP],  esi, 0, 0, control_callback, edi, 0
409
        stdcall USBControlTransferAsync, [ebx + ftdi_context.nullP],  esi, 0, 0, control_callback, edi, 0
370
        DEBUGF 1, 'K : Returned value is %d\n', eax
410
        test    eax, eax        
-
 
411
        jz      .error
371
        mov     eax, [EventData]
412
        mov     eax, [EventData]
372
        mov     ebx, [EventData+4]
413
        mov     ebx, [EventData+4]
373
        call    WaitEvent     
414
        call    WaitEvent     
374
        jmp     .endswitch
415
        jmp     .endswitch
375
        
-
 
376
  .ftdi_set_bitmode:
-
 
377
        DEBUGF 1,'K : FTDI Seting bitmode\n'                   
-
 
378
        mov     word[ConfPacket], (FTDI_DEVICE_OUT_REQTYPE) + (SIO_SET_BITMODE_REQUEST shl 8)
-
 
379
        mov     edi, [edi+input]        
-
 
380
        mov     dx, word[edi+8]                
-
 
381
        mov     word[ConfPacket+2], dx                                        
-
 
382
        jmp     .ftdi_out_control_transfer     
-
 
383
 
416
        
384
  .ftdi_setrtshigh:
417
  .ftdi_setrtshigh:
385
        DEBUGF 1,'K : FTDI Setting RTS pin HIGH\n'                     
418
        DEBUGF 1,'K : FTDI Setting RTS pin HIGH\n'                     
386
        mov     dword[ConfPacket], (FTDI_DEVICE_OUT_REQTYPE) + (SIO_SET_MODEM_CTRL_REQUEST shl 8) + (SIO_SET_RTS_HIGH shl 16)
419
        mov     dword[ConfPacket], (FTDI_DEVICE_OUT_REQTYPE) + (SIO_SET_MODEM_CTRL_REQUEST shl 8) + (SIO_SET_RTS_HIGH shl 16)
387
        jmp     .ftdi_out_control_transfer         
420
        jmp     .ftdi_out_control_transfer_noinp         
388
 
421
 
389
  .ftdi_setrtslow:
422
  .ftdi_setrtslow:
390
        DEBUGF 1,'K : FTDI Setting RTS pin LOW\n'             
423
        DEBUGF 1,'K : FTDI Setting RTS pin LOW\n'             
391
        mov     dword[ConfPacket], (FTDI_DEVICE_OUT_REQTYPE) + (SIO_SET_MODEM_CTRL_REQUEST shl 8) + (SIO_SET_RTS_LOW shl 16)
424
        mov     dword[ConfPacket], (FTDI_DEVICE_OUT_REQTYPE) + (SIO_SET_MODEM_CTRL_REQUEST shl 8) + (SIO_SET_RTS_LOW shl 16)
392
        jmp     .ftdi_out_control_transfer         
425
        jmp     .ftdi_out_control_transfer_noinp           
393
        
426
        
394
  .ftdi_setdtrhigh:
427
  .ftdi_setdtrhigh:
395
        DEBUGF 1,'K : FTDI Setting DTR pin HIGH\n'                     
428
        DEBUGF 1,'K : FTDI Setting DTR pin HIGH\n'                     
396
        mov     dword[ConfPacket], (FTDI_DEVICE_OUT_REQTYPE) + (SIO_SET_MODEM_CTRL_REQUEST shl 8) + (SIO_SET_DTR_HIGH shl 16)
429
        mov     dword[ConfPacket], (FTDI_DEVICE_OUT_REQTYPE) + (SIO_SET_MODEM_CTRL_REQUEST shl 8) + (SIO_SET_DTR_HIGH shl 16)
397
        jmp     .ftdi_out_control_transfer         
430
        jmp     .ftdi_out_control_transfer_noinp           
398
 
431
 
399
  .ftdi_setdtrlow:
432
  .ftdi_setdtrlow:
400
        DEBUGF 1,'K : FTDI Setting DTR pin LOW\n'             
433
        DEBUGF 1,'K : FTDI Setting DTR pin LOW\n'             
401
        mov     dword[ConfPacket], (FTDI_DEVICE_OUT_REQTYPE) + (SIO_SET_MODEM_CTRL_REQUEST shl 8) + (SIO_SET_DTR_LOW shl 16)
434
        mov     dword[ConfPacket], (FTDI_DEVICE_OUT_REQTYPE) + (SIO_SET_MODEM_CTRL_REQUEST shl 8) + (SIO_SET_DTR_LOW shl 16)
402
        jmp     .ftdi_out_control_transfer         
435
        jmp     .ftdi_out_control_transfer_noinp           
403
        
436
        
404
  .ftdi_usb_reset:
437
  .ftdi_usb_reset:
405
        DEBUGF 1,'K : FTDI Reseting\n'
438
        DEBUGF 1,'K : FTDI Reseting\n'
406
        mov     dword[ConfPacket], (FTDI_DEVICE_OUT_REQTYPE) + (SIO_RESET_REQUEST shl 8) + (SIO_RESET_SIO shl 16)
439
        mov     dword[ConfPacket], (FTDI_DEVICE_OUT_REQTYPE) + (SIO_RESET_REQUEST shl 8) + (SIO_RESET_SIO shl 16)
407
        jmp     .ftdi_out_control_transfer
440
        jmp     .ftdi_out_control_transfer_noinp  
408
        
441
        
409
  .ftdi_purge_rx_buf:
442
  .ftdi_purge_rx_buf:
410
        mov     dword[ConfPacket], (FTDI_DEVICE_OUT_REQTYPE) + (SIO_RESET_REQUEST shl 8) + (SIO_RESET_PURGE_RX shl 16)
443
        mov     dword[ConfPacket], (FTDI_DEVICE_OUT_REQTYPE) + (SIO_RESET_REQUEST shl 8) + (SIO_RESET_PURGE_RX shl 16)
411
        jmp     .ftdi_out_control_transfer
444
        jmp     .ftdi_out_control_transfer_noinp  
412
        
445
        
413
  .ftdi_purge_tx_buf:
446
  .ftdi_purge_tx_buf:
414
        mov     dword[ConfPacket], (FTDI_DEVICE_OUT_REQTYPE) + (SIO_RESET_REQUEST shl 8) + (SIO_RESET_PURGE_TX shl 16)
447
        mov     dword[ConfPacket], (FTDI_DEVICE_OUT_REQTYPE) + (SIO_RESET_REQUEST shl 8) + (SIO_RESET_PURGE_TX shl 16)
415
        jmp     .ftdi_out_control_transfer
448
        jmp     .ftdi_out_control_transfer_noinp  
416
 
-
 
417
H_CLK = 120000000
-
 
418
C_CLK = 48000000        
-
 
419
  .ftdi_set_baudrate:
-
 
420
        mov     edi, [edi+input]
-
 
421
        mov     ebx, [edi]
-
 
422
        cmp     [ebx + ftdi_context.chipType], TYPE_2232H
-
 
423
        jl      .c_clk        
-
 
424
        imul    eax, [edi+8], 10
-
 
425
        cmp     eax, H_CLK / 0x3FFF        
-
 
426
        jle     .c_clk
-
 
427
  .h_clk:       
-
 
428
        cmp     dword[edi+8], H_CLK/10
-
 
429
        jl      .h_nextbaud1
-
 
430
        xor     edx, edx
-
 
431
        mov     ecx, H_CLK/10
-
 
432
        jmp     .calcend
-
 
433
        
-
 
434
  .c_clk:
-
 
435
        cmp     dword[edi+8], C_CLK/10
-
 
436
        jl      .c_nextbaud1
-
 
437
        xor     edx, edx
-
 
438
        mov     ecx, C_CLK/10
-
 
439
        jmp     .calcend  
-
 
440
  
-
 
441
  .h_nextbaud1:
-
 
442
        cmp     dword[edi+8], H_CLK/(10 + 10/2)
-
 
443
        jl      .h_nextbaud2
-
 
444
        mov     edx, 1
-
 
445
        mov     ecx, H_CLK/(10 + 10/2)
-
 
446
        jmp     .calcend
-
 
447
        
-
 
448
  .c_nextbaud1:
-
 
449
        cmp     dword[edi+8], C_CLK/(10 + 10/2)
-
 
450
        jl      .c_nextbaud2
-
 
451
        mov     edx, 1
-
 
452
        mov     ecx, C_CLK/(10 + 10/2)
-
 
453
        jmp     .calcend        
-
 
454
        
-
 
455
  .h_nextbaud2:      
-
 
456
        cmp     dword[edi+8], H_CLK/(2*10)
-
 
457
        jl      .h_nextbaud3
-
 
458
        mov     edx, 2
-
 
459
        mov     ecx, H_CLK/(2*10)
-
 
460
        jmp     .calcend
-
 
461
        
-
 
462
  .c_nextbaud2:      
-
 
463
        cmp     dword[edi+8], C_CLK/(2*10)
-
 
464
        jl      .c_nextbaud3
-
 
465
        mov     edx, 2
-
 
466
        mov     ecx, C_CLK/(2*10)
-
 
467
        jmp     .calcend        
-
 
468
        
-
 
469
  .h_nextbaud3:
-
 
470
        mov     eax, H_CLK*16/10  ; eax - best_divisor
-
 
471
        div     dword[edi+8]      ; [edi+8] - baudrate
-
 
472
        push    eax
-
 
473
        and     eax, 1
-
 
474
        pop     eax
-
 
475
        shr     eax, 1
-
 
476
        jz      .h_rounddowndiv     ; jump by result of and eax, 1
-
 
477
        inc     eax
-
 
478
  .h_rounddowndiv:
-
 
479
        cmp     eax, 0x20000
-
 
480
        jle     .h_best_divok
-
 
481
        mov     eax, 0x1FFFF
-
 
482
  .h_best_divok:
-
 
483
        mov     ecx, eax        
-
 
484
        mov     eax, H_CLK*16/10
-
 
485
        div     ecx
-
 
486
        xchg    ecx, eax            ; ecx - best_baud
-
 
487
        push    ecx
-
 
488
        and     ecx, 1
-
 
489
        pop     ecx
-
 
490
        shr     ecx, 1
-
 
491
        jz      .rounddownbaud
-
 
492
        inc     ecx
-
 
493
        jmp     .rounddownbaud
-
 
494
        
-
 
495
  .c_nextbaud3:
-
 
496
        mov     eax, C_CLK*16/10  ; eax - best_divisor
-
 
497
        div     dword[edi+8]      ; [edi+8] - baudrate
-
 
498
        push    eax
-
 
499
        and     eax, 1
-
 
500
        pop     eax
-
 
501
        shr     eax, 1
-
 
502
        jz      .c_rounddowndiv     ; jump by result of and eax, 1
-
 
503
        inc     eax
-
 
504
  .c_rounddowndiv:
-
 
505
        cmp     eax, 0x20000
-
 
506
        jle     .c_best_divok
-
 
507
        mov     eax, 0x1FFFF
-
 
508
  .c_best_divok:
-
 
509
        mov     ecx, eax        
-
 
510
        mov     eax, C_CLK*16/10
-
 
511
        div     ecx
-
 
512
        xchg    ecx, eax            ; ecx - best_baud
-
 
513
        push    ecx
-
 
514
        and     ecx, 1
-
 
515
        pop     ecx
-
 
516
        shr     ecx, 1
-
 
517
        jz      .rounddownbaud
-
 
518
        inc     ecx
-
 
519
        
-
 
520
  .rounddownbaud:
-
 
521
        mov     edx, eax            ; edx - encoded_divisor
-
 
522
        shr     edx, 3
-
 
523
        and     eax, 0x7
-
 
524
        push    esp
-
 
525
        push    7 6 5 1 4 2 3 0
-
 
526
        mov     eax, [esp+eax*4]
-
 
527
        shl     eax, 14
-
 
528
        or      edx, eax
-
 
529
        mov     esp, [esp+36]
-
 
530
        
-
 
531
  .calcend:
-
 
532
        mov     eax, edx        ; eax - *value
-
 
533
        mov     ecx, edx        ; ecx - *index
-
 
534
        and     eax, 0xFFFF
-
 
535
        cmp     [ebx + ftdi_context.chipType], TYPE_2232H
-
 
536
        jge     .foxyindex        
-
 
537
        shr     ecx, 16
-
 
538
        jmp     .preparepacket
-
 
539
  .foxyindex:
-
 
540
        shr     ecx, 8
-
 
541
        and     ecx, 0xFF00
-
 
542
        or      ecx, [ebx + ftdi_context.index]
-
 
543
        
449
        
544
  .preparepacket:
-
 
545
        mov     word[ConfPacket], (FTDI_DEVICE_OUT_REQTYPE) + (SIO_SET_BAUDRATE_REQUEST shl 8)
450
  .ftdi_set_bitmode:
546
        mov     word[ConfPacket+2], ax
451
        DEBUGF 1,'K : FTDI Seting bitmode\n'                   
547
        mov     word[ConfPacket+4], cx
-
 
548
        mov     word[ConfPacket+6], 0
452
        mov     word[ConfPacket], (FTDI_DEVICE_OUT_REQTYPE) + (SIO_SET_BITMODE_REQUEST shl 8)                                       
549
        jmp     .own_index
453
        jmp     .ftdi_out_control_transfer_withinp        
550
     
454
     
551
  .ftdi_set_line_property:
455
  .ftdi_set_line_property:
552
        mov     word[ConfPacket], (FTDI_DEVICE_OUT_REQTYPE) + (SIO_SET_DATA_REQUEST shl 8)
456
        mov     word[ConfPacket], (FTDI_DEVICE_OUT_REQTYPE) + (SIO_SET_DATA_REQUEST shl 8)
553
        mov     edi, [edi+input]        
-
 
554
        mov     dx, word[edi+8]                
-
 
555
        mov     word[ConfPacket+2], dx
-
 
556
        jmp     .ftdi_out_control_transfer
457
        jmp     .ftdi_out_control_transfer_withinp
557
        
458
        
558
  .ftdi_set_latency_timer:
459
  .ftdi_set_latency_timer:
559
        mov     word[ConfPacket], (FTDI_DEVICE_OUT_REQTYPE) + (SIO_SET_LATENCY_TIMER_REQUEST shl 8)
460
        mov     word[ConfPacket], (FTDI_DEVICE_OUT_REQTYPE) + (SIO_SET_LATENCY_TIMER_REQUEST shl 8)        
560
        mov     edi, [edi+input]        
-
 
561
        mov     dx, word[edi+8]                
-
 
562
        mov     word[ConfPacket+2], dx        
-
 
563
        jmp     .ftdi_out_control_transfer
461
        jmp     .ftdi_out_control_transfer_withinp
564
        
462
        
565
  .ftdi_set_event_char:
463
  .ftdi_set_event_char:
566
        mov     word[ConfPacket], (FTDI_DEVICE_OUT_REQTYPE) + (SIO_SET_EVENT_CHAR_REQUEST shl 8)
464
        mov     word[ConfPacket], (FTDI_DEVICE_OUT_REQTYPE) + (SIO_SET_EVENT_CHAR_REQUEST shl 8)
567
        mov     edi, [edi+input]        
-
 
568
        mov     dx, word[edi+8]                
-
 
569
        mov     word[ConfPacket+2], dx
-
 
570
        jmp     .ftdi_out_control_transfer
465
        jmp     .ftdi_out_control_transfer_withinp
571
 
466
 
572
  .ftdi_set_error_char:
467
  .ftdi_set_error_char:
573
        mov     word[ConfPacket], (FTDI_DEVICE_OUT_REQTYPE) + (SIO_SET_ERROR_CHAR_REQUEST shl 8)
468
        mov     word[ConfPacket], (FTDI_DEVICE_OUT_REQTYPE) + (SIO_SET_ERROR_CHAR_REQUEST shl 8)
574
        mov     edi, [edi+input]        
-
 
575
        mov     dx, word[edi+8]                
-
 
576
        mov     word[ConfPacket+2], dx
-
 
577
        jmp     .ftdi_out_control_transfer 
469
        jmp     .ftdi_out_control_transfer_withinp 
578
        
470
        
579
  .ftdi_setflowctrl:
471
  .ftdi_setflowctrl:
580
        mov     dword[ConfPacket], (FTDI_DEVICE_OUT_REQTYPE) + (SIO_SET_FLOW_CTRL_REQUEST shl 8) + (0 shl 16)      
472
        mov     dword[ConfPacket], (FTDI_DEVICE_OUT_REQTYPE) + (SIO_SET_FLOW_CTRL_REQUEST shl 8) + (0 shl 16)
581
        mov     edi, [edi+input]
-
 
582
        mov     ebx, [edi]
473
        mov     ebx, [edi+4]
583
        mov     cx, word[edi+8]   
474
        mov     cx, word[edi+8]   
584
        or      ecx, [ebx + ftdi_context.index]
475
        or      ecx, [ebx + ftdi_context.index]
585
        mov     word[ConfPacket+4], cx
476
        mov     word[ConfPacket+4], cx
586
        xor     cx, cx
477
        xor     cx, cx
587
        mov     word[ConfPacket+6], cx
478
        mov     word[ConfPacket+6], cx
588
        jmp     .own_index
479
        jmp     .own_index
589
 
480
 
590
  .ftdi_read_pins:
481
  .ftdi_read_pins:                            
591
        DEBUGF 1,'K : FTDI Reading pins\n'
-
 
592
        mov     edi, [edi+input]                                  
-
 
593
        mov     ebx, [edi] 
482
        mov     ebx, [edi] 
594
        mov     dword[ConfPacket], FTDI_DEVICE_IN_REQTYPE + (SIO_READ_PINS_REQUEST shl 8) + (0 shl 16)
483
        mov     dword[ConfPacket], FTDI_DEVICE_IN_REQTYPE + (SIO_READ_PINS_REQUEST shl 8) + (0 shl 16)
595
        mov     ecx, [ebx + ftdi_context.index]
484
        mov     ecx, [ebx + ftdi_context.index]
596
        mov     word[ConfPacket+4], cx
485
        mov     word[ConfPacket+4], cx
597
        mov     word[ConfPacket+6], 1
486
        mov     word[ConfPacket+6], 1
598
        lea     esi, [ConfPacket]
487
        lea     esi, [ConfPacket]
599
        lea     edi, [EventData]
488
        lea     edi, [EventData]
600
        mov     ecx, [ioctl]
489
        mov     ecx, [ioctl]
601
        mov     ecx, [ecx+output]
490
        mov     ecx, [ecx+output]
602
        stdcall USBControlTransferAsync, [ebx + ftdi_context.nullP],  esi, ecx, 1, control_callback, edi, 0
491
        stdcall USBControlTransferAsync, [ebx + ftdi_context.nullP],  esi, ecx, 1, control_callback, edi, 0
603
        DEBUGF 1, 'K : Returned value is %d\n', eax
-
 
604
        mov     eax, [EventData]
492
        mov     eax, [EventData]
605
        mov     ebx, [EventData+4]
493
        mov     ebx, [EventData+4]
606
        call    WaitEvent     
494
        call    WaitEvent     
607
        jmp     .endswitch
495
        jmp     .endswitch
608
 
496
        
-
 
497
  .ftdi_set_wchunksize:
-
 
498
        mov     ebx, [edi+4]
-
 
499
        mov     ecx, [edi+8]
-
 
500
        cmp     [ebx + ftdi_context.maxPacketSize], ecx
-
 
501
        jg      .error
-
 
502
        mov     [ebx + ftdi_context.writeBufChunkSize], ecx
-
 
503
        jmp     .endswitch
-
 
504
   
-
 
505
  .ftdi_get_wchunksize:
-
 
506
        mov     esi, [edi+output]
-
 
507
        mov     edi, [edi+input]
-
 
508
        mov     ebx, [edi+4]
-
 
509
        mov     ecx, [ebx + ftdi_context.writeBufChunkSize]
-
 
510
        mov     [esi], ecx
-
 
511
        jmp     .endswitch
-
 
512
 
-
 
513
  .ftdi_set_rchunksize:
-
 
514
        mov     ebx, [edi+4]
-
 
515
        mov     ecx, [edi+8]
-
 
516
        cmp     [ebx + ftdi_context.maxPacketSize], ecx
-
 
517
        jg      .error
-
 
518
        mov     [ebx + ftdi_context.readBufChunkSize], ecx
-
 
519
        jmp     .endswitch
-
 
520
 
-
 
521
  .ftdi_get_rchunksize:
609
  .ftdi_write_data:
522
        mov     esi, [edi+output]
610
        mov     edi, [edi+input]        
523
        mov     edi, [edi+input]
-
 
524
        mov     ebx, [edi+4]
-
 
525
        mov     ecx, [ebx + ftdi_context.readBufChunkSize]
-
 
526
        mov     [esi], ecx
-
 
527
        jmp     .endswitch        
-
 
528
 
-
 
529
  .ftdi_write_data:
-
 
530
        mov     esi, edi
-
 
531
        add     esi, 12        
611
        mov     ebx, [edi+4]
532
        mov     ebx, [edi+4]
612
        xor     ecx, ecx        ; ecx - offset     
533
        xor     ecx, ecx        ; ecx - offset      
613
  .dataleft:        
-
 
614
        mov     edx, [ebx + ftdi_context.writeBufChunkSize] ; edx - write_size
-
 
615
        push    ecx
-
 
616
        add     ecx, edx
534
  .write_loop:
617
        cmp     ecx, [edi+8]    ; [edi+8] - size
-
 
618
        pop     ecx
-
 
619
        jle     .morethanchunk_write
-
 
620
        mov     edx, [edi+8]           
535
        mov     edx, [edi+8]    ; edx - write_size
-
 
536
        sub     edx, ecx
-
 
537
        cmp     edx, [ebx + ftdi_context.writeBufChunkSize]
-
 
538
        jle     .lessthanchunk_write
621
        sub     edx, ecx
539
        mov     edx, [ebx + ftdi_context.writeBufChunkSize]
-
 
540
  .lessthanchunk_write:
622
  .morethanchunk_write:
541
        add     esi, ecx
-
 
542
        lea     eax, [EventData]
623
        lea     eax, [EventData]
543
        push    ecx ebx esi edi
624
        stdcall USBNormalTransferAsync, [ebx + ftdi_context.inEP], [edi+12+ecx], edx, bulk_callback, eax, 1
-
 
625
        push    ebx edi edx ecx
544
        stdcall USBNormalTransferAsync, [ebx + ftdi_context.inEP], esi, edx, bulk_callback, eax, 1        
626
        mov     eax, [EventData]
545
        mov     eax, [EventData]
627
        mov     ebx, [EventData+4]
546
        mov     ebx, [EventData+4]
628
        call    WaitEvent
547
        call    WaitEvent
-
 
548
        mov     eax, [EventData]
-
 
549
        mov     ebx, [EventData+4]        
-
 
550
        call    ClearEvent
629
        pop     ecx edx edi ebx
551
        pop     edi esi ebx ecx
630
        cmp     [EventData+8], -1
552
        cmp     [EventData+8], -1
631
        jz      .endswitch;jz      .error
553
        jz .error
632
        add     ecx, [EventData+8]
554
        add     ecx, [EventData+8]
633
        cmp     ecx, [edi+8]
555
        cmp     ecx, [edi+8]
634
        jl      .dataleft
556
        jge     .eventdestroy
635
        jmp     .endswitch
557
        jmp     .write_loop
636
        
558
        
-
 
559
  .ftdi_read_data:
637
  .ftdi_read_data:
560
        mov     edi, [ioctl]
638
        mov     esi, [edi+input]
561
        mov     esi, [edi+input]
639
        mov     edi, [edi+output]
562
        mov     edi, [edi+output]
640
        mov     ebx, [esi+4]        
563
        mov     ebx, [esi+4]        
641
        xor     ecx, ecx
564
        xor     ecx, ecx
642
  .read_loop:
565
  .read_loop:  
643
        mov     edx, [esi+8]
566
        mov     edx, [esi+8]
-
 
567
        cmp     ecx, edx
-
 
568
        jge     .eventdestroy ;!!!
644
        sub     edx, ecx
569
        sub     edx, ecx
645
        test    edx, edx
-
 
646
        jz      .endswitch
-
 
647
        cmp     edx, [ebx + ftdi_context.readBufChunkSize]
570
        cmp     edx, [ebx + ftdi_context.readBufChunkSize]
648
        jl      .lessthanchunk_read
571
        jl      .lessthanchunk_read
649
        mov     edx, [ebx + ftdi_context.readBufChunkSize]     
572
        mov     edx, [ebx + ftdi_context.readBufChunkSize]     
650
  .lessthanchunk_read:
573
  .lessthanchunk_read:
651
        lea     eax, [EventData]
574
        lea     eax, [EventData]
652
        stdcall USBNormalTransferAsync, [ebx + ftdi_context.outEP], [edi+ecx], edx, bulk_callback, eax, 1        
575
        add     edi, ecx
653
        push    esi edi ecx ebx
576
        push    esi edi ecx ebx
-
 
577
        stdcall USBNormalTransferAsync, [ebx + ftdi_context.outEP], edi, edx, bulk_callback, eax, 1        
654
        mov     eax, [EventData]
578
        mov     eax, [EventData]
655
        mov     ebx, [EventData+4]        
579
        mov     ebx, [EventData+4]        
656
        call    WaitEvent
580
        call    WaitEvent
-
 
581
        mov     eax, [EventData]
-
 
582
        mov     ebx, [EventData+4]        
-
 
583
        call    ClearEvent
657
        pop     ebx ecx edi esi
584
        pop     ebx ecx edi esi
658
        cmp     [EventData+8], -1
585
        cmp     [EventData+8], -1
659
        jz      .endswitch;jz      .error
586
        jz      .error
660
        add     ecx, [EventData+8]
587
        add     ecx, [EventData+8]
661
        jmp     .read_loop 
588
        jmp     .read_loop 
662
        
589
        
663
  .ftdi_poll_modem_status:
590
  .ftdi_poll_modem_status:                                 
664
        mov     edi, [edi+input]                                  
-
 
665
        mov     ebx, [edi+4] 
591
        mov     ebx, [edi+4] 
666
        mov     dword[ConfPacket], FTDI_DEVICE_IN_REQTYPE + (SIO_POLL_MODEM_STATUS_REQUEST shl 8) + (0 shl 16)
592
        mov     dword[ConfPacket], FTDI_DEVICE_IN_REQTYPE + (SIO_POLL_MODEM_STATUS_REQUEST shl 8) + (0 shl 16)
667
        mov     ecx, [ebx + ftdi_context.index]
593
        mov     ecx, [ebx + ftdi_context.index]
668
        mov     word[ConfPacket+4], cx
594
        mov     word[ConfPacket+4], cx
669
        mov     word[ConfPacket+6], 1
595
        mov     word[ConfPacket+6], 1
670
        lea     esi, [ConfPacket]
596
        lea     esi, [ConfPacket]
671
        lea     edi, [EventData]
597
        lea     edi, [EventData]
672
        mov     ecx, [ioctl]
598
        mov     ecx, [ioctl]
673
        mov     ecx, [ecx+output]
599
        mov     ecx, [ecx+output]
674
        stdcall USBControlTransferAsync, [ebx + ftdi_context.nullP],  esi, ecx, 2, control_callback, edi, 0
600
        stdcall USBControlTransferAsync, [ebx + ftdi_context.nullP],  esi, ecx, 2, control_callback, edi, 0
675
        DEBUGF 1, 'K : Returned value is %d\n', eax
-
 
676
        mov     eax, [EventData]
601
        mov     eax, [EventData]
677
        mov     ebx, [EventData+4]
602
        mov     ebx, [EventData+4]
678
        call    WaitEvent
603
        call    WaitEvent
679
        mov     ax, word[ecx]
604
        mov     ax, word[ecx]
680
        xchg    ah, al
605
        xchg    ah, al
681
        and     ah, 0xFF
606
        and     ah, 0xFF
682
        mov     word[ecx], ax
607
        mov     word[ecx], ax
683
        jmp     .endswitch
608
        jmp     .endswitch
684
        
609
        
685
  .ftdi_get_latency_timer:
610
  .ftdi_get_latency_timer:                                 
686
        mov     edi, [edi+input]                                  
-
 
687
        mov     ebx, [edi+4] 
611
        mov     ebx, [edi+4] 
688
        mov     dword[ConfPacket], FTDI_DEVICE_IN_REQTYPE + (SIO_GET_LATENCY_TIMER_REQUEST shl 8) + (0 shl 16)
612
        mov     dword[ConfPacket], FTDI_DEVICE_IN_REQTYPE + (SIO_GET_LATENCY_TIMER_REQUEST shl 8) + (0 shl 16)
689
        mov     ecx, [ebx + ftdi_context.index]
613
        mov     ecx, [ebx + ftdi_context.index]
690
        mov     word[ConfPacket+4], cx
614
        mov     word[ConfPacket+4], cx
691
        mov     word[ConfPacket+6], 1
615
        mov     word[ConfPacket+6], 1
692
        lea     esi, [ConfPacket]
616
        lea     esi, [ConfPacket]
693
        lea     edi, [EventData]
617
        lea     edi, [EventData]
694
        mov     ecx, [ioctl]
618
        mov     ecx, [ioctl]
695
        mov     ecx, [ecx+output]
619
        mov     ecx, [ecx+output]
696
        stdcall USBControlTransferAsync, [ebx + ftdi_context.nullP],  esi, ecx, 2, control_callback, edi, 0
620
        stdcall USBControlTransferAsync, [ebx + ftdi_context.nullP],  esi, ecx, 2, control_callback, edi, 0
697
        DEBUGF 1, 'K : Returned value is %d\n', eax
-
 
698
        mov     eax, [EventData]
621
        mov     eax, [EventData]
699
        mov     ebx, [EventData+4]
622
        mov     ebx, [EventData+4]
700
        call    WaitEvent
623
        call    WaitEvent
701
        jmp     .endswitch
624
        jmp     .endswitch
702
                
625
                
703
  .ftdi_get_list:
626
  .ftdi_get_list:
704
        call    linkedlist_gethead                        
627
        call    linkedlist_gethead
-
 
628
        test    eax, eax
-
 
629
        jz      .endswitch                        
705
        mov     edi, [edi+output]
630
        mov     edi, [edi+output]
706
        push    edi
631
        push    edi
707
        add     edi, 4
632
        add     edi, 4
708
        xor     ecx, ecx
633
        xor     ecx, ecx
709
  .nextdev:
634
  .nextdev:
710
        inc     ecx
635
        inc     ecx
711
        cmp     [eax + ftdi_context.lockPID], 0
636
        cmp     [eax + ftdi_context.lockPID], 0
712
        jnz      .dev_is_locked        
637
        jnz      .dev_is_locked        
713
        mov     dword[edi], 'NLKD'
638
        mov     dword[edi], 'NLKD'
714
        jmp     .nextfields
639
        jmp     .nextfields
715
  .dev_is_locked:
640
  .dev_is_locked:
716
        mov     dword[edi], 'LCKD'
641
        mov     dword[edi], 'LCKD'
717
  .nextfields:
642
  .nextfields:
718
        mov     bl, [eax + ftdi_context.chipType]
643
        mov     bl, [eax + ftdi_context.chipType]
719
        mov     [edi+4], ebx
644
        mov     [edi+4], ebx
720
        mov     [edi+8], eax
645
        mov     [edi+8], eax
721
        add     edi, 12
646
        add     edi, 12
722
        mov     eax, [eax + ftdi_context.next_context]
647
        mov     eax, [eax + ftdi_context.next_context]
723
        test    eax, eax
648
        test    eax, eax
724
        jnz     .nextdev
649
        jnz     .nextdev
725
        pop     edi
650
        pop     edi
726
        mov     [edi], ecx
651
        mov     [edi], ecx
727
        jmp     .endswitch
652
        jmp     .endswitch
728
        	   
653
        	   
729
  .ftdi_lock:
654
  .ftdi_lock:
730
        DEBUGF 1, 'K : FTDI lock attempt\n'
655
        DEBUGF 1, 'K : FTDI lock attempt\n'
731
        mov     esi, [edi+input]
656
        mov     esi, [edi+input]
732
        mov     ebx, [esi+4]
657
        mov     ebx, [esi+4]
733
        mov     eax, [ebx + ftdi_context.lockPID]
658
        mov     eax, [ebx + ftdi_context.lockPID]
734
        test    eax, eax
659
        test    eax, eax
735
        jnz     .lockedby
660
        jnz     .lockedby
736
        DEBUGF 1, 'K : Lock success\n'
661
        DEBUGF 1, 'K : Lock success\n'
737
        mov     eax, [esi]
662
        mov     eax, [esi]
738
        mov     [ebx + ftdi_context.lockPID], eax
663
        mov     [ebx + ftdi_context.lockPID], eax
739
  .lockedby:
664
  .lockedby:
740
        mov     edi, [edi+output]
665
        mov     edi, [edi+output]
741
        mov     [edi], eax
666
        mov     [edi], eax
742
        jmp     .endswitch
667
        jmp     .endswitch
743
        
668
        
744
  .ftdi_unlock:
669
  .ftdi_unlock:
745
        mov     esi, [edi+input]
670
        mov     esi, [edi+input]
746
        mov     edi, [edi+output]
671
        mov     edi, [edi+output]
747
        mov     ebx, [esi+4]
672
        mov     ebx, [esi+4]
748
        mov     eax, [ebx + ftdi_context.lockPID]
673
        mov     eax, [ebx + ftdi_context.lockPID]
749
        cmp     eax, [esi]
674
        cmp     eax, [esi]
750
        jnz     .unlockimp
675
        jnz     .unlockimp
751
        mov     [ebx + ftdi_context.lockPID], 0
676
        mov     [ebx + ftdi_context.lockPID], 0
752
        mov     dword[edi], 0
677
        mov     dword[edi], 0
753
        jmp     .endswitch   
678
        jmp     .endswitch   
754
  .unlockimp:     
679
  .unlockimp:     
755
        mov     [edi], eax
680
        mov     [edi], eax
756
        jmp     .endswitch  
681
        jmp     .endswitch 
-
 
682
 
-
 
683
H_CLK = 120000000
-
 
684
C_CLK = 48000000        
-
 
685
  .ftdi_set_baudrate:
-
 
686
        mov     ebx, [edi+4]
-
 
687
        cmp     [ebx + ftdi_context.chipType], TYPE_2232H
-
 
688
        jl      .c_clk        
-
 
689
        imul    eax, [edi+8], 10
-
 
690
        cmp     eax, H_CLK / 0x3FFF        
-
 
691
        jle     .c_clk
-
 
692
  .h_clk:       
-
 
693
        cmp     dword[edi+8], H_CLK/10
-
 
694
        jl      .h_nextbaud1
-
 
695
        xor     edx, edx
-
 
696
        mov     ecx, H_CLK/10
-
 
697
        jmp     .calcend
-
 
698
        
-
 
699
  .c_clk:
-
 
700
        cmp     dword[edi+8], C_CLK/10
-
 
701
        jl      .c_nextbaud1
-
 
702
        xor     edx, edx
-
 
703
        mov     ecx, C_CLK/10
-
 
704
        jmp     .calcend  
-
 
705
  
-
 
706
  .h_nextbaud1:
-
 
707
        cmp     dword[edi+8], H_CLK/(10 + 10/2)
-
 
708
        jl      .h_nextbaud2
-
 
709
        mov     edx, 1
-
 
710
        mov     ecx, H_CLK/(10 + 10/2)
-
 
711
        jmp     .calcend
-
 
712
        
-
 
713
  .c_nextbaud1:
-
 
714
        cmp     dword[edi+8], C_CLK/(10 + 10/2)
-
 
715
        jl      .c_nextbaud2
-
 
716
        mov     edx, 1
-
 
717
        mov     ecx, C_CLK/(10 + 10/2)
-
 
718
        jmp     .calcend        
-
 
719
        
-
 
720
  .h_nextbaud2:      
-
 
721
        cmp     dword[edi+8], H_CLK/(2*10)
-
 
722
        jl      .h_nextbaud3
-
 
723
        mov     edx, 2
-
 
724
        mov     ecx, H_CLK/(2*10)
-
 
725
        jmp     .calcend
-
 
726
        
-
 
727
  .c_nextbaud2:      
-
 
728
        cmp     dword[edi+8], C_CLK/(2*10)
-
 
729
        jl      .c_nextbaud3
-
 
730
        mov     edx, 2
-
 
731
        mov     ecx, C_CLK/(2*10)
-
 
732
        jmp     .calcend        
-
 
733
        
-
 
734
  .h_nextbaud3:
-
 
735
        mov     eax, H_CLK*16/10  ; eax - best_divisor
-
 
736
        div     dword[edi+8]      ; [edi+8] - baudrate
-
 
737
        push    eax
-
 
738
        and     eax, 1
-
 
739
        pop     eax
-
 
740
        shr     eax, 1
-
 
741
        jz      .h_rounddowndiv     ; jump by result of and eax, 1
-
 
742
        inc     eax
-
 
743
  .h_rounddowndiv:
-
 
744
        cmp     eax, 0x20000
-
 
745
        jle     .h_best_divok
-
 
746
        mov     eax, 0x1FFFF
-
 
747
  .h_best_divok:
-
 
748
        mov     ecx, eax        
-
 
749
        mov     eax, H_CLK*16/10
-
 
750
        div     ecx
-
 
751
        xchg    ecx, eax            ; ecx - best_baud
-
 
752
        push    ecx
-
 
753
        and     ecx, 1
-
 
754
        pop     ecx
-
 
755
        shr     ecx, 1
-
 
756
        jz      .rounddownbaud
-
 
757
        inc     ecx
-
 
758
        jmp     .rounddownbaud
-
 
759
        
-
 
760
  .c_nextbaud3:
-
 
761
        mov     eax, C_CLK*16/10  ; eax - best_divisor
-
 
762
        div     dword[edi+8]      ; [edi+8] - baudrate
-
 
763
        push    eax
-
 
764
        and     eax, 1
-
 
765
        pop     eax
-
 
766
        shr     eax, 1
-
 
767
        jz      .c_rounddowndiv     ; jump by result of and eax, 1
-
 
768
        inc     eax
-
 
769
  .c_rounddowndiv:
-
 
770
        cmp     eax, 0x20000
-
 
771
        jle     .c_best_divok
-
 
772
        mov     eax, 0x1FFFF
-
 
773
  .c_best_divok:
-
 
774
        mov     ecx, eax        
-
 
775
        mov     eax, C_CLK*16/10
-
 
776
        div     ecx
-
 
777
        xchg    ecx, eax            ; ecx - best_baud
-
 
778
        push    ecx
-
 
779
        and     ecx, 1
-
 
780
        pop     ecx
-
 
781
        shr     ecx, 1
-
 
782
        jz      .rounddownbaud
-
 
783
        inc     ecx
-
 
784
        
-
 
785
  .rounddownbaud:
-
 
786
        mov     edx, eax            ; edx - encoded_divisor
-
 
787
        shr     edx, 3
-
 
788
        and     eax, 0x7
-
 
789
        push    esp
-
 
790
        push    7 6 5 1 4 2 3 0
-
 
791
        mov     eax, [esp+eax*4]
-
 
792
        shl     eax, 14
-
 
793
        or      edx, eax
-
 
794
        mov     esp, [esp+36]
-
 
795
        
-
 
796
  .calcend:
-
 
797
        mov     eax, edx        ; eax - *value
-
 
798
        mov     ecx, edx        ; ecx - *index
-
 
799
        and     eax, 0xFFFF
-
 
800
        cmp     [ebx + ftdi_context.chipType], TYPE_2232H
-
 
801
        jge     .foxyindex        
-
 
802
        shr     ecx, 16
-
 
803
        jmp     .preparepacket
-
 
804
  .foxyindex:
-
 
805
        shr     ecx, 8
-
 
806
        and     ecx, 0xFF00
-
 
807
        or      ecx, [ebx + ftdi_context.index]
-
 
808
        
-
 
809
  .preparepacket:
-
 
810
        mov     word[ConfPacket], (FTDI_DEVICE_OUT_REQTYPE) + (SIO_SET_BAUDRATE_REQUEST shl 8)
-
 
811
        mov     word[ConfPacket+2], ax
-
 
812
        mov     word[ConfPacket+4], cx
-
 
813
        mov     word[ConfPacket+6], 0
-
 
814
        jmp     .own_index        
757
        
815
        
758
endp 
816
endp 
759
restore   handle
817
restore   handle
760
restore   io_code
818
restore   io_code
761
restore   input
819
restore   input
762
restore   inp_size
820
restore   inp_size
763
restore   output
821
restore   output
764
restore   out_size 
822
restore   out_size 
765
 
823
 
766
 
824
 
767
align 4
825
align 4
768
proc control_callback stdcall uses ebx edi esi, .pipe:DWORD, .status:DWORD, .buffer:DWORD, .length:DWORD, .calldata:DWORD   
826
proc control_callback stdcall uses ebx edi esi, .pipe:DWORD, .status:DWORD, .buffer:DWORD, .length:DWORD, .calldata:DWORD   
769
   
827
   
770
        DEBUGF 1, 'K : status is %d\n', [.status] 
828
        DEBUGF 1, 'K : status is %d\n', [.status] 
771
        mov     ecx, [.calldata]
829
        mov     ecx, [.calldata]
772
        mov     eax, [ecx]
830
        mov     eax, [ecx]
773
        mov     ebx, [ecx+4]
831
        mov     ebx, [ecx+4]
774
        mov     edx, [.status]
832
        mov     edx, [.status]
775
        mov     [ecx+8], edx
833
        mov     [ecx+8], edx
776
        xor     esi, esi
834
        xor     esi, esi
777
        xor     edx, edx
835
        xor     edx, edx
778
        call    RaiseEvent              
836
        call    RaiseEvent              
779
        ret
837
        ret
780
endp
838
endp
781
 
839
 
782
proc bulk_callback stdcall uses ebx edi esi, .pipe:DWORD, .status:DWORD, .buffer:DWORD, .length:DWORD, .calldata:DWORD
840
proc bulk_callback stdcall uses ebx edi esi, .pipe:DWORD, .status:DWORD, .buffer:DWORD, .length:DWORD, .calldata:DWORD
783
 
841
 
784
        DEBUGF 1, 'K : status is %d\n', [.status]        
842
        DEBUGF 1, 'K : status is %d\n', [.status]        
785
        mov     ecx, [.calldata]
843
        mov     ecx, [.calldata]
786
        mov     eax, [ecx]
844
        mov     eax, [ecx]
787
        mov     ebx, [ecx+4]
845
        mov     ebx, [ecx+4]
788
        cmp     [.status], 0
846
        cmp     [.status], 0
789
        jg      .error?
847
        jz      .normal
790
  .error?:
-
 
791
        cmp     [.status], 9
848
        cmp     [.status], 9
792
        jne     .error
849
        jne     .error
-
 
850
  .normal:
793
        mov     edx, [.length]
851
        mov     edx, [.length]
794
        mov     [ecx+8], edx
852
        mov     [ecx+8], edx
795
        jmp     .ok
853
        jmp     .ok
796
  .error:
854
  .error:
797
        mov     [ecx+8], dword -1
855
        mov     [ecx+8], dword -1
798
  .ok:
856
  .ok:    
799
        xor     esi, esi
857
        xor     esi, esi
800
        xor     edx, edx
858
        xor     edx, edx
801
        ;mov     edx, 0x80000000
-
 
802
        call    RaiseEvent            
859
        call    RaiseEvent            
803
        ret
860
        ret
804
endp
861
endp
805
 
862
 
806
proc DeviceDisconnected stdcall uses  ebx esi edi, .device_data:DWORD
863
proc DeviceDisconnected stdcall uses  ebx esi edi, .device_data:DWORD
807
 
864
 
808
        DEBUGF 1, 'K : FTDI deleting device data %x\n', [.device_data]
865
        DEBUGF 1, 'K : FTDI deleting device data %x\n', [.device_data]
809
        mov     eax, [.device_data] 
866
        mov     eax, [.device_data] 
810
        call    linkedlist_delete
867
        call    linkedlist_delete
811
        ret           
868
        ret           
812
endp
869
endp
813
 
870
 
814
include 'linkedlist.inc'
871
include 'linkedlist.inc'
815
        
872
        
816
; Exported variable: kernel API version.
873
; Exported variable: kernel API version.
817
align 4
874
align 4
818
version dd      50005h
875
version dd      50005h
819
; Structure with callback functions.
876
; Structure with callback functions.
820
usb_functions:
877
usb_functions:
821
        dd      12
878
        dd      12
822
        dd      AddDevice
879
        dd      AddDevice
823
        dd      DeviceDisconnected
880
        dd      DeviceDisconnected
824
 
881
 
825
;for DEBUGF macro
882
;for DEBUGF macro
826
include_debug_strings
883
include_debug_strings
827
 
884
 
828
 
885
 
829
 
886
 
830
 
887
 
831
; for uninitialized data
888
; for uninitialized data
832
;section '.data' data readable writable align 16
889
;section '.data' data readable writable align 16