home *** CD-ROM | disk | FTP | other *** search
/ Piper's Pit BBS/FTP: ibm 0020 - 0029 / ibm0020-0029 / ibm0028.tar / ibm0028 / GRLF-C-2.ZIP / GFUNC / CIRLINE.ASM < prev    next >
Encoding:
Assembly Source File  |  1990-05-30  |  7.5 KB  |  373 lines

  1.         page    58,132
  2.  
  3. ;
  4. ; cirline.asm
  5. ; contains: gcircle(),gline(),setmaxx(),setmaxy()
  6. ;
  7.         include    model.h
  8.         include    prologue.h
  9.         name    cirline
  10.  
  11.         dseg    cirlin
  12. color        dw    0
  13. dir        dw    0
  14. maxxval        dw    639
  15. maxyval        dw    199
  16.         endds
  17.  
  18. dyn    struc
  19.   cury        dw    ?
  20.   curx        dw    ?
  21.   c1000        dw    ?
  22.   iaspect    dw    ?
  23.   aspect    dw    ?
  24.   yp        dw    ?
  25.   xp        dw    ?
  26.         db    @ab dup(?)    ;pushed bp & return address
  27.   xx        dw    ?
  28.   yy        dw    ?
  29.   radius    dw    ?
  30.   colr        dw    ?
  31.   numer        dw    ?
  32.   denom        dw    ?
  33. dyn    ends
  34.  
  35. ldyn    struc
  36.     db    @ab dup(?)    ;pushed bp & return address
  37. x1    dw    ?
  38. y1    dw    ?
  39. x2    dw    ?
  40. y2    dw    ?
  41. clr    dw    ?
  42. ldyn    ends
  43.  
  44.         pseg    circ
  45.  
  46. ;==>--    void gcircle(x,y,radius,color,aspectnumer,aspectdenom)
  47. ;
  48. ;;    ARGUMENTS:
  49. ;      (int)        x    -    Center coordinate
  50. ;      (int)        y    -    Center coordinate
  51. ;      (int)        radius    -    Radius of circle
  52. ;      (int)        color    -    Foreground color
  53. ;      (int)        aspectnumer -    Aspect Ratio numerator
  54. ;      (int)        aspectdenom -    Aspect Ratio denominator
  55. ;
  56. ;;    DESCRIPTION:
  57. ;      A graphics circle or elipse is drawn.  The indicated color is
  58. ;      used for the object, which has its center at coordinates x,y.
  59. ;      The aspect ratio may be 1 for a circle, < 1 for an elipse
  60. ;      wider than it is high, or > 1 for a thin, high elipse, and it
  61. ;      is computed internally as aspect_numer/aspect_denom.
  62. ;
  63. ;;    AUTHOR:
  64. ;    Adapted from pp 140-154 of "The Serious Assembler" (c) 1985
  65. ;    by Charles A. Crayne and Dian Girard
  66. ;      Copyright (C)1987-1990 Greenleaf Software Inc. All Rights Reserved.
  67. ;;;
  68.     cproc    gcircle,,,,14
  69.     mov    ax,[bp].colr
  70.     and    ax,00ffh        ;15 is greatest color.
  71.     mov    color,ax        ;local store color
  72.     mov    ax,[bp].numer        ;aspect numerator
  73.     cmp    ax,0            ;can't use 0 here or negatives.
  74.     jg    ok1
  75.     jmp    cxit
  76. ok1:    cmp    [bp].denom,0        ;..or here..
  77.     jg    ok2
  78.     jmp    cxit
  79. ok2:    mov    [bp].c1000,1000        ;scale factor = 1000
  80.     imul    [bp].c1000
  81.     idiv    [bp].denom        ;ax=aspect*1000
  82.     mov    [bp].aspect,ax        ; save aspect
  83.     mov    ax,[bp].denom        ;get denom
  84.     imul    [bp].c1000        ;sacle it..
  85.     idiv    [bp].numer        ;ax = inv aspect * 1000
  86.     mov    [bp].iaspect,ax        ;save it..
  87. ;
  88. ;  y=y+1  x=x-tan(inv aspect)
  89. ;
  90.     mov    ax,[bp].radius        ;get radius
  91.     cmp    ax,1
  92.     jg    ok3
  93.     jmp    cxit            ;don't do it if it doesn't exist
  94. ok3:    mov    [bp].xp,ax        ;1st previous x
  95.     imul    [bp].c1000        ;scale
  96.     mov    [bp].cury,0        ;zero initial y value
  97. circa:    push    ax
  98.     push    dx
  99.     add    ax,500            ;round it
  100.     adc    dx,0
  101.     idiv    [bp].c1000        ;rescale x
  102.     mov    bx,ax            ;1st quad
  103.     push    bx            ;new calculated x
  104. circaa:    add    ax,[bp].xx        ;add x origin
  105.     mov    di,[bp].yy        ;y origin
  106.     sub    di,[bp].cury
  107.     mov    si,ax            ;get x to plot
  108.     call    point            ; and plot it
  109.     sub    si,bx            ;get 2nd quadrant
  110.     sub    si,bx            ; x+origin
  111.     call    point
  112.     add    di,[bp].cury        ;get 3rd quadrant
  113.     add    di,[bp].cury        ;y+origin
  114.     call    point
  115.     add    si,bx            ;get 4th quadrant
  116.     add    si,bx            ;x+origin
  117.     call    point
  118.     inc    bx
  119.     cmp    bx,[bp].xp        ;x gap ?
  120.     jae    circb            ; no..
  121.     mov    ax,bx            ;set intermediate point
  122.     jmp    circaa            ;go plot it..
  123.  
  124. circb:    pop    bx            ;calculated x
  125.     mov    [bp].xp,bx        ;previous x
  126.     inc    [bp].cury        ;new y
  127.     mov    ax,[bp].cury        ;y
  128.     imul    [bp].iaspect
  129.     idiv    bx            ;tan*inv aspect
  130.     xor    dx,dx             ; remainder
  131.     mov    [bp].curx,ax        ;curx=tan*inv aspect
  132.     idiv    [bp].iaspect        ;ax=tan
  133.     cmp    ax,1            ;tan=1 ?
  134.     pop    dx
  135.     pop    ax
  136.     jae    circc            ;go to next sector
  137.     neg    [bp].curx        ;to dec x
  138.     add    ax,[bp].curx        ;new x value
  139.     adc    dx,-1            ;negative carry
  140.     jmp    short circa        ;plot new point
  141. ;
  142. ; Plot 45 to 90 degrees.
  143. ;
  144. circc:    mov    ax,[bp].cury        ;next y
  145.     mov    [bp].yp,ax        ;init previous x
  146.     imul    [bp].c1000        ;dx:ax=y*1000
  147.     mov    [bp].cury,bx        ;last x value
  148.     dec    [bp].cury        ;next x
  149. circd:    push    ax
  150.     push    dx
  151.     add    ax,500            ;round
  152.     adc    dx,0
  153.     idiv    [bp].c1000
  154.     mov    bx,ax            ;1st quad
  155.     push    bx
  156. circda:    add    ax,[bp].yy        ;add y origin
  157.     mov    si,[bp].xx        ;x origin
  158.     add    si,[bp].cury
  159.     mov    di,ax            ;y
  160.     call    point
  161.     sub    si,[bp].cury        ;2nd quadrant
  162.     sub    si,[bp].cury        ;x
  163.     call    point
  164.     sub    di,bx            ;3rd quadrant
  165.     sub    di,bx            ;y
  166.     call    point
  167.     add    si,[bp].cury        ;4th quad
  168.     add    si,[bp].cury        ;x
  169.     call    point
  170.     dec    bx
  171.     cmp    bx,[bp].yp        ;gap ?
  172.     jbe    circe            ;no
  173.     mov    ax,bx
  174.     jmp    circda            ;plot intermediate point
  175. circe:    pop    bx
  176.     mov    [bp].yp,bx        ;save previous 7
  177.     sub    di,[bp].yy        ;y-y orign
  178.     neg    di            ;y origin adjust
  179.     xchg    si,di            ;si=y
  180.     cmp    [bp].cury,0        ;90 degree ?
  181.     js    circg            ;yes,exit
  182.     dec    [bp].cury        ;new x
  183.     mov    ax,[bp].cury
  184.     imul    [bp].aspect        ;aspect*1000
  185.     idiv    si
  186.     mov    [bp].curx,ax        ;delta y
  187.     pop    dx
  188.     pop    ax
  189.     xor    bx,bx
  190.     cmp    [bp].curx,0        ;sign check
  191.     jns    circf            ;positive
  192.     mov    bx,-1            ;negative carry
  193. circf:    add    ax,[bp].curx        ;new xvalue
  194.     adc    dx,bx            ;hi word carry
  195.     jmp    circd            ;plot next point
  196. circg:    
  197. cxit:    add    sp,4
  198.     cproce
  199.  
  200.  
  201. ;==>--    void gline(x1,y1,x2,y2,color)
  202. ;
  203. ;;    ARGUMENTS:
  204. ;      (int)        x1    -    x co-ordinate of end 1
  205. ;      (int)        y1    -    y co-ordinate of end 1
  206. ;      (int)        x2    -    x co-ordinate of end 2
  207. ;      (int)        y2    -    y co-ordinate of end 2
  208. ;      (int)        color    -    color 0..2
  209. ;
  210. ;;    DESCRIPTION:
  211. ;      A line is drawn between two end points defined by the coordinate
  212. ;      sets x1,y1 and x2,y2.  The specified color is used as a selection
  213. ;      of one of three colors for the palette.
  214. ;
  215. ;;    AUTHOR:
  216. ;    Adapted from pp 140-154 of "The Serious Assembler" (c) 1985
  217. ;    by Charles A. Crayne and Dian Girard
  218. ;      Copyright (C)1987-1990 Greenleaf Software Inc. All Rights Reserved.
  219. ;;;
  220.     cproc    gline
  221.     mov    ax,[bp].clr        ;color
  222.     mov    color,ax        ;put where point can get it
  223.     mov    si,[bp].x1        ;get coordinates to registers.
  224.     mov    di,[bp].y1
  225.     mov    ax,[bp].x2
  226.     mov    bx,[bp].y2
  227.     mov    dx,0
  228.     cmp    si,ax
  229.     jbe    noxchg
  230.     xchg    si,ax
  231.     xchg    di,bx
  232. noxchg:    sub    ax,si
  233.     mov    bp,ax
  234.     sub    bx,di
  235.     mov    cx,1
  236.     jns    notneg
  237.     neg    cx
  238.     neg    bx
  239. notneg:    mov    dir,cx
  240.     mov    ax,bx            ;save y diff constant in ax
  241.     call    point
  242.     cmp    bp,bx
  243.     jle    case1            ;delta x le delta y
  244.     jmp    short case2            ;delta x gt delta y
  245. case1:    cmp    dir,1
  246.     jne    case3            ;negative y
  247.     mov    cx,ax
  248. lp1:    dec    cx
  249.     js    lxit
  250.     inc    di
  251.     add    dx,bp
  252.     cmp    ax,dx
  253.     ja    skp1
  254.     sub    dx,ax
  255.     inc    si
  256. skp1:    call    point
  257.     jmp    short lp1
  258.  
  259. case3:    mov    cx,ax
  260. lp3:    dec    cx
  261.     js    lxit
  262.     dec    di
  263.     add    dx,bp
  264.     cmp    ax,dx
  265.     ja    skp3
  266.     sub    dx,ax
  267.     inc    si
  268. skp3:    call    point
  269.     jmp    short lp3
  270.  
  271. case2:    cmp    dir,1
  272.     jne    case4            ;negative y
  273.     mov    cx,bp
  274. lp2:    dec    cx
  275.     js    lxit
  276.     inc    si
  277.     add    dx,ax
  278.     cmp    bp,dx
  279.     ja    skp2
  280.     sub    dx,bp
  281.     inc    di
  282. skp2:    call    point
  283.     jmp    short lp2
  284. case4:    mov    cx,bp
  285. lp4:    dec    cx
  286.     js    lxit
  287.     inc    si
  288.     add    dx,ax
  289.     cmp    bp,dx
  290.     ja    skp4
  291.     sub    dx,bp
  292.     dec    di
  293. skp4:    call    point
  294.     jmp    short lp4
  295. lxit:
  296.     cproce
  297.  
  298. ;==>--    void setmaxx(max)
  299. ;
  300. ;;    ARGUMENTS:
  301. ;      (int)        max    -    set maximum value for x-axis
  302. ;
  303. ;;    DESCRIPTION:
  304. ;      This function sets a local variable that is used to determine
  305. ;      when an x value is out of range.
  306. ;
  307. ;;    SIDE EFFECTS:
  308. ;      local variable is modified.
  309. ;
  310. ;;    AUTHOR:
  311. ;      Copyright (C)1987-1990 Greenleaf Software Inc. All Rights Reserved.
  312. ;;;
  313.     cproc    setmaxx
  314.     mov    ax,parm1_
  315.     mov    maxxval,ax
  316.     cproce
  317.  
  318. ;==>--    void setmaxy(max)
  319. ;
  320. ;;    ARGUMENTS:
  321. ;      (int)        max    -    set maximum value for y-axis
  322. ;
  323. ;;    DESCRIPTION:
  324. ;      This function sets a local variable that is used to determine
  325. ;      when an y value is out of range.
  326. ;
  327. ;;    SIDE EFFECTS:
  328. ;      local variable is modified.
  329. ;
  330. ;;    AUTHOR:
  331. ;      Copyright (C)1987-1990 Greenleaf Software Inc. All Rights Reserved.
  332. ;;;
  333.     cproc    setmaxy
  334.     mov    ax,parm1_
  335.     mov    maxyval,ax
  336.     cproce
  337. ;
  338. ;  Plot one point.
  339. ;
  340. point    proc    near
  341.     push    bp
  342.     push    ax
  343.     push    bx
  344.     push    cx
  345.     push    dx
  346.     push    si
  347.     push    di
  348.     cmp    si,0        ;left side
  349.     jl    ptxit
  350.     cmp    di,0        ;top edge
  351.     jl    ptxit
  352.     cmp    si,maxxval
  353.     jg    ptxit
  354.     cmp    di,maxyval
  355.     jg    ptxit
  356.     mov    dx,di        ;row
  357.     mov    cx,si        ;col
  358.     mov    ax,color    ;color
  359.     mov    ah,12        ;function to write DOT
  360.     xor    bh,bh
  361.     int    10h        ;write it !
  362. ptxit:    pop    di
  363.     pop    si
  364.     pop    dx
  365.     pop    cx
  366.     pop    bx
  367.     pop    ax
  368.     pop    bp
  369.     ret
  370. point    endp
  371.     endps
  372.     end
  373.