home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / basic / library / qb_pds / asmmod / getput.asm < prev    next >
Encoding:
Assembly Source File  |  1986-07-19  |  7.1 KB  |  156 lines

  1. TITLE: Character mode GET and PUT
  2. Two assy routines to make windowing in text mode a lot faster.  Pass them
  3. integer parameters ROW1%,COL1% and ROW2%,COL2% that indicate the upper left and
  4. lower right of the area to get or put (like the graphics stmts. GET and PUT,
  5. except in character units), and the first element (subscript 0 unless you've
  6. done an OPTION BASE 1, in which case it's 1) of an array big enough to hold the
  7. characters and attributes in that size window.  This will be (ROW2%-ROW1%+1) *
  8. (COL2%-COL1%+1) characters + the same number of attributes, so an integer array
  9. defined of size (ROW2%-ROW1%+1) * (COL2%-COL%1+1) (-1 if OPTION BASE 0) will do
  10. it.  Note that the program assumes IBM video with a CGA, and does next to no
  11. error checking if any at all.  Use carefully or modify so you don't crash if
  12. you use it wrong.  If the comments are unclear I will explain to anyone
  13. interested.  These are *very* much faster than trying to accomplish the same
  14. thing using the SCREEN function,  and I use them a lot.
  15.  
  16. Note the use of the structure to make the code more readable and eliminate the
  17. confusion as to just where the params are on the stack.  I recommend it as a
  18. practice to anyone who asks.  Also note that the routines are essentially the
  19. same except for the dataflow direction...if you're pressed for space you could
  20. add another parameter that indicates 'get' or 'put' and save a lot of space.
  21. IN the compiler, where I use this, code space is not a premium commodity.
  22.  
  23. The following is cget.  Call with CALL CGET(ROW1%,COL1%,ROW2%,COL2%,ARR%(0))
  24.  
  25.         page    ,132
  26. stack   struc
  27. bpsav   dw      ?                       ;saved by us
  28. retoff  dw      ?                       ;from callf
  29. retseg  dw      ?                       ; from BASIC
  30. array   dw      ?                       ;pointer to array in DS
  31. col2    dw      ?                       ;get characters from row1,col1
  32. row2    dw      ?                       ; to row2,col2
  33. col1    dw      ?                       ;
  34. row1    dw      ?                       ;
  35. stack   ends
  36.  
  37. code    segment public 'code'
  38.         assume  cs:code,ds:code
  39.         public  cget
  40.  
  41. cget    proc    far
  42.         push    bp
  43.         mov     bp,sp
  44.         mov     si,[bp].row2            ;si -> row2
  45.         mov     ax,[si]                 ;ax has last row
  46.         mov     si,[bp].row1            ;si -> row1
  47.         mov     bx,[si]                 ;form # of rows in ax
  48.         sub     ax,bx                   ;ax=rows-1
  49.         inc     ax                      ;ax=rows
  50.         mov     si,[bp].col2            ;si -> col2
  51.         mov     cx,[si]                 ;now form # of cols in cx
  52.         mov     si,[bp].col1            ;si -> col1
  53.         mov     bx,[si]                 ;bx=col1
  54.         sub     cx,bx                   ;cx has # of cols-1
  55.         inc     cx                      ;cx has # of cols
  56.         mov     bx,ax                   ;bx=# of rows
  57.  
  58.         push    ds                      ;save ds
  59.         pop     es                      ;es points to BASIC's ds
  60.         push    es                      ;restore on stack
  61.         mov     si,[bp].row1            ;si -> row1
  62.         mov     dx,[si]                 ;si will -> regen buffer
  63.         dec     dx                      ;make zero-rel
  64.         mov     ax,160                  ;multiplier
  65.         mul     dl                      ;ax=offset to row
  66.         mov     si,[bp].col1            ;si -> col1
  67.         mov     si,[si]
  68.         dec     si                      ;make col zero-rel
  69.         shl     si,1                    ;si=offset in row to col
  70.         add     si,ax                   ;total offset in si
  71.  
  72.         mov     di,[bp].array           ;di points to array element 0
  73.         mov     ax,0b800h               ;set up to vidram
  74.         mov     ds,ax                   ;
  75. loop:   push    cx                      ;save col count
  76.         rep     movs    word ptr es:[di],word ptr [si]
  77.         add     si,160                  ;new row
  78.         pop     cx                      ;cx=col count
  79.         sub     si,cx                   ;move back to right place
  80.         sub     si,cx                   ;twice because 2 bytes per char
  81.         dec     bx                      ;row count
  82.         jnz     loop
  83.  
  84.         pop     ds
  85.         pop     bp
  86.         ret     10                      ;get rid of 5 parms
  87. cget    endp
  88. code    ends
  89.         end
  90.  
  91. The following is cput.  Call with CALL CPUT(ROW1%,COL1%,ROW2%,COL2%,ARR%(0))
  92.  
  93.         page    ,132
  94. stack   struc
  95. bpsav   dw      ?                       ;saved by us
  96. retoff  dw      ?                       ;from callf
  97. retseg  dw      ?                       ;from BASIC
  98. array   dw      ?                       ;pointer to array in DS
  99. col2    dw      ?                       ;get characters from row1,col1
  100. row2    dw      ?                       ; to row2,col2
  101. col1    dw      ?                       ;
  102. row1    dw      ?                       ;
  103. stack   ends
  104.  
  105. code    segment public 'code'
  106.         assume  cs:code,ds:code
  107.         public  cput
  108.  
  109. cput    proc    far
  110.         push    bp
  111.         mov     bp,sp
  112.         mov     si,[bp].row2            ;si -> row2
  113.         mov     ax,[si]                 ;ax has last row
  114.         mov     si,[bp].row1            ;si -> row1
  115.         mov     bx,[si]                 ;form # of rows in ax
  116.         sub     ax,bx                   ;ax=rows-1
  117.         inc     ax                      ;ax=rows
  118.         mov     si,[bp].col2            ;si -> col2
  119.         mov     cx,[si]                 ;now form # of cols in cx
  120.         mov     si,[bp].col1            ;si -> col1
  121.         mov     bx,[si]                 ;bx=col1
  122.         sub     cx,bx                   ;cx has # of cols-1
  123.         inc     cx                      ;cx has # of cols
  124.         mov     bx,ax                   ;bx=# of rows
  125.  
  126.         push    es                      ;restore on stack
  127.         mov     si,[bp].row1            ;di -> row1
  128.         mov     dx,[si]                 ;di will -> regen buffer
  129.         dec     dx                      ;make zero-rel
  130.         mov     ax,160                  ;multiplier
  131.         mul     dl                      ;ax=offset to row
  132.         mov     di,[bp].col1            ;di -> col1
  133.         mov     di,[di]
  134.         dec     di                      ;make col zero-rel
  135.         shl     di,1                    ;di=offset in row to col
  136.         add     di,ax                   ;total offset in di
  137.  
  138.         mov     si,[bp].array           ;si points to array element 0
  139.         mov     ax,0b800h               ;set up to vidram
  140.         mov     es,ax                   ;
  141. loop:   push    cx                      ;save col count
  142.         rep     movs    word ptr es:[di],word ptr [si]
  143.         add     di,160                  ;new row
  144.         pop     cx                      ;cx=col count
  145.         sub     di,cx                   ;move back to right place
  146.         sub     di,cx                   ;twice because 2 bytes per char
  147.         dec     bx                      ;row count
  148.         jnz     loop
  149.  
  150.         pop     es
  151.         pop     bp
  152.         ret     10                      ;get rid of 5 parms
  153. cput    endp
  154. code    ends
  155.         end
  156.