home *** CD-ROM | disk | FTP | other *** search
/ M.u.C.S. Disc 2000 / MUCS2000.iso / falcon / whip.031 / vlm / nailspin.1_2 / source / nailspin.s < prev    next >
Text File  |  1999-06-23  |  39KB  |  2,008 lines

  1.         OPT    D-
  2.         COMMENT    HEAD=%111
  3.         OUTPUT    E:\WHIP!\VLM\NAILSPIN.VLM
  4.         TEXT
  5.  
  6. scrxbytes:    =    320*2
  7. scrlines:    =    240
  8. scrsize:    =    scrxbytes*scrlines
  9.  
  10. envlightrot:    =    1            * Rotating envmap or still.
  11.  
  12. envmapxres:    =    320            * / the clipwindow
  13. envmapyres:    =    240            * \ dimensions
  14.  
  15. maxpoints:    =    500            * maximum number of points in object
  16. maxedges:    =    1000            * maximum number of edges in object
  17. maxtriangles:    =    500            * maximum number of triangles in object
  18. avgedgelen:    =    50            * maximum average length of edges
  19.  
  20. * Internal point-structure (with texture-coordinates)
  21.         RSRESET
  22. pointx:        RS.W    1
  23. pointy:        RS.W    1
  24. pointtx:    RS.W    1
  25. pointty:    RS.W    1
  26. pointz:        RS.W    1
  27. pointsize:    RS.W    1
  28.  
  29. * Internal triangle format (with color & hiddenedge info)
  30.         RSRESET
  31. trianglep1:    RS.W    1
  32. trianglep2:    RS.W    1
  33. trianglep3:    RS.W    1
  34. triangleinfo:    RS.W    1
  35. trianglesize:    RS.W    1
  36.  
  37.         RSRESET
  38. edgelength:    RS.W    1
  39. edgestarty:    RS.W    1
  40. edgeslope:    RS.L    1
  41. edgeheadersize:    RS.W    1
  42.  
  43.         RSRESET
  44. edgex:        RS.W    1
  45. edgetx:        RS.W    1
  46. edgety:        RS.W    1
  47. edgeentrysize:    RS.W    1
  48.  
  49. *** VLM STRUCTURE **************************************************************
  50.  
  51.                 DC.B "VLM2"     ;vlm module type
  52.                 DC.L infotext   ;pointer to infotext
  53.                 DC.L settings   ;pointer to settings-structure
  54.                 DC.L init       ;pointer to init routine
  55.                 DC.L deinit     ;pointer to deinit routine
  56.                 DC.L main       ;pointer to mainloop routine
  57.  
  58. * Libs
  59.         INCLUDE    FIMATH.I
  60.         TEXT
  61.  
  62. ;SERVICE ROUTINES PROVIDED BY THE CALLING PROGRAM
  63. set_vblrout:
  64. ;a0: new vbl subroutine
  65.                 movea.l service_struct,A1
  66.                 movea.l (A1),A1
  67.                 jsr     (A1)
  68.                 rts
  69.  
  70. wait_vbl:
  71.                 movea.l service_struct,A1
  72.                 movea.l 4(A1),A1
  73.                 jsr     (A1)
  74.                 rts
  75.  
  76. set_scradr:
  77. ;a0: new screen adress
  78.                 movea.l service_struct,A1
  79.                 movea.l 8(A1),A1
  80.                 jsr     (A1)
  81.                 rts
  82.  
  83. set_resolution:
  84. ;d0: number of the wanted resolution
  85.                 movea.l service_struct,A1
  86.                 movea.l 12(A1),A1
  87.                 jsr     (A1)
  88.                 rts
  89.  
  90. get_left_spec:
  91.                 movea.l service_struct,A1
  92.                 movea.l 16(A1),A1
  93.                 jsr     (A1)            ;returns in a0 the adress of left spec
  94.                 rts
  95.  
  96. get_right_spec:
  97.                 movea.l service_struct,A1
  98.                 movea.l 20(A1),A1
  99.                 jsr     (A1)            ;returns in a0 the adress of right spec
  100.                 rts
  101.  
  102. get_left_volume:
  103.                 movea.l service_struct,A1
  104.                 movea.l 24(A1),A1
  105.                 jsr     (A1)            ;returns in d0 the left volume value
  106.                 rts
  107.  
  108. get_right_volume:
  109.                 movea.l service_struct,A1
  110.                 movea.l 28(A1),A1
  111.                 jsr     (A1)            ;returns in d0 the right volume value
  112.                 rts
  113.  
  114. get_left_osci:
  115.                 movea.l service_struct,A1
  116.                 movea.l 32(A1),A1
  117.                 jsr     (A1)            ;returns in a0 the adress of osci data
  118.                 rts
  119.  
  120. get_right_osci:
  121.                 movea.l service_struct,A1
  122.                 movea.l 36(A1),A1
  123.                 jsr     (A1)            ;returns in a0 the adress of osci data
  124.                 rts
  125.  
  126. service_struct: DC.L 0          ;must be set in 'init'
  127.  
  128. ********************************************************************************
  129.  
  130. infotext:
  131.                 DC.B "NAILSPIN 3D (sKINNY pUPPY)",0
  132.                 DC.B "author:  EarX/FUN",0
  133.                 DC.B "version: 1.2",0
  134.                 DC.B "date:    13-06-1999"   ,0
  135.                 DC.B 0
  136.                 EVEN
  137.  
  138. settings:    DC.L 7
  139.  
  140.         DC.L parname1_txt
  141.         DC.L 3            ;parameter type = slider
  142. distance:    DC.L 400        ;parametervalue
  143.         DC.L distslider_tbl
  144.  
  145.         DC.L parname2_txt
  146.         DC.L 3
  147. rotspeed:    DC.L 7
  148.         DC.L spedslider_tbl
  149.  
  150.         DC.L parname3_txt
  151.         DC.L 3
  152. objectvibr:    DC.L 300
  153.         DC.L vibrslider_tbl
  154.  
  155.         DC.L parname4_txt
  156.         DC.L 1
  157. rotswitch:    DC.L 0
  158.         DC.L 0
  159.  
  160.         DC.L parname5_txt
  161.         DC.L 3
  162. peaktreshold:    DC.L 16384
  163.         DC.L peakslider_tbl
  164.  
  165.         DC.L parname6_txt
  166.         DC.L 3
  167. objectresp:    DC.L 50
  168.         DC.L respslider_tbl
  169.  
  170.         DC.L parname7_txt
  171.         DC.L 2
  172. objecttraject:    DC.L 0
  173.         DC.L trajselect_tbl
  174.  
  175. distslider_tbl:    DC.L    0
  176.         DC.L    800
  177.  
  178. spedslider_tbl:    DC.L    0
  179.         DC.L    15
  180.  
  181. vibrslider_tbl:    DC.L    0
  182.         DC.L    600
  183.  
  184. respslider_tbl:    DC.L    0
  185.         DC.L    200
  186.  
  187. peakslider_tbl:    DC.L    0
  188.         DC.L    32768
  189.  
  190. trajselect_tbl:    DC.L    2
  191.         DC.B    "SINE-O-MATIC",0
  192.         DC.B    "STEREOID-PHONIC",0
  193.  
  194. parname1_txt:    DC.B "CAMERA DISTANCE",0
  195. parname2_txt:    DC.B "OBJECT ROTATION",0
  196. parname3_txt:    DC.B "OBJECT VIBRATION",0
  197. parname4_txt:    DC.B "ROTATIONSWITCH",0
  198. parname5_txt:    DC.B "ROTATIONSWITCH TRESHOLD",0
  199. parname6_txt:    DC.B "ROTATIONSWITCH RESPONSE",0
  200. parname7_txt:    DC.B "TRAJECTORY",0
  201.                 EVEN
  202.  
  203. init:
  204. ;a0: service structure
  205.     move.l  A0,service_struct
  206.  
  207.     moveq    #1,D0                * set resolution to 320x240
  208.     bsr    set_resolution
  209.  
  210. * Initialize screenaddresses..
  211. .ramok:    lea    scr,a0
  212.     move.l    #scr_buf,d0
  213.     addq.l    #4,d0                * / long even
  214.     andi.b    #%11111100,d0            * \ address..
  215.     move.l    d0,(a0)+
  216.     addi.l    #scrsize,d0
  217.     move.l    d0,(a0)+
  218.     addi.l    #scrsize,d0
  219.     move.l    d0,(a0)+
  220.  
  221.     REPT    3
  222.     moveq    #0,d0
  223.     moveq    #0,d1
  224.     move.w    #envmapxres-1,d6
  225.     move.w    #envmapyres-1,d7
  226.     bsr    CLEAR_RECTANGLE
  227.     bsr     switch_screens
  228.     ENDR
  229.  
  230.     bsr    SET_ENVTORUS
  231.     rts
  232.  
  233. deinit:
  234.     rts
  235.  
  236. main:    bsr     switch_screens
  237.     bsr    PLOT_ENVMAP320200
  238.     rts
  239.  
  240. PLOT_ENVMAP320200:
  241. .decrease_peak:
  242.     move.w    .peak(pc),d0
  243.     subi.w    #256,d0
  244.     bcs.s    .skip_store
  245.     move.w    d0,.peak
  246. .skip_store:
  247. .end_decreasepeak
  248. .calc_vol:
  249.     bsr    get_left_volume
  250.     move.w    d0,.leftvol
  251.     moveq    #0,d7
  252.     move.w    d0,d7
  253.     bsr    get_right_volume
  254.     move.w    d0,.rightvol
  255.     moveq    #0,d1
  256.     move.w    d0,d1
  257.     add.l    d1,d7
  258.     lsr.l    #1,d7
  259. .end_calcvol
  260.     tst.w    rotswitch+2
  261.     beq.s    .end_rotswitch
  262.  
  263.     cmp.w    peaktreshold+2,d7
  264.     blo.s    .no_reverse
  265.     cmp.w    .peak(pc),d7
  266.     bcs.s    .no_reverse
  267.     move.w    $4bc.w,d1
  268.     sub.w    .start4bc(pc),d1
  269.     cmp.w    objectresp+2,d1
  270.     blo.s    .no_reverse
  271.     not.w    .inverse
  272.     move.w    d7,.peak
  273.     move.w    $4bc.w,.start4bc
  274.     move.w    .lastrot(pc),.startrot
  275. .no_reverse:
  276. .end_rotswitch:
  277.  
  278.     move.w    d7,-(sp)
  279.  
  280. * First of all, clear the painted object from the current screenbuffer.
  281.     movem.w    .rect_tbl(pc),d0-d1/d6-d7
  282.     bsr    CLEAR_RECTANGLE
  283.  
  284. * Now calculate everything and prepare for painting to the screen.
  285.        movea.l    envobjadr,a1
  286.     lea    .rot_tbl(pc),a2
  287.  
  288. .inversecontrol:
  289.     tst.w    .inverse(pc)
  290.     beq.s    .pos
  291.     move.w    .startrot(pc),d0
  292.     sub.w    $4bc.w,d0
  293.     add.w    .start4bc(pc),d0
  294.     bra.s    .end_control
  295. .pos:    move.w    .startrot(pc),d0
  296.     add.w    $4bc.w,d0
  297.     sub.w    .start4bc(pc),d0
  298. .end_control:
  299.     move.w    d0,.lastrot
  300.  
  301.     move.w    d0,d1
  302.     mulu.w    rotspeed+2,d0
  303.     lsr.l    #1,d0
  304.     move.w    d0,(a2)
  305.     mulu.w    rotspeed+2,d1
  306.     lsl.l    #2,d1
  307.     move.l    d1,d2
  308.     add.l    d1,d1
  309.     add.l    d2,d1
  310.     lsr.l    #4,d1
  311.     move.w    d1,2(a2)
  312.     bsr    ROTATE_OBJECT
  313.     move.w    (sp)+,d7
  314. .calc_xy:
  315.     lea    sine_tbl,a0
  316.     move.w    $4bc.w,d0
  317.     move.w    d0,d1
  318.     Do_SinModulo    d0
  319.     Get_Sin    a0,d0,d0
  320.     mulu.w    #7,d1
  321.     lsr.w    #1,d1
  322.     Do_SinModulo    d1
  323.     Get_Sin    a0,d1,d1
  324.     asr.w    #7,d0
  325.     asr.w    #8,d1
  326.     tst.w    objecttraject+2
  327.     beq.s    .end_calcxy
  328.     tst.w    .invertposx(pc)
  329.     bne.s    .do_posxinverse
  330.     move.w    .rightvol(pc),d0
  331.     sub.w    .leftvol(pc),d0
  332.     bra.s    .end_inverse
  333. .do_posxinverse:
  334.     move.w    .leftvol(pc),d0
  335.     sub.w    .rightvol(pc),d0
  336. .end_inverse:
  337.     asr.w    #7,d0
  338.     add.w    d0,.objectposx
  339.     move.w    .objectposx(pc),d0
  340.     bmi.s    .objnegx
  341.     cmpi.w    #200,d0
  342.     blt.s    .end_calcxy
  343.     move.w    #200,d0
  344.     not.w    .invertposx
  345.     bra.s    .end_calcxy
  346. .objnegx:
  347.     cmpi.w    #-200,d0
  348.     bgt.s    .end_calcxy
  349.     move.w    #-200,d0
  350.     not.w    .invertposx
  351. .end_calcxy:
  352.     move.w    distance+2(pc),d2
  353.     addi.w    #500,d2
  354.     neg.w    d2
  355.     mulu.w    objectvibr+2,d7
  356.     swap    d7
  357.     add.w    d7,d2
  358.     cmpi.w    #-100,d2
  359.     blt.s    .far_enough
  360.     move.w    #-100,d2
  361. .far_enough:
  362.     movem.w    d0-d2,-(sp)
  363.     bsr    TRANSFORM_OBJECT
  364.     lea    boundbox_tbl,a1
  365.     lea    .rot_tbl(pc),a2
  366.     lea    .rect_tbl(pc),a0
  367.     bsr    CALC_BOUNDINGWINDOW
  368.     addq    #6,sp
  369.  
  370. * Finally paint everything on screen.
  371. ;    lea    .rot_tbl(pc),a1
  372. ;    bsr    PLOT_ROTATION
  373.     bsr    PLOT_OBJECT
  374.  
  375. * Do timing and flipping of animationpages.
  376.     lea    .rect_tbl(pc),a0
  377.     movem.l    (a0),d0-d5
  378.     movem.l    d2-d5,(a0)
  379.     movem.l    d0-d1,4*4(a0)
  380.     rts
  381.  
  382. .rot_tbl:
  383.     DC.W    0,0,0
  384. .rect_tbl:
  385.     DS.W    4*3
  386. .peak:    DC.W    0
  387. .inverse:
  388.     DC.W    0
  389. .startrot:
  390.     DC.W    0
  391. .start4bc:
  392.     DC.W    0
  393. .lastrot:
  394.     DC.W    0
  395. .leftvol:
  396.     DC.W    0
  397. .rightvol:
  398.     DC.W    0
  399. .objectposx:
  400.     DC.W    0
  401. .invertposx:
  402.     DC.W    0
  403.  
  404. SET_ENVTORUS:
  405.     move.l    #torusobject_buf,envobjadr
  406.  
  407.     movea.l    envobjadr,a1
  408.     lea    boundbox_tbl,a0
  409.     bsr    CALC_BOUNDINGBOX
  410.     movea.l    envobjadr,a1
  411.     bsr    INIT_OBJECT
  412.     rts
  413.  
  414. * Gets addresses of all tables in the 3d-object.
  415. * INPUT: a1: objectaddress (EARX envmapped format)
  416. INIT_OBJECT:
  417.     move.w    (a1)+,d0
  418.     cmpi.w    #maxpoints,d0
  419.     move.w    d0,d7
  420.     mulu.w    #pointsize,d0
  421.     adda.l    d0,a1
  422.     move.l    a1,pnttritbladr            * address of pointtriangles
  423.     move.w    (a1)+,d0
  424.     cmpi.w    #maxtriangles,d0
  425.     lea    (a1,d0.w*trianglesize),a1
  426.     move.w    d0,d1
  427.     move.l    a1,edgestbladr            * address of edges
  428.     move.w    (a1)+,d0
  429.     cmpi.w    #maxedges,d0
  430.     lea    (a1,d0.w*4),a1
  431.     move.l    a1,tritbladr            * address of edgetriangles
  432.     mulu.w    #6,d1
  433.     adda.l    d1,a1
  434.     move.l    a1,normaltbladr            * address of normals
  435.  
  436. * Rescale normals.
  437.     subq.w    #1,d7
  438. .loop:    movem.w    (a1),d0-d2
  439.     muls.w    #$f0,d0
  440.     muls.w    #$f0,d1
  441.     muls.w    #$f0,d2
  442.     asr.l    #8,d0
  443.     asr.l    #8,d1
  444.     asr.l    #8,d2
  445.     move.w    d0,(a1)+
  446.     move.w    d1,(a1)+
  447.     move.w    d2,(a1)+
  448.     dbra    d7,.loop
  449.     rts
  450.  
  451. * Gets addresses of all tables in the 3d-object.
  452. * INPUT: a1: objectaddress (EARX envmapped format)
  453. INIT_OBJECT128:
  454.     move.w    (a1)+,d0
  455.     move.w    d0,d7
  456.     mulu.w    #pointsize,d0
  457.     adda.l    d0,a1
  458.     move.l    a1,pnttritbladr            * address of pointtriangles
  459.     move.w    (a1)+,d0
  460.     lea    (a1,d0.w*trianglesize),a1
  461.     move.w    d0,d1
  462.     move.l    a1,edgestbladr            * address of edges
  463.     move.w    (a1)+,d0
  464.     lea    (a1,d0.w*4),a1
  465.     move.l    a1,tritbladr            * address of edgetriangles
  466.     mulu.w    #6,d1
  467.     adda.l    d1,a1
  468.     move.l    a1,normaltbladr            * address of normals
  469.  
  470. * Rescale normals for 128*128 texture.
  471.     subq.w    #1,d7
  472. .loop:    movem.w    (a1),d0-d2
  473.     asr.w    #1,d0
  474.     asr.w    #1,d1
  475.     asr.w    #1,d2
  476.     move.w    d0,(a1)+
  477.     move.w    d1,(a1)+
  478.     move.w    d2,(a1)+
  479.     dbra    d7,.loop
  480.     rts
  481.  
  482. * INPUT: a0: address of boundingbox-buffer to fill
  483. *        a1: address of object's pointtable
  484. CALC_BOUNDINGBOX:
  485. * First find the highest and lowest x,y,z components..
  486.     move.w    (a1)+,d7
  487.     move.w    pointx(a1),d0
  488.     move.w    pointy(a1),d1
  489.     move.w    pointz(a1),d2
  490.     move.w    d0,d3
  491.     move.w    d1,d4
  492.     move.w    d2,d5
  493.     subq.w    #2,d7
  494.     bmi.s    .endloop
  495.     lea    pointsize(a1),a1
  496.  
  497. .loop:    move.w    pointx(a1),d6
  498.     cmp.w    d6,d0
  499.     ble.s    .nonewxl
  500.     move.w    d6,d0
  501. .nonewxl:
  502.     cmp.w    d6,d3
  503.     bge.s    .nonewxh
  504.     move.w    d6,d3
  505. .nonewxh:
  506.     move.w    pointy(a1),d6
  507.     cmp.w    d6,d1
  508.     ble.s    .nonewyl
  509.     move.w    d6,d1
  510. .nonewyl:
  511.     cmp.w    d6,d4
  512.     bge.s    .nonewyh
  513.     move.w    d6,d4
  514. .nonewyh:
  515.     move.w    pointz(a1),d6
  516.     cmp.w    d6,d2
  517.     ble.s    .nonewzl
  518.     move.w    d6,d2
  519. .nonewzl:
  520.     cmp.w    d6,d5
  521.     bge.s    .nonewzh
  522.     move.w    d6,d5
  523. .nonewzh:
  524.     lea    pointsize(a1),a1
  525.     dbra    d7,.loop
  526. .endloop:
  527.  
  528. * Now create a box (8 points) from the 
  529.     move.w    d0,(a0)+            * / (xl,yl,zl)
  530.     move.w    d1,(a0)+            * | 
  531.     move.w    d2,(a0)+            * \
  532.     move.w    d0,(a0)+            * / (xl,yl,zh)
  533.     move.w    d1,(a0)+            * | 
  534.     move.w    d5,(a0)+            * \
  535.     move.w    d0,(a0)+            * / (xl,yh,zl)
  536.     move.w    d4,(a0)+            * | 
  537.     move.w    d2,(a0)+            * \
  538.     move.w    d0,(a0)+            * / (xl,yh,zh)
  539.     move.w    d4,(a0)+            * | 
  540.     move.w    d5,(a0)+            * \
  541.     move.w    d3,(a0)+            * / (xh,yl,zl)
  542.     move.w    d1,(a0)+            * | 
  543.     move.w    d2,(a0)+            * \
  544.     move.w    d3,(a0)+            * / (xh,yl,zh)
  545.     move.w    d1,(a0)+            * | 
  546.     move.w    d5,(a0)+            * \
  547.     move.w    d3,(a0)+            * / (xh,yh,zl)
  548.     move.w    d4,(a0)+            * | 
  549.     move.w    d2,(a0)+            * \
  550.     move.w    d3,(a0)+            * / (xh,yh,zh)
  551.     move.w    d4,(a0)+            * | 
  552.     move.w    d5,(a0)+            * \
  553.     rts
  554.  
  555. * INPUT: 8(sp).w: x center
  556. *        6(sp).w: y center
  557. *        4(sp).w: z center
  558. *        a0: address of rectangleinfo
  559. *        a1: address of boundingbox structure
  560. *        a2: address of rotationtable
  561. CALC_BOUNDINGWINDOW:
  562.     movea.l    a0,a5                * Backup rectinfo address.
  563. * Get sine-values..
  564.     lea    sine_tbl,a3
  565.     move.w    (a2)+,d0
  566.     Do_SinModulo    d0
  567.     Get_SinCos    a3,d0,d1,d2
  568.     move.w    (a2)+,d0
  569.     Do_SinModulo    d0
  570.     Get_SinCos    a3,d0,d3,d4
  571.  
  572.     lea    .box_tbl(pc),a0
  573.     movea.l    a1,a2
  574.     movea.l    a0,a6
  575.  
  576. * Calculate the x-coordinates..
  577.     moveq    #8-1,d7
  578. .xloop    move.w    (a1),d0
  579.     muls.w    d4,d0
  580.     addq    #4,a1
  581.     move.w    (a1)+,d5
  582.     muls.w    d3,d5
  583.     sub.l    d5,d0
  584.     add.l    d0,d0
  585.     swap    d0
  586.     move.w    d0,(a0)
  587.     addq    #6,a0
  588.     dbra    d7,.xloop
  589.  
  590. * Calculate the y-coordinates..
  591.     lea    2(a6),a0            * Get address of first y-coord
  592.     move.l    d3,a3                * Backup
  593.     move.l    d4,a4                * Backup
  594.     muls.w    d1,d3
  595.     muls.w    d1,d4
  596.     subq.l    #1,d3
  597.     subq.l    #1,d4
  598.     add.l    d3,d3
  599.     add.l    d4,d4
  600.     swap    d3
  601.     swap    d4
  602.     move.l    a2,a1
  603.     moveq    #8-1,d7
  604. .yloop:    movem.w    (a1)+,d5-d6
  605.     muls.w    d3,d5
  606.     muls.w    d2,d6
  607.     move.w    (a1)+,d0
  608.     muls.w    d4,d0
  609.     add.l    d0,d5
  610.     add.l    d6,d5
  611.     add.l    d5,d5
  612.     swap    d5
  613.     move.w    d5,(a0)
  614.     addq    #6,a0
  615.     dbra    d7,.yloop
  616.  
  617. * Calculate the z-coordinates..
  618.     lea    4(a6),a0            * Get address of first z-coord
  619.     move.l    a3,d3
  620.     move.l    a4,d4
  621.     muls.w    d2,d3
  622.     muls.w    d2,d4
  623.     subq.l    #1,d3
  624.     subq.l    #1,d4
  625.     add.l    d3,d3
  626.     add.l    d4,d4
  627.     swap    d3
  628.     swap    d4
  629.     move.l    a2,a1
  630.     moveq    #8-1,d7
  631. .zloop:    movem.w    (a1)+,d5-d6
  632.     muls.w    d3,d5
  633.     muls.w    d1,d6
  634.     sub.l    d6,d5
  635.     move.w    (a1)+,d0
  636.     muls.w    d4,d0
  637.     add.l    d0,d5
  638.     add.l    d5,d5
  639.     swap    d5
  640.     move.w    d5,(a0)
  641.     addq    #6,a0
  642.     dbra    d7,.zloop
  643.  
  644. * Perspectivate the points.
  645.     movea.l    a5,a0
  646.     movem.w    4(sp),a3-a5            * Get center-coordinates.
  647.     move.l    a0,-(sp)            * Backup rectangleaddress.
  648.     movea.l    a6,a0
  649.     moveq    #8-2,d7
  650.     move.w    #scrxbytes/4,d3
  651.     move.w    #envmapyres/2,d4
  652.     move.w    #$0100,d5
  653.     sub.w    a5,d5
  654.     move.w    #310,d6
  655.  
  656.     movem.w    (a0)+,d1-d2
  657.     move.w    (a0)+,d0
  658.     neg.w    d0
  659.     add.w    d5,d0                * d0.w: scalefactor
  660.     add.l    a3,d1
  661.     add.l    a4,d2
  662.     lsl.l    #8,d1
  663.     muls.w    d6,d2
  664.     divs.w    d0,d1                * Scale x-coordinate.
  665.     divs.w    d0,d2                * Scale y-coordinate.
  666.     add.w    d3,d1                * Center x-coordinate.
  667.     add.w    d4,d2                * Center y-coordinate.
  668.     movea.w    d1,a1
  669.     movea.w    d2,a2
  670.     movea.w    d1,a5
  671.     movea.w    d2,a6
  672.  
  673. .loop:    movem.w    (a0)+,d1-d2
  674.     move.w    (a0)+,d0
  675.     neg.w    d0
  676.     add.w    d5,d0                * d0.w: scalefactor
  677.     add.l    a3,d1
  678.     add.l    a4,d2
  679.     lsl.l    #8,d1
  680.     muls.w    d6,d2
  681.     divs.w    d0,d1                * Scale x-coordinate.
  682.     divs.w    d0,d2                * Scale y-coordinate.
  683.     add.w    d3,d1                * Center x-coordinate.
  684.     add.w    d4,d2                * Center y-coordinate.
  685.     cmpa.w    d1,a1
  686.     ble.s    .nonewxl
  687.     movea.w    d1,a1
  688.     bra.s    .endcmpx
  689. .nonewxl:
  690.     cmpa.w    d1,a5
  691.     bge.s    .nonewxh
  692.     movea.w    d1,a5
  693. .nonewxh:
  694. .endcmpx:
  695.     cmpa.w    d2,a2
  696.     ble.s    .nonewyl
  697.     movea.w    d2,a2
  698.     bra.s    .endcmpy
  699. .nonewyl:
  700.     cmpa.w    d2,a6
  701.     bge.s    .nonewyh
  702.     movea.w    d2,a6
  703. .nonewyh:
  704. .endcmpy:
  705.     dbra    d7,.loop
  706.  
  707.     movea.l    (sp)+,a0            * Get rectangleaddress.
  708.     subq    #1,a1                * / Make clearwindow
  709.     subq    #1,a2                * \ a bit wider.
  710.     addq    #1,a5
  711.     addq    #1,a6    
  712.     movem.w    a1-a2/a5-a6,(a0)        * Store rectangle.
  713.     rts
  714.  
  715. .box_tbl:
  716.     DS.W    8*3
  717.  
  718. * INPUT: d0.w: left x
  719. *        d1.w: upper y
  720. *        d2.w: right x
  721. *        d3.w: lower y
  722. CLEAR_RECTANGLE:
  723.     tst.w    d0
  724.     bpl.s    .testx0
  725.     moveq    #0,d0
  726. .testx0:
  727.     cmpi.w    #envmapxres,d0
  728.     blt.s    .endtestx0
  729.     move.w    #envmapxres-1,d0
  730. .endtestx0:
  731.  
  732.     tst.w    d1
  733.     bpl.s    .testy0
  734.     moveq    #0,d1
  735. .testy0:
  736.     cmpi.w    #envmapyres,d1
  737.     blt.s    .endtesty0
  738.     move.w    #envmapyres-1,d1
  739. .endtesty0:
  740.  
  741.     tst.w    d6
  742.     bgt.s    .testx1
  743.     moveq    #0,d6
  744. .testx1:
  745.     cmpi.w    #envmapxres,d6
  746.     blt.s    .endtestx1
  747.     move.w    #envmapxres-1,d6
  748. .endtestx1:
  749.  
  750.     tst.w    d7
  751.     bgt.s    .testy1
  752.     moveq    #0,d7
  753. .testy1:
  754.     cmpi.w    #envmapyres,d7
  755.     blt.s    .endtesty1
  756.     move.w    #envmapyres-1,d7
  757. .endtesty1:
  758.  
  759.     movea.l    scr,a0
  760.     move.w    d6,d2
  761.     move.w    d7,d3
  762.     addq.w    #1,d2
  763.     andi.w    #$fffe,d2
  764.     adda.w    d2,a0
  765.     adda.w    d2,a0
  766.     mulu.w    #scrxbytes,d3
  767.     adda.l    d3,a0
  768.     sub.w    d0,d6
  769.     addq.w    #1,d6
  770.     sub.w    d1,d7
  771.     moveq    #$00000000,d0
  772.     move.l    d0,d1
  773.     move.l    d0,d2
  774.     move.l    d0,d3
  775.     move.l    d0,d4
  776.     movea.l    d0,a1
  777.     movea.l    d0,a2
  778.     movea.l    d0,a3
  779.     movea.w    #scrxbytes,a4
  780.     lsr.w    #1,d6
  781.     move.w    d6,d5
  782.     add.w    d6,d5
  783.     add.w    d5,d5
  784.     suba.w    d5,a4
  785.     ext.l    d6
  786.     move.l    d6,d5
  787.     andi.w    #$0007,d6
  788.     lsr.w    #3,d5
  789.     neg.l    d5
  790.     neg.l    d6
  791.     lea    (.endchunks.w,pc,d5.l*4),a5
  792.     lea    (.endpix.w,pc,d6.l*2),a6
  793.  
  794. .yloop:    jmp    (a5)
  795.     REPT    envmapxres/16
  796.     movem.l    d0-d4/a1-a3,-(a0)
  797.     ENDR
  798. .endchunks:
  799.     jmp    (a6)
  800.     REPT    7
  801.     move.l    d0,-(a0)
  802.     ENDR
  803. .endpix:
  804.  
  805.     suba.l    a4,a0
  806.     dbra    d7,.yloop
  807.     rts
  808.  
  809. * INPUT: d0.w: left x
  810. *        d1.w: upper y
  811. *        d2.w: right x
  812. *        d3.w: lower y
  813. CLEAR_RECTANGLEDBL:
  814.     tst.w    d0
  815.     bpl.s    .testx0
  816.     moveq    #0,d0
  817. .testx0:
  818.     cmpi.w    #envmapxres,d0
  819.     blt.s    .endtestx0
  820.     move.w    #envmapxres-1,d0
  821. .endtestx0:
  822.  
  823.     tst.w    d1
  824.     bpl.s    .testy0
  825.     moveq    #0,d1
  826. .testy0:
  827.     cmpi.w    #100,d1
  828.     blt.s    .endtesty0
  829.     move.w    #100-1,d1
  830. .endtesty0:
  831.  
  832.     tst.w    d6
  833.     bgt.s    .testx1
  834.     moveq    #0,d6
  835. .testx1:
  836.     cmpi.w    #envmapxres,d6
  837.     blt.s    .endtestx1
  838.     move.w    #envmapxres,d6
  839. .endtestx1:
  840.  
  841.     tst.w    d7
  842.     bgt.s    .testy1
  843.     moveq    #0,d7
  844. .testy1:
  845.     cmpi.w    #100,d7
  846.     blt.s    .endtesty1
  847.     move.w    #100-1,d7
  848. .endtesty1:
  849.  
  850.     add.w    d0,d0
  851.     add.w    d6,d6
  852.     movea.l    scr,a0
  853.     move.w    d6,d2
  854.     move.w    d7,d3
  855.     adda.w    d2,a0
  856.     adda.w    d2,a0
  857.     mulu.w    #scrxbytes,d3
  858.     adda.l    d3,a0
  859.     sub.w    d0,d6
  860.     addq.w    #1,d6
  861.     sub.w    d1,d7
  862.     moveq    #$00000000,d0
  863.     move.l    d0,d1
  864.     move.l    d0,d2
  865.     move.l    d0,d3
  866.     move.l    d0,d4
  867.     movea.l    d0,a1
  868.     movea.l    d0,a2
  869.     movea.l    d0,a3
  870.     movea.w    #scrxbytes,a4
  871.     lsr.w    #1,d6
  872.     move.w    d6,d5
  873.     add.w    d6,d5
  874.     add.w    d5,d5
  875.     suba.w    d5,a4
  876.     ext.l    d6
  877.     move.l    d6,d5
  878.     andi.w    #$0007,d6
  879.     lsr.w    #3,d5
  880.     neg.l    d5
  881.     neg.l    d6
  882.     add.l    d5,d5
  883.     add.l    d5,d5
  884.     add.l    d6,d6
  885.     lea    (.endchunks.b,pc,d5.l),a5
  886.     lea    (.endpix.b,pc,d6.l),a6
  887.  
  888. .yloop:
  889.  
  890. .xloop:
  891.     jmp    (a5)
  892.     REPT    scrxbytes/32
  893.     movem.l    d0-d4/a1-a3,-(a0)
  894.     ENDR
  895. .endchunks:
  896.     jmp    (a6)
  897.     REPT    7
  898.     move.l    d0,-(a0)
  899.     ENDR
  900. .endpix:
  901.  
  902.     suba.l    a4,a0
  903.     dbra    d7,.yloop
  904.     rts
  905.  
  906. * INPUT: a1: address of rotationtable
  907. PLOT_ROTATION:
  908.     movea.l    scr,a0
  909.     move.w    (a1)+,d7
  910.     Do_SinModulo    d7
  911.     mulu.w    #((1<<16)*envmapxres)/sintbllen,d7
  912.     swap    d7
  913.     move.w    d7,d6
  914.     subq.w    #1,d7
  915.     bmi.s    .endplotx
  916.  
  917. .loop:    move.w    #$f800,(a0)+
  918.     dbra    d7,.loop
  919.  
  920.     move.w    #envmapxres-1,d7
  921.     sub.w    d6,d7
  922.     bmi.s    .skipclr1
  923.     moveq    #0,d0
  924. .clrloop1:
  925.     move.w    d0,(a0)+
  926.     dbra    d7,.clrloop1
  927. .skipclr1:
  928. .endplotx:
  929.  
  930.     movea.l    scr,a0
  931.     adda.l    #envmapxres*2*2,a0
  932.     move.w    (a1)+,d7
  933.     Do_SinModulo    d7
  934.     mulu.w    #((1<<16)*envmapxres)/sintbllen,d7
  935.     swap    d7
  936.     move.w    d7,d6
  937.     subq.w    #1,d7
  938.     bmi.s    .endploty
  939.  
  940. .loop2:    move.w    #$03c0,(a0)+
  941.     dbra    d7,.loop2
  942. .endloop2:
  943.  
  944.     move.w    #envmapxres-1,d7
  945.     sub.w    d6,d7
  946.     bmi.s    .skipclr2
  947.     moveq    #0,d0
  948. .clrloop2:
  949.     move.w    d0,(a0)+
  950.     dbra    d7,.clrloop2
  951. .skipclr2:
  952. .endploty:
  953.     rts
  954.  
  955. * This routine is just a easy to calculate sinus-matrix thingy
  956. * rotates around the x-axis and then around the y-axis.
  957. * makes a rotated copy of the original...
  958. * INPUT: a1: address of source objectbuffer
  959. *        a2: address of rotation-array
  960. ROTATE_OBJECT:
  961. * Get sine-values..
  962.     lea    sine_tbl,a0
  963.     move.w    (a2)+,d0
  964.     Do_SinModulo    d0
  965.     Get_SinCos    a0,d0,d1,d2
  966.     move.w    (a2)+,d0
  967.     Do_SinModulo    d0
  968.     Get_SinCos    a0,d0,d3,d4
  969.     lea    points_tbl,a0
  970.     move.w    (a1)+,d7
  971.     move.w    d7,(a0)+
  972.     subq.w    #1,d7
  973.     movea.w    d7,a5
  974.     movea.l    a1,a2
  975.     movea.l    a0,a6
  976.  
  977. * Calculate the x-coordinates..
  978. .xloop    move.w    (a1),d0
  979.     muls.w    d4,d0
  980.     addq    #pointz,a1
  981.     move.w    (a1)+,d5
  982.     muls.w    d3,d5
  983.     sub.l    d5,d0
  984.     add.l    d0,d0
  985.     swap    d0
  986.     move.w    d0,(a0)
  987.     lea    pointsize(a0),a0
  988.     dbra    d7,.xloop
  989.  
  990. * Calculate the texture x-coordinates..
  991.     lea    pointtx(a6),a0            * Get address of first texture x-coord
  992.     movea.l    normaltbladr,a1
  993.     move.w    a5,d7
  994.     IFNE    envlightrot
  995. .normxloop:
  996.     move.w    (a1)+,d0
  997.     muls.w    d4,d0
  998.     addq    #2,a1
  999.     move.w    (a1)+,d5
  1000.     muls.w    d3,d5
  1001.     sub.l    d5,d0
  1002.     swap    d0
  1003.     move.w    d0,(a0)
  1004.     lea    pointsize(a0),a0
  1005.     dbra    d7,.normxloop
  1006.     ELSE
  1007. .normxloop:
  1008.     move.w    (a1),(a0)
  1009.     addq    #6,a1
  1010.     lea    pointsize(a0),a0
  1011.     dbra    d7,.normxloop
  1012.     ENDC
  1013.  
  1014. * Calculate the y-coordinates..
  1015.     lea    pointy(a6),a0            * Get address of first y-coord
  1016.     move.l    d3,a3                * Backup
  1017.     move.l    d4,a4                * Backup
  1018.     muls.w    d1,d3
  1019.     muls.w    d1,d4
  1020.     subq.l    #1,d3
  1021.     subq.l    #1,d4
  1022.     add.l    d3,d3
  1023.     add.l    d4,d4
  1024.     swap    d3
  1025.     swap    d4
  1026.     move.l    a2,a1
  1027.     move.w    a5,d7
  1028. .yloop:    movem.w    (a1),d5-d6
  1029.     muls.w    d3,d5
  1030.     muls.w    d2,d6
  1031.     addq    #pointz,a1
  1032.     move.w    (a1)+,d0
  1033.     muls.w    d4,d0
  1034.     add.l    d0,d5
  1035.     add.l    d6,d5
  1036.     add.l    d5,d5
  1037.     swap    d5
  1038.     move.w    d5,(a0)
  1039.     lea    pointsize(a0),a0
  1040.     dbra    d7,.yloop
  1041.  
  1042. * Calculate the texture y-coordinates..
  1043.     lea    pointty(a6),a0            * Get address of first texture y-coord
  1044.     movea.l    normaltbladr,a1
  1045.     move.w    a5,d7
  1046.     IFNE    envlightrot
  1047. .normyloop:
  1048.     movem.w    (a1)+,d5-d6
  1049.     muls.w    d3,d5
  1050.     muls.w    d2,d6
  1051.     move.w    (a1)+,d0
  1052.     muls.w    d4,d0
  1053.     add.l    d0,d5
  1054.     add.l    d6,d5
  1055.     swap    d5
  1056.     move.w    d5,(a0)
  1057.     lea    pointsize(a0),a0
  1058.     dbra    d7,.normyloop
  1059.     ELSE    
  1060.     addq    #2,a1
  1061. .normyloop:
  1062.     move.w    (a1),(a0)
  1063.     addq    #6,a1
  1064.     lea    pointsize(a0),a0
  1065.     dbra    d7,.normyloop
  1066.     ENDC
  1067.  
  1068. * Calculate the z-coordinates..
  1069.     lea    pointz(a6),a0            * Get address of first z-coord
  1070.     move.l    a3,d3
  1071.     move.l    a4,d4
  1072.     muls.w    d2,d3
  1073.     muls.w    d2,d4
  1074.     subq.l    #1,d3
  1075.     subq.l    #1,d4
  1076.     add.l    d3,d3
  1077.     add.l    d4,d4
  1078.     swap    d3
  1079.     swap    d4
  1080.     move.l    a2,a1
  1081.     move.w    a5,d7
  1082. .zloop:    movem.w    (a1),d5-d6
  1083.     muls.w    d3,d5
  1084.     muls.w    d1,d6
  1085.     sub.l    d6,d5
  1086.     addq    #pointz,a1
  1087.     move.w    (a1)+,d0
  1088.     muls.w    d4,d0
  1089.     add.l    d0,d5
  1090.     add.l    d5,d5
  1091.     swap    d5
  1092.     move.w    d5,(a0)
  1093.     lea    pointsize(a0),a0
  1094.     dbra    d7,.zloop
  1095.     rts
  1096.  
  1097. * Adds x, y, z values to each of the points in the object and
  1098. * transforms 3d -> 2d.
  1099. * INPUT: d0.w: x-offset
  1100. *        d1.w: y-offset
  1101. *        d2.w: z-offset
  1102. TRANSFORM_OBJECT:
  1103.     lea    points_tbl,a0
  1104.     move.w    (a0)+,d7
  1105.     subq.w    #1,d7
  1106.  
  1107.     move.w    #scrxbytes/4,d3
  1108.     move.w    #envmapyres/2,d4
  1109.     movea.w    d0,a3
  1110.     movea.w    d1,a4
  1111.     move.w    #$0100,d5
  1112.     sub.w    d2,d5
  1113.     move.w    #310,d6
  1114.  
  1115. .loop:    move.w    pointz(a0),d0
  1116.     neg.w    d0
  1117.     add.w    d5,d0            * d0.w: scale factor
  1118.     movem.w    (a0),d1-d2
  1119.     add.l    a3,d1
  1120.     add.l    a4,d2
  1121.     lsl.l    #8,d1
  1122.     muls.w    d6,d2
  1123.     divs.w    d0,d1            * Scale x-coordinate.
  1124.     divs.w    d0,d2            * Scale y-coordinate.
  1125.     add.w    d3,d1            * Center x-coordinate.
  1126.     add.w    d4,d2            * Center y-coordinate.
  1127.     move.w    d1,(a0)+
  1128.     move.w    d2,(a0)+
  1129.     addq    #pointsize-4,a0
  1130.     dbra    d7,.loop
  1131.     rts
  1132.  
  1133. * Plots one environment mapped object. Backface culling and painters
  1134. * algorithm depthsorting are used.
  1135. * The object plotting is only suited to objects that have a texture mapped
  1136. * around them. That is: only one texturebitmap.
  1137. PLOT_OBJECT:
  1138. * STEP 0:
  1139. * Set all edges to unused..
  1140.     moveq    #0,d0
  1141.     lea    .edgesdone_tbl,a0
  1142.     movea.l    edgestbladr,a1
  1143.     move.w    (a1),d7
  1144.     lsr.w    #2,d7
  1145. .clredgesdoneloop:
  1146.     move.l    d0,(a0)+
  1147.     dbra    d7,.clredgesdoneloop
  1148.  
  1149. * STEP 1:
  1150. * Put all Z-points of triangles in the sorting table and kick out backface
  1151. * triangles. Also mark the used edges.
  1152. .putsortvals:
  1153.     movea.l    pnttritbladr,a5
  1154.     move.w    (a5)+,d7
  1155.     subq.w    #1,d7
  1156.     bmi    .rts
  1157.     moveq    #0,d0
  1158.     lea    points_tbl+2,a3
  1159.     lea    .sort_tbl+2,a6
  1160.     movea.l    tritbladr,a1
  1161.     lea    .edgesdone_tbl,a2
  1162.  
  1163. .putsortvalsloop:
  1164.     move.w    (a5)+,d6
  1165.     mulu.w    #pointsize,d6
  1166.     movea.w    pointz(a3,d6.l),a4
  1167.     movem.w    (a3,d6.l),d1-d2
  1168.     move.w    (a5)+,d6
  1169.     mulu.w    #pointsize,d6
  1170.     adda.w    pointz(a3,d6.l),a4
  1171.     movem.w    (a3,d6.l),d3-d4
  1172.     move.w    (a5)+,d6
  1173.     mulu.w    #pointsize,d6
  1174.     adda.w    pointz(a3,d6.l),a4
  1175.     movem.w    (a3,d6.l),d5-d6
  1176.  
  1177.     sub.w    d3,d1
  1178.     sub.w    d3,d5
  1179.     sub.w    d4,d2
  1180.     sub.w    d4,d6
  1181.     muls.w    d1,d6
  1182.     muls.w    d2,d5
  1183.     cmp.l    d6,d5
  1184.     bgt.s    .visible
  1185.     addq    #6,a1
  1186.     bra.s    .endputsortvalsloop
  1187. .visible:
  1188.     addq.w    #1,d0                    * Increase number of visible triangles.
  1189.     move.w    a4,(a6)+                * Store Z-center of triangle in sortingtable.
  1190.     move.l    a1,(a6)+                * Store address of triangle.
  1191.     movem.w    (a1)+,d1-d3                * Get edgenumbers.
  1192.     moveq    #1,d4
  1193.     move.b    d4,(a2,d1.l)                * Mark edge 0 as visible.
  1194.     move.b    d4,(a2,d2.l)                * Mark edge 1 as visible.
  1195.     move.b    d4,(a2,d3.l)                * mark edge 2 as visible.
  1196. .endputsortvalsloop:
  1197.     addq    #trianglesize-triangleinfo,a5
  1198.     dbra    d7,.putsortvalsloop
  1199.     move.w    d0,.sort_tbl                * Store number of visible triangles.
  1200.  
  1201. * STEP 2:
  1202. * Calculate all the visible edges into nice edgetables.
  1203. .calcedges:
  1204.     lea    temp_buf,a4
  1205.     lea    .edgesdone_tbl,a3
  1206.     movea.l    edgestbladr,a2
  1207.     move.w    (a2)+,d7
  1208.     subq.w    #1,d7
  1209.     bmi    .rts
  1210.     lea    points_tbl+2,a1
  1211.     lea    2*2*maxedges(a4),a0
  1212.     movea.l    a0,a6
  1213.  
  1214. .calcedgeloop:
  1215.     move.w    d7,-(sp)
  1216.  
  1217.     tst.b    (a3)+
  1218.     beq.s    .dontcalcedge
  1219.  
  1220.     move.l    a0,(a4)+
  1221.  
  1222.     move.w    (a2)+,d0
  1223.     move.w    (a2)+,d4
  1224.  
  1225.     mulu.w    #pointsize,d0
  1226.     mulu.w    #pointsize,d4
  1227.     movem.w    (a1,d0.l),d0-d3
  1228.     movem.w    (a1,d4.l),d4-d7
  1229.     bsr    CALCULATE_EDGETABLE
  1230.     bra.s    .calcedgeloopend
  1231.  
  1232. .dontcalcedge:
  1233.     addq    #4,a4
  1234.     addq    #4,a2
  1235.  
  1236. .calcedgeloopend:
  1237.     move.w    (sp)+,d7
  1238.     dbra    d7,.calcedgeloop
  1239.  
  1240. * STEP 3:
  1241. * Now sort all the visible triangles using combsort.
  1242. * Combsort rules!! Thanx to Dynacore/.tSCc. for his great article!
  1243.     lea    .sort_tbl,a1
  1244.     move.w    (a1)+,d7            * d7.w: number of triangles
  1245.     subq.w    #1,d7
  1246.     beq.s    .endcombsort
  1247.     bmi    .rts
  1248.     movea.l    a1,a3
  1249.     move.w    d7,d4
  1250.     lsr.w    #1,d4                * d4.w: gapsize
  1251.     bra.s    .endcalcgap
  1252. .combsortloop:
  1253.     cmpi.w    #2,d4                * / If the gapsize
  1254.     bhi.s    .calcgap            * | is already 1 or
  1255.     moveq    #1,d4                * | 2 then always
  1256.     bra.s    .endcalcgap            * \ set it to 1.
  1257. .calcgap:
  1258.     mulu.w    #((1<<16)*10)/13,d4        * / Resize
  1259.     swap    d4                * \ the gap.
  1260. .endcalcgap:
  1261.     move.w    d7,d6
  1262.     sub.w    d4,d6
  1263.     move.w    d4,d0
  1264.     mulu.w    #2+4,d0
  1265.     lea    (a3,d0.l),a5
  1266.     moveq    #0,d5                * d5.w: number of swaps done in loop
  1267.  
  1268. .combsortinloop:
  1269.     move.w    (a1),d0
  1270.     move.w    (a5),d1
  1271.     cmp.w    d1,d0
  1272.     ble.s    .noswap
  1273.     move.w    d1,(a1)+            * / Swap
  1274.     move.w    d0,(a5)+            * \ depth.
  1275.     move.l    (a1),d0                * / Swap the 
  1276.     move.l    (a5),(a1)+            * | triangle
  1277.     move.l    d0,(a5)+            * \ addresses.
  1278.     addq.w    #1,d5
  1279.     dbra    d6,.combsortinloop
  1280.     bra.s    .combsortloopend
  1281. .noswap:    
  1282.     addq    #6,a1
  1283.     addq    #6,a5
  1284.     dbra    d6,.combsortinloop
  1285. .combsortloopend:
  1286.     movea.l    a3,a1
  1287.     move.w    d5,d5
  1288.     bne.s    .combsortloop
  1289.     cmpi.w    #1,d4
  1290.     bne.s    .combsortloop
  1291. .endcombsort:
  1292.  
  1293. * STEP 4:
  1294. * Plot all the visible triangles in their Z-order.
  1295.     lea    .sort_tbl,a1
  1296.     move.w    (a1)+,d7
  1297.     subq.w    #1,d7
  1298.     bmi.s    .rts
  1299.     lea    temp_buf,a2
  1300.     movea.l    envtextureadr,a3
  1301.     adda.l    #(256*2*128)+128*2,a3
  1302.  
  1303. .plottriangleloop:
  1304.     move.w    d7,-(sp)
  1305.  
  1306.     addq    #2,a1
  1307.     movea.l    (a1)+,a0
  1308.     movem.w    (a0),d0-d2
  1309.     movem.l    a1-a3,-(sp)
  1310.     bsr    PLOT_ENVMAPTRIANGLE
  1311.     movem.l    (sp)+,a1-a3
  1312.  
  1313.     move.w    (sp)+,d7
  1314.     dbra    d7,.plottriangleloop
  1315.  
  1316. .rts:    rts
  1317.  
  1318. .edgesdone_tbl:
  1319.     DS.B    maxedges
  1320. .sort_tbl:
  1321.     DS.W    3*maxtriangles
  1322.  
  1323. ;    lsl.l    #6,d4
  1324. ;    movea.l    d4,a6
  1325. ;    adda.l    a6,a6
  1326. ;    adda.l    d4,a6
  1327. ;    adda.l    d5,a6
  1328. ;    move.l    (a5,a6.l),d4
  1329.  
  1330. * Calculates all scanline points of the edges and puts them in a table.
  1331. * This should also take care of horizontal clipping and of onscreen
  1332. * detection.
  1333. * INPUT: d0.l: X-start
  1334. *        d1.l: Y-start
  1335. *        d2.l: TX-start
  1336. *        d3.l: TY-start
  1337. *        d4.l: X-end
  1338. *        d5.l: Y-end
  1339. *        d6.l: TX-end
  1340. *        d7.l: TY-end
  1341. *        a0: address to write new edgetable to
  1342. * OUTPUT: a0: address of next edgetable
  1343. CALCULATE_EDGETABLE:
  1344.     cmp.w    d5,d1
  1345.     bgt.s    .domirrored
  1346.  
  1347.     beq.s    .emptyedge
  1348.     sub.l    d1,d5
  1349.     move.w    d5,(a0)+
  1350.     move.w    d1,(a0)+
  1351.     swap    d0
  1352.     swap    d4
  1353.     sub.w    d0,d0
  1354.     sub.w    d4,d4
  1355.     sub.l    d0,d4
  1356.     lsl.l    #8,d2
  1357.     lsl.l    #8,d3    
  1358.     lsl.l    #8,d6
  1359.     lsl.l    #8,d7
  1360.     sub.l    d2,d6
  1361.     sub.l    d3,d7
  1362.     divs.w    d5,d6
  1363.     divs.w    d5,d7
  1364.     divs.l    d5,d4
  1365.     move.l    d4,(a0)+
  1366. .loop:    move.l    d0,d1
  1367.     swap    d1
  1368.     move.w    d1,(a0)+
  1369.     move.w    d2,(a0)+
  1370.     move.w    d3,(a0)+
  1371.     add.l    d4,d0
  1372.     add.w    d6,d2
  1373.     add.w    d7,d3
  1374.     dbra    d5,.loop
  1375.     rts    
  1376. * Edge is completely horizontal, so it doesn't need to be drawn.
  1377. .emptyedge:
  1378.     clr.w    (a0)+
  1379.     move.w    d1,(a0)+
  1380.     addq    #edgeheadersize-4,a0
  1381.     rts
  1382.  
  1383. * Y-start is larger than Y-end, so do everything the other way round.
  1384. .domirrored:
  1385.     sub.l    d5,d1
  1386.     beq.s    .mirroremptyedge
  1387.     move.w    d1,(a0)+
  1388.     move.w    d5,(a0)+
  1389.     swap    d4
  1390.     swap    d0
  1391.     sub.w    d4,d4
  1392.     sub.w    d0,d0
  1393.     sub.l    d4,d0
  1394.     lsl.l    #8,d6
  1395.     lsl.l    #8,d7    
  1396.     lsl.l    #8,d2
  1397.     lsl.l    #8,d3
  1398.     sub.l    d6,d2
  1399.     sub.l    d7,d3
  1400.     divs.w    d1,d2
  1401.     divs.w    d1,d3
  1402.     divs.l    d1,d0
  1403.     move.l    d0,(a0)+
  1404. .mirrorloop:
  1405.     move.l    d4,d5
  1406.     swap    d5
  1407.     move.w    d5,(a0)+
  1408.     move.w    d6,(a0)+
  1409.     move.w    d7,(a0)+
  1410.     add.l    d0,d4
  1411.     add.w    d2,d6
  1412.     add.w    d3,d7
  1413.     dbra    d1,.mirrorloop
  1414.     rts    
  1415. * Edge is completely horizontal, so it doesn't need to be drawn.
  1416. .mirroremptyedge:
  1417.     clr.w    (a0)+
  1418.     move.w    d5,(a0)+
  1419.     addq    #edgeheadersize-4,a0
  1420.     rts
  1421.  
  1422. * Plots a texturemapped triangle using the specified edgetables.
  1423. * Does not do clipping whatsoever. The clipping of an object needs
  1424. * to be done by the routine that handles edge-calculations and the
  1425. * one that handles culling and sorting.
  1426. * INPUT: d0.l: edge index 1
  1427. *        d1.l: edge index 2
  1428. *        d2.l: edge index 3
  1429. *        a2: address of edgetable-buffer
  1430. *        a3: address of middle of texture (256*256 highcolor)
  1431. PLOT_ENVMAPTRIANGLE:
  1432.     move.l    a3,.textureadr
  1433.     movea.l    (a2,d0.l*4),a4
  1434.     movea.l    (a2,d1.l*4),a5
  1435.     movea.l    (a2,d2.l*4),a6
  1436.  
  1437. * Find out which two edges are first and which one is second.
  1438. .order:    move.w    edgestarty(a4),d0
  1439.     move.w    edgestarty(a5),d1
  1440.     move.w    edgestarty(a6),d2
  1441.     cmp.w    d0,d1
  1442.     beq.s    .endorder
  1443.     cmp.w    d0,d2
  1444.     bne.s    .1_2
  1445.     exg    a6,a5
  1446.     exg    d2,d1
  1447.     bra.s    .endorder
  1448. .1_2:    exg    a6,a4
  1449.     exg    d2,d0
  1450. .endorder:
  1451.  
  1452. * Test if all edges start are first => triangle is a dot/scanline or a \/
  1453. .testspecial:
  1454.     cmp.w    d0,d2
  1455.     bne    .calcnormalslope
  1456.     tst.w    (a4)
  1457.     bne.s    .testa5
  1458.     exg    a4,a6
  1459.     bra.s    .testscan
  1460. .testa5:
  1461.     tst.w    (a5)
  1462.     bne.s    .testscan
  1463.     exg    a5,a6
  1464. * Test if the triangle is a dot/scanline
  1465. .testscan:
  1466.     tst.w    (a4)
  1467.     bne.s    .specialslope
  1468.     tst.w    (a5)
  1469.     bne.s    .specialslope
  1470.     tst.w    (a6)
  1471.     bne.s    .specialslope
  1472.     rts
  1473.  
  1474. * Calculate slope-offset table for special \/ case.
  1475. .specialslope:
  1476.     lea    .textureoffset_tbl(pc),a1
  1477.     movem.w    edgeheadersize(a4),d0-d2
  1478.     movem.w    edgeheadersize(a5),d3-d5
  1479.     sub.w    d0,d3
  1480.     beq    .endscanplot
  1481.     sub.l    d1,d4
  1482.     sub.l    d2,d5
  1483.     divs.w    d3,d4
  1484.     divs.w    d3,d5
  1485.     move.w    d3,d3
  1486.     bpl.s    .d3pos
  1487.     neg.w    d3
  1488. .d3pos:    addq.w    #1,d3
  1489.     moveq    #0,d1
  1490.     moveq    #0,d2
  1491.     lsl.l    #8,d4
  1492.     swap    d5
  1493.     move.w    d4,d5
  1494.     swap    d5
  1495.     swap    d4
  1496. .specialcalcslopeloop:
  1497.     move.w    d2,d0
  1498.     move.b    d1,d0
  1499.     move.w    d0,(a1)+
  1500.     add.l    d5,d2
  1501.     addx.b    d4,d1
  1502.     dbra    d3,.specialcalcslopeloop
  1503. * Find out which edges are left and which are right.
  1504.     move.w    edgeheadersize(a5),d0
  1505.     cmp.w    edgeheadersize(a4),d0
  1506.     bge.s    .plot
  1507.     exg    a4,a5
  1508.     bra.s    .plot
  1509.  
  1510. * Calculate slope-offset table for normal case.
  1511. .calcnormalslope:
  1512.     lea    .textureoffset_tbl(pc),a1
  1513.     move.w    (a4),d6
  1514.     move.w    (a5),d1
  1515.     cmp.w    d1,d6
  1516.     ble.s    .d6smaller
  1517.     move.w    d1,d6
  1518. .d6smaller:
  1519.     mulu.w    #6,d6
  1520.     movem.w    edgeheadersize(a4,d6.l),d0-d2
  1521.     movem.w    edgeheadersize(a5,d6.l),d3-d5
  1522.     sub.w    d0,d3
  1523.     beq    .endscanplot
  1524.     sub.l    d1,d4
  1525.     sub.l    d2,d5
  1526.     divs.w    d3,d4
  1527.     divs.w    d3,d5
  1528.     moveq    #0,d1
  1529.     moveq    #0,d2
  1530.     move.w    d3,d3
  1531.     bpl.s    .normlengthpos
  1532.     neg.w    d3
  1533. .normlengthpos:
  1534.     addq.w    #1,d3
  1535.     lsl.l    #8,d4
  1536.     swap    d5
  1537.     move.w    d4,d5
  1538.     swap    d5
  1539.     swap    d4
  1540. .normalcalcslopeloop:
  1541.     move.w    d2,d0
  1542.     move.b    d1,d0
  1543.     move.w    d0,(a1)+
  1544.     add.l    d5,d2
  1545.     addx.b    d4,d1
  1546.     dbra    d3,.normalcalcslopeloop
  1547. * Find out which edges are left and which are right..
  1548. .leftright:
  1549.     move.l    edgeslope(a5),d0
  1550.     cmp.l    edgeslope(a4),d0
  1551.     bge.s    .noswap
  1552.     exg    a4,a5
  1553. .noswap:
  1554.  
  1555. * Prepare for plotting in the screenbuffer.
  1556. .plot:
  1557. .initplot:
  1558.     moveq    #0,d6
  1559.     move.w    (a4),d5
  1560.     move.w    (a5),d6
  1561.     sub.w    d5,d6
  1562.     bgt.s    .endinitplot
  1563.     neg.w    d6
  1564.     move.w    (a5),d5
  1565.     bset    #31,d6                * Edge in a4 is longest.
  1566. .endinitplot:
  1567.  
  1568.     movea.l    scr,a3
  1569.     move.l    .textureadr(pc),d7
  1570.     move.l    #.textureoffset_tbl,d4
  1571.  
  1572. .yclip:
  1573.     move.w    edgestarty(a4),d0
  1574.     bpl.s    .noylowclip
  1575.     add.w    d0,d5
  1576.     ble.s    .noplotfirst
  1577.     neg.w    d0
  1578.     mulu.w    #6,d0
  1579.     adda.l    d0,a4
  1580.     adda.l    d0,a5
  1581.     moveq    #0,d0
  1582.     bra.s    .endyclip
  1583. .noplotfirst:
  1584.     add.w    d5,d6
  1585.     ble    .rts
  1586.     neg.w    d0
  1587.     neg.w    d5
  1588.     mulu.w    #6,d0
  1589.     mulu.w    #6,d5
  1590.     lea    edgeheadersize(a4,d0.l),a4
  1591.     lea    edgeheadersize(a5,d0.l),a5
  1592.     adda.l    d5,a6
  1593.     bra    .plotsecond
  1594. .noylowclip:
  1595.     cmpi.w    #envmapyres,d0
  1596.     bge    .rts
  1597.     move.w    d6,d1
  1598.     add.w    d5,d1
  1599.     add.w    d0,d1
  1600.     bmi    .rts
  1601.     subi.w    #envmapyres,d1
  1602.     bmi.s    .endyclip
  1603.     sub.w    d1,d6
  1604.     bpl.s    .endyclip
  1605.     add.w    d6,d5
  1606. .endyclip:
  1607.  
  1608. .plotfirst:
  1609.     mulu.w    #scrxbytes,d0
  1610.     addq    #edgeheadersize,a4
  1611.     addq    #edgeheadersize,a5
  1612.     adda.l    d0,a3
  1613.     subq.w    #1,d5
  1614. * Plot upper part of triangle.
  1615. .firstloop:
  1616.     movea.l    d4,a2
  1617.     move.w    (a5),d3
  1618.     addq    #6,a5
  1619.     movem.w    (a4)+,d0-d2
  1620.  
  1621.     movea.l    d7,a1
  1622.     lsr.w    #8,d1
  1623.     move.b    d1,d2
  1624.     lea    (a1,d2.l*2),a1
  1625.  
  1626.     move.l    d0,d1
  1627.     bpl.s    .xpos1
  1628.     neg.l    d1
  1629.     lea    (a2,d1.l*2),a2
  1630.     moveq    #0,d0
  1631. .xpos1:    lea    (a3,d0.l*2),a0
  1632.     cmpi.w    #envmapxres,d3
  1633.     blt.s    .nottoobig
  1634.     move.w    d3,d2
  1635.     subi.w    #envmapxres-1,d2
  1636.     sub.w    d2,d3
  1637. .nottoobig:
  1638.     sub.w    d0,d3
  1639.     bmi.s    .endfirstline
  1640.  
  1641. .pixelloop:
  1642.     move.w    (a2)+,d1
  1643.     move.w    (a1,d1.w*2),(a0)+
  1644.     dbra    d3,.pixelloop
  1645.  
  1646. .endfirstline:
  1647.     lea    scrxbytes(a3),a3
  1648.     dbra    d5,.firstloop
  1649. .endplotfirst:
  1650.  
  1651. * Plot lower part of triangle..
  1652. .plotsecond:
  1653.     subq.w    #1,d6
  1654.     bmi.s    .endsecond            * Triangle is a /\ or a \/
  1655. * Test if left or right was shorter..
  1656.     btst    #31,d6                * Which edge is longest?
  1657.     bne.s    .noswaplr
  1658.     lea    edgeheadersize(a6),a4
  1659.     move.w    d6,d5
  1660.     sub.w    d6,d6
  1661.     bra    .firstloop
  1662.  
  1663. .noswaplr:
  1664.     move.w    d6,d5
  1665.     sub.w    d6,d6
  1666.     lea    edgeheadersize(a6),a5
  1667.     bra    .firstloop
  1668.  
  1669. .endsecond:
  1670.  
  1671. .endscanplot:
  1672.  
  1673. .rts:    rts
  1674.  
  1675. .edgestartadr:
  1676.     DS.L    1
  1677. .textureadr:
  1678.     DS.L    1
  1679. .textureoffset_tbl:
  1680.     DS.W    scrxbytes/2
  1681.  
  1682. * Plots a texturemapped triangle using the specified edgetables.
  1683. * Does not do clipping whatsoever. The clipping of an object needs
  1684. * to be done by the routine that handles edge-calculations and the
  1685. * one that handles culling and sorting.
  1686. * INPUT: d0.l: edge index 1
  1687. *        d1.l: edge index 2
  1688. *        d2.l: edge index 3
  1689. *        a2: address of edgetable-buffer
  1690. *        a3: address of middle of texture (128*128 highcolor)
  1691. PLOT_MAPTRIANGLE128:
  1692.     move.l    a3,.textureadr
  1693.     movea.l    (a2,d0.l*4),a4
  1694.     movea.l    (a2,d1.l*4),a5
  1695.     movea.l    (a2,d2.l*4),a6
  1696.  
  1697. * Find out which two edges are first and which one is second.
  1698. .order:    move.w    edgestarty(a4),d0
  1699.     move.w    edgestarty(a5),d1
  1700.     move.w    edgestarty(a6),d2
  1701.     cmp.w    d0,d1
  1702.     beq.s    .endorder
  1703.     cmp.w    d0,d2
  1704.     bne.s    .1_2
  1705.     exg    a6,a5
  1706.     exg    d2,d1
  1707.     bra.s    .endorder
  1708. .1_2:    exg    a6,a4
  1709.     exg    d2,d0
  1710. .endorder:
  1711.  
  1712. * Test if all edges start are first => triangle is a dot/scanline or a \/
  1713. .testspecial:
  1714.     cmp.w    d0,d2
  1715.     bne    .calcnormalslope
  1716.     tst.w    (a4)
  1717.     bne.s    .testa5
  1718.     exg    a4,a6
  1719.     bra.s    .testscan
  1720. .testa5:
  1721.     tst.w    (a5)
  1722.     bne.s    .testscan
  1723.     exg    a5,a6
  1724. * Test if the triangle is a dot/scanline
  1725. .testscan:
  1726.     tst.w    (a4)
  1727.     bne.s    .specialslope
  1728.     tst.w    (a5)
  1729.     bne.s    .specialslope
  1730.     tst.w    (a6)
  1731.     bne.s    .specialslope
  1732.     rts
  1733.  
  1734. * Calculate slope-offset table for special \/ case.
  1735. .specialslope:
  1736.     lea    .textureoffset_tbl(pc),a1
  1737.     movem.w    edgeheadersize(a4),d0-d2
  1738.     movem.w    edgeheadersize(a5),d3-d5
  1739.     sub.w    d0,d3
  1740.     beq    .endscanplot
  1741.     sub.l    d1,d4
  1742.     sub.l    d2,d5
  1743.     divs.w    d3,d4
  1744.     divs.w    d3,d5
  1745.     move.w    d3,d3
  1746.     bpl.s    .d3pos
  1747.     neg.w    d3
  1748. .d3pos:    moveq    #0,d1
  1749.     moveq    #0,d2
  1750.     lsl.l    #8,d4
  1751.     swap    d5
  1752.     move.w    d4,d5
  1753.     swap    d5
  1754.     swap    d4
  1755.     addq.w    #1,d3
  1756. .specialcalcslopeloop:
  1757.     move.w    d2,d0
  1758.     sub.b    d0,d0
  1759.     add.b    d1,d0
  1760.     add.b    d0,d0
  1761.     add.w    d0,d0
  1762.     move.w    d0,(a1)+
  1763.     add.l    d5,d2
  1764.     addx.b    d4,d1
  1765.     dbra    d3,.specialcalcslopeloop
  1766. * Find out which edges are left and which are right.
  1767.     move.w    edgeheadersize(a5),d0
  1768.     cmp.w    edgeheadersize(a4),d0
  1769.     bge.s    .plot
  1770.     exg    a4,a5
  1771.     bra.s    .plot
  1772.  
  1773. * Calculate slope-offset table for normal case.
  1774. .calcnormalslope:
  1775.     lea    .textureoffset_tbl(pc),a1
  1776.     move.w    (a4),d6
  1777.     move.w    (a5),d1
  1778.     cmp.w    d1,d6
  1779.     ble.s    .d6smaller
  1780.     move.w    d1,d6
  1781. .d6smaller:
  1782.     mulu.w    #6,d6
  1783.     movem.w    edgeheadersize(a4,d6.l),d0-d2
  1784.     movem.w    edgeheadersize(a5,d6.l),d3-d5
  1785.     sub.w    d0,d3
  1786.     beq    .endscanplot
  1787.     sub.l    d1,d4
  1788.     sub.l    d2,d5
  1789.     divs.w    d3,d4
  1790.     divs.w    d3,d5
  1791.     moveq    #0,d1
  1792.     moveq    #0,d2
  1793.     move.w    d3,d3
  1794.     bpl.s    .normlengthpos
  1795.     neg.w    d3
  1796. .normlengthpos:
  1797.     lsl.l    #8,d4
  1798.     swap    d5
  1799.     move.w    d4,d5
  1800.     swap    d5
  1801.     swap    d4
  1802.     addq.w    #1,d3
  1803. .normalcalcslopeloop:
  1804.     move.w    d2,d0
  1805.     sub.b    d0,d0
  1806.     add.b    d1,d0
  1807.     add.b    d0,d0
  1808.     add.w    d0,d0
  1809.     move.w    d0,(a1)+
  1810.     add.l    d5,d2
  1811.     addx.b    d4,d1
  1812.     dbra    d3,.normalcalcslopeloop
  1813. * Find out which edges are left and which are right..
  1814. .leftright:
  1815.     move.l    edgeslope(a5),d0
  1816.     cmp.l    edgeslope(a4),d0
  1817.     bge.s    .noswap
  1818.     exg    a4,a5
  1819. .noswap:
  1820.  
  1821. * Prepare for plotting in the screenbuffer.
  1822. .plot:
  1823. .initplot:
  1824.     moveq    #0,d6
  1825.     move.w    (a4),d5
  1826.     move.w    (a5),d6
  1827.     sub.w    d5,d6
  1828.     bgt.s    .endinitplot
  1829.     neg.w    d6
  1830.     move.w    (a5),d5
  1831.     bset    #31,d6                * Edge in a4 is longest.
  1832. .endinitplot:
  1833.  
  1834.     movea.l    scr,a3
  1835.     move.l    .textureadr(pc),d7
  1836.     move.l    #.textureoffset_tbl,d4
  1837.  
  1838. .yclip:    move.w    edgestarty(a4),d0
  1839.     bpl.s    .noylowclip
  1840.     add.w    d0,d5
  1841.     ble.s    .noplotfirst
  1842.     neg.w    d0
  1843.     mulu.w    #6,d0
  1844.     adda.l    d0,a4
  1845.     adda.l    d0,a5
  1846.     moveq    #0,d0
  1847.     bra.s    .endyclip
  1848. .noplotfirst:
  1849.     add.w    d5,d6
  1850.     ble    .rts
  1851.     neg.w    d0
  1852.     neg.w    d5
  1853.     mulu.w    #6,d0
  1854.     mulu.w    #6,d5
  1855.     lea    edgeheadersize(a4,d0.l),a4
  1856.     lea    edgeheadersize(a5,d0.l),a5
  1857.     adda.l    d5,a6
  1858.     bra    .plotsecond
  1859. .noylowclip:
  1860.     cmpi.w    #envmapyres,d0
  1861.     bge    .rts
  1862.     move.w    d6,d1
  1863.     add.w    d5,d1
  1864.     add.w    d0,d1
  1865.     bmi    .rts
  1866.     subi.w    #envmapyres,d1
  1867.     bmi.s    .endyclip
  1868.     sub.w    d1,d6
  1869.     bpl.s    .endyclip
  1870.     add.w    d6,d5
  1871. .endyclip:
  1872.  
  1873. .plotfirst:
  1874.     mulu.w    #scrxbytes,d0
  1875.     addq    #edgeheadersize,a4
  1876.     addq    #edgeheadersize,a5
  1877.     adda.l    d0,a3
  1878.     subq.w    #1,d5
  1879. * Plot upper part of triangle.
  1880. .firstloop:
  1881.     movea.l    d4,a2
  1882.     move.w    (a5),d3
  1883.     addq    #6,a5
  1884.     movem.w    (a4)+,d0-d2
  1885.  
  1886.     movea.l    d7,a1
  1887.     lsr.w    #8,d1
  1888.     move.b    d1,d2
  1889.     add.b    d2,d2    
  1890.     lea    (a1,d2.w*2),a1
  1891.  
  1892.     move.l    d0,d1
  1893.     bpl.s    .xpos1
  1894.     neg.l    d1
  1895.     lea    (a2,d1.l*2),a2
  1896.     moveq    #0,d0
  1897. .xpos1:    lea    (a3,d0.l*4),a0
  1898.     cmpi.w    #envmapxres-1,d3
  1899.     blt.s    .nottoobig
  1900.     move.w    d3,d2
  1901.     subi.w    #envmapxres-1,d2
  1902.     sub.w    d2,d3
  1903. .nottoobig:
  1904.     sub.w    d0,d3
  1905.     bmi.s    .endfirstline
  1906.  
  1907. .pixloop:
  1908.     move.w    (a2)+,d1
  1909.     move.l    (a1,d1.w),(a0)+
  1910.     dbra    d3,.pixloop
  1911.  
  1912. .endfirstline:
  1913.     lea    scrxbytes(a3),a3
  1914.     dbra    d5,.firstloop
  1915. .endplotfirst:
  1916.  
  1917. * Plot lower part of triangle..
  1918. .plotsecond:
  1919.     subq.w    #1,d6
  1920.     bmi.s    .endsecond            * Triangle is a /\ or a \/
  1921. * Test if left or right was shorter..
  1922.     btst    #31,d6                * Which edge is longest?
  1923.     bne.s    .noswaplr
  1924.     lea    edgeheadersize(a6),a4
  1925.     move.w    d6,d5
  1926.     sub.w    d6,d6
  1927.     bra    .firstloop
  1928.  
  1929. .noswaplr:
  1930.     move.w    d6,d5
  1931.     sub.w    d6,d6
  1932.     lea    edgeheadersize(a6),a5
  1933.     bra    .firstloop
  1934.  
  1935. .endsecond:
  1936.  
  1937. .endscanplot:
  1938.  
  1939. .rts:    rts
  1940.  
  1941. .edgestartadr:
  1942.     DS.L    1
  1943. .textureadr:
  1944.     DS.L    1
  1945. .textureoffset_tbl:
  1946.     DS.W    scrxbytes/2
  1947.  
  1948. ********
  1949.  
  1950. ;ROUTINE SWITCHES VISIBLE SCREEN AND CYCLES THE SCREENADRESSES
  1951. switch_screens:
  1952.     lea    scr,a1
  1953.     move.l    (a1)+,a0
  1954.     move.l    (a1)+,d1
  1955.     move.l    (a1),-4(a1)
  1956.     move.l    a0,(a1)
  1957.     move.l    d1,-8(a1)
  1958.     bsr    set_scradr
  1959.     rts
  1960.  
  1961. ******** DATA ********
  1962.  
  1963.     DATA
  1964.  
  1965. envobjadr:
  1966.     DC.L    torusobject_buf
  1967. envtextureadr:
  1968.     DC.L    texture_dat
  1969. torusobject_buf:
  1970.     INCBIN    DIABLO.DAT
  1971.     ;INCBIN    TORUS.DAT
  1972.     EVEN
  1973. texture_dat:
  1974.     INCBIN    FLAREWVE.APX
  1975.     ;INCBIN    FLAREPLS.APX
  1976.     ;INCBIN    FLARECLD.APX
  1977.     ;INCBIN    PSYCH.APX
  1978.     ;INCBIN    STONE.APX
  1979.     ;INCBIN    WOBBEL.APX
  1980.     ;INCBIN    BLOB2.RAW
  1981. sine_tbl:
  1982.     INCBIN    SINUS.DAT
  1983.  
  1984. ******** BSS ********
  1985.  
  1986.     BSS
  1987.  
  1988. boundbox_tbl:
  1989.     DS.W    8*3                * 8 points in box
  1990.  
  1991. points_tbl:
  1992.     DS.W    1                * number of 3d-points in object
  1993.     DS.W    pointsize*maxpoints        * X,Y,TX,TY,Z
  1994. pnttritbladr:
  1995.     DS.L    1
  1996. edgestbladr:
  1997.     DS.L    1
  1998. tritbladr:
  1999.     DS.L    1
  2000. normaltbladr:
  2001.     DS.L    1
  2002.  
  2003. temp_buf:
  2004.     DS.L    512*256
  2005.  
  2006. scr:    DS.L    3
  2007. scr_buf:
  2008.     DS.L    (scrsize/4)*3