Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  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
  46. BUTTONYSTART= 50
  47. BUTTONXSPACE= 10
  48. BUTTONCOUNT = 8
  49. ONCOLOR     = 0x0018c015
  50. OFFCOLOR    = 0x00db2521
  51.  
  52. INIT:
  53.         mov         [btn_state], 0xFF
  54.         mov         [btn_io], 0xFF
  55.  
  56.         mcall   68, 11
  57.         call    draw_window
  58.         mov         edi, drv_name
  59.         mcall   68, 16, edi
  60.     cmp     eax, 0
  61.     jnz     @f
  62.     debug_print 'Error while loading driver\n'
  63.   @@:
  64.     mov     [IOCTLs+IOCTL.handle], eax
  65.     mov     eax, 8
  66.     mov     [IOCTLs+IOCTL.inp_size], eax
  67.     mov     [IOCTLs+IOCTL.out_size], eax
  68.     mov         eax, out_buf
  69.     mov         [IOCTLs+IOCTL.output], eax
  70.     mov         eax, in_buf
  71.     mov         [IOCTLs+IOCTL.input], eax
  72.  
  73.     call    drivercomm.getlist
  74.     call    drivercomm.getlock
  75.     call    drivercomm.bitmode
  76.     call    drivercomm.baud
  77.  
  78. event_wait:
  79.         mov         eax, 10
  80.         mcall
  81.  
  82.         cmp         eax, 1                      ; Event redraw request ?
  83.         je          redraw
  84.  
  85.         cmp         eax, 2                      ; Event key in buffer ?
  86.         je          key
  87.  
  88.         cmp         eax, 3                      ; Event button in buffer ?
  89.         je          button
  90.  
  91.         jmp         event_wait
  92.  
  93. redraw:
  94.         call    draw_window
  95.         jmp         event_wait
  96.  
  97. key:
  98.         mcall   2
  99.     cmp     ah, '8'
  100.     jg      event_wait
  101.     cmp     ah, '1'
  102.     jl      event_wait
  103.     sub     ah, 0x2F
  104.     jmp     button.noclose
  105.  
  106. button:
  107.         mov         eax,17
  108.         mcall
  109.  
  110.         cmp         ah, 1
  111.         jle         .noclose
  112.     call    drivercomm.unlock
  113.         mov         eax, -1
  114.         mcall
  115.  
  116.  .noclose:
  117.         cmp         ah, 10
  118.         jge         .toggleb
  119.         movzx   edx, ah
  120.         dec         ah
  121.         dec         ah
  122.         mov         cl, ah
  123.         mov         ah ,1
  124.         shl         ah, cl
  125.         xor         byte[btn_state], ah
  126.     push    edx
  127.     call    drivercomm.write
  128.     call    drivercomm.read
  129.     pop     edx
  130.         call    redraw_obutton
  131.         jmp         event_wait
  132.  
  133.   .toggleb:
  134.     cmp     ah, 18
  135.     jg      event_wait
  136.     movzx       edx, ah
  137.         mov         cl, ah
  138.         sub         cl, 10
  139.         mov         ah, 1
  140.         shl         ah, cl
  141.         xor         byte[btn_io], ah
  142.         call    draw_tbutton
  143.         jmp         event_wait
  144.  
  145. drivercomm:                             ;Driver communication procs
  146.   .baud:
  147.     mov     [IOCTLs+IOCTL.io_code], 10
  148.     mov     edi, in_buf
  149.     mov     eax, [pid]
  150.     mov     [edi], eax
  151.     mov     eax, [dev]
  152.     mov     [edi+4], eax
  153.     mov     [edi+8], dword 9600
  154.     mcall   68, 17, IOCTLs
  155.     ret
  156.  
  157.   .write:
  158.     mov     [IOCTLs+IOCTL.io_code], 8
  159.     mov     edi, in_buf
  160.     mov     eax, [pid]
  161.     mov     [edi], eax
  162.     mov     eax, [dev]
  163.     mov     [edi+4], eax
  164.     mov     [edi+8], dword 1
  165.     mov     al, [btn_state]
  166.     mov     byte[edi+12], al
  167.     mcall   68, 17, IOCTLs
  168.     ret
  169.  
  170.   .read:
  171.     mov     [IOCTLs+IOCTL.io_code], 9
  172.     mov     edi, in_buf
  173.     mov     eax, [pid]
  174.     mov     [edi], eax
  175.     mov     eax, [dev]
  176.     mov     [edi+4], eax
  177.     mov     [edi+8], dword 1
  178.     mcall   68, 17, IOCTLs
  179.     mov     al, byte[out_buf]
  180.     mov     [btn_state], al
  181.     newline
  182.     ret
  183.  
  184.   .getlock:
  185.     mcall       9, thread_inf, 0
  186.     mov     eax, dword[thread_inf+30]
  187.     mov     [pid], eax
  188.     mov     edi, in_buf
  189.     mov     [edi], eax
  190.     mov     eax, 2
  191.     mov     [IOCTLs+IOCTL.io_code], eax
  192.     mov     eax, [dev]
  193.     mov     [edi+4], eax
  194.     mov     eax, 8
  195.     mov     [IOCTLs+IOCTL.inp_size], eax
  196.     mcall   68, 17, IOCTLs
  197.     ret
  198.  
  199.   .getlist:
  200.     mov     eax, 1
  201.     mov     [IOCTLs+IOCTL.io_code], eax
  202.     mcall   68, 17, IOCTLs
  203.     mov     edi, out_buf
  204.     mov     eax, [edi+12]
  205.     mov     [dev], eax
  206.     ret
  207.  
  208.   .bitmode:
  209.         mov             [IOCTLs+IOCTL.io_code], 11
  210.     mov     edi, in_buf
  211.         mov         eax, [pid]
  212.         mov         [edi], eax
  213.         mov         eax, [dev]
  214.         mov         [edi+4], eax
  215.         xor         eax, eax
  216.         mov         al, [btn_io]
  217.         mov         ah, 0x04
  218.         mov         [edi+8], eax
  219.     mcall   68, 17, IOCTLs
  220.     ret
  221.  
  222.   .unlock:
  223.     mov     eax, [pid]
  224.     mov     edi, in_buf
  225.     mov     [edi], eax
  226.     mov     eax, 3
  227.     mov     [IOCTLs+IOCTL.io_code], eax
  228.     mov     eax, [dev]
  229.     mov     [edi+4], eax
  230.     mov     eax, 8
  231.     mov     [IOCTLs+IOCTL.inp_size], eax
  232.     mcall   68, 17, IOCTLs
  233.     ret
  234.  
  235. ;  *********************************************
  236. ;  ******  WINDOW DEFINITIONS AND DRAW  ********
  237. ;  *********************************************
  238.  
  239. draw_window:
  240.         mov         eax, 12
  241.         mov         ebx, 1
  242.         mcall
  243.  
  244.         mov         eax, 0
  245.         mov         ebx, 100 * 65536 + (BUTTONXSIZE+BUTTONXSPACE)*BUTTONCOUNT+BUTTONXSTART*2
  246.         mov         ecx, 100 * 65536 + 120
  247.         mov         edx, 0x14E1E1E1
  248.         mov         esi, 0x808899ff
  249.         mov         edi, title
  250.         mcall
  251.  
  252.         mov     edx, BUTTONCOUNT+1
  253.   .oloop:
  254.     push    edx
  255.     call    draw_obutton
  256.     pop     edx
  257.     dec     edx
  258.     cmp     edx, 1
  259.     jnz     .oloop
  260.  
  261.         mov     edx, BUTTONCOUNT+9
  262.   .tloop:
  263.     push    edx
  264.     call    draw_tbutton
  265.     pop     edx
  266.     dec     edx
  267.     cmp     edx, 9
  268.     jnz     .tloop
  269.  
  270.         mov         eax, 12
  271.         mov         ebx, 2
  272.         mcall
  273.         ret
  274.  
  275. redraw_obutton:
  276.         mov         eax, 8
  277.     push    edx
  278.         or          edx, 0x80 shl 24
  279.         mcall
  280.         pop         edx
  281. draw_obutton:
  282.         mov         ecx, edx
  283.         dec         ecx
  284.         dec         ecx
  285.         xor         ebx, ebx
  286.         mov         bl, [btn_state]
  287.         mov         bh, 1
  288.         shl         bh, cl
  289.         and         bl, bh
  290.         jz          .off
  291.         mov         esi, ONCOLOR
  292.         jmp         .aftercolor
  293.   .off:
  294.         mov         esi, OFFCOLOR
  295.   .aftercolor:
  296.         mov         bl, [btn_io]
  297.         and         bl, bh
  298.         jne     .output
  299.         or          edx, 1 shl 29
  300.   .output:
  301.         push    ecx
  302.         imul    bx, cx, word(BUTTONXSPACE+BUTTONXSIZE)
  303.         add         bx, BUTTONXSTART
  304.         imul    ebx, 65536
  305.         add         ebx, BUTTONXSIZE
  306.         mov         ecx, BUTTONYSTART*65536+BUTTONYSIZE
  307.         mcall   8
  308.         pop         ecx
  309.         xor         ebx, ebx
  310.         mov         bl, [btn_io]
  311.         mov         bh, 1
  312.         shl         bh, cl
  313.         and         bl, bh
  314.         jnz         .text
  315.         ret
  316.   .text:
  317.         mov         bl, [btn_state]
  318.         and         bl, bh
  319.         jz          .off_text
  320.         mov         edx, on_text
  321.         jmp         .aftertext
  322.   .off_text:
  323.         mov         edx, off_text
  324.   .aftertext:
  325.         imul    bx, cx, word(BUTTONXSPACE+BUTTONXSIZE)
  326.         add         bx, (BUTTONXSTART + (BUTTONXSIZE/2)-5)
  327.         shl         ebx, 16
  328.         add         ebx, BUTTONYSTART + (BUTTONYSIZE/2)
  329.         mcall   4,,1 shl 31
  330.         ret
  331.  
  332. draw_tbutton:
  333.         mov         ecx, edx
  334.         sub         ecx, 10
  335.         push    edx ecx
  336.         or          edx, 1 shl 31
  337.         mcall   8
  338.         xor         edi, edi
  339.         imul    di, cx, word(BUTTONXSPACE+BUTTONXSIZE)
  340.         push    edi
  341.         shl         edi, 16
  342.         mov         ebx, (BUTTONXSTART)*65536+BUTTONYSTART-12
  343.         add         ebx, edi
  344.         mcall   4,, 1 shl 31, i_text
  345.         mov         ebx, (BUTTONXSTART+5)*65536+BUTTONXSIZE-5*2
  346.         add         ebx, edi
  347.         mcall   13,, (BUTTONYSTART-13)*65536+9, 0xFFFFFF
  348.         mov         ebx, (BUTTONXSTART+BUTTONXSIZE-4)*65536+BUTTONYSTART-12
  349.         add         ebx, edi
  350.         mcall   4,, 1 shl 31, o_text
  351.         pop         edi ecx edx
  352.         mov         ebx, edi
  353.         add         ebx, (BUTTONXSTART+7)
  354.         mov         al, [btn_io]
  355.         mov         ah, 1
  356.         shl         ah, cl
  357.         and         al, ah
  358.         jz          .input
  359.         add         ebx, (BUTTONXSIZE-14)/2
  360.   .input:
  361.         shl         ebx, 16
  362.         add         ebx, (BUTTONXSIZE-14)/2
  363.         mcall   8,,(BUTTONYSTART-12)*65536+6,, 0x00576B8C
  364.         ret
  365.  
  366. ;  *********************************************
  367. ;  *************   DATA AREA   *****************
  368. ;  *********************************************
  369.  
  370. btn_state   db ?
  371. btn_io      db ?
  372. dev                 dd ?
  373. pid                     dd ?
  374. counter     dd ?
  375. drv_name    db 'usbother', 0
  376. off_text    db 'OFF', 0
  377. on_text     db 'ON', 0
  378. i_text      db 'I', 0
  379. o_text      db 'O', 0
  380. out_buf     rd 10
  381. in_buf      rd 10
  382. IOCTLs      rd 6
  383. thread_inf  rb 1024
  384. title       db "FT232 Control Center", 0
  385.  
  386. I_END: