home *** CD-ROM | disk | FTP | other *** search
/ ftp.barnyard.co.uk / 2015.02.ftp.barnyard.co.uk.tar / ftp.barnyard.co.uk / cpm / walnut-creek-CDROM / CPM / TURBODSG / HXDC24.MAC < prev    next >
Text File  |  2000-06-30  |  3KB  |  110 lines

  1. .comment \
  2.  
  3. HXDC24 module by ESKAY 08-21-84
  4.  
  5. HXDC24 converts a 24 bit number in EHL and stores it at (IX)
  6. on exit, IX points to the byte following the 8-digit number,
  7. all other registers are undefined.
  8.  
  9. This module is in the Public Domain and may be used, improved,
  10. updated and otherwise treated as necessary for any particular
  11. application. This module may be used freely in commercial
  12. programming but may not be sold as an individual component.
  13.  
  14. There are 4 modes of operation supported, as determined by the contents
  15. of the accumulator on entry:
  16.  
  17. A = 0    raw conversion with leading zeroes
  18. A = 1    conversion with no leading zeroes
  19. A = 2    conversion with leading zeroes and commas as thousands dividers
  20. A = 3    conversion with no leading zeroes, with commas
  21.  
  22.     (bits 0 and 1 are used, all others are insignificant)
  23.  
  24.     Have fun displaying 24-bit numbers!
  25.  
  26. \
  27. .z80
  28. ;
  29.     public    hxdc24
  30. ;
  31. hxdc24:    ld    (flag),a    ;save the mode flag
  32.     ld    bc,6980h    ;-10,000,000
  33.     ld    d,67h
  34.     call    mkdec        ;make tens of millions
  35.     ld    bc,0bdc0h    ;-1,000,000
  36.     ld    d,0f0h
  37.     call    mkdec        ;make millions
  38.     ld    a,(flag)
  39.     bit    0,a        ;if commas flag reset...
  40.     jr    z,skc        ;then skip commas
  41.     call    putcm        ;  else may need a comma
  42. skc:    ld    bc,7960h    ;-100,000
  43.     ld    d,0feh
  44.     call    mkdec        ;make hundreds of thousands
  45.     ld    bc,-10000
  46.     ld    d,0ffh
  47.     call    mkdec        ;make tens of thousands
  48.     ld    bc,-1000
  49.     call    mkdec        ;make thousands (D reg is preserved FF)
  50.     ld    a,(flag)
  51.     bit    0,a        ;if commas flag reset...
  52.     jr    z,skc1        ;then skip commas
  53.     call    putcm        ;  else may need a comma
  54. skc1:    ld    bc,-100
  55.     call    mkdec        ;make hundreds
  56.     ld    bc,-10
  57.     call    mkdec        ;make tens
  58.     ld    bc,-1
  59.     call    mkdec        ;make units
  60. ;    ret    nz
  61. ;    ld    a,'0'
  62. ;    call    putcx
  63.     ret
  64. ;
  65. mkdec:    ld    iy,-1        ;set up counter
  66. mkdecl:    ld    (hltmp),hl    ;save intermediate result
  67.     ld    (detmp),de
  68.     inc    iy
  69.     add    hl,bc        ;subtract DBC from EHL until carry...
  70.     ld    a,e        ;...IY then has the decimal digit
  71.     adc    a,d
  72.     ld    e,a
  73.     jr    c,mkdecl
  74.     ld    hl,(hltmp)    ;restore intermediate result
  75.     ld    de,(detmp)
  76.     push    iy        ;get IY into BC
  77.     pop    bc
  78.     push    hl        ;save HL
  79.     ld    hl,flag        ;get flag byte
  80.     ld    a,c        ;if digit <> 0...
  81.     or    a
  82.     jr    nz,doput    ;...then put it out...
  83.     bit    1,(hl)        ;...else if zero suppress...
  84.     jr    nz,nozer    ;...then skip
  85. doput:    res    1,(hl)        ;once we have a non-zero, suppress flag is off
  86.     add    a,'0'        ;make ascii digit
  87.     call    putcx        ;put it away at (IX)
  88. nozer:    pop    hl        ;restore hl
  89.     ret
  90. ;
  91. ; conditional comma output
  92. ; make comma only if preceded by a digit
  93. ;
  94. putcm:    ld    a,(flag)
  95.     bit    1,a        ;if flag bit 1 is on...
  96.     ret    nz        ;...then leading zeroes being suppressed...
  97.     ld    a,','        ;else output comma
  98. ;
  99. ; store A at (IX) and increment pointer
  100. ;
  101. putcx:    ld    (ix+0),a
  102.     inc    ix
  103.     ret
  104. ;
  105. hltmp:    dw    0        ;temporary storage
  106. detmp:    dw    0
  107. flag:    db    0        ;mode flag byte
  108.     end
  109. ),hl    ;save intermediate result
  110.