home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 23 / IOPROG_23.ISO / SOFT / ASM / BCDASM.ZIP / BCDASM / DOC / BCDAPI.TXT < prev    next >
Encoding:
Text File  |  1997-06-03  |  26.5 KB  |  924 lines

  1.  
  2.  
  3. -----------------
  4. FILE : BCDABS.ASM
  5. -----------------
  6.  
  7. ;//////////////////////////////////////////////////////////////////////
  8. ;//    Name    bcdAbs
  9. ;//    Desc    Find absolute value of a packed signed BCD.
  10. ;//
  11. ;//
  12. ;//    Entry    Passed args
  13. ;//    Exit    Destination = abs(destination).
  14. ;//        Acc undefined.
  15.  
  16. bcdAbs    proc
  17. arg    dstBCD    :dataptr, \    ; Addr of BCD
  18.     dstsz    :@uint        ; Byte size of BCD
  19.  
  20.  
  21. -----------------
  22. FILE : BCDADD.ASM
  23. -----------------
  24.  
  25. ;//////////////////////////////////////////////////////////////////////
  26. ;//    Name    bcdAdd
  27. ;//    Desc    Add two packed signed BCD numbers (dest += src).
  28. ;//
  29. ;//
  30. ;//    Entry    Passed args
  31. ;//    Exit    Packed signed BCD sum returned to destination.
  32. ;//        Accumulator (and sf,zf,cf flags) determined:
  33. ;//        Acc = 0: No carry
  34. ;//        Acc = 1: Carry (overflow)
  35. ;//
  36. ;//    Note    Destination and source may be the same.
  37.  
  38. bcdAdd    proc
  39. arg    dstBCD    :dataptr, \    ; Addr of 1st addend (=result)
  40.     srcBCD    :dataptr, \    ; Addr of 2nd addend
  41.     BCDsz    :@uint        ; Byte size of each BCD
  42.  
  43.  
  44. ;//////////////////////////////////////////////////////////////////////
  45. ;//    Name    bcdSub
  46. ;//    Desc    Subtract two packed signed BCD numbers (dest -= src).
  47. ;//
  48. ;//
  49. ;//    Entry    Passed args
  50. ;//    Exit    Packed signed BCD difference returned to destination.
  51. ;//        Accumulator (and sf,zf,cf flags) determined:
  52. ;//        Acc = 0: No borrow
  53. ;//        Acc = 1: Borrow (overflow)
  54. ;//
  55. ;//    Note    Destination and source may be the same
  56.     @alignn
  57. bcdSub    proc
  58. arg    dstBCD    :dataptr, \    ; Addr of minuend (=result)
  59.     srcBCD    :dataptr, \    ; Addr of subtrahend
  60.     BCDsz    :@uint        ; Byte size of each BCD
  61.  
  62.  
  63. -------------------
  64. FILE : BCDBE2LE.ASM
  65. -------------------
  66.  
  67. ;//////////////////////////////////////////////////////////////////////
  68. ;//    Name    bcdBe2le
  69. ;//    Desc    Convert packed signed BCD from big-endian format
  70. ;//        to little-endian format.
  71. ;//
  72. ;//
  73. ;//    Entry    Passed args
  74. ;//    Exit    Packed signed little-endian BCD returned to destination
  75. ;//        Acc undefined.
  76. ;//
  77. ;//    Note    Destination and source *cannot* overlap.
  78. ;//
  79. ;//        Little-endian format stores the least-significant byte
  80. ;//        lowest in memory (the usual on Intel PCs).
  81.  
  82. bcdBe2le proc
  83. arg    dstBCD    :dataptr, \    ; Addr of destination BCD storage
  84.     srcBCD    :dataptr, \    ; Addr of source big-endian BCD
  85.     srcsz    :@uint        ; Byte size of each BCD
  86.  
  87.  
  88. ;//////////////////////////////////////////////////////////////////////
  89. ;//    Name    bcdLe2be
  90. ;//    Desc    Convert packed signed BCD from little-endian format
  91. ;//        to big-endian format.
  92. ;//
  93. ;//
  94. ;//    Entry    Passed args
  95. ;//    Exit    Packed signed big-endian BCD returned to destination.
  96. ;//        Acc undefined.
  97. ;//
  98. ;//    Note    Destination and source *cannot* overlap.
  99.  
  100. bcdLe2be proc
  101. arg    dstBCD    :dataptr, \    ; Addr of destination BCD storage
  102.     srcBCD    :dataptr, \    ; Addr of source little-endian BCD
  103.     srcsz    :@uint        ; Byte size of each BCD
  104.  
  105.  
  106. -----------------
  107. FILE : BCDCMP.ASM
  108. -----------------
  109.  
  110. ;//////////////////////////////////////////////////////////////////////
  111. ;//    Name    bcdCmp
  112. ;//    Desc    Compare two packed signed BCD numbers.
  113. ;//
  114. ;//
  115. ;//    Entry    Passed args
  116. ;//    Exit    Accumulator (and cf,zf,sf flags) set according to the
  117. ;//        (string) comparison: BCD1st - BCD2nd
  118. ;//        Acc = -1:  1st < 2nd
  119. ;//        Acc =  0:  1st = 2nd
  120. ;//        Acc = +1:  1st > 2nd
  121. ;//
  122. ;//    Note    Unlike bcdSub, this procedure returns the result based
  123. ;//        on a string comparison of the operands.
  124.  
  125. bcdCmp    proc
  126. arg    BCD1st    :dataptr, \    ; Addr of 1st BCD
  127.     BCD2nd    :dataptr, \    ; Addr of 2nd BCD
  128.     BCDsz    :@uint        ; Byte size of each BCD
  129.  
  130.  
  131. ------------------
  132. FILE : BCDCMPZ.ASM
  133. ------------------
  134.  
  135. ;//////////////////////////////////////////////////////////////////////
  136. ;//    Name    bcdCmpz
  137. ;//    Desc    Compare a packed signed BCD number against zero.
  138. ;//
  139. ;//
  140. ;//    Entry    Passed args
  141. ;//    Exit    Accumulator (and cf,zf,sf flags) determined:
  142. ;//        Acc = -1: Number is negative
  143. ;//        Acc =  0: Number is zero
  144. ;//        Acc = +1: Number is positive
  145. ;//
  146. ;//    Note    Disregards sign of zero.
  147.  
  148. bcdCmpz proc
  149. arg    dstBCD    :dataptr, \    ; Addr of BCD
  150.     dstsz    :@uint        ; Byte size of BCD
  151.  
  152.  
  153. -----------------
  154. FILE : BCDFMT.ASM
  155. -----------------
  156.  
  157. ;//////////////////////////////////////////////////////////////////////
  158. ;//    Name    bcdFmt
  159. ;//    Desc    Format a packed signed BCD for Ascii output.
  160. ;//        (Write BCD to string.)
  161. ;//
  162. ;//
  163. ;//    Entry    Passed args
  164. ;//        - pass (-1) to use default value (see below)
  165. ;//        - width defaults to string length (may expand
  166. ;//          to strsz-1)
  167. ;//        - numDec indicates how many decimals the BCD has
  168. ;//          (decimal dot moves left by numDec positions)
  169. ;//        - prec indicates how many decimals to output
  170. ;//        - for positive numbers/zero, signCh can be
  171. ;//          ' ' to replace '+', or 00h to suppress '+'
  172. ;//        - fillCh can be in range 21h..7Fh to replace
  173. ;//          ' ' as string fill character
  174. ;//        - sepMCh can be 00h to suppress grouping by 1000's
  175. ;//
  176. ;//    Exit    Zero-ended Ascii string returned to destination buffer.
  177. ;//        Acc = string length (0 if bad args or string exceeds
  178. ;//        destination's size)
  179. ;//
  180. ;//    Note    Here's the number -123456789012 in various formats:
  181. ;//        ;0----+----1----+----2    (w=width, nD=numDec)
  182. ;//        "    123,456,789,012-"    w 20
  183. ;//        "   1,234,567,890.12-"    w 20, nD 2
  184. ;//        "1,234,567,890.12-"    w -1, nD 2
  185. ;//        "1234567890.12-"    w -1, nD 2, sepMCh 0
  186. ;//        "1234.56789012-   "    w 17, nD 8, sepMCh 0, rtJust 0
  187. ;//        "        1,234.57-"    w 17, nD 8, prec 2
  188. ;//        "        0.001235-"    w 17, nD 14, prec 6
  189. ;//        "12.3456789012000-"     w 17, nD 10, prec 13
  190. ;//        " 0.0123456789012000-"  w 20, nD 13, prec 16
  191.  
  192. bcdFmt    proc
  193. arg    pStr    :dataptr, \    ; Addr of Ascii result buffer
  194.     strsz    :@uint, \     ; Byte size of buffer   (min. width+1)
  195.     pBCD    :dataptr, \    ; Addr of packed signed BCD
  196.     bcdsz    :@uint, \    ; Byte size of BCD
  197.     width    :@uint, \    ; Field width        (default: length)
  198.     numDec    :@uint, \    ; Number of decimals   (default: zero)
  199.     prec    :@uint, \    ; Decimals to output    (default: all)
  200.     rtJust    :byte, \    ; Right justify     (default: yes)
  201.     signCh    :byte, \    ; Sign character (default: '+' or '-')
  202.     fillCh    :byte, \    ; Fill character    (default: ' ')
  203.     sepCh    :byte, \    ; Decimal separator    (default: '.')
  204.     sepMCh    :byte        ; Thousands separator    (default: ',')
  205.  
  206.  
  207. ------------------
  208. FILE : BCDIDIV.ASM
  209. ------------------
  210.  
  211. ;//////////////////////////////////////////////////////////////////////
  212. ;//    Name    bcdIdiv
  213. ;//    Desc    Signed division and modulo of two packed signed BCDs
  214. ;//        (lo(dst) = dst / src,  hi(dst) = dst % src)
  215. ;//
  216. ;//
  217. ;//    Entry    Passed args (see note)
  218. ;//    Exit    Acc > 0:
  219. ;//          Low (destination) = packed signed BCD quotient
  220. ;//          high(destination) = packed signed BCD remainder
  221. ;//          replacing the dividend.
  222. ;//          The byte size of each of these results is half the
  223. ;//          size of the original destination operand.
  224. ;//
  225. ;//          The sign of the quotient is determined from the
  226. ;//          signs of divisor and dividend.
  227. ;//          The remainder keeps the sign of the dividend.
  228. ;//
  229. ;//        Acc = 0:
  230. ;//          Error: division by zero or overflow (result would
  231. ;//          exceed destination's size); in these cases, the
  232. ;//          dividend is unchanged.
  233. ;//
  234. ;//
  235. ;//    Note    Before calling this procedure, both operands must be
  236. ;//        scaled to double-size, for example after a call to
  237. ;//        bcdImul (dividend) or bcdSx (divisor) both of which
  238. ;//        create a double-size packed signed BCD result.
  239. ;//        The most-significant half of the divisor must not
  240. ;//        contain any significant BCD digits (i.e. all zeros,
  241. ;//        except for the sign bit).
  242. ;//
  243. ;//        The divisor is left unchanged by this procedure (but
  244. ;//        provides temporary work space used during execution).
  245. ;//
  246. ;//
  247. ;//    ToDo    Write wrapper to make 'bcdMod' procedure.
  248.  
  249. bcdIdiv proc            ; NZB = non-zero byte ('MSB')
  250. arg    dstBCD    :dataptr, \    ; Addr of dividend (size = srcsz)
  251.     srcBCD    :dataptr, \    ; Addr of divisor
  252.     srcsz    :@uint        ; Byte size of divisor (see note)
  253.  
  254.  
  255. ------------------
  256. FILE : BCDIMUL.ASM
  257. ------------------
  258.  
  259. ;//////////////////////////////////////////////////////////////////////
  260. ;//    Name    bcdImul
  261. ;//    Desc    Signed multiplication of two packed signed BCDs.
  262. ;//
  263. ;//
  264. ;//    Entry    Passed args
  265. ;//    Exit    Double-size packed signed BCD product returned to
  266. ;//        destination _replacing_ the multiplicand.
  267. ;//        Acc undefined.
  268. ;//
  269. ;//    Note    Both BCD operands must be defined as double-size, e.g.
  270. ;//            mplic  dt 456512,?
  271. ;//            mplier dt 888644,?
  272. ;//        where the high-order is undefined (because the result
  273. ;//        is returned as double-precision and the multiplier
  274. ;//        provides temporary work space for this procedure).
  275. ;//
  276. ;//        Destination and source may be the same.
  277. ;//
  278. ;//    Note    This procedure was inspired by:
  279. ;//        MPMUL1.ASM by Ray Duncan * PC Magazine Vol. 8 no. 20
  280. ;//        Copyright (C) 1989 Ziff Davis Communications
  281. ;//
  282. ;//
  283. ;//    ToDo    Rewrite loop to skip non-significant zeros.
  284.  
  285. bcdImul proc
  286. arg    dstBCD    :dataptr, \    ; Addr of multiplicand
  287.     srcBCD    :dataptr, \    ; Addr of multiplier
  288.     srcsz    :@uint        ; Byte size of each BCD (double-size)
  289.  
  290.  
  291. -------------------
  292. FILE : BCDISBCD.ASM
  293. -------------------
  294.  
  295. ;//////////////////////////////////////////////////////////////////////
  296. ;//    Name    bcdIsbcd
  297. ;//    Desc    Validate the format of a packed signed BCD number,
  298. ;//        i.e. does it contain non-BCD digits.
  299. ;//
  300. ;//
  301. ;//    Entry    Passed args
  302. ;//    Exit    Acc = 0: Error, contains non-BCD digit(s)
  303. ;//        Acc > 0: No error
  304. ;//
  305. ;//    Note    A packed BCD number stored by the FPU (using the
  306. ;//        FBSTP instruction) may contain 0FFh in the sign byte,
  307. ;//        indicating that the number is a 'BCD indefinite'.
  308. ;//        This function does not flag this as an error (assuming
  309. ;//        it is handled by an FPU exception handler routine),
  310. ;//        and accepts any value in the sign byte.
  311.  
  312. bcdIsbcd proc
  313. arg    srcBCD    :dataptr, \    ; Addr of BCD
  314.     srcsz    :@uint        ; Byte size of BCD
  315.  
  316.  
  317. ----------------
  318. FILE : BCDLD.ASM
  319. ----------------
  320.  
  321. ;//////////////////////////////////////////////////////////////////////
  322. ;//    Name    bcdLdz
  323. ;//    Desc    Load zero as a packed BCD value.
  324. ;//
  325. ;//
  326. ;//    Entry    Passed args
  327. ;//    Exit    Destination = zero. Acc undefined.
  328.  
  329. bcdLdz    proc
  330. arg    dstBCD    :dataptr, \    ; Addr of destination BCD
  331.     dstsz    :@uint        ; Byte size of dest.
  332.  
  333.  
  334. ;//////////////////////////////////////////////////////////////////////
  335. ;//    Name    bcdLd1
  336. ;//    Desc    Load +1 as a packed signed BCD value.
  337. ;//
  338. ;//
  339. ;//    Entry    Passed args
  340. ;//    Exit    Destination = +1. Acc undefined.
  341.  
  342. bcdLd1    proc
  343. arg    dstBCD    :dataptr, \    ; Addr of destination BCD
  344.     dstsz    :@uint        ; Byte size of dest.
  345.  
  346.  
  347. ;//////////////////////////////////////////////////////////////////////
  348. ;//    Name    bcdLd100
  349. ;//    Desc    Load +100 (decimal) as a packed signed BCD value.
  350. ;//
  351. ;//
  352. ;//    Entry    Passed args
  353. ;//    Exit    Destination = +100. Acc undefined.
  354.  
  355. bcdLd100 proc
  356. arg    dstBCD    :dataptr, \    ; Addr of destination BCD
  357.     dstsz    :@uint        ; Byte size of dest.
  358.  
  359.  
  360. -----------------
  361. FILE : BCDMOV.ASM
  362. -----------------
  363.  
  364. ;//////////////////////////////////////////////////////////////////////
  365. ;//    Name    bcdMov
  366. ;//    Desc    Move (copy) a packed BCD value.
  367. ;//
  368. ;//
  369. ;//    Entry    Passed args
  370. ;//    Exit    Destination = source. Acc undefined.
  371.  
  372. bcdMov    proc
  373. arg    dstBCD    :dataptr, \    ; Addr of destination BCD (size=srcsz)
  374.     srcBCD    :dataptr, \    ; Addr of source BCD
  375.     srcsz    :@uint        ; Byte size of source BCD
  376.  
  377.  
  378. -----------------
  379. FILE : BCDNEG.ASM
  380. -----------------
  381.  
  382. ;//////////////////////////////////////////////////////////////////////
  383. ;//    Name    bcdNeg
  384. ;//    Desc    Reverse the sign of a packed signed BCD number.
  385. ;//
  386. ;//
  387. ;//    Entry    Passed args
  388. ;//    Exit    Accumulator (and cf,zf,sf flags) determined:
  389. ;//        Acc = -1: Number became negative
  390. ;//        Acc =  0: Number is zero
  391. ;//        Acc = +1: Number became positive
  392. ;//
  393. ;//    Note    Disregards sign of zero.
  394.  
  395. bcdNeg    proc
  396. arg    dstBCD    :dataptr, \    ; Addr of BCD
  397.     dstsz    :@uint        ; Byte size of BCD
  398.  
  399.  
  400. -----------------
  401. FILE : BCDP2A.ASM
  402. -----------------
  403.  
  404. ;//////////////////////////////////////////////////////////////////////
  405. ;//    Name    bcdA2p
  406. ;//    Desc    Convert decimal Ascii string to packed signed BCD.
  407. ;//        String format: [whitespace][sign]digits
  408. ;//        Digit parsing stops at 1st non-digit.
  409. ;//
  410. ;//
  411. ;//    Entry    Passed args
  412. ;//    Exit    Packed signed BCD returned to destination.
  413. ;//        Acc = 0: error: bad digits/overflow (dest. = zero)
  414. ;//        Acc > 0: no errors
  415.  
  416. bcdA2p    proc
  417. arg    dstBCD    :dataptr, \    ; Addr of destination BCD
  418.     dstsz    :@uint, \    ; Byte size of destination
  419.     pStr    :dataptr    ; Addr of Ascii string
  420.  
  421.  
  422. ;//////////////////////////////////////////////////////////////////////
  423. ;//    Name    bcdP2a
  424. ;//    Desc    Convert a packed signed BCD to (unformatted) decimal
  425. ;//        Ascii. Outputs a leading '+' or '-' and min. one digit.
  426. ;//
  427. ;//
  428. ;//    Entry    Passed args
  429. ;//    Exit    Zero-terminated Ascii string returned to destination.
  430. ;//        Acc = length of destination string (less trailing 0).
  431. ;//
  432. ;//    Note    Maximum output to the destination string (incl. the
  433. ;//        trailing zero) equals twice the BCD's byte size.
  434.  
  435. bcdP2a    proc
  436. arg    pStr    :dataptr, \    ; Addr of AsciiZ destination
  437.     srcBCD    :dataptr, \    ; Addr of source BCD
  438.     srcsz    :@uint        ; Byte size of source BCD
  439.  
  440.  
  441. -----------------
  442. FILE : BCDP2B.ASM
  443. -----------------
  444.  
  445. ;//////////////////////////////////////////////////////////////////////
  446. ;//    Name    bcdP2b
  447. ;//    Desc    Convert packed signed BCD to signed binary.
  448. ;//
  449. ;//
  450. ;//    Entry    Passed args
  451. ;//    Exit    Signed binary value returned to destination.
  452. ;//        Acc undefined.
  453. ;//
  454. ;//    Note    The parameter [dstsz] which indicates the byte size
  455. ;//        of the binary destination, must be even-sized and 
  456. ;//        large enough to ensure no overflow during the 
  457. ;//        conversion. A qword (8 bytes) is required to convert
  458. ;//        a tbyte (10 bytes) source BCD.
  459. ;//
  460. ;//    ToDo    Return error if overflow/loss of significance/bad size.
  461.  
  462. bcdP2b    proc
  463. arg    dstBIN    :dataptr, \    ; Addr of binary destination
  464.     dstsz    :@uint, \    ; Byte size of dest. (see note)
  465.     srcBCD    :dataptr, \    ; Addr of source BCD
  466.     srcsz    :@uint        ; Byte size of src
  467.  
  468.  
  469. ;//////////////////////////////////////////////////////////////////////
  470. ;//    Name    bcdB2p
  471. ;//    Desc    Convert signed binary to packed signed BCD.
  472. ;//
  473. ;//
  474. ;//    Entry    Passed args
  475. ;//    Exit    Acc > 0: Packed signed BCD returned to destination
  476. ;//        Acc = 0: Error (bad srcsz)
  477. ;//
  478. ;//    Note    The parameter [srcsz] which indicates the byte size of
  479. ;//        the binary source must be even (min. 2), and contain
  480. ;//        no more significant bits than can be converted to
  481. ;//        packed BCD format without overflow (for example, max.
  482. ;//        59 significant bits of a qword, plus sign bit).
  483. ;//
  484. ;//    ToDo    Return error if overflow/loss of significance.
  485.  
  486.     MAX_SIZEOF_BIN = 20h
  487.  
  488. bcdB2p    proc
  489. arg    dstBCD    :dataptr, \    ; Addr of destination BCD
  490.     dstsz    :@uint, \    ; Byte size of dst
  491.     srcBIN    :dataptr, \    ; Addr of source binary
  492.     srcsz    :@uint        ; Byte size of src (even, min. 2)
  493.  
  494.  
  495. -----------------
  496. FILE : BCDP2U.ASM
  497. -----------------
  498.  
  499. ;//////////////////////////////////////////////////////////////////////
  500. ;//    Name    bcdP2u
  501. ;//    Desc    Convert packed signed BCD to un-packed signed BCD.
  502. ;//
  503. ;//
  504. ;//    Entry    Passed args
  505. ;//    Exit    Un-packed signed BCD returned to destination.
  506. ;//        Acc undefined.
  507. ;//
  508. ;//    Note    Size of destination must be double-size.
  509.  
  510. bcdP2u    proc
  511. arg    dstBCD    :dataptr, \    ; Addr of destination (size = 2*srcsz)
  512.     srcBCD    :dataptr, \    ; Addr of source packed BCD value
  513.     srcsz    :@uint        ; Byte size of source BCD
  514.  
  515.  
  516. ;//////////////////////////////////////////////////////////////////////
  517. ;//    Name    bcdU2p
  518. ;//    Desc    Convert un-packed signed BCD to packed signed BCD.
  519. ;//
  520. ;//
  521. ;//    Entry    Passed args
  522. ;//    Exit    Packed signed BCD returned to destination.
  523. ;//        Acc = 0: Source BCD contains significant information
  524. ;//             that cannot be packed (see note)
  525. ;//        Acc > 0: No error
  526. ;//
  527. ;//    Note    Since the top byte is used for the sign, a 10-byte
  528. ;//        packed BCD can contain (10-1)*2 digits (=18); a 20-
  529. ;//        byte un-packed BCD can contain (20-1) digits (=19).
  530. ;//        Hence, an un-packed number may contain information
  531. ;//        that cannot be converted (this is unusual since an
  532. ;//        unpacked BCD is generally used as temporary storage
  533. ;//        for a packed BCD; it's also compromising the BCD
  534. ;//        format).
  535.  
  536. bcdU2p    proc
  537. arg    dstBCD    :dataptr, \    ; Addr of destination (size = srcsz/2)
  538.     srcBCD    :dataptr, \    ; Addr of source un-packed BCD value
  539.     srcsz    :@uint        ; Byte size of source
  540.  
  541.  
  542. -----------------
  543. FILE : BCDSHL.ASM
  544. -----------------
  545.  
  546. ;//////////////////////////////////////////////////////////////////////
  547. ;//    Name    bcdShl
  548. ;//    Desc    Perform a digit left-shift of a packed signed BCD.
  549. ;//
  550. ;//
  551. ;//    Entry    Passed args
  552. ;//    Exit    Packed signed BCD returned to destination.
  553. ;//        Accumulator (and cf,zf flags) determined:
  554. ;//             Acc = 0: Result is zero (zf=1)
  555. ;//        Acc > 0: Result is non-zero (zf=0)
  556. ;//
  557. ;//        If any significant digits were shifted out
  558. ;//        of the high-order, cf=1, else cf=0
  559. ;//        (sign and overflow flags should be ignored).
  560. ;//
  561. ;//    Note    A 10-byte BCD holds 18 BCD digits ( 2*(10-1) ).
  562. ;//
  563. ;//    Note    This procedure shifts one digit, i.e. one nibble, 
  564. ;//        per shift count effectively performing a
  565. ;//        MUL 10-to-the-n'th-power operation.
  566. ;//        Zeros are shifted into the low-order. The sign of
  567. ;//        the destination is changed only if the result is
  568. ;//        zero. If the shift count is larger than or equals
  569. ;//        the number of digits in the BCD, the result will
  570. ;//        be zero.
  571.  
  572. bcdShl    proc
  573. arg    dstBCD    :dataptr, \    ; Addr of BCD
  574.     dstsz    :@uint, \    ; Byte size of BCD
  575.     count    :@uint        ; No. of BCD digits to shift
  576.  
  577.  
  578. -----------------
  579. FILE : BCDSHR.ASM
  580. -----------------
  581.  
  582. ;//////////////////////////////////////////////////////////////////////
  583. ;//    Name    bcdShr
  584. ;//    Desc    Perform a digit right-shift of a packed signed BCD.
  585. ;//
  586. ;//
  587. ;//    Entry    Passed args
  588. ;//    Exit    Packed signed BCD returned to destination.
  589. ;//        Accumulator (and zf flag) determined:
  590. ;//        Acc = 0: Result is zero
  591. ;//        Acc > 0: Result is non-zero
  592. ;//        (carry, sign, and overflow flags should be ignored)
  593. ;//
  594. ;//    Note    A 10-byte BCD holds 18 BCD digits ( 2*(10-1) ).
  595. ;//
  596. ;//    Note    This procedure shifts one digit, i.e. one nibble, per
  597. ;//        shift count effectively performing a
  598. ;//        DIV 10-to-the-n'th-power operation.
  599. ;//        Zeros are shifted into the high-order of destination.
  600. ;//        The sign of the BCD is changed only if the result is
  601. ;//        zero. If the shift count is larger than or equals the
  602. ;//        number of digits in the BCD, the result will be zero.
  603.  
  604. bcdShr    proc
  605. arg    dstBCD    :dataptr, \    ; Addr of destination BCD
  606.     dstsz    :@uint, \    ; Byte size of BCD
  607.     count    :@uint        ; No. of BCD digits to shift
  608.  
  609.  
  610. ------------------
  611. FILE : BCDSWAP.ASM
  612. ------------------
  613.  
  614. ;//////////////////////////////////////////////////////////////////////
  615. ;//    Name    bcdSwap
  616. ;//    Desc    Exchange (swap) two packed signed BCD numbers.
  617. ;//
  618. ;//
  619. ;//    Entry    Passed args
  620. ;//    Exit    Contents of numbers exchanged.
  621. ;//        Acc undefined.
  622.  
  623. bcdSwap proc
  624. arg    dstBCD    :dataptr, \    ; Addr of 1st BCD
  625.     srcBCD    :dataptr, \    ; Addr of 2nd BCD
  626.     BCDsz    :@uint        ; Byte size of each BCD
  627.  
  628.  
  629. ----------------
  630. FILE : BCDSX.ASM
  631. ----------------
  632.  
  633. ;//////////////////////////////////////////////////////////////////////
  634. ;//    Name    bcdSx
  635. ;//    Desc    Sign-extend a packed signed BCD number into a
  636. ;//        double-size packed signed BCD (convert to double-size).
  637. ;//
  638. ;//
  639. ;//    Entry    Passed args
  640. ;//    Exit    Double-size packed signed BCD returned to destination.
  641. ;//        Acc undefined.
  642. ;//
  643. ;//    Note    Destination and source may be the same.
  644.  
  645. bcdSx    proc
  646. arg    dstBCD    :dataptr, \    ; Addr of dest BCD (size = 2*srcsz)
  647.     srcBCD    :dataptr, \    ; Addr of source BCD (OK if = dstBCD)
  648.     srcsz    :@uint        ; Byte size of source BCD
  649.  
  650.  
  651. ----------------
  652. FILE : BCDUU.ASM
  653. ----------------
  654.  
  655. ;//////////////////////////////////////////////////////////////////////
  656. ;//    Name    BCDUUmov
  657. ;//    Desc    Move (copy) an un-packed BCD value.
  658. ;//
  659. ;//
  660. ;//    Entry    Passed args
  661. ;//    Exit    Destination = source. Acc undefined.
  662.  
  663. BCDUUmov proc
  664. arg    dstBCD    :dataptr, \    ; Addr of dest. BCD (size = srcsz)
  665.     srcBCD    :dataptr, \    ; Addr of source BCD
  666.     srcsz    :@uint        ; Byte size of source
  667.  
  668.  
  669. ;//////////////////////////////////////////////////////////////////////
  670. ;//    Name    BCDUUadd
  671. ;//    Desc    Add two unpacked unsigned BCD numbers (dst += src).
  672. ;//
  673. ;//
  674. ;//    Entry    Passed args
  675. ;//    Exit    Sum of dest. and source returned to destination.
  676. ;//        Accumulator (and cf flag) determined:
  677. ;//        Acc = 0: No carry
  678. ;//        Acc = 1: Carry (overflow)
  679. ;//
  680. ;//    Note    Destination and source may be the same.
  681.  
  682. BCDUUadd proc
  683. arg    dstBCD    :dataptr, \    ; Addr of dest. BCD (size = srcsz)
  684.     srcBCD    :dataptr, \    ; Addr of source BCD
  685.     srcsz    :@uint        ; Byte size of source
  686.  
  687.  
  688. ;//////////////////////////////////////////////////////////////////////
  689. ;//    Name    BCDUUsub
  690. ;//    Desc    Subtract two unpacked unsigned BCD numbers (dst -= src)
  691. ;//
  692. ;//
  693. ;//    Entry    Passed args
  694. ;//    Exit    Difference (dest - source) returned to destination.
  695. ;//        Accumulator (and cf flag) determined:
  696. ;//        Acc = 0: No borrow
  697. ;//        Acc = 1: Borrow (underflow)
  698. ;//
  699. ;//    Note    Destination and source may be the same.
  700.  
  701. BCDUUsub proc
  702. arg    dstBCD    :dataptr, \    ; Addr of dest. BCD (size = srcsz)
  703.     srcBCD    :dataptr, \    ; Addr of source BCD
  704.     srcsz    :@uint        ; Byte size of source
  705.  
  706.  
  707. ;//////////////////////////////////////////////////////////////////////
  708. ;//    Name    BCDUUu2p
  709. ;//    Desc    Convert un-packed unsigned BCD to packed unsigned BCD.
  710. ;//
  711. ;//
  712. ;//    Entry    Passed args
  713. ;//    Exit    Packed BCD returned to destination.
  714. ;//        Acc > 0: No error.
  715. ;//        Acc = 0: High word of source contains information
  716. ;//             that cannot be converted.
  717. ;//
  718. ;//    Note    Assumes source size is twice that of destination.
  719.  
  720. BCDUUu2p proc
  721. arg    dstBCD    :dataptr, \    ; Addr of dest. BCD (size = srcsz/2)
  722.     srcBCD    :dataptr, \    ; Addr of unpacked source BCD
  723.     srcsz    :@uint        ; Byte size of source
  724.  
  725.  
  726. ;//////////////////////////////////////////////////////////////////////
  727. ;//    Name    BCDUUu2a
  728. ;//    Desc    Convert unpacked unsigned BCD to decimal Ascii.
  729. ;//        Outputs at least one character.
  730. ;//
  731. ;//
  732. ;//    Entry    Passed args
  733. ;//    Exit    Zero-terminated Ascii string returned to destination.
  734. ;//        Acc = length of destination string (less trailing 0).
  735. ;//
  736. ;//    Note    Maximum output to the destination string equals the
  737. ;//        BCD's byte size plus 1.
  738.  
  739. BCDUUu2a proc
  740. arg    pStr    :dataptr, \    ; Addr of AsciiZ dest.
  741.     srcBCD    :dataptr, \    ; Addr of source BCD
  742.     srcsz    :@uint        ; Byte size of source BCD
  743.  
  744.  
  745. ;//////////////////////////////////////////////////////////////////////
  746. ;//    Name    BCDUUmul
  747. ;//    Desc    Multiply two unpacked unsigned BCDs (dst *= src).
  748. ;//
  749. ;//
  750. ;//    Entry    Passed args
  751. ;//    Exit    Double-size unpacked unsigned BCD product returned to
  752. ;//        destination _replacing_ the multiplicand.
  753. ;//        Acc undefined.
  754. ;//
  755. ;//    Note    Both BCD operands must be defined as double-size,
  756. ;//        where the high-order is undefined (because the result
  757. ;//        is returned as double-precision, and the multiplier
  758. ;//        provides temporary work space for this procedure).
  759. ;//
  760. ;//        See bcdImul for details on algorithm.
  761.  
  762. BCDUUmul proc
  763. arg    dstBCD    :dataptr, \    ; Addr of BCD multiplicand
  764.     srcBCD    :dataptr, \    ; Addr of BCD multiplier
  765.     srcsz    :@uint        ; Byte size of each BCD (double-size)
  766.  
  767.  
  768. ------------------
  769. FILE : BIN2ASC.ASM
  770. ------------------
  771.  
  772. ;//////////////////////////////////////////////////////////////////////
  773. ;//    Name    bin2asc
  774. ;//    Desc    Convert signed binary number to decimal Asciiz string.
  775. ;//
  776. ;//
  777. ;//    Entry    Passed args
  778. ;//    Exit    Left-justified Asciiz string returned to destination.
  779. ;//        Acc = string length (0 if bad srcsz).
  780. ;//
  781. ;//    Note    Destination storage must hold sufficient space.
  782. ;//        Insignificant leading zeros are not output.
  783. ;//
  784. ;//        Uses a shift-and-subtract algorithm whose primary 
  785. ;//        virtue is its ability to handle very large numbers.
  786.  
  787.     MAX_SIZEOF_BIN = 20h
  788.         DIVISOR = 10d           ; Decimal conversion
  789.  
  790. bin2asc proc
  791. arg    dstStr    :dataptr, \    ; Addr of Asciiz destination
  792.     srcBIN    :dataptr, \    ; Addr of signed binary source
  793.     srcsz    :@uint        ; Byte size of source (even, min. 2)
  794.  
  795.  
  796. ;//////////////////////////////////////////////////////////////////////
  797. ;//    Name    HexN
  798. ;//    Desc    Convert unsigned binary word/dword to hexadecimal
  799. ;//        Asciiz string.
  800. ;//
  801. ;//
  802. ;//    Entry    Passed args
  803. ;//    Exit    Acc = string length.
  804.  
  805. HexN    proc
  806. arg    pStr    :dataptr, \    ; Addr of destination Asciiz string
  807.     mval    :@uint        ; 16-bit: word; 32-bit: dword value
  808.  
  809.  
  810. -------------------
  811. FILE : CONSOLIO.ASM
  812. -------------------
  813.  
  814. ;//////////////////////////////////////////////////////////////////////
  815. ;//    Name    IsDevRedir                      (DOS)
  816. ;//    Desc    Test redirection of standard input or standard output.
  817. ;//
  818. ;//
  819. ;//    Entry    Passed arg
  820. ;//    Exit    Acc > 0: Is redirected.
  821. ;//        Acc = 0: Not redirected.
  822. ;//        Acc =-1: Error on DOS call.
  823.  
  824. IsDevRedir proc
  825. arg    hDev    :@uint        ; Device handle (STDIN or STDOUT)
  826.  
  827.  
  828. ;//////////////////////////////////////////////////////////////////////
  829. ;//    Name    GetKey                           (DOS)
  830. ;//    Desc    (Wait for and) Read character from the standard input
  831. ;//        device (usually the keyboard).
  832. ;//
  833. ;//
  834. ;//    Entry    N/A
  835. ;//    Exit    Acc = keyboard code (al zero if extended key).
  836. ;//
  837. ;//    Note    Checks for Ctrl-C and Ctrl-Break.
  838.  
  839. GetKey    proc
  840.  
  841.  
  842. ;//////////////////////////////////////////////////////////////////////
  843. ;//    Name    WriteZStr                      (DOS)
  844. ;//    Desc    Write zero-terminated Ascii string to standard output.
  845. ;//
  846. ;//
  847. ;//    Entry    Passed arg
  848. ;//    Exit    Acc = No. of bytes written.
  849.  
  850. WriteZStr proc
  851. arg    pStr    :dataptr    ; Addr of AsciiZ string
  852.  
  853.  
  854. ;//////////////////////////////////////////////////////////////////////
  855. ;//    Name    WriteNL                       (DOS)
  856. ;//    Desc    Write new-line (one CR/LF pair) to standard output.
  857. ;//
  858. ;//
  859. ;//    Entry    N/A
  860. ;//    Exit    Acc = No. of bytes written.
  861.  
  862. WriteNL    proc
  863.  
  864.  
  865. ;//////////////////////////////////////////////////////////////////////
  866. ;//    Name    IsDevRedir                    (Win32)
  867. ;//    Desc    Test redirection of standard input or standard output.
  868. ;//
  869. ;//
  870. ;//    Entry    Passed arg
  871. ;//    Exit    Acc > 0: Is redirected.
  872. ;//        Acc = 0: Not redirected.
  873. ;//        Acc =-1: Error on Win32 API call.
  874. ;//
  875. ;//    Note    Returns 0 if stdout redirected to LPTn (COMn?)
  876. ;//        or if a DOS box is running under Win95 v4.00.950a.
  877. ;//
  878. ;//    ToDo    Make this work as the DOS version!
  879.  
  880. IsDevRedir proc
  881. arg    hDev    :@uint        ; STD_INPUT_HANDLE or STD_OUTPUT_HANDLE
  882.  
  883.  
  884. ;//////////////////////////////////////////////////////////////////////
  885. ;//    Name    GetKey                         (Win32)
  886. ;//    Desc    (Wait for and) Read character from the standard input
  887. ;//        device (usually the keyboard).
  888. ;//
  889. ;//
  890. ;//    Entry    N/A
  891. ;//    Exit    Acc = keyboard code.
  892. ;//
  893. ;//    Note    Doesn't read extended keys (function or arrow keys).
  894. ;//        Returns Ctrl-C as 03h (but Ctrl-Break is handled by
  895. ;//        Windows).
  896.  
  897. GetKey    proc
  898.  
  899.  
  900. ;//////////////////////////////////////////////////////////////////////
  901. ;//    Name    WriteZStr                    (Win32)
  902. ;//    Desc    Write zero-terminated Ansi string to standard output.
  903. ;//
  904. ;//
  905. ;//    Entry    Passed arg
  906. ;//    Exit    Acc = No. of bytes written.
  907.  
  908. WriteZStr proc
  909. arg    pzStr    :dataptr    ; Addr of AnsiZ string
  910.  
  911.  
  912. ;//////////////////////////////////////////////////////////////////////
  913. ;//    Name    WriteNL                     (Win32)
  914. ;//    Desc    Write new-line (one CR/LF pair) to standard output.
  915. ;//
  916. ;//
  917. ;//    Entry    N/A
  918. ;//    Exit    As for WriteZStr
  919. ;//     Calls   WriteZStr
  920.  
  921. WriteNL proc
  922.  
  923.  
  924. ;.