home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_02_06 / 2n06008a < prev    next >
Text File  |  1991-03-16  |  4KB  |  196 lines

  1. ; (c) Copyright 1991, Martin Stitt
  2. ; xmit_par.asm - tsr program, doesparallel port output
  3. ; to be loaded in the test machine.
  4.  
  5. outport    equ    03bch    ; parallel port base addr
  6.  
  7. include    dumpmacs.inc    ; include for intvect equate
  8.  
  9. _TEXT    segment para public 'CODE'
  10.         assume  cs:_TEXT,ds:_TEXT,es:_TEXT,ss:_TEXT
  11.     org    0100H
  12. start:
  13.     jmp    begin
  14.  
  15. int_tbl label word
  16.     dw    xmit_al, xmit_str, xmit_byte, xmit_word
  17. int_tbl_wrds equ $-int_tbl
  18.  
  19. hex_table     db    '0123456789ABCDEF'
  20. byte_buff    db    '   ',0
  21. word_buff    db    '     ',0
  22.  
  23. ;= xmit_al ============================================
  24. ; in:    al = the character to transmit
  25. ;    dx = the output port's base address
  26. ;
  27. ; out:    all registers preserved 
  28. ;    interrupt flag setting preserved 
  29. ;======================================================
  30.     assume    ds:nothing,es:nothing,ss:nothing
  31. xmit_al:
  32.     push    ax
  33.     push    ax        ; save the byte to xmit
  34.     inc    dx        ; address base+1
  35. wait1:
  36.     in    al,dx        ; loop until ready 
  37.     jmp    $+2        ; signal is high
  38.     test    al,80h
  39.     jz    wait1
  40.     pop    ax        ; recover data byte
  41.     dec    dx
  42.     pushf            ; save int flag state
  43.     cli            ; no irqs here  
  44.     out    dx,al        ; write data to port
  45.     jmp    $+2
  46.     inc    dx
  47.     inc    dx        ; address base+2
  48.     in    al,dx        ; read current states
  49.     jmp    $+2
  50.     xor    al,1        ; toggle the strobe bit
  51.     out    dx,al
  52.     jmp    $+2
  53.     dec    dx        ; back to base+1
  54. wait2:
  55.     in    al,dx        ; loop until ready 
  56.     jmp    $+2        ; signal is low
  57.     test    al,80h
  58.     jnz    wait2
  59.     dec    dx        ; restore entry dx
  60.     popf            ; restore int flag
  61.     pop    ax
  62.     ret
  63.  
  64. ;= xmit_str ===========================================
  65. ; in:    ds:si -> the asciiz string to dump
  66. ;    dx = the output port's base address
  67. ;
  68. ; out:    all registers preserved 
  69. ;======================================================
  70. xmit_str:
  71.     push    ax
  72.     push    si
  73.     cld
  74. xs1:
  75.     lodsb            ; pull in each char 
  76.     or    al,al        ; of the string
  77.     jz    xs2        ; done yet?
  78.     call    xmit_al        ; xmit the character
  79.     jmp    short xs1
  80. xs2:
  81.     pop    si
  82.     pop    ax
  83.     ret
  84.  
  85. ;= byte2hex ===========================================
  86. ; in:    al = the byte to be converted
  87. ;    ds:si -> buffer in which to write result
  88. ;
  89. ; out:    buffer at ds:si contains two ascii characters
  90. ;======================================================
  91.     assume    ds:nothing,es:nothing,ss:nothing
  92. byte2hex:
  93.     push    ax
  94.     push    bx
  95.     push    si
  96.     mov    bx,offset hex_table
  97.     push    ax
  98.     shr    al,1
  99.     shr    al,1
  100.     shr    al,1        ; convert byte to 2 hex
  101.     shr    al,1        ; chars and stuff 
  102.     xlat    hex_table    ; in buffer
  103.     mov    [si],al
  104.     pop    ax
  105.     and    al,0fh
  106.     xlat    hex_table
  107.     mov    [si+1],al
  108.     pop    si
  109.     pop    bx
  110.     pop    ax
  111.     ret
  112.  
  113. ;= xmit_byte ==========================================
  114. ; in:    al = byte to convert and xmit
  115. ;
  116. ; out:    all registers preserved 
  117. ;======================================================
  118.     assume    ds:nothing,es:nothing,ss:nothing
  119. xmit_byte:
  120.     push    si
  121.     push    ds
  122.     mov    si,cs
  123.     mov    ds,si
  124.     mov    si,offset byte_buff
  125.     call    byte2hex
  126.     call    xmit_str    ; xmit the buffer
  127.     pop    ds
  128.     pop    si
  129.     ret
  130.  
  131. ;= xmit_word ==========================================
  132. ; in:    si = word to convert and xmit
  133. ;
  134. ; out:    all registers preserved                
  135. ;======================================================
  136.     assume    ds:nothing,es:nothing,ss:nothing
  137. xmit_word:
  138.     push    ax
  139.     push    si
  140.     push    ds
  141.     mov    ax,si
  142.     mov    si,cs
  143.     mov    ds,si
  144.     mov    si,offset word_buff
  145.     xchg    ah,al
  146.     call    byte2hex    ; convert word to 4 hex
  147.     add    si,2        ; chars and stuff 
  148.     mov    al,ah        ; in buffer
  149.     call    byte2hex
  150.     sub    si,2
  151.     call    xmit_str    ; xmit the buffer
  152.     pop    ds
  153.     pop    si
  154.     pop    ax
  155.     ret
  156.  
  157. ;= int_handler ========================================
  158. ; in:    ah = function selector
  159. ;
  160. ; out:    all registers preserved 
  161. ;======================================================
  162.     assume    ds:nothing,es:nothing,ss:nothing
  163. handler:
  164.     push    bx
  165.     mov    bl,ah
  166.     xor    bh,bh        ; lookup function and
  167.     shl    bx,1        ; call corresponding 
  168.     cmp    bx,int_tbl_wrds    ; service routine
  169.     jae    intx
  170.     push    dx
  171.     mov    dx,outport    ; load base address
  172.     call    cs:[int_tbl+bx]
  173.     pop    dx
  174. intx:
  175.     pop    bx
  176.     iret
  177.  
  178. endres  label   byte
  179.  
  180. ;==== main routine
  181.     assume  ds:_TEXT,es:_TEXT,ss:_TEXT
  182. begin:
  183.     xor    ax,ax        ; hook the int vector
  184.     mov    es,ax
  185.     assume    es:nothing
  186.     mov    word ptr es:[intvect*4],offset handler
  187.     mov    word ptr es:[intvect*4+2],cs
  188.     mov    dx,offset endres+15
  189.     mov    cl,4
  190.     shr    dx,cl        ; terminate & stay res
  191.     mov    ax,3100h
  192.     int    21h
  193. _TEXT    ends
  194.     end    start
  195.  
  196.