home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-386-Vol-2of3.iso / b / bgi256-3.zip / SBASE.INC < prev    next >
Text File  |  1992-12-28  |  32KB  |  1,199 lines

  1. ;SBASE.INC - Copyright 1992 Knight Software
  2. ; History:
  3. ;  30 Nov 1992 - Adapted for protected mode operation
  4. ;                 split off of main to simplify configuration 
  5. ;  22 Dec 1992 - Changed SetWriteMode to add floodfill options.
  6.  
  7. ;**********************************************************************
  8. ;
  9. ;--- INSTALL ----------------------------------------------------------
  10. ;Driver initialization and installation
  11. ;The Install function is used to prepare the driver for use. 
  12. ;
  13. ;The calls to this function allow the kernal to inquire the 
  14. ;mode information, and allow the kernal to install the mode 
  15. ;infomation.                                                
  16. ;Assume:  DS = data segment
  17. ;Entry:   AL = 00    CL = Mode number
  18. ;Return:  ES:BX = Pointer to Device Status Table
  19. ;
  20. ;Entry:      AL = 01    CL = N/A
  21. ;Return:  CX = Number of modes supported (last mode+1)
  22. ;
  23. ;Entry:      AL = 02    CL = Mode number
  24. ;Return:  ES:BX = Pointer to Mode name (Pascal type String)
  25. ;Destory: None
  26.  
  27. _install PROC    NEAR
  28.     PUSH    SI
  29.     PUSH    DI
  30.     PUSH    AX
  31.     PUSH    DX
  32.     CMP    AL,0
  33.     JNZ    @Install1     ;Install device command 
  34.     CMP    CL,MaxModes    ;if greater than Max # modes
  35.     JC    @installa    ;then force default mode
  36.     MOV    CL,DefaultMode    ;else use selected value
  37. @installa:
  38.     MOV    WORD PTR DS:[ScanLineLength],0 ;clear scan line length
  39.     MOV    DS:[ModeSelect],CL    ;save requested mode
  40.     PUSH    DS
  41.     POP    ES        ;Point ES:BX to status block
  42.     LEA    BX,StatBlock
  43.     CALL    DetectCard    ;determine what card we have
  44.     CALL    MiscInit    ;initalize misc variables
  45.     JMP    @InstallDone
  46.  
  47. @Install1:    ; Mode Query Command
  48.     CMP    AL,1
  49.     JNZ    @Install2
  50.     CMP    BYTE PTR DS:[ModeXflag],0
  51.     JNZ    @Installm
  52.     MOV    CX,DS:[NumberModes]  ;return number of modes available
  53.     JMP    @InstallDone
  54. @Installm:
  55.     MOV    CX,DS:[RetValue]     ;return alternate selected value
  56.     INC    CX             ;pre-distort the result
  57.     JMP    @InstallDone
  58.  
  59. @Install2:    ; Mode Name Command
  60.     CMP    AL,2
  61.     MOV    AH,grError     ;Bad cmd
  62.     JNZ    @Installx
  63.     CALL    GetModeName
  64.     MOV    AH,grInvalidMode ;Bad mode number
  65.     JNC    @Installx
  66.     JMP    @InstallDone
  67.  
  68. @Installx:    ; Bad Install Exit
  69.     MOV    DS:[StatBlock.stat],AH    ;save error
  70. @Installdone:
  71.     POP    DX
  72.     POP    AX
  73.     POP    DI
  74.     POP    SI
  75.     RET
  76. _install ENDP
  77.  
  78.  
  79. ;--- INIT -------------------------------------------------------------
  80. ;Initialize device for output 
  81. ;Assume:  DS = data segment
  82. ;Entry:   ES:BX points to Device Information Table 
  83. ;                        (not Device Status Table)
  84. ;Return:  N/A
  85. ;Destory: None
  86.  
  87. _init    PROC    NEAR
  88.     PUSH    AX
  89.     PUSH    CX
  90.     MOV    CH,ES:[BX]    ;get InitColor
  91.     MOV    CL,ES:[BX+1]    ;Get Init flag
  92.     CMP    CL,65H        ;if 65H don't init
  93.     JZ    @InitExit
  94.     MOV    DS:[InitColor],CH      ;save init color to use
  95.     CALL    word ptr DS:[InitDisplayProc] ;call the selected init code
  96.     JZ    @InitExit
  97.     MOV    AH,grInvalidMode  ;bad mode
  98.     MOV    DS:[StatBlock.stat],AH
  99. @InitExit:
  100.     POP    CX
  101.     POP    AX
  102.     RET
  103. _init    ENDP
  104.  
  105.  
  106. ;--- CLEAR ------------------------------------------------------------
  107. ;Clear graphics device (screen) and ready it for new output. 
  108. ;Assume:  DS = data segment
  109. ;Entry:   N/A
  110. ;Return:  N/A
  111. ;Destroy: None
  112.  
  113. _clear    PROC    NEAR
  114.     PUSH    SI
  115.     PUSH    DI
  116.     PUSH    DX
  117.     PUSH    CX
  118.     PUSH    BX
  119.     PUSH    AX
  120.     MOV    CX,0              ;Start clear at 0,0
  121.     MOV    DX,0
  122.     MOV    AX,DS:[StatBlock.BytesPerScanLine] ;Clear full width of screen
  123.     MOV    BX,DS:[StatBlock.TotalScanLines]   ;Clear full height of screen
  124.     LEA    SI,FillPattern          ;DS:SI = start of cpu memory 
  125.     LEA    DI,WriteClear         ;point DI at proc to use
  126.     CALL    DoBitMap          ;Copy cpu memory to screen
  127.     POP    AX
  128.     POP    BX
  129.     POP    CX
  130.     POP    DX
  131.     POP    DI
  132.     POP    SI
  133.     RET
  134.     RET
  135. _clear    ENDP
  136.  
  137.  
  138. ;--- POST -------------------------------------------------------------
  139. ;Post screen. This is required for devices that need to be posted.
  140. ;Since the IBM displays are always visible, there is no need to
  141. ;do anything here.
  142. ;Assume:  DS = data segment
  143. ;Entry:   N/A
  144. ;Return:  N/A
  145. ;Destory: None
  146.  
  147. _post    PROC    NEAR
  148.     RET
  149. _post    ENDP
  150.  
  151.  
  152. ;--- MOVE -------------------------------------------------------------
  153. ;Set the master Current Pointer to coordinates passed in AX, BX.
  154. ;Assume:  DS = data segment
  155. ;Entry:   AX = X  
  156. ;         BX = Y 
  157. ;Return:  N/A
  158. ;Destory: None
  159.  
  160. _move   PROC  NEAR
  161.     MOV    DS:[CPX],AX
  162.     MOV    DS:[CPY],BX
  163.     RET
  164. _move    ENDP
  165.  
  166.  
  167. ;--- DRAW -------------------------------------------------------------
  168. ;Draw a line from the master Current Pointer to the 
  169. ;coordinates passed in AX,BX.
  170. ;Assume:   DS = data segment
  171. ;Entry:    AX = X
  172. ;          BX = Y 
  173. ;Return:   N/A
  174. ;Destroys: None
  175.  
  176. _draw    PROC    NEAR
  177.     PUSH    CX
  178.     PUSH    DX
  179.     MOV    CX,DS:[CPX]
  180.     MOV    DX,DS:[CPY]
  181.     CALL    PlotLine
  182.     POP    DX
  183.     POP    CX
  184.     RET
  185. _draw    ENDP
  186.  
  187.  
  188. ;--- VECT -------------------------------------------------------------
  189. ;Draw a line between the coordinates passed in AX, BX, CX, DX.
  190. ;Assume:   DS = data segment
  191. ;Entry:    AX = X Start
  192. ;          BX = Y Start
  193. ;          CX = X End
  194. ;          DX = Y End
  195. ;Return:   N/A
  196. ;Destroys: None
  197.  
  198. _vect    PROC    NEAR
  199.     CALL    PlotLine
  200.     RET
  201. _vect    ENDP
  202.  
  203.  
  204. ; @EM --- BAR ---------------------------------------------------------
  205. ;Draw a filled rectangle with the CP as the Lower Left corner, 
  206. ;and the coordinate in AX, BX as the upper right.
  207. ;Assume:   DS = data segment
  208. ;Entry:    AX = X upper corner  
  209. ;          BX = Y upper corner
  210. ;          CX = Depth for 3D bars
  211. ;          DX = Draw Top Flag (DX<>0 = Draw Top)
  212. ;Return:   N/A
  213. ;Destroys: None
  214.  
  215. ;_bar  PROC  NEAR                        ; @@@@@@                    
  216. ;    RET                              ; this function is emulated 
  217. ;_bar    ENDP                             ; @@@@@@                    
  218.  
  219.  
  220. ;--- PATBAR -----------------------------------------------------------
  221. ;Draw a patterned box at the passed coordinates in AX, BX, CX, DX. 
  222. ;The pattern is provided by the information previously passed to 
  223. ;the set fill pattern function.
  224. ;Assume:   DS = data segment
  225. ;Entry:    AX = X1 Corner  
  226. ;          BX = Y1 Corner
  227. ;          CX = X2 Corner  
  228. ;          DX = Y2 Corner
  229. ;Return:   N/A
  230. ;Destroys: None
  231.  
  232. _patbar    PROC    NEAR
  233.     PUSH    SI
  234.     PUSH    DI
  235.     PUSH    DX
  236.     PUSH    CX
  237.     PUSH    BX
  238.     PUSH    AX
  239.     CMP    AX,CX        ;insure that start X is in CX
  240.     JNC    @PatBar1
  241.     XCHG    AX,CX
  242. @PatBar1:
  243.     CMP    BX,DX        ;insure that start Y is in DX
  244.     JNC    @PatBar2
  245.     XCHG    BX,DX
  246. @PatBar2:
  247.     SUB    AX,CX        ;put X size in AX
  248.     INC    AX
  249.     SUB    BX,DX        ;put Y size in BX
  250.     INC    BX
  251.     LEA    SI,FillPattern     ;DS:SI = start of cpu memory 
  252.     LEA    DI,WriteFillLine ;point DI at proc to use
  253.     CALL    DoBitMap     ;Copy cpu memory to screen
  254.     POP    AX
  255.     POP    BX
  256.     POP    CX
  257.     POP    DX
  258.     POP    DI
  259.     POP    SI
  260.     RET
  261. _patbar    ENDP
  262.  
  263.  
  264. ; @EM --- ARC ---------------------------------------------------------
  265. ;Draw an elliptical arc from the start angle in AX, 
  266. ;to the end angle in BX, using the the CP as the Center Point, 
  267. ;and the X and Y Radii in CX, DX. Angles are 0-360 degrees.
  268. ;Assume:  DS = data segment
  269. ;Entry:   AX = Start Angle  BX = End Angle
  270. ;         CX = X radius of arc
  271. ;         DX = Y radius of arc
  272. ;Return:  N/A
  273. ;Destory: None
  274.  
  275. ;_arc  PROC  NEAR                        ; @@@@@@                    
  276. ;    RET                              ; this function is emulated 
  277. ;_arc    ENDP                             ; @@@@@@                    
  278.  
  279.  
  280. ; @EM --- PIESLICE ----------------------------------------------------
  281. ;Draw an elliptical sector from the start angle in AX,
  282. ;to the end angle in BX, using the CP as the Center Point, 
  283. ;and the X and Y Radii in CX, DX. Angles are 0-360 degrees.
  284. ;Assume:  DS = data segment
  285. ;Entry:   AX = Start Angle  BX = End Angle
  286. ;         CX = X radius of arc
  287. ;         DX = Y radius of arc
  288. ;Return:  N/A
  289. ;Destory: None
  290.  
  291. ;_pieslice  PROC  NEAR                   ; @@@@@@                    
  292. ;    RET                              ; this function is emulated 
  293. ;_pieslice ENDP                          ; @@@@@@                    
  294.  
  295.  
  296. ; @EM --- FILLED ELLIPSE ----------------------------------------------
  297. ;Draw an ellipse using the CP as the Center Point, 
  298. ;and the X and Y radii passed in AX, BX.
  299. ;Assume:  DS = data segment
  300. ;Entry:   AX = X Radius of ellipse
  301. ;         BX = Y Radius of ellipse
  302. ;Return:  N/A
  303. ;Destory: None
  304.  
  305. ;_filled_ellipse  PROC  NEAR             ; @@@@@@                    
  306. ;    RET                              ; this function is emulated 
  307. ;_filled_ellipse ENDP                    ; @@@@@@                    
  308.  
  309.  
  310. ;--- PALETTE ---------------------------------------------------------- 
  311. ;Set a specific palette entry to a given color.
  312. ;Assume:  DS = data segment
  313. ;Entry:
  314. ; Top two bits of AX contain command code.
  315. ; 00 : set EGA color - Index in AL, Color in BL
  316. ; 01 : not used 
  317. ; 10 : set specific VGA palette - BX=red, CX=green, DX=blue, AX=index
  318. ; 11 : set EGA background color - BL=Color
  319. ;Return:  N/A
  320. ;Destory: None
  321.  
  322. _palette PROC    NEAR
  323.     AND    AH,0C0H
  324.     JZ    @Pal0    ;set color value
  325.     CMP    AH,80H
  326.     JZ    @Pal2    ;set dac color register
  327.     CMP    AH,40H    ;this function not used
  328.     JZ    @PalX
  329.     MOV    AL,0    ;set background color
  330. @Pal0:    CALL    SetEGAPal ;Go set the EGA palette
  331.     RET
  332.  
  333. @Pal2:    CALL    SetVGAPal ;Get set the VGA palette
  334. @PalX:    RET
  335.  
  336. _palette ENDP
  337.  
  338.  
  339. ;--- ALL PALETTE ------------------------------------------------------
  340. ;Load an EGA palette with a table of colors.
  341. ;Assume:  DS    = data segment
  342. ;Entry:   ES:BX = EGA Palette Table to load
  343. ;Return:  N/A
  344. ;Destory: None
  345.  
  346. _allpalette PROC  NEAR
  347.     CALL    SetFullEGAPal
  348.     RET
  349. _allpalette ENDP
  350.  
  351.  
  352. ;--- COLOR ------------------------------------------------------------
  353. ;Set the palette indexs to the specified drawing color in AL
  354. ;and the specified fill color in AH.
  355. ;Assume:  DS = data segment
  356. ;Entry:   AL = Drawing Color
  357. ;         AH = Fill color
  358. ;Return:  N/A
  359. ;Destroy: None
  360.  
  361. _color  PROC  NEAR
  362.     MOV    DS:[DrawForeColor],AL
  363.     MOV    DS:[FillForeColor],AH
  364.     RET
  365. _color    ENDP
  366.  
  367.  
  368. ;--- FILL STYLE -------------------------------------------------------
  369. ;Set the fill pattern to the specified pattern number passed in AL.
  370. ;If the pattern number is 0FFH, the pattern is define in
  371. ;a user supplied array pointed at by ES:BX.
  372. ;Assume:  DS    = data segment
  373. ;Entry:   AL    = Pattern # (0FFH for user def)
  374. ;         ES:BX = User pattern data if needed
  375. ;Return:  N/A
  376. ;Destroy: None
  377.  
  378. _fillstyle PROC    NEAR
  379.     PUSH    ES
  380.     PUSH    DI
  381.     PUSH    CX
  382.     PUSH    BX
  383.     PUSH    AX
  384.     MOV    CX,4         ;Copy four words (eight bytes)
  385.     LEA    DI,FillPattern   ;copy pattern to Fill Pattern array
  386.     CMP    AL,0FFH
  387.     JZ    @UserFill
  388.     PUSH    DS
  389.     POP    ES
  390.     MOV    AH,0    ;Adjust for table index
  391.     SHL    AX,1    ;Pattern number times eight
  392.     SHL    AX,1
  393.     SHL    AX,1
  394.     LEA    BX,FillTable
  395.     ADD    BX,AX    ;ES:BX points into table
  396. @UserFill:
  397.     MOV    AX,ES:[BX] ;Copy pattern to drawing array
  398.     MOV    DS:[DI],AX
  399.     INC    BX
  400.     INC    DI
  401.     INC    BX
  402.     INC    DI
  403.     LOOP    @UserFill
  404.     POP    AX
  405.     POP    BX
  406.     POP    CX
  407.     POP    DI
  408.     POP    ES
  409.     RET
  410. _fillstyle ENDP
  411.  
  412.  
  413. ;--- LINE STYLE -------------------------------------------------------
  414. ;Set the line style to the specified style number passed in AL.
  415. ;If the style number is > 3  then the style is define in the user 
  416. ;supplied pattern in BX. The line width to use is passed in CX. 
  417. ;Note: The calling Graph unit actually does the triple width
  418. ;      by drawing the line three times, so don't do it in here. 
  419. ;Assume:  DS = data segment
  420. ;Entry:   AL = Style # ( >3 for user def)
  421. ;         BX = User Line Pattern
  422. ;         CX = Line Width (1 or 3)
  423. ;Return:  N/A
  424. ;Destory: None
  425.  
  426. _linestyle PROC    NEAR
  427.     PUSH    DI
  428.     PUSH    BX
  429.     PUSH    AX
  430.     MOV    DS:[LineWidth],CL
  431.     CMP    AL,4
  432.     JNC    @LineStyleX
  433.     AND    AX,03H
  434.     ADD    AX,AX
  435.     LEA    DI,LinePatternTable
  436.     ADD    DI,AX
  437.     MOV    BX,DS:[DI]
  438. @LineStyleX:
  439.     MOV    DS:[LinePattern],BX
  440.     POP    AX
  441.     POP    BX
  442.     POP    DI
  443.     RET
  444. _linestyle ENDP
  445.  
  446.  
  447. ;--- TEXT STYLE -------------------------------------------------------
  448. ;Set the text attributes for font rendering
  449. ;Assume:  DS = data segment
  450. ;Entry:   AL = Font Number
  451. ;         AH = Font Path and Direction
  452. ;         BX = Desired X Character Size
  453. ;         CX = Desired Y Character Size
  454. ;Return:  BX = Actual X Character Size
  455. ;         CX = Actual Y Character Size
  456. ;Destroy: None
  457.  
  458. _textstyle PROC NEAR
  459.     PUSH    CX
  460.     PUSH    BX
  461.     PUSH    AX
  462.     MOV    DS:[FontNumber],AL
  463.     MOV    DS:[FontDir],AH
  464.     SHR    CL,1
  465.     SHR    CL,1
  466.     SHR    CL,1
  467.     JNZ    @TextStyle1
  468.     INC    CL
  469. @TextStyle1:
  470.     CMP    CL,10
  471.     JL    @TextStyle2
  472.     MOV    CL,10
  473. @TextStyle2:
  474.     MOV    DS:[FontMultX],CL
  475.  
  476.     SHR    BL,1
  477.     SHR    BL,1
  478.     SHR    BL,1
  479.     JNZ    @TextStyle3
  480.     INC    BL
  481. @TextStyle3:
  482.     CMP    BL,10
  483.     JL    @TextStyle4
  484.     MOV    BL,10
  485. @TextStyle4:
  486.     MOV    DS:[FontMultY],BL
  487.  
  488.     MOV    AL,DS:[CharSizeX]
  489.     MUL    BL
  490.     MOV    BL,AL
  491.     MOV    BH,0
  492.     MOV    DS:[FontSizeX],BL
  493.  
  494.     MOV    AL,DS:[CharSizeY]
  495.     MUL    CL
  496.     MOV    CL,AL
  497.     MOV    CH,0
  498.     MOV    DS:[FontSizeY],CL
  499.     POP    AX
  500.     POP    BX
  501.     POP    CX
  502.     RET
  503. _textstyle ENDP
  504.  
  505.  
  506. ;--- TEXT -------------------------------------------------------------
  507. ;Draw a string in the current font with the
  508. ;justification point at the CP.
  509. ;Assume:  DS    = data segment
  510. ;Entry:   ES:BX = Pointer to string
  511. ;         CX    = String Length
  512. ;Return:  N/A
  513. ;Destroy: None
  514.  
  515. _drawtext    PROC    NEAR
  516.     CALL    DrawText
  517.     RET
  518. _drawtext    ENDP
  519.  
  520.  
  521. ;--- TEXT SIZE --------------------------------------------------------
  522. ;Calculate the dimensions (in pixels) of an input text string.
  523. ;Assume:  DS    = data segment
  524. ;Entry:   ES:BX = Pointer to string
  525. ;         CX    = String Length
  526. ;Return:  BX    = Width of string
  527. ;         CX    = Height of string
  528. ;Destroy: None
  529.  
  530. _textsize PROC    NEAR
  531.     PUSH    AX
  532.     MOV    AH,0
  533.     MOV    AL,DS:[FontSizeX]
  534.     MUL    CX
  535.     MOV    BX,AX
  536.     MOV    CH,0
  537.     MOV    CL,DS:[FontSizeY]
  538.     POP    AX
  539.     RET
  540. _textsize ENDP
  541.  
  542. ;--- FLOOD FILL -------------------------------------------------------
  543. ;Do a floodfill in the current color using the specified X,Y address 
  544. ;in AX, BX as the seed point. CL contains the border color.
  545. ;Assume:  DS = data segment
  546. ;Entry:   AX = Seed X                  
  547. ;         BX = Seed Y            ;warning: this flood fill has problems   
  548. ;         CL = Border color      ;with complex floods. I still haven't  
  549. ;Return:  N/A                    ;fixed it (I'm not sure how to yet).
  550. ;Destroy: None
  551.  
  552. _floodfill PROC NEAR
  553.     MOV    DS:[CPX],AX    ;update CPxy
  554.     MOV    DS:[CPY],BX
  555.     CALL    DoFloodFill    ;(Located in SFLOOD.INC)
  556.     RET
  557. _floodfill ENDP
  558.  
  559.  
  560. ;--- GET PIXEL --------------------------------------------------------
  561. ;Read a pixel from the coordinates specified in AX, BX.
  562. ;Assume:  DS = data segment
  563. ;Entry:   AX = X
  564. ;         BX = Y 
  565. ;Return:  DL = Pixel value read
  566. ;Destroy: None
  567.  
  568. _getpixel PROC NEAR
  569.     PUSH    AX
  570.     MOV    DS:[PixelX],AX
  571.     MOV    DS:[PixelY],BX
  572.     CALL    GetPixelAddress
  573.     CALL    ReadPixel    ;pixel color returned in AL
  574.     MOV    DL,AL
  575.     POP    AX
  576.     RET
  577. _getpixel ENDP
  578.  
  579.  
  580. ;--- SET PIXEL --------------------------------------------------------
  581. ;Write a pixel to the coordinate specified in AX, BX.
  582. ;Assume:  DS = data segment
  583. ;Entry:   AX = X
  584. ;         BX = Y 
  585. ;         DL = Pixel value to write
  586. ;Return:  N/A
  587. ;Destory: None
  588.  
  589. _setpixel PROC NEAR
  590.     PUSH    AX
  591.     MOV    DS:[PixelX],AX
  592.     MOV    DS:[PixelY],BX
  593.     CALL    GetPixelAddress
  594.     MOV    AL,DL
  595.     CALL    DrawPixel    ;fore color is passed in AL
  596.     POP    AX
  597.     RET
  598. _setpixel ENDP
  599.  
  600.  
  601. ;--- BIT MAP UTILITIES ------------------------------------------------
  602. ;Return a pointer to a table of misc bit map driver utilities. 
  603. ;Assume:  DS    = data segment
  604. ;Entry:   N/A
  605. ;Return:  ES:BX = Base of table
  606. ;Destory: None
  607. ;The table is configured as follows:
  608. ;BitMapTable:      DW GOTOGRAPHIC
  609. ;           DW EXITGRAPHIC
  610. ;           DW PUTPIX
  611. ;           DW GETPIX
  612. ;           DW BITSPERPIXEL
  613. ;           DW SETPAGE
  614. ;           DW SETVISUAL
  615. ;           DW SETWRITEMODE
  616.  
  617. _bitmaputil PROC NEAR
  618.     PUSH    DS
  619.     POP    ES
  620.     LEA    BX,BitMapTable
  621.     RET
  622. _bitmaputil ENDP
  623.  
  624.  
  625. ;--- SAVE BIT MAP -----------------------------------------------------
  626. ;Save a portion of the screen to CPU memory.
  627. ;Assume:  DS        = data segment
  628. ;Entry:   ES:BX     = Pointer to CPU memory buffer
  629. ;         CX        = Start X coord of block to save
  630. ;         DX        = Start Y coord of block to save
  631. ;         ES:[BX]   = Width of block to save
  632. ;         ES:[BX+2] = Height of block to save
  633. ;Return:  Data in CPU memory buffer starting at ES:[BX+4]
  634. ;Destory: None
  635.  
  636. _savebitmap PROC NEAR
  637.     PUSH    SI
  638.     PUSH    DI
  639.     PUSH    BX
  640.     PUSH    AX
  641.     MOV    SI,BX
  642.     MOV    AX,ES:[SI]    ;[SI]= X size (width)
  643.     INC    AX        ;Save in AX
  644.     MOV    BX,ES:[SI+2]    ;[SI+2]= Y size (height)
  645.     INC    BX        ;Save in BX
  646.     ADD    SI,4        ;ES:SI = start of cpu memory 
  647.     LEA    DI,ReadBitMap   ;point DI at proc to use
  648.     CALL    DoBitMap    ;Copy screen to cpu memory
  649.     POP    AX
  650.     POP    BX
  651.     POP    DI
  652.     POP    SI
  653.     RET
  654. _savebitmap ENDP
  655.  
  656.  
  657. ;--- RESTORE BIT MAP --------------------------------------------------
  658. ;Restore a portion of the screen from CPU memory.
  659. ;Assume:  DS        = data segment
  660. ;Entry:   ES:BX     = Pointer to CPU memory buffer
  661. ;         CX        = Start X coordinate of area to restore
  662. ;         DX        = Start Y coordinate of area to restore
  663. ;         ES:[BX]   = Width of area to restore
  664. ;         ES:[BX+2] = Height of area to restore
  665. ;         ES:[BX+4] = Data to restore to screen
  666. ;         AL        = Write mode to use for restoring the area
  667. ;              (see SetWriteMode procedure for modes allowed)
  668. ;Return:  N/A
  669. ;Destory: None
  670.  
  671. _restorebitmap PROC NEAR
  672.     PUSH    SI
  673.     PUSH    DI
  674.     PUSH    BX
  675.     PUSH    AX
  676.     AND    AL,1FH        ;strip off any garbage in AL
  677.     MOV    DS:[BitMapPixelWriteMode],AL ;save the mode select
  678.     MOV    AH,0        ;index into proc pointer table
  679.     ADD    AX,AX        ;to get the proc address
  680.     LEA    SI,DrawModeTable
  681.     ADD    SI,AX
  682.     MOV    DI,DS:[SI]        ;get selected proc addr into DI
  683.     LEA    SI,BitMapPixelProc ;save selected draw mode procedure 
  684.     MOV    DS:[SI],DI        ;address in the procedure pointer
  685.  
  686.     MOV    SI,BX
  687.     MOV    AX,ES:[SI]    ;[SI]= X size (width)
  688.     INC    AX        ;Save in AX
  689.     MOV    BX,ES:[SI+2]    ;[SI+2]= Y size (height)
  690.     INC    BX        ;Save in BX
  691.     ADD    SI,4        ;ES:SI = start of cpu memory 
  692.     LEA    DI,WriteBitMap  ;point DI at proc to use
  693.     CALL    DoBitMap    ;Copy cpu memory to screen
  694.     POP    AX
  695.     POP    BX
  696.     POP    DI
  697.     POP    SI
  698.     RET
  699. _restorebitmap    ENDP
  700.  
  701.  
  702. ;--- SET CLIP ---------------------------------------------------------
  703. ;Set the clipping window to the rectangle defined by the 
  704. ;the coordinates passed in AX, BX as the upper left corner
  705. ;and CX, DX as the lower left corner.
  706. ;Note: Clipping per the BGI defintion is actually done in the
  707. ;calling graph unit. There's no real need to clip in the BGI driver.
  708. ;Assume:  DS = data segment
  709. ;Entry:   AX = Upper Left X 
  710. ;         BX = Upper Left Y 
  711. ;         CX = Lower Right X 
  712. ;         DX = Lower Right Y 
  713. ;Return:  N/A
  714. ;Destory: None
  715.  
  716. _setclip PROC NEAR
  717.     MOV    DS:[ClipX1],AX
  718.     MOV    DS:[ClipY1],BX
  719.     MOV    DS:[ClipX2],CX
  720.     MOV    DS:[ClipY2],DX
  721.     RET
  722. _setclip ENDP
  723.  
  724.  
  725. ;--- COLOR QUERY ------------------------------------------------------
  726. ;Return the color parameters of the device
  727. ;Assume:  DS = data segment
  728. ;Entry:   AL = Command for query
  729. ;Return: 
  730. ;  if AL = 0 : BX = Total colors available
  731. ;              CX = Maximum color value (BX minus one)
  732. ;  if AL = 1 : ES:BX pointer to default EGA palette 
  733. ;Destory: None
  734.  
  735. _color_query PROC NEAR
  736.     CMP    AL,0
  737.     JZ    @Query0    ;get max palette
  738.     CMP    AL,1
  739.     JZ    @Query1    ;get default palette
  740.     JMP    SHORT @QueryX    ;error
  741.  
  742. @Query0:
  743.     MOV    BH,0
  744.     MOV    BL,DS:[StatBlock.ctblf]
  745.     INC    BX
  746.     MOV    CX,BX
  747.     DEC    CX
  748.     JMP    SHORT @QueryX
  749.  
  750. @Query1:
  751.     PUSH    DS
  752.     POP    ES
  753.     LEA    BX,EgaPalette
  754. @QueryX:
  755.     RET
  756. _color_query ENDP
  757.  
  758.  
  759. ;----------------------------------------------------------------------
  760. ;35 DUP (NONE)    ; Reserved Entry Points
  761.  
  762.  
  763. ;**********************************************************************
  764. ;WARNING! The data segment (DS) is not correctly setup when BMI code
  765. ;is called. Neither is ES. All registers probably should be saved.
  766.  
  767. ;--- BMI ENTER BIT MAP MODE -------------------------------------------
  768. ;switch to pixel graphics mode
  769. ;Assume:  nothing
  770. ;Entry:   N/A
  771. ;Return:  N/A
  772. ;Destory: None
  773.  
  774. bmi_gotographic    PROC FAR
  775.     RET        ; do nothing
  776. bmi_gotographic    ENDP
  777.  
  778.  
  779. ;--- BMI EXIT BIT MAP MODE --------------------------------------------
  780. ;return to normal graphics mode
  781. ;Assume:  nothing
  782. ;Entry:   N/A
  783. ;Return:  N/A
  784. ;Destory: None
  785.  
  786. bmi_exitgraphic    PROC FAR
  787.     RET        ; do nothing
  788. bmi_exitgraphic    ENDP
  789.  
  790.  
  791. ;--- BMI SET PIXEL ----------------------------------------------------
  792. ;Fast version of Set Pixel. 
  793. ;Assume:  nothing
  794. ;Entry:   AX = X
  795. ;         BX = Y 
  796. ;         DL = Pixel value to write
  797. ;Return:  N/A
  798. ;Destory: None
  799.  
  800. bmi_putpixel    PROC FAR
  801.     PUSH    DS
  802.      IF BGIVERSION LT 3
  803.     PUSH    CS
  804.     POP    DS
  805.      ELSE
  806.     MOV    DS,CS:[ALIAS]
  807.      ENDIF
  808.     CALL    _setpixel   ;See _setpixel for more information
  809.     POP    DS 
  810.     RET            ;since we only have one setpixel version
  811. bmi_putpixel    ENDP
  812.  
  813.  
  814. ;--- BMI GET PIXEL ----------------------------------------------------
  815. ;Fast version of Get Pixel. 
  816. ;Assume:  nothing
  817. ;Entry:   AX = X
  818. ;         BX = Y 
  819. ;Return:  DL = Pixel value read
  820. ;Destory: None
  821.  
  822. bmi_getpixel    PROC FAR
  823.     PUSH    DS
  824.      IF BGIVERSION LT 3
  825.     PUSH    CS
  826.     POP    DS
  827.      ELSE
  828.     MOV    DS,CS:[ALIAS]
  829.      ENDIF
  830.     CALL    _getpixel   ;See _getpixel for more information
  831.     POP    DS 
  832.     RET            ;since we only have one getpixel version
  833. bmi_getpixel    ENDP
  834.  
  835.  
  836. ;--- BMI BITS PER PIXEL -----------------------------------------------
  837. ;Return how many bits are in a pixel
  838. ;Assume:  nothing
  839. ;Entry:   N/A
  840. ;Return:  AX = number of bits used to define a pixel
  841. ;Destory: None
  842.  
  843. bmi_bitsperpixel PROC FAR
  844.     PUSH    DS
  845.      IF BGIVERSION LT 3
  846.     PUSH    CS
  847.     POP    DS
  848.      ELSE
  849.     MOV    DS,CS:[ALIAS]
  850.      ENDIF
  851.     MOV    AL,DS:[StatBlock.PixelBits]
  852.     MOV    AH,0
  853.     POP    DS
  854.     RET
  855. bmi_bitsperpixel ENDP
  856.  
  857.  
  858. ;--- BMI SET PAGE -----------------------------------------------------
  859. ;Draw the page passed in AL
  860. ;Assume:  nothing
  861. ;Entry:   AL = Page to draw
  862. ;Return:  N/A
  863. ;Destory: None
  864.  
  865. bmi_setpage    PROC FAR
  866.     RET            ;no draw page selection being done
  867. bmi_setpage    ENDP
  868.  
  869.  
  870. ;--- BMI SET VISUAL PAGE ----------------------------------------------
  871. ;Select the visual display page passed AL
  872. ;Assume:  nothing
  873. ;Entry:   AL = Display page to select
  874. ;Return:  N/A
  875. ;Destory: None
  876.  
  877. bmi_setvisual    PROC FAR
  878.     RET            ;no visual page selection being done
  879. bmi_setvisual    ENDP
  880.  
  881.  
  882. ;--- BMI SET WRITE MODE -----------------------------------------------
  883. ;Set pixel write mode as passed in AL for the procedure group specified
  884. ;or select specific function by command.
  885. ;Assume: nothing
  886. ;Entry:  AL = Bits 5-7 = command
  887. ;             Bits 0-4 = mode/type
  888. ;
  889. ;Bits 5,6 and 7 select the command function to be performed.
  890. ;  000 = 0:(00) Line write mode
  891. ;  001 = 1:(20) Pixel write mode
  892. ;  010 = 2:(40) Fill write mode
  893. ;  011 = 3:(60) FloodFill type
  894. ;  100 = 4:(80) Text write mode
  895. ;  101 = 5:(A0)  <reserved>
  896. ;  110 = 6:(C0)  <reserved>
  897. ;  111 = 7:(E0) Misc commands 
  898. ;
  899. ;for commands 00, 20, 40, and 80 one of the following subfunctions
  900. ;is added to the command. 
  901. ;  0= MOVE write       8= FORE MOVE write      16= BACK MOVE write     
  902. ;  1= XOR write        9= FORE XOR write       17= BACK XOR write      
  903. ;  2= OR write        10= FORE OR write        18= BACK OR write      
  904. ;  3= AND write       11= FORE AND write       19= BACK AND write     
  905. ;  4= NOT MOVE write  12= FORE NOT MOVE write  20= BACK NOT MOVE write
  906. ;  5= NOT XOR write   13= FORE NOT XOR write   21= BACK NOT XOR write 
  907. ;  6= NOT OR write    14= FORE NOT OR write    22= BACK NOT OR write  
  908. ;  7= NOT AND write   15= FORE NOT AND write   23= BACK NOT AND write 
  909. ;  24 = Set Background color to currently selected foreground color.
  910. ;  30 = Return current selected write mode on next GetMaxMode call.
  911. ;  31 = Return current background color on next GetMaxMode call.
  912. ;  25-29 = (-unused-)
  913. ;
  914. ;for command 60 (floodfill commands), one of the following subfunctions 
  915. ;is added to the command.
  916. ;  0= Border fill         8= Auto Fill         12= DelayDraw Off
  917. ;  1= Seed fill           9= Complex Fill      13= DelayDraw On
  918. ;  2-7   = (-unused-)    10= Compress Off      14= Tracer Off
  919. ;  16-30 = (-unused-)    11= Compress On       15= Tracer On
  920. ;  31 = Return currently selected floodfill option bits
  921. ;
  922. ;for command E0 (misc commands), one of the following subfunctions 
  923. ;is added to the command.
  924. ;   0-23 =   (-unused-)
  925. ;     24 = Set PutImage background color to current draw color (SetColor).
  926. ;     25 = Return current selected graphics mode in next GetMaxMode call.
  927. ;     26 = Return last peak floodfill stack usage in next GetMaxMode call.
  928. ;     27 = Return last floodfill stack free space in next GetMaxMode call. 
  929. ;     28 =   (-unused-)
  930. ;     29 =   (-unused-)
  931. ;     30 = Return last used putimage write mode in next GetMaxMode call. 
  932. ;     31 = Return current PutImage background color on next GetMaxMode call.
  933. ;note: #25 is used for reverse compatiblity to V2.0x of the BGI256 driver.
  934. ;Future versions will require the Misc command function to be used 
  935. ;(prior version did not require it (ie the top three bits were ignored).
  936. ;This version will still respond to #25, but you should use the 0E0H
  937. ;misc command tag for future compatibility.
  938. ;
  939. ;note: The old command C0 (BitMap write mode) will not be supported in 
  940. ;the future. it still functions in this version of the driver, but it 
  941. ;may change on the next release. The function only was able to set the 
  942. ;background color of the PutImage function anyway, so I moved it to 
  943. ;the Misc Command function to free up the group number for future use.
  944. ;
  945. ;-------------
  946. ;Return:  N/A
  947. ;Destroy: None
  948.  
  949. bmi_setwritemode PROC FAR
  950.     PUSH    DS
  951.     PUSH    DX
  952.     PUSH    CX
  953.     PUSH    BX
  954.     PUSH    AX
  955.      IF BGIVERSION LT 3
  956.     PUSH    CS
  957.     POP    DS
  958.      ELSE
  959.     MOV    DS,CS:[ALIAS]
  960.      ENDIF
  961.     MOV    CX,AX        ;stuff procedure selection in CL
  962.     AND    CL,0E0H        ;strip off draw mode select
  963.     AND    AL,1FH        ;strip off proc sel info in AL
  964.  
  965.     CMP    AL,25    ;-->    ;@(note: this will go away in the future)
  966.     JZ    @Bmiswg    ;-->    ;@you will have to use misc command instead
  967.     CMP    CL,0C0H    ;-->    ;@(note: this will go away in the future)
  968.     JZ    @Bmiswa    ;-->    ;@you will have to use misc command instead
  969.  
  970.     CMP    CL,060H
  971.     JZ    @Bmiswf        ;process fill type command
  972.     CMP    CL,0A0H    
  973.     JZ    @Bmiswx        ;currently unused so ignore this
  974.     CMP    CL,0E0H
  975.     JZ    @Bmiswg        ;process misc commands
  976.  
  977. @Bmiswa:
  978.     CMP    AL,24        ;0-23 its a write mode command so go do it
  979.     JL    @Bmiswp        ;Go set proc mode
  980.     JZ    @Bmiswb        ;24=Do Background color selection
  981.     CMP    AL,30
  982.     JL    @Bmiswx        ;25-29=unknown function
  983.     JZ    @Bmisww        ;30=ret write mode on next GetMaxMode call
  984.     JMP    @Bmiswv        ;31=ret backgnd color on next GetMaxMode call
  985.  
  986. @Bmiswg:
  987.     JMP    @Bmiswm
  988.  
  989. @Bmiswrb:
  990.     MOV    AH,0         ;ret byte value
  991. @Bmiswrw:
  992.     MOV    DS:[RetValue],AX ;ret word value
  993.     MOV    byte ptr DS:[ModeXflag],1 ;mark that value is to be returned
  994. @Bmiswx:
  995.     POP    AX
  996.     POP    BX
  997.     POP    CX
  998.     POP    DX
  999.     POP    DS
  1000.     RET
  1001. bmi_setwritemode ENDP
  1002.  
  1003.  
  1004. ;--------------------------------
  1005. ;write mode command processor
  1006. @Bmiswp:
  1007.     MOV    CH,AL         ;save the mode select
  1008.     MOV    AH,0        ;index into proc pointer table
  1009.     ADD    AX,AX        ;to get the proc address
  1010.     LEA    BX,DrawModeTable
  1011.     ADD    BX,AX
  1012.     MOV    DX,DS:[BX]        ;get selected proc addr into DX
  1013.     CALL    GetWriteModeAdr
  1014.     JNZ    @Bmiswpx     ;invalid mode selection
  1015.     MOV    DS:[BX],DX   ;save selected draw mode procedure address
  1016.     MOV    BX,AX         ;in the selected group procedure pointer
  1017.     MOV    DS:[BX],CH   ;save mode select number
  1018. @Bmiswpx:
  1019.     JMP    @Bmiswx
  1020.  
  1021. ;--------------------------------
  1022. ;set background write mode 
  1023. @Bmiswb:
  1024.     CALL    GetBackColorAdr ;function 24, set background
  1025.     JNZ    @Bmiswbx    ;<-- invalid background selection
  1026.     MOV    AH,DS:[DrawForeColor]
  1027.     MOV    DS:[BX],AH    ;store the new background color
  1028. @Bmiswbx:
  1029.     JMP    @Bmiswx
  1030.  
  1031. ;--------------------------------
  1032. ;return selected write mode on next GetMaxMode call
  1033. @Bmisww:
  1034.     CALL    GetWriteModeAdr
  1035.     JNZ    @Bmiswwx    ;<-- invalid background selection
  1036.     MOV    BX,AX
  1037.     MOV    AL,DS:[BX]    ;read current selected mode
  1038.     JMP    @Bmiswrb
  1039. @Bmiswwx:
  1040.     JMP    @Bmiswx
  1041.  
  1042. ;--------------------------------
  1043. ;return selected background color on next GetMaxMode call
  1044. @Bmiswv:
  1045.     CALL    GetBackColorAdr ;function 24, set background
  1046.     JNZ    @Bmiswvx    ;<-- invalid background selection
  1047.     MOV    AL,DS:[BX]    ;get the background color
  1048.     JMP    @Bmiswrb
  1049. @Bmiswvx:
  1050.     JMP    @Bmiswx
  1051.  
  1052. ;--------------------------------
  1053. ;floodfill type command processor
  1054. @Bmiswf:
  1055.     CMP    AL,16        ;over range?
  1056.     JNC    @Bmiswf8
  1057.     MOV    CH,DS:[FloodFillType] ;get current type flags
  1058.     MOV    BL,AL        ;copy new select bit to BL
  1059.     AND    BL,01H        ;strip off control bits
  1060.     MOV    BH,0FEH        ;init bit mask
  1061.     MOV    CL,AL
  1062.     SHR    CL,1        ;seed or border fill command?
  1063.     JZ    @Bmiswf7    ;yes, go set the type bit
  1064.     CMP    AL,08H
  1065.     JL    @Bmiswfx    ;unused command
  1066.     CMP    AL,10H        ;control command?
  1067.     JGE    @Bmiswfx
  1068.     AND    CL,03H        ;strip garbage
  1069.     INC    CL        ;adjust bit position
  1070.     INC    CL
  1071. @Bmiswf7:
  1072.     ROL    BH,CL        ;move bit mask into position
  1073.     ROL    BL,CL        ;move bit flag into position
  1074.     AND    CH,BH        ;strip old bit
  1075.     OR    CH,BL        ;or in new bit
  1076.     MOV    DS:[FloodFillType],CH    ;set floodfill type
  1077.     JMP    @Bmiswfx
  1078.  
  1079. @Bmiswf8:
  1080.     CMP    AL,31        ;return floodfill option bits?
  1081.     JNZ    @Bmiswfx
  1082.     MOV    AL,DS:[FloodFillType]
  1083.     JMP    @Bmiswrb
  1084. @Bmiswfx:
  1085.     JMP    @Bmiswx
  1086.  
  1087.  
  1088. ;--------------------------------
  1089. ;misc command processor
  1090. ;24=set putimage background color
  1091. ;25=ret selected graphics mode
  1092. ;26=ret xystack peak
  1093. ;27=ret xystack free
  1094. ;30=ret putimage background color
  1095. ;31=ret last used putimage write mode
  1096. @Bmiswm:
  1097.     CMP    AL,24        ;set putimage background color
  1098.     JZ    @Bmiswm3
  1099.     CMP    AL,25        ;ret graphics mode selection
  1100.     JZ    @Bmiswm4
  1101.     CMP    AL,26        ;ret xystack peak
  1102.     JZ    @Bmiswm5
  1103.     CMP    AL,27        ;ret xystack free
  1104.     JZ    @Bmiswm6
  1105.     CMP    AL,30        ;ret last used putimage write mode
  1106.     JZ    @Bmiswm7
  1107.     CMP    AL,31        ;ret putimage background color
  1108.     JZ    @Bmiswm8
  1109. @Bmiswmx:
  1110.     JMP    @Bmiswx        ;unknown function request
  1111.  
  1112. @Bmiswm3:
  1113.     MOV    AH,DS:[DrawForeColor]    ;update the putimage backcolor
  1114.     MOV    DS:[BitMapBackColor],AH    ;to be the current drawing color
  1115.     JMP    @Bmiswmx
  1116.  
  1117. @Bmiswm4:
  1118.     MOV    AL,DS:[ModeSelect]    ;25=return current graphics mode
  1119.     JMP    @Bmiswrb
  1120.  
  1121. @Bmiswm5:
  1122.     MOV    AX,DS:[XYStackPeak]    ;26=return xystack peak
  1123.     JMP    @Bmiswrw
  1124.  
  1125. @Bmiswm6:
  1126.     MOV    AX,DS:[XYStackFree]    ;27=return xystack free
  1127.     JMP    @Bmiswrw
  1128.  
  1129. @Bmiswm7:
  1130.     MOV    AL,DS:[BitMapPixelWriteMode] ;30=ret putimage write mode
  1131.     JMP    @Bmiswrb
  1132.  
  1133. @Bmiswm8:
  1134.     MOV    AL,DS:[BitMapBackColor] ;31=return putimage backcolor
  1135.     JMP    @Bmiswrb
  1136.  
  1137.  
  1138. ;----------------------------------------------------------------
  1139. ;return the desired write mode and write procedure addresses
  1140. ;Assume: DS = data segment
  1141. ;Enter:  CL = mode selector
  1142. ;Return: AX = write mode variable address
  1143. ;        BX = write procedure pointer
  1144. ;destroy: nothing
  1145.  
  1146. GetWriteModeAdr PROC NEAR
  1147.     LEA    AX,LinePixelWriteMode
  1148.     LEA    BX,LinePixelProc
  1149.     CMP    CL,0        ;set for line procs?
  1150.     JZ    @Bmiswdx
  1151.     LEA    AX,DrawPixelWriteMode
  1152.     LEA    BX,DrawPixelProc
  1153.     CMP    CL,20H        ;set for pixel procs?
  1154.     JZ    @Bmiswdx
  1155.     LEA    AX,FillPixelWriteMode
  1156.     LEA    BX,FillPixelProc
  1157.     CMP    CL,40H        ;set for fill procs?
  1158.     JZ    @Bmiswdx
  1159.     LEA    AX,TextPixelWriteMode
  1160.     LEA    BX,TextPixelProc
  1161.     CMP    CL,80H        ;set for text procs?
  1162.     JZ    @Bmiswdx
  1163.     LEA    AX,BitMapPixelWriteMode
  1164.     LEA    BX,BitMapPixelProc ;(note: 0C0H goes away in future)
  1165.     CMP    CL,0C0H
  1166.     JZ    @Bmiswdx
  1167. @Bmiswdx:
  1168.     RET    ;unused selections: (060H, 0A0H, 0E0H, 0C0H)
  1169. GetWriteModeAdr ENDP
  1170.  
  1171.  
  1172. ;----------------------------------------------------------------------
  1173. ;return the desired background color variable address
  1174. ;Assume: DS = data segment
  1175. ;Enter:  CL = mode selector
  1176. ;Return: BX = write mode variable address
  1177. ;destroy: nothing
  1178.  
  1179. GetBackColorAdr PROC NEAR
  1180.     LEA    BX,DrawBackColor      ;(line back color)
  1181.     CMP    CL,00H
  1182.     JZ    @Bmiswcx
  1183.     LEA    BX,PixelBackColor
  1184.     CMP    CL,20H
  1185.     LEA    BX,FillBackColor
  1186.     CMP    CL,40H
  1187.     JZ    @Bmiswcx
  1188.     LEA    BX,TextBackColor
  1189.     CMP    CL,80H
  1190.     JZ    @Bmiswcx
  1191.     LEA    BX,BitMapBackColor ;(note: this bitmap cmd goes away in future)
  1192.     CMP    CL,0C0H
  1193.     JZ    @Bmiswcx
  1194. @Bmiswcx:
  1195.     RET    ;unused selections: (060H, 0A0H, 0E0H, 0C0H)
  1196. GetBackColorAdr ENDP
  1197.  
  1198. ;-----------------------------------------------------------------------
  1199.