Subversion Repositories Kolibri OS

Rev

Rev 6878 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2. ;                                                  ;
  3. ;    86DUINO GPIO DEMO APPLICATION                 ;
  4. ;                                                  ;
  5. ;      Compile with FASM                           ;
  6. ;                                                  ;
  7. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  8.  
  9. format binary as ""                     ; Binary file format without extension
  10.  
  11. use32                                   ; Tell compiler to use 32 bit instructions
  12.  
  13. org 0x0                                 ; the base address of code, always 0x0
  14.  
  15. ; The header
  16.  
  17. db 'MENUET01'
  18. dd 0x01
  19. dd START
  20. dd I_END
  21. dd 0x100000
  22. dd 0x7fff0
  23. dd 0, 0
  24.  
  25. ; The code area
  26.  
  27. include '../../macros.inc'
  28.  
  29. START:                                  ; start of execution
  30.  
  31.         mcall   68, 16, drv_name        ; load the driver
  32.         mov     [IOCTL.handle], eax
  33.  
  34.         call    draw_window             ; draw the window
  35.  
  36. ; After the window is drawn, it's practical to have the main loop.
  37. ; Events are distributed from here.
  38.  
  39. event_wait:
  40.         mov     eax, 10                 ; function 10 : wait until event
  41.         mcall                           ; event type is returned in eax
  42.  
  43.         cmp     eax, 1                  ; Event redraw request ?
  44.         je      red                     ; Expl.: there has been activity on screen and
  45.                                         ; parts of the applications has to be redrawn.
  46.  
  47.         cmp     eax, 2                  ; Event key in buffer ?
  48.         je      key                     ; Expl.: User has pressed a key while the
  49.                                         ; app is at the top of the window stack.
  50.  
  51.         cmp     eax, 3                  ; Event button in buffer ?
  52.         je      button                  ; Expl.: User has pressed one of the
  53.                                         ; applications buttons.
  54.  
  55.         jmp     event_wait
  56.  
  57. ;  The next section reads the event and processes data.
  58.  
  59. red:                                    ; Redraw event handler
  60.         call    draw_window             ; We call the window_draw function and
  61.         jmp     event_wait              ; jump back to event_wait
  62.  
  63. key:                                    ; Keypress event handler
  64.         mov     eax, 2                  ; The key is returned in ah. The key must be
  65.         mcall                           ; read and cleared from the system queue.
  66.  
  67.         cmp     ah, 'q'
  68.         jne     @f
  69.         call    read_gpio0
  70.         or      al, 1 shl 0             ; Set bit 0
  71.         call    write_gpio0
  72.         jmp     event_wait
  73.   @@:
  74.         cmp     ah, 'w'
  75.         jne     @f
  76.         call    read_gpio0
  77.         and     al, not (1 shl 0)       ; Clear bit 0
  78.         call    write_gpio0
  79.         jmp     event_wait
  80.   @@:
  81.         cmp     ah, 'e'
  82.         jne     @f
  83.         call    read_adc0
  84.         mov     ecx, eax
  85.         mcall   47, 0x00040100,,25 shl 16 + 25, 0x40000000, 0x00ffffff          ; 4 digits hex number in ecx
  86.         jmp     event_wait
  87.   @@:
  88.         cmp     ah, 'a'
  89.         jne     @f
  90.         call    read_gpio0
  91.         or      al, 1 shl 2             ; Set bit 2
  92.         call    write_gpio0
  93.         jmp     event_wait
  94.   @@:
  95.         cmp     ah, 's'
  96.         jne     @f
  97.         call    read_gpio0
  98.         and     al, not (1 shl 2)       ; Clear bit 2
  99.         call    write_gpio0
  100.         jmp     event_wait
  101.   @@:
  102.         jmp     event_wait              ; Just read the key, ignore it and jump to event_wait.
  103.  
  104. button:                                 ; Buttonpress event handler
  105.         mov     eax, 17                 ; The button number defined in window_draw
  106.         mcall                           ; is returned to ah.
  107.  
  108.         cmp     ah, 1                   ; button id=1 ?
  109.         jne     noclose
  110.         mov     eax, -1                 ; Function -1 : close this program
  111.         mcall
  112.  
  113. noclose:
  114.         jmp     event_wait              ; This is for ignored events, useful at development
  115.  
  116. ;  *********************************************
  117. ;  ******  WINDOW DEFINITIONS AND DRAW  ********
  118. ;  *********************************************
  119. ;
  120. ;  The static window parts are drawn in this function. The window canvas can
  121. ;  be accessed later from any parts of this code (thread) for displaying
  122. ;  processes or recorded data, for example.
  123. ;
  124. ;  The static parts *must* be placed within the fn 12 , ebx = 1 and ebx = 2.
  125.  
  126. draw_window:
  127.         mov     eax, 12                 ; function 12: tell os about windowdraw
  128.         mov     ebx, 1                  ; 1, start of draw
  129.         mcall
  130.  
  131.         mov     eax, 0                  ; function 0 : define and draw window
  132.         mov     ebx, 100 * 65536 + 300  ; [x start] *65536 + [x size]
  133.         mov     ecx, 100 * 65536 + 120  ; [y start] *65536 + [y size]
  134.         mov     edx, 0x14ffffff         ; color of work area RRGGBB
  135.                                         ; 0x02000000 = window type 4 (fixed size, skinned window)
  136.         mov     esi, 0x808899ff         ; color of grab bar  RRGGBB
  137.                                         ; 0x80000000 = color glide
  138.         mov     edi, title
  139.         mcall
  140.  
  141.         mov     ebx, 25 * 65536 + 35    ; draw info text with function 4
  142.         mov     ecx, 0x224466
  143.         mov     edx, text
  144.         mov     esi, 40
  145.         mov     eax, 4
  146.  
  147.   .newline:                             ; text from the DATA AREA
  148.         mcall
  149.         add     ebx, 10
  150.         add     edx, 40
  151.         cmp     byte[edx], 0
  152.         jne     .newline
  153.  
  154.         mov     eax, 12                 ; function 12:tell os about windowdraw
  155.         mov     ebx, 2                  ; 2, end of draw
  156.         mcall
  157.  
  158.         ret
  159.  
  160. ; Read GPIO0 port to AL register
  161. read_gpio0:
  162.         mov     [IOCTL.io_code], 1
  163.         mcall   68, 17, IOCTL
  164.         ret
  165.  
  166. ; Write AL register to GPIO0 port
  167. write_gpio0:
  168.         mov     [IOCTL.io_code], 2
  169.         mov     [IOCTL.input], eax
  170.         mcall   68, 17, IOCTL
  171.         ret
  172.  
  173. ; Read ADC0
  174. read_adc0:
  175.         mov     [IOCTL.io_code], 3
  176.         mcall   68, 17, IOCTL
  177.         ret
  178.  
  179. ;  *********************************************
  180. ;  *************   DATA AREA   *****************
  181. ;  *********************************************
  182. ;
  183. ; Data can be freely mixed with code to any parts of the image.
  184. ; Only the header information is required at the beginning of the image.
  185.  
  186. text    db  "This is an 86DUINO GPIO demo program    "
  187.         db  "                                        "
  188.         db  "press q/w to toggle GPIO 0 pin 0        "
  189.         db  "or e to read ADC0 channel               ", 0
  190.  
  191. title   db  "86Duino Example application", 0
  192.  
  193. drv_name        db '86DUINO-GPIO', 0
  194.  
  195. IOCTL:
  196.    .handle      dd ?
  197.    .io_code     dd ?
  198.    .input       dd ?
  199.    .inp_size    dd ?
  200.    .output      dd ?
  201.    .out_size    dd ?
  202.  
  203. I_END: