home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / simtel / sigm / vols200 / vol247 / routines.a86 < prev    next >
Encoding:
Text File  |  1994-07-13  |  5.4 KB  |  297 lines

  1. eject
  2. ;
  3. ;The routines in this file are supposed to be included
  4. ;    in main programs. Any equates or db needed for 
  5. ;    the following routines will be maintained in this
  6. ;    file
  7. ;
  8.  
  9.     DSEG    $
  10.  
  11. register    db    '    $'        ;for printing of a register
  12. ;
  13. vector        rs    16        ;for ASCII bit vector
  14.         db    '$'
  15. ;
  16. cursor_position    db    esc,'=  $'    ;for positioning cursor
  17. ;
  18. ten        dw    10        ;for conversion routine
  19. ;
  20. ;--------EQUATES------------
  21. load_drive_at    equ    .50h        ;in base page, location of load drive
  22. print_string    equ    9
  23. ret_current_disk equ    25
  24. esc        equ    1bh
  25. con_out        equ    2
  26. list_out    equ    5
  27.  
  28. eject
  29.     CSEG    $
  30.  
  31. ;
  32. ;ASCII_DECIMAL_TO_HEX 
  33. ;    si    input buffer
  34. ;    di    result location
  35. ;    cx    # of input characters
  36. ;
  37. ascii_decimal_to_hex:
  38.     mov    bx,1
  39.     add    si,cx
  40.     dec    si
  41.     std        ;si will be decremented in following loop
  42.     clc
  43. dec_loop:
  44.     xor    ax,ax
  45.     lodsb        ;get character
  46.     sub    al,30h    ;make into number
  47.     cmp    al,9    ;make sure it's a number
  48.     jg    conversion_error
  49.     mul    bx    ;power of ten * value of char
  50.     add    [di],ax    ;add to result location
  51.     mov    ax,bx
  52.     mul    ten    ;next power of ten
  53.     mov    bx,ax
  54.     loop    dec_loop
  55. dec_@1:
  56.     cld
  57.     jc    conversion_error_1    ;if carry set then number was too big
  58.     ret
  59. conversion_error:
  60.     cld
  61. conversion_error_1:
  62.     stc
  63.     ret
  64.  
  65. ;-------------------------------
  66. ;FIND_LOAD_DRIVE
  67. ;    input    none
  68. ;    output    al=drive where program was loaded (0-15)
  69. ;
  70. find_load_drive:
  71.     mov    al,load_drive_at
  72.     dec    al
  73.     cmp    al,0ffh
  74.     jne    not_default
  75.     mov    cl,ret_current_disk    
  76.     call    bdos
  77. not_default:
  78.     ret
  79. eject
  80. ;------------------------------
  81. ;HEX_TO_ASCII_DECIMAL
  82. ;    input    ax=binary number
  83. ;        cx=# of decimal digits
  84. ;        di=offset of message area
  85. hex_to_dec:
  86.     dec di ! add di,cx    ;di now points to last digit
  87.     mov    bx,10
  88. hex_loop:
  89.     sub    dx,dx
  90.     div    bx
  91.     add    dl,'0'
  92.     mov [di],dl! dec di
  93.     loop    hex_loop
  94.     ret
  95. ;-------------------------------
  96. ;HEX_TO_ASCII_HEX
  97. ;    input    al=hex number
  98. ;    output    dx=ASCII of al
  99. ;
  100. hex_to_ascii_hex:
  101.     push    ax
  102.     xor    dx,dx
  103. hex1:
  104.     xor    ah,ah
  105.     mov    cl,4
  106.     shl    ax,cl
  107.     cmp    ah,0ah
  108.     jge    hex2
  109.     add    ah,30h
  110.     jmp    hex3
  111. hex2:
  112.     add    ah,37h
  113. hex3:
  114.     or    dx,dx
  115.     jnz    hex4
  116.     mov    dh,ah
  117.     jmp    hex1
  118. hex4:
  119.     mov    dl,ah
  120.     pop    cx
  121.     ret
  122. ;---------------------------
  123. ;PRINT_REGISTER , at current cursor position
  124. ;    input    ax=register
  125. ;        bx=0 if word , 2 if byte
  126. ;
  127. print_reg_w:
  128.     xor    bx,bx
  129.     jmp    print_register
  130. printf_reg_b:
  131.     mov    bx,2
  132. print_register:
  133.     push    bx
  134.     mov di,offset register ! call hex_word
  135.     mov    dx,offset register
  136.     pop bx ! add dx,bx
  137.     mov    cl,print_string
  138.     jmp    bdos
  139. ;
  140. ;--------------------------------
  141. ;PRINT_VECTOR , ASCII vector at current cursor position
  142. ;    input    AX = word for vector
  143. ;
  144. print_vector:
  145.     mov di,offset vector ! call make_vector
  146.     mov dx,offset vector ! mov cl,print_string
  147.     jmp    bdos
  148. ;
  149. ;------------------------------------
  150. ;PUT_MESSAGE
  151. ;Put message pointed to by SI at specified position
  152. ;input message form: row,col,'message.....$'
  153. ;output    none
  154. ;
  155. put_message:
  156.     lodsw ! push si    ;get row & col in AX
  157.     call    place
  158.     pop    dx
  159.     mov    cl,print_string
  160.     call    bdos
  161.     ret
  162. ;
  163. ;----------------------------------
  164. ;PLACE
  165. ;Place cursor at position in AX
  166. ;input    ah=col al=row
  167. ;output    none
  168. ;
  169. place:
  170.     add    ax,2020H
  171. ;row/col are based on one, need to be zero based, also need 20h offset
  172.  
  173.     mov    word ptr cursor_position+2,ax
  174.     mov    dx,offset cursor_position
  175.     mov cl,print_string ! call bdos
  176.     ret
  177. ;
  178. ;--------------------
  179. ;HEX_WORD
  180. ;input    AX=word
  181. ;    ES:DI= offset of string space
  182. ;
  183. hex_word:
  184.     mov    cx,4
  185. hex_wor_loop:
  186.     push    cx ! push ax
  187.     and    ax,0f000h
  188.     mov    cl,4 ! shr ax,cl
  189.     cmp    ah,0ah
  190.     jge    hexw2
  191.     add    ah,30h ! jmp hexw3
  192. hexw2:
  193.     add    ah,37h
  194. hexw3:
  195.     mov    [di],ah ! inc di
  196.     pop    ax     ! shl ax,cl
  197.     pop    cx
  198.     loop    hex_wor_loop
  199.     ret
  200. hex_byte:
  201.     mov    cx,2
  202.     xchg    ah,al
  203.     jmp    hex_wor_loop
  204. ;--------------------------
  205. ;MAKE_VECTOR
  206. ;Make ASCII vector from word in AX
  207. ;input    AX = word vector
  208. ;    ES:DI = offset of destination
  209. ;output none
  210. ;
  211. make_vector:
  212.     mov cx,16 ! mov bl,30h
  213. vector_loop:
  214.     clc ! rcl ax,1 ! push ax
  215.     pushf ! xor al,al ! popf
  216.     adc al,bl
  217.     stosb ! pop ax
  218.     loop    vector_loop
  219.     ret
  220. ;
  221. ;------------------------------------
  222. ;Put number of fields in CX,starting at offset in AX
  223. ;input    AX = offset into fields_table
  224. ;    CX = number of entries
  225. ;    SI = offset of fields_table
  226. ;
  227. put_fields:
  228.     shl ax,1 ! add si,ax
  229. pf_loop:
  230.     push    cx
  231.     lodsw ! push si
  232.     mov     si,ax
  233.     call    put_message
  234.     pop si ! pop cx
  235.     loop    pf_loop
  236.     ret
  237. ;
  238. ;--------------------------------------
  239. ;PRINT_BCD_REGISTER
  240. ;Print BCD register 
  241. ;input    AX = register
  242. ;    BX = 0 for word, 2 for byte
  243. ;
  244. print_bcd_reg:
  245.     mov cx,4 ! mov di,offset register
  246. bcd_loop:
  247.     push cx ! push ax
  248.     mov al,0f0h ! and al,ah
  249.     mov cl,4 ! shr al,cl
  250.     add al,30h ! stosb
  251.     pop ax ! mov cl,4 ! shl ax,cl
  252.     pop    cx
  253.     loop    bcd_loop
  254.     mov dx,offset register ! add dx,bx
  255.     mov cl,print_string ! jmp bdos
  256. ;-------------------------------------
  257. ;P_MESSAGE print mesage
  258. ;
  259. p_message:
  260.     mov    cl,print_string
  261.     jmp    bdos
  262. ;-------------------------------------
  263. ;NEW_PR_LINE  send new-line to printer
  264. ;
  265. new_pr_line:
  266.     mov    al,0dh
  267.     call    list_char
  268.     mov    al,0ah
  269.     call    list_char
  270.     ret
  271. ;
  272. ;NEW_LINE    send new-line to screen
  273. ;
  274. new_line:
  275.     mov    dl,0dh
  276.     call    con_char
  277.     mov    dl,0ah
  278. ;
  279. ;CON_CHAR    send character to console
  280. ;
  281. con_char:
  282.     mov    cl,con_out
  283.     jmp    bdos
  284. ;
  285. ;LIST_CHAR    send character to list device
  286. ;
  287. list_char:
  288.     mov    cl,list_out
  289. ;
  290. ;----------------------------------------------------------
  291. ;
  292. bdos:
  293.     int    224
  294.     ret
  295.  
  296.     end
  297.