home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / ddkx86v5.zip / DDKX86 / SRC / VDH / XGAREAD.ASM < prev    next >
Assembly Source File  |  1995-04-14  |  41KB  |  791 lines

  1. ;*DDK*************************************************************************/
  2. ;
  3. ; COPYRIGHT (C) Microsoft Corporation, 1989
  4. ; COPYRIGHT    Copyright (C) 1995 IBM Corporation
  5. ;
  6. ;    The following IBM OS/2 WARP source code is provided to you solely for
  7. ;    the purpose of assisting you in your development of OS/2 WARP device
  8. ;    drivers. You may use this code in accordance with the IBM License
  9. ;    Agreement provided in the IBM Device Driver Source Kit for OS/2. This
  10. ;    Copyright statement may not be removed.;
  11. ;*****************************************************************************/
  12.         PAGE    60,132
  13.         TITLE   XGAREAD.ASM -- Common Buffer Read Routines for EGA, VGA, BGA
  14. ;/*****************************************************************************
  15. ;*
  16. ;* SOURCE FILE NAME = XGAREAD.ASM
  17. ;*
  18. ;* DESCRIPTIVE NAME = BUFFERUPDATE read routines     
  19. ;*
  20. ;*
  21. ;* VERSION      V2.0
  22. ;*
  23. ;* DATE         
  24. ;*
  25. ;* DESCRIPTION  Common Buffer Read Routines for EGA, VGA, BGA 
  26. ;*
  27. ;* FUNCTIONS    ReadCellTypes   
  28. ;*              ReadCharStr     
  29. ;*              ReadCellStr     
  30. ;*              SetBuffAddr 
  31. ;*              FastBuffAddr    
  32. ;*              CalcTouchRect   
  33. ;*
  34. ;* NOTES        NONE
  35. ;*             
  36. ;* STRUCTURES   NONE
  37. ;*
  38. ;* EXTERNAL REFERENCES  
  39. ;*
  40. ;*              NONE
  41. ;*
  42. ;* EXTERNAL FUNCTIONS
  43. ;*
  44. ;*              NONE
  45. ;*
  46. ;* CHANGE ACTIVIY =
  47. ;*   DATE      FLAG       APAR    CHANGE DESCRIPTION
  48. ;*   --------  ---------- -----   --------------------------------------
  49. ;*   mm/dd/yy  @Vr.mpppxx xxxxx   xxxxxxx
  50. ;*  03/25/89   @P1                TPL, DCR 132 changes
  51. ;*  06/25/89   @T37       B703759 TPL, DCR 132 fix
  52. ;*  01/29/91   MS00               TPL, Convert IFDEF to IF
  53. ;*  01/29/91   MS01               TPL, Rollover MS's runtime
  54. ;*                                check for CGA speedup
  55. ;*  04/11/91   D1348      D1348   NAKADA, Enable DBCS support in Vio-Window 
  56. ;*****************************************************************************/
  57.  
  58.         .286c                           ; 286 protect mode instructions
  59.  
  60.         .xlist
  61.         INCLUDE struc.inc               ; Structure macro
  62.         INCLUDE error2.inc              ; Subsystem error equates
  63.         INCLUDE vdhstruc.inc            ; Buffer update data structures
  64.         INCLUDE vdhctl.inc              ; Conditional Assembly Control  ;MS01
  65.         INCLUDE vdhequ.inc              ; Buffer update equates
  66.         INCLUDE xgamac.inc                                              ;@P1
  67.         .list
  68.  
  69.         EXTRN   SetGenParms:NEAR        ; Set up general buffer update parms @P1
  70.  
  71. IF VDHCGA AND (1 - CGA_ALWAYS_FAST)     ; IF VDHCGA AND NOT CGA_ALWAYS_FAST ;MS01
  72.  
  73. ;/*
  74. ;**  If CGA video memory accesses may need to wait for retrace,
  75. ;**  these routines are necessary. (See MAKEFILE)
  76. ;*/
  77.         extrn   CGA_REP_MOVSW:far                                       ;@P1
  78.         extrn   CGA_REP_STOSW:far                                       ;@P1
  79.         extrn   CGA_REP_MOVSB_INCSI_LOOP:far                            ;@P1
  80.         extrn   CGA_REP_MOVSW_STOSW_LOOP:far                            ;@P1
  81.         extrn   CGA_REP_INCDI_STOSB_LOOP:far                            ;@P1
  82.         extrn   CGA_REP_STOSB_INCDI_LOOP:far                            ;@P1
  83.         extrn   CGA_REP_LODSB_STOSW_LOOP:far                            ;@P1
  84.         extrn   CGA_REP_MOVSB_INCDI_LOOP:far                            ;@P1
  85.         extrn   CGA_REP_MOVSW_ADDSI2_LOOP:far                           ;@P1
  86. ENDIF   ;VDHCGA                                                         ;MS00
  87.  
  88. IFDEF D1348 ;See whether it is of DBCS or not.
  89.         extrn   ReadCellTypesWrld:near
  90.     IFDEF MSKK  ;DBCS bits read
  91.         extrn   ReadCharStrWrld:near
  92.         extrn   ReadCellStrWrld:near
  93.     ENDIF
  94. ENDIF ;D1348
  95.  
  96. R2CSEG  SEGMENT WORD PUBLIC 'CODE'
  97.         ASSUME  CS:R2CSEG,DS:NOTHING,ES:NOTHING
  98.  
  99. ;/****************************************************************************
  100. ;*                                                                     
  101. ;* SUBROUTINE NAME:     ReadCellTypes  ReadCellTypes3                  
  102. ;*                                                                     
  103. ;* DESCRIPTIVE NAME:    Video device handler read cell types           
  104. ;*                                                                     
  105. ;* FUNCTION:    Process read cell types sub-function.                  
  106. ;*                                                                     
  107. ;* ENTRY POINT: ReadCellTypes                                          
  108. ;*   LINKAGE:   Near Call from BUFFERUPDATE rouinte                    
  109. ;*                                                                     
  110. ;* INPUT:                                                              
  111. ;*                                                                     
  112. ;* AX = 0                                                              
  113. ;* SS:BP  --->  Stack frame                     (see VDHSTRUC.INC)     
  114. ;* DS:SI  --->  Parameter block buffer          (see XGABUFUP.ASM)     
  115. ;* ES:DI  --->  Mode data in environment buffer (see XGABUFUP.ASM)     
  116. ;*                                                                     
  117. ;* PARAMETER BLOCK FORMAT:                                             
  118. ;*                                                                     
  119. ;*   SIZE   DESCRIPTION                                                
  120. ;*   ----   -----------                                                
  121. ;*                                                                     
  122. ;*   WORD   Parameter length                                           
  123. ;*   WORD   Flags                     (source data buffer - LVB, PVB)  
  124. ;*   DWORD  Application data address  (target data buffer)             
  125. ;*   DWORD  Application data2 address (not used in this call)          
  126. ;*   WORD   Index (0)                                                  
  127. ;*   WORD   Starting row              (source row)                     
  128. ;*   WORD   Starting column           (source column)                  
  129. ;*   WORD   Secondary row             (not used in this call)          
  130. ;*   WORD   Secondary column          (not used in this call)          
  131. ;*   WORD   RepeatFactor              (input and output length)        
  132. ;*   WORD   LogicalBufSel                                              
  133. ;*                                                                     
  134. ;* OUTPUT:                                                             
  135. ;*                                                                     
  136. ;* EXIT-NORMAL: AX = 0                                                 
  137. ;*                                                                     
  138. ;* EXIT-ERROR:  AX = Error from LocateBuffAddr                         
  139. ;*                                                                     
  140. ;* EFFECTS:     All                                                    
  141. ;*                                                                     
  142. ;* INTERNAL REFERENCES: LocateBuffAddr                                 
  143. ;*                                                                     
  144. ;* EXTERNAL REFERENCES: None                                           
  145. ;*                                                                     
  146. ;****************************************************************************/
  147.  
  148.         PUBLIC  ReadCellTypes
  149.         PUBLIC  ReadCellTypes3                                          ;@P1
  150. ReadCellTypes   PROC    NEAR
  151. ReadCellTypes3:                                                         ;@P1
  152. IFDEF D1348 ;CheckCharType of DBCS
  153.         mov     bx,0                            ; Operation in terms of cells
  154. ELSE  ;D1348
  155.         mov     bx, 1                           ; Set indicator for word move
  156. ENDIF ;D1348
  157.         call    SetBuffAddr                     ; On exit: BX = sel, AX = off @P1
  158.         .if     <nc>                            ; Continue?
  159.             shr     cx, 1                       ; Adjust for word move
  160.             les     di, [si].AppDataAddr        ; Setup destination address @P1
  161.  
  162. IFDEF D1348 ;CheckCharType of DBCS
  163.             .if    <bit <[bp].flgDBCS> and anyDBCS> and
  164.             .if    <[bp].j_funcindx eq WorldFmtIndx>
  165.                 mov     ds,bx                   ; Use LVB as source
  166.                 mov     si,ax                   ; Setup source offset
  167.                 call    ReadCellTypesWrld
  168.                 sub     ax,ax                   ; Clear return code
  169.             .else
  170. ENDIF ;D1348
  171.  
  172.                 sub     ax, ax                  ; Clear return code         @P1
  173.                 rep     stosw                   ; Transfer zeros to user buffer @P1
  174. IFDEF D1348
  175.             .endif
  176. ENDIF ;D1348
  177.         .endif                                  ; 
  178.         ret
  179.  
  180. ReadCellTypes   ENDP
  181.  
  182. ;/****************************************************************************
  183. ;*                                                                     
  184. ;* SUBROUTINE NAME:     ReadCharStr                                    
  185. ;*                                                                     
  186. ;* DESCRIPTIVE NAME:    Video device handler read characters           
  187. ;*                                                                     
  188. ;* FUNCTION:    Process read characters sub-function.                  
  189. ;*              The characters are read from either PVB or LVB         
  190. ;*              starting at the specified row, column location.        
  191. ;*              Line wrap occurs if the end of a line is reached.      
  192. ;*              Read function is terminated if the end of PVB or       
  193. ;*              LVB is reached.  The characters read are placed        
  194. ;*              in the specified buffer and the number of chars        
  195. ;*              read is returned in the RepeatFactor field of          
  196. ;*              the parameter block.                                   
  197. ;*                                                                     
  198. ;* ENTRY POINT: ReadCharStr                                            
  199. ;*   LINKAGE:   Near Call from BUFFERUPDATE routine                    
  200. ;*                                                                     
  201. ;* INPUT:                                                              
  202. ;*                                                                     
  203. ;* AX = 0                                                              
  204. ;* SS:BP  --->  Stack frame                     (see VDHSTRUC.INC)     
  205. ;* DS:SI  --->  Parameter block buffer          (see XGABUFUP.ASM)     
  206. ;* ES:DI  --->  Mode data in environment buffer (see XGABUFUP.ASM)     
  207. ;*                                                                     
  208. ;* PARAMETER BLOCK FORMAT:                                             
  209. ;*                                                                     
  210. ;*   SIZE   DESCRIPTION                                                
  211. ;*   ----   -----------                                                
  212. ;*                                                                     
  213. ;*   WORD   Parameter length                                           
  214. ;*   WORD   Flags                     (source data buffer - LVB, PVB)  
  215. ;*   DWORD  Application data address  (target data buffer)             
  216. ;*   DWORD  Application data2 address (not used in this call)          
  217. ;*   WORD   Index (1)                                                  
  218. ;*   WORD   Starting row              (source row)                     
  219. ;*   WORD   Starting column           (source column)                  
  220. ;*   WORD   Secondary row             (not used in this call)          
  221. ;*   WORD   Secondary column          (not used in this call)          
  222. ;*   WORD   RepeatFactor              (input and output length)        
  223. ;*   WORD   LogicalBufSel                                              
  224. ;*                                                                     
  225. ;* OUTPUT:      Application data buffer = characters read              
  226. ;*              RepeatFactor = number of characters read               
  227. ;*                                                                     
  228. ;* EXIT-NORMAL: AX = 0                                                 
  229. ;*                                                                     
  230. ;* EXIT-ERROR:  AX = Error from LocateBuffAddr                         
  231. ;*                                                                     
  232. ;* EFFECTS:     All registers                                          
  233. ;*                                                                     
  234. ;* INTERNAL REFERENCES: LocateBuffAddr                                 
  235. ;*                                                                     
  236. ;* EXTERNAL REFERENCES: None                                           
  237. ;*                                                                     
  238. ;****************************************************************************/
  239.  
  240.         PUBLIC  ReadCharStr
  241. ReadCharStr     PROC    NEAR
  242.  
  243.         mov     bx, 0                           ; Move in terms of Cell count
  244.         call    SetBuffAddr                     ; On exit: BX = sel, AX = off @P1
  245.         .if     <nc>                            ; Continue?
  246.             .if     <nonzero bx>                ; LVB flag set?             @P1
  247.                 les     di, [si].AppDataAddr    ; Setup destination address @P1
  248.                 mov     ds, bx                  ; Use LVB as source         @P1
  249.                 mov     si, ax                  ; Setup source offset       @P1
  250.                 .if     <[bp].cellsize e WorldCellSize> near                @P1
  251.                     .repeat                     ;                           @P1
  252.                         movsb                   ; Transfer chars to destination
  253.                         add     si, 3           ; skip the attribute bytes  @P1
  254.                     .loop                       ;                           @P1
  255.                 .else                           ;                           @P1
  256.                     .repeat                     ;                           @P1
  257.                         movsb                   ; Transfer chars to destination
  258.                         inc     si              ; skip the attribute byte   @P1
  259.                     .loop                       ;                           @P1
  260.                 .endif                          ;                           @P1
  261.             .else                               ; read from PVB             @P1
  262.                 les     di, [si].AppDataAddr    ; Setup destination address @P1
  263.                 mov     bx, [bp].PVB_Sel        ; Use PVB as source         @P1
  264.                 .if     <nonzero bx>            ;                           @P1
  265.                     mov     ds, bx              ; Setup source selector     @P1
  266.                     mov     si, [bp].PVBOff     ; Setup source offset       @P1
  267.                     REP_MOVSB_INCSI_LOOP        ; Use the above macro so CGA can
  268.                                                 ; use the same set of sources
  269.                 .endif                          ;                           @P1
  270.             .endif                              ;                           @P1
  271.             sub     ax,ax                       ; Clear return code
  272.         .endif                                  ; 
  273.         ret
  274.  
  275. ReadCharStr     ENDP
  276.  
  277. ;/****************************************************************************
  278. ;*                                                                      
  279. ;* SUBROUTINE NAME:     ReadCellStr                                     
  280. ;*                                                                      
  281. ;* DESCRIPTIVE NAME:    Video device handler read cells                 
  282. ;*                                                                      
  283. ;* FUNCTION:    Process read cells sub-function.                        
  284. ;*              The cells are read from either PVB or LVB starting      
  285. ;*              at the specified row, column location.  Line wrap       
  286. ;*              occurs if the end of a line is reached.  Read           
  287. ;*              function is terminated if the end of PVB or LVB         
  288. ;*              is reached.  The cells read are placed in the           
  289. ;*              specified buffer and the number of cells read           
  290. ;*              is returned in the RepeatFactor field of the            
  291. ;*              parameter block.                                        
  292. ;*                                                                      
  293. ;* ENTRY POINT: ReadCellStr                                             
  294. ;*   LINKAGE:   Near Call from BUFFERUPDATE routine                     
  295. ;*                                                                      
  296. ;* INPUT:                                                               
  297. ;*                                                                      
  298. ;* AX =   0                                                             
  299. ;* SS:BP  --->  Stack frame                     (see VDHSTRUC.INC)      
  300. ;* DS:SI  --->  Parameter block buffer          (see XGABUFUP.ASM)      
  301. ;* ES:DI  --->  Mode data in environment buffer (see XGABUFUP.ASM)      
  302. ;*                                                                      
  303. ;* PARAMETER BLOCK FORMAT:                                              
  304. ;*                                                                      
  305. ;*   SIZE   DESCRIPTION                                                 
  306. ;*   ----   -----------                                                 
  307. ;*                                                                      
  308. ;*   WORD   Parameter length                                            
  309. ;*   WORD   Flags                     (source data buffer - LVB, PVB)   
  310. ;*   DWORD  Application data address  (target data buffer)              
  311. ;*   DWORD  Application data2 address (not used in this call)           
  312. ;*   WORD   Index (2)                                                   
  313. ;*   WORD   Starting row              (source row)                      
  314. ;*   WORD   Starting column           (source column)                   
  315. ;*   WORD   Secondary row             (not used in this call)           
  316. ;*   WORD   Secondary column          (not used in this call)           
  317. ;*   WORD   RepeatFactor              (input and output length)         
  318. ;*   WORD   LogicalBufSel                                               
  319. ;*                                                                      
  320. ;* OUTPUT:      Application data buffer = character cells read          
  321. ;*              RepeatFactor = sum of char/attr pairs read              
  322. ;*                                                                      
  323. ;* EXIT-NORMAL: AX = 0                                                  
  324. ;*                                                                      
  325. ;* EXIT-ERROR:  AX = Error from LocateBuffAddr                          
  326. ;*                                                                      
  327. ;* EFFECTS:     All                                                     
  328. ;*                                                                      
  329. ;* INTERNAL REFERENCES: LocateBuffAddr                                  
  330. ;*                                                                      
  331. ;* EXTERNAL REFERENCES: None                                            
  332. ;*                                                                      
  333. ;****************************************************************************/
  334.  
  335.         PUBLIC  ReadCellStr
  336. ReadCellStr     PROC    NEAR
  337.  
  338.         mov     bx, 1                       ; Move in terms of buffer length
  339.         call    SetBuffAddr                 ; On exit: BX = sel, AX = off @P1
  340.         .if     <nc>                        ; Continue?
  341.             shr     cx, 1                   ; Adjust for word move
  342.             les     di, [si].AppDataAddr    ; Setup destination address   @P1
  343.             .if     <nonzero bx>            ; LVB flag set?               @P1
  344.                 mov     ds, bx              ; Setup source selector       @P1
  345.                 mov     si, ax              ; Setup source offset         @P1
  346.                 rep     movsw               ; Transfer cells to destination @P1
  347.             .else                           ;                             @P1
  348.                 mov     bx, [bp].PVB_Sel    ; Use PVB as source           @P1
  349.                 .if     <nonzero bx>        ;                             @P1
  350.                     mov     ds, bx          ; Setup source selector       @P1
  351.                     mov     si, [bp].PVBOff ; Setup source offset         @P1
  352.                     .if     <[bp].cellsize e WorldCellSize>              ;@P1
  353.                         shr     cx, 1       ; Adjust for dword move       @P1
  354.                         xor     ax,ax       ; (ax) = final word of attribute @P1
  355.                         REP_MOVSW_STOSW_LOOP; Use macro so CGA can use the same
  356.                                             ; sources as everyone else    @P1
  357.  
  358.                     .else                   ;                             @P1
  359.                         REP_MOVSW           ; Use macro so CGA can use the same
  360.                                             ; sources as everyone else    @P1
  361.                     .endif                  ;                             @P1
  362.                 .endif                      ;                             @P1
  363.             .endif                          ;                             @P1
  364.             xor     ax,ax                   ; set a good return code
  365.         .endif
  366.         ret
  367.  
  368. ReadCellStr     ENDP
  369.  
  370.  
  371. ;/****************************************************************************
  372. ;*                                                                      
  373. ;* SUBROUTINE NAME:     SetBuffAddr                                     
  374. ;*                                                                      
  375. ;* DESCRIPTIVE NAME:    Video device handler locate video buffer addr   
  376. ;*                                                                      
  377. ;* FUNCTION:    Determine the source/target buffer address for the      
  378. ;*              read/write function based on the information in the     
  379. ;*              parameter buffer and the mode data buffer.              
  380. ;*                                                                      
  381. ;* ENTRY POINT: SetBuffAddr                                             
  382. ;*   LINKAGE:   Near Call                                               
  383. ;*                                                                      
  384. ;* INPUT:                                                               
  385. ;*                                                                      
  386. ;* AX = 0                                                               
  387. ;* BX = Type of transfer                                                
  388. ;*      0 - the RepeatFactor is a count of cells or characters          
  389. ;*     !0 - the RepeatFactor is a user buffer length                    
  390. ;* SS:BP  --->  Stack frame                     (see VDHSTRUC.INC)      
  391. ;* DS:SI  --->  Parameter block buffer          (see XGABUFUP.ASM)      
  392. ;* ES:DI  --->  Mode data in environment buffer (see XGABUFUP.ASM)      
  393. ;*                                                                      
  394. ;* OUTPUT:  AX = LVB offset                                             
  395. ;*          BX = LVB selector OR 0 if LVB not requested                 
  396. ;*          CX = adjusted LVB repeat factor                             
  397. ;*          DS:[SI].RepeatFactor = # of bytes to be transfered          
  398. ;*          CY = 1 Error encountered                                    
  399. ;*          [BP].PVB_Sel    - Selector to the PVB or 0                  
  400. ;*          [BP].LVB_Sel    - Selector to the LVB or 0                  
  401. ;*          [BP].cellsize   - number of bytes per cell in LVB           
  402. ;*          [BP].FirstRow   - number of cells or bytes in first row     
  403. ;*          [BP].RowLength  - number of cells or bytes in later rows    
  404. ;*          [BP].LVBCount   - number of cells or bytes to move, LVB     
  405. ;*          [BP].LVBOff     - offset for read or write in LVB           
  406. ;*          [BP].PVBSkip    - number of bytes to next row in PVB        
  407. ;*          [BP].PVBCount   - number of cells or bytes to move, PVB     
  408. ;*          [BP].PVBOff     - offset for read or write in LVB           
  409. ;*                                                                      
  410. ;* EXIT-NORMAL: CY = clear                                              
  411. ;*                                                                      
  412. ;* EXIT-ERROR:  CY = set                                                
  413. ;*              AX = 0  if RepeatFactor = 0 for char or attr move       
  414. ;*                                      = 0 or 1 for cell move          
  415. ;*              AX = ERROR_VIO_INVALID_PARMS                            
  416. ;*                                                                      
  417. ;* EFFECTS:     AX, BX, CX, DX, CY                                      
  418. ;*                                                                      
  419. ;* INTERNAL REFERENCES: None                                            
  420. ;*                                                                      
  421. ;* EXTERNAL REFERENCES: None                                            
  422. ;*
  423. ;* PSEUDOCODE
  424. ;*
  425. ;*      if !( (mincol <= parmcol <= maxcol) &&
  426. ;*            (minrow <= parmrow <= maxrow) )
  427. ;*          exit with error
  428. ;*
  429. ;*      PVBSkip = (modeRows - lvb_width) * cellsize
  430. ;*      RowLength = lvb_width * cellsize
  431. ;*      LVBOff = (parmrow - minrow) * lvb_width +
  432. ;*                    (parmcol - mincol) * cellsize
  433. ;*      PVBOff = (parmrow * modeCols + parmcol) * cellsize
  434. ;*      BytesLeft = lvb_width * lvb_height * cellsize - LVBOff
  435. ;*      if (Read/Write Buffer Cells length)
  436. ;*          if (parmcount > BytesLeft)
  437. ;*              parmcount = BytesLeft
  438. ;*          LVBCount = parmcount
  439. ;*          PVBCount = parmcount
  440. ;*      else (Read/Write Chars or Cell count)
  441. ;*          CellsLeft = BytesLeft/CellSize
  442. ;*          if (parmcount > CellsLeft)
  443. ;*              parmcount = CellsLeft
  444. ;*          LVBCount = parmcount
  445. ;*          PVBCount = parmcount
  446. ;*
  447. ;*      if  (cellsize == 4)
  448. ;*          PVBOff = PVBOff / 2
  449. ;*          if (Read/Write Buffer Cells length)
  450. ;*              PVBCount = parmcount/2
  451. ;*
  452. ;****************************************************************************/
  453.  
  454.         PUBLIC  SetBuffAddr                                     ;@P1 begin
  455. SetBuffAddr PROC    NEAR
  456.  
  457.         call    SetGenParms             ; set general parameters for all
  458.  
  459.         .if     <c>                     ; US default values
  460.             jmp     FastBuffAddr        ; do fast version of the calculations
  461.         .endif
  462.  
  463.         ;/*
  464.         ;**  Possible bizarre LVB.  (cx) = maxcolumn, (ax) = maxrow
  465.         ;*/
  466.  
  467.         .if     <cx b ds:[si].Col> or
  468.         mov     cx,[bp].mincol
  469.         .if     <cx a ds:[si].Col>      ;   No, return error
  470.             mov     ax,ERROR_VIO_COL
  471.             jmp     sbaerr
  472.         .endif
  473.  
  474.         .if     <ax b ds:[si].Row> or   ; Is the column coordinate valid?
  475.         mov     ax,[bp].minrow
  476.         .if     <ax a ds:[si].Row>      ;   No, exit with error
  477.             mov     ax,ERROR_VIO_ROW
  478.             jmp     sbaerr
  479.         .endif
  480.  
  481.         .if     <nonzero bx>
  482.             mov     ax,[bp].cellsize    ; cell size must be a power of 2
  483.             dec     ax                  ; (ax) = bitmask for MOD
  484.             xor     ax,-1               ; (ax) = bitmask for round down
  485.             and     ds:[si].RepeatFactor,ax
  486.         .endif
  487.  
  488.         .if     <ds:[si].RepeatFactor e 0>  ; check for NOP read or write
  489.             xor     ax,ax               ; zero length writes and reads are
  490.             jmp     sbaerr              ; valid, but do nothing
  491.         .endif
  492.  
  493.         mov     ax,[bp].maxcol              ; calculate the number of cells
  494.         sub     ax,ds:[si].Col              ; in the first row of the read or
  495.         inc     ax                          ; or write
  496.         mov     [bp].FirstRow,ax
  497.  
  498.         mov     ax,es:[di].TextCols         ; calculate number of bytes per row
  499.         sub     ax,[bp].lvb_width           ; skipped when moving from PVB line
  500.         shl     ax,1                        ; to PVB line
  501.         mov     [bp].PVBSkip,ax
  502.  
  503.         mov     cx,[bp].lvb_width           ; caluculate the Row Length of the LVB
  504.         shl     cx,1                        ; in bytes in a two byte cell LVB
  505.         mov     [bp].RowLength,cx
  506.                                             ; (cx) = bytes per LVB row
  507.         mov     ax,ds:[si].Row              ; calculate offset into the LVB
  508.         sub     ax,[bp].minrow
  509.         mul     cx
  510.         mov     cx,ds:[si].Col
  511.         sub     cx,[bp].mincol
  512.         shl     cx,1
  513.         add     ax,cx
  514.         mov     [bp].LVBOff,ax
  515.  
  516.         mov     ax,ds:[si].Row              ; calculate the PVB offset
  517.         mul     es:[di].TextCols
  518.         add     ax,ds:[si].Col
  519.         shl     ax,1
  520.         mov     [bp].PVBOff,ax
  521.  
  522.         mov     ax,[bp].lvb_width           ; calculate longest possible write/read
  523.         mul     [bp].lvb_height
  524.         shl     ax,1
  525.         sub     ax,[bp].LVBOff              ; (ax) = longest write in bytes
  526.  
  527.         cmp     [bp].cellsize,DefaultCellSize   ; Is this the default Cell Size?
  528.         .if     <nz>
  529.  
  530.             or      bx,bx                   ; Is this a cell or char count?
  531.             .if     <z>                     ;   Yes, calculate cell or char count
  532.                 shr     ax,1                ; (ax) = longest write in cells
  533.                 shr     [bp].RowLength,1    ; convert row length to cells
  534.                 .if     <ax b ds:[si].RepeatFactor> ; truncate the length if needed
  535.                     mov     ds:[si].RepeatFactor,ax
  536.                 .else
  537.                     mov     ax,ds:[si].RepeatFactor
  538.                 .endif
  539.                 mov     [bp].LVBCount,ax
  540.                 mov     [bp].PVBCount,ax
  541.             .else
  542.                 shl     ax,1                ; (ax) = longest write in bytes
  543. IFDEF D1348 ;support of 64K PS
  544.                 .if     <nc> and            ; if 64K, CY is set
  545. ENDIF ;D1348
  546.                 .if     <ax b ds:[si].RepeatFactor> ; truncate the length if needed
  547.                     mov     ds:[si].RepeatFactor,ax
  548.                 .else
  549.                     mov     ax,ds:[si].RepeatFactor
  550.                 .endif
  551.                 mov     [bp].LVBCount,ax    ; byte count for 4 byte cell LVB
  552.                 shr     ax,1
  553.                 mov     [bp].PVBCount,ax; byte count for 2 byte cell PVB
  554.                 shl     [bp].FirstRow,2     ; Adjust LVB first row length
  555.                 shl     [bp].RowLength,1    ; Adjust LVB row length for cell size
  556.             .endif
  557.             shl     [bp].LVBOff,1           ; Adjust LVB start offset for cell size
  558.         .else
  559.             or      bx,bx                   ; Is this a cell or char count?
  560.             .if     <z>                     ;   Yes, calculate cell or char count
  561.                 shr     ax,1                ; (ax) = longest write in cells
  562.                 shr     [bp].RowLength,1    ; convert row length to cells
  563.             .else
  564.                 shl     [bp].FirstRow,1     ; Adjust LVB first row length
  565.             .endif
  566.             .if     <ax b ds:[si].RepeatFactor> ; truncate the length if needed
  567.                 mov     ds:[si].RepeatFactor,ax
  568.             .else
  569.                 mov     ax,ds:[si].RepeatFactor
  570.             .endif
  571.             mov     [bp].LVBCount,ax
  572.             mov     [bp].PVBCount,ax
  573.         .endif
  574.  
  575.         cmp     ds:[si].ParmLength,LVBRowOff; Does caller want the touch rect?
  576.         .if     <ae>                    ;   Yes, return the Touch Rect
  577.             call    CalcTouchRect
  578.         .endif
  579.  
  580.         mov     bx,[bp].LVB_Sel         ; (bx) = LVB or 0
  581.         mov     ax,[bp].LVBOff          ; (ax) = offset into LVB
  582.         mov     cx,[bp].LVBCount        ; (cx) = LVB repeat count
  583.  
  584.         clc
  585. sbax:   ret
  586.  
  587. sbaerr: stc
  588.         jmp     sbax
  589.  
  590. SetBuffAddr ENDP                                                ;@P1 end
  591.  
  592.  
  593. ;/****************************************************************************
  594. ;*
  595. ;* FUNCTION NAME = FastBuffAddr
  596. ;*
  597. ;* DESCRIPTION   = Set buffer addresses for US case                                     
  598. ;*
  599. ;*      FastBuffAddr takes advantage of the fact the the PVB and LVB are
  600. ;*      both the same size and format.  It calculates all of the end values
  601. ;*      that SetBuffAddr does, but does it for the CGA format LVB/PVB only.
  602. ;*
  603. ;* INPUT         = SS:BP - local data storage area                
  604. ;*                 DS:SI - user passed parameter block            
  605. ;*                 ES:DI - environment data
  606. ;*                 BX - 0 if write in cells, !0 if write in bytes 
  607. ;*                 [bp].cellsize - number of bytes per cell       
  608. ;*
  609. ;* OUTPUT        = 
  610. ;*
  611. ;*            Carry Clear
  612. ;*              AX = LVB offset
  613. ;*              BX = LVB selector OR 0 if LVB not requested
  614. ;*              CX = adjusted LVB repeat factor
  615. ;*              DS:[SI].RepeatFactor = # of bytes to be transfered
  616. ;*              CY = 1 Error encountered
  617. ;*              [BP].PVB_Sel    - Selector to the PVB or 0
  618. ;*              [BP].LVB_Sel    - Selector to the LVB or 0
  619. ;*              [BP].cellsize   - number of bytes per cell in LVB
  620. ;*              [BP].FirstRow   - number of cells or bytes in first row
  621. ;*              [BP].RowLength  - number of cells or bytes in later rows
  622. ;*              [BP].LVBCount   - number of cells or bytes to move, LVB
  623. ;*              [BP].LVBOff     - offset for read or write in LVB
  624. ;*              [BP].PVBSkip    - number of bytes to next row in PVB
  625. ;*              [BP].PVBCount   - number of cells or bytes to move, PVB
  626. ;*              [BP].PVBOff     - offset for read or write in LVB
  627. ;*
  628. ;*            Carry Set
  629. ;*              AX = error code
  630. ;*
  631. ;*      USES    AX,BX,CX,DX,FLAGS
  632. ;*
  633. ;* RETURN-NORMAL = NONE
  634. ;* RETURN-ERROR  = NONE
  635. ;*
  636. ;****************************************************************************/
  637.  
  638.             Public  FastBuffAddr                                ;@P1 begin
  639. FastBuffAddr    PROC
  640.  
  641.         mov     cx,ds:[si].Col
  642.         mov     ax,es:[di].TextCols
  643.         .if     <cx ae ax>      ;   No, return error
  644.             mov     ax,ERROR_VIO_COL
  645.             jmp     sbaerr
  646.         .endif
  647.  
  648.         mov     [bp].RowLength,ax
  649.         sub     ax,cx
  650.         mov     [bp].FirstRow,ax
  651.  
  652.         mov     ax,ds:[si].Row
  653.         .if     <ax ae es:[di].TextRows>      ;   No, return error
  654.             mov     ax,ERROR_VIO_ROW
  655.             jmp     sbaerr
  656.         .endif
  657.  
  658.         mul     es:[di].TextCols    ; calculate the LVB/PVB offset
  659.         add     ax,cx
  660.         shl     ax,1
  661.         mov     [bp].PVBOff,ax
  662.         mov     [bp].LVBOff,ax
  663.         mov     cx,ax               ; (cx) = offset of beginning of write
  664.  
  665.         mov     ax,es:[di].TextCols ; calculate longest possible write/read
  666.         mul     es:[di].TextRows    ; calculate longest possible write/read
  667.         shl     ax,1
  668.         sub     ax,cx               ; (ax) = longest write in bytes
  669.  
  670.         or      bx,bx               ; Is this a cell or char count?
  671.         .if     <z>                 ;   Yes, calculate cell or char count
  672.             shr     ax,1            ; (ax) = longest write in cells
  673.         .else
  674.             and     ds:[si].RepeatFactor,0FFFEh
  675.             shl     [bp].FirstRow,1 ; Adjust LVB first row length
  676.             shl     [bp].RowLength,1; convert row length to bytes
  677.         .endif
  678.         .if     <ax b ds:[si].RepeatFactor> ; truncate the length if needed
  679.             mov     ds:[si].RepeatFactor,ax
  680.         .else
  681.             mov     ax,ds:[si].RepeatFactor
  682.         .endif
  683.         mov     [bp].LVBCount,ax
  684.         mov     [bp].PVBCount,ax
  685.         .if     <zero ax>
  686.             jmp     fbaerr
  687.         .endif
  688.  
  689.         mov     [bp].PVBSkip,0
  690.         mov     bx,[bp].LVB_Sel         ; (bx) = LVB or 0
  691.         mov     ax,[bp].LVBOff          ; (ax) = offset into LVB
  692.         mov     cx,[bp].LVBCount        ; (cx) = LVB repeat count
  693.  
  694.         clc
  695. fbax:   ret
  696.  
  697. fbaerr: stc
  698.         jmp     fbax
  699.  
  700. FastBuffAddr    ENDP                                            ;@P1 end
  701.  
  702. ;/****************************************************************************
  703. ;*
  704. ;* FUNCTION NAME = CalcTouchRect
  705. ;*
  706. ;* DESCRIPTION   = Calculate the rectangle touched by the given function 
  707. ;*
  708. ;*       CalcTouchRect calculate the tightest rectangle that includes all of
  709. ;*       the cells that may have been changed by the given call.             
  710. ;*
  711. ;* INPUT         = 
  712. ;*
  713. ;*              SS:BP - local data storage area
  714. ;*              DS:SI - user passed parameter block
  715. ;*              BX - 0 if write in cells, !0 if write in bytes
  716. ;*              [bp].LVBCount   -  number of units to write, LVB
  717. ;*              [bp].mincol     -  left most column of LVB
  718. ;*              [bp].maxcol     -  right most column of LVB
  719. ;*              [bp].FirstRow   -  number of units to write first row of LVB
  720. ;*              [bp].RowLength  -  number of units per row, LVB
  721. ;*              [bp].cellsize   -  number of bytes per cell
  722. ;*
  723. ;* OUTPUT    =  ds:si-> Touchxxx - set to reflect rectangle affected
  724. ;*
  725. ;*      USES    AX,CX,DX,FLAGS
  726. ;*
  727. ;*                 ds:si - 2nd attribute pointer               
  728. ;*                 es:di - LVB pointer                         
  729. ;*                 cx    - attr count                          
  730. ;*
  731. ;* RETURN-NORMAL = NONE
  732. ;* RETURN-ERROR  = NONE
  733. ;*
  734. ;****************************************************************************/
  735.  
  736.             Public  CalcTouchRect                               ;@P1 begin
  737. CalcTouchRect   PROC
  738.  
  739.         cmp     ds:[si].FuncIndex,MIN_WRT_INDEX ; Is this a write?
  740.         .if     <ae>                ;   Yes, return the Touch Rect
  741.             mov     cx,ds:[si].Row
  742.             mov     ds:[si].TouchYTop,cx
  743.             mov     ax,[bp].LVBCount    ; (ax) = read or write count
  744.             .if     <ax a [bp].FirstRow>; multiple row write
  745.                 mov     dx,[bp].mincol
  746.                 mov     ds:[si].TouchXLeft,dx
  747.                 mov     dx,[bp].maxcol
  748.                 mov     ds:[si].TouchXRight,dx
  749.  
  750.                 ;/*
  751.                 ;**  This calculation is complicated.
  752.                 ;**  ax = number of units to be written
  753.                 ;**  ax-FirstRow give the number of units in 2nd
  754.                 ;**      and later rows
  755.                 ;**  ((ax-FirstRow - 1)/RowLength) + 1 = # of rows beyond 1st
  756.                 ;*/
  757.  
  758.                 xor     dx,dx           ; (dx:ax) = (ax) = w count
  759.                 sub     ax,[bp].FirstRow; (ax) = w count for 2nd+ rows
  760.                 dec     ax              ; zero index bytes in the last row
  761.                 div     [bp].RowLength  ; (ax) = # rows written - 1
  762.                 inc     ax              ; (ax) = # of 2nd+ rows written
  763.                 add     cx,ax           ; (cx) = bottom row written
  764.                 mov     ds:[si].TouchYBottom,cx
  765.             .else                       ; single row write
  766.                 mov     ds:[si].TouchYBottom,cx
  767.                 mov     dx,ds:[si].Col
  768.                 mov     ds:[si].TouchXLeft,dx
  769.                 .if     <nonzero bx>
  770.                     mov     cx,[bp].cellsize
  771.                     shr     cx,1
  772.                     shr     ax,cl
  773.                 .endif
  774.                 dec     ax              ; a 1 cell write has same lf,rt col
  775.                 add     ax,dx           ; (ax) = right most column
  776.                 mov     ds:[si].TouchXRight,ax
  777.             .endif
  778.         .else                       ; read call, no data affected
  779.             mov     ds:[si].TouchYTop,-1
  780.             mov     ds:[si].TouchXLeft,-1
  781.             mov     ds:[si].TouchXRight,-1
  782.             mov     ds:[si].TouchYBottom,-1
  783.         .endif
  784.         ret
  785.  
  786. CalcTouchRect   ENDP                                            ;@P1 end
  787.  
  788. R2CSEG  ENDS
  789.         END
  790.  
  791.