printi32.asm 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. #include once <printnum.asm>
  2. #include once <neg32.asm>
  3. #include once <div32.asm>
  4. #include once <attr.asm>
  5. ;
  6. __PRINTI32:
  7. lda z80_d ;- ld a,d
  8. sta z80_a
  9. ora z80_a ;- or a
  10. ;- jp p, __PRINTU32
  11. jsr __PRINT_MINUS ;- call __PRINT_MINUS
  12. jsr __NEG32 ;- call __NEG32
  13. __PRINTU32:
  14. ;- PROC
  15. ;- LOCAL __PRINTU_LOOP
  16. lda %0 ;- ld b,0 ; Counter
  17. sta z80_b
  18. __PRINTU_LOOP:
  19. lda z80_h ;- ld a,h
  20. sta z80_a
  21. ora z80_l ;- or l
  22. ora z80_d ;- or d
  23. ora z80_e ;- or e
  24. jeq __PRINTU_START ;- jp z, __PRINTU_START
  25. lda z80_c ;- push bc
  26. pha
  27. lda z80_b
  28. pha
  29. lda #<0 ;- ld bc,0
  30. sta z80_c
  31. lda #>0
  32. sta z80_b
  33. lda z80_c ;- push bc
  34. pha
  35. lda z80_b
  36. pha
  37. lda #<10 ;- ld bc,10
  38. sta z80_c
  39. lda #>10
  40. sta z80_b
  41. lda z80_c ;- push bc ; Push 00 0A (10 Dec) into the stack = divisor
  42. pha
  43. lda z80_b
  44. pha
  45. jsr __DIVU32 ;- call __DIVU32 ; Divides by 32. D'E'H'L' contains modulo (L' since < 10)
  46. pla ;- pop bc
  47. sta z80_b
  48. pla
  49. sta z80_c
  50. lda z80_c ;- exx
  51. ldx z80_cp
  52. stx z80_c
  53. sta z80_cp
  54. lda z80_b
  55. ldx z80_bp
  56. stx z80_b
  57. sta z80_bp
  58. lda z80_e
  59. ldx z80_ep
  60. stx z80_e
  61. sta z80_ep
  62. lda z80_d
  63. ldx z80_dp
  64. stx z80_d
  65. sta z80_dp
  66. lda z80_l
  67. ldx z80_lp
  68. stx z80_l
  69. sta z80_lp
  70. lda z80_h
  71. ldx z80_hp
  72. stx z80_h
  73. sta z80_hp
  74. lda z80_l ;- ld a,l
  75. sta z80_a
  76. ;- or '0' ; Stores ASCII digit (must be print in reversed order)
  77. pha ;- push af
  78. php
  79. lda z80_c ;- exx
  80. ldx z80_cp
  81. stx z80_c
  82. sta z80_cp
  83. lda z80_b
  84. ldx z80_bp
  85. stx z80_b
  86. sta z80_bp
  87. lda z80_e
  88. ldx z80_ep
  89. stx z80_e
  90. sta z80_ep
  91. lda z80_d
  92. ldx z80_dp
  93. stx z80_d
  94. sta z80_dp
  95. lda z80_l
  96. ldx z80_lp
  97. stx z80_l
  98. sta z80_lp
  99. lda z80_h
  100. ldx z80_hp
  101. stx z80_h
  102. sta z80_hp
  103. inc z80_b ;- inc b
  104. jmp __PRINTU_LOOP ;- jp __PRINTU_LOOP ; Uses JP in loops
  105. ;- ENDP