Mercurial > public > mk2
comparison code_part1/OSTC_code_asm_part1/menu_custom.asm @ 355:f49d6f0fc870
Allow negatif CF:
* CF reset table encodes signed -128/+127 values. Upates CF48.
* Display & check signed min/max bounds in cf menu.
* Adapt CF alarm for signed values.
author | JeanDo |
---|---|
date | Tue, 07 Jun 2011 03:55:30 +0200 |
parents | 6bdf80d7276c |
children | d4ca9196e830 |
comparison
equal
deleted
inserted
replaced
354:cec312042b94 | 355:f49d6f0fc870 |
---|---|
54 CF_MILI EQU 4 ; Displays 1.015 | 54 CF_MILI EQU 4 ; Displays 1.015 |
55 CF_BOOL EQU 5 ; Displays ON/OFF | 55 CF_BOOL EQU 5 ; Displays ON/OFF |
56 CF_SEC EQU 6 ; Displays 4:00 | 56 CF_SEC EQU 6 ; Displays 4:00 |
57 CF_COLOR EQU 7 ; Display 240 plus a color watch (inverse video space) | 57 CF_COLOR EQU 7 ; Display 240 plus a color watch (inverse video space) |
58 ; | 58 ; |
59 CF_TYPES EQU 0x1F | 59 CF_TYPES EQU 0x0F |
60 CF_MAX_BIT EQU 6 ; Default is the highest safe value. | 60 CF_MAX_BIT EQU 6 ; Default is the highest safe value. |
61 CF_MAX EQU (1<<CF_MAX_BIT) | 61 CF_MAX EQU (1<<CF_MAX_BIT) |
62 CF_MIN_BIT EQU 5 ; Default is the lowest safe value. | 62 CF_MIN_BIT EQU 5 ; Default is the lowest safe value. |
63 CF_MIN EQU (1<<CF_MIN_BIT) | 63 CF_MIN EQU (1<<CF_MIN_BIT) |
64 CF_NEG_BIT EQU 4 ; Allow negativ values. | |
65 CF_NEG EQU (1<<CF_NEG_BIT) | |
64 ; | 66 ; |
65 CF_INT15 EQU 0x80; Default display. Flag for 15bit, typeless values. | 67 CF_INT15 EQU 0x80; Default display. Flag for 15bit, typeless values. |
66 | 68 |
67 ; Overlay our tmp data with some unused variables. But use more | 69 ; Overlay our tmp data with some unused variables. But use more |
68 ; meaningfull labels... | 70 ; meaningfull labels... |
406 lfsr FSR2, letter | 408 lfsr FSR2, letter |
407 | 409 |
408 btfsc cf_type,7 ; A 15bit value ? | 410 btfsc cf_type,7 ; A 15bit value ? |
409 bra cf_no_min ; Don't display, hence clear line... | 411 bra cf_no_min ; Don't display, hence clear line... |
410 | 412 |
411 btfss cf_type, CF_MIN_BIT ; A min value exists ? | 413 btfss cf_type,CF_MIN_BIT ; A min value exists ? |
412 bra cf_no_min | 414 bra cf_no_min |
413 | 415 |
416 btfss cf_type,CF_NEG_BIT | |
417 bra cf_min_unsigned | |
418 | |
419 ; Uses 16bit sub for checking signed min value. | |
420 movff cf_value,sub_a+0 ; A <- value | |
421 clrf sub_a+1 | |
422 btfsc cf_value,7 ; extend sign if value < 0 | |
423 setf sub_a+1 | |
424 | |
425 movff cf_min,sub_b+0 ; B <- min (with signed extend) | |
426 setf sub_b+1 ; min have to be negativ. | |
427 call sub16 ; Compute (A-B) | |
428 | |
429 btfss neg_flag ; Result < 0 ? | |
430 bra cf_min_passed ; NO | |
431 bra cf_min_failed ; YES | |
432 | |
433 cf_min_unsigned: | |
414 movf cf_min,W ; Retrieve current 8b value | 434 movf cf_min,W ; Retrieve current 8b value |
415 subwf cf_value,W ; Compute (lo-min) | 435 subwf cf_value,W ; Compute (value-min) |
416 bc cf_min_passed ; Ok if CARRY, ie. min >= lo | 436 bc cf_min_passed ; Ok if CARRY, ie. min >= lo |
437 | |
438 cf_min_failed: | |
417 call PLED_warnings_color | 439 call PLED_warnings_color |
418 WIN_INVERT 1 | 440 WIN_INVERT 1 |
419 cf_min_passed: | 441 |
420 | 442 cf_min_passed: |
421 STRCAT "> " ; A min value follows | 443 STRCAT "> " ; A min value follows |
422 movff cf_min, lo | 444 movff cf_min, lo |
423 rcall display_formated | 445 rcall display_formated |
424 | 446 |
425 cf_no_min: | 447 cf_no_min: |
437 bra cf_no_max ; Don't display, hence clear line too... | 459 bra cf_no_max ; Don't display, hence clear line too... |
438 | 460 |
439 btfss cf_type, CF_MAX_BIT ; A max value exists ? | 461 btfss cf_type, CF_MAX_BIT ; A max value exists ? |
440 bra cf_no_max | 462 bra cf_no_max |
441 | 463 |
464 btfss cf_type,CF_NEG_BIT | |
465 bra cf_max_unsigned | |
466 | |
467 ; Uses 16bit sub for checking signed min value. | |
468 movff cf_max,sub_a+0 ; A <- max (with signed extend) | |
469 clrf sub_a+1 ; max have to be positiv. | |
470 | |
471 movff cf_value,sub_b+0 ; B <- value | |
472 clrf sub_b+1 | |
473 btfsc cf_value,7 ; extend sign if value < 0 | |
474 setf sub_b+1 | |
475 call sub16 ; Compute (A-B) | |
476 | |
477 btfss neg_flag ; Result < 0 ? | |
478 bra cf_max_passed ; NO | |
479 bra cf_max_failed ; YES | |
480 | |
481 cf_max_unsigned: | |
442 movf cf_value,W ; Retrieve current max bound | 482 movf cf_value,W ; Retrieve current max bound |
443 subwf cf_max,W ; Compute (max-lo) | 483 subwf cf_max,W ; Compute (max-lo) |
444 bc cf_max_passed ; Ok if no carry, ie. max <= lo | 484 bc cf_max_passed ; Ok if no carry, ie. max <= lo |
485 | |
486 cf_max_failed: | |
445 call PLED_warnings_color | 487 call PLED_warnings_color |
446 WIN_INVERT 1 | 488 WIN_INVERT 1 |
447 cf_max_passed: | 489 |
448 | 490 cf_max_passed: |
449 STRCAT "< " ; A max value follows | 491 STRCAT "< " ; A max value follows |
450 movff cf_max, lo | 492 movff cf_max, lo |
451 rcall display_formated | 493 rcall display_formated |
452 | 494 |
453 cf_no_max: | 495 cf_no_max: |
466 ; Input : hi:lo = data to display. | 508 ; Input : hi:lo = data to display. |
467 ; cf_type = the type. | 509 ; cf_type = the type. |
468 ; cf_min, cf_max : the optional min/max. | 510 ; cf_min, cf_max : the optional min/max. |
469 ; FSR2 = current string pointer. | 511 ; FSR2 = current string pointer. |
470 display_formated: | 512 display_formated: |
513 movf cf_type,W ; Just set N flags | |
514 bn cf_type_80 ; Keep 15bits value in old format. | |
515 | |
516 ;---- handle signed values ----------------------------------------------- | |
517 ; NOTE: only 8bit values can have a negativ flag right now. | |
518 btfss cf_type,CF_NEG_BIT ; Signed value ? | |
519 bra cf_type_unsigned ; NO: display unsigned as-is | |
520 | |
521 btfss lo,7 ; Negativ value ? | |
522 bra cf_type_pos ; NO: display positives with a + sign. | |
523 | |
524 PUTC '-' ; YES: display with a - sign. | |
525 negf lo ; and correct the said value. | |
526 bra cf_type_unsigned | |
527 | |
528 cf_type_pos: | |
529 PUTC '+' | |
471 | 530 |
472 ;---- decode type -------------------------------------------------------- | 531 ;---- decode type -------------------------------------------------------- |
473 movf cf_type,W ; Just set N/Z flags | 532 cf_type_unsigned: |
474 bn cf_type_neg ; Keep 15bits value in old format. | 533 ; Jump table: ; test the value with cleared flags... |
475 andlw CF_TYPES ; Look just at types | 534 movf cf_type,W |
535 andlw CF_TYPES ; Look just at types | |
476 bz cf_type_00 ; 8bit standard mode | 536 bz cf_type_00 ; 8bit standard mode |
477 | 537 |
478 ; Jump table: ; test the value with cleared flags... | |
479 dcfsnz WREG | 538 dcfsnz WREG |
480 bra cf_type_01 | 539 bra cf_type_01 |
481 dcfsnz WREG | 540 dcfsnz WREG |
482 bra cf_type_02 | 541 bra cf_type_02 |
483 dcfsnz WREG | 542 dcfsnz WREG |
555 | 614 |
556 cf_type_00: ; 8bit mode. Or unrecognized type... | 615 cf_type_00: ; 8bit mode. Or unrecognized type... |
557 clrf hi | 616 clrf hi |
558 bsf leftbind | 617 bsf leftbind |
559 | 618 |
560 cf_type_neg: ; 15bit mode. | 619 cf_type_80: ; 15bit mode. |
561 bcf hi,7 | 620 bcf hi,7 |
562 output_16 | 621 output_16 |
563 retlw 0 | 622 retlw 0 |
564 | 623 |
565 ;----------------------------------------------------------------------------- | 624 ;----------------------------------------------------------------------------- |
819 rcall getcustom8_1 ; Read into WREG | 878 rcall getcustom8_1 ; Read into WREG |
820 movwf lo ; Save it. | 879 movwf lo ; Save it. |
821 | 880 |
822 btfss cf_type,CF_MIN_BIT | 881 btfss cf_type,CF_MIN_BIT |
823 bra check_no_min | 882 bra check_no_min |
824 | 883 |
884 btfss cf_type,CF_NEG_BIT | |
885 bra check_min_unsigned | |
886 | |
887 ; Uses 16bit sub for checking signed min value. | |
888 movff lo,sub_a+0 ; A <- value | |
889 clrf sub_a+1 | |
890 btfsc cf_value,7 ; extend sign if value < 0 | |
891 setf sub_a+1 | |
892 | |
893 movff cf_min,sub_b+0 ; B <- min (with signed extend) | |
894 setf sub_b+1 ; min have to be negativ. | |
895 call sub16 ; Compute (A-B) | |
896 | |
897 btfss neg_flag ; Result < 0 ? | |
898 bra check_no_min ; NO | |
899 retlw 0 ; YES = FAILED | |
900 | |
901 check_min_unsigned: | |
825 cpfsgt cf_min ; Compare to cf_min | 902 cpfsgt cf_min ; Compare to cf_min |
826 bra check_no_min ; PASSED: continue. | 903 bra check_no_min ; PASSED: continue. |
827 retlw 0 ; NO: return failed. | 904 retlw 0 ; NO: return failed. |
828 | 905 |
829 check_no_min: | 906 check_no_min: |
830 btfss cf_type,CF_MAX_BIT ; Is there a MAX bound ? | 907 btfss cf_type,CF_MAX_BIT ; Is there a MAX bound ? |
831 retlw -1 ; No check: return OK. | 908 retlw -1 ; No check: return OK. |
832 | 909 |
910 btfss cf_type,CF_NEG_BIT | |
911 bra check_max_unsigned | |
912 | |
913 ; Uses 16bit sub for checking signed min value. | |
914 movff cf_max,sub_a+0 ; A <- max (with signed extend) | |
915 clrf sub_a+1 ; max have to be positiv. | |
916 | |
917 movff lo,sub_b+0 ; B <- value | |
918 clrf sub_b+1 | |
919 btfsc cf_value,7 ; extend sign if value < 0 | |
920 setf sub_b+1 | |
921 call sub16 ; Compute (A-B) | |
922 | |
923 btfss neg_flag ; Result < 0 ? | |
924 retlw -1 ; NO | |
925 retlw 0 ; YES | |
926 | |
927 check_max_unsigned: | |
833 movf lo,W ; Compute value-max | 928 movf lo,W ; Compute value-max |
834 cpfslt cf_max | 929 cpfslt cf_max |
835 retlw -1 ; Bound met: return OK. | 930 retlw -1 ; Bound met: return OK. |
836 retlw 0 ; NO: return failed. | 931 retlw 0 ; NO: return failed. |