Advertisement
Zeda

text_len

Aug 27th, 2019
741
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ;Optimized from E37's routine
  2.  
  3. text_len:
  4. ;finds the length in pixels the string
  5. ;inputs:
  6. ;   hl = zero terminated string
  7. ;returns:
  8. ;   de = length of the string in pixels
  9.  
  10.    ld   bc, 0
  11.  
  12. text_len_max:
  13. ;inputs:
  14. ;   hl = zero terminated string
  15. ;   bc = maximum number of characters (it will stop after hl characters or when 0 is reached, whichever comes first)
  16. ;returns:
  17. ;   de = length of the string in pixels
  18.  
  19.   xor a
  20.   ld d,a
  21.   ld e,a
  22. TextRLoop:
  23.    or   (hl)
  24.    ret   z
  25. ;   push   bc
  26.    push   hl
  27.    push   de
  28.  
  29.    call   get_sFont_custom    ;preserves BC
  30.    xor   a
  31.    ld   l, (hl)
  32.    ld   h, a
  33.    pop   de
  34.    add   hl, de
  35.    ex    de,hl
  36.  
  37.    pop   hl
  38. ;   pop   bc
  39.    cpi
  40.    jp    pe, TextRLoop
  41.    ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement