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