home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / cpm / utils / asmutl / asmlib.lbr / SETLZB.AZM / SETLZB.ASM
Assembly Source File  |  1991-06-25  |  5KB  |  181 lines

  1. ;----------------------------------------------------------------
  2. ;        This is a module in the ASMLIB library
  3. ;
  4. ; Enable leading zero blanking on the next numeric output.
  5. ;
  6. ;            Written         R.C.H.     16/8/83
  7. ;            Last Update    R.C.H.       31/12/83
  8. ;
  9. ; Eliminate all self modifying code         R.C.H.   22/10/83
  10. ; Add ? to front of global subroutines         R.C.H.   31/12/83
  11. ;----------------------------------------------------------------
  12. ;
  13.     name    'setlzb'
  14. ;
  15.     public    lzb,blzb,clzb,nolzb
  16.     public    ?lzpr1,?lzpr2,?lzpr3,?lzprint
  17.     extrn    ?lzbchr,?blank,dispatch
  18.     maclib    z80
  19. ;
  20. ; Leadng zero printing is done in the different modes by recoginzing the
  21. ; following codes. These are defined as follows.
  22. ;
  23. ; 00    No lzb, standard default
  24. ; 01    Standard leading zero blanking
  25. ; 02    Blank filled leading zero blanking
  26. ; 03    Character filled leading zero blanking
  27. ;
  28. lzb:
  29.     push    psw
  30.     mvi    a,1            ; Select
  31. lzb$common:
  32.     sta    lzbtype            ; Save in the data byte for it
  33.     pop    psw
  34.     ret
  35. ;
  36. ;----------------------------------------------------------------
  37. ;       Enable blank filled LZB on next numeric output.
  38. ;----------------------------------------------------------------
  39. ;
  40. blzb:
  41.     push    psw
  42.     mvi    a,2
  43.     jr    lzb$common
  44. ;
  45. ;----------------------------------------------------------------
  46. ; Enable character fill leading zero blanking. Character in A
  47. ;----------------------------------------------------------------
  48. ;
  49. clzb:
  50.     push    psw
  51.     sta    ?lzbchr            ; save the character to lzb fill with
  52.     mvi    a,3            ; Character filled lzb code
  53.     jr    lzb$common
  54. ;
  55. ;----------------------------------------------------------------
  56. ; Clear Leading Zero blanking
  57. ;----------------------------------------------------------------
  58. ;
  59. nolzb:
  60.     push    psw
  61.     xra    a
  62.     jr    lzb$common
  63. ;
  64. ;----------------------------------------------------------------
  65. ; This section is rather important since it is used by all numeric 
  66. ; printing routines to leading zero print digits. All the routines 
  67. ; for the different types of leading zero printing are contained 
  68. ; herein. Also note that the LZ$PRINT label is called by all or
  69. ; most numeric prionting routines and uses the lzbtype byte to
  70. ; jump to the required printing routine.
  71. ;----------------------------------------------------------------
  72. ;
  73. ?lzprint:
  74.     push    h            ; Deepest on the stack
  75.     push    d
  76.     push    psw
  77.     lda    lzbtype            ; Load the destination
  78.     mvi    d,0
  79.     mov    e,a            ; Load the offset
  80.     lxi    h,lz$table        ; Point to start of table
  81.     dad    d
  82.     dad    d            ; Index into the table
  83.     mov    e,m
  84.     inx    h
  85.     mov    d,m            ; Now de -> the routine
  86.     xchg                ; HL -> the address
  87.     pop    psw
  88.     pop    d
  89.     xthl                ; Restore hl, stack -> address
  90.     ret                ; Goto the table address
  91. ;
  92. ; The following table of routines is indexed into by the leading
  93. ; zero blanking type byte to get the address of the required routine
  94. ; to print the character in A.
  95. ;
  96. lz$table:
  97.     dw    dispatch
  98.     dw    ?lzpr1        ; Standard lzb
  99.     dw    ?lzpr2        ; Blank filled lzb
  100.     dw    ?lzpr3        ; Character filled lzb
  101. ;
  102. ; The following three routines are pointed to by the above jump 
  103. ; when it is modified by a call to one of the entries.
  104. ;
  105. ?lzpr1:    ; Standard leading zero suppression
  106.     call    chk$blank        ; See if we are past LZB due to a digit
  107.     cpi    '0'            ; is it a space ?
  108.     rz
  109.     jmp    dispatch        ; else print if not = 0
  110. ?lzpr2:    ; If it is = 0 then print a space
  111.     call    chk$blank        ; See if we are past LZB due to a digit
  112.     cpi    '0'
  113.     jnz    dispatch        ; print it if > 0
  114.     mvi    a,' '            ; else load a space
  115.     jmp    dispatch
  116. ?lzpr3:    ; If the character = 0 then use the LZBCHR character to print
  117.     call    chk$blank        ; See if we are past LZB due to a digit
  118.     cpi    '0'            ; zero ?
  119.     jnz    dispatch        ; print is > 0
  120.     lda    ?lzbchr            ; else load the fill character
  121.     jmp    dispatch
  122. ;
  123. chk$blank:    ; Check the blank byte. If it is not 00 then we print the digit
  124.     cpi    '0'            ; is the digit a zero ?
  125.     jrnz    set$blank        ; Set the blank byte
  126. ; If the digit is a zero then detect if we MUST print it then
  127.     lda    ?blank
  128.     ora    a            ; if 00 the we do no need to
  129.     jrnz    send$blank        
  130.     mvi    a,'0'
  131.     ret                ; return and do what may
  132. ;
  133. send$blank:    ; Here is jumped to when blank <> 0 so we must print it
  134.     pop    psw            ; kill the return address
  135.     mvi    a,'0'            ; load a zero
  136.     jmp    dispatch        ; send the byte
  137. ;
  138. set$blank:
  139.     push    psw            ; save the digit
  140.     mvi    a,0ffh
  141.     sta    ?blank
  142.     pop    psw
  143.     ret                ; return to the caller, blank set
  144. ;
  145.     dseg
  146. lzbtype:
  147.     db    00            ; Type of leading zero blanking
  148. ;
  149.     end
  150.  
  151.  
  152.  
  153.  
  154.  
  155.  
  156.  
  157.  
  158.  
  159.  
  160.  
  161.  
  162.  
  163.  
  164.  
  165.  
  166.  
  167.  
  168.  
  169.  
  170.  
  171.  
  172.  
  173.  
  174.  
  175.  
  176.  
  177.  
  178.  
  179.  
  180.  
  181.