?login_element?

Subversion Repositories NedoOS

Rev

Blame | Last modification | View Log | Download

  1. #ifndef included_ascii_to_BCD
  2. #define included_ascii_to_BCD
  3.  
  4. #ifndef TOK_DECIMAL
  5. #ifdef TOK_DECIMAL
  6. #define TOK_DECIMAL TOK_DECIMAL
  7. #else
  8. #define TOK_DECIMAL '.'
  9. #endif
  10. #endif
  11.  
  12. ascii_to_BCD:
  13. ;Inputs:
  14. ;   HL points to the next digit to read in
  15. ;   B is the base-10 exponent
  16. ;   carry flag is set if we shouldn't increment the exponent
  17. ;Outputs:
  18. ;   HL is advanced as needed (not necessarily by 2)
  19. ;   A is the next BCD byte
  20. ;   carry is set if it was already set initially, or if a decimal was reached,
  21. ;   or if a non-numeric character was reached, otherwise, carry remains reset.
  22. ;Destroys:
  23. ;   C
  24.   jr c,ascii_to_BCD_noexp
  25.   ld a,(hl)
  26.   cp TOK_DECIMAL
  27.   jr z,ascii_to_BCD_decimal_found1
  28.   cp '0'
  29.   jr c,ascii_to_BCD_done1
  30.   cp '9'+1
  31.   jr nc,ascii_to_BCD_done1
  32.   inc hl
  33.   inc b
  34.   add a,a
  35.   add a,a
  36.   add a,a
  37.   add a,a
  38.   ld c,a
  39.  
  40.   ld a,(hl)
  41.   cp TOK_DECIMAL
  42.   jr z,ascii_to_BCD_decimal_found2
  43.   cp '0'
  44.   jr c,ascii_to_BCD_done2
  45.   cp '9'+1
  46.   jr nc,ascii_to_BCD_done2
  47.   inc hl
  48.   inc b
  49.   and %00001111
  50.   or c
  51.   ret
  52.  
  53. ascii_to_BCD_done1:
  54.   xor a
  55.   scf
  56.   ret
  57. ascii_to_BCD_done2:
  58.   ld a,c
  59.   scf
  60.   ret
  61.  
  62. ascii_to_BCD_decimal_found1:
  63.   inc hl
  64. ascii_to_BCD_noexp:
  65.   ld a,(hl)
  66.   cp '0'
  67.   jr c,ascii_to_BCD_done1
  68.   cp '9'+1
  69.   jr nc,ascii_to_BCD_done1
  70.   add a,a
  71.   add a,a
  72.   add a,a
  73.   add a,a
  74.   ld c,a
  75.  
  76. ascii_to_BCD_decimal_found2:
  77.   inc hl
  78.   ld a,(hl)
  79.   cp '0'
  80.   jr c,ascii_to_BCD_done2
  81.   cp '9'+1
  82.   jr nc,ascii_to_BCD_done2
  83.   inc hl
  84.   and %00001111
  85.   or c
  86.   scf
  87.   ret
  88. #endif
  89.