Mercurial > public > hwos_code
annotate src/menu_processor.asm @ 628:cd58f7fc86db
3.05 stable work
author | heinrichsweikamp |
---|---|
date | Thu, 19 Sep 2019 12:01:29 +0200 |
parents | c40025d8e750 |
children | 185ba2f91f59 |
rev | line source |
---|---|
0 | 1 ;============================================================================= |
2 ; | |
623 | 3 ; File menu_processor.asm combined next generation V3.03.2 |
0 | 4 ; |
275 | 5 ; Routines to handle all hwOS graphic/text menus. |
0 | 6 ; |
7 ; Copyright (c) 2011, JD Gascuel, HeinrichsWeikamp, all right reserved. | |
8 ;============================================================================= | |
9 ; HISTORY | |
275 | 10 ; 2012-11-02 : [jDG] Cleanup for hwOS: removed icons. Added scrolling. |
582 | 11 ; But need a font with lower/upper alpha chars... |
0 | 12 |
604 | 13 #include "hwos.inc" |
0 | 14 #include "convert.inc" |
15 #include "strings.inc" | |
16 #include "tft.inc" | |
17 #include "varargs.inc" | |
18 #include "start.inc" | |
19 #include "surfmode.inc" | |
20 #include "divemode.inc" | |
21 #include "tft_outputs.inc" | |
22 #include "eeprom_rs232.inc" | |
62 | 23 #include "adc_lightsensor.inc" |
604 | 24 #include "i2c.inc" |
623 | 25 #include "rtc.inc" |
26 #include "wait.inc" | |
229 | 27 |
0 | 28 |
604 | 29 ; NOTE: needs to be identical in .inc and .asm ! |
623 | 30 #define MENU_LINES_MAX .7 ; maximum number of lines per screen |
604 | 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 | |
34 #define MENU_HEIGHT .27 ; spacing between menu lines | |
35 #define MENU_VCENTER .125 ; position on screen | |
36 #define MENU_LINE_MAX_LENGTH .20 ; length in characters | |
582 | 37 #define option_item proc_item |
0 | 38 |
623 | 39 |
582 | 40 extern aa_wordprocessor |
41 extern option_inc | |
42 extern option_draw | |
43 extern TFT_clear_divemode_menu | |
44 extern TFT_divemask_color | |
45 extern rtc_set_rtc | |
46 extern divemode_option0_return | |
47 extern TFT_fillup_with_spaces | |
0 | 48 |
49 | |
623 | 50 menu_proc CODE |
0 | 51 |
52 ;============================================================================= | |
623 | 53 ; menu handler |
0 | 54 ; |
623 | 55 ; Input: TBLPTR = addr of menu block |
56 | |
582 | 57 global menu_processor |
0 | 58 menu_processor: |
623 | 59 ; btfss divemode ; in dive mode? |
60 ; call request_speed_fastest ; NO - request CPU speed change to fastest speed | |
582 | 61 ;---- Read menu block ------------------------------------------------ |
604 | 62 VARARGS_BEGIN ; read inline PROM data |
63 clrf STKPTR ; never return from here | |
64 VARARGS_GET8 item_max ; get number of items | |
65 VARARGS_GET8 menu_flags ; get flags | |
66 VARARGS_GET24 menu_title ; get pointer to menu title | |
67 VARARGS_GET8 menu_center ; vertical position | |
68 movff TBLPTRL, menu_block+0 ; save base address for menu_read_item | |
623 | 69 movff TBLPTRH, menu_block+1 ; ... |
70 movff TBLPTRU, menu_block+2 ; ... | |
71 btfss divemode ; in dive mode? | |
604 | 72 bra menu_processor0 ; NO |
623 | 73 |
604 | 74 ; Required for menus with less entries than the calling menu but not so nice when setting up gas 6.... mH |
582 | 75 movlw .1 |
623 | 76 cpfsgt menu_pos_cur ; only if menu_pos_cur = 1... |
604 | 77 call TFT_clear_divemode_menu ; ... clear the menu! |
623 | 78 ; Draw one frame around the dive mode menu |
582 | 79 call TFT_divemask_color |
80 WIN_FRAME_COLOR16 dm_menu_row, dm_menu_lower, dm_menu_left ,dm_menu_right ; top, bottom, left, right | |
81 call TFT_standard_color | |
0 | 82 |
623 | 83 bra menu_processor1 ; skip next code segment in dive mode |
0 | 84 |
85 menu_processor0: | |
582 | 86 ;---- draw menu title ------------------------------------------------ |
87 clrf CCP1CON ; stop PWM | |
604 | 88 bcf PORTC,2 ; pull PWM out to GND |
582 | 89 call TFT_ClearScreen |
90 rcall menu_processor_title | |
91 rcall menu_processor_bottom_line | |
0 | 92 |
169
dcf3e08f31ac
CHANGE: Improve internal logbook usability
heinrichsweikamp
parents:
125
diff
changeset
|
93 menu_processor1: |
623 | 94 WIN_FONT FT_SMALL |
169
dcf3e08f31ac
CHANGE: Improve internal logbook usability
heinrichsweikamp
parents:
125
diff
changeset
|
95 |
582 | 96 ;---- Select menu type ----------------------------------------------- |
97 bra menu_vertical | |
0 | 98 |
604 | 99 |
100 ;============================================================================= | |
101 ; draw menu bottom line | |
102 ; | |
582 | 103 menu_processor_bottom_line: |
104 ;---- Draw bottom line ----------------------------------------------- | |
105 TEXT_TINY .5, .240-.16, tNext | |
106 TEXT_TINY .160-.6*.6, .240-.16, tEnter | |
623 | 107 goto TFT_standard_color ; ...and return |
0 | 108 |
109 ;============================================================================= | |
604 | 110 ; (re-)draw menu title |
0 | 111 ; |
582 | 112 menu_processor_title: |
604 | 113 WIN_BOX_BLACK .2,.23,.0,.159 ; clear menu title |
114 MENU_TITLE_FONT .0, .2 ; menu title positioning | |
115 btfss menu_flags,0 ; static or dynamic title? | |
116 bra menu_processor_static_title ; static title | |
117 rcall menu_processor_call_title ; dynamic title - add gas, detail and color | |
582 | 118 bra menu_processor_title_1 |
0 | 119 |
582 | 120 menu_processor_static_title: |
604 | 121 movff menu_title+0,FSR1L ; just copy string |
582 | 122 movff menu_title+1,FSR1H |
123 call strcpy_text | |
0 | 124 |
125 menu_processor_title_1: | |
582 | 126 WIN_COLOR color_greenish |
604 | 127 movf FSR2L,W ; get title length |
128 mullw .9 ; convert to half pixels | |
129 bcf STATUS,C ; clear carry | |
582 | 130 rrcf PRODL ; /2 |
604 | 131 movf PRODL,W ; back to WREG |
582 | 132 sublw .80 ; 80 - width |
604 | 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.) | |
582 | 136 call aa_wordprocessor |
137 call TFT_standard_color | |
138 return | |
0 | 139 |
140 ;============================================================================= | |
141 ; Call dynamic proc for menu title: | |
142 | |
143 menu_processor_call_title: | |
604 | 144 movff menu_title+2,PCLATU ; execute computed goto |
582 | 145 movff menu_title+1,PCLATH |
146 movf menu_title+0,W | |
147 movwf PCL | |
148 | |
0 | 149 ;============================================================================= |
604 | 150 ; Restart with first icon/line selected |
151 ; | |
582 | 152 global menu_processor_reset |
0 | 153 menu_processor_reset: |
623 | 154 clrf menustack ; clear first stack position |
155 clrf menustack_pointer ; set stack pointer to first stack position | |
156 clrf selected_item ; set last menu item to first item | |
582 | 157 return |
0 | 158 |
582 | 159 |
160 global menu_processor_double_pop | |
623 | 161 global menu_processor_pop |
582 | 162 menu_processor_double_pop: |
623 | 163 decf menustack_pointer,F ; decrement stack pointer |
164 menu_processor_pop: | |
165 decf menustack_pointer,F ; decrement stack pointer | |
166 btfsc menustack_pointer,7 ; did the stack pointer under-run? | |
167 clrf menustack_pointer ; YES - reset stack pointer to first stack position | |
168 movf menustack_pointer,W ; load stack pointer into WREG | |
169 lfsr FSR2,menustack ; load base address of menu stack | |
170 movff PLUSW2,selected_item ; retrieve menu item from stack | |
171 return ; done | |
172 | |
0 | 173 |
174 menu_processor_push: | |
623 | 175 lfsr FSR2,menustack ; load base address of menu stack |
176 movf menustack_pointer,W ; load stack pointer into WREG | |
177 movff selected_item,PLUSW2 ; save menu item to stack | |
178 incf menustack_pointer,W ; increment stack pointer, park result in WREG | |
179 btfss WREG,3 ; result < 8 ? | |
180 movwf menustack_pointer ; YES - update stack pointer | |
181 clrf selected_item ; set to first item in new menu | |
182 return ; done | |
183 | |
0 | 184 |
185 ;---- Execute menu selection ------------------------------------------------- | |
186 do_menu_item: | |
623 | 187 bcf switch_right ; clear left-over button event |
604 | 188 movf selected_item,W ; reread proc address from table |
189 rcall menu_read_item ; (destroys PROD) | |
190 movff selected_item,PRODL ; pass along selected line | |
191 rcall menu_processor_push ; remember where we got from (clears selected_item) | |
192 movff proc_item+2,PCLATU ; then execute computed goto | |
582 | 193 movff proc_item+1,PCLATH |
194 movf proc_item+0,W | |
195 movwf PCL | |
0 | 196 |
197 ;============================================================================= | |
198 ; Get current item from table. | |
199 ; | |
604 | 200 ; Input : Item number in WREG, menu_block. |
201 ; Output : icon_large, text_item, proc_item 16bits pointers. | |
202 ; Trashed: PROD, WREG | |
0 | 203 ; |
204 menu_read_item: | |
604 | 205 mullw .10 ; 10 bytes per item |
206 movf PRODL,W ; then do a 24 bits add | |
582 | 207 addwf menu_block+0,W ; with menu_block, and |
208 movwf TBLPTRL ; setup TBLPTR | |
209 movf PRODH,W | |
210 addwfc menu_block+1,W | |
211 movwf TBLPTRH | |
212 movlw 0 | |
213 addwfc menu_block+2,W | |
214 movwf TBLPTRU | |
604 | 215 VARARGS_GET8 value_type ; read 10 bytes of item data |
582 | 216 VARARGS_GET24 dynamic_item |
217 VARARGS_GET24 proc_item | |
604 | 218 VARARGS_GET8 WREG ; skip dummy byte |
582 | 219 VARARGS_GET16 text_item |
0 | 220 |
582 | 221 return |
0 | 222 |
223 ;============================================================================= | |
604 | 224 ; Vertical menu - set of line/value to choose from, |
225 ; entry point to update lines already shown | |
0 | 226 ; |
582 | 227 global menu_vertical |
0 | 228 menu_vertical: |
604 | 229 rcall menu_draw_lines ; always re-draw whole menu |
230 movlw CCP1CON_VALUE ; see hwos.inc | |
623 | 231 btfss divemode ; in dive mode? |
604 | 232 movwf CCP1CON ; NO - power-on backlight |
0 | 233 |
234 menu_vertical_1: | |
623 | 235 movf selected_item,W ; copy current menu item selection to WREG |
236 rcall menu_read_item ; get current menu item data | |
604 | 237 movf proc_item+0,W ; check if proc address is NULL |
582 | 238 iorwf proc_item+1,W |
604 | 239 bz next_line_menu ; YES - not selectable |
623 | 240 btfss divemode ; in dive mode? |
604 | 241 rcall menu_draw_selected_line ; NO |
623 | 242 btfss imprint_time_date ; currently imprinting the current time & date? |
243 bra menu_line_loop_pre1 ; NO | |
244 btfss switch_right ; YES - right button pressed, i.e. time or date changed? | |
245 bra menu_line_loop_pre1 ; NO | |
246 call TFT_show_time_date_menu_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) | |
0 | 248 |
249 menu_line_loop_pre1: | |
623 | 250 btfsc imprint_color_schemes ; in the color scheme menu? |
251 call TFT_show_color_schemes ; YES - update the color schemes | |
0 | 252 |
253 menu_line_loop_pre2: | |
623 | 254 bcf switch_right ; clear left-over right button event |
255 bcf switch_left ; clear left-over left button event | |
0 | 256 |
257 menu_line_loop_pre3: | |
623 | 258 btfsc divemode ; in dive mode? |
259 goto divemode_option0_return ; YES - return to it | |
260 ;bra menu_line_loop_surface ; - proceed to surface mode dispatcher | |
604 | 261 |
623 | 262 ; dispatcher for surface mode menus |
263 menu_line_loop_surface: | |
264 call reset_timeout_surfmode ; reset timeout | |
265 menu_line_loop: | |
266 call housekeeping ; handle data imprinting, screen dump request, timeout and entering dive mode | |
267 btfsc switch_right ; right button pressed? | |
268 bra do_line_menu ; YES - type dependent | |
269 btfsc switch_left ; left button pressed? | |
270 bra next_line_menu ; YES - goto next item | |
271 bra menu_line_loop ; NO to both - loop | |
604 | 272 |
0 | 273 |
274 ;---- Move to menu's next line | |
275 next_line_menu: | |
623 | 276 bcf switch_left ; clear button event |
604 | 277 incf selected_item,F ; select next item |
623 | 278 movf selected_item,W ; copy item number to WREG |
279 cpfseq item_max ; item number == max ? | |
604 | 280 bra menu_vertical_1 ; NO - redraw cursor |
623 | 281 clrf selected_item ; YES - wrap-around to first item |
604 | 282 bra menu_vertical_1 ; then redraw cursor |
0 | 283 |
582 | 284 global do_line_menu |
0 | 285 do_line_menu: |
623 | 286 decf menu_pos_cur,W ; menu_processor needs 0-5 |
287 btfsc divemode ; in dive mode? | |
288 movwf selected_item ; YES - set selected item from WREG | |
604 | 289 movf selected_item,W ; read selected descriptor |
582 | 290 rcall menu_read_item |
604 | 291 movf value_type,W ; switch on data type |
582 | 292 bz menu_do_line_call ; CALL |
293 dcfsnz WREG | |
294 bra menu_do_line_call ; STRING: do as call | |
295 dcfsnz WREG | |
296 bra menu_do_line_option ; OPTION | |
297 dcfsnz WREG | |
298 bra menu_do_line_call ; DYNAMIC: do as call | |
604 | 299 bra menu_line_loop_pre3 ; else do nothing |
0 | 300 |
301 ;---- CALL | |
302 menu_do_line_call: | |
604 | 303 rcall do_menu_item ; same as icon menu: calculated goto |
304 rcall menu_processor_pop ; back to same line, | |
305 bra menu_vertical ; then continue into menu... | |
0 | 306 |
307 ;---- Call option specific increment subroutine | |
308 menu_do_line_option: | |
604 | 309 movff option_item+0,FSR0L ; get option handle |
582 | 310 movff option_item+1,FSR0H |
311 call option_inc ; increment | |
623 | 312 movff selected_item,PRODL ; pass selection to callback |
582 | 313 rcall menu_text_call |
623 | 314 bra menu_vertical ; redraw all lines |
0 | 315 |
316 ;----------------------------------------------------------------------------- | |
317 | |
623 | 318 global menu_draw_lines_divemode ; entry point for re-drawing of the menu to update color-coding of gases |
0 | 319 menu_draw_lines_divemode: |
582 | 320 movlw dm_menu_item1_row |
321 movff WREG,win_top | |
322 movlw dm_menu_item1_column | |
323 movff WREG,win_leftx2 | |
324 clrf start_item | |
623 | 325 movff item_max,menu_pos_max ; copy item_max for dive mode cursor routine |
582 | 326 bra menu_draw_lines_2 |
0 | 327 |
328 menu_draw_lines: | |
623 | 329 btfsc divemode ; in dive mode? |
604 | 330 bra menu_draw_lines_divemode ; YES |
331 btfsc menu_flags,0 ; Dynamic title? | |
332 rcall menu_processor_title ; YES - redraw it then | |
623 | 333 MENU_LINE_FONT MENU_LEFT, 0 ; initialize start position/font |
582 | 334 movff menu_center,win_top ; computed in menu block. |
0 | 335 |
582 | 336 ; Does the menu have more than 6 lines ? |
337 movf item_max,W | |
623 | 338 addlw -(MENU_LINES_MAX+1) ; |
339 bnn menu_draw_long_menu ; bra if >= 7 | |
582 | 340 clrf start_item |
341 bra menu_draw_lines_2 | |
0 | 342 |
343 menu_draw_long_menu: | |
604 | 344 movf selected_item,W ; start at selected-6 |
582 | 345 addlw -(MENU_LINES_MAX-1) |
604 | 346 btfsc STATUS,N ; is this < 0 ? |
347 clrf WREG ; YES - start from top instead | |
582 | 348 movwf start_item |
0 | 349 |
350 menu_draw_lines_2: | |
582 | 351 movff start_item, menu_item |
623 | 352 WIN_FONT FT_SMALL ; set font size |
0 | 353 |
354 menu_draw_lines_1: | |
623 | 355 call TFT_standard_color ; set default text color |
582 | 356 movf menu_item,W |
357 rcall menu_read_item | |
604 | 358 movf value_type,W ; switch on data type |
582 | 359 bz menu_draw_line_call |
360 dcfsnz WREG | |
361 bra menu_draw_line_string | |
362 dcfsnz WREG | |
363 bra menu_draw_line_option | |
364 dcfsnz WREG | |
365 bra menu_draw_line_dynamic | |
366 bra menu_draw_line_none | |
0 | 367 |
368 menu_draw_line_string: | |
604 | 369 movff text_item+0,TBLPTRL ; read not-translated string from PROM |
582 | 370 movff text_item+1,TBLPTRH |
604 | 371 call strcpy_prom ; copy in buffer |
582 | 372 bra menu_draw_line_none |
0 | 373 |
582 | 374 menu_draw_line_call: |
604 | 375 movff text_item+0,FSR1L ; read string from PROM |
582 | 376 movff text_item+1,FSR1H |
604 | 377 call strcpy_text ; copy in buffer |
582 | 378 bra menu_draw_line_none |
379 | |
0 | 380 menu_draw_line_option: |
604 | 381 movff text_item+0,FSR1L ; read string from PROM |
582 | 382 movff text_item+1,FSR1H |
604 | 383 call strcpy_text ; copy in buffer |
384 movff option_item+0,FSR0L ; retrieve option handle | |
582 | 385 movff option_item+1,FSR0H |
623 | 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) | |
582 | 388 bra menu_draw_line_none |
0 | 389 |
390 menu_draw_line_dynamic: | |
582 | 391 lfsr FSR2,buffer |
604 | 392 movff menu_item,PRODL ; pass item to callback |
393 rcall menu_text_call ; push return address | |
582 | 394 bra menu_draw_line_none |
0 | 395 |
396 ; Computed goto to pointer inside dynamic_item: | |
397 menu_text_call: | |
604 | 398 movf dynamic_item+0,W ; check if callback is NULL |
582 | 399 iorwf dynamic_item+1,W |
400 iorwf dynamic_item+2,W | |
401 btfsc STATUS,Z | |
604 | 402 return ; YES - don't call it |
403 movff dynamic_item+2,PCLATU ; prepare... | |
582 | 404 movff dynamic_item+1,PCLATH |
405 movf dynamic_item+0,W | |
604 | 406 movwf PCL ; ...and jump |
0 | 407 |
408 menu_draw_line_none: | |
623 | 409 btfsc divemode ; in dive mode? |
410 bra menu_draw_line_none_divemode ; YES | |
582 | 411 movlw MENU_LINE_MAX_LENGTH |
623 | 412 call TFT_fillup_with_spaces ; fill up FSR2 with spaces (total string length in #WREG) |
582 | 413 clrf WREG |
604 | 414 movff WREG,buffer+MENU_LINE_MAX_LENGTH ; NO - make sure won't be longer than MENU_LINE_MAX_LENGTH ch |
582 | 415 call aa_wordprocessor |
604 | 416 bcf win_invert ; clear flag for inverted output by default |
417 movlw MENU_HEIGHT ; NO - move to next line | |
582 | 418 addwf win_top,F |
419 incf menu_item,F ; inc loop counter | |
604 | 420 movf start_item,W ; first line (scrolled) |
582 | 421 subwf menu_item,W ; current - first |
623 | 422 xorlw MENU_LINES_MAX ; get max number of lines |
423 btfsc STATUS,Z ; already done max number of lines? | |
582 | 424 return ; YES |
0 | 425 menu_draw_line_none2: |
604 | 426 movf menu_item,W ; done item_max lines? |
582 | 427 xorwf item_max,W |
428 btfss STATUS,Z | |
623 | 429 bra menu_draw_lines_1 ; NO - loop... |
582 | 430 return |
0 | 431 |
432 menu_draw_line_none_divemode: | |
582 | 433 movlw .10 |
623 | 434 call TFT_fillup_with_spaces ; fill up FSR2 with spaces (total string length in #WREG) |
582 | 435 clrf WREG |
436 movff WREG,buffer+.10 | |
604 | 437 call aa_wordprocessor ; draw the line |
438 bcf win_invert ; reset invert flag | |
623 | 439 movlw .24 ; dive mode menu spacing |
582 | 440 addwf win_top,F |
441 incf menu_item,F ; inc loop counter | |
442 movlw .3 | |
623 | 443 cpfseq menu_item ; at position 4? |
604 | 444 bra menu_draw_line_none2 ; NO |
582 | 445 movlw dm_menu_item4_row |
604 | 446 movff WREG,win_top ; reset row |
582 | 447 movlw dm_menu_item4_column |
604 | 448 movff WREG,win_leftx2 ; new column |
449 bra menu_draw_line_none2 ; done | |
0 | 450 |
451 ;----------------------------------------------------------------------------- | |
623 | 452 ; draw cursor |
0 | 453 menu_draw_selected_line: |
604 | 454 WIN_BOX_BLACK .34,.221,MENU_LEFT-8,MENU_LEFT-2 ; clear left column |
582 | 455 call TFT_standard_color |
604 | 456 WIN_SMALL MENU_LEFT-8, 0 ; arrow symbol only in small font |
457 movf start_item,W ; first line (scrolled) | |
582 | 458 subwf selected_item,W ; selected - first |
459 mullw MENU_HEIGHT ; 30 pixel by line | |
460 movf PRODL,W ; result | |
461 addwf menu_center,W ; added to first line | |
623 | 462 movwf win_top ; and stored to position |
582 | 463 STRCPY_PRINT "\xb7" ; print cursor |
464 return | |
0 | 465 |
582 | 466 END |