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

  1. ; (c) Copyright 1991, Martin Stitt
  2. ; recv_par.asm - parallel port data --> direct video.
  3. ; to be run at the monitor machine.
  4.  
  5. inport    equ    0278h
  6.  
  7. cols    equ    80        ; # of cols on display
  8. rows    equ    25        ; # of rows on display
  9. rowbytes equ    cols*2        ; bytes per row
  10. scrbytes equ    rowbytes*rows    ; total bytes in screen
  11. vidattr    equ    07h        ; display attribute
  12.  
  13. _TEXT    segment para public 'CODE'
  14.         assume  cs:_TEXT,ds:_TEXT,es:_TEXT,ss:_TEXT
  15.     org    0100H
  16. start:
  17.     jmp    begin
  18.  
  19. vid_ptr    label dword        ; ptr for video writes
  20. vid_ofs    dw    0
  21. vid_seg    dw    0
  22. strobe    db    ?        ; tracks strobe bit
  23.  
  24. ;= char2vid ===========================================
  25. ; in:    al = the character to dislay (or cr or lf)
  26. ;    ds -> local data segment
  27. ;
  28. ; out:    crashes ah,bx,cx,dx,si,di,es,flags
  29. ;======================================================
  30.         assume  ds:_TEXT,es:nothing,ss:nothing
  31. char2vid:
  32.     cmp    al,13
  33.     jne    chv1        ; if a carriage return
  34.     mov    ax,[vid_ofs]    ;  calc start of row
  35.     xor    dx,dx
  36.     mov    bx,rowbytes
  37.     div    bx
  38.     mul    bx
  39.     mov    [vid_ofs],ax
  40.     xor    ax,ax
  41.     jmp    short chv2
  42. chv1:
  43.     cmp    al,10
  44.     jne    chv2            ; if a linefeed
  45.     add    [vid_ofs],rowbytes  ;  calc next line
  46.     xor    ax,ax
  47. chv2:
  48.     les    di,[vid_ptr]    ; if vid_ofs > lim, 
  49.     cmp    di,scrbytes    ;  scroll the screen 
  50.     jb    chv3        ;  and reset [vid_ofs]
  51.     push    ax
  52.     push    ds
  53.     mov    si,es
  54.     mov    ds,si
  55.     assume    ds:nothing
  56.     mov    si,rowbytes            
  57.     xor    di,di
  58.     mov    cx,(scrbytes-rowbytes)/2
  59.     rep    movsw
  60.     mov    di,(scrbytes-rowbytes)
  61.     mov    cx,cols
  62.     mov    al,20h
  63.     mov    ah,vidattr
  64.     rep    stosw
  65.     mov    di,(scrbytes-rowbytes)
  66.     pop    ds
  67.     assume    ds:_TEXT
  68.     pop    ax
  69. chv3:
  70.     or    ax,ax        ; if not control code
  71.     jz    chv4        ;  display the char
  72.     mov    ah,7        ; normal video attr
  73.     stosw
  74. chv4:
  75.     mov    [vid_ofs],di    ; update offset
  76.     ret
  77.  
  78. ;= poll ===============================================
  79. ; in:    none
  80. ;
  81. ; out:    crashes ax,bx,dx,es + crashed by char2vid
  82. ;======================================================
  83.         assume  ds:_TEXT,es:nothing,ss:nothing
  84. poll:
  85.     mov    dx,inport    ; address base
  86.     mov    al,0        ; clear bit to raise
  87.     out    dx,al        ;  ready signal
  88.     jmp    $+2
  89.     mov    ax,40h        ; address the 40:17
  90.     mov    es,ax        ; shift state byte
  91.     assume    es:nothing
  92.     inc    dx        ; address base+1
  93. poll2:
  94.     test    byte ptr es:[17h],3 ; if either shift 
  95.     jnz    poll3            ; key down, exit
  96.     in    al,dx        ; read strobe
  97.     jmp    $+2
  98.     and    al,40h
  99.     cmp    al,[strobe]    ; wait until strobe 
  100.     je    poll2        ;  changes
  101.     mov    [strobe],al    ; update record 
  102.     dec    dx        ; address base
  103.     mov    al,1
  104.     out    dx,al        ; set bit to lower
  105.     jmp    $+2        ;  ready signal
  106.     inc    dx
  107.     in    al,dx        ; read parallel ports
  108.     jmp    $+2        ; form data byte value
  109.     mov    ah,al
  110.     mov    bl,al
  111.     and    bl,80h
  112.     shl    ah,1
  113.     and    ah,70h
  114.     inc    dx
  115.     in    al,dx
  116.     jmp    $+2
  117.     and    al,0fh
  118.     or    al,ah
  119.     or    al,bl
  120.     xor    al,8bh
  121.     call    char2vid    ; display the character
  122.     jmp     poll
  123. poll3:
  124.     ret
  125.  
  126. ;==== main routine
  127.         assume  ds:_TEXT,es:_TEXT,ss:_TEXT
  128. begin:
  129.     mov    [vid_seg],0b000h  ; determine video seg
  130.     mov    ax,40h
  131.     mov    es,ax
  132.     assume    es:nothing
  133.     cmp    byte ptr es:[49h],7
  134.     je    have_vseg
  135.     mov    [vid_seg],0b800h
  136. have_vseg:
  137.     mov    es,[vid_seg]    ; clear the screen
  138.     mov    al,20h
  139.     mov    ah,vidattr
  140.     mov    cx,scrbytes/2
  141.     xor    di,di
  142.     cld
  143.     rep    stosw
  144.     mov    dx,inport    ; init ports for input
  145.     xor    al,al
  146.     out    dx,al        ; turn off busy signal
  147.     inc    dx
  148.     out    dx,al        ; enable input
  149.     jmp    $+2
  150.     in    al,dx
  151.     jmp    $+2
  152.     and    al,40h
  153.     mov    [strobe],al    ; init strobe state
  154.     inc    dx
  155.     mov    al,4h
  156.     out    dx,al        ; enable input
  157.     call    poll        ; listen to the port
  158.     mov    ax,4c00h
  159.     int    21h
  160. _TEXT    ends
  161.     end    start
  162.  
  163.