home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / video / 3 / 3_9.asm < prev   
Encoding:
Assembly Source File  |  1988-08-11  |  2.2 KB  |  105 lines

  1.         TITLE    'Listing 3-9'
  2.         NAME    DisplayText
  3.         PAGE    55,132
  4.  
  5. ;
  6. ; Name:        DisplayText
  7. ;
  8. ; Function:    Display an alphanumeric string without interference on the CGA
  9. ;
  10. ; Caller:    Microsoft C:
  11. ;
  12. ;            int DisplayText1(buf,n,offset);
  13. ;
  14. ;            char *buf;        /* buffer containing text in
  15. ;                           CGA alphanumeric format
  16. ;                           (alternating character codes
  17. ;                           and attribute bytes
  18. ;                        */
  19. ;
  20. ;            int n;            /* buffer length in bytes */
  21. ;
  22. ;            unsigned int offset;    /* offset into video buffer */
  23. ;
  24.  
  25. Set80X25    EQU    (1 SHL 0)    ; bit masks for Mode Control Register
  26. Set320X200    EQU    (1 SHL 1)
  27. BlackAndWhite    EQU    (1 SHL 2)
  28. EnableVideo    EQU    (1 SHL 3)
  29. Set640X200    EQU    (1 SHL 4)
  30. EnableBlink    EQU    (1 SHL 5)
  31.  
  32. ARGbuf        EQU    word ptr [bp+4]    ; stack frame addressing
  33. ARGn        EQU    word ptr [bp+6]
  34. ARGoffset    EQU    word ptr [bp+8]
  35. TIMEOUT        EQU    5        ; Horizontal Retrace timeout loop limit
  36.  
  37.  
  38. _TEXT        SEGMENT    byte public 'CODE'
  39.         ASSUME    cs:_TEXT
  40.  
  41.         PUBLIC    _DisplayText
  42. _DisplayText    PROC    near
  43.  
  44.         push    bp        ; usual C prologue to establish
  45.         mov    bp,sp        ;  stack frame and preserve registers
  46.         push    si
  47.         push    di
  48.  
  49.         mov    ax,0B800h
  50.         mov    es,ax
  51.         mov    di,ARGoffset    ; ES:DI -> destination in video buffer
  52.         mov    si,ARGbuf    ; DS:SI -> source buffer
  53.         mov    bx,ARGn
  54.         shr    bx,1        ; BX := buffer length in words
  55.  
  56.         mov    dx,3DAh        ; DX := CGA Status Port
  57.  
  58. ; wait for start of vertical blanking period
  59.  
  60. L01:        mov    cx,TIMEOUT    ; CX := loop counter (timeout value)
  61.  
  62. L02:        in    al,dx        ; AL := video status
  63.         test    al,8
  64.         jnz    L02        ; loop if in vertical retrace
  65.         test    al,1
  66.         jz    L02        ; loop if not in horizontal retrace
  67.  
  68.         cli            ; disable interrupts during horiz retrace
  69.  
  70. L03:        in    al,dx
  71.         test    al,1
  72.         loopnz    L03        ; loop until end of retrace or timeout
  73.  
  74.         sti            ; re-enable interrupts
  75.  
  76.         jz    L01        ; loop if no timeout
  77.  
  78. ; blank the display
  79.  
  80.         mov    dl,0D8h        ; DX := 3D8h (Mode Control register)
  81.         mov    al,(Set80X25 OR EnableBlink)
  82.         out    dx,al        ; turn video off
  83.  
  84. ; copy the data to the video buffer
  85.  
  86.         mov    cx,bx        ; CX := buffer length in words
  87.         rep    movsw
  88.  
  89. ; re-enable the display
  90.  
  91.         or    al,EnableVideo
  92.         out    dx,al
  93.  
  94.         pop    di        ; usual C epilogue to restore registers
  95.         pop    si        ;  and discard stack frame
  96.         mov    sp,bp
  97.         pop    bp
  98.         ret
  99.  
  100. _DisplayText    ENDP
  101.  
  102. _TEXT        ENDS
  103.  
  104.         END
  105.