home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / cpm / utils / asmutl / asmlib.lbr / IHL.AZM / IHL.ASM
Encoding:
Assembly Source File  |  1991-06-25  |  3.4 KB  |  144 lines

  1. ;----------------------------------------------------------------
  2. ;         This is a module in the ASMLIB library
  3. ;
  4. ; The two entry points in this module read ascii from the KEYBOARD
  5. ; and convert to a number into the Hl register pair.
  6. ;
  7. ; 1) IDHL    Read a DECIMAL number into HL. Note that the result 
  8. ;        is HEX still so that it can be used as a counter 
  9. ;        ie. 100 input returns HL = 64.
  10. ; 2) IHHL    Read a HEX number into HL
  11. ;
  12. ; Both routines return zero in A if the last character read was a legal
  13. ; digit else A will contain the error character.
  14. ;
  15. ;            Written        R.C.H.             19/8/83
  16. ;            Last Update    R.C.H.        22/10/83
  17. ;----------------------------------------------------------------
  18. ;
  19.     name    'ihl'
  20. ;
  21.     public    idhl,ihhl
  22.     extrn    cbuff,caps        ; get a line from console etc
  23. ;
  24.     maclib    z80
  25. ;
  26. idhl:
  27.     call    get$buf            ; load the buffer from console
  28.     lxi    h,0
  29.     lda    bufsiz
  30.     ora    a
  31.     rz                ; quit if nothing read
  32. ; Now read the buffer, condition, put into HL.
  33.     push    b            ; save
  34.     push    d
  35.     mov    b,a            ; use as a counter
  36. idhl2:
  37.     call    get$chr            ; Get a character
  38. ; Convert to a binary value now of 0..9
  39.     sui    '0'            
  40.     jrc    inp$err         ; Error since a non number
  41.     cpi    9 + 1            ; Check if greater than 9
  42.     jrnc    inp$err
  43. ; Now shift the result to the right by multiplying by 10 then add in this digit
  44.     mov    d,h            ; copy HL -> DE
  45.     mov    e,l
  46.     dad    h            ; * 2
  47.     dad    h            ; * 4
  48.     dad    d            ; * 5
  49.     dad    h            ; * 10 total now
  50. ; Now add in the digit from the buffer
  51.     mov    e,a
  52.     mvi    d,00
  53.     dad    d            ; all done now
  54. ; Loop on till all characters done
  55.     djnz    idhl2            ; do next character from buffer
  56.     jr    inp$end            ; all done
  57. ;
  58. ;
  59. ;----------------------------------------------------------------
  60. ; Read a HEX number into HL from the keyboard.
  61. ;----------------------------------------------------------------
  62. ;
  63. ihhl:
  64.     call    get$buf
  65.     lxi    h,00
  66.     lda    bufsiz
  67.     ora    a
  68.     rz                ; return if no character read
  69. ;
  70.     push    b
  71.     push    d            ; save
  72.     mov    b,a
  73. ;
  74. ihhl2:
  75.     call    get$chr            ; get a character
  76. ; Now convert the nibble to a hex digit 0..F
  77.     sui    '0'
  78.     cpi    9 + 1
  79.     jrc    ihhl3            ; mask in then
  80.     sui    'A'-'0'-10
  81.     cpi    16
  82.     jrnc    inp$err
  83. ;
  84. ; Shift the result left 4 bits and MASK in the digit in A
  85. ihhl3:
  86.     dad    h
  87.     dad    h
  88.     dad    h
  89.     dad    h            ; shifted right 4 now
  90.     ora    l            ; mask in the digit
  91.     mov    l,a            ; put back
  92.     djnz    ihhl2            ; keep on till all digits done
  93. ;
  94. inp$end:
  95.     xra    a            ; Zero is a goo exit
  96. inp$end2:
  97.     pop    d
  98.     pop    b
  99.     ret
  100. ;
  101. inp$err:    ; Here when a non digit is encountered
  102.     lda    buftmp
  103.     jr    inp$end2
  104. ;
  105. ; Subroutines for shared code etc....
  106. ;
  107. get$buf:    ; Load the buffer from the screen via CBUFF.
  108.     push    d
  109.     xra    a
  110.     sta    buffer+1        ; clear buffer original value
  111.     lxi    d,buffer
  112.     call    cbuff
  113.     pop    d
  114.     lxi    h,buftxt        ; point to the start of text
  115.     shld    bufadr            ; set up a pointer
  116.     lxi    h,00            ; clear the result register
  117.     ret
  118. ;
  119. ; Get a character from the buffer, capitalize it on the way
  120. ;
  121. get$chr:
  122.     push    h
  123.     lhld    bufadr
  124.     mov    a,m            ; get the character
  125.     sta    buftmp            ; save the character
  126.     inx    h            ; point to next character
  127.     shld    bufadr
  128.     pop    h            ; restore
  129. ; Now capitalize it
  130.     jmp    caps
  131. ;
  132. ; ================
  133. ;
  134.     dseg                ; Save in the data segment
  135. ;
  136. buftmp    db    00            ; A temporary character store
  137. bufadr:    db    00,00
  138. buffer:    db    6            ; maximum characters
  139. bufsiz:    db    00            ; characters read
  140. buftxt:    db    00,00,00,00,00,00    ; text buffer
  141. ;
  142.     end
  143.  
  144.