Subversion Repositories Kolibri OS

Rev

Rev 5034 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
5034 gtament 1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
;;                                                              ;;
3
;; Copyright (C) KolibriOS team 2004-2014. All rights reserved. ;;
4
;; Distributed under terms of the GNU General Public License    ;;
5
;;                                                              ;;
6
;;  FT232 SyncBB mode demonstration for KolibriOS               ;;
7
;;                                                              ;;
8
;;   Written by gtament@gmail.com                               ;;
9
;;                                                              ;;
10
;;         GNU GENERAL PUBLIC LICENSE                           ;;
11
;;          Version 2, June 1991                                ;;
12
;;                                                              ;;
13
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
14
 
15
format binary as ""
16
use32
17
org 0x0
18
 
19
; The header
20
 
21
db 'MENUET01'
22
dd 0x01
23
dd INIT
24
dd I_END
25
dd 0x100000
26
dd 0x7fff0
27
dd 0, 0
28
 
29
; The code area
30
 
31
include '../../macros.inc'
32
include '../../debug.inc'
33
 
34
struct IOCTL
35
handle			dd	?
36
io_code 		dd	?
37
input			dd	?
38
inp_size		dd	?
39
output			dd	?
40
out_size		dd	?
41
ends
42
 
43
BUTTONXSIZE = 60
44
BUTTONYSIZE = 60
45
BUTTONXSTART= 20
5041 gtament 46
BUTTONYSTART= 55
5034 gtament 47
BUTTONXSPACE= 10
48
BUTTONCOUNT = 8
49
ONCOLOR     = 0x0018c015
50
OFFCOLOR    = 0x00db2521
51
 
5041 gtament 52
;Flags
53
PIN_CONF_FLAG = 0
54
 
5034 gtament 55
INIT:
56
	mov	    [btn_state], 0xFF
57
	mov	    [btn_io], 0xFF
58
 
59
	mcall	68, 11
60
	call	draw_window
61
	mov	    edi, drv_name
62
	mcall	68, 16, edi
63
    cmp     eax, 0
64
    jnz     @f
65
    debug_print 'Error while loading driver\n'
66
  @@:
67
    mov     [IOCTLs+IOCTL.handle], eax
68
    mov     eax, 8
69
    mov     [IOCTLs+IOCTL.inp_size], eax
70
    mov     [IOCTLs+IOCTL.out_size], eax
71
    mov 	eax, out_buf
72
    mov 	[IOCTLs+IOCTL.output], eax
73
    mov 	eax, in_buf
74
    mov 	[IOCTLs+IOCTL.input], eax
75
 
76
    call    drivercomm.getlist
5041 gtament 77
    test    eax, eax
78
    jnz     @f
79
    mcall   4, 5 shl 16 + 25, 1 shl 31 + 0xFF shl 16, noftdi_msg
80
  @@:
5034 gtament 81
    call    drivercomm.getlock
5041 gtament 82
    mov     eax, [pid]
83
    cmp     eax, [out_buf]
84
    jz	    @f
85
    mcall   4, 5 shl 16 + 25, 1 shl 31 + 0xFF shl 16, devlkd_msg
86
    jmp     event_wait
87
  @@:
88
    mcall   4, 5 shl 16 + 25, 1 shl 31, welcio_msg
89
    mov     [flags], 1 shl PIN_CONF_FLAG
90
    call    draw_window.no_redraw
91
    jmp     event_wait
92
  .init_cont:
93
    call    draw_window
94
    mcall   4, 5 shl 16 + 25, 1 shl 31 + ONCOLOR, devrdy_msg
5034 gtament 95
 
96
event_wait:
97
	mov	    eax, 10
98
	mcall
99
 
100
	cmp	    eax, 1			; Event redraw request ?
101
	je	    redraw
102
 
103
	cmp	    eax, 2			; Event key in buffer ?
104
	je	    key
105
 
106
	cmp	    eax, 3			; Event button in buffer ?
107
	je	    button
108
 
109
	jmp	    event_wait
110
 
111
redraw:
112
	call	draw_window
113
	jmp	    event_wait
114
 
115
key:
116
	mcall	2
117
    cmp     ah, '8'
118
    jg	    event_wait
119
    cmp     ah, '1'
120
    jl	    event_wait
121
    sub     ah, 0x2F
122
    jmp     button.noclose
123
 
124
button:
125
	mov	    eax,17
126
	mcall
127
 
128
	cmp	    ah, 1
5041 gtament 129
	jg	    .noclose
5034 gtament 130
    call    drivercomm.unlock
131
	mov	    eax, -1
132
	mcall
133
 
134
 .noclose:
135
	cmp	    ah, 10
136
	jge	    .toggleb
5041 gtament 137
	mov	    ebx, [flags]
138
	and 	ebx, 1 shl PIN_CONF_FLAG
139
	jnz	    event_wait
5034 gtament 140
	movzx	edx, ah
141
	dec	    ah
142
	dec	    ah
143
	mov	    cl, ah
144
	mov	    ah ,1
145
	shl	    ah, cl
5041 gtament 146
	mov	    al, [btn_io]
147
	and	    al, ah
148
	jz	    .input
5034 gtament 149
	xor	    byte[btn_state], ah
5041 gtament 150
  .input:
151
    call    draw_window.oloop_entry
5034 gtament 152
    call    drivercomm.write
153
    call    drivercomm.read
5041 gtament 154
    ;call    drivercomm.pins
5034 gtament 155
	jmp	    event_wait
156
 
157
  .toggleb:
5041 gtament 158
    cmp     ah, 19
159
    jg	    .pinconf
5034 gtament 160
    movzx	edx, ah
161
	mov	    cl, ah
162
	sub	    cl, 10
163
	mov	    ah, 1
164
	shl	    ah, cl
165
	xor	    byte[btn_io], ah
166
	call	draw_tbutton
167
	jmp	    event_wait
168
 
5041 gtament 169
  .pinconf:
170
    cmp     ah, 20
171
    mov     eax, [flags]
172
    and     eax, 1 shl PIN_CONF_FLAG
173
    jz	    .no_conf
174
    call    drivercomm.bitmode
175
    call    drivercomm.baud
176
  .no_conf:
177
    xor     [flags], 1 shl PIN_CONF_FLAG
178
    jmp     INIT.init_cont
179
 
5034 gtament 180
drivercomm:				;Driver communication procs
181
  .baud:
182
    mov     [IOCTLs+IOCTL.io_code], 10
183
    mov     edi, in_buf
184
    mov     eax, [pid]
185
    mov     [edi], eax
186
    mov     eax, [dev]
187
    mov     [edi+4], eax
188
    mov     [edi+8], dword 9600
189
    mcall   68, 17, IOCTLs
190
    ret
191
 
192
  .write:
193
    mov     [IOCTLs+IOCTL.io_code], 8
194
    mov     edi, in_buf
195
    mov     eax, [pid]
196
    mov     [edi], eax
197
    mov     eax, [dev]
198
    mov     [edi+4], eax
199
    mov     [edi+8], dword 1
200
    mov     al, [btn_state]
5041 gtament 201
    mov     ecx, 4
202
    add     edi, 12
203
    rep     stosb
5034 gtament 204
    mcall   68, 17, IOCTLs
205
    ret
206
 
207
  .read:
208
    mov     [IOCTLs+IOCTL.io_code], 9
209
    mov     edi, in_buf
210
    mov     eax, [pid]
211
    mov     [edi], eax
212
    mov     eax, [dev]
213
    mov     [edi+4], eax
5041 gtament 214
    mov     [edi+8], dword 3
5034 gtament 215
    mcall   68, 17, IOCTLs
5041 gtament 216
    test    eax, eax
217
    jz	    .read_ok
218
    debug_print 'Error'
219
    newline
220
 .read_ok:
221
    mov     al, byte[out_buf+2]
5034 gtament 222
    mov     [btn_state], al
223
    ret
224
 
225
  .getlock:
226
    mcall	9, thread_inf, 0
227
    mov     eax, dword[thread_inf+30]
228
    mov     [pid], eax
229
    mov     edi, in_buf
230
    mov     [edi], eax
231
    mov     eax, 2
232
    mov     [IOCTLs+IOCTL.io_code], eax
233
    mov     eax, [dev]
234
    mov     [edi+4], eax
235
    mov     eax, 8
236
    mov     [IOCTLs+IOCTL.inp_size], eax
237
    mcall   68, 17, IOCTLs
238
    ret
239
 
240
  .getlist:
241
    mov     eax, 1
242
    mov     [IOCTLs+IOCTL.io_code], eax
243
    mcall   68, 17, IOCTLs
244
    mov     edi, out_buf
245
    mov     eax, [edi+12]
246
    mov     [dev], eax
5041 gtament 247
    mov     eax, [edi]
5034 gtament 248
    ret
249
 
250
  .bitmode:
251
	mov		[IOCTLs+IOCTL.io_code], 11
252
    mov     edi, in_buf
253
	mov	    eax, [pid]
254
	mov	    [edi], eax
255
	mov	    eax, [dev]
256
	mov	    [edi+4], eax
257
	xor	    eax, eax
5041 gtament 258
	mov	    ah, [btn_io]
259
	mov	    al, 0x01
5034 gtament 260
	mov	    [edi+8], eax
261
    mcall   68, 17, IOCTLs
262
    ret
263
 
5041 gtament 264
  .pins:
265
    mov [IOCTLs+IOCTL.io_code], 22
266
    mov edi, in_buf
267
    mov eax, [pid]
268
    mov [edi], eax
269
    mov eax, [dev]
270
    mov [edi+4], eax
271
    mcall 68, 17, IOCTLs
272
    mov al, byte[out_buf]
273
    mov [btn_state], al
274
    ret
275
 
5034 gtament 276
  .unlock:
277
    mov     eax, [pid]
278
    mov     edi, in_buf
279
    mov     [edi], eax
280
    mov     eax, 3
281
    mov     [IOCTLs+IOCTL.io_code], eax
282
    mov     eax, [dev]
283
    mov     [edi+4], eax
284
    mov     eax, 8
285
    mov     [IOCTLs+IOCTL.inp_size], eax
286
    mcall   68, 17, IOCTLs
287
    ret
288
 
289
;  *********************************************
290
;  ******  WINDOW DEFINITIONS AND DRAW  ********
291
;  *********************************************
292
 
293
draw_window:
294
	mov	    eax, 12
295
	mov	    ebx, 1
296
	mcall
297
 
298
	mov	    eax, 0
299
	mov	    ebx, 100 * 65536 + (BUTTONXSIZE+BUTTONXSPACE)*BUTTONCOUNT+BUTTONXSTART*2
300
	mov	    ecx, 100 * 65536 + 120
301
	mov	    edx, 0x14E1E1E1
302
	mov	    esi, 0x808899ff
303
	mov	    edi, title
304
	mcall
305
 
5041 gtament 306
  .no_redraw:
307
	mcall	    8, ((BUTTONXSIZE+BUTTONXSPACE)*BUTTONCOUNT-30) shl 16 + 60, 25 shl 16 + 12, 20, 0x00E1E1E1
308
	mov	    eax, [flags]
309
	and	    eax, 1 shl PIN_CONF_FLAG
310
	jz	    .no_toggles
311
	mcall	    4, ((BUTTONXSIZE+BUTTONXSPACE)*BUTTONCOUNT-27) shl 16 + 28, 1 shl 31, fnsh_btn
312
	mov	    edx, BUTTONCOUNT+9
313
  .tloop:
314
    push    edx
315
    call    draw_tbutton
316
    pop     edx
317
    dec     edx
318
    cmp     edx, 9
319
    jnz     .tloop
320
    jmp     @f
321
  .no_toggles:
322
	mcall 4, ((BUTTONXSIZE+BUTTONXSPACE)*BUTTONCOUNT-27) shl 16 + 28, 1 shl 31, conf_btn
323
  @@:
324
  .oloop_entry:
5034 gtament 325
	mov	edx, BUTTONCOUNT+1
326
  .oloop:
327
    push    edx
328
    call    draw_obutton
329
    pop     edx
330
    dec     edx
331
    cmp     edx, 1
332
    jnz     .oloop
333
 
334
	mov	    eax, 12
335
	mov	    ebx, 2
336
	mcall
337
	ret
338
 
339
redraw_obutton:
340
	mov	    eax, 8
341
    push    edx
342
	or	    edx, 0x80 shl 24
343
	mcall
344
	pop	    edx
345
draw_obutton:
346
	mov	    ecx, edx
347
	dec	    ecx
348
	dec	    ecx
349
	xor	    ebx, ebx
350
	mov	    bl, [btn_state]
351
	mov	    bh, 1
352
	shl	    bh, cl
353
	and	    bl, bh
354
	jz	    .off
355
	mov	    esi, ONCOLOR
356
	jmp	    .aftercolor
357
  .off:
358
	mov	    esi, OFFCOLOR
359
  .aftercolor:
360
	mov	    bl, [btn_io]
361
	and	    bl, bh
362
	jne	.output
363
	or	    edx, 1 shl 29
364
  .output:
365
	push	ecx
366
	imul	bx, cx, word(BUTTONXSPACE+BUTTONXSIZE)
367
	add	    bx, BUTTONXSTART
368
	imul	ebx, 65536
369
	add	    ebx, BUTTONXSIZE
370
	mov	    ecx, BUTTONYSTART*65536+BUTTONYSIZE
371
	mcall	8
372
	pop	    ecx
373
	xor	    ebx, ebx
374
	mov	    bl, [btn_io]
375
	mov	    bh, 1
376
	shl	    bh, cl
377
	and	    bl, bh
378
	jnz	    .text
379
	ret
380
  .text:
381
	mov	    bl, [btn_state]
382
	and	    bl, bh
383
	jz	    .off_text
384
	mov	    edx, on_text
385
	jmp	    .aftertext
386
  .off_text:
387
	mov	    edx, off_text
388
  .aftertext:
389
	imul	bx, cx, word(BUTTONXSPACE+BUTTONXSIZE)
390
	add	    bx, (BUTTONXSTART + (BUTTONXSIZE/2)-5)
391
	shl	    ebx, 16
392
	add	    ebx, BUTTONYSTART + (BUTTONYSIZE/2)
393
	mcall	4,,1 shl 31
394
	ret
395
 
396
draw_tbutton:
397
	mov	    ecx, edx
398
	sub	    ecx, 10
399
	push	edx ecx
400
	or	    edx, 1 shl 31
401
	mcall	8
402
	xor	    edi, edi
403
	imul	di, cx, word(BUTTONXSPACE+BUTTONXSIZE)
404
	push	edi
405
	shl	    edi, 16
406
	mov	    ebx, (BUTTONXSTART)*65536+BUTTONYSTART-12
407
	add	    ebx, edi
408
	mcall	4,, 1 shl 31, i_text
409
	mov	    ebx, (BUTTONXSTART+5)*65536+BUTTONXSIZE-5*2
410
	add	    ebx, edi
411
	mcall	13,, (BUTTONYSTART-13)*65536+9, 0xFFFFFF
412
	mov	    ebx, (BUTTONXSTART+BUTTONXSIZE-4)*65536+BUTTONYSTART-12
413
	add	    ebx, edi
414
	mcall	4,, 1 shl 31, o_text
415
	pop	    edi ecx edx
416
	mov	    ebx, edi
417
	add	    ebx, (BUTTONXSTART+7)
418
	mov	    al, [btn_io]
419
	mov	    ah, 1
420
	shl	    ah, cl
421
	and	    al, ah
422
	jz	    .input
423
	add	    ebx, (BUTTONXSIZE-14)/2
424
  .input:
425
	shl	    ebx, 16
426
	add	    ebx, (BUTTONXSIZE-14)/2
427
	mcall	8,,(BUTTONYSTART-12)*65536+6,, 0x00576B8C
428
	ret
429
 
430
;  *********************************************
431
;  *************   DATA AREA   *****************
432
;  *********************************************
433
 
434
btn_state   db ?
435
btn_io	    db ?
5041 gtament 436
dev		dd ?
437
pid		dd ?
438
flags	    dd ?
5034 gtament 439
drv_name    db 'usbother', 0
5041 gtament 440
noftdi_msg  db 'No FTDI connected', 0
441
devrdy_msg  db 'First FTDI is ready', 0
442
devlkd_msg  db 'First FTDI is locked', 0
443
welcio_msg  db 'Please, choose pin state', 0
444
conf_btn    db 'Configure', 0
445
fnsh_btn    db 'Finish', 0
5034 gtament 446
off_text    db 'OFF', 0
447
on_text     db 'ON', 0
448
i_text	    db 'I', 0
449
o_text	    db 'O', 0
450
out_buf     rd 10
451
in_buf	    rd 10
452
IOCTLs	    rd 6
453
thread_inf  rb 1024
454
title	    db "FT232 Control Center", 0
455
 
456
I_END: