Mirror of CollapseOS
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
706B

  1. ; Format the number in DE into the string at (HL) in a decimal form.
  2. ; Null-terminated. DE is considered an unsigned number.
  3. fmtDecimal:
  4. push ix
  5. push hl
  6. push de
  7. push af
  8. push hl \ pop ix
  9. ex de, hl ; orig number now in HL
  10. ld e, 0
  11. .loop1:
  12. call .div10
  13. push hl ; push remainder. --> lvl E
  14. inc e
  15. ld a, b ; result 0?
  16. or c
  17. push bc \ pop hl
  18. jr nz, .loop1 ; not zero, continue
  19. ; We now have C digits to print in the stack.
  20. ; Spit them!
  21. push ix \ pop hl ; restore orig HL.
  22. ld b, e
  23. .loop2:
  24. pop de ; <-- lvl E
  25. ld a, '0'
  26. add a, e
  27. ld (hl), a
  28. inc hl
  29. djnz .loop2
  30. ; null terminate
  31. xor a
  32. ld (hl), a
  33. pop af
  34. pop de
  35. pop hl
  36. pop ix
  37. ret
  38. .div10:
  39. push de
  40. ld de, 0x000a
  41. call divide
  42. pop de
  43. ret