home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / pascal / turbo55 / tp55 / tcmvsmem.asm < prev    next >
Assembly Source File  |  1989-05-02  |  6KB  |  152 lines

  1. ; Turbo Pascal 5.5 object-oriented example
  2. ; Assembler code for TCALC example
  3. ; Copyright (c) 1989 by Borland International, Inc.
  4.  
  5. MODEL TPASCAL
  6.  
  7. LOCALS
  8.  
  9. DATASEG
  10.  
  11.   EXTRN CheckSnow : BYTE
  12.  
  13. CODESEG
  14.  
  15.   PUBLIC MoveToScreen, MoveFromScreen
  16.  
  17. ; procedure MoveToScreen(var Source, Dest; Len : Word);
  18. ;
  19. ; Moves memory from normal RAM to screen memory, making sure that the video
  20. ; interference that can occur when you do this on certain CGA's is
  21. ; prevented.
  22. ;
  23. ; Variables:
  24. ;
  25. ;   Source : Far pointer to the location of the memory to be moved.
  26. ;   Dest : Far pointer to the destination of the memory to be moved.
  27. ;   Len : The amount in bytes of the memory to be moved.
  28.  
  29. Proc MoveToScreen Source : DWord, Dest : DWord, Len : Word
  30.   push    ds                   ; Save DS
  31.   mov     bh,[CheckSnow]       ; Load CheckSnow value
  32.   lds     si,[Source]          ; Source pointer into DS:SI
  33.   les     di,[Dest]            ; Dest pointer into ES:DI
  34.   mov     cx,[Len]             ; Len value into CX
  35.   jcxz    @@0                  ; Quit if Len = 0
  36.   cmp     si,di                ; Find out if source comes before destination
  37.                                ;   in memory
  38.   jle     @@1                  ; If it does, copy from end of memory area
  39.   cld                          ; Set direction to forward
  40.   jmp     short @@2
  41. @@1:
  42.   add     si,cx                ; Move SI and DI to the ends of the memory
  43.   sub     si,2                 ;   areas
  44.   add     di,cx
  45.   sub     di,2
  46.   std                          ; Set direction to backward
  47. @@2:
  48.   cmp     bh,0                 ; If CheckSnow is false, use fast screen I/O
  49.   je      @@7
  50. @@3:
  51.   shr     cx,1                 ; Change bytes to words
  52.   mov     dx,3DAh              ; Point DX to CGA status port
  53.   mov     bl,9                 ; Move horiz. + vertical retrace mask to bl
  54. @@4:
  55.   lodsw                        ; Grab a video word
  56.   mov     bp,ax                ; Save it in BP
  57. @@5:
  58.   in      al,dx                ; Get 6845 status
  59.   rcr     al,1                 ; Check horizontal retrace
  60.   jb      @@5                  ; Loop if in horizontal retrace: this prevents
  61.                                ;   starting in mid-retrace, since there is
  62.                                ;   exactly enough time for 1 and only 1 STOSW
  63.                                ;   during horizontal retrace
  64.   cli                          ; No ints during critical section
  65. @@6:
  66.   in      al,dx                ; Get 6845 status
  67.   and     al,bl                ; Check for both kinds of retrace: IF the
  68.                                ;   video board does not report horizontal
  69.                                ;   retrace while in vertical retrace, this
  70.                                ;   will allow several characters to be
  71.                                ;   stuffed in during vertical retrace
  72.   jz      @@6                  ; Loop if equal to zero
  73.   mov     ax,bp                ; Get the video word
  74.   stosw                        ; Store the video word
  75.   sti                          ; Allow interrupts
  76.   loop    @@4                  ; Go do next word
  77.   jmp     short @@0
  78. @@7:
  79.   shr     cx,1                 ; Change bytes to words
  80.   rep     movsw
  81. @@0:
  82.   pop     ds                   ; Restore DS
  83.   ret
  84. ENDP
  85.  
  86. ; procedure MoveFromScreen(var Source, Dest; Len : Word);
  87. ;
  88. ; Moves memory to normal RAM from screen memory, making sure that the video
  89. ; interference that can occur when you do this on certain CGA's is
  90. ; prevented.
  91. ;
  92. ; Variables:
  93. ;
  94. ;   Source : Far pointer to the location of the memory to be moved.
  95. ;   Dest : Far pointer to the destination of the memory to be moved.
  96. ;   Len : The amount in bytes of the memory to be moved.
  97.  
  98. Proc MoveFromScreen Source : DWord, Dest : DWord, Len : Word
  99.   push    ds                   ; Save DS
  100.   mov     bh,[CheckSnow]       ; Load CheckSnow value
  101.   lds     si,[Source]          ; Source pointer into DS:SI
  102.   les     di,[Dest]            ; Dest pointer into ES:DI
  103.   mov     cx,[Len]             ; Len value into CX
  104.   jcxz    @@0                  ; Quit if Len = 0
  105.   cmp     si,di                ; Find out if source comes before destination
  106.                                ;   in memory
  107.   jle     @@1
  108.   cld                          ; Set direction to forward
  109.   jmp     short @@2
  110. @@1:
  111.   add     si,cx                ; Move SI and DI to the ends of the memory
  112.   sub     si,2                 ;   areas
  113.   add     di,cx
  114.   sub     di,2
  115.   std                          ; Set direction to backward
  116. @@2:
  117.   cmp     bh,0                 ; If CheckSnow is false, use fast screen I/O
  118.   je      @@6
  119. @@3:
  120.   shr     cx,1                 ; Change bytes to words
  121.   mov     dx,3DAh              ; Point DX to CGA status port
  122. @@4:
  123.   in      al,dx                ; Get 6845 status
  124.   rcr     al,1                 ; Check horizontal retrace
  125.   jb      @@4                  ; Loop if in horizontal retrace: this prevents
  126.                                ;   starting in mid-retrace, since there is
  127.                                ;   exactly enough time for 1 and only 1 LODSW
  128.                                ;   during horizontal retrace
  129.   cli                          ; No ints during critical section
  130. @@5:
  131.   in      al,dx                ; Get 6845 status
  132.   rcr     al,1                 ; Check for horizontal retrace: LODSW is 1
  133.                                ;   clock cycle slower than STOSW; because of
  134.                                ;   this, the vertical retrace trick can't be
  135.                                ;   used because it causes flicker!  (RCR AL,1
  136.                                ;   is 1 cycle faster than AND AL,AH)
  137.   jnb     @@5                  ; Loop if not in retrace
  138.   lodsw                        ; Load the video word
  139.   sti                          ; Allow interrupts
  140.   stosw                        ; Store the video word
  141.   loop    @@4                  ; Go do next word
  142.   jmp     short @@0
  143. @@6:
  144.   shr     cx,1                 ; Change bytes to words
  145.   rep     movsw
  146. @@0:
  147.   pop     ds                   ; Restore DS
  148.   ret
  149. ENDP
  150.  
  151. END
  152.