Subversion Repositories Kolibri OS

Rev

Rev 6878 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
5558 hidnplayr 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                   ; 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               ; Clear bit 0
78
        call    write_gpio0
79
        jmp     event_wait
80
 
81
  @@:
82
        jmp     event_wait              ; Just read the key, ignore it and jump to event_wait.
83
 
84
button:                                 ; Buttonpress event handler
85
        mov     eax,17                  ; The button number defined in window_draw
86
        mcall                           ; is returned to ah.
87
 
88
        cmp     ah,1                    ; button id=1 ?
89
        jne     noclose
90
        mov     eax,-1                  ; Function -1 : close this program
91
        mcall
92
 
93
noclose:
94
        jmp     event_wait              ; This is for ignored events, useful at development
95
 
96
;  *********************************************
97
;  ******  WINDOW DEFINITIONS AND DRAW  ********
98
;  *********************************************
99
;
100
;  The static window parts are drawn in this function. The window canvas can
101
;  be accessed later from any parts of this code (thread) for displaying
102
;  processes or recorded data, for example.
103
;
104
;  The static parts *must* be placed within the fn 12 , ebx = 1 and ebx = 2.
105
 
106
draw_window:
107
        mov     eax, 12                 ; function 12: tell os about windowdraw
108
        mov     ebx, 1                  ; 1, start of draw
109
        mcall
110
 
111
        mov     eax, 0                  ; function 0 : define and draw window
112
        mov     ebx, 100 * 65536 + 300  ; [x start] *65536 + [x size]
113
        mov     ecx, 100 * 65536 + 120  ; [y start] *65536 + [y size]
114
        mov     edx, 0x14ffffff         ; color of work area RRGGBB
115
                                        ; 0x02000000 = window type 4 (fixed size, skinned window)
116
        mov     esi, 0x808899ff         ; color of grab bar  RRGGBB
117
                                        ; 0x80000000 = color glide
118
        mov     edi, title
119
        mcall
120
 
121
        mov     ebx, 25 * 65536 + 35    ; draw info text with function 4
122
        mov     ecx, 0x224466
123
        mov     edx, text
124
        mov     esi, 40
125
        mov     eax, 4
126
 
127
  .newline:                             ; text from the DATA AREA
128
        mcall
129
        add     ebx, 10
130
        add     edx, 40
131
        cmp     byte[edx], 0
132
        jne     .newline
133
 
134
        mov     eax, 12                 ; function 12:tell os about windowdraw
135
        mov     ebx, 2                  ; 2, end of draw
136
        mcall
137
 
138
        ret
139
 
140
; Read GPIO0 port to AL register
141
read_gpio0:
142
        mov     [IOCTL.io_code], 1
143
        mcall   68, 17, IOCTL
144
        ret
145
 
146
; Write AL register to GPIO0 port
147
write_gpio0:
148
        mov     [IOCTL.io_code], 2
149
        mov     [IOCTL.input], eax
150
        mcall   68, 17, IOCTL
151
        ret
152
 
153
;  *********************************************
154
;  *************   DATA AREA   *****************
155
;  *********************************************
156
;
157
; Data can be freely mixed with code to any parts of the image.
158
; Only the header information is required at the beginning of the image.
159
 
160
text    db  "This is an 86DUINO GPIO demo program    "
161
        db  "                                        "
162
        db  "press q/w to toggle GPIO 0 pin 0        ", 0
163
 
164
title   db  "86Duino Example application", 0
165
 
166
drv_name        db '86DUINO-GPIO', 0
167
 
168
IOCTL:
169
   .handle      dd ?
170
   .io_code     dd ?
171
   .input       dd ?
172
   .inp_size    dd ?
173
   .output      dd ?
174
   .out_size    dd ?
175
 
176
I_END: