home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / dos / grafik / cbgi111 / src / lib / device.inc < prev    next >
Encoding:
Text File  |  1990-06-15  |  8.1 KB  |  314 lines

  1. ; ************************************************************************
  2. ; File: Device.inc
  3. ;
  4. ; Copyright (c) 1988,1989  Borland International, Inc.
  5. ; Copyright (c) 1989,1990  R. Adsett 
  6. ;
  7. ; Purpose: define all the strucs/macros for the BGI interface
  8. ;    Heavily modified to provide a transparent C interface.
  9. ;
  10. ; Last Update: 15/06/90
  11. ;
  12. ; Updates: 30/09/88 -- Original
  13. ;       22/06/89 -- Add stack switching logic so that a C interface can
  14. ;            be used without fear.  Requires the external word
  15. ;            _STACK_ which resides just before the end of the
  16. ;            driver stack.
  17. ;       15/06/90 -- Change from ideal mode back to normal MASM syntax.
  18. ;            Avoid the use of the simplified model and segment
  19. ;            directives since the segment order has to be 
  20. ;            changed from the default DOSSEG ordering.  See
  21. ;            C0CBGI.ASM for a more complete explanation.  Also
  22. ;            some cosmetic changes.
  23. ;
  24. ; ************************************************************************
  25.  
  26. callBGI macro    p
  27.  
  28.     ifndef    BGI_add                ; long call device driver ovr
  29.     extrn    BGI_add:dword            ; though pointer to driver
  30.     endif
  31.     mov    si,$&p                ; (si) is the function code
  32.     call    dword ptr BGI_add
  33.  
  34. endm
  35.  
  36. BGIstat macro    p                ; get es:<si> --> ddo status
  37.     ifndef    stable
  38.     extrn    stable:dword
  39.     endif
  40.     les    si,cs:dword ptr stable        ; get location of status to si
  41.     add    si,$&p                ; offset to correct location
  42. endm
  43.  
  44. ; **********************************************************************
  45.  
  46. ; The following macro builds the required BGI header block
  47.  
  48. BGI    macro    name
  49.  
  50. EXTRN _stack_:WORD            ; Where the stack is.
  51.  
  52. ;;
  53. ;; Needed by other routines that do a stack switch.
  54. ;;
  55.  
  56. public    STACK_SEG            ; Save SS:SP for stack switch
  57. public    STACK_PTR
  58. public    regbx                 ; These registers are overwritten
  59. public    regdx                 ;   during the stack switch.  
  60. public    regsi                 ;   They are saved here so they
  61. public    regdi                 ;   can be restored.
  62.  
  63.                     ; the following builds
  64.     public    name            ; the required ddo header block
  65. name    proc    far            ; the vector table must be at
  66.                     ; 'ddovec' if vector not speced
  67.     push    ds            ; (push ds, push cs are signature)
  68.     push    cs            ; make ds=cs
  69.     pop    ds
  70.     cld                ; just in case
  71.     push    bp            ; 6 bytes
  72.  
  73.     call    dispatch
  74.  
  75.     nop
  76.  
  77.     pop    bp
  78.     pop    ds            ; restore
  79.     ret                ; far
  80. endp
  81.     db    'CB'            ; just for fun
  82.     dw    ?
  83. EMULATE2:ret                ; emulate function (nop until
  84.     dw    0,0            ; patched by loader)
  85. RESERVED:
  86. NONE:    ret                ; near ret for unused functions
  87.  
  88. STACK_SEG dw 0                ; Save SS:SP for stack switch
  89. STACK_PTR dw 0
  90. regbx    dw    0            ; These registers are overwritten
  91. regdx    dw    0            ;   during the stack switch.  
  92. regsi    dw    0            ;   They are saved here so they
  93. regdi    dw    0            ;   can be restored.
  94.  
  95. ;;;;
  96.  
  97. dispatch    proc    near        ;Perform the stack switch and 
  98.                     ;call the desired routine.
  99.     mov    [regbx],bx        ;Save incoming registers.
  100.     mov    [regdx],dx
  101.     mov    [regsi],si
  102.     mov    [regdi],di
  103.  
  104.     mov    dx,ds            ;dx = ds = cs
  105.  
  106.         mov    di,ss            ;Save old SS:SP
  107.         mov    si,sp
  108.     mov    [STACK_SEG],di
  109.     mov    [STACK_PTR],si
  110.  
  111.     mov    bx, offset DGROUP:_stack_    ;New stack is where?
  112.  
  113. ;;    Set up the driver stack
  114.  
  115.     cli                ;In case we have an old CPU.
  116.     
  117.     mov    ss, dx            ; Stack goes here.
  118.     mov    sp, bx
  119.  
  120.     sti                ;Back to normal.
  121.  
  122.     mov    bx,[regbx]        ;Restore all those registers.
  123.     mov    dx,[regdx]
  124.     mov    si,[regsi]
  125.     mov    di,[regdi]
  126. ;;;;
  127.  
  128.     call    [DDOVEC+si]        ; call the local function
  129. ;;;;
  130.     mov    si,[STACK_SEG]        ;Old stack was where?
  131.     mov    di,[STACK_PTR]
  132.  
  133.     cli                ;In case we have an old CPU.
  134.     mov    ss,si            ;Restore Old stack.
  135.     mov    sp,di
  136.     sti
  137.     ret
  138. ;;;;
  139. endp
  140.  
  141. EMULATE    proc    near            ;Kernal can't handle a switched
  142.                     ;stack so...
  143.     mov    si,[STACK_SEG]        ;Restore stack.
  144.     mov    di,[STACK_PTR]
  145.  
  146.     cli
  147.     mov    ss,si
  148.     mov    sp,di
  149.     sti
  150.  
  151.     mov    bx,[regbx]        ;Restore registers.
  152.     mov    dx,[regdx]
  153.     mov    si,[regsi]
  154.     mov    di,[regdi]
  155.     jmp    EMULATE2        ;call kernal emulator
  156.  
  157. endp
  158.  
  159. endm
  160.  
  161. ; ************** the device driver vector table definition **************
  162.  
  163. $ddo        struc
  164.  
  165. $install    dw    ?    ; install device.
  166.                 ; required to return es:<bx> to status table.
  167.  
  168. $init        dw    ?    ; (bh)=texture (bl)= background color to use.
  169.                 ; ready device for output.
  170.                 ; es:[di] --> rotate,xclip1,yclip1,xclip2,yclip2
  171.  
  172. $clear        dw    ?    ; clear graphics device and ready it for
  173.                 ; output.
  174.  
  175. $post        dw    ?    ; make picture visible. used for making
  176.                 ; printer bitmaps visible, for unloading
  177.                 ; the plotter pen, or for restoring screen.
  178.  
  179. $move        dw    ?    ; used by text, arc, symbol, draw, fill etc.
  180.                 ; set c.p. (ax,bx) = (x,y)
  181.  
  182. $draw        dw    ?    ; draw to (ax,bx) = (x,y)
  183.  
  184. $vect        dw    ?    ; (ax,bx,cx,dx) = x0,y0,x1,y1
  185.  
  186. $poly        dw    ?    ; draw polygon.
  187.                 ; ax=0 start new polygon definition
  188.                 ; ax=1 close and trace poly
  189.                 ; ax=2 close,  fill poly and trace
  190.                 ; ax=3 close and fill poly
  191.                 ; ax=4 draw points and don't capture
  192.                 ; ax=5 turn off polygon capture
  193.                 ; ax=6 draw polygon at es:[bx] and (cx) points
  194.                 ; ax=7 fill & trace polygon at es:[bx] with (cx) points
  195.                 ; ax=8 fill polygon at es:[bx] with (cx) points
  196.  
  197. $dbar        dw    ?    ; bar fill (cpx,cpy,ax,bx)=x0,y0,x1,y1
  198.                 ; (bx,cx)=dx,dy for 3d (with outline)
  199.  
  200. $patbar        dw    ?    ; pattern bar (no outline)
  201.  
  202. $darc        dw    ?    ; draw arc
  203.  
  204. $piesl        dw    ?    ; (ax,bx)= start ang, end ang
  205.                 ; (cx,dx)= x radius, y radius
  206.                 ; center is a cp. (with outline)
  207.  
  208. $fellipse    dw    ?    ; (ab,bx) = x radius, yradius
  209.                 ; (no outline)
  210.  
  211. $palette    dw    ?    ; load a palette entry
  212.                 ; (ax)=entry # (bx)=value
  213.                 ; if (ax)=-1 set background
  214.  
  215. $allpalette    dw    ?    ; load the full palette
  216.                 ; es:[bx] --> palette array
  217.  
  218. $color        dw    ?    ; set active draw color & pattern fill color
  219.                 ; (al)= draw (trace) color (ah)=fill color
  220.  
  221. $fstyle        dw    ?    ; (al)=fill pattern #
  222.                 ; (al)=0 no fill, 1 solid ...
  223.                 ; (ah)=background color (normally 0)
  224.                 ; (used only if pattern in al > 80h)
  225.                 ; if (al)=ff es:<bx>--> pattern definition
  226.  
  227. $lstyle        dw    ?    ; (al)=0(solid) 1(dotted) 2(centerline) 3(dash)
  228.                 ; 4(use pattern) (bx)=bit pattern
  229.                 ; (cx)=line width (normally one)
  230.  
  231. $tstyle        dw    ?    ; (al)=font (ah)=style
  232.                 ; (bx)=x charsize (cx)=y charsize
  233.                 ; if (al)=ff es:<bx>--> font definition table
  234.                 ; changes all params to those available.
  235.  
  236. $text        dw    ?    ; draw text. es:<bx> --> <string>, (0)
  237.  
  238. $textsize    dw    ?    ; text length.
  239.  
  240. $textinfo    dw    ?    ; extended text settings.
  241.  
  242. $flood        dw    ?    ; floodfill (ax,bx) = x,y seed coordinate.
  243.  
  244. $getpix        dw    ?    ; read pixel @(ax,bx) to (dl)
  245.  
  246. $putpix        dw    ?    ; put (dl) to pixel @(ax,bx)
  247.  
  248. $bitmaputil    dw    ?    ; returns (es:[bx]) = bitmap utilities.
  249.                 ;    dw gotographic
  250.                 ;    dw exitgraphic
  251.                 ;    dw putpix
  252.                 ;    dw getpix
  253.                 ;    dw pixelsperbyte
  254.                 ;    dw setwritemode
  255.  
  256. $savebitmap    dw    ?    ; es:[bx]--> buffer to save bitmap to.
  257.                 ; contain bitmap size (pixels) in 1st 2 words
  258.                 ; cx = start x    dx = start line # y
  259.  
  260.  
  261. $restorebitmap    dw    ?    ; es:[bx]--> bitmap buffer to restore.
  262.                 ; contains bitmap size (pixels) in 1st 2 words
  263.                 ; cx=start x dx= start y to put
  264.                 ; (al) = bitblt op (copy, xor, comp, etc.)
  265.  
  266. $setclip    dw    ?    ; extended function to set clip window
  267.                 ; (ax,bx)-(cx,dx) = clip rectangle
  268.  
  269. $query_color    dw    ?    ; extended function for color information
  270.  
  271. $escape        dw    ?    ; escape function for direct i/o
  272.  
  273. $symbol        dw    ?    ; draw symbol (al) = symbol #
  274.                 ; if (al)=ff es:<bx>--> symbol definition
  275.  
  276. $reserve    dw    ?    ; 32 reserved entry points
  277.  
  278. $user        dw    ?    ; User available entry points
  279.  
  280. ends
  281.  
  282. ; ************** the device driver status table definition **************
  283.  
  284. $status        struc
  285.  
  286. $stat    db    0        ; 0 = no errors
  287. $devtyp db    0        ; device type 0=screen 1=printer 2=plotter
  288. $xres    dw    639        ; full resolution
  289. $yres    dw    199
  290. $xefres dw    639        ; effective resolution
  291. $yefres dw    199
  292. $xinch    dw    9000        ; device size in inches*1000
  293. $yinch    dw    7000
  294. $aspec    dw    21200        ; aspect ratio
  295. $chsiz    dw    808h        ; standard char size x,y (points)
  296. $coltbl dw    9090h        ; color tables
  297. ends
  298.  
  299. ; **********************************************************************
  300. ; this struc defines the info struc returned from the
  301. ; bgi bitmaputil function call @(es:[bx])
  302. $bitmapinfo        struc
  303. $gotographic    dw    ?
  304. $exitgraphic    dw    ?
  305. $putpixel    dw    ?
  306. $getpixel    dw    ?
  307. $bitsperpixel    dw    ?
  308. $setpage    dw    ?    ; draw page in (al)
  309. $setvisual    dw    ?    ; visual display page (al)
  310. $setwritemode    dw    ?    ; set write mode (al)
  311. ends
  312.  
  313.  
  314.