printi16.asm 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #include once <printnum.asm>
  2. #include once <div16.asm>
  3. #include once <neg16.asm>
  4. #include once <attr.asm>
  5. ;
  6. __PRINTI16: ; Prints a 16bits signed in HL
  7. ; Converts 16 to 32 bits
  8. ;- PROC
  9. ;- LOCAL __PRINTU_LOOP
  10. lda z80_h ;- ld a,h
  11. sta z80_a
  12. ora z80_a ;- or a
  13. jpl __PRINTU16 ;- jp p, __PRINTU16
  14. jsr __PRINT_MINUS ;- call __PRINT_MINUS
  15. jsr __NEGHL ;- call __NEGHL
  16. __PRINTU16:
  17. lda %0 ;- ld b,0
  18. sta z80_b
  19. __PRINTU_LOOP:
  20. lda z80_h ;- ld a,h
  21. sta z80_a
  22. ora z80_l ;- or l
  23. jeq __PRINTU_START ;- jp z, __PRINTU_START
  24. lda z80_c ;- push bc
  25. pha
  26. lda z80_b
  27. pha
  28. lda #<10 ;- ld de,10
  29. sta z80_e
  30. lda #>10
  31. sta z80_d
  32. jsr __DIVU16_FAST ;- call __DIVU16_FAST ; Divides by DE. DE = MODULUS at exit. Since < 256, E = Modulus
  33. pla ;- pop bc
  34. sta z80_b
  35. pla
  36. sta z80_c
  37. lda z80_e ;- ld a,e
  38. sta z80_a
  39. ora #$30 ;- or '0' ; Stores ASCII digit (must be print in reversed order)
  40. pha ;- push af
  41. php
  42. inc z80_b ;- inc b
  43. jmp __PRINTU_LOOP ;- jp __PRINTU_LOOP ; Uses JP in loops
  44. ;- ENDP