home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Programming / Assembler / dse-src1.dms / in.adf / vector.s < prev    next >
Encoding:
Text File  |  1990-12-16  |  22.8 KB  |  1,091 lines

  1.     
  2.     section    code,code_c
  3.  
  4.     jmp    TETRAGON
  5.  
  6.  
  7.     TETRAGON:
  8.     
  9. res=320
  10. wpl=res/16
  11. color=0
  12. Botline=$c0
  13.     
  14.     *************************************************************
  15.     *                                                           *
  16.     *        3D GRAPHICS DRIVER, CONVERTED BY ANTIACTION        *
  17.     *                      OF TETRAGON                          *
  18.     *                                                           *
  19.     *                                                           *
  20.     *************************************************************
  21.     
  22.     s:
  23.     bsr    Start                ; Init screen stuff
  24.     bsr    Main                ; Do main stuff
  25.     bsr    Reset                ; Reset screen stuff
  26.     rts
  27.     
  28.     ****************************
  29.     * Pass upper screen to VDC *
  30.     *  while drawing the other *
  31.     ****************************
  32.     
  33.     pageup:
  34.     move.l    d0,-(a7)
  35.     move.l    #$70000,DrawPlane        ; Rastport structure
  36.     move.l    #$78000,d0            ; BitMap pointer
  37.     move.w    d0,LowBMPtr
  38.     swap    d0
  39.     move.w    d0,HiBMPtr            ; Copper fixes the rest
  40.     bsr    WaitBot
  41.     move.l    (a7)+,d0
  42.     rts
  43.     
  44.     ****************************
  45.     * Pass lower screen to VDC *
  46.     *  while drawing the other *
  47.     ****************************
  48.     
  49.     pagedown:
  50.     move.l    d0,-(a7)
  51.     move.l    #$78000,DrawPlane            ; Rastport structure
  52.     move.l    #$70000,d0            ; BitMap pointer
  53.     move.w    d0,LowBMPtr
  54.     swap    d0
  55.     move.w    d0,HiBMPtr            ; Copper fixes the rest
  56.     bsr    Waitbot
  57.     move.l    (a7)+,d0
  58.     rts
  59.     
  60.     WaitBot:
  61.     move.w    #$222,color
  62.     cmp.b    #BotLine,$dff006
  63.     bne.s    WaitBot
  64.     move.w    #$000,color
  65.     rts
  66.     
  67.     ********************
  68.     * Clear the screen *
  69.     ********************
  70.     
  71.     clwork:
  72.     btst    #14,$dff002
  73.     bne.s    ClWork
  74.     
  75.     move.l    DrawPlane,$dff054
  76.     move.l    #$01000000,$dff040
  77.     move.w    #0,$dff066
  78.     move.w    #200*64+wpl,$dff058
  79.     
  80.     move.w    #$0f0,color
  81.     rts
  82.     
  83.     ****************************
  84.     * Initialize stuff routine *
  85.     ****************************
  86.     
  87.     Start:
  88.     move.l    4.w,a6
  89.     jsr    -132(a6)
  90.     
  91.     lea    GfxName,a1
  92.     moveq    #0,d0
  93.     jsr    -552(a6)            ; Open Gfx Library
  94.     move.l    d0,GfxBase
  95.     
  96.     move.l    d0,a6
  97.     
  98.     move.l    $32(a6),OldCop
  99.     move.l    #Coplist,$32(a6)        ; Set coplist pointer
  100.     rts
  101.     
  102.     Reset:
  103.     move.l    GfxBase,a6
  104.     move.l    OldCop,$32(a6)
  105.     move.l    4.w,a6
  106.     jsr    -138(a6)
  107.     rts
  108.     
  109.     *******************************************************************
  110.     * Draw-line routine, The points are passed in D2,D3 (start point) *
  111.     * and A2, A3 (end point)                                          *
  112.     *******************************************************************
  113.     
  114.     Drawl:
  115.     movem.l    d0-d3/a0-a1,-(a7)
  116.     
  117.     move.l    d2,d0
  118.     move.l    d3,d1                ; X,y start
  119.     move.l    a2,d2
  120.     move.l    a3,d3                ; X,y end
  121.     bsr    Draw
  122.     
  123.     movem.l    (a7)+,d0-d3/a0-a1
  124.     rts
  125.     
  126.     ****************
  127.     * Blitter Line *
  128.     ****************
  129.     
  130.     Draw:
  131.     movem.l    d2-d7/a2-a3,-(a7)
  132.     moveq    #$f,d4
  133.     and.w    d2,d4                ; low 4 bits
  134.     sub.w    d3,d1                ; Height
  135.     mulu    #res/8,d3            ; Start address
  136.     sub.w    d2,d0                ; Width
  137.     blt.s    No1
  138.     tst.w    d1
  139.     blt.s    No2
  140.     cmp.w    d0,d1
  141.     bge.s    No3
  142.     moveq    #$11,d7
  143.     bra.s    OctSel                ; Octant #
  144.     No3:
  145.     moveq    #1,d7
  146.     exg    d1,d0
  147.     OctSel:
  148.     bra.s    No4
  149.     No2:
  150.     neg.w    d1
  151.     cmp.w    d0,d1
  152.     bge.s    Skip
  153.     moveq    #$19,d7
  154.     bra.s    No4
  155.     Skip:
  156.     moveq    #5,d7
  157.     exg    d1,d0
  158.     No4:
  159.     bra.s    OctsSel
  160.     No1:
  161.     neg.w    d0
  162.     tst.w    d1
  163.     blt.s    No11
  164.     
  165.     cmp.w    d0,d1
  166.     bge.s    No12
  167.     moveq    #$15,d7
  168.     bra.s    OctSel2
  169.     
  170.     No12:
  171.     moveq    #9,d7
  172.     exg    d1,d0
  173.     OctSel2:
  174.     bra.s    OctsSel
  175.     
  176.     No11:
  177.     neg.w    d1
  178.     cmp.w    d0,d1
  179.     bge.s    No13
  180.     moveq    #$1d,d7
  181.     bra.s    OctsSel
  182.     No13:
  183.     moveq    #$d,d7
  184.     exg    d1,d0
  185.     OctsSel:
  186.     add.w    d1,d1
  187.     asr.w    #3,d2
  188.     ext.l    d2
  189.     add.l    d2,d3                ; Total offset
  190.     move.w    d1,d2
  191.     sub.w    d0,d2
  192.     bge.s    NoMinus
  193.     ori.w    #$40,d7                ; Sign = -
  194.     NoMinus:
  195.     lea    $dff000,a0
  196.     move.w    d2,a3
  197.     move.w    #$ffff,d6            ; LinePtrn
  198.     WaitBl:
  199.     btst    #6,2(a0)
  200.     bne.s    WaitBl
  201.     move.w    d1,$62(a0)            ; 4Y
  202.     move.w    d2,d1
  203.     sub.w    d0,d1
  204.     move.w    d1,$64(a0)            ; 4Y-4X
  205.     moveq    #-1,d1
  206.     move.l    d1,$44(a0)            ; AFWM+ALWM
  207.     move.w    #res/8,$60(a0)            ; BitMap Width in bytes
  208.     move.w    d7,d5
  209.     addq.w    #1,d0
  210.     asl.w    #6,d0
  211.     addq.w    #2,d0                ; Blitsize
  212.     move.w    d4,d2
  213.     swap    d4
  214.     asr.l    #4,d4                ; First pixelpos
  215.     ori.w    #$b00,d4            ; Use ABD
  216.     move.w    #$8000,$74(a0)            ; Index
  217.     clr.w    d1
  218.     NoSpesh:
  219.     move.l    DrawPlane,d7            ; Pointer
  220.     swap    d5
  221.     move.w    d4,d5
  222.     move.b    #$ca,d5            ; MinTerms
  223.     swap    d5
  224.     add.l    d3,d7
  225.     WtBl2:
  226.     btst    #6,2(a0)
  227.     bne.s    WtBl2
  228.     move.l    d5,$40(a0)            ; BltCon0 & 1
  229.     move.w    a3,$52(a0)            ; 2Y-X
  230.     move.l    d7,$48(a0)
  231.     move.l    d7,$54(a0)            ; Start address of line
  232.     move.w    d6,$72(a0)            ; Pattern
  233.     move.w    d0,$58(a0)            ; Size
  234.     movem.l    (a7)+,d2-d7/a2-a3
  235.     rts
  236.     
  237.     *****************************************************
  238.     * Sine and cosine function, angle is passed in D0   *
  239.     * and the sine and cosine are returned in D1 and D2 *
  240.     *****************************************************
  241.     
  242.     sincos:
  243.     tst.w    d0                ; Angle neg. add 360°
  244.     bpl.s    NoAddi
  245.     add.w    #360,d0
  246.     noaddi:
  247.     move.l    #sintab,a1            ; Beginning ad. of sinetable
  248.     move.l    d0,d2                ; Angle in d0 and d2
  249.     lsl.w    #1,d0                ; Angle times 2 as index
  250.     move.w    0(a1,d0.w),d1            ; Sine to D1
  251.     cmp.w    #270,d2                ; Calc cosine through
  252.     blt.s    plus9                ; displacement of sine value
  253.     sub.w    #270,d2                ; by 90 degrees
  254.     bra    sendsin
  255.     plus9:
  256.     add.w    #90,d2
  257.     sendsin:
  258.     lsl.w    #1,d2
  259.     move.w    (a1,d2.w),d2            ; Cosine to D2
  260.     
  261.     rts                    ; And return
  262.     
  263.     *****************************************************
  264.     * Sine function                        *
  265.     * Angle is passed in d0 and the sine returned in D1 *
  266.     *****************************************************
  267.     
  268.     sin:
  269.     move.l    #sintab,a1
  270.     tst.w    d0
  271.     bpl.s    sin1
  272.     add.w    #360,d0
  273.     sin1:
  274.     lsl.w    #1,d0
  275.     move.w    (a1,d0.w),d1
  276.     rts
  277.     
  278.     *************************************************************
  279.     * Init the main diagonal of the result matrix with          *
  280.     * ones which were multiplied by 2^14. This subroutine must  *
  281.     * be called at least once before the call by rotate, or the *
  282.     * result matrix will only consist of zeros.                 *
  283.     *************************************************************
  284.     
  285.     matinit:
  286.     moveq    #0,d1
  287.     move.w    #16384,d2            ; The initial value for
  288.     move.w    d2,Matrix11            ; the main diagonal of
  289.     move.w    d1,Matrix12            ; the result matrix
  290.     move.w    d1,Matrix13            ; all other elements 
  291.     move.w    d1,Matrix21            ; at zero.
  292.     move.w    d2,Matrix22
  293.     move.w    d1,Matrix23
  294.     move.w    d1,Matrix31
  295.     move.w    d1,Matrix32
  296.     move.w    d2,Matrix33
  297.     rts
  298.     
  299.     ***************************************************************
  300.     * Multiplication of the rotation matrix by the rotation       *
  301.     * matrix for rotation about the X-Axis                        *
  302.     ***************************************************************
  303.     
  304.     xrotate:
  305.     move.w    XAngle,d0        ; Multiply matrix11-matrix33
  306.     jsr    SinCos            ; with the rotation matrix
  307.     move.w    d1,sinx            ; for a rotation about the X-Axis
  308.     move.w    d2,cosx
  309.     move.w    d1,d3
  310.     move.w    d2,d4
  311.     move.w    Matrix11,Rotx11        ; The first column of the matrix
  312.     move.w    Matrix21,Rotx21        ; Does not change with X rotation
  313.     move.w    Matrix31,Rotx31
  314.     muls    Matrix12,d2
  315.     muls    Matrix13,d1
  316.     sub.l    d1,d2
  317.     lsl.l    #2,d2
  318.     swap    d2
  319.     move.w    d2,Rotx12
  320.     move.w    d3,d1
  321.     move.w    d4,d2
  322.     muls    Matrix22,d2
  323.     muls    Matrix23,d1
  324.     sub.l    d1,d2
  325.     lsl.l    #2,d2
  326.     swap    d2
  327.     move.w    d2,rotx22
  328.     move.w    d3,d1
  329.     move.w    d4,d2
  330.     muls    Matrix32,d2
  331.     muls    Matrix33,d1
  332.     sub.l    d1,d2
  333.     lsl.l    #2,d2
  334.     swap    d2
  335.     move.w    d2,Rotx32
  336.     move.w    d3,d1
  337.     move.w    d4,d2
  338.     muls    Matrix12,d1
  339.     muls    Matrix13,d2
  340.     add.l    d1,d2
  341.     lsl.l    #2,d2
  342.     swap    d2
  343.     move.w    d2,Rotx13
  344.     move.w    d3,d1
  345.     move.w    d4,d2
  346.     muls    Matrix22,d1
  347.     muls    Matrix23,d2
  348.     add.l    d1,d2
  349.     lsl.l    #2,d2
  350.     swap    d2
  351.     move.w    d2,Rotx23
  352.     muls    Matrix32,d3
  353.     muls    Matrix33,d4
  354.     add.l    d3,d4
  355.     lsl.l    #2,d4
  356.     swap    d4
  357.     move.w    d4,Rotx33
  358.     move.l    #Rotx11,a1
  359.     move.l    #Matrix11,a2
  360.     moveq    #8,d7            ; Number of matrix elements
  361.     
  362.     roxlop1:
  363.     move.w    (a1)+,(a2)+        ; Copy result matrix, which
  364.     dbra    d7,roxlop1        ; is still in ROTXnn, to MATRIXnn
  365.     rts
  366.     
  367.     ***********************************************************
  368.     * Multiply the general rotation matrix by the Y-axis      *
  369.     * rotation matrix. Results are stored in the general      *
  370.     * rotation matrix                      *
  371.     ***********************************************************
  372.     
  373.     yrotate:
  374.     move.w    YAngle,d0        ; Angle around which rotation is made
  375.     jsr    SinCos
  376.     move.w    d1,siny
  377.     move.w    d2,cosy
  378.     move.w    d1,d3            ; Sine of Y-Angle
  379.     move.w    d2,d4            ; Cosine of Y-angle
  380.     
  381.     muls    Matrix11,d2
  382.     muls    Matrix13,d1
  383.     add.l    d1,d2
  384.     lsl.l    #2,d2
  385.     swap    d2
  386.     move.w    d2,Rotx11
  387.     move.w    d3,d1
  388.     move.w    d4,d2
  389.     
  390.     muls    Matrix21,d2
  391.     muls    Matrix23,d1
  392.     add.l    d1,d2
  393.     lsl.l    #2,d2
  394.     swap    d2
  395.     move.w    d2,Rotx21
  396.     move.w    d3,d1
  397.     move.w    d4,d2
  398.     
  399.     muls    Matrix31,d2
  400.     muls    Matrix33,d1
  401.     add.l    d1,d2
  402.     lsl.l    #2,d2
  403.     swap    d2
  404.     move.w    d2,Rotx31
  405.     neg.w    d3
  406.     move.w    d3,d1                ; -siny in the rotation mat.
  407.     move.w    d4,d2
  408.     
  409.     move.w    Matrix12,Rotx12
  410.     move.w    Matrix22,Rotx22            ; The second column
  411.     move.w    Matrix32,Rotx32            ; of the starting matrix
  412.                         ; does not change.
  413.     muls    Matrix11,d1
  414.     muls    Matrix13,d2
  415.     add.l    d1,d2
  416.     lsl.l    #2,d2
  417.     swap    d2
  418.     move.w    d2,Rotx13
  419.     move.w    d3,d1
  420.     move.w    d4,d2
  421.     
  422.     muls    Matrix21,d1
  423.     muls    Matrix23,d2
  424.     add.l    d1,d2
  425.     lsl.l    #2,d2
  426.     swap    d2
  427.     move.w    d2,Rotx23
  428.     
  429.     muls    Matrix31,d3
  430.     muls    Matrix33,d4
  431.     add.l    d3,d4
  432.     lsl.l    #2,d4
  433.     swap    d4
  434.     move.w    d4,Rotx33
  435.     
  436.     moveq    #8,d7
  437.     
  438.     move.l    #Rotx11,a1            ; Address of result matrix
  439.     move.l    #Matrix11,a2            ; Address of original matrix
  440.     
  441.     yrotlop1:
  442.     move.w    (a1)+,(a2)+            ; Copy result matrix
  443.     dbra    d7,yrotlop1            ; to original matrix
  444.     rts
  445.     
  446.     ********************************************
  447.     * Z-axis - Rotation matrix multiplications *
  448.     ********************************************
  449.     
  450.     zrotate:
  451.     move.w    ZAngle,d0
  452.     jsr    SinCos
  453.     move.w    d1,SinZ
  454.     move.w    d2,CosZ
  455.     move.w    d1,d3
  456.     move.w    d2,d4
  457.     
  458.     muls    Matrix11,d2
  459.     muls    Matrix12,d1
  460.     sub.l    d1,d2
  461.     lsl.l    #2,d2
  462.     swap    d2
  463.     move.w    d2,Rotx11
  464.     move.w    d3,d1
  465.     move.w    d4,d2
  466.     
  467.     muls    Matrix21,d2
  468.     muls    Matrix22,d1
  469.     sub.l    d1,d2
  470.     lsl.l    #2,d2
  471.     swap    d2
  472.     move.w    d2,Rotx21
  473.     move.w    d3,d1
  474.     move.w    d4,d2
  475.     
  476.     muls    Matrix31,d2
  477.     muls    Matrix32,d1
  478.     sub.l    d1,d2
  479.     lsl.l    #2,d2
  480.     swap    d2
  481.     move.w    d2,Rotx31
  482.     move.w    d3,d1
  483.     move.w    d4,d2
  484.     
  485.     muls    Matrix11,d1
  486.     muls    Matrix12,d2
  487.     add.l    d1,d2
  488.     lsl.l    #2,d2
  489.     swap    d2
  490.     move.w    d2,Rotx12
  491.     move.w    d3,d1
  492.     move.w    d4,d2
  493.     
  494.     muls    Matrix21,d1
  495.     muls    Matrix22,d2
  496.     add.l    d1,d2
  497.     lsl.l    #2,d2
  498.     swap    d2
  499.     move.w    d2,Rotx22
  500.     
  501.     muls    Matrix31,d3
  502.     muls    Matrix32,d4
  503.     add.l    d3,d4
  504.     lsl.l    #2,d4
  505.     swap    d4
  506.     move.w    d4,Rotx32
  507.     
  508.     move.w    Matrix13,Rotx13            ; The third column remains
  509.     move.w    Matrix23,Rotx23            ; Unchanged
  510.     move.w    Matrix33,Rotx33
  511.     
  512.     moveq    #8,d7
  513.     move.l    #Rotx11,a1
  514.     move.l    #Matrix11,a2
  515.     
  516.     zrotlop1:
  517.     move.w    (a1)+,(a2)+            ; Copy to general
  518.     dbra    d7,zrotlop1            ; rotation matrix
  519.     rts
  520.     
  521.     **************************************************************
  522.     * Multiply every point whose Array address is in datx etc.   *
  523.     * by previous translation of the coordinate source to        *
  524.     * point [offx,offy,offz], with the general rotation matrix.  *
  525.     * The coordinate source of the result coordinates is then    *
  526.     * moved to point [xoffs,yoffs,zoffs]                         *
  527.     **************************************************************
  528.     
  529.     rotate:
  530.     move.w    NumMark,d0            ; Number of points to be
  531.     ext.l    d0                ; transformed as counter
  532.     subq.l    #1,d0
  533.     
  534.     move.l    datx,a1
  535.     move.l    daty,a2
  536.     move.l    datz,a3
  537.     
  538.     move.l    pointx,a4
  539.     move.l    pointy,a5
  540.     move.l    pointz,a6
  541.     
  542.     rotate1:
  543.     move.w    (a1)+,d1            ; X-Coordinate
  544.     add.w    Offx,d1
  545.     move.w    d1,d4
  546.     
  547.     move.w    (a2)+,d2            ; Y-Coordinate
  548.     add.w    Offy,d2            ; Translation to point[offx,offy,offz]
  549.     move.w    d2,d5
  550.     
  551.     move.w    (a3)+,d3            ; Z-Coordinate
  552.     add.w    offz,d3
  553.     move.w    d3,d6
  554.     
  555.     muls    Matrix11,d1
  556.     muls    Matrix21,d2
  557.     muls    Matrix31,d3
  558.     
  559.     add.l    d1,d2
  560.     add.l    d2,d3
  561.     lsl.l    #2,d3
  562.     swap    d3
  563.     add.w    xoffs,d3
  564.     move.w    d3,(a4)+            ; Rotated X-Coordinate
  565.     
  566.     move.w    d4,d1
  567.     move.w    d5,d2
  568.     move.w    d6,d3
  569.     
  570.     muls    Matrix12,d1
  571.     muls    Matrix22,d2
  572.     muls    Matrix32,d3
  573.     add.l    d1,d2
  574.     add.l    d2,d3
  575.     lsl.l    #2,d3
  576.     swap    d3
  577.     add.w    yoffs,d3
  578.     move.w    d3,(a5)+        ; Rotated Y-Coordinate
  579.     
  580.     muls    Matrix13,d4
  581.     muls    Matrix23,d5
  582.     muls    Matrix33,d6
  583.     add.l    d4,d5
  584.     add.l    d5,d6
  585.     lsl.l    #2,d6
  586.     swap    d6
  587.     add.w    Zoffs,d6
  588.     move.w    d6,(a6)+        ; Rotated Z-Coordinate
  589.     
  590.     dbra    d0,rotate1
  591.     rts
  592.     
  593.     *********************************************************************
  594.     * Perspective, calculated from the transformed points in the arrays *
  595.     * pointx, pointy and pointz the screen coordinates, which           *
  596.     * are then stored in the arrays xplot and yplot.                    *
  597.     *********************************************************************
  598.     
  599.     pers:
  600.     move.l    pointx,a1        ; Beginning address of point arrays
  601.     move.l    pointy,a2
  602.     move.l    pointz,a3
  603.     
  604.     move.l    xplot,a4        ; Start address of display coordinate
  605.     move.l    yplot,a5        ; array.
  606.     
  607.     move.w    NumMark,d0        ; Number of points to be transformed
  608.     ext.l    d0
  609.     subq.l    #1,d0
  610.     
  611.     perlop:
  612.     move.w    (a3)+,d5        ; Z-coordinate of object
  613.     move.w    d5,d6
  614.     move.w    Dist,d4            ; Enlargement factor
  615.     sub.w    d5,d4            ; Dist minus Z-coordinate of obj.coord
  616.     ext.l    d4
  617.     lsl.l    #8,d4            ; Times 256 for value fitting
  618.     move.w    Zobs,d3            ; Projection center Z-coordinates
  619.     ext.l    d3
  620.     
  621.     sub.l    d6,d3            ; Minus z-coordinate of object
  622.     bne.s    pers1
  623.     
  624.     moveq    #0,d1            ; Catch division by zero
  625.     addq.l    #2,a1
  626.     addq.l    #2,a2
  627.     move.w    d1,(a4)+
  628.     move.w    d1,(a5)+
  629.     bra.s    perend1
  630.     
  631.     pers1:
  632.     divs    d3,d4
  633.     move.w    d4,d3
  634.     move.w    (a1)+,d1        ; X-Coordinate of object
  635.     move.w    d1,d2
  636.     neg.w    d1
  637.     muls    d1,d3            ; Multiplied by perspective factor
  638.     lsr.l    #8,d3            ; /256 save value fitting
  639.     
  640.     add.w    d3,d2            ; Add to x-coordinate
  641.     add.w    x0,d2            ; Add screen offset (center point)
  642.     move.w    d2,(a4)+        ; Display X-coordinate
  643.     
  644.     move.w    (a2)+,d1        ; Y-Coordinate of object
  645.     move.w    d1,d2
  646.     neg.w    d1
  647.     muls    d1,d4
  648.     lsr.l    #8,d4            ; /256
  649.     
  650.     add.w    d4,d2
  651.     neg.w    d2            ; Display offset, mirror of Y-Axis
  652.     add.w    y0,d2            ; Source at [X0,Y0]
  653.     move.w    d2,(a5)+        ; Display Y-Coordinate
  654.     perend1:
  655.     dbra    d0,perlop        ; Until all points transformed
  656.     
  657.     move.w    #$ff0,color
  658.     rts
  659.     
  660.     *******************************************************
  661.     * Draw number of lines from array from lines in linxy *
  662.     *******************************************************
  663.     
  664.     drawn1:
  665.     move.l    XPlot,a4        ; Display X-Coordinate
  666.     move.l    YPlot,a5        ; Display Y-Coordinate
  667.     move.w    numline,d0        ; Number of lines
  668.     ext.l    d0
  669.     subq.l    #1,d0            ; As counter
  670.     move.l    linxy,a6        ; Address of line array
  671.     
  672.     drlop:
  673.     move.l    (a6)+,d1        ; First line (P1,P2)
  674.     subq.w    #1,d1            ; Fit to list structure
  675.     lsl.w    #1,d1            ; Times list element length (2)
  676.     move.w    (a4,d1.w),d2        ; X-Coordinate of 2nd point
  677.     move.w    (a5,d1.w),d3        ; Y-Coordinate of second point
  678.     swap    d1
  679.     subq.w    #1,d1
  680.     lsl.w    #1,d1
  681.     move.w    (a4,d1.w),a2        ; X-Coordinate of first point
  682.     move.w    (a5,d1.w),a3        ; Y-Coordinate of first point
  683.     bsr    Drawl            ; Draw line from P1 to P2
  684.     dbra    d0,drlop        ; Until all lines drawn
  685.     rts
  686.     
  687.     ************************
  688.     * Simple counting loop *
  689.     ************************
  690.     
  691.     wait1:
  692.     dbra    d0,wait1        ; Delay loop
  693.     rts
  694.     
  695.     ***********************************
  696.     * Variables for the basic program *
  697.     ***********************************
  698.     
  699.     * Sine table starts here
  700.     
  701.     sintab:
  702.     dc.w    0,286,572,857,1143,1428,1713,1997,2280
  703.     dc.w    2563,2845,3126,3406,3686,3964,4240,4516
  704.     dc.w    4790,5063,5334,5604,5872,6138,6402,6664
  705.     dc.w    6924,7182,7438,7692,7943,8192,8438,8682
  706.     dc.w    8923,9162,9397,9630,9860,10087,10311,10531
  707.     dc.w    10749,10963,11174,11381,11585,11786,11982,12176
  708.     dc.w    12365,12551,12733,12911,13085,13255,13421,13583
  709.     dc.w    13741,13894,14044,14189,14330,14466,14598,14726
  710.     dc.w    14849,14962,15082,15191,15296,15396,15491,15582
  711.     dc.w    15668,15749,15826,15897,15964,16026,16083,16135
  712.     dc.w    16182,16225,16262,16294,16322,16344,16362,16374
  713.     dc.w    16382,16383
  714.     
  715.     dc.w    16382,16374,16362,16344,16322,16294,16262,16225
  716.     dc.w    16182
  717.     dc.w    16135,16083,16026,15964,15897,15826,15749,15668
  718.     dc.w    15582,15491,15396,15296,15191,15082,14962,14849
  719.     dc.w    14726,14598,14466,14330,14189,14044,13894,13741
  720.     dc.w    13583,13421,13255,13085,12911,12733,12551,12365
  721.     dc.w    12176,11982,11786,11585,11381,11174,10963,10749
  722.     dc.w    10531,10311,10087,9860,9630,9397,9162,8923
  723.     dc.w    8682,8438,8192,7943,7692,7438,7182,6924
  724.     dc.w    6664,6402,6138,5872,5604,5334,5063,4790
  725.     dc.w    4516,4240,3964,3686,3406,3126,2845,2563
  726.     dc.w    2280,1997,1713,1428,1143,857,572,286,0
  727.     
  728.     dc.w    -286,-572,-857,-1143,-1428,-1713,-1997,-2280
  729.     dc.w    -2563,-2845,-3126,-3406,-3686,-3964,-4240,-4516
  730.     dc.w    -4790,-5063,-5334,-5604,-5872,-6138,-6402,-6664
  731.     dc.w    -6924,-7182,-7438,-7692,-7943,-8192,-8438,-8682
  732.     dc.w    -8923,-9162,-9397,-9630,-9860,-10087,-10311,-10531
  733.     dc.w    -10749,-10963,-11174,-11381,-11585,-11786,-11982,-12176
  734.     dc.w    -12365,-12551,-12733,-12911,-13085,-13255,-13421,-13583
  735.     dc.w    -13741,-13894,-14044,-14189,-14330,-14466,-14598,-14726
  736.     dc.w    -14849,-14962,-15082,-15191,-15296,-15396,-15491,-15582
  737.     dc.w    -15668,-15749,-15826,-15897,-15964,-16026,-16083,-16135
  738.     dc.w    -16182,-16225,-16262,-16294,-16322,-16344,-16362,-16374
  739.     dc.w    -16382,-16383
  740.     
  741.     dc.w    -16382,-16374,-16362,-16344,-16322,-16294,-16262,-16225
  742.     dc.w    -16182
  743.     dc.w    -16135,-16083,-16026,-15964,-15897,-15826,-15749,-15668
  744.     dc.w    -15582,-15491,-15396,-15296,-15191,-15082,-14962,-14849
  745.     dc.w    -14726,-14598,-14466,-14330,-14189,-14044,-13894,-13741
  746.     dc.w    -13583,-13421,-13255,-13085,-12911,-12733,-12551,-12365
  747.     dc.w    -12176,-11982,-11786,-11585,-11381,-11174,-10963,-10749
  748.     dc.w    -10531,-10311,-10087,-9860,-9630,-9397,-9162,-8923
  749.     dc.w    -8682,-8438,-8192,-7943,-7692,-7438,-7182,-6924
  750.     dc.w    -6664,-6402,-6138,-5872,-5604,-5334,-5063,-4790
  751.     dc.w    -4516,-4240,-3964,-3686,-3406,-3126,-2845,-2563
  752.     dc.w    -2280,-1997,-1713,-1428,-1143,-857,-572,-286,0
  753.     
  754.     x0:dc.w    0
  755.     y0:dc.w    0
  756.     z0:dc.w    0
  757.     z1:dc.w    0
  758.     
  759.     linxy:dc.l    0        ; Address of line array
  760.     
  761.     nummark:dc.w    0        ; Number of points
  762.     numline:dc.w    0        ; Number of lines
  763.     
  764.     pointx:dc.l    0        ; Variables of point arrays for world,
  765.     pointy:dc.l    0        ; view, and screen coordinates
  766.     pointz:dc.l    0
  767.     
  768.     xplot:dc.l    0
  769.     yplot:dc.l    0
  770.     
  771.     datx:dc.l    0
  772.     daty:dc.l    0
  773.     datz:dc.l    0
  774.     
  775.     sinx:dc.w    0        ; Temporary storage for sin & cos
  776.     siny:dc.w    0        ; values
  777.     sinz:dc.w    0
  778.     
  779.     cosx:dc.w    0
  780.     cosy:dc.w    0
  781.     cosz:dc.w    0
  782.     
  783.     var1:dc.w    0        ; General variables
  784.     var2:dc.w    0
  785.     var3:dc.w    0
  786.     
  787.     xangle:dc.w    0        ; Variables for passing angles
  788.     yangle:dc.w    0        ; to the rotation subroutine
  789.     zangle:dc.w    0
  790.     
  791.     leftx:dc.w    0
  792.     lefty:dc.w    0
  793.     rightx:dc.w    0
  794.     righty:dc.w    0
  795.     
  796.     dist:dc.w    0
  797.     zobs:dc.w    1500
  798.     
  799.     rotx11:dc.w    16384        ; Space here for the result matrix
  800.     rotx12:dc.w    0        ; of matrix multiplication
  801.     rotx13:dc.w    0
  802.     rotx21:dc.w    0
  803.     rotx22:dc.w    16384
  804.     rotx23:dc.w    0
  805.     rotx31:dc.w    0
  806.     rotx32:dc.w    0
  807.     rotx33:dc.w    16384
  808.     
  809.     matrix11:dc.w    0        ; Space here for the general rotation
  810.     matrix12:dc.w    0        ; matrix
  811.     matrix13:dc.w    0
  812.     matrix21:dc.w    0
  813.     matrix22:dc.w    0
  814.     matrix23:dc.w    0
  815.     matrix31:dc.w    0
  816.     matrix32:dc.w    0
  817.     matrix33:dc.w    0
  818.     
  819.     DrawPlane:dc.l    0
  820.     
  821.     CopList:
  822.     dc.w    $0180,$0000,$0182,$fff
  823.     dc.w    $0100,res/321*32768+$1200,$00e0
  824.     hibmptr:
  825.     dc.w    $0007,$00e2
  826.     lowbmptr:
  827.     dc.w    $0000,$0092,$0038,$0094,$00d0
  828.     dc.w    $008e,$2c81,$0090,$f4c1
  829.     dc.w    $0120
  830.     sp1h:dc.w 0,$0122
  831.     sp1l:dc.w 0,$0124
  832.     sp2h:dc.w 0,$0126
  833.     sp2l:dc.w 0,$0128
  834.     sp3h:dc.w 0,$012a
  835.     sp3l:dc.w 0,$012c,0,$012e,0,$0130,0,$0132,0,$0134,0
  836.     dc.w $0136,0,$0138,0,$013a,0,$013c,0,$013e,0
  837.     
  838.     dc.w    $ffff,$fffe
  839.     
  840.     GfxName:
  841.     dc.b    "graphics.library",0
  842.     even
  843.     
  844.     GfxBase:dc.l    0
  845.     
  846.     OldCop:dc.l    0
  847.     
  848.     Main:
  849.     bsr    GetReso
  850.     
  851.     bsr    MakeWrld        ; Create the world system
  852.     bsr    WorldSet        ; Pass the world parameters
  853.     
  854.     bsr    SetRotDp        ; Init obs.ref.point
  855.     bsr    PageUp
  856.     bsr    ClWork
  857.     bsr    PageDown
  858.     bsr    ClWork            ; Init both pages
  859.     
  860.     bsr    inp_chan        ; Input and change parameters
  861.     move.w    #2047,dist
  862.     
  863.     mainlop1:
  864.     BTST    #$0A,$DFF016
  865.     BEQ.S    MAINLOP1
  866.     bsr    PointRot
  867.     bsr    Pers            ; Do Perspective
  868.     bsr    DrawN1            ; Draw It
  869.     bsr    PageUp            ; Display It
  870.     
  871.     bsr    Inp_Chan        ; Input new parameters
  872.     bsr    ClWork
  873.     bsr    PointRot        ; Rotate
  874.     bsr    Pers            ; Perspective
  875.     bsr    DrawN1            ; Drawit
  876.     bsr    PageDown
  877.     bsr    Inp_Chan        ; Input Parameters
  878.     bsr    ClWork
  879.     btst    #6,$bfe001
  880.     bne.s    mainlop1
  881.     
  882.     mainend:
  883.     bsr    PageUp
  884.     rts
  885.     
  886.     inp_chan:
  887.     addq.w    #1,Hyangle
  888.     addq.w    #1,Hzangle
  889.     cmp.w    #360,Hyangle
  890.     blt.s    Nosub
  891.     sub.w    #360,Hyangle
  892.     NosuB:
  893.     cmp.w    #360,hzangle
  894.     blt.s    Nosubz
  895.     sub.w    #360,Hzangle
  896.     NosuBz:
  897.     sub.w    #10,Dist
  898.     cmp.w    #-1000,Dist
  899.     bgt.s    NoClr
  900.     move.w    #-1000,Dist
  901.     NoClr:
  902.     move.w    #$00f,color
  903.     rts
  904.     
  905.     ************************************************
  906.     * Init the rotation reference point to [0,0,0] *
  907.     ************************************************
  908.     
  909.     setrotdp:
  910.     moveq    #0,d1
  911.     move.w    d1,rotdpx
  912.     move.w    d1,rotdpy
  913.     move.w    d1,rotdpz
  914.     move.w    #0,hyangle        ; Start rotation angle
  915.     move.w    #0,hxangle
  916.     move.w    #0,hzangle
  917.     rts
  918.     
  919.     ***********************************************************
  920.     * Rotation around one point, the rotation reference point *
  921.     ***********************************************************
  922.     
  923.     pointrot:
  924.     move.w    Hxangle,xangle    ; Rotate the world around the angle
  925.     move.w    hyangle,yangle    ; hxangle, hyangle, hzangle about the
  926.     move.w    hzangle,zangle
  927.     move.w    rotdpx,d0    ; Rotation reference point
  928.     move.w    rotdpy,d1
  929.     move.w    rotdpz,d2
  930.     move.w    d0,xoffs
  931.     move.w    d1,yoffs
  932.     move.w    d2,zoffs    ; Add for back transformation
  933.     neg.w    d0
  934.     neg.w    d1
  935.     neg.w    d2
  936.     move.w    d0,offx        ; Subtract for transformation
  937.     move.w    d1,offy
  938.     move.w    d2,offz
  939.     bsr    Matinit
  940.     bsr    zrotate
  941.     bsr    yrotate
  942.     bsr    xrotate
  943.     bsr    rotate
  944.     move.w    #$f00,color
  945.     rts
  946.     
  947.     *****************************************************
  948.     * Creation of the world system from the object data *
  949.     *****************************************************
  950.     
  951.     Makewrld:
  952.     move.l    #ObjDatx,a1        ; Create the world system by
  953.     move.l    #ObjDaty,a2
  954.     move.l    #ObjDatz,a3
  955.     move.l    #worldx,a4
  956.     move.l    #worldy,a5
  957.     move.l    #worldz,a6
  958.     move.w    hnummark,d0
  959.     ext.l    d0
  960.     subq.l    #1,d0
  961.     makewl1:
  962.     move.w    (a1)+,(a4)+        ; Copying the object data into the
  963.     move.w    (a2)+,(a5)+        ; world data
  964.     move.w    (a3)+,(a6)+
  965.     dbra    d0,makewl1
  966.     move.w    hnumline,d0
  967.     ext.l    d0
  968.     subq.l    #1,d0
  969.     move.l    #ObjLin,a1
  970.     move.l    #wlinxy,a2
  971.     makewl2:
  972.     move.l    (a1)+,(a2)+
  973.     dbra    d0,makewl2
  974.     rts
  975.     
  976.     ***********************************************
  977.     * Pass the world parameters to base variables *
  978.     ***********************************************
  979.     
  980.     worldset:
  981.     move.l    #Worldx,datx        ; Pass variables for rotation routine
  982.     move.l    #worldy,daty
  983.     move.l    #Worldz,datz
  984.     move.l    #viewx,pointx
  985.     move.l    #viewy,pointy
  986.     move.l    #viewz,pointz
  987.     move.l    #wlinxy,linxy
  988.     move.w    PictureX,x0
  989.     move.w    Picturey,Y0
  990.     move.w    proz,zobs
  991.     move.w    r1z1,dist
  992.     move.l    #screenx,xplot
  993.     move.l    #screeny,yplot
  994.     move.w    hnumline,numline
  995.     move.w    hnummark,nummark
  996.     rts
  997.     
  998.     getReso:
  999.     move.w    #res/2,PictureX
  1000.     move.w    #100,pictureY
  1001.     rts
  1002.     
  1003.     *****************
  1004.     * variable data *
  1005.     *****************
  1006.     
  1007.     *********************
  1008.     * Object definition *
  1009.     *********************
  1010.     
  1011.     ObjDatx:
  1012.     dc.w    0,40,0,-40,-15,0,15,0,-15,15
  1013.     dc.w    0,35,0,-35
  1014.     
  1015.     ObjDaty:
  1016.     dc.w    40,0,-40,0,15,15,15,-25,10,10
  1017.     dc.w    35,0,-35,0
  1018.     
  1019.     ObjDatz:
  1020.     dc.w    0,0,0,0,10,10,10,10,10,10
  1021.     dc.w    20,20,20,20
  1022.     
  1023.     ***** What points should be connected with lines? ****
  1024.     
  1025.     ObjLin:
  1026.     dc.w    1,2, 2,3, 3,4, 4,1, 5,7, 6,8, 5,9, 7,10
  1027.     dc.w    11,12, 12,13, 13,14, 14,11, 1,11, 2,12
  1028.     dc.w    3,13,4,14
  1029.     
  1030.     hnummark:dc.w    14    ; Number of corner points of the object
  1031.     hnumline:dc.w    16    ; Number of lines in the object
  1032.     
  1033.     hxangle:dc.w    0    ; Rotation angle of the object around X axis
  1034.     hyangle:dc.w    0
  1035.     hzangle:dc.w    0
  1036.     
  1037.     xwplus:dc.w    0    ; Angle increment around x axis
  1038.     ywplus:dc.w    0
  1039.     zwplus:dc.w    0
  1040.     
  1041.     picturex:dc.w    res
  1042.     picturey:dc.w    100    ; Origin location on screen
  1043.     
  1044.     rotdpx:dc.w    0
  1045.     rotdpy:dc.w    0
  1046.     rotdpz:dc.w    0    ; Rotation datum point
  1047.     
  1048.     r1z1:dc.w    0
  1049.     normz:dc.w    1500
  1050.     
  1051.     plusrot:dc.l    0
  1052.     first:dc.l    0
  1053.     second:dc.w    0
  1054.     delta1:dc.w    0
  1055.     
  1056.     flag:dc.b    1
  1057.     even
  1058.     
  1059.     diffz:dc.w    0
  1060.     dx:dc.w        0
  1061.     dy:dc.w        0
  1062.     dz:dc.w        0
  1063.     
  1064.     worldx:dcb.w    100,0    ; World coordinate array
  1065.     worldy:dcb.w    100,0
  1066.     worldz:dcb.w    100,0
  1067.     
  1068.     viewx:dcb.w    100,0    ; View coordinate array
  1069.     viewy:dcb.w    100,0
  1070.     viewz:dcb.w    100,0
  1071.     
  1072.     screenx:dcb.w    100,0    ; Display coordinate array
  1073.     screeny:dcb.w    100,0
  1074.     
  1075.     wlinxy:dcb.l    300,0    ; Line array
  1076.     
  1077.     prox:dc.w    0    ; Coordinates of the projection center
  1078.     proy:dc.w    0    ; on the positive Z-axis
  1079.     proz:dc.w    2000
  1080.     
  1081.     offx:dc.w    0
  1082.     offy:dc.w    0
  1083.     offz:dc.w    0
  1084.     xoffs:dc.w    0
  1085.     yoffs:dc.w    0
  1086.     zoffs:dc.w    0
  1087.     
  1088.     loopc:dc.l    0
  1089.     end:
  1090.  
  1091.