home *** CD-ROM | disk | FTP | other *** search
/ Turbo Toolbox / Turbo_Toolbox.iso / turbo5 / mcmvsmem.asm < prev    next >
Assembly Source File  |  1988-10-09  |  5KB  |  149 lines

  1.  
  2. ;           Copyright (c) 1985, 87 by Borland International, Inc.
  3.  
  4.     TITLE    MCMVSMEM
  5.  
  6. DATA    SEGMENT    WORD PUBLIC
  7.  
  8.         ASSUME DS:DATA
  9.  
  10.         EXTRN CheckSnow : BYTE
  11.  
  12. DATA    ENDS
  13.  
  14. CODE    SEGMENT    BYTE PUBLIC
  15.  
  16.     ASSUME    CS:CODE
  17.  
  18.     PUBLIC    MoveToScreen, MoveFromScreen
  19.  
  20. ; procedure MoveToScreen(var Source, Dest; Len : Word);
  21.  
  22. MoveToScreen    PROC    FAR
  23.   push    bp
  24.   mov     bp,sp
  25.   push    bp                   ; Save Turbo's BP
  26.   push    ds                   ;   and DS
  27.   mov     bh,ds:CheckSnow      ; Load CheckSnow value
  28.   lds     si,dword ptr [bp+12] ; Source pointer into DS:SI
  29.   les     di,dword ptr [bp+8]  ; Dest pointer into ES:DI
  30.   mov     cx,[bp+6]            ; Len value into CX
  31.   cmp     cx,0                 ; Quit if Len = 0
  32.   je      x0
  33.   cmp     si,di
  34.   jle     x1
  35.   cld                          ; Set string direction to forward
  36.   jmp short x2
  37. x1:
  38.   add     si,cx
  39.   sub     si,2
  40.   add     di,cx
  41.   sub     di,2
  42.   std
  43. x2:
  44.   cmp     bh,0
  45.   je      x7
  46. x3:
  47.   shr     cx,1                 ; Change bytes to words
  48.   mov     dx,3DAh              ; Point DX to CGA status port
  49.   mov     bl,9                 ; Move horiz. + vertical retrace mask to bl
  50. x4:     
  51.   lodsw                        ; Grab a video word
  52.   mov     bp,ax                ; Save it in BP
  53. x5:     
  54.   in      al,dx                ; Get 6845 status
  55.   rcr     al,1                 ; Check horizontal retrace
  56.   jb      x5                   ; Loop if in horizontal retrace: this prevents
  57.                                ;   starting in mid-retrace, since there is
  58.                                ;   exactly enough time for 1 and only 1 STOSW
  59.                                ;   during horizontal retrace
  60.   cli                          ; No ints during critical section
  61. x6:     
  62.   in      al,dx                ; Get 6845 status
  63.   and     al,bl                ; Check for both kinds of retrace: IF the
  64.                                ;   video board does not report horizontal
  65.                                ;   retrace while in vertical retrace, this
  66.                                ;   will allow several characters to be
  67.                                ;   stuffed in during vertical retrace
  68.   jz      x6                   ; Loop if equal to zero
  69.   mov     ax,bp                ; Get the video word
  70.   stosw                        ; Store the video word
  71.   sti                          ; Allow interrupts
  72.   loop    x4                   ; Go do next word
  73.   jmp short x0
  74. x7:
  75.   shr     cx,1                 ; Change bytes to words
  76.   rep     movsw
  77. x0:
  78.   pop     ds                   ; Restore DS
  79.   pop     bp                   ;   and BP
  80.   mov     sp,bp
  81.   pop     bp
  82.   ret     10
  83. MoveToScreen    ENDP
  84.  
  85. ; procedure MoveFromScreen(var Source, Dest; Len : Word);
  86.  
  87. MoveFromScreen    PROC    FAR
  88.   push    bp
  89.   mov     bp,sp
  90.   push    bp                   ; Save Turbo's BP
  91.   push    ds                   ;   and DS
  92.   mov     bh,ds:CheckSnow      ; Load CheckSnow value
  93.   lds     si,dword ptr [bp+12] ; Source pointer into DS:SI
  94.   les     di,dword ptr [bp+8]  ; Dest pointer into ES:DI
  95.   mov     cx,[bp+6]            ; Len value into CX
  96.   cmp     cx,0                 ; Quit if Len = 0
  97.   je      y0
  98.   cmp     si,di
  99.   jle     y1
  100.   cld                          ; Set string direction to forward
  101.   jmp short y2
  102. y1:
  103.   add     si,cx
  104.   sub     si,2
  105.   add     di,cx
  106.   sub     di,2
  107.   std
  108. y2:
  109.   cmp     bh,0
  110.   je      y6
  111. y3:
  112.   shr     cx,1                 ; Change bytes to words
  113.   mov     dx,3DAh              ; Point DX to CGA status port
  114. y4:     
  115.   in      al,dx                ; Get 6845 status
  116.   rcr     al,1                 ; Check horizontal retrace
  117.   jb      y4                   ; Loop if in horizontal retrace: this prevents
  118.                                ;   starting in mid-retrace, since there is
  119.                                ;   exactly enough time for 1 and only 1 LODSW
  120.                                ;   during horizontal retrace
  121.   cli                          ; No ints during critical section
  122. y5:     
  123.   in      al,dx                ; Get 6845 status
  124.   rcr     al,1                 ; Check for horizontal retrace: LODSW is 1
  125.                                ;   clock cycle slower than STOSW; because of
  126.                                ;   this, the vertical retrace trick can't be
  127.                                ;   used because it causes flicker!  (RCR AL,1
  128.                                ;   is 1 cycle faster than AND AL,AH)
  129.   jnb     y5                   ; Loop if not in retrace
  130.   lodsw                        ; Load the video word
  131.   sti                          ; Allow interrupts
  132.   stosw                        ; Store the video word
  133.   loop    y4                   ; Go do next word
  134.   jmp short y0
  135. y6:
  136.   shr     cx,1                 ; Change bytes to words
  137.   rep movsw
  138. y0:
  139.   pop     ds                   ; Restore DS
  140.   pop     bp                   ;   and BP
  141.   mov     sp,bp
  142.   pop     bp
  143.   ret     10
  144. MoveFromScreen    ENDP
  145.  
  146. CODE    ENDS
  147.  
  148.     END
  149.