Mercurial > public > hwos_code
comparison src/menu_processor.asm @ 634:4050675965ea
3.10 stable release
author | heinrichsweikamp |
---|---|
date | Tue, 28 Apr 2020 17:34:31 +0200 |
parents | 185ba2f91f59 |
children | 8c1f1f334275 |
comparison
equal
deleted
inserted
replaced
633:690c48db7b5b | 634:4050675965ea |
---|---|
1 ;============================================================================= | 1 ;============================================================================= |
2 ; | 2 ; |
3 ; File menu_processor.asm combined next generation V3.08.6 | 3 ; File menu_processor.asm * combined next generation V3.09.5 |
4 ; | 4 ; |
5 ; Routines to handle all hwOS graphic/text menus. | 5 ; Routines to handle all hwOS graphic/text menus. |
6 ; | 6 ; |
7 ; Copyright (c) 2011, JD Gascuel, HeinrichsWeikamp, all right reserved. | 7 ; Copyright (c) 2011, JD Gascuel, HeinrichsWeikamp, all right reserved. |
8 ;============================================================================= | 8 ;============================================================================= |
22 #include "eeprom_rs232.inc" | 22 #include "eeprom_rs232.inc" |
23 #include "adc_lightsensor.inc" | 23 #include "adc_lightsensor.inc" |
24 #include "i2c.inc" | 24 #include "i2c.inc" |
25 #include "rtc.inc" | 25 #include "rtc.inc" |
26 #include "wait.inc" | 26 #include "wait.inc" |
27 #include "colorschemes.inc" | |
27 | 28 |
28 | 29 |
29 ; NOTE: needs to be identical in .inc and .asm ! | 30 ; NOTE: needs to be identical in .inc and .asm ! |
31 ; | |
30 #define MENU_LINES_MAX .7 ; maximum number of lines per screen | 32 #define MENU_LINES_MAX .7 ; maximum number of lines per screen |
31 #define MENU_TITLE_FONT WIN_STD ; font needs to contain lower and UPPER chars | |
32 #define MENU_LINE_FONT WIN_SMALL ; font needs to contain lower and UPPER chars | |
33 #define MENU_LEFT .20 ; position of first menu item | 33 #define MENU_LEFT .20 ; position of first menu item |
34 #define MENU_HEIGHT .27 ; spacing between menu lines | 34 #define MENU_HEIGHT_SURF .27 ; spacing between menu item in surface mode (pixel) |
35 #define MENU_HEIGHT_DIVE .24 ; spacing between menu item in surface mode (pixel) | |
35 #define MENU_VCENTER .125 ; position on screen | 36 #define MENU_VCENTER .125 ; position on screen |
36 #define MENU_LINE_MAX_LENGTH .20 ; length in characters | 37 #define MAX_LINE_LENGTH_TITLE .17 ; max menu title length (characters) |
37 #define option_item proc_item | 38 #define MAX_LINE_LENGTH_SURF .20 ; max menu item length in surface menu (characters) |
38 | 39 #define MAX_LINE_LENGTH_DIVE .10 ; max menu item length in dive mode menu (characters) |
39 | 40 #define MENU_ITEM_DATA_SIZE .4 ; size of a menu item data block |
40 extern aa_wordprocessor | 41 |
42 ; Alias for easier code reading | |
43 #define option_addr item_funct_addr | |
44 | |
45 | |
46 extern option_adjust_group_member | |
41 extern option_inc | 47 extern option_inc |
48 extern option_dec | |
42 extern option_draw | 49 extern option_draw |
43 extern TFT_clear_divemode_menu | 50 |
44 extern TFT_divemask_color | |
45 extern rtc_set_rtc | 51 extern rtc_set_rtc |
46 extern divemode_option_divemenu_return | 52 extern divemode_option_divemenu_return |
47 extern TFT_fillup_with_spaces | 53 |
48 | 54 |
49 | 55 ;============================================================================= |
50 menu_proc CODE | 56 menu_proc CODE |
51 | |
52 ;============================================================================= | 57 ;============================================================================= |
53 ; menu handler | 58 |
54 ; | 59 |
55 ; Input: TBLPTR = addr of menu block | 60 ;----------------------------------------------------------------------------- |
56 | 61 ; Entry Point for Menu Processor, called by MENU_BEGIN Macros |
62 ; | |
57 global menu_processor | 63 global menu_processor |
58 menu_processor: | 64 menu_processor: |
59 ; btfss divemode ; in dive mode? | 65 ; read menu header |
60 ; call request_speed_fastest ; NO - request CPU speed change to fastest speed | 66 VARARGS_BEGIN ; load TBLPTR with start address of the menu header data |
61 ;---- Read menu block ------------------------------------------------ | |
62 VARARGS_BEGIN ; read inline PROM data | |
63 clrf STKPTR ; never return from here | 67 clrf STKPTR ; never return from here |
64 VARARGS_GET8 item_max ; get number of items | 68 |
65 VARARGS_GET8 menu_flags ; get flags | 69 VARARGS_GET8 menu_item_count ; get number of items |
66 VARARGS_GET24 menu_title ; get pointer to menu title | 70 VARARGS_GET8 menu_vertical_start ; get vertical start position of 1st menu item |
67 VARARGS_GET8 menu_center ; vertical position | 71 |
68 movff TBLPTRL, menu_block+0 ; save base address for menu_read_item | 72 movf menu_vertical_start,W ; excite flags |
69 movff TBLPTRH, menu_block+1 ; ... | 73 bz menu_processor_no_title ; no menu title text -> skip reading menu title text address |
70 movff TBLPTRU, menu_block+2 ; ... | 74 |
75 VARARGS_GET16 menu_title_addr ; get address of menu title text | |
76 | |
77 menu_processor_no_title: | |
78 | |
79 movff TBLPTRL, menu_item_data_start+0 ; store base address for menu_read_menu_item_data | |
80 movff TBLPTRH, menu_item_data_start+1 ; ... | |
81 movff TBLPTRU, menu_item_data_start+2 ; ... | |
82 | |
71 btfss divemode ; in dive mode? | 83 btfss divemode ; in dive mode? |
72 bra menu_processor0 ; NO | 84 bra menu_processor_menu_title ; NO - no frame in surface mode menu |
73 | 85 |
74 ; Required for menus with less entries than the calling menu but not so nice when setting up gas 6.... mH | 86 ; required for menus with less entries than the calling menu but not so nice when setting up gas 6.... mH |
75 movlw .1 | 87 movlw .1 ; menu_pos_cur = 1 ? |
76 cpfsgt menu_pos_cur ; only if menu_pos_cur = 1... | 88 cpfsgt menu_pos_cur ; ... |
77 call TFT_clear_divemode_menu ; ... clear the menu! | 89 call TFT_clear_divemode_menu ; YES - clear the menu |
78 ; Draw one frame around the dive mode menu | 90 |
79 call TFT_divemask_color | 91 ; draw a frame around the dive mode menu |
80 WIN_FRAME_COLOR16 dm_menu_row, dm_menu_lower, dm_menu_left ,dm_menu_right ; top, bottom, left, right | 92 movf pallet_color_mask,W ; get mask color into WREG |
81 call TFT_standard_color | 93 WIN_FRAME_COLOR dm_menu_row, dm_menu_lower, dm_menu_left ,dm_menu_right ; top, bottom, left, right |
82 | 94 bra menu_processor_menu_body ; the dive mode menu has no menu title and footer |
83 bra menu_processor1 ; skip next code segment in dive mode | 95 |
84 | 96 menu_processor_menu_title: |
85 menu_processor0: | 97 ; prepare screen |
86 ;---- draw menu title ------------------------------------------------ | |
87 clrf CCP1CON ; stop PWM | 98 clrf CCP1CON ; stop PWM |
88 bcf PORTC,2 ; pull PWM out to GND | 99 bcf PORTC,2 ; fade out backlight |
89 call TFT_ClearScreen | 100 call TFT_ClearScreen ; clear screen |
90 rcall menu_processor_title | 101 |
91 rcall menu_processor_bottom_line | 102 ; draw menu title |
92 | 103 WIN_BOX_BLACK .2,.23,.0,.159 ; clear menu title area |
93 menu_processor1: | 104 WIN_STD .0, .2 ; set menu title font and position |
94 WIN_FONT FT_SMALL | 105 FONT_COLOR color_greenish ; set menu title font color |
95 | 106 movff menu_title_addr+0,FSR1L ; point to multi-lingual menu title text |
96 ;---- Select menu type ----------------------------------------------- | 107 movff menu_title_addr+1,FSR1H ; ... |
97 bra menu_vertical | 108 call strcpy_text_FSR ; copy translated text into the buffer |
98 | 109 movf FSR2L,W ; get title text length |
99 | 110 mullw .9 ; compute title length in pixels_x2 |
100 ;============================================================================= | 111 bcf STATUS,C ; divide by 2 |
101 ; draw menu bottom line | 112 rrcf PRODL ; ... |
102 ; | 113 movf PRODL,W ; get result into WREG |
103 menu_processor_bottom_line: | 114 sublw .80 ; compute 80 (screen center position) - half title width in pixel_x2 |
104 ;---- Draw bottom line ----------------------------------------------- | 115 movwf win_leftx2 ; set result as horizontal start position |
105 TEXT_TINY .5, .240-.16, tNext | 116 movlw MAX_LINE_LENGTH_TITLE ; load max allowed length of a menu title |
106 TEXT_TINY .160-.6*.6, .240-.16, tEnter | 117 movwf FSR2L ; set buffer pointer to end of max length |
107 goto TFT_standard_color ; ...and return | 118 clrf INDF2 ; terminate string at max length |
108 | 119 PRINT ; output menu title |
109 ;============================================================================= | 120 |
110 ; (re-)draw menu title | 121 ; draw footer line |
111 ; | 122 FONT_COLOR_MEMO ; select default color |
112 menu_processor_title: | 123 WIN_TINY .5, .224 ; tiny font, left position |
113 WIN_BOX_BLACK .2,.23,.0,.159 ; clear menu title | 124 STRCPY_TEXT_PRINT tNext ; print "Next" |
114 MENU_TITLE_FONT .0, .2 ; menu title positioning | 125 WIN_TINY .124, .224 ; tiny font, righ position |
115 btfss menu_flags,0 ; static or dynamic title? | 126 STRCPY_TEXT_PRINT tEnter ; print "Enter" |
116 bra menu_processor_static_title ; static title | 127 |
117 rcall menu_processor_call_title ; dynamic title - add gas, detail and color | 128 menu_processor_menu_body: |
118 bra menu_processor_title_1 | 129 FONT_SIZE FT_SMALL ; select font size |
119 | 130 bra menu_vertical ; draw the menu items |
120 menu_processor_static_title: | 131 |
121 movff menu_title+0,FSR1L ; just copy string | 132 |
122 movff menu_title+1,FSR1H | 133 ;----------------------------------------------------------------------------- |
123 call strcpy_text | 134 ; Helper Function - call Callback-Function to draw the Menu Item Title |
124 | 135 ; |
125 menu_processor_title_1: | |
126 WIN_COLOR color_greenish | |
127 movf FSR2L,W ; get title length | |
128 mullw .9 ; convert to half pixels | |
129 bcf STATUS,C ; clear carry | |
130 rrcf PRODL ; /2 | |
131 movf PRODL,W ; back to WREG | |
132 sublw .80 ; 80 - width | |
133 movwf win_leftx2 ; aligned to center | |
134 movlw .0 ; string termination code | |
135 movff WREG,buffer+.17 ; limit to 17 chars (std font max.) | |
136 call aa_wordprocessor | |
137 call TFT_standard_color | |
138 return | |
139 | |
140 ;============================================================================= | |
141 ; Call dynamic proc for menu title: | |
142 | |
143 menu_processor_call_title: | 136 menu_processor_call_title: |
144 movff menu_title+2,PCLATU ; execute computed goto | 137 movff menu_title_addr+2,PCLATU ; execute computed goto |
145 movff menu_title+1,PCLATH | 138 movff menu_title_addr+1,PCLATH ; ... |
146 movf menu_title+0,W | 139 movf menu_title_addr+0,W ; ... |
147 movwf PCL | 140 movwf PCL ; ... |
148 | 141 |
149 ;============================================================================= | 142 |
150 ; Restart with first icon/line selected | 143 ;----------------------------------------------------------------------------- |
144 ; Clear all memorized Menu Item Selections and restart with Cursor on first Item | |
151 ; | 145 ; |
152 global menu_processor_reset | 146 global menu_processor_reset |
153 menu_processor_reset: | 147 menu_processor_reset: |
154 clrf menustack ; clear first stack position | 148 clrf menustack ; clear first stack position |
155 clrf menustack_pointer ; set stack pointer to first stack position | 149 clrf menustack_pointer ; set stack pointer to first stack position |
156 clrf selected_item ; set last menu item to first item | 150 clrf selected_item ; set cursor position to first menu item |
157 return | 151 return ; done |
158 | 152 |
159 | 153 |
154 ;----------------------------------------------------------------------------- | |
155 ; Pull / Double-Pull Cursor Position from Stack | |
156 ; | |
160 global menu_processor_double_pop | 157 global menu_processor_double_pop |
161 global menu_processor_pop | 158 global menu_processor_pop |
162 menu_processor_double_pop: | 159 menu_processor_double_pop: |
163 decf menustack_pointer,F ; decrement stack pointer | 160 decf menustack_pointer,F ; decrement stack pointer |
164 menu_processor_pop: | 161 menu_processor_pop: |
165 decf menustack_pointer,F ; decrement stack pointer | 162 decf menustack_pointer,F ; decrement stack pointer |
166 btfsc menustack_pointer,7 ; did the stack pointer under-run? | 163 btfsc menustack_pointer,7 ; did the stack pointer under-run? |
167 clrf menustack_pointer ; YES - reset stack pointer to first stack position | 164 clrf menustack_pointer ; YES - reset stack pointer to first stack position |
168 movf menustack_pointer,W ; load stack pointer into WREG | 165 movf menustack_pointer,W ; load stack pointer into WREG |
169 lfsr FSR2,menustack ; load base address of menu stack | 166 lfsr FSR2,menustack ; load base address of menu stack |
170 movff PLUSW2,selected_item ; retrieve menu item from stack | 167 movff PLUSW2,selected_item ; retrieve cursor position from stack |
171 return ; done | 168 return ; done |
172 | 169 |
173 | 170 |
171 ;----------------------------------------------------------------------------- | |
172 ; Push Cursor Position onto Stack | |
173 ; | |
174 menu_processor_push: | 174 menu_processor_push: |
175 lfsr FSR2,menustack ; load base address of menu stack | 175 lfsr FSR2,menustack ; load base address of menu stack |
176 movf menustack_pointer,W ; load stack pointer into WREG | 176 movf menustack_pointer,W ; load stack pointer into WREG |
177 movff selected_item,PLUSW2 ; save menu item to stack | 177 movff selected_item,PLUSW2 ; save cursor position to stack |
178 incf menustack_pointer,W ; increment stack pointer, park result in WREG | 178 incf menustack_pointer,W ; increment stack pointer, park result in WREG |
179 btfss WREG,3 ; result < 8 ? | 179 btfss WREG,3 ; result < 8 ? |
180 movwf menustack_pointer ; YES - update stack pointer | 180 movwf menustack_pointer ; YES - update stack pointer |
181 clrf selected_item ; set to first item in new menu | 181 clrf selected_item ; set cursor to first item in new menu |
182 return ; done | 182 return ; done |
183 | 183 |
184 | 184 |
185 ;---- Execute menu selection ------------------------------------------------- | 185 ;----------------------------------------------------------------------------- |
186 do_menu_item: | 186 ; Helper Function - call Menu Item Function |
187 bcf switch_right ; clear left-over button event | 187 ; |
188 movf selected_item,W ; reread proc address from table | 188 menu_call_item_function: |
189 rcall menu_read_item ; (destroys PROD) | 189 bcf switch_right ; clear button event |
190 movff selected_item,PRODL ; pass along selected line | 190 movf selected_item,W ; copy current cursor position to WREG |
191 rcall menu_processor_push ; remember where we got from (clears selected_item) | 191 rcall menu_read_menu_item_data ; read item function address |
192 movff proc_item+2,PCLATU ; then execute computed goto | 192 movff selected_item,PRODL ; pass cursor position (menu item number) to call function |
193 movff proc_item+1,PCLATH | 193 rcall menu_processor_push ; push current cursor position onto stack |
194 movf proc_item+0,W | 194 clrf PCLATU ; execute computed goto |
195 movwf PCL | 195 movff item_funct_addr+1,PCLATH ; ... |
196 | 196 movf item_funct_addr+0,W ; ... |
197 ;============================================================================= | 197 movwf PCL ; ... |
198 ; Get current item from table. | 198 |
199 ; | 199 |
200 ; Input : Item number in WREG, menu_block. | 200 ;----------------------------------------------------------------------------- |
201 ; Output : icon_large, text_item, proc_item 16bits pointers. | 201 ; Read Menu Item Data |
202 ; Trashed: PROD, WREG | 202 ; |
203 ; | 203 menu_read_menu_item_data: |
204 menu_read_item: | 204 cpfsgt menu_item_count ; selected menu item valid? || * Safety Check * to prevent any computed |
205 mullw .10 ; 10 bytes per item | 205 clrf WREG ; NO - change selection to first item || goto to an illegal random target address |
206 movf PRODL,W ; then do a 24 bits add | 206 |
207 addwf menu_block+0,W ; with menu_block, and | 207 mullw MENU_ITEM_DATA_SIZE ; compute menu item data offset |
208 movwf TBLPTRL ; setup TBLPTR | 208 movf PRODL,W ; add offset to base address of menu data block and set up TBLPTR |
209 movf PRODH,W | 209 addwf menu_item_data_start+0,W ; ... |
210 addwfc menu_block+1,W | 210 movwf TBLPTRL ; ... |
211 movwf TBLPTRH | 211 movf PRODH,W ; ... |
212 movlw 0 | 212 addwfc menu_item_data_start+1,W ; ... |
213 addwfc menu_block+2,W | 213 movwf TBLPTRH ; ... |
214 movwf TBLPTRU | 214 movlw 0 ; ... |
215 VARARGS_GET8 value_type ; read 10 bytes of item data | 215 addwfc menu_item_data_start+2,W ; ... |
216 VARARGS_GET24 dynamic_item | 216 movwf TBLPTRU ; ... |
217 VARARGS_GET24 proc_item | 217 |
218 VARARGS_GET8 WREG ; skip dummy byte | 218 VARARGS_GET16 item_title_addr ; read address of item title function or title text | with embedded |
219 VARARGS_GET16 text_item | 219 VARARGS_GET16 item_funct_addr ; read address of item call function or option definition data | menu item type |
220 | 220 |
221 return | 221 movlw .2 ; probe for menu item type = OPTION |
222 | 222 btfsc item_funct_addr,0 ; is type OPTION? |
223 ;============================================================================= | 223 bra menu_read_menu_item_data_1 ; YES |
224 ; Vertical menu - set of line/value to choose from, | 224 |
225 ; entry point to update lines already shown | 225 movlw .1 ; probe for menu item type = MENU_CALL |
226 btfsc item_title_addr,0 ; is type MENU_CALL? | |
227 bra menu_read_menu_item_data_1 ; YES | |
228 | |
229 movlw .0 ; must be MENU_DYNAMIC | |
230 | |
231 menu_read_menu_item_data_1: | |
232 movwf item_type ; store menu item type | |
233 bcf item_title_addr+0,0 ; strip menu item type encoding from addresses (reset to even addresses) | |
234 bcf item_funct_addr+0,0 ; ... | |
235 | |
236 return ; done | |
237 | |
238 | |
239 ;----------------------------------------------------------------------------- | |
240 ; Menu HMI Operation | |
226 ; | 241 ; |
227 global menu_vertical | 242 global menu_vertical |
228 menu_vertical: | 243 menu_vertical: |
229 rcall menu_draw_lines ; always re-draw whole menu | 244 rcall menu_draw_menu_items ; draw all menu items |
230 movlw CCP1CON_VALUE ; see hwos.inc | 245 movlw CCP1CON_VALUE ; load PWM setting |
231 btfss divemode ; in dive mode? | 246 btfss divemode ; in dive mode? |
232 movwf CCP1CON ; NO - power-on backlight | 247 movwf CCP1CON ; NO - power-on backlight |
233 | 248 |
234 menu_vertical_1: | 249 menu_vertical_loop: |
235 movf selected_item,W ; copy current menu item selection to WREG | 250 movf selected_item,W ; get cursor position into WREG |
236 rcall menu_read_item ; get current menu item data | 251 rcall menu_read_menu_item_data ; read menu item data |
237 movf proc_item+0,W ; check if proc address is NULL | 252 movf item_funct_addr+0,W ; check if execute function call address is NULL |
238 iorwf proc_item+1,W | 253 iorwf item_funct_addr+1,W ; ... |
239 bz next_line_menu ; YES - not selectable | 254 bz next_line_menu ; YES - not selectable, step cursor to next menu item |
240 btfss divemode ; in dive mode? | 255 btfss divemode ; NO - in dive mode? |
241 rcall menu_draw_selected_line ; NO | 256 rcall menu_draw_cursor_surf ; NO - draw the cursor (main menu style) |
242 btfss imprint_time_date ; currently imprinting the current time & date? | 257 btfss imprint_time_date ; - currently imprinting the current time & date? |
243 bra menu_line_loop_pre1 ; NO | 258 bra menu_line_loop_pre1 ; NO - skip |
244 btfss switch_right ; YES - right button pressed, i.e. time or date changed? | 259 btfss switch_right ; YES - right button pressed, i.e. time or date changed? |
245 bra menu_line_loop_pre1 ; NO | 260 bra menu_line_loop_pre1 ; NO - skip |
246 call TFT_show_time_date_menu_fast ; YES - show a fast response on the screen (may momentarily show an illegal day/month combination) | 261 call TFT_imprint_time_date_fast ; YES - show a fast response on the screen (may momentarily show an illegal day/month combination) |
247 call rtc_set_rtc ; - update time and date on RTC module (corrects illegal day/month combinations) | 262 call rtc_set_rtc ; - update time and date on RTC module (corrects illegal day/month combinations) |
248 | 263 |
249 menu_line_loop_pre1: | 264 menu_line_loop_pre1: |
250 btfsc imprint_color_schemes ; in the color scheme menu? | |
251 call TFT_show_color_schemes ; YES - update the color schemes | |
252 | |
253 menu_line_loop_pre2: | |
254 bcf switch_right ; clear left-over right button event | 265 bcf switch_right ; clear left-over right button event |
255 bcf switch_left ; clear left-over left button event | 266 bcf switch_left ; clear left-over left button event |
256 | 267 |
257 menu_line_loop_pre3: | 268 menu_line_loop_pre2: |
258 btfsc divemode ; in dive mode? | 269 btfsc divemode ; in dive mode? |
259 goto divemode_option_divemenu_return ; YES - return to it | 270 goto divemode_option_divemenu_return ; YES - return to it |
260 ;bra menu_line_loop_surface ; NO - proceed to surface mode dispatcher | 271 call reset_timeout_surfmode ; NO - reset timeout |
261 | 272 |
262 ; dispatcher for surface mode menus | |
263 menu_line_loop_surface: | |
264 call reset_timeout_surfmode ; reset timeout | |
265 menu_line_loop: | 273 menu_line_loop: |
266 call housekeeping ; handle data imprinting, screen dump request, timeout and entering dive mode | 274 call housekeeping ; - handle data imprinting, screen dump request, timeout and entering dive mode |
267 btfsc switch_right ; right button pressed? | 275 btfsc switch_right ; - right button pressed? |
268 bra do_line_menu ; YES - type dependent | 276 bra do_line_menu ; YES - execute menu item function |
269 btfsc switch_left ; left button pressed? | 277 btfss switch_left ; NO - left button pressed? |
270 bra next_line_menu ; YES - goto next item | 278 bra menu_line_loop ; NO - loop |
271 bra menu_line_loop ; NO to both - loop | 279 next_line_menu: ; YES - step cursor to next menu item |
272 | 280 bcf switch_left ; - clear button event |
273 | 281 incf selected_item,F ; - increment cursor position to next item |
274 ;---- Move to menu's next line | 282 movf selected_item,W ; - copy new item number to WREG |
275 next_line_menu: | 283 cpfseq menu_item_count ; - new item number beyond number of menu items? |
276 bcf switch_left ; clear button event | 284 bra menu_vertical_loop ; NO - redraw cursor |
277 incf selected_item,F ; select next item | 285 clrf selected_item ; YES - reset cursor position to first item |
278 movf selected_item,W ; copy item number to WREG | 286 bra menu_vertical_loop ; - redraw cursor |
279 cpfseq item_max ; item number == max ? | 287 |
280 bra menu_vertical_1 ; NO - redraw cursor | 288 |
281 clrf selected_item ; YES - wrap-around to first item | 289 ;----------------------------------------------------------------------------- |
282 bra menu_vertical_1 ; then redraw cursor | 290 ; Execute Menu Item Function |
283 | 291 ; |
284 global do_line_menu | 292 global do_line_menu |
285 do_line_menu: | 293 do_line_menu: |
286 decf menu_pos_cur,W ; menu_processor needs 0-5 | 294 decf menu_pos_cur,W ; get selected menu item (0-5) into WREG |
287 btfsc divemode ; in dive mode? | 295 btfsc divemode ; in dive mode? |
288 movwf selected_item ; YES - set selected item from WREG | 296 movwf selected_item ; YES - take selected menu item from dive mode |
289 movf selected_item,W ; read selected descriptor | 297 movf selected_item,W ; copy selected menu item to WREG |
290 rcall menu_read_item | 298 rcall menu_read_menu_item_data ; read menu item data |
291 movf value_type,W ; switch on data type | 299 movf item_type,W ; switch on menu item type |
292 bz menu_do_line_call ; CALL | 300 bz menu_do_line_call ; -> 0: call (with dynamic title) |
293 dcfsnz WREG | 301 dcfsnz WREG ; |
294 bra menu_do_line_call ; STRING: do as call | 302 bra menu_do_line_call ; -> 1: call (with fixed title) |
295 dcfsnz WREG | 303 dcfsnz WREG ; |
296 bra menu_do_line_option ; OPTION | 304 bra menu_do_line_option ; -> 2: option |
297 dcfsnz WREG | 305 bra menu_line_loop_pre2 ; else do nothing |
298 bra menu_do_line_call ; DYNAMIC: do as call | 306 |
299 bra menu_line_loop_pre3 ; else do nothing | |
300 | |
301 ;---- CALL | |
302 menu_do_line_call: | 307 menu_do_line_call: |
303 rcall do_menu_item ; same as icon menu: calculated goto | 308 rcall menu_call_item_function ; push current cursor position onto stack and call menu item function |
304 rcall menu_processor_pop ; back to same line, | 309 rcall menu_processor_pop ; get back cursor position |
305 bra menu_vertical ; then continue into menu... | 310 bra menu_vertical ; re-draw the menu |
306 | 311 |
307 ;---- Call option specific increment subroutine | |
308 menu_do_line_option: | 312 menu_do_line_option: |
309 movff option_item+0,FSR0L ; get option handle | 313 movff option_addr+0,FSR0L ; get address of option definition data |
310 movff option_item+1,FSR0H | 314 movff option_addr+1,FSR0H ; ... |
311 call option_inc ; increment | 315 btfsc option_addr+1,4 ; shall stop at max value? |
312 movff selected_item,PRODL ; pass selection to callback | 316 bsf option_stop_at_max ; YES - set flag |
313 rcall menu_text_call | 317 btfsc option_addr+1,6 ; is the selected option an option group member? |
314 bra menu_vertical ; redraw all lines | 318 call option_adjust_group_member ; YES - adjust address to selected group member |
315 | 319 btfss option_addr+1,5 ; shall increment? |
316 ;----------------------------------------------------------------------------- | 320 call option_inc ; YES - increment option value |
317 | 321 btfsc option_addr+1,5 ; shall decrement? |
318 global menu_draw_lines_divemode ; entry point for re-drawing of the menu to update color-coding of gases | 322 call option_dec ; YES - decrement option value |
323 bcf option_stop_at_max ; revert to default (= wrap-around after max value) | |
324 bra menu_vertical ; re-draw the menu | |
325 | |
326 | |
327 ;----------------------------------------------------------------------------- | |
328 ; Draw all Menu Items | |
329 ; | |
330 menu_draw_menu_items: | |
331 btfss divemode ; in dive mode? | |
332 bra menu_draw_lines_surfmode ; NO | |
333 ;bra menu_draw_lines_divemode ; YES | |
334 | |
335 global menu_draw_lines_divemode | |
319 menu_draw_lines_divemode: | 336 menu_draw_lines_divemode: |
320 movlw dm_menu_item1_row | 337 movlw dm_menu_item1_row ; get row position for 1st item |
321 movff WREG,win_top | 338 movwf win_top ; set vertical output position |
322 movlw dm_menu_item1_column | 339 movlw dm_menu_item1_column ; get column position for 1st item |
323 movff WREG,win_leftx2 | 340 movwf win_leftx2 ; set horizontal output position |
324 clrf start_item | 341 clrf menu_item_start ; set first item in menu block as first item to draw |
325 movff item_max,menu_pos_max ; copy item_max for dive mode cursor routine | 342 movff menu_item_count,menu_pos_max ; copy number of item in menu block to menu_pos_max |
326 bra menu_draw_lines_2 | 343 bra menu_draw_menu_items_common ; continue with common part |
327 | 344 |
328 menu_draw_lines: | 345 menu_draw_lines_surfmode: |
346 WIN_SMALL MENU_LEFT, 0 ; initialize start position and font | |
347 movff menu_vertical_start,win_top ; set vertical output position | |
348 clrf menu_item_start ; set first item in menu block as first item to draw | |
349 | |
350 IFDEF scrolling_menu_enabled | |
351 ; does the menu have more than 7 item ? | |
352 movf menu_item_count,W ; get number of menu items | |
353 addlw -(MENU_LINES_MAX+1) ; more than 7 item? | |
354 bn menu_draw_menu_items_common ; NO - continue with common part | |
355 movf selected_item,W ; YES - compute first item to be drawn as current cursor position - 6 | |
356 addlw -(MENU_LINES_MAX-1) ; - ... | |
357 btfsc STATUS,N ; - is this < 0 ? | |
358 clrf WREG ; YES - revert to starting from first item | |
359 movwf menu_item_start ; - set first item to be drawn | |
360 ENDIF ; scrolling_menu_enabled | |
361 | |
362 menu_draw_menu_items_common: | |
363 movff menu_item_start,menu_item_curr ; initialize menu item counter | |
364 FONT_SIZE FT_SMALL ; set font size | |
365 | |
366 menu_draw_menu_items_loop: | |
367 FONT_COLOR_MEMO ; set default font color (may be changed by dynamic titles) | |
368 movf menu_item_curr,W ; get menu item to draw | |
369 rcall menu_read_menu_item_data ; read menu item data | |
370 movf item_type,W ; switch on menu item type: | |
371 bz menu_draw_menu_item_dynamic ; -> 0: call with dynamic title | |
372 dcfsnz WREG ; | |
373 bra menu_draw_menu_item_call ; -> 1: call with fixed title | |
374 dcfsnz WREG ; | |
375 bra menu_draw_menu_item_option ; -> 2: option increment | |
376 bra menu_draw_menu_item_print ; no output in case of illegal type | |
377 | |
378 menu_draw_menu_item_dynamic: | |
379 | |
380 movf item_title_addr+0,W ; check if call address is NULL | |
381 iorwf item_title_addr+1,W ; ... | |
382 btfsc STATUS,Z ; is null? | |
383 bra menu_draw_menu_item_no_print ; YES - no printing on this menu line | |
384 INIT_BUFFER ; NO - initialize buffer | |
385 movff menu_item_curr,PRODL ; - pass menu item position to call function | |
386 rcall menu_text_call ; - call dynamic title function | |
387 bra menu_draw_menu_item_print ; - print menu item | |
388 | |
389 menu_draw_menu_item_call: | |
390 movff item_title_addr+0,FSR1L ; point to multi-lingual text | |
391 movff item_title_addr+1,FSR1H ; ... | |
392 call strcpy_text_FSR ; copy translated text to buffer | |
393 bra menu_draw_menu_item_print ; print menu item | |
394 | |
395 menu_draw_menu_item_option: | |
396 movff item_title_addr+0,FSR1L ; point to multi-lingual text | |
397 movff item_title_addr+1,FSR1H ; ... | |
398 call strcpy_text_FSR ; copy translated text to buffer | |
399 movff option_addr+0,FSR0L ; hand over address of option definition data | |
400 movff option_addr+1,FSR0H ; ... | |
401 btfsc option_addr+1,6 ; is the selected option an option group member? | |
402 call option_adjust_group_member ; YES - adjust address to selected group member | |
403 btfss block_option_value ; displaying of option value suspended? | |
404 call option_draw ; NO - draw option value | |
405 ;bra menu_draw_menu_item_print ; print menu item | |
406 | |
407 menu_draw_menu_item_print: | |
408 movlw MAX_LINE_LENGTH_SURF ; load maximum length for a surface menu item | |
329 btfsc divemode ; in dive mode? | 409 btfsc divemode ; in dive mode? |
330 bra menu_draw_lines_divemode ; YES | 410 movlw MAX_LINE_LENGTH_DIVE ; YES - replace with maximum length for a dive mode menu item |
331 btfsc menu_flags,0 ; dynamic title? | 411 call TFT_buffer_trim_length ; fill up or cut buffer to max length |
332 rcall menu_processor_title ; YES - redraw it then | 412 PRINT ; print menu item to screen |
333 MENU_LINE_FONT MENU_LEFT, 0 ; initialize start position/font | 413 ;bra menu_draw_menu_item_no_print ; continue with after-print actions |
334 movff menu_center,win_top ; computed in menu block | 414 |
335 | 415 menu_draw_menu_item_no_print: |
336 ; Does the menu have more than 6 lines ? | 416 movlw MENU_HEIGHT_SURF ; get menu items vertical spacing for surface mode |
337 movf item_max,W | 417 btfsc divemode ; in dive mode? |
338 addlw -(MENU_LINES_MAX+1) ; | 418 movlw MENU_HEIGHT_DIVE ; YES - replace with vertical spacing for dive mode |
339 bnn menu_draw_long_menu ; bra if >= 7 | 419 |
340 clrf start_item | 420 addwf win_top,F ; adjust vertical output position |
341 bra menu_draw_lines_2 | 421 incf menu_item_curr,F ; go to next menu item |
342 | 422 |
343 menu_draw_long_menu: | 423 btfss divemode ; in dive mode? |
344 movf selected_item,W ; start at selected-6 | 424 bra menu_draw_menu_item_surfmode ; NO |
345 addlw -(MENU_LINES_MAX-1) | 425 ;bra menu_draw_menu_item_divemode ; YES |
346 btfsc STATUS,N ; is this < 0 ? | 426 |
347 clrf WREG ; YES - start from top instead | 427 menu_draw_menu_item_divemode: |
348 movwf start_item | 428 movlw .3 ; load a 3 |
349 | 429 cpfseq menu_item_curr ; just done menu item 3 ? |
350 menu_draw_lines_2: | 430 bra menu_draw_menu_item_common ; NO - continue with common part |
351 movff start_item, menu_item | 431 movlw dm_menu_item4_row ; YES - set vertical position for 2nd column |
352 WIN_FONT FT_SMALL ; set font size | 432 movff WREG,win_top ; - ... |
353 | 433 movlw dm_menu_item4_column ; - set horizontal position for 2nd column |
354 menu_draw_lines_1: | 434 movff WREG,win_leftx2 ; - ... |
355 call TFT_standard_color ; set default text color | 435 bra menu_draw_menu_item_common ; - continue with common part |
356 movf menu_item,W | 436 |
357 rcall menu_read_item | 437 menu_draw_menu_item_surfmode: |
358 movf value_type,W ; switch on data type | 438 IFDEF scrolling_menu_enabled |
359 bz menu_draw_line_call | 439 movf menu_item_start,W ; get the number of the menu item that menu drawing started with |
360 dcfsnz WREG | 440 subwf menu_item_curr,W ; compute how many item have been drawn already |
361 bra menu_draw_line_string | 441 xorlw MENU_LINES_MAX ; compare with how max item fit the screen |
362 dcfsnz WREG | 442 btfsc STATUS,Z ; screen full? |
363 bra menu_draw_line_option | 443 return ; YES - done |
364 dcfsnz WREG | 444 ;bra menu_draw_menu_item_common ; NO - continue with common part |
365 bra menu_draw_line_dynamic | 445 ENDIF ; scrolling_menu_enabled |
366 bra menu_draw_line_none | 446 |
367 | 447 menu_draw_menu_item_common: |
368 menu_draw_line_string: | 448 movf menu_item_curr,W ; get current menu item |
369 movff text_item+0,TBLPTRL ; read not-translated string from PROM | 449 xorwf menu_item_count,W ; compare with total number of menu items, more item to do? |
370 movff text_item+1,TBLPTRH | 450 bnz menu_draw_menu_items_loop ; YES - loop |
371 call strcpy_prom ; copy in buffer | 451 return ; NO - done |
372 bra menu_draw_line_none | 452 |
373 | 453 |
374 menu_draw_line_call: | 454 ;----------------------------------------------------------------------------- |
375 movff text_item+0,FSR1L ; read string from PROM | 455 ; Helper Function - call Function for dynamic Title |
376 movff text_item+1,FSR1H | 456 ; |
377 call strcpy_text ; copy in buffer | |
378 bra menu_draw_line_none | |
379 | |
380 menu_draw_line_option: | |
381 movff text_item+0,FSR1L ; read string from PROM | |
382 movff text_item+1,FSR1H | |
383 call strcpy_text ; copy in buffer | |
384 movff option_item+0,FSR0L ; retrieve option handle | |
385 movff option_item+1,FSR0H | |
386 btfss block_option_value ; display of option value suspended? | |
387 call option_draw ; NO - draw option (do not do it when setting time or date) | |
388 bra menu_draw_line_none | |
389 | |
390 menu_draw_line_dynamic: | |
391 lfsr FSR2,buffer | |
392 movff menu_item,PRODL ; pass item to callback | |
393 rcall menu_text_call ; push return address | |
394 bra menu_draw_line_none | |
395 | |
396 ; Computed goto to pointer inside dynamic_item: | |
397 menu_text_call: | 457 menu_text_call: |
398 movf dynamic_item+0,W ; check if callback is NULL | 458 clrf PCLATU ; execute a computed goto |
399 iorwf dynamic_item+1,W | 459 movff item_title_addr+1,PCLATH ; ... |
400 iorwf dynamic_item+2,W | 460 movf item_title_addr+0,W ; ... |
401 btfsc STATUS,Z | 461 movwf PCL ; ... |
402 return ; YES - don't call it | 462 |
403 movff dynamic_item+2,PCLATU ; prepare... | 463 |
404 movff dynamic_item+1,PCLATH | 464 ;----------------------------------------------------------------------------- |
405 movf dynamic_item+0,W | 465 ; Draw the Cursor (Main Menu Style) |
406 movwf PCL ; ...and jump | 466 ; |
407 | 467 menu_draw_cursor_surf: |
408 menu_draw_line_none: | 468 WIN_LEFT MENU_LEFT-8 ; set horizontal start of cursor column |
409 btfsc divemode ; in dive mode? | 469 WIN_WIDTH .6 ; set width of cursor column |
410 bra menu_draw_line_none_divemode ; YES | 470 WIN_HEIGHT .223 ; set preliminary hight of cursor column |
411 movlw MENU_LINE_MAX_LENGTH | 471 |
412 call TFT_fillup_with_spaces ; fill up FSR2 with spaces (total string length in #WREG) | 472 movf menu_vertical_start,W ; get vertical start of menu items |
413 clrf WREG | 473 movwf win_top ; set vertical start of cursor column |
414 movff WREG,buffer+MENU_LINE_MAX_LENGTH ; NO - make sure won't be longer than MENU_LINE_MAX_LENGTH ch | 474 subwf win_height,F ; final hight = prelim.height - vertical start |
415 call aa_wordprocessor | 475 |
416 bcf win_invert ; clear flag for inverted output by default | 476 clrf WREG ; set color to black |
417 movlw MENU_HEIGHT ; NO - move to next line | 477 BOX_COLOR ; clear cursor area |
418 addwf win_top,F | 478 |
419 incf menu_item,F ; inc loop counter | 479 movf menu_item_start,W ; get number of menu item that is on the first line |
420 movf start_item,W ; first line (scrolled) | 480 subwf selected_item,W ; compute line number of current menu item |
421 subwf menu_item,W ; current - first | 481 |
422 xorlw MENU_LINES_MAX ; get max number of lines | 482 mullw MENU_HEIGHT_SURF ; multiply line number with vertical menu items spacing |
423 btfsc STATUS,Z ; already done max number of lines? | 483 movf PRODL,W ; get computed vertical offset |
424 return ; YES | 484 addwf menu_vertical_start,W ; add offset to vertical start position |
425 menu_draw_line_none2: | 485 movwf win_top ; set final vertical position |
426 movf menu_item,W ; done item_max lines? | 486 bra menu_draw_cursor_common ; print cursor and return |
427 xorwf item_max,W | 487 |
428 btfss STATUS,Z | 488 |
429 bra menu_draw_lines_1 ; NO - loop... | 489 ;----------------------------------------------------------------------------- |
430 return | 490 ; Draw the Cursor (Dive Mode Style) |
431 | 491 ; |
432 menu_draw_line_none_divemode: | 492 global menu_draw_cursor_dive |
433 movlw .10 | 493 menu_draw_cursor_dive: |
434 call TFT_fillup_with_spaces ; fill up FSR2 with spaces (total string length in #WREG) | 494 ; clear cursor areas |
435 clrf WREG | 495 WIN_BOX_BLACK dm_menu_row+.1, dm_menu_lower-.1, dm_menu_item1_column-.8, dm_menu_item1_column-.1 |
436 movff WREG,buffer+.10 | 496 WIN_BOX_BLACK dm_menu_row+.1, dm_menu_lower-.1, dm_menu_item4_column-.8, dm_menu_item4_column-.1 |
437 call aa_wordprocessor ; draw the line | 497 |
438 bcf win_invert ; reset invert flag | 498 movlw dm_menu_item1_column-.8 ; load position of left column |
439 movlw .24 ; dive mode menu spacing | 499 btfsc menu_pos_cur,2 ; cursor at menu item 4..6 ? |
440 addwf win_top,F | 500 movlw dm_menu_item4_column-.8 ; YES - replace with position of right column |
441 incf menu_item,F ; inc loop counter | 501 movwf win_leftx2 ; set horizontal position |
442 movlw .3 | 502 |
443 cpfseq menu_item ; at position 4? | 503 decf menu_pos_cur,W ; get cursor position as 0..5 into WREG |
444 bra menu_draw_line_none2 ; NO | 504 btfsc menu_pos_cur,2 ; cursor at menu item 4..6 ? |
445 movlw dm_menu_item4_row | 505 addlw -.3 ; YES - subtract 3 to get line number in right column |
446 movff WREG,win_top ; reset row | 506 |
447 movlw dm_menu_item4_column | 507 mullw MENU_HEIGHT_DIVE ; multiply line number with vertical menu items spacing |
448 movff WREG,win_leftx2 ; new column | 508 movf PRODL,W ; get computed vertical offset |
449 bra menu_draw_line_none2 ; done | 509 addlw dm_menu_item1_row ; add offset to vertical start position |
450 | 510 movwf win_top ; set final vertical position |
451 ;----------------------------------------------------------------------------- | 511 ;bra menu_draw_cursor_common ; print cursor and return |
452 ; draw cursor | 512 |
453 menu_draw_selected_line: | 513 |
454 WIN_BOX_BLACK .34,.221,MENU_LEFT-8,MENU_LEFT-2 ; clear left column | 514 ;----------------------------------------------------------------------------- |
455 call TFT_standard_color | 515 ; Helper Function - common Part of drawing the Cursor |
456 WIN_SMALL MENU_LEFT-8, 0 ; arrow symbol only in small font | 516 ; |
457 movf start_item,W ; first line (scrolled) | 517 menu_draw_cursor_common: |
458 subwf selected_item,W ; selected - first | 518 FONT_COLOR_MEMO ; set font color |
459 mullw MENU_HEIGHT ; 30 pixel by line | 519 FONT_SIZE FT_SMALL ; set font size |
460 movf PRODL,W ; result | |
461 addwf menu_center,W ; added to first line | |
462 movwf win_top ; and stored to position | |
463 STRCPY_PRINT "\xb7" ; print cursor | 520 STRCPY_PRINT "\xb7" ; print cursor |
464 return | 521 return ; done |
522 | |
523 ;----------------------------------------------------------------------------- | |
465 | 524 |
466 END | 525 END |