home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / sd386v50.zip / sd386src.zip / VBOX.ASM < prev    next >
Assembly Source File  |  1996-04-19  |  12KB  |  407 lines

  1.         page    ,132
  2.         title   Video Box Routines
  3.         subttl  Copyright (C) 1988 IBM (Written 11/87 by Jim Christensen)
  4.         name    VBOX
  5.  
  6.         .386
  7. _TEXT   SEGMENT  DWORD USE32 PUBLIC 'CODE'
  8. _TEXT      ENDS
  9. _DATA   SEGMENT  DWORD USE32 PUBLIC 'DATA'
  10. _DATA      ENDS
  11.         ASSUME   CS: FLAT, DS: FLAT, SS: FLAT, ES: FLAT
  12. _DATA   SEGMENT  DWORD USE32 PUBLIC 'DATA'
  13.         extrn    VideoPtr:dword  ;Pointer to logical video buffer
  14.         extrn    VideoMap:dword  ;Pointer to logical to physical attr vector
  15.         extrn    VideoCols:word  ;# of columns per screen row
  16.         extrn    VideoAtr:byte   ;default logical video attribute
  17.  
  18. TBEDGE   = 0CDh
  19. LREDGE   = 0BAh
  20. TLCORNER = 0C9h
  21. TRCORNER = 0BBh
  22. BLCORNER = 0C8h
  23. BRCORNER = 0BCh
  24.  
  25.         align 4
  26. _DATA   ends
  27. EXTRN   Vio32ShowBuf:near
  28. PUBLIC  Vgetbox
  29. PUBLIC  Vputbox
  30. PUBLIC  Vfmtbox
  31. _TEXT   SEGMENT  DWORD USE32 PUBLIC 'CODE'
  32.  
  33. ;------------------------------------------------------------------------------;
  34. ; name          Vgetbox
  35. ;
  36. ; synopsis      Vgetbox( buffer, row, col, rows, cols );
  37. ;               char *buffer;           /* pointer to buffer for data */
  38. ;               int row, col,           /* upper left corner of box (0..N) */
  39. ;               int rows, cols;         /* size of box (1..N) */
  40. ;
  41. ; description   This function copies the (attr,char) pairs from the specified
  42. ;               rectangle in the video buffer to the buffer provided.
  43. ;------------------------------------------------------------------------------;
  44.  
  45. buffer = 8
  46. row    = 12
  47. col    = 16
  48. rows   = 20
  49. cols   = 24
  50.  
  51. Vgetbox PROC   NEAR
  52.         push    ebp
  53.         mov     ebp,esp
  54.         push    ds                 ;save flat address
  55.         push    esi
  56.         push    edi
  57.         push    eax
  58.         push    ebx
  59.         push    ecx
  60.         push    edx
  61.  
  62.         xor     esi, esi           ;clear working reg
  63.         xor     eax, eax           ;clear working reg
  64.         mov     ebx, [ebp+row]
  65.         mov     ecx, [ebp+col]
  66.         mov     edx, [ebp+cols]
  67.         mov     dh,  [ebp+rows]
  68.         call    setABCD
  69.         lds     si, VideoPtr  ;ds:si -> 1st (char,attr) in video ram
  70.         add     si, ax
  71.         mov     edi, [ebp+buffer]   ;es:di -> video save buffer
  72. gb10:
  73.         mov     cl, bl
  74.         rep     movsw
  75.         add     si, dx
  76.         dec     bh
  77.         jnz     gb10
  78.  
  79.         pop     edx
  80.         pop     ecx
  81.         pop     ebx
  82.         pop     eax
  83.         pop     edi
  84.         pop     esi
  85.         pop     ds
  86.         leave
  87.         ret
  88. Vgetbox endp
  89.  
  90. ;------------------------------------------------------------------------------;
  91. ; name          Vputbox
  92. ;
  93. ; synopsis      Vputbox( buffer, row, col, rows, cols );
  94. ;               char *buffer;           /* pointer to buffer for data */
  95. ;               int row, col,           /* upper left corner of box (0..N) */
  96. ;               int rows, cols;         /* size of box (1..N) */
  97. ;
  98. ; description   This function copies the (attr,char) pairs from the buffer
  99. ;               to the specified rectangle of the video buffer.
  100. ;------------------------------------------------------------------------------;
  101.  
  102. buffer = 8
  103. row    = 12
  104. col    = 16
  105. rows   = 20
  106. cols   = 24
  107.  
  108. Vputbox PROC   NEAR
  109.         push    ebp
  110.         mov     ebp,esp
  111.         push    esi
  112.         push    edi
  113.         push    eax
  114.         push    ebx
  115.         push    ecx
  116.         push    edx
  117.         push    es                 ;save flat address
  118.  
  119.         xor     edi, edi           ;clear working reg
  120.         xor     eax, eax           ;clear working reg
  121.         mov     ebx, [ebp+row]
  122.         mov     ecx, [ebp+col]
  123.         mov     edx, [ebp+cols]
  124.         mov     dh,  [ebp+rows]
  125.         call    setABCD
  126.         les     di, VideoPtr      ;es:di -> 1st (char,attr) in video ram
  127.         add     di, ax
  128.         push    ax                ;save starting video buffer offset
  129.         push    di                ;save starting video buffer address
  130.         mov     esi, [ebp+buffer]   ;ds:si -> video save buffer on stack
  131. pb10:
  132.         mov     cl, bl
  133.         rep     movsw
  134.         add     di, dx
  135.         dec     bh
  136.         jnz     pb10
  137.  
  138.         pop     ax                ;starting video buffer adddress
  139.         sub     di, ax            ;di = # of bytes changed
  140.         pop     ax                ;starting screen buffer offset
  141.         pop     es                 ;restore flat address reg
  142.  
  143.         push    00                 ;3rd parm to Vio32ShowBuf
  144.         push    edi                ;2nd parm to Vio32ShowBuf
  145.         push    eax                ;1st parm to Vio32ShowBuf
  146.         call    Vio32ShowBuf
  147.         add     esp,0Ch
  148.  
  149.         pop     edx
  150.         pop     ecx
  151.         pop     ebx
  152.         pop     eax
  153.         pop     edi
  154.         pop     esi
  155.         leave
  156.         ret
  157. Vputbox endp
  158.  
  159. ;------------------------------------------------------------------------------;
  160. ; name          Vfmtbox
  161. ;
  162. ; synopsis      Vfmtbox( buffer, row, col, rows, cols );
  163. ;               char *buffer;           /* pointer to buffer for data */
  164. ;               int row, col,           /* upper left corner of box (0..N) */
  165. ;               int rows, cols;         /* size of box (1..N) */
  166. ;
  167. ; description   This function formats the specified rectangle of the video ram,
  168. ;               and then puts the message contained in the buffer into it.  The
  169. ;               format of the message in the buffer is as follows:
  170. ;
  171. ;               row (byte), col (byte), text (N bytes), zero (byte)
  172. ;
  173. ;               The buffer contains any number of these sequences, ended by
  174. ;               a row of zero.  The row and column are relative to the edges
  175. ;               of the box.  A column of zero indicates a centered row.  Note
  176. ;               that the first and last row and column are used by the border
  177. ;               of the box.
  178. ;------------------------------------------------------------------------------;
  179.  
  180. TVideoAtr       equ byte ptr [ebp-30] ;default physical attribute on stack
  181. VideoOffset     equ word ptr [ebp-32] ;segment offset of start of video buffer
  182.  
  183. buffer = 8
  184. row    = 12
  185. col    = 16
  186. rows   = 20
  187. cols   = 24
  188.  
  189. Vfmtbox PROC   NEAR
  190.         push    ebp
  191.         mov     ebp,esp
  192.         push    esi
  193.         push    edi
  194.         push    eax
  195.         push    ebx
  196.         push    ecx
  197.         push    edx
  198.         push    es                 ;save flat address
  199.  
  200.         xor     eax, eax          ;clear working reg
  201.         mov     ebx, VideoMap     ;es:bx -> Logical to Physical attribute table
  202.         mov     al, VideoAtr      ;al = default logical attribute
  203.         xlat                      ;al = default physical attribute
  204.         push    ax                ;set VideoAtr to default physical attribute
  205.  
  206.         xor     edi, edi          ;clear working reg
  207.         les     di, VideoPtr      ;es:di -> video buffer
  208.         push    di                ;set VideoOffset to start of logical buffer
  209.  
  210.         mov     al, ' '
  211.         mov     ebx, [ebp+row]
  212.         mov     ecx, [ebp+col]
  213.         mov     edx, [ebp+cols]
  214.         mov     dh,  [ebp+rows]
  215.         call    filblk
  216.  
  217.         mov     al, TBEDGE
  218.         mov     bx, [ebp+row]
  219.         mov     cx, [ebp+col]
  220.         mov     dh, 1
  221.         mov     dl, [ebp+cols]
  222.         call    filblk
  223.  
  224.         mov     al, TBEDGE
  225.         mov     bx, [ebp+row]
  226.         add     bx, [ebp+rows]
  227.         dec     bx
  228.         mov     cx, [ebp+col]
  229.         mov     dh, 1
  230.         mov     dl, [ebp+cols]
  231.         call    filblk
  232.  
  233.         mov     al, LREDGE
  234.         mov     bx, [ebp+row]
  235.         mov     cx, [ebp+col]
  236.         mov     dh, [ebp+rows]
  237.         mov     dl, 1
  238.         call    filblk
  239.  
  240.         mov     al, LREDGE
  241.         mov     bx, [ebp+row]
  242.         mov     cx, [ebp+col]
  243.         add     cx, [ebp+cols]
  244.         dec     cx
  245.         mov     dh, [ebp+rows]
  246.         mov     dl, 1
  247.         call    filblk
  248.  
  249.         mov     al, TLCORNER
  250.         mov     bx, [ebp+row]
  251.         mov     cx, [ebp+col]
  252.         mov     dx, 0101h
  253.         call    filblk
  254.  
  255.         mov     al, BLCORNER
  256.         mov     bx, [ebp+row]
  257.         add     bx, [ebp+rows]
  258.         dec     bx
  259.         mov     cx, [ebp+col]
  260.         mov     dx, 0101h
  261.         call    filblk
  262.  
  263.         mov     al, TRCORNER
  264.         mov     bx, [ebp+row]
  265.         mov     cx, [ebp+col]
  266.         add     cx, [ebp+cols]
  267.         dec     cx
  268.         mov     dx, 0101h
  269.         call    filblk
  270.  
  271.         mov     al, BRCORNER
  272.         mov     bx, [ebp+row]
  273.         add     bx, [ebp+rows]
  274.         dec     bx
  275.         mov     cx, [ebp+col]
  276.         add     cx, [ebp+cols]
  277.         dec     cx
  278.         mov     dx, 0101h
  279.         call    filblk
  280.  
  281.         mov     esi, [ebp+buffer] ;ds:si -> buffer
  282. fb10:
  283.         lodsw                   ;(ah,al) = relative (col,row) for line
  284.         or      al, al
  285.         jz      fb90            ;jump if end of text
  286.         or      ah, ah
  287.         jnz     fb20            ;jump if starting column specified
  288.  
  289.         mov     di, si          ;di -> 1st byte of text
  290.         xor     ax, ax
  291.         mov     cx, -1
  292.         push    es
  293.         push    ds
  294.         pop     es              ;es:di -> 1st byte of text
  295.         repne   scasb           ;scan for trailing null
  296.         pop     es
  297.         inc     cx              ;cx = -1 - (# chars + 1) + 1
  298.         inc     cx              ;cx = -(# chars)
  299.         add     cx, [ebp+cols]   ;cx = # of spare columns
  300.         js      fb90            ;jump if text wider than box
  301.         shr     cx, 1
  302.  
  303.         movzx   cx, cl                   ;cl     = relative col
  304.         movzx   bx, byte ptr [si-2]      ;[si-2] = relative row
  305.  
  306. fb20:
  307.         add     bx, [ebp+row]   ;bx = absolute row
  308.         add     cx, [ebp+col]   ;cx = absolute col
  309.         mov     ax, VideoCols
  310.         mul     bx              ;ax = screen offset to start of row
  311.         add     ax, cx          ;ax = screen offset to start of msg
  312.         shl     ax, 1           ;ax = video buffer offset to start of msg
  313.         xchg    ax, di          ;es:di -> 1st (char,attr) in video ram
  314.         mov     cx, VideoCols
  315.         mov     ah, TVideoAtr
  316.         jmp     short fb40
  317. fb30:
  318.         stosw
  319. fb40:
  320.         lodsb
  321.         or      al, al
  322.         loopnz  fb30
  323.         jz      fb10
  324. fb90:
  325.         add     sp, 4           ;discard VideoAtr and VideoOffset
  326.         pop     es                 ;restore flat address reg
  327.         push    0               ;3rd parm to Vio16ShowBuf
  328.  
  329.         mov     ax, [ebp+rows]
  330.         dec     ax
  331.         mov     bx, VideoCols
  332.         mul     bx
  333.         add     ax, [ebp+cols]
  334.         shl     ax, 1
  335.         push    eax              ;2nd parm to Vio16ShowBuf
  336.  
  337.         mov     ax, VideoCols
  338.         mul     word ptr [ebp+row]
  339.         add     ax, [ebp+col]
  340.         shl     ax, 1           ;ax = starting video buffer offset
  341.         push    eax              ;1st parm to Vio16ShowBuf
  342.         call    Vio32ShowBuf
  343.         add     esp,0Ch
  344.  
  345.         pop     edx
  346.         pop     ecx
  347.         pop     ebx
  348.         pop     eax
  349.         pop     edi
  350.         pop     esi
  351.         leave
  352.         ret
  353. Vfmtbox endp
  354.  
  355. ;Input  bx = row (0..N)
  356. ;       cx = col (0..N)
  357. ;       dh = # of rows (1..N)
  358. ;       dl = # of cols (1..N)
  359. ;
  360. ;Output ax = video buffer offset to (row,col)
  361. ;       bh = # of rows (1..N)
  362. ;       bl = # of cols (1..N)
  363. ;       cx = 0
  364. ;       dx = (# of cols/screen) - (# of cols used)
  365.  
  366. setABCD proc    near
  367.         xchg    ax, bx          ;ax = row (0..N)
  368.         push    edx
  369.         mov     bx, VideoCols
  370.         mul     bx
  371.         pop     edx
  372.         add     ax, cx
  373.         shl     ax, 1
  374.  
  375.         mov     bx, dx          ;(bh,bl) = (# of rows, # of cols)
  376.         xor     dx, dx
  377.         mov     dx, VideoCols
  378.         movzx   cx, bl
  379.         sub     dx, cx
  380.         shl     dx, 1
  381.         xor     cx, cx
  382.  
  383.         ret
  384. setABCD endp
  385.  
  386. filblk  proc    near
  387.         push    ax
  388.         call    setABCD
  389.         add     ax, VideoOffset
  390.         xchg    ax, di          ;es:di -> 1st (char,attr) in video ram
  391.  
  392.         pop     ax
  393.         mov     ah, TVideoAtr    ;display attribute
  394. fl10:
  395.         mov     cl, bl
  396.         rep     stosw
  397.  
  398.         add     di, dx
  399.         dec     bh
  400.         jnz     fl10
  401.  
  402.         ret
  403. filblk  endp
  404.  
  405. _TEXT   ends
  406.         end
  407.