comparison src/menu_processor.asm @ 0:11d4fc797f74

init
author heinrichsweikamp
date Wed, 24 Apr 2013 19:22:45 +0200
parents
children ec4d8503ec45
comparison
equal deleted inserted replaced
-1:000000000000 0:11d4fc797f74
1 ;=============================================================================
2 ;
3 ; File menu_processor.asm
4 ;
5 ; Routines to handle all OSTC3 graphic/text menus.
6 ;
7 ; Copyright (c) 2011, JD Gascuel, HeinrichsWeikamp, all right reserved.
8 ;=============================================================================
9 ; HISTORY
10 ; 2012-11-02 : [jDG] Cleanup for OSTC3: removed icons. Added scrolling.
11 ; But need a font with lower/upper alpha chars...
12
13 #include "convert.inc"
14 #include "ostc3.inc"
15 #include "strings.inc"
16 #include "tft.inc"
17 #include "varargs.inc"
18 #include "wait.inc"
19 #include "start.inc"
20 #include "surfmode.inc"
21 #include "divemode.inc"
22 #include "tft_outputs.inc"
23 #include "eeprom_rs232.inc"
24
25 ;NOTE: should be idenric in .inc and .asm !
26 #define MENU_LINES_MAX .7 ; Number of lines per screen?
27 #define MENU_TITLE_FONT WIN_STD ; Font should contains lower/UPPER alpha
28 #define MENU_LINE_FONT WIN_SMALL ; Font should contains lower/UPPER alpha
29 #define MENU_LEFT .20 ; Position of first menu item
30 #define MENU_HEIGHT .27 ; Spacing between menu lines.
31 #define MENU_VCENTER .125 ; Position on screen.
32 #define MENU_LINE_MAX_LENGTH .20 ; Length in characters
33
34 ; Other needed references
35 extern aa_wordprocessor,option_inc,option_draw,comm_mode
36
37
38 ;=============================================================================
39 ; Temporary data.
40
41 CBLOCK tmp+0x20 ; Reserved space for options.asm
42 menu_flags ; Various flags for menu:
43 ; bit 0 :dynamic menu
44 menu_item ; Index of the current item.
45 start_item ; Index of the first item (scrolling)
46 item_max ; Number of items in menu.
47 selected_item ; Index of the current item.
48 value_type ; Type for vertical menu.
49 dynamic_item:3 ; Callback addr
50 menu_block:3 ; Address of the menu block (ie. item 0)
51 menu_title:3 ; text or proc for dynamic menu.
52 menu_center ; centering for line menu.
53 proc_item:3 ; Address of the current proc.
54 text_item:2 ; Address of the current text.
55 ; Reserved to tmp+0x35
56 ENDC
57
58 #define option_item proc_item
59
60 basic CODE
61 ;=============================================================================
62 ; menu handler.
63 ;
64 ; Input: TBLPTR = addr of menu block.
65 global menu_processor
66 menu_processor:
67 banksel common ; Bank1
68 btfss divemode ; Not in divemode
69 call speed_fastest ; Make it quick !
70
71 ;---- Read menu block ------------------------------------------------
72 VARARGS_BEGIN ; Read inline PROM data
73 clrf STKPTR ; Never return, anyway...
74 VARARGS_GET8 item_max ; Get number of items
75 VARARGS_GET8 menu_flags ; Get flags
76 VARARGS_GET24 menu_title ; Get pointer to menu title
77 VARARGS_GET8 menu_center ; Vertical position
78 movff TBLPTRL, menu_block+0 ; Save base address for menu_read_item
79 movff TBLPTRH, menu_block+1
80 movff TBLPTRU, menu_block+2
81
82 extern TFT_clear_divemode_menu
83 btfss divemode ; In divemode?
84 bra menu_processor0 ; No
85
86 movlw .1
87 cpfsgt menupos ; only if menupos=1...
88 call TFT_clear_divemode_menu ; ... Clear the menu!
89 bra menu_processor1 ; Yes, skip some lines here
90
91 menu_processor0:
92 ;---- draw menu title ------------------------------------------------
93 clrf CCP1CON ; stop PWM
94 bcf PORTC,2 ; Pull PWM out to GND
95 call TFT_ClearScreen
96 rcall menu_processor_title
97
98 ;---- Draw bottomline ------------------------------------------------
99 TEXT_TINY .5, .240-.16, tNext
100 TEXT_TINY .160-6*5, .240-.16, tEnter
101
102 menu_processor1:
103 movlw FT_SMALL
104 movff WREG, win_font
105
106 ;---- Select menu type -----------------------------------------------
107 bra menu_vertical
108
109 ;=============================================================================
110 ; (re-)draw menu title.
111 ;
112 menu_processor_title:
113 btfss menu_flags,0 ; Static or dynmic title ?
114 bra menu_processor_static_title
115
116 lfsr FSR2,buffer
117 rcall menu_processor_call_title ; add gas, detail and color.
118 bra menu_processor_title_1
119
120 menu_processor_static_title:
121 movff menu_title+0,FSR1L ; Just copy string.
122 movff menu_title+1,FSR1H
123 call strcpy_text
124
125 menu_processor_title_1:
126 WIN_BOX_BLACK .2,.23,.0,.160 ; Clear Menu title
127 MENU_TITLE_FONT .0, .2 ; Menu title positionning
128 WIN_COLOR color_greenish
129 movf FSR2L,W ; Get title length
130 mullw .9 ; Convert to half pixels
131 bcf STATUS,C ; Clear carry
132 rrcf PRODL ; /2
133 movf PRODL,W ; Back to WREG
134 sublw .80 ; 80 - width
135 movwf win_leftx2 ; Aligned to center.
136
137 call aa_wordprocessor
138 TFT_STD_COLOR
139 return
140
141 ;=============================================================================
142 ; Call dynamic proc for menu title:
143
144 menu_processor_call_title:
145 movff menu_title+2,PCLATU ; Just execute computed goto.
146 movff menu_title+1,PCLATH
147 movf menu_title+0,W
148 movwf PCL
149
150 ;=============================================================================
151 ; Restart with first icon/line selected.
152 global menu_processor_reset
153 menu_processor_reset:
154 banksel common
155 lfsr FSR2,menustack
156 clrf POSTINC2
157 clrf POSTINC2
158 clrf POSTINC2
159 clrf POSTINC2
160 clrf POSTINC2
161 clrf selected_item
162 return
163
164 global menu_processor_pop
165 menu_processor_pop:
166 movff menustack+0,selected_item
167 movff menustack+1,menustack+0
168 movff menustack+2,menustack+1
169 movff menustack+3,menustack+2
170 movff menustack+4,menustack+3
171 return
172
173 menu_processor_push:
174 movff menustack+3,menustack+4
175 movff menustack+2,menustack+3
176 movff menustack+1,menustack+2
177 movff menustack+0,menustack+1
178 movff selected_item,menustack+0
179 clrf selected_item
180 return
181
182 ;---- Execute menu selection -------------------------------------------------
183 do_menu_item:
184 bcf switch_right ; Avoid loops.
185 call speed_normal ; Back to normal speed.
186
187 movf selected_item,W ; Reread proc address from table.
188 rcall menu_read_item ; (destroy PROD)
189
190 movff selected_item,PRODL ; Pass along selected line
191
192 rcall menu_processor_push ; Remember where we get from. (clears selected_item)
193
194 movff proc_item+2,PCLATU ; Then execute computed goto.
195 movff proc_item+1,PCLATH
196 movf proc_item+0,W
197 movwf PCL
198
199 ;=============================================================================
200 ; Get current item from table.
201 ;
202 ; Input : Item number in WREG, menu_block.
203 ;
204 ; Output: icon_large, text_item, proc_item 16bits pointers.
205 ;
206 ; Trashed: PROD, WREG
207 menu_read_item:
208 mullw .10 ; 10 bytes per item.
209 movf PRODL,W ; Then do a 24bits add
210 addwf menu_block+0,W ; with menu_block, and
211 movwf TBLPTRL ; setup TBLPTR
212 movf PRODH,W
213 addwfc menu_block+1,W
214 movwf TBLPTRH
215 movlw 0
216 addwfc menu_block+2,W
217 movwf TBLPTRU
218
219 VARARGS_GET8 value_type ; Read 10 bytes of item data
220 VARARGS_GET24 dynamic_item
221 VARARGS_GET24 proc_item
222 VARARGS_GET8 WREG ; Skip dummy byte
223 VARARGS_GET16 text_item
224
225 return
226
227 ;=============================================================================
228 ; Vertical menu : set of line/value to choose from.
229 ; Entry point to update lines already shown.
230 ;
231 global menu_vertical
232 menu_vertical:
233 btfss divemode ; Not in divemode
234 clrf timeout_counter2 ; Reset timeout
235
236 menu_vertical_2:
237 rcall menu_draw_lines ; Always re-draw whole menu
238
239 movlw CCP1CON_VALUE ; See ostc3.inc
240 btfss divemode ; Not in divemode
241 movwf CCP1CON ; Power-on backlight
242
243 menu_vertical_1:
244 movf selected_item,W ; Get current item data
245 rcall menu_read_item
246 movf proc_item+0,W ; Check if pro address is NULL ?
247 iorwf proc_item+1,W
248 bz next_line_menu ; YES: not selectable !
249
250 btfss divemode ; Not in divemode
251 rcall menu_draw_selected_line
252
253 extern rtc_set_rtc
254 btfss settime_setdate ; In the Set Time or Set Date menu?
255 bra menu_line_loop_pre2 ; no, skip all following
256
257 movff month,lo ; new month
258 dcfsnz lo,F
259 movlw .31
260 dcfsnz lo,F
261 movlw .28
262 dcfsnz lo,F
263 movlw .31
264 dcfsnz lo,F
265 movlw .30
266 dcfsnz lo,F
267 movlw .31
268 dcfsnz lo,F
269 movlw .30
270 dcfsnz lo,F
271 movlw .31
272 dcfsnz lo,F
273 movlw .31
274 dcfsnz lo,F
275 movlw .30
276 dcfsnz lo,F
277 movlw .31
278 dcfsnz lo,F
279 movlw .30
280 dcfsnz lo,F
281 movlw .31
282 cpfsgt day ; day ok?
283 bra menu_line_loop_pre1 ; OK!
284 movlw .1 ; not OK, set to 1st
285 movwf day
286
287 menu_line_loop_pre1:
288 btfsc switch_right ; Enter pressed?
289 call rtc_set_rtc ; Yes, update mins,sec,hours,day,month and year to rtc module
290 call TFT_show_time_date_menu ; Update clock
291
292 menu_line_loop_pre2:
293 bcf switch_right
294 bcf switch_left
295 btfss divemode ; Not in Divemode
296 call speed_normal
297
298 menu_line_loop_pre3:
299 extern divemode_option0_return
300 btfsc divemode ; In divemode?
301 goto divemode_option0_return ; Yes, return to it
302
303 menu_line_loop:
304 btfsc switch_right
305 bra do_line_menu ; Type dependent
306 btfsc switch_left
307 bra next_line_menu
308
309 btfss onesecupdate ; New second
310 bra menu_line_loop2 ; not yet...
311
312 call timeout_surfmode ; timeout
313 call set_dive_modes ; check, if divemode must be entered
314
315 btfsc settime_setdate ; In the Set Time or Set Date menu?
316 call TFT_show_time_date_menu ; Yes, update clock
317 btfsc menu_show_sensors ; In the "Sensors" menu?
318 call TFT_menu_hud ; Yes, update HUD data
319
320 bcf onesecupdate ; one second updates done
321
322 menu_line_loop2:
323 btfsc sleepmode ; Timeout?
324 goto restart ; Yes, back to surfacemode
325 btfsc divemode
326 goto restart ; Enter Divemode if required
327
328 btfsc enable_screen_dumps ; =1: Ignore vin_usb, wait for "l" command (Screen dump)
329 bra menu_line_loop3
330 btfsc vusb_in ; USB plugged in?
331 goto comm_mode ; Start COMM mode
332 bra menu_line_loop4
333 menu_line_loop3:
334 btfss vusb_in ; USB (still) plugged in?
335 bcf enable_screen_dumps ; No, clear flag
336 call rs232_get_byte
337 btfsc rs232_recieve_overflow
338 bra menu_line_loop4
339 movlw "l"
340 cpfseq RCREG1
341 bra menu_line_loop4
342 call TFT_dump_screen ; Dump the screen contents
343 menu_line_loop4:
344
345 bra menu_line_loop
346
347 ;---- Move to menu's next line
348 next_line_menu:
349 btfss divemode ; not in divemode
350 call speed_fastest
351 bcf switch_left ; Avoid looping.
352
353 incf selected_item,F ; Select next item.
354 movf selected_item,W ; Index == max ?
355 cpfseq item_max
356 bra menu_vertical_1 ; NO: redraw cursor.
357
358 clrf selected_item ; YES: restart for item 0.
359 bra menu_vertical_1 ; Then redraw cursor.
360
361 global do_line_menu
362 do_line_menu:
363 btfss divemode ; not in divemode
364 call speed_fastest
365 ; bcf switch_right ; Avoid looping.
366
367 decf menupos,W ; menu_processor needs 0-5...
368 btfsc divemode ; only in divemode
369 movwf selected_item
370
371 movf selected_item,W ; Read selected descriptor
372 rcall menu_read_item
373
374 movf value_type,W ; Switch on data type
375 bz menu_do_line_call ; CALL
376 dcfsnz WREG
377 bra menu_do_line_call ; STRING: do as call
378 dcfsnz WREG
379 bra menu_do_line_option ; OPTION
380 dcfsnz WREG
381 bra menu_do_line_call ; DYNAMIC: do as call
382 bra menu_line_loop_pre3 ; else do nothing...
383
384 ;---- CALL
385 menu_do_line_call:
386 rcall do_menu_item ; Same as icon menu: calculated goto.
387 rcall menu_processor_pop ; Back to same line,
388 bra menu_vertical ; Then continue into menu...
389
390 ;---- Call option specific increment subroutine
391 menu_do_line_option:
392 movff option_item+0,FSR0L ; Get option handle
393 movff option_item+1,FSR0H
394 call option_inc ; increment
395
396 movff selected_item,PRODL ; Pass selection to callback.
397 rcall menu_text_call
398 bra menu_vertical_2 ; redraw all lines...
399
400 ;-----------------------------------------------------------------------------
401
402 menu_draw_lines_divemode:
403 movlw divemode_menu_item1_row
404 movff WREG,win_top
405 movlw divemode_menu_item1_column
406 movff WREG,win_leftx2
407 clrf start_item
408 movff item_max,menupos4 ; Copy item_max for divemode cursor routine
409 bra menu_draw_lines_2
410
411 menu_draw_lines:
412 btfsc divemode ; in divemode?
413 bra menu_draw_lines_divemode ; Yes
414
415 btfsc menu_flags,0 ; Dynamic title ?
416 rcall menu_processor_title ; YES: redraw it then.
417
418 MENU_LINE_FONT MENU_LEFT, 0 ; Init start position/font
419 movff menu_center,win_top ; computed in menu block.
420
421 ; Does the menu have more than 6 lines ?
422 movf item_max,W
423 addlw -(MENU_LINES_MAX+1) ; (max - 7)
424 bnn menu_draw_long_menu ; bra if (max >= 7)
425
426 clrf start_item
427 bra menu_draw_lines_2
428
429 menu_draw_long_menu:
430 movf selected_item,W ; Start at selected-6
431 addlw -(MENU_LINES_MAX-1)
432 btfsc STATUS,N ; This is <0 ?
433 clrf WREG ; YES: start from top instead.
434 movwf start_item
435
436 menu_draw_lines_2:
437 movff start_item, menu_item
438
439 menu_draw_lines_1:
440 TFT_STD_COLOR ; Restore color after disabled lines.
441
442 movf menu_item,W
443 rcall menu_read_item
444
445 movf value_type,W ; Switch on data type
446 bz menu_draw_line_call
447 dcfsnz WREG
448 bra menu_draw_line_string
449 dcfsnz WREG
450 bra menu_draw_line_option
451 dcfsnz WREG
452 bra menu_draw_line_dynamic
453 bra menu_draw_line_none
454
455 menu_draw_line_string:
456 movff text_item+0,TBLPTRL ; Read not-translated string from PROM.
457 movff text_item+1,TBLPTRH
458 call strcpy_prom ; Copy in buffer
459 bra menu_draw_line_none
460
461 menu_draw_line_call:
462 movff text_item+0,FSR1L ; Read string from PROM.
463 movff text_item+1,FSR1H
464 call strcpy_text ; Copy in buffer
465
466 bra menu_draw_line_none
467
468 menu_draw_line_option:
469 movff text_item+0,FSR1L ; Read string from PROM.
470 movff text_item+1,FSR1H
471 call strcpy_text ; Copy in buffer
472
473 movff option_item+0,FSR0L ; Retrieve option handle.
474 movff option_item+1,FSR0H
475 call option_draw
476 bra menu_draw_line_none
477
478 menu_draw_line_dynamic:
479 lfsr FSR2,buffer
480 movff menu_item,PRODL ; Pass item to callback.
481 rcall menu_text_call ; Push return address.
482 bra menu_draw_line_none
483
484 ; Computed goto to pointer inside dynamic_item:
485 menu_text_call:
486 movf dynamic_item+0,W ; Check if callback is NULL
487 iorwf dynamic_item+1,W
488 iorwf dynamic_item+2,W
489 btfsc STATUS,Z
490 return ; YES: don't call it.
491
492 movff dynamic_item+2,PCLATU ; Prepare...
493 movff dynamic_item+1,PCLATH
494 movf dynamic_item+0,W
495 movwf PCL ; And jump !
496
497 menu_draw_line_none:
498 extern TFT_fillup_with_spaces
499
500 btfsc divemode ; In divemode?
501 bra menu_draw_line_none_divemode ; Yes
502
503 movlw MENU_LINE_MAX_LENGTH
504 call TFT_fillup_with_spaces ; Fillup FSR2 with spaces (Total string length in #WREG)
505 clrf WREG
506 movff WREG,buffer+MENU_LINE_MAX_LENGTH;No ; Make sure won't be longer than MENU_LINE_MAX_LENGTH ch
507 call aa_wordprocessor
508 movlw MENU_HEIGHT ; No, Move to next line
509 addwf win_top,F
510 incf menu_item,F ; inc loop counter
511
512 movf start_item,W ; First line (scrolled)
513 subwf menu_item,W ; current - first
514 xorlw MENU_LINES_MAX ; Already done 6 lines ?
515 btfsc STATUS,Z
516 return ; YES
517 menu_draw_line_none2:
518 movf menu_item,W ; Done item_max lines ?
519 xorwf item_max,W
520 btfss STATUS,Z
521 bra menu_draw_lines_1 ; No: loop...
522 return
523
524 menu_draw_line_none_divemode:
525 movlw .10
526 call TFT_fillup_with_spaces ; Fillup FSR2 with spaces (Total string length in #WREG)
527 clrf WREG
528 movff WREG,buffer+.10
529
530 call aa_wordprocessor ; Draw the line!
531
532 movlw .0
533 movff WREG,win_invert ; Reset invert flag
534
535 movlw .24 ; Divemode menu spacing
536 addwf win_top,F
537 incf menu_item,F ; inc loop counter
538
539 movlw .3
540 cpfseq menu_item ; At pos 4?
541 bra menu_draw_line_none2 ; No
542
543 movlw divemode_menu_item4_row
544 movff WREG,win_top ; Reset row
545 movlw divemode_menu_item4_column
546 movff WREG,win_leftx2 ; New column
547 bra menu_draw_line_none2 ; Done.
548
549 ;-----------------------------------------------------------------------------
550 ; Put a mark in front of the current line
551 menu_draw_selected_line:
552 clrf timeout_counter2 ; Reset timeout
553 WIN_BOX_BLACK .34,.221,MENU_LEFT-8,MENU_LEFT-2 ; Clear left column
554
555 TFT_STD_COLOR
556 WIN_SMALL MENU_LEFT-8, 0 ; Arrow symbol only in small font
557 movf start_item,W ; First line (scrolled)
558 subwf selected_item,W ; selected - first
559 mullw MENU_HEIGHT ; 30 pixel by line
560 movf PRODL,W ; result
561 addwf menu_center,W ; added to first line
562 movwf win_top ; and stored to pos.
563 STRCPY_PRINT "\xb7" ; print cursor
564
565 return
566
567 END