home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / misc / volume2 / egafast / Part1 next >
Encoding:
Internet Message Format  |  1991-08-07  |  35.0 KB

  1. From: mcdonald@uxe.cso.uiuc.edu (J.D. McDonald )
  2. Newsgroups: comp.sources.misc
  3. Subject: v02i022: EGAFAST IBM-PC Graphics Package, Part 1/2
  4. Message-ID: <7133@ncoast.UUCP>
  5. Date: 26 Jan 88 04:27:34 GMT
  6. Approved: allbery@ncoast.UUCP
  7.  
  8. Comp.sources.misc: Volume 2, Issue 22
  9. Submitted-By: J.D. McDonald <mcdonals@uxe.cso.uiuc.edu>
  10. Archive-Name: egafast/Part1
  11.  
  12. [I am sending this person a complimentary "shar" program.  I can post it as
  13. is or spend the next 6 months trying to take the two files apart... guess
  14. which I chose.  The author takes his chances with its making it over the
  15. net.  ++bsa]
  16.  
  17. due to the size, distribution is in two parts
  18. This is part one.
  19.  
  20.  
  21. *********begin file READ.ME*************
  22. This is a very simple graphics package for the EGA and VGA. It draws the
  23. basic primitives of lines, ellipses, filled rectangles, filled ellipses,
  24. and text (two sizes and user defined). It is written to get the ultimate
  25. in high speed possible while drawing in the set/reset mode. It can be
  26. called from Microsoft C and Fortran, or any language including assembler
  27. which follows their calling conventions.
  28. Here is a list of the included files:
  29.  
  30. CLIPLINE C     Source code for clipped line routine.
  31. EGAFORT  H     Header file for subroutine prototypes for Fortran.
  32. EGAGRA   ASM   The main graphics package source.
  33. EGAGRA   DOC   Documentation.
  34. EGATEST  C     A test program to verify correct compilation.
  35. ELLIPSE  C     Source code for ellipse drawers.
  36. GRAFEX1  C     Example program that draws a star.
  37. GRAFEX2  C     Example program that uses user-defined patterns.
  38. INTEST   ASM   Assembler subroutine for SLUGS.FOR
  39. MACROS   AH    Header file for EGAGRA.ASM which defines memory model.
  40. MOVERM   C     Example program for plane masking.
  41. MOVERS   C     Example program for page swapping and plane masking.
  42. SLUGS    FOR   Example program in Fortran whose results look nice.
  43.  
  44. Some of the code in this package is patterned after that of U.E.Kruse of
  45. the U. of I. Physics department. The grafex1 demo program generates
  46. essentially the same pattern as the one of the same name in the package
  47. by Scott Snyder of caltech recently posted on the net. The macros.ah
  48. is also from his package.
  49.  
  50. Your comments are welcome, especially if you see anything faster.
  51.  
  52. Doug McDonald
  53. University of Illinois
  54. 505 S. Matthews 
  55. Urbana Ill. 61801
  56. (mcdonald@uiucuxe or mcdonald@uxe.cso.uiuc.edu)
  57.  
  58.  
  59. ***********end file READ.ME***********
  60. ***********begin file EGAGRA.ASM************
  61. include macros.ah
  62.  
  63. _DATA   segment  word public 'DATA'
  64. first8  dw       0
  65. first14 dw       0
  66. drawseg dw      0A000h
  67. maxseg  dw      28000
  68. maxline dw      350
  69. _DATA   ends
  70. CONST   segment  word public 'CONST'
  71. ate     dw       8
  72. fourt   dw       14
  73. eighty  dw       80
  74. btab    db       80h,40h,20h,10h,8h,4h,2h,1h
  75. left    db       255,127,63,31,15,7,3,1
  76. right   db       128,192,224,240,248,252,254,255
  77. CONST   ends
  78. _BSS    segment  word public 'BSS'
  79. es8       dw        ?
  80. bp8       dw        ?
  81. es14      dw        ?
  82. bp14      dw        ?      
  83. leftbit   db        ?
  84. rightbit  db        ?
  85. lefttop   dw        ?
  86. leftbot   dw        ?
  87. righttop  dw        ?
  88. rightbot  dw        ?
  89. ysave     dw        ?
  90. leftx     dw        ?
  91. rightx    dw        ?
  92. xx0       dw        ?
  93. yy0       dw        ?
  94. xx1       dw        ?
  95. yy1       dw        ?
  96. xc10      dw        ?
  97. xc20      dw        ?
  98. xc11      dw        ?
  99. xc21      dw        ?
  100. lowyb     dw        ?
  101. del_y     dw        ?
  102. del_x     dw        ?
  103. _BSS      ends
  104. DGROUP  GROUP    CONST, _BSS, _DATA
  105.          assume   ds: DGROUP, ss: DGROUP, es:  DGROUP
  106. cseg    _egagraf
  107.  
  108. ;The code in this program has been optimized for speed, not readibility.
  109. ;As much as possible is put into registers. Replication of large blocks
  110. ;of code has been used in some places to avoid calling subroutines.
  111.  
  112. pBegin  _symbol
  113. ;  symbol(ix,iy,height,icol,&isym) plots a single 8xheight character  
  114. ;  matrix pointed to by isym at ix, iy in color icol. 
  115. ;  ix, iy and icol are integers 
  116.         push    bp
  117.         mov     bp,sp
  118.         push    di
  119.         push    si
  120. ifdef NEARDATA
  121.         mov     si, word ptr [bp+argbase+12]   ;pick up address of table
  122.         mov     bx,ds                          ;containing symbol to plot
  123.         mov     es,bx
  124. endif
  125. ifdef FARDATA
  126.         les     si,[bp+argbase+12]
  127. endif
  128.         mov     bx,word ptr [bp+argbase+8]      ;height
  129.         mov     ax,word ptr [bp+argbase+4]      ;this is x
  130.         mov     dx,ax                ;break x into byte # and bit in byte
  131.         and     dx,7
  132.         mov     cl,3
  133.         sar     ax,cl
  134.         mov     [bp+argbase+8],ax    ;byte #
  135.         mov     [bp+argbase+4],dx    ;leftmost bit used   
  136.         mov     dx,drawseg       ; segment of display buffer
  137.         push    ds
  138.         mov     ax,es             
  139.         mov     es,dx
  140.         mov     ds,ax               
  141.         jmp     commonl
  142.  
  143. pEnd _symbol
  144.  
  145.  
  146. pBegin _slettr
  147. ;  slettr(ix,iy,ichr,icol) plots a single 8-high IBM character ichr at x,y in 
  148. ;  color icol.   all are integers
  149.         push    bp
  150.         mov     bp,sp
  151.         push    di
  152.         push    si
  153.         cmp     first8,0        ;get address of bios table of characters
  154.         jne     sec8
  155.         inc     first8          ;done only first time this routine is called
  156.         mov     ah, 011h
  157.         mov     al, 030h
  158.         mov     bh, 03
  159.         push    bp              ;(gasp)Bios call destroys BP
  160.         int     010h
  161.         mov     ax,es
  162.         mov     es8,ax
  163.         mov     bp8,bp
  164.         pop     bp
  165. sec8:
  166.         xor     ax,ax
  167.         mov     al,byte ptr [bp+argbase+8]   ;this is the character
  168.                                 ;look up location of ascii characters
  169.         mov     cl,3
  170.         shl     ax,cl            ;in bios 
  171.         add     ax,bp8             
  172.         mov     si,ax              
  173.         mov     ax,word ptr [bp+argbase+4]      ;this is x
  174.         mov     dx,ax
  175.         and     dx,7             ;break into bit and byte
  176.         mov     cl,3
  177.         sar     ax,cl
  178.         mov     [bp+argbase+8],ax  ;byte #
  179.         mov     [bp+argbase+4],dx  ;bit in byte     
  180.         mov     ax,drawseg       ; segment of display buffer
  181.         mov     es,ax               
  182.         push    ds
  183.         mov     ax,es8          ; segment for bios reference
  184.         mov     ds,ax           ; used to 
  185.         mov     bx,8            ;find character
  186.         jmp     commonl
  187.  
  188. pEnd _slettr
  189.  
  190.  
  191. pBegin _llettr
  192. ; llettr(ix,iy,ichr,icol) plots a single IBM 14-high character ichr at x,y in 
  193. ; color icol.   all are integers
  194.         push    bp
  195.         mov     bp,sp
  196.         push    di
  197.         push    si
  198.  
  199.         cmp     first14,0       ;works just like slettr : done again for speed
  200.         jne     sec14
  201.         inc     first14
  202.         mov     ah, 011h
  203.         mov     al, 030h
  204.         mov     bh, 02
  205.         push    bp
  206.         int     010h
  207.         mov     ax,es
  208.         mov     es14,ax
  209.         mov     bp14,bp
  210.         pop     bp
  211. sec14:
  212.  
  213.         xor     ax,ax
  214.         mov     al,byte ptr [bp+argbase+8]    
  215.         mul     fourt        
  216.         add     ax,bp14           
  217.         mov     si,ax              
  218.         mov     ax,word ptr [bp+argbase+4]  
  219.         mov     dx,ax
  220.         and     dx,7
  221.         mov     cl,3
  222.         sar     ax,cl
  223.         mov     [bp+argbase+8],ax
  224.         mov     [bp+argbase+4],dx              
  225.  
  226.         mov     ax,drawseg     
  227.         mov     es,ax               
  228.         push    ds
  229.         mov     ax,es14       
  230.         mov     ds,ax      
  231.         mov     bx,14       
  232.  
  233.  
  234. commonl:
  235.                               ; symbol, slettr, and llettr the same after this
  236.                               ; compute location of byte to change
  237.         mov     ax,word ptr [bp+argbase+6]         ;this is y
  238.         mov     dx,ax
  239.         shl     dx,1
  240.         shl     dx,1
  241.         add     ax,dx
  242.         mov     cl,4
  243.         shl     ax,cl
  244.         add     ax,[bp+argbase+8]               ;this is horiz byte number
  245.         mov     di,ax
  246.  
  247.         mov     dx,3ceh         ; change SET/RESET register
  248.         mov     al,00h          ; to contain the color to write.
  249.         out     dx,al
  250.         mov     dx,3cfh
  251.         mov     ax,word ptr [bp+argbase+10]     ; <-- color
  252.         out     dx,al
  253.  
  254.         mov     dx,3ceh         ;point controller to bit mask register
  255.         mov     al,08h
  256.         out     dx,al
  257.         mov     dx,3cfh
  258.         cmp     word ptr [bp+argbase+8],0ffffh  ;special case:partially off
  259.                                                 ;left edge of screen
  260.         je      loop2m1
  261.         cmp     word ptr [bp+argbase+8],79      ;Partially off right edge
  262.         je      loop2p1
  263.         cmp     word ptr [bp+argbase+8],80  ;totally off screen horizontally
  264.         jae     commf
  265. loop2:
  266.  
  267.         xor     ax,ax
  268.         mov     ah,ds:[si+0]            ;get pattern of current row
  269.         mov     cx,[bp+argbase+4]
  270.         shr     ax,cl                   ;shr to get two bytes
  271.         out     dx,al    
  272.         inc     byte ptr es:[di+1]      ;actual screen write
  273.         mov     al,ah
  274.         out     dx,al
  275.         inc     byte ptr es:[di]        ;write second byte
  276.         add     di,80                   ;next row
  277.         inc     si
  278.         dec     bx
  279.         jg      loop2
  280.         jmp     commf
  281. loop2m1:
  282.  
  283.         xor     ax,ax                   ;leftmost byte is off screen
  284.         mov     ah,ds:[si+0]            ;get current row pattern
  285.         mov     cx,[bp+argbase+4]
  286.         shr     ax,cl                   ;shr to get two bytes
  287.         out     dx,al    
  288.         inc     byte ptr es:[di+1]      ;actual screen write
  289.         add     di,80
  290.         inc     si
  291.         dec     bx
  292.         jg      loop2m1
  293.         jmp     commf
  294. loop2p1:
  295.  
  296.         xor     ax,ax                  ;rightmost byte is off screen
  297.         mov     ah,ds:[si+0]           ;get current row pattern
  298.         mov     cx,[bp+argbase+4]
  299.         shr     ax,cl                  ;shr to get two bytes
  300.         mov     al,ah
  301.         out     dx,al
  302.         inc     byte ptr es:[di]
  303.         add     di,80
  304.         inc     si
  305.         dec     bx
  306.         jg      loop2p1
  307.  
  308. commf:
  309.         pop     ds
  310.         pop     si
  311.         pop     di
  312.         pop     bp
  313.         ret
  314.  
  315. pEnd _llettr
  316.  
  317. pBegin _max_lin
  318.         mov     ax,maxline
  319.         ret
  320. pEnd   _max_lin
  321.  
  322. ; setmod.asm routine to be called from c to set mode n using
  323. ; call setmod(n) : n=3 set to cursor mode, n=16 set to color graphics mode
  324. ; n = 15 for bw graphics mode, 18 for VGA 480x640 color mode 
  325.  
  326. pBegin _setmod
  327.  
  328.         push    bp
  329.         mov     bp,sp
  330.  
  331.         mov     ax, word ptr [bp+argbase+4]     
  332.         mov     maxseg,28000
  333.         mov     maxline,350
  334.         cmp     ax,18
  335.         jnz     setm1
  336.         mov     maxseg,38400
  337.         mov     maxline,480
  338. setm1:
  339.         int     10H
  340.         pop     bp              
  341.         ret
  342.  
  343. pEnd _setmod
  344.  
  345. pBegin _zsetup
  346.         push    dx
  347.         push    ax
  348.  
  349.         mov     dx,3c4h         ; allow writing to all planes
  350.         mov     al,02h          ; can be changed by setmask
  351.         out     dx,al
  352.         mov     dx,3c5h
  353.         mov     al,0fh
  354.         out     dx,al
  355.  
  356.         mov     dx,3ceh         ; change ENABLE SET/RESET register
  357.         mov     al,01h          ; to use SET/RESET feature
  358.         out     dx,al
  359.         mov     dx,3cfh
  360.         mov     al,0fh
  361.         out     dx,al
  362.         pop     ax
  363.         pop     dx
  364.         ret
  365. pEnd _zsetup
  366.  
  367. ; ZLINE  :  SUBROUTINE TO DRAW LINE ON EGA BOARD
  368. ;this version has microsoft c calling convention
  369. ;      zline(ix0,iy0,ix1,iy1,icolor)
  370. pBegin _zline 
  371.         push    bp
  372.         mov     bp,sp
  373.         mov     cx,word ptr [bp+argbase+6]      ;cx has first y
  374.         cmp     cx,word ptr [bp+argbase+10]     ;compare with last y
  375.         jne     nhoriz
  376.         jmp     far ptr __horiz_
  377. nhoriz:
  378.         sub     sp,6
  379.         push    di
  380.         push    si 
  381.         mov     dx,3ceh      ;set up color register
  382.         mov     al,00h
  383.         out     dx,al
  384.         mov     dx,3cfh
  385.         mov     ax,word ptr [bp+argbase+12]     ;this is color
  386.         out     dx,al
  387.  
  388.         mov     dx,word ptr [bp+argbase+10]     ;dx has last y
  389.         mov     ax,word ptr [bp+argbase+8]
  390.         mov     di,ax                           ;di has last x
  391.         mov     bx,word ptr [bp+argbase+4]      ;bx has first x 
  392.         mov     ax,di
  393.         sub     ax,bx           
  394.         jge     store_x
  395.         mov     bx,di           
  396.         mov     di,dx           ;make sure line goes from lower to higher x
  397.         mov     dx,cx
  398.         mov     cx,di
  399.         neg     ax
  400. store_x: 
  401.         mov     word ptr[bp+argbase+6],ax
  402.         mov     word ptr[bp+argbase+4],bx        ;store new first point
  403.         mov     word ptr[bp+argbase+8],cx
  404.         sub     dx,cx
  405.         mov     word ptr [bp-2],80 ;put increment for pointer in screen buffer
  406.         jge     store_y         ;into temporary
  407.         neg     word ptr [bp-2]
  408.         neg     dx
  409. store_y:
  410.         mov     word ptr[bp+argbase+10],dx
  411. ;initialize values
  412.         mov     dx,3ceh         ;prepare register for changing pixel
  413.         mov     al,08h
  414.         out     dx,al
  415.         mov     ax,drawseg       ;load start of screen buffer in es  
  416.         mov     es,ax
  417. ;calculate address in screen buffer of first point
  418.         mov     ax,word ptr[bp+argbase+4]
  419.         mov     dx,ax
  420.         and     dx,7
  421.         mov     cl,3
  422.         sar     ax,cl
  423.         mov     si,ax      ;load initial x byte offset into si
  424.         lea     bx,btab
  425.         add     bx,dx      ;[bx] has a 1 in bit of first point 
  426.         mov     ax,word ptr[bp+argbase+8]   ; mul by first y
  427.         mov     dx,ax
  428.         shl     dx,1
  429.         shl     dx,1
  430.         add     ax,dx
  431.         mov     cl,4
  432.         shl     ax,cl
  433.         mov     dx,ax
  434.         mov     al,[bx]         ;al has pointer in byte for exact bits
  435.         mov     bx,dx           ;bx has address in screen buffer
  436.         mov     cx,0            ;cx is  point counter
  437. ;figure out if slope is greater or less than 1
  438.         mov     dx,word ptr[bp+argbase+6]
  439.         cmp     dx,word ptr[bp+argbase+10]
  440.         jl      csteep
  441.         call    slant
  442.         jmp     finish
  443. csteep:
  444.         call    steep
  445. finish:
  446.         pop     si
  447.         pop     di
  448.         mov     sp,bp
  449.         pop     bp
  450.         ret        
  451.  
  452. pEnd _zline 
  453. slant    proc    near
  454.           ;slope<1
  455.         cmp     si,80      ;test for line off screen to right
  456.         jge     quit1
  457.         mov     di,word ptr[bp+argbase+10]
  458.         mov     dx,word ptr[bp+argbase+6]
  459.         mov     word ptr [bp-4],dx
  460.         shr     dx,1
  461.         mov     word ptr [bp-6],dx
  462.         mov     dx,3cfh
  463. newdot:
  464.         cmp     si,0       ;test for line off screen to left
  465.         jl      q1
  466.         out     dx,al                   ;output bit in byte to mask register
  467.         inc     byte ptr es:[bx][si]    ;insert byte in buffer ... note that 
  468.                         ;the inc instruction doesn't actually do the
  469.                         ;work -- it;s done by the EGA's wierd hardware
  470. q1:     ror     al,1            ;rotate bit in byte
  471.         jnc     nc1             ;test for shifting to next byte in screen 
  472.         inc     si              ;memory
  473.         cmp     si,80     
  474.         je      quit1
  475. nc1:    add     cx,di           ;this is the actual line algorithm
  476.         cmp     cx,word ptr [bp-6]  ;standard algorithm registerized for speed
  477.         jle     dcount
  478.         sub     cx,word ptr[bp+argbase+6]
  479.         add     bx,word ptr [bp-2]
  480. dcount: dec     word ptr [bp-4]
  481.         jge     newdot
  482. quit1:  ret
  483.  
  484.  
  485. slant    endp
  486. steep   proc    near
  487.         ;slope>1     see comments in "slant"
  488.         cmp     si,80
  489.         jge     quit2
  490.         mov     di,word ptr[bp+argbase+6]
  491.         or      di,di
  492.         je      vertical
  493.         mov     dx,word ptr[bp+argbase+10]
  494.         mov     word ptr[bp-4],dx
  495.         shr     dx,1
  496.         mov     word ptr[bp-6],dx
  497.         mov     dx,3cfh
  498.         out     dx,al
  499. newdot2:
  500.         cmp     si,0
  501.         jl      c3
  502.         inc     byte ptr es:[bx][si]
  503. c3:     add     bx,word ptr [bp-2]
  504.         add     cx,di
  505.         cmp     cx,word ptr[bp-6]
  506.         jle     dcount2
  507.         sub     cx,word ptr[bp+argbase+10]
  508.         ror     al,1
  509.         out     dx,al
  510.         jnc     dcount2
  511.         inc     si
  512.         cmp     si,80
  513.         je      quit2   
  514. dcount2:
  515.         dec     word ptr[bp-4]
  516.         jge     newdot2
  517. quit2:  ret
  518. vertical:
  519.         add     bx,si
  520.         cmp     si,0               ;special case for vertical lines
  521.         jl      quit2              ;which doesn't need fancy algorithm
  522.         mov     cx,word ptr[bp+argbase+10]
  523.         mov     dx,3cfh
  524.         out     dx,al
  525. loopy2: 
  526.         inc     byte ptr es:[bx]
  527. c3v:
  528.         add     bx,word ptr [bp-2]
  529.         dec     cx
  530.         jge     loopy2
  531.         ret
  532.  
  533.  
  534. steep   endp
  535.  
  536. ; setpal.asm routine to be called from c to set palete m to n
  537. ; setpal(m,n)  m=0 to 15, n 0 to 63
  538.  
  539.  
  540. pBegin  _setpal
  541.         push    bp  
  542.         mov     bp, sp
  543.         push    di
  544.         push    si
  545. ; Get arguments into registers
  546.         mov     bl, byte ptr [bp+argbase+4] 
  547.         mov     bh, byte ptr [bp+argbase+6] 
  548.         mov     al,0
  549.         mov     ah,16
  550.  
  551. ; Call BIOS
  552.         int     10H
  553.         pop     si
  554.         pop     di
  555.         pop     bp 
  556.         ret     
  557. pEnd _setpal
  558.  
  559. ;char colorlist[17]
  560. ;setpals(colorlist) causes all 16 palete registers and the border color   
  561. ;colorlist[16] to be set in one call. This uses the BIOS. 
  562.  
  563. ;pBegin _setpals
  564. ;        push    bp
  565. ;        mov     bp, sp
  566. ;ifdef NEARDATA
  567. ;        mov     dx, word ptr [bp+argbase+4] 
  568. ;        mov     ax,ds
  569. ;        mov     es,ax
  570. ;endif
  571. ;ifdef FARDATA
  572. ;        les     dx,[bp+argbase+4]
  573. ;endif
  574. ;        mov    al,2
  575. ;        mov    ah,16;
  576.  
  577. ; Call BIOS
  578. ;        int     10H
  579. ;        pop     bp   
  580. ;        ret
  581. ;pEnd    _setpals
  582.  
  583.  
  584. ;char colorlist[17]
  585. ;setpals(colorlist) causes all 16 palete registers and the border color   
  586. ;colorlist[16] to be set in one call. This is MUCH faster than the one
  587. ;using the IBM BIOS
  588.  
  589. pBegin _setpals
  590.         push    bp
  591.         mov     bp, sp
  592.         push    si
  593. ifdef NEARDATA
  594.         mov     bx, word ptr [bp+argbase+4] 
  595.         mov     ax,ds
  596.         mov     es,ax
  597. endif
  598. ifdef FARDATA
  599.         les     bx,[bp+argbase+4]
  600. endif
  601.         mov     dx,03dah
  602. spnvr:  in      al,dx ;wait for NOT vertical retrace
  603.         test    al,8
  604.         jnz     spnvr
  605. spvr:   in      al,dx ;wait for vertical retrace
  606.         test    al,8
  607.         jz      spvr
  608.         xor     si,si
  609.         mov     dx,03c0h
  610. sp2loop:
  611.         mov     ax,si
  612.         out     dx,al
  613.         mov     al,byte ptr es:[bx][si]
  614.         out     dx,al
  615.         inc     si
  616.         cmp     si,16
  617.         jne     sp2loop
  618.         mov     al,011h
  619.         out     dx,al
  620.         mov     al,byte ptr es:[bx][si]
  621.         out     dx,al
  622.         mov     al,020h
  623.         out     dx,al
  624.  
  625.         pop     si
  626.         pop     bp   
  627.         ret
  628. pEnd    _setpals
  629.  
  630.  
  631.  
  632. ;this routine resets the system to use ordinary bios or dos screen writes
  633. ;it has no parameters and may be called from any language
  634. pBegin _curmod
  635.         push    dx
  636.         push    ax
  637.  
  638.         mov     dx,3ceh                 ; change ENABLE SET/RESET register
  639.         mov     al,01h                  ; to disable SET/RESET feature
  640.         out     dx,al
  641.         mov     dx,3cfh
  642.         mov     al,00h
  643.         out     dx,al
  644.         mov     dx,3ceh                 ;set bit mask to enable all
  645.         mov     al,08h                  ;8 bits in a byte
  646.         out     dx,al
  647.         mov     dx,3cfh
  648.         mov     al,0ffh
  649.         out     dx,al
  650.  
  651.  
  652.         pop     ax
  653.         pop     dx
  654.         ret
  655. pEnd _curmod
  656.  
  657. ;         zpoint.asm plot point at xt,yt in color zpcol
  658. pBegin _zpoint
  659.         push    bp
  660.         mov     bp,sp
  661.  
  662.         mov     dx,3ceh                 ; change SET/RESET register
  663.         mov     al,00h                  ; to contain the color to write.
  664.         out     dx,al
  665.         mov     dx,3cfh
  666.         mov     al,byte ptr [bp+argbase+8]      ; <-- THIS IS THE COLOR.
  667.         out     dx,al
  668.         mov     ax,drawseg               ; segment of display buffer
  669.         mov     es,ax
  670.         mov     cx,word ptr [bp+argbase+4]      ; this is x value
  671.         mov     bx,cx
  672.         and     bx,7
  673.         sar     cx,1                     ;split x into bit and byte
  674.         sar     cx,1
  675.         sar     cx,1
  676.         or      cx,cx
  677.         jl      ptquit
  678.         cmp     cx,79
  679.         jg      ptquit
  680.  
  681.         mov     dx,3ceh 
  682.         mov     al,08h
  683.         out     dx,al                   ;set bit mask register
  684.         mov     dx,3cfh
  685.         mov     al,byte ptr btab[bx]
  686.         out     dx,al
  687.  
  688.         mov     bx,cx
  689.         mov     ax,word ptr [bp+argbase+6]         ;this is y value
  690.         mov     dx,ax
  691.         shl     dx,1
  692.         shl     dx,1
  693.         add     ax,dx
  694.         mov     cl,4
  695.         shl     ax,cl
  696.         add     bx,ax      
  697.         inc     byte ptr es:[bx]
  698.  
  699. ptquit: pop     bp
  700.         ret    
  701.  
  702. pEnd _zpoint
  703.  
  704.  
  705. pBegin _setmask 
  706. ;  set mask register     setmask(mask)
  707.  
  708.         push    bp
  709.         mov     bp,sp
  710.  
  711.         mov     cx,word ptr [bp+argbase+4]
  712.         mov     dx,03c4h
  713.         mov     al,2
  714.         out     dx,al
  715.         mov     dx,03c5h
  716.         mov     al,cl
  717.         out     dx,al
  718.         pop     bp
  719.         ret    
  720.  
  721.  
  722. pEnd _setmask
  723.  
  724.  
  725. ;_e_start start up ellipse plotter
  726. ; e_start(xleft,xright,y,color)
  727. pBegin _e_start 
  728.         push    bp
  729.         mov     bp,sp
  730.  
  731.         mov     dx,3ceh                ; change SET/RESET register
  732.         mov     al,00h                 ; to contain the color to write.
  733.         out     dx,al
  734.         mov     dx,3cfh
  735.         mov     al,byte ptr [bp+argbase+10]     ; <-- THIS IS THE COLOR.
  736.         out     dx,al
  737.         mov     ax,drawseg               ; segment of display buffer
  738.         mov     es,ax
  739.  
  740.         mov     cx,word ptr [bp+argbase+4]      ; this is left x value
  741.         mov     bx,cx
  742.         and     bx,7
  743.         sar     cx,1
  744.         sar     cx,1
  745.         sar     cx,1
  746.         mov     dx,3ceh           
  747.         mov     al,08h
  748.         out     dx,al
  749.         mov     dx,3cfh
  750.         mov     al,byte ptr btab[bx]
  751.         mov     leftbit,al
  752.  
  753.         out     dx,al
  754.  
  755.         mov     ax,word PTR [bp+argbase+8]  
  756.         mov     bx,ax
  757.         shl     ax,1
  758.         shl     ax,1
  759.         add     bx,ax
  760.         shl     bx,1
  761.         shl     bx,1
  762.         shl     bx,1
  763.         shl     bx,1
  764.         mov     ysave,bx
  765.         mov     leftx,cx
  766.         add     bx,cx
  767.         mov     leftbot,bx
  768.         mov     lefttop,bx
  769.         cmp     cx,80
  770.         jae     s1
  771.         inc     byte ptr es:[bx]
  772.  
  773. s1:     mov     cx,word ptr [bp+argbase+6]      ; this is right x value
  774.         mov     bx,cx
  775.         and     bx,7
  776.         sar     cx,1
  777.         sar     cx,1
  778.         sar     cx,1
  779.  
  780.         mov     dx,3cfh
  781.         mov     al,byte ptr btab[bx]
  782.         mov     rightbit,al
  783.         out     dx,al
  784.         mov     bx,ysave
  785.         mov     rightx,cx
  786.         add     bx,cx
  787.         mov     rightbot,bx
  788.         mov     righttop,bx
  789.         cmp     cx,80
  790.         jae     s2
  791.         inc     byte ptr es:[bx]
  792.  
  793. s2:     pop     bp
  794.         ret    
  795.  
  796. pEnd _e_start
  797.  
  798.  
  799. pBegin _e_xd
  800.         mov     ax,drawseg        
  801.         mov     es,ax
  802.         rol     rightbit,1
  803.         mov     al,rightbit
  804.         jae     l1  
  805.         dec     rightx      
  806.         dec     rightbot
  807.         dec     righttop        
  808. l1:     mov     dx,3cfh
  809.         out     dx,al
  810.         cmp     rightx,80
  811.         jae     s3
  812.         mov     bx,righttop
  813.         inc     byte ptr es:[bx]
  814.         mov     bx,rightbot
  815.         inc     byte ptr es:[bx]        
  816.  
  817. s3:     
  818.         ror     leftbit,1
  819.         mov     al,leftbit
  820.         jae     l2        
  821.         inc     leftx
  822.         inc     lefttop        
  823.         inc     leftbot
  824. l2:     out     dx,al
  825.         cmp     leftx,80
  826.         jae     s4
  827.         mov     bx,lefttop
  828.         inc     byte ptr es:[bx]
  829.         mov     bx,leftbot
  830.         inc     byte ptr es:[bx]        
  831. s4:     ret
  832. pEnd _e_xd 
  833.  
  834. pBegin _e_xdyu
  835.         mov     ax,drawseg           
  836.         mov     es,ax
  837.         rol     rightbit,1
  838.         mov     al,rightbit
  839.         jae     l3        
  840.         dec     rightx
  841.         dec     rightbot
  842.         dec     righttop        
  843. l3:     mov     dx,3cfh
  844.         out     dx,al
  845.         mov     cx,80
  846.         add     righttop,cx
  847.         sub     rightbot,cx
  848.         cmp     rightx,cx
  849.         jae     s5
  850.         mov     bx,righttop
  851.         inc     byte ptr es:[bx]
  852.         mov     bx,rightbot
  853.         inc     byte ptr es:[bx]        
  854.  
  855. s5:     
  856.         ror     leftbit,1
  857.         mov     al,leftbit
  858.         jae     l4        
  859.         inc     leftx
  860.         inc     lefttop        
  861.         inc     leftbot
  862. l4:     out     dx,al
  863.         add     lefttop,cx
  864.         sub     leftbot,cx
  865.         cmp     leftx,cx
  866.         jae     s6
  867.         mov     bx,lefttop
  868.         inc     byte ptr es:[bx]
  869.         mov     bx,leftbot
  870.         inc     byte ptr es:[bx]        
  871.  
  872.  
  873. s6:     ret
  874. pEnd _e_xdyu 
  875.  
  876. pBegin _e_yu
  877.         mov     ax,drawseg           
  878.         mov     es,ax
  879.         mov     al,leftbit
  880.         mov     dx,3cfh
  881.         out     dx,al
  882.         mov     cx,80
  883.         add     lefttop,cx
  884.         sub     leftbot,cx
  885.         cmp     leftx,cx
  886.         jae     s7
  887.         mov     bx,lefttop
  888.         inc     byte ptr es:[bx]
  889.         mov     bx,leftbot
  890.         inc     byte ptr es:[bx]        
  891. s7:     mov     al,rightbit
  892.         out     dx,al
  893.         add     righttop,cx
  894.         sub     rightbot,cx
  895.         cmp     rightx,cx
  896.         jae     s8
  897.         mov     bx,righttop
  898.         inc     byte ptr es:[bx]
  899.         mov     bx,rightbot
  900.         inc     byte ptr es:[bx]        
  901.  
  902. s8:     ret
  903. pEnd _e_yu 
  904.  
  905. pBegin _rectfill
  906. ;  rectfill(ix0,iy0,ix1,iy1,icol) plots a rectangle in 
  907. ; color icol.   all are integers
  908.         push    bp
  909.         mov     bp,sp
  910.         mov     bx,word PTR [bp+argbase+10]     ;bx has y1
  911.         cmp     bx,word ptr [bp+argbase+6]      ;compare with y0
  912.         jne     notflat
  913.         jmp     far ptr __horiz_
  914. notflat:
  915.         push    di
  916.         push    si
  917.         nop
  918.  
  919.         mov     dx,3ceh                 ; change SET/RESET register
  920.         mov     al,00h                  ; to contain the color to write.
  921.         out     dx,al
  922.         mov     dx,3cfh
  923.         mov     al,byte ptr [bp+argbase+12]     ; <-- THIS IS THE COLOR.
  924.         out     dx,al
  925.         mov     cx,word PTR [bp+argbase+4]      ;cx has x0
  926.         mov     dx,word PTR [bp+argbase+6]      ;dx has y0
  927.         mov     ax,word PTR [bp+argbase+8]      ;ax has x1
  928.  
  929.         cmp     ax,cx           ;make first point leftmost one
  930.         jge     test2
  931.         mov     si,ax
  932.         mov     ax,cx
  933.         mov     cx,si
  934. test2:  or      ax,ax
  935.         jge     test3
  936.         jmp     rfinish
  937. test3:  cmp     cx,640          ;clip to screen limits
  938.         jl      test4
  939.         jmp     rfinish
  940. test4:  cmp     cx,0
  941.         jge     test5
  942.         sub     cx,cx
  943. test5:  cmp     ax,640
  944.         jl      test6
  945.         mov     ax,639
  946. test6:
  947.         cmp     bx,dx
  948.         jge     test7
  949.         mov     si,bx
  950.         mov     bx,dx
  951.         mov     dx,si
  952. test7:  or      bx,bx
  953.         jge     test8
  954.         jmp     rfinish
  955. test8:  cmp     dx,maxline
  956.         jl      test9
  957.         jmp     rfinish
  958. test9:  cmp     dx,0
  959.         jge     testa
  960.         sub     dx,dx
  961. testa:  cmp     bx,maxline
  962.         jl      testb
  963.         mov     bx,maxline
  964.         dec     bx
  965. testb:  
  966.  
  967.         mov     xx0,cx
  968.         mov     yy0,dx
  969.         mov     xx1,ax
  970.         mov     yy1,bx
  971.  
  972.         mov     ax,cx                   ;calculate bte position in graphics
  973.         mov     dx,ax                   ;memory (x value)
  974.         and     dx,7
  975.         mov     cl,3
  976.         sar     ax,cl 
  977.         mov     xc10,ax                 ;byte value for leftmost point
  978.         mov     xc20,dx                 ;offset in byte
  979.         mov     di,ax
  980.         mov     ax,xx1
  981.         mov     dx,ax
  982.         and     dx,7
  983.         mov     cl,3
  984.         sar     ax,cl 
  985.         mov     xc11,ax                 ;byte value for rightmost byte
  986.         mov     xc21,dx                 ;offset in byte
  987.         sub     ax,di
  988.         mov     del_x,ax       
  989.         mov     ax,drawseg       
  990.         mov     es,ax
  991.         mov     dx,3ceh
  992.         mov     al,08h
  993.         out     dx,al
  994.  
  995.         mov     ax,yy0           ; compute location of first byte to change
  996.         mov     dx,ax            ; (y value) 
  997.         shl     dx,1
  998.         shl     dx,1
  999.         add     ax,dx            ; mul by 80
  1000.         mov     cl,4
  1001.         shl     ax,cl
  1002.         add     ax,xc10
  1003.         mov     lowyb,ax
  1004.  
  1005.         mov     ax,yy1
  1006.         sub     ax,yy0
  1007.         inc     ax
  1008.         mov     del_y,ax        ;number of y lines
  1009.         mov     bx,xc20
  1010.         mov     dl,left[bx]
  1011.         or      del_x,0
  1012.         jnz     leftcol         ;if only one byte column, may need to mask
  1013.         mov     bx,xc21         ;right hand bits
  1014.         and     dl,right[bx]
  1015. leftcol:
  1016.         mov     al,dl
  1017.         mov     dx,3cfh        ;draw the entire left column of bytes
  1018.         out     dx,al          ;set bit mask register     
  1019.         mov     bx,lowyb
  1020.         mov     cx,del_y          
  1021.         mov     ax,80
  1022. loopd:  inc     byte ptr es:[bx]
  1023.         add     bx,ax
  1024.         loop    loopd          ;end of left column drawer
  1025.         cmp     del_x,1
  1026.         jl      rfinish
  1027.         jz      lastcol 
  1028.         mov     al,255
  1029.         out     dx,al          ;set mask register to all eight bits
  1030.         mov     bx,del_y
  1031.         mov     ax,lowyb
  1032.         inc     ax
  1033.         mov     si,del_x
  1034.         dec     si
  1035. loope:  mov     cx,si         ;draw the middle columns
  1036.         mov     di,ax
  1037.         rep     stosb
  1038.         add     ax,80
  1039.         dec     bx
  1040.         jnz     loope
  1041.  
  1042. lastcol:
  1043.         mov     bx,xc21      ;draw the right column
  1044.         mov     al,right[bx]
  1045.         out     dx,al          
  1046.         mov     bx,lowyb
  1047.         add     bx,del_x          
  1048.         mov     cx,del_y
  1049.         mov     ax,80
  1050. loopf:  inc     byte ptr es:[bx]
  1051.         add     bx,ax
  1052.         loop    loopf 
  1053.  
  1054. rfinish:
  1055.         pop     si
  1056.         pop     di
  1057.         pop     bp
  1058.         ret
  1059.  
  1060.  
  1061. pEnd _rectfill
  1062.  
  1063. pBegin __horiz_             ;stripped down version of rectfill
  1064.         push    di
  1065.         push    si
  1066.  
  1067.         mov     dx,word PTR [bp+argbase+6]      ;dx has y0
  1068.         cmp     dx,maxline      ;test for off screen verticallly
  1069.         jae     rfinish
  1070.         mov     dx,3ceh                 ; change SET/RESET register
  1071.         mov     al,00h                  ; to contain the color to write.
  1072.         out     dx,al
  1073.         mov     dx,3cfh
  1074.         mov     al,byte ptr [bp+argbase+12]     ; <-- THIS IS THE COLOR.
  1075.         out     dx,al
  1076.         mov     cx,word PTR [bp+argbase+4]      ;cx has x0
  1077.         mov     bx,word PTR [bp+argbase+8]      ;bx has x1
  1078.  
  1079.         cmp     bx,cx
  1080.         jge     test2h
  1081.         mov     si,bx
  1082.         mov     bx,cx
  1083.         mov     cx,si
  1084. test2h: or      bx,bx         ;clip to screen
  1085.         jge     test3h
  1086.         jmp     hfinish
  1087. test3h: cmp     cx,640
  1088.         jl      test4h
  1089.         jmp     hfinish
  1090. test4h: cmp     cx,0
  1091.         jge     test5h
  1092.         sub     cx,cx
  1093. test5h: cmp     bx,640
  1094.         jl      test6h
  1095.         mov     bx,639
  1096. test6h:
  1097.  
  1098.         xor     dx,dx 
  1099.         mov     ax,cx
  1100.         div     ate
  1101.         mov     xc10,ax                 ;byte value
  1102.         mov     xc20,dx                 ;offset in byte
  1103.         mov     cx,ax
  1104.         xor     dx,dx      
  1105.         mov     ax,bx
  1106.         div     ate
  1107.         mov     xc11,ax
  1108.         mov     xc21,dx
  1109.         sub     ax,cx
  1110.         mov     cx,ax       
  1111.         mov     ax,drawseg       
  1112.         mov     es,ax
  1113.         mov     dx,3ceh
  1114.         mov     al,08h
  1115.         out     dx,al
  1116.  
  1117.                             ; compute location of byte to change
  1118.         mov     ax,word ptr [bp+argbase+6]
  1119.         mov     dx,ax
  1120.         shl     dx,1
  1121.         shl     dx,1
  1122.         add     ax,dx
  1123.         shl     ax,1
  1124.         shl     ax,1
  1125.         shl     ax,1
  1126.         shl     ax,1
  1127.         add     ax,xc10
  1128.         mov     di,ax
  1129.  
  1130.         mov     bx,xc20
  1131.         mov     al,left[bx]
  1132.         or      cx,cx
  1133.         jnz     leftcoh         
  1134.         mov     bx,xc21          
  1135.         and     al,right[bx]
  1136. leftcoh:
  1137.         mov     dx,3cfh
  1138.         out     dx,al     
  1139.         inc     byte ptr es:[di]
  1140.         inc     di
  1141.         cmp     cx,1
  1142.         jl      hfinish
  1143.         jz      lastcoh 
  1144.         mov     al,255
  1145.         out     dx,al
  1146.         dec     cx
  1147.         rep     stosb
  1148.  
  1149. lastcoh:
  1150.         mov     bx,xc21
  1151.         mov     al,right[bx]
  1152.         out     dx,al          
  1153.         inc     byte ptr es:[di]
  1154.  
  1155. hfinish:
  1156.         pop     si
  1157.         pop     di
  1158.         pop     bp
  1159.         ret
  1160.  
  1161. pEnd __horiz_
  1162. ;setdraw(i)  sets drawing buffer to i  i = 0 or 1
  1163.  
  1164. pBegin _setdraw       
  1165.  
  1166.         push    bp
  1167.         mov     bp,sp
  1168.         mov     cx, word ptr [bp+argbase+4]     
  1169.         mov     ax,0a000h
  1170. loopds:
  1171.         cmp     cx,0
  1172.         jz      ds1
  1173.         add     ax,0800h
  1174.         cmp     maxline,480
  1175.         jnz     ds1
  1176.         add     ax,0800h
  1177. ds1:    mov     drawseg,ax
  1178.         pop     bp              
  1179.         ret
  1180.  
  1181. pEnd _setdraw
  1182.  
  1183. ;setdisp(i) sets the displayed segment to i = 0 or 1 
  1184. pBegin _setdisp       
  1185.  
  1186.         push    bp
  1187.         mov     bp,sp
  1188.         mov     ax, word ptr [bp+argbase+4]     
  1189.  
  1190.         mov     ah,5
  1191.         int     010h
  1192.         pop     bp              
  1193.         ret
  1194.  
  1195. pEnd _setdisp
  1196.  
  1197. endcs _egagraf
  1198.       end
  1199.  
  1200. **************end file EGAGRA.ASM**************
  1201. **************begin file MACROS.AH*************
  1202.  
  1203.   SMALL equ 1
  1204.  
  1205. ;
  1206. ; break down modules
  1207. ;
  1208. ifdef SMALL
  1209.   NEARDATA equ 1
  1210.   NEARCODE equ 1
  1211. endif
  1212.  
  1213. ifdef COMPACT
  1214.    FARDATA equ 1
  1215.   NEARCODE equ 1
  1216. endif
  1217.  
  1218. ifdef MEDIUM
  1219.   NEARDATA equ 1
  1220.    FARCODE equ 1
  1221. endif
  1222.  
  1223. ifdef LARGE
  1224.    FARDATA equ 1
  1225.    FARCODE equ 1
  1226. endif
  1227.  
  1228. ;
  1229. ; define model-dependent parameters
  1230. ;
  1231.  
  1232. ifdef NEARCODE
  1233.   argbase equ 0
  1234. endif
  1235.  
  1236. ifdef FARCODE
  1237.   argbase equ 2
  1238. endif
  1239.  
  1240. ;
  1241. ; macros
  1242. ;
  1243.  
  1244. cseg    macro moduleName
  1245.     ifdef FARCODE
  1246.       moduleName&_TEXT segment byte public 'CODE'
  1247.       assume cs: moduleName&_TEXT
  1248.     else
  1249.       _TEXT segment byte public 'CODE'
  1250.       assume cs: _TEXT
  1251.     endif
  1252.     endm
  1253.  
  1254. endcs    macro moduleName
  1255.     ifdef FARCODE
  1256.       moduleName&_TEXT ends
  1257.     else
  1258.       _TEXT ends
  1259.     endif
  1260.     endm
  1261.  
  1262. pBegin    macro pName
  1263.     ifdef FARCODE
  1264.       pName proc far
  1265.     else
  1266.       pName proc near
  1267.     endif
  1268.         public pName
  1269.     endm
  1270.  
  1271. pEnd    macro pName
  1272.     pName endp
  1273.     endm
  1274.  
  1275.  
  1276. ****************end file MACROS.AH*************
  1277. ****************begin file EGAFORT.H***********
  1278. $notruncate
  1279.       interface to subroutine slettr[c](ix,iy,ichr,icol)
  1280.       integer*2 ix,iy,ichr,icol
  1281.       end
  1282.  
  1283.       interface to subroutine symbol[c]
  1284.      1            (ix,iy,height,icol,symb[reference])
  1285.       integer*2 ix,iy,height,icol
  1286.       integer*1 symb(8)
  1287.       end
  1288.  
  1289.       interface to subroutine llettr[c](ix,iy,ichr,icol)
  1290.       integer*2 ix,iy,ichr,icol
  1291.       end
  1292.  
  1293.       interface to subroutine setmod[c](n)
  1294.       integer*2 n
  1295.       end
  1296.  
  1297.       interface to subroutine setdraw[c](n)
  1298.       integer*2 n
  1299.       end
  1300.  
  1301.       interface to subroutine setdisp[c](n)
  1302.       integer*2 n
  1303.       end
  1304.  
  1305.       interface to subroutine zsetup[c]()
  1306.       end
  1307.  
  1308.  
  1309.       interface to subroutine zline[c](ix0, iy0, ix1, iy1, icol)
  1310.       integer*2 ix0, iy0, ix1, iy1, icol
  1311.       end
  1312.  
  1313.       interface to subroutine clipline[c](ix0, iy0, ix1, iy1,
  1314.      1    icol)
  1315.       integer*2 ix0, iy0, ix1, iy1, icol
  1316.       end
  1317.  
  1318.       interface to subroutine setpal[c](ipal, icol)
  1319.       integer*2 ipal, icol
  1320.       end
  1321.  
  1322.       interface to subroutine setpals[c](palete[reference])
  1323.       integer*1 palete(17)
  1324.       end
  1325.  
  1326.       interface to subroutine curmod[c]()
  1327.       end
  1328.  
  1329.       interface to subroutine zpoint[c](ix, iy, icol)
  1330.       integer*2 ix, iy, icol
  1331.       end
  1332.  
  1333.       interface to subroutine setmask[c](mask)
  1334.       integer*2 mask
  1335.       end
  1336.  
  1337.       interface to subroutine rectfill[c](ix0, iy0, ix1, iy1, icol)
  1338.       integer*2 ix0, iy0, ix1, iy1, icol
  1339.       end
  1340.  
  1341.       interface to subroutine ellipse[c](ix0, iy0, irx, iry, icol)
  1342.       integer*2 ix0, iy0, irx, iry, icol
  1343.       end
  1344.  
  1345.       interface to subroutine fillelip[c](ix0, iy0, irx, iry, icol)
  1346.       integer*2 ix0, iy0, irx, iry, icol
  1347.       end
  1348.  
  1349. *************end file EGAFORT.H*****************
  1350.