home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c222 / 1.ddi / SOURCE / IBMLIB / GR_DRIVE.ASM < prev    next >
Encoding:
Assembly Source File  |  1991-01-17  |  10.2 KB  |  463 lines

  1. ;
  2. ;  gr_drive.asm
  3. ;
  4. ;  Purpose: Graphics primitives.
  5. ;
  6. ;  Blackstar C Function Libarary
  7. ;  (c) Copyright 1985,1989 Sterling Castle Software
  8. ;
  9.  
  10.     include model
  11.     include blackstr.mac
  12.  
  13.  
  14.     dseg    'DATA'
  15.  
  16.     ;--------------------------
  17.     ; graphics variables
  18.     ;--------------------------
  19.     wrdot    equ    12
  20.     rddot    equ    13
  21.     video    equ    010h    ;video interrupt number
  22.  
  23.     gbuf    db      255 dup (0)
  24.  
  25.     ifdef   asm_386
  26.     ptptr   dd      $
  27.     dele    dd      ?
  28.     delp    dd      ?
  29.     dels    dd      ?
  30.     delsx   dd      ?       ;deltas for straight and diagonal
  31.     delsy   dd      ?
  32.     delse   dd      ?       ;error delta
  33.     deldx   dd      ?       ;diagonal deltas
  34.     deldy   dd      ?
  35.     delde   dd      ?
  36.     else
  37.     ptptr   dw      $
  38.     dele    dw      ?
  39.     delp    dw      ?
  40.     dels    dw      ?
  41.     delsx   dw      ?       ;deltas for straight and diagonal
  42.     delsy   dw      ?
  43.     delse   dw      ?       ;error delta
  44.     deldx   dw      ?       ;diagonal deltas
  45.     deldy   dw      ?
  46.     delde   dw      ?
  47.     endif
  48.  
  49.     public    _grx_,_gry_,_grcols_,_grrows_,_grmode_
  50.     public    _grbcolr_,_grbcol_,_grfcol_,_grfcolr_
  51.     public  _grxorf_,_grfpal_,_grbpal_
  52.     public _gr_minx_,_gr_miny_,_gr_maxx_,_gr_maxy_
  53.     public    _gr_seg_,_gr_off_,_gr_buf_,_gr_bytes_
  54.  
  55.     ;--------------
  56.     ; ints
  57.     ;--------------
  58.     ifdef   asm_386
  59.     alias gr_minx_    DWORD
  60.     _gr_minx_       dd    0    ;minimum x
  61.     alias gr_maxx_  DWORD
  62.     _gr_maxx_       dd    0    ;max x
  63.     alias gr_miny_    DWORD
  64.     _gr_miny_       dd    0    ;minimum y
  65.     alias gr_maxy_  DWORD
  66.     _gr_maxy_       dd    0    ;max y
  67.     alias gr_bytes_ DWORD
  68.     _gr_bytes_    dd    16384    ;# bytes in buffer
  69.     alias grx_    DWORD
  70.     _grx_        dd    0    ;graphics cursor y position
  71.     alias gry_    DWORD
  72.     _gry_        dd    0    ;graphics cursor y position
  73.     alias grrows_    DWORD
  74.     _grrows_    dd    0    ;maximum value in x position
  75.     alias grcols_    DWORD
  76.     _grcols_    dd    0    ;maximum value in y position
  77.     alias grmode_    DWORD
  78.     _grmode_    dd    0    ;graphics mode
  79.     else
  80.     alias gr_minx_    WORD
  81.     _gr_minx_       dw    0    ;minimum x
  82.     alias gr_maxx_  WORD
  83.     _gr_maxx_       dw    0    ;max x
  84.     alias gr_miny_    WORD
  85.     _gr_miny_       dw    0    ;minimum y
  86.     alias gr_maxy_  WORD
  87.     _gr_maxy_       dw    0    ;max y
  88.     alias gr_bytes_ WORD
  89.     _gr_bytes_    dw    16384    ;# bytes in buffer
  90.     alias grx_    WORD
  91.     _grx_        dw    0    ;graphics cursor y position
  92.     alias gry_    WORD
  93.     _gry_        dw    0    ;graphics cursor y position
  94.     alias grrows_    WORD
  95.     _grrows_    dw    0    ;maximum value in x position
  96.     alias grcols_    WORD
  97.     _grcols_    dw    0    ;maximum value in y position
  98.     alias grmode_    WORD
  99.     _grmode_    dw    0    ;graphics mode
  100.     endif
  101.  
  102.     ; Need a pointer to the display buffer for large models
  103.      ; as well as the seg and offset values for small models
  104.     ;------------------
  105.     ; char * gr_buf_
  106.     ;------------------
  107.     ifdef    asm_386    ;LARGE_DATAgenerate regen buffer address
  108.     alias gr_buf_    DWORD
  109.     alias _gr_buf_    DWORD
  110.     else
  111.     alias gr_buf_    WORD
  112.     alias _gr_buf_    WORD
  113.     endif
  114.  
  115.     ifdef    asm_386
  116.     alias gr_off_    DWORD
  117.     _gr_off_    dd    0    ;buffer offset
  118.     else
  119.     alias gr_off_    WORD
  120.     _gr_off_    dw    0    ;buffer offset
  121.     endif
  122.  
  123.     alias gr_seg_   WORD
  124.     ifdef    asm_386
  125.     _gr_seg_    dw     1ch    ;Pharlap's graphics segment
  126.     else
  127.     _gr_seg_    dw     0b800h    ;graphics segment
  128.     endif
  129.  
  130.     alias grxorf_    BYTE
  131.     _grxorf_    db    0    ;xor flag for set point
  132.     alias grbcolr_    BYTE
  133.     _grbcolr_    db    0    ;graphics background color
  134.     alias grbcol_    BYTE
  135.     _grbcol_    db    0    ;graphics background color for gr_wfill
  136.     alias grfcolr_    BYTE
  137.     _grfcolr_    db    0    ;graphics foreground color value    
  138.     alias grfcol_    BYTE
  139.     _grfcol_    db    0    ;graphics foreground color for gr_pt
  140.  
  141.     ;--------------------
  142.     ; char * grfpal_
  143.     ;--------------------
  144.     ifdef    asm386 ;LARGE_DATA
  145.     alias grfpal_    DWORD
  146.     _grfpal_    dd    0    ;foreground color palette
  147.     alias grbpal_    DWORD
  148.     _grbpal_    dd    0    ;background color palette
  149.     else
  150.     alias grfpal_    WORD
  151.     _grfpal_    dw    0    ;foreground color palette
  152.     alias grbpal_    WORD
  153.     _grbpal_    dw    0    ;background color palette
  154.     endif
  155.     enddseg
  156.  
  157.  
  158.     cseg    gr_pt__
  159.  
  160. ;-----------------
  161. ;  Macros
  162. ;-----------------
  163. ;
  164.  
  165. mwrdot  macro                   ;write a dot (ecx,edx is x,y)
  166.     mov     ah,wrdot
  167.     mov     bh,0
  168.     int     video
  169.     endm
  170.  
  171. mrddot  macro                   ;read a dot macro
  172.     mov     ah,rddot
  173.     mov     bh,0            ;do this for EGA
  174.     int     video
  175.     mov     ah,0
  176.     endm
  177.  
  178. ;-----------------
  179. ;  gr_pt_(x,y)                  set point at x,y
  180. ;------------------
  181. ;                               Useage: gr_pt_(x,y);
  182. ;
  183. ;                               int gr_pt_(int x, int y);
  184.  
  185.     public  gr_pt_
  186.  
  187. gr_pt_  proc
  188.     parm386<<x,dword>,<y,dword>>
  189.     parm86 <<x,word>,<y,word>>
  190.     prolog
  191.  
  192.     ifdef   Large_data
  193.     mov     ax,seg dgroup
  194.     mov     ds,ax
  195.     endif
  196.  
  197.     mov     al,_grfcol_     ;foreground color
  198.     or      al,_grxorf_     ;xor it?
  199.     mov     ecx,x
  200.     mov     edx,y
  201.     mwrdot                  ;do write dot command
  202.     
  203.     ifdef    asm_386
  204.     movsx    eax,ax
  205.     endif
  206.  
  207.     epilog
  208. gr_pt_ endp
  209.  
  210.  
  211. ;--------------------
  212. ;  gr_gpt_(x,y)                 get color of point at x,y
  213. ;--------------------
  214. ;                               Usage:  gr_gpt_(x,y);
  215. ;
  216. ;                               int gr_gpt_(int x, int y);
  217.  
  218.     public  gr_gpt_
  219.  
  220. gr_gpt_ proc
  221.     parm386<<xa,dword>,<ya,dword>>
  222.     parm86 <<xa,word>,<ya,word>>
  223.     prolog
  224.  
  225.     mov     ecx,xa          ;x co-ordinate
  226.     mov     edx,ya          ;y co-ordinate
  227.     mrddot                  ;read dot command
  228.  
  229.     ifdef    asm_386
  230.     movsx    eax,ax
  231.     endif
  232.  
  233.     epilog
  234. gr_gpt_ endp
  235.  
  236.  
  237. ;--------------------
  238. ;  gr_gwin_(buff)               get current graphics windo to buff
  239. ;--------------------
  240. ;                               Usage:  gr_gwin_(buff)
  241. ;
  242. ;                               int gr_gwin_(char *buff);
  243.  
  244.     public  gr_gwin_
  245.  
  246. gr_gwin_ proc
  247.     parms<<buff,ptr>>
  248.     prolog
  249.     push    es
  250.  
  251.     ifdef   Large_data
  252.     mov     ax,seg dgroup
  253.     mov     ds,ax
  254.     endif
  255.  
  256.     loadptr les,edi,buff    ;buffer addr
  257.     mov     edx,_gr_miny_
  258. grwi0:  mov     ecx,_gr_minx_   ;start at diag pt
  259.  
  260. grwi1:  mrddot                  ;read the dot
  261.     mov     es:[edi],al     ;store in buff
  262.     inc     edi
  263.     inc     ecx
  264.     cmp     ecx,_gr_maxx_   ;done a line?
  265.     jle     grwi1
  266.     inc     edx
  267.     cmp     edx,_gr_maxy_   ;done all lines?
  268.     jle     grwi0
  269.  
  270.     ifdef    asm_386
  271.     movsx    eax,ax
  272.     endif
  273.  
  274.     pop     es              ;restore es
  275.     epilog
  276. gr_gwin_ endp
  277.  
  278.  
  279. ;--------------------
  280. ;  gr_pwin_(buff)               put buff to  current graphics
  281. ;--------------------
  282. ;                               Usage:  gr_pwin_(buff)
  283. ;
  284. ;                               int gr_pwin_(char *buff);
  285.  
  286.     public  gr_pwin_
  287.  
  288. gr_pwin_ proc
  289.     parms<<buffa,ptr>>
  290.     prolog
  291.     push    es
  292.  
  293.     ifdef   Large_data
  294.     mov     ax,seg dgroup
  295.     mov     ds,ax
  296.     endif
  297.  
  298.     loadptr les,edi,buffa   ;buffer address
  299.     mov     edx,_gr_miny_
  300. grpi0:  mov     ecx,_gr_minx_   ;start at diag pt
  301.  
  302. grpi1:  mov     al,es:[edi]     ;get value for dot
  303.     mwrdot                  ;write the dot
  304.     inc     edi             ;point edi to next value to write
  305.     inc     ecx
  306.     cmp     ecx,_gr_maxx_   ;done a line?
  307.     jle     grpi1
  308.     inc     edx
  309.     cmp     edx,_gr_maxy_   ;done all lines?
  310.     jle     grpi0
  311.  
  312.     ifdef    asm_386
  313.     movsx    eax,ax
  314.     endif
  315.  
  316.     pop     es              ;restore es
  317.     epilog
  318. gr_pwin_ endp
  319.  
  320.  
  321.  
  322. ;-----------------------
  323. ;  gr_ln_(x1,y1,x2,y2)          draw a line from x1,y1 to x2,y2
  324. ;-----------------------
  325. ;                               Useage: gr_ln_(x1,y1,x2,y2)
  326. ;
  327. ;                               int gr_ln_(int x1, int y1, int x2, int y2);
  328.  
  329.     public  gr_ln_
  330.  
  331. gr_ln_ proc
  332.     parm386<<x1,dword>,<y1,dword>,<x2,dword>,<y2,dword>>
  333.     parm86<<x1,word>,<y1,word>,<x2,word>,<y2,word>>
  334.     prolog
  335.  
  336.     ifdef   Large_data
  337.     mov     ax,seg dgroup
  338.     mov     ds,ax
  339.     endif
  340.  
  341.     mov     esi,1           ;start with 1 increments
  342.     mov     edi,1
  343.     mov     edx,y2          ;find y2-y1
  344.     sub     edx,y1
  345.     jge     line1           ;skip if y2>=y1
  346.  
  347.     neg     edi             ;negative increments for y
  348.     neg     edx             ;absolute value of y2-y1
  349.  
  350. line1:  mov     deldy,edi       ;store y update for diagonal moves
  351.     mov     ecx,x2          ;find x2-x1
  352.     sub     ecx,x1
  353.     jge     line2           ;skip if x2>x1
  354.  
  355.     neg     esi             ;negative increment for x
  356.     neg     ecx             ;absolute value of x2-x1
  357.  
  358. line2:  mov     deldx,esi       ;store x update for diagonal moves
  359.     cmp     ecx,edx         ;edx or dy bigger?
  360.     jge     setdiag         ;ok
  361.  
  362.     mov     esi,0           ;kill x increment
  363.     xchg    ecx,edx         ;and use the y
  364.     jmp     line3
  365.  
  366. setdiag:mov     edi,0           ;kill y increment (will use x )
  367.  
  368. line3:  mov     dels,ecx        ;change in straight
  369.     mov     delp,edx        ;change in perpendicular
  370.     mov     delsx,esi       ;x update in straght
  371.     mov     delsy,edi       ;y update in straight
  372.  
  373.     mov     esi,x1          ;x1 to esi
  374.     mov     edi,y1          ;y1 to edi
  375.     mov     eax,delp
  376.     sal     eax,1           ;2 * delp
  377.     mov     delse,eax       ;error change if straight move
  378.     sub     eax,ecx         ;2*delp - dels
  379.     mov     ebx,eax         ;initial value
  380.     sub     eax,ecx         ;2*delp - 2*dels
  381.     mov     delde,eax       ;change if diagonal move
  382.     inc     ecx             ;adjust count
  383.  
  384. lineit: push    ebx             ;save error term
  385.     push    ecx
  386.     push    edi             ;y
  387.     push    esi             ;x
  388.  
  389.     ifdef   Large_code
  390.     push    cs
  391.     endif
  392.  
  393.     call    gr_pt_          ;set it
  394.     add     esp,2*Word_size ;remove from stack
  395.     pop     ecx
  396.     pop     ebx
  397.     cmp     ebx,0           ;straight or diagonal
  398.     jge     linedi
  399.  
  400. linest: add     esi,delsx       ;update x
  401.     add     edi,delsy       ;update y
  402.     add     ebx,delse       ;update error term
  403.     loop    lineit
  404.     jmp     line_x          ;and exit
  405.  
  406. linedi: add     esi,deldx       ;update x
  407.     add     edi,deldy       ;update y
  408.     add     ebx,delde       ;update error term
  409.     loop    lineit
  410.  
  411. line_x: 
  412.  
  413.     ifdef    asm_386
  414.     movsx    eax,ax
  415.     endif
  416.  
  417.     epilog
  418. gr_ln_ endp
  419.  
  420.  
  421.  
  422. ;-------------------------
  423. ;   gr_wfill_            fill a window
  424. ;-------------------------
  425. ;                               Usage: gr_wfill_()
  426. ;
  427. ;                               int gr_wfill(void);
  428.  
  429.     public  gr_wfill_
  430.  
  431. gr_wfill_ proc
  432.     prolog
  433.  
  434.     ifdef   Large_data
  435.     mov     ax,seg dgroup
  436.     mov     ds,ax
  437.     endif
  438.  
  439.     mov     ecx,_gr_minx_
  440. wfill:  mov     edx,_gr_miny_
  441.  
  442. wfill1: mov     al,_grfcol_
  443.     mwrdot
  444.     inc     edx
  445.     cmp     edx,_gr_maxy_
  446.     jl      wfill1
  447.  
  448. wfill2: inc     ecx
  449.     cmp     ecx,_gr_maxx_
  450.     jl      wfill
  451.  
  452.     ifdef    asm_386
  453.     movsx    eax,ax
  454.     endif
  455.  
  456.     epilog
  457. gr_wfill_ endp
  458.  
  459.     endcseg gr_pt__
  460.     end
  461.  
  462.  
  463.