home *** CD-ROM | disk | FTP | other *** search
/ The Fred Fish Collection 1.5 / ffcollection-1-5-1992-11.iso / ff_disks / 300-399 / ff321.lzh / Turtle / sources / TurtleLibrary.asm < prev   
Assembly Source File  |  1990-02-27  |  15KB  |  717 lines

  1. ;
  2. ; Turtle-Library V3.0
  3. ;
  4. ; 04.01.90
  5. ;
  6. ; Thomas Albers
  7. ;
  8.  
  9.     INCDIR    "DevpacAm:include/"
  10.     
  11.     INCLUDE    "exec.offsets"
  12.     INCLUDE    "graphics.offsets"
  13.     INCLUDE    "mathffp.offsets"
  14.     INCLUDE    "mathtrans.offsets"
  15.     
  16.     INCLUDE    "exec/types.i"
  17.     INCLUDE    "exec/alerts.i"
  18.     INCLUDE    "exec/initializers.i"
  19.     INCLUDE    "exec/libraries.i"
  20.     INCLUDE    "exec/lists.i"
  21.     INCLUDE    "exec/resident.i"
  22.     
  23.     INCLUDE    "graphics/rastport.i"
  24.     
  25. ExecBase    =    4
  26.     
  27.     
  28.     ;TurtleBase
  29.     
  30.     STRUCTURE TurtleBase,LIB_SIZE
  31.     ULONG    tb_SegList        ;pointer to Segment List,
  32.     ULONG    tb_GfxBase        ; to Graphics Library,
  33.     ULONG    tb_FFPBase        ; to MathFFP Library,
  34.     ULONG    tb_FFPTBase        ; and to MathTrans Library
  35.     LABEL    TurLib_SIZEOF
  36.  
  37.     ;TurtleHandle
  38.  
  39.     STRUCTURE TurtleHandle,0
  40.     APTR    th_RastPort        ;pointer to RastPort
  41.     FLOAT    th_xPosition        ;x Position (FFP)
  42.     FLOAT    th_yPosition        ;y Position (FFP)
  43.     UWORD    th_angle            ;angle of Turtle
  44.     UWORD    th_xStart        ;initial x
  45.     UWORD    th_yStart        ;initial y
  46.     UWORD    th_aStart        ;initial angle
  47.     UBYTE    th_Flags            ;flags
  48.     UBYTE    th_FlagStart        ;initial flags
  49.     STRUCT    th_PointArray,12        ;points of Turtle triangle
  50.     LABEL    TurtleHandle_SIZEOF
  51.  
  52.     ;Flags
  53.  
  54.     BITDEF    Tur,Hide,0        ;turtle hidden
  55.     BITDEF    Tur,Up,1            ;pen Up
  56.     BITDEF    Tur,xComp,2        ;x compression
  57.     BITDEF    Tur,yComp,3        ;y compression 
  58.     BITDEF    Tur,TValid,7        ;triangle valid
  59.  
  60.     ;if someone tried to run this
  61. Start:
  62.     MOVEQ    #0,D0
  63.     RTS
  64.  
  65. Priority    =    0
  66. Version    =    3
  67. Revision    =    2
  68.  
  69.     ;Resident structure for Library
  70. Resident:
  71.     DC.W    RTC_MATCHWORD        ;magic value
  72.     DC.L    Resident            ;pointer to beginning
  73.     DC.L    EndCode            ; and end of structure
  74.     DC.B    RTF_AUTOINIT        ;type
  75.     DC.B    Version            ;version
  76.     DC.B    NT_LIBRARY        ;node type
  77.     DC.B    Priority            ;priority
  78.     DC.L    TurtName            ;library name
  79.     DC.L    InfoStrg            ;info string
  80.     DC.L    InitData            ;initialisisation data
  81.  
  82. TurtName    DC.B    "turtle.library",0
  83.  
  84. InfoStrg    DC.B    "turtle.library V3.2 (04 Jan 1990) by Thomas Albers",13,10,0
  85.  
  86. GfxName    DC.B    "graphics.library",0
  87. FFPName    DC.B    "mathffp.library",0
  88. FFPTName    DC.B    "mathtrans.library",0
  89.  
  90.     EVEN
  91.  
  92.     
  93. InitData:
  94.     DC.L    TurLib_SIZEOF        ;size of Library base
  95.     DC.L    FuncTable        ;function table
  96.     DC.L    DataTable        ;table for InitStruct
  97.     DC.L    LibInit            ;initialisation routine
  98.  
  99. FuncTable:
  100.     DC.L    Open
  101.     DC.L    Close
  102.     DC.L    Expunge
  103.     DC.L    ExtFunc
  104.     DC.L    CreateTurtle
  105.     DC.L    ReturnTurtle
  106.     DC.L    TurnLeft
  107.     DC.L    TurnRight
  108.     DC.L    PenUp
  109.     DC.L    PenDown
  110.     DC.L    HideTurtle
  111.     DC.L    ShowTurtle
  112.     DC.L    SetAngle
  113.     DC.L    SetPosition
  114.     DC.L    ResetTurtle
  115.     DC.L    Forward
  116.     DC.L    -1
  117.  
  118. DataTable:
  119.     INITBYTE    LN_TYPE,NT_LIBRARY
  120.     INITLONG    LN_NAME,TurtName
  121.     INITBYTE    LIB_FLAGS,LIBF_SUMUSED|LIBF_CHANGED
  122.     INITWORD    LIB_VERSION,Version
  123.     INITWORD    LIB_REVISION,Revision
  124.     INITLONG    LIB_IDSTRING,InfoStrg
  125.     DC.L    0
  126.  
  127. LibInit:
  128.     ;This routine is called after the library has been loaded from disk
  129.     ;D0: Pointer to Library
  130.     ;A0: Pointer to Segment list
  131.     
  132.     MOVEM.L    A5-A6,-(SP)
  133.     
  134.     MOVE.L    ExecBase,A6
  135.     
  136.     MOVE.L    D0,A5            ;pointer to Library
  137.     MOVE.L    A0,tb_SegList(A5)        ;save pointer to Segment list
  138.     
  139.     LEA    GfxName,A1        ;open Graphics Library
  140.     MOVEQ    #0,D0
  141.     JSR    _LVOOpenLibrary(A6)
  142.     MOVE.L    D0,tb_GfxBase(A5)
  143.     BEQ.S    .LibIni1            ;error?
  144.     
  145.     LEA    FFPName,A1        ;open MathFFP Library
  146.     MOVEQ    #0,D0
  147.     JSR    _LVOOpenLibrary(A6)
  148.     MOVE.L    D0,tb_FFPBase(A5)
  149.     BEQ.S    .LibIni2            ;error?
  150.     
  151.     LEA    FFPTName,A1        ;open MathTrans Library
  152.     MOVEQ    #0,D0
  153.     JSR    _LVOOpenLibrary(A6)
  154.     MOVE.L    D0,tb_FFPTBase(A5)
  155.     BEQ.S    .LibIni3            ;error?
  156.  
  157.     MOVE.L    A5,D0            ;allright, return Pointer to Library
  158.     MOVEM.L    (SP)+,A5-A6
  159.     RTS
  160.     
  161. .LibIni3    MOVE.L    tb_FFPBase(A5),A1        ;error, close Libraries
  162.     JSR    _LVOCloseLibrary(A6)
  163.     
  164. .LibIni2    MOVE.L    tb_GfxBase(A5),A1
  165.     JSR    _LVOCloseLibrary(A6)
  166.     
  167. .LibIni1    CLR.L    D0            ;and return 0
  168.     
  169.     MOVEM.L    (SP)+,A5-A6
  170.     RTS
  171.     
  172. Open:
  173.     ;This routine is called each time when the library is opened
  174.     ;A6: Pointer to Library
  175.     
  176.     ADDQ.W    #1,LIB_OPENCNT(A6)    ;increase Open count
  177.     BCLR    #LIBB_DELEXP,LIB_FLAGS(A6)    ;no Delayed Expunge
  178.     MOVE.L    A6,D0            ;return pointer to Library
  179.     RTS
  180.  
  181. Close:
  182.     ;This routine gets called each time the library is closed
  183.     ;A6: Pointer to Library
  184.     
  185.     SUBQ.W    #1,LIB_OPENCNT(A6)    ;decrease Open count
  186.     BNE.S    .Clos1            ;still open
  187.     
  188.     BTST    #LIBB_DELEXP,LIB_FLAGS(A6)    ;Delayed Expunge?
  189.     BNE.S    Expunge            ;yes, do it
  190.     
  191. .Clos1    CLR.L    D0            ;return 0 (no Expunge)
  192.     RTS
  193.     
  194. Expunge:
  195.     ;This routine is used to clear the library from memory
  196.     ;A6: Pointer to Library
  197.     
  198.     TST.W    LIB_OPENCNT(A6)        ;library still open?
  199.     BEQ.S    .Expung1            ;no, remove it
  200.     
  201.     BSET    #LIBB_DELEXP,LIB_FLAGS(A6)    ;set Delayed Expunge flag
  202.     CLR.L    D0            ;and return 0
  203.     RTS
  204.     
  205. .Expung1    MOVEM.L    D2-D3/A4-A6,-(SP)
  206.     
  207.     MOVE.L    A6,A5            ;pointer to library
  208.     MOVE.L    ExecBase,A6
  209.     MOVE.L    tb_SegList(A5),D2        ;pointer to Segment list
  210.     
  211.     MOVEQ    #8,D3            ;close Libraries
  212. .Expung2    MOVE.L    tb_GfxBase(A5,D3.W),A1
  213.     JSR    _LVOCloseLibrary(A6)
  214.     SUBQ.W    #4,D3
  215.     BPL.S    .Expung2
  216.     
  217.     MOVE.L    A5,A1            ;remove library from library list
  218.     JSR    _LVORemove(A6)
  219.     
  220.     CLR.L    D0
  221.     MOVE.L    A5,A1
  222.     MOVE.W    LIB_NEGSIZE(A5),D0
  223.     
  224.     SUB.L    D0,A1            ;pointer to beginning of library
  225.     ADD.W    LIB_POSSIZE(A5),D0    ;length
  226.     
  227.     JSR    _LVOFreeMem(A6)        ;return memory
  228.     
  229.     MOVE.L    D2,D0            ;return pointer to Segment list
  230.     MOVEM.L    (SP)+,D2-D3/A5-A6
  231.     RTS
  232.     
  233. ExtFunc:
  234.     ;unused function 
  235.     
  236.     MOVEQ    #0,D0
  237.     RTS
  238.     
  239. CreateTurtle:
  240.     ;create TurtleHandle
  241.     ;
  242.     ;A0: pointer to RastPort
  243.     ;D0: x position
  244.     ;D1: y position
  245.     ;D2: angle
  246.     ;D3: flags
  247.     
  248.     MOVEM.L    D0-D3/A0/A4-A6,-(SP)
  249.     MOVE.L    A6,A5
  250.     MOVE.L    ExecBase,A6
  251.     
  252.     MOVEQ    #TurtleHandle_SIZEOF,D0    ;allocate memory
  253.     MOVEQ    #0,D1
  254.     JSR    _LVOAllocMem(A6)
  255.     TST.L    D0            ;error?
  256.     BEQ.S    .Create1            ;yes, return
  257.     MOVE.L    D0,A4            ;pointer to memory
  258.         
  259.     MOVE.L    tb_FFPBase(A5),A6
  260.     
  261.     MOVE.L    16(SP),th_RastPort(A4)    ;store pointer to RastPort
  262.     MOVE.W    10(SP),th_angle(A4)    ; and angle in Handle
  263.     MOVE.W    10(SP),th_aStart(A4)
  264.     MOVE.B    15(SP),D0        ;flags
  265.     BCLR    #TurB_TValid,D0        ;clear Triangle Valid flag
  266.     MOVE.B    D0,th_Flags(A4)        ;and store it
  267.     MOVE.B    D0,th_FlagStart(A4)
  268.     MOVE.W    2(SP),D0            ;x position
  269.     MOVE.W    D0,th_xStart(A4)        ;as initial position in Handle
  270.     EXT.L    D0
  271.     JSR    _LVOSPFlt(A6)        ;to FFP
  272.     MOVE.L    D0,th_xPosition(A4)    ;as actual position
  273.     MOVE.W    6(SP),D0            ;y position
  274.     MOVE.W    D0,th_yStart(A4)
  275.     EXT.L    D0
  276.     JSR    _LVOSPFlt(A6)
  277.     MOVE.L    D0,th_yPosition(A4)
  278.     
  279.     MOVE.L    A4,A0            ;draw triangle
  280.     MOVE.L    A5,A6
  281.     BSR    DrawTurtle
  282.     
  283.     MOVE.L    A4,D0            ;return pointer to TurtleHandle
  284.     
  285. .Create1    ADDQ.L    #8,SP
  286.     MOVEM.L    (SP)+,D2-D3/A0/A4-A6
  287.     RTS
  288.     
  289. ReturnTurtle:
  290.     ;return TurtleHandle
  291.     ;
  292.     ;A0: Zeiger auf Handle
  293.     
  294.     MOVE.L    A6,-(SP)
  295.     
  296.     BSR    DrawTurtle        ;clear triangle
  297.     
  298.     MOVE.L    ExecBase,A6
  299.     
  300.     MOVE.L    A0,A1            ;and return memory
  301.     MOVEQ    #TurtleHandle_SIZEOF,D0
  302.     JSR    _LVOFreeMem(A6)
  303.     
  304.     MOVE.L    (SP)+,A6
  305.     RTS 
  306.     
  307. TurnRight:
  308.     ;turn Turtle to the right (negative)
  309.     ;
  310.     ;A0: pointer to Turtlehandle
  311.     ;D0: angle
  312.     
  313.     NEG.W    D0            ;change sign
  314.     ;und weiter bei TurnLeft
  315.     
  316. TurnLeft:
  317.     ;turn Turtle to the left (positive)
  318.     ;
  319.     ;A0: pointer to Turtlehandle
  320.     ;D0: angle
  321.     
  322.     BSR    DrawTurtle        ;clear triangle
  323.     
  324.     ADD.W    th_Angle(A0),D0        ;new angle
  325.     EXT.L    D0
  326.     DIVS    #360,D0            ;mod 360
  327.     
  328.     SWAP    D0            ;remainder
  329.     TST.W    D0            ;positiv?
  330.     BPL.S    .TurnRi1            ;yes
  331.     ADD.W    #360,D0            ;no, make positive
  332.     
  333. .TurnRi1    MOVE.W    D0,th_Angle(A0)        ;save angle
  334.     
  335.     BCLR    #TurB_TValid,th_Flags(A0)    ;triangle invalid
  336.     BRA    DrawTurtle        ;new triangle
  337.     
  338. PenUp:
  339.     ;Pen up
  340.     ;
  341.     ;A0: pointer to TurtleHandle
  342.     ;
  343.     BSET    #TurB_Up,th_Flags(A0)    ;set Pen Up flag
  344.     RTS
  345.     
  346. PenDown:
  347.     ;Pen down
  348.     ;
  349.     ;A0: pointer to TurtleHandle
  350.     ;
  351.     BCLR    #TurB_Up,th_Flags(A0)    ;clear Pen Up flag
  352.     RTS
  353.     
  354. HideTurtle:
  355.     ;Hide Turtle triangle
  356.     ;
  357.     ;A0: pointer to TurtleHandle
  358.     ;
  359.     BTST    #TurB_Hide,th_Flags(A0)    ;already hidden?
  360.     BNE.S    .HideTu1            ;yes
  361.     
  362.     BSR    DrawTurtle        ;clear triangle
  363.     
  364.     BSET    #TurB_Hide,th_Flags(A0)    ;set Hide Turtle flag
  365. .HideTu1    RTS
  366.     
  367. ShowTurtle:
  368.     ;Show Turtle triangle
  369.     ;
  370.     ;A0: pointer to TurtleHandle
  371.     ;
  372.     BCLR    #TurB_Hide,th_Flags(A0)    ;clear Hide Turtle flag
  373.     BEQ.S    .ShowTu1            ;already cleared
  374.     
  375.     BCLR    #TurB_TValid,th_Flags(A0)    ;triangle invalid
  376.     BSR    DrawTurtle        ;draw it
  377. .ShowTu1    RTS
  378.     
  379. SetAngle:
  380.     ;Set Turtle angle
  381.     ;
  382.     ;A0: pointer to TurtleHandle
  383.     ;D0: new angle
  384.     ;
  385.     BSR    DrawTurtle        ;clear triangle
  386.     
  387.     MOVE.W    D0,th_Angle(A0)        ;new angle
  388.     
  389.     BCLR    #TurB_TValid,th_Flags(A0)    ;triangle invalid
  390.     BRA    DrawTurtle        ;draw it
  391.     
  392. SetPosition:
  393.     ;Set Turtle position
  394.     ;
  395.     ;A0: Zeiger auf Turtlehandle
  396.     ;D0: x position
  397.     ;D1: y position
  398.     ;
  399.     MOVEM.L    D0-D1/A4-A6,-(SP)
  400.     
  401.     BSR    DrawTurtle        ;clear triangle
  402.     
  403.     MOVE.L    A0,A4            ;TurtleHandle
  404.     MOVE.L    A6,A5
  405.     MOVE.L    tb_FFPBase(A5),A6        ;FFP Library
  406.     
  407.     MOVE.W    2(SP),D0            ;x position
  408.     EXT.L    D0
  409.     JSR    _LVOSPFlt(A6)        ;to FFP
  410.     MOVE.L    D0,th_xPosition(A4)    ;save it
  411.     
  412.     MOVE.W    6(SP),D0            ;y-Position
  413.     EXT.L    D0
  414.     JSR    _LVOSPFlt(A6)
  415.     MOVE.L    D0,th_yPosition(A4)
  416.     
  417.     MOVE.L    A5,A6
  418.     BCLR    #TurB_TValid,th_Flags(A4)    ;triangle invalid
  419.     BSR    DrawTurtle        ;draw it
  420.     
  421.     ADDQ.L    #8,SP
  422.     MOVEM.L    (SP)+,A4-A6
  423.     RTS
  424.     
  425. ResetTurtle:
  426.     ;Reset Turtle to initial state
  427.     ;
  428.     ;A0: pointer to TurtleHandle
  429.     ;
  430.     MOVEM.L    A4-A6,-(SP)
  431.     
  432.     BSR    DrawTurtle        ;clear triangle
  433.     
  434.     MOVE.L    A0,A4            ;pointer to TurtleHandle
  435.     MOVE.L    A6,A5
  436.     MOVE.L    tb_FFPBase(A5),A6
  437.     
  438.     MOVE.W    th_aStart(A4),th_Angle(A4)    ;set angle and flags to initial values
  439.     MOVE.B    th_FlagStart(A4),th_Flags(A4)
  440.     
  441.     MOVE.W    th_xStart(A4),D0        ;initial x position
  442.     EXT.L    D0
  443.     JSR    _LVOSPFlt(A6)        ;to FFP
  444.     MOVE.L    D0,th_xPosition(A4)    ;actual x position
  445.     
  446.     MOVE.W    th_yStart(A4),D0        ;initial y position
  447.     EXT.L    D0
  448.     JSR    _LVOSPFlt(A6)
  449.     MOVE.L    D0,th_yPosition(A4)
  450.     
  451.     MOVE.L    A5,A6
  452.     BSR    DrawTurtle        ;draw triangle
  453.     
  454.     MOVEM.L    (SP)+,A4-A6
  455.     RTS
  456.     
  457. Forward:
  458.     ;Move Turtle
  459.     ;
  460.     ;A0: pointer to TurtleHandle
  461.     ;D0: distance (FFP)
  462.     ;
  463.     MOVEM.L    D2-D6/A2-A3/A5-A6,-(SP)
  464.     MOVE.L    D0,D2            ;distance
  465.     MOVE.L    A0,A2            ;TurtleHandle
  466.     MOVE.L    A6,A5            ;library
  467.     
  468.     BSR    DrawTurtle        ;clear triangle
  469.     
  470.     MOVE.L    tb_FFPBase(A5),A6
  471.     
  472.     MOVE.W    th_Angle(A2),D0        ;convert angle
  473.     EXT.L    D0
  474.     JSR    _LVOSPFlt(A6)        ;to FFP
  475.     
  476.     MOVE.L    #$8EFA353B,D1        ; (pi/180)
  477.     JSR    _LVOSPMul(A6)        ;and to radians
  478.     
  479.     MOVE.L    tb_FFPTBase(A5),A6
  480.     
  481.     SUBQ.L    #4,SP            ;space for cosine on stack
  482.     MOVE.L    SP,D1
  483.     JSR    _LVOSPSinCos(A6)
  484.     MOVE.L    D0,D5            ;sine
  485.     MOVE.L    (SP)+,D6            ;cosine
  486.     
  487.     MOVE.L    tb_FFPBase(A5),A6
  488.     
  489.     MOVE.L    D2,D1            ;y component of distance:
  490.     JSR    _LVOSPMul(A6)        ; yd := d * sin w
  491.     MOVE.L    D0,D1
  492.     
  493.     MOVE.L    th_yPosition(A2),D0    ;y position:
  494.     JSR    _LVOSPSub(A6)        ; yp := yp-yd
  495.     MOVE.L    D0,D3
  496.     
  497.     MOVE.L    D6,D0            ;x component of distance:
  498.     MOVE.L    D2,D1            ; xd := d * cos w
  499.     JSR    _LVOSPMul(A6)
  500.     
  501.     MOVE.L    th_xPosition(A2),D1    ;x position:
  502.     JSR    _LVOSPAdd(A6)        ; xp := xp+xd
  503.     MOVE.L    D0,D2
  504.     
  505.     BTST    #TurB_Up,th_Flags(A2)    ;Pen up?
  506.     BNE.S    .Forwar1            ;yes
  507.     
  508.     MOVE.L    th_RastPort(A2),A3    ;Rastport
  509.     
  510.     MOVE.L    th_yPosition(A2),D0    ;convert old position to integer
  511.     JSR    _LVOSPFix(A6)
  512.     MOVE.L    D0,D4
  513.     
  514.     MOVE.L    th_xPosition(A2),D0
  515.     JSR    _LVOSPFix(A6)
  516.     
  517.     MOVE.L    tb_GfxBase(A5),A6
  518.     
  519.     MOVE.L    A3,A1            ;graphics cursor to old position
  520.     MOVE.L    D4,D1
  521.     JSR    _LVOMove(A6)
  522.     
  523.     MOVE.L    tb_FFPBase(A5),A6
  524.     
  525.     MOVE.L    D3,D0            ;convert new position to integer
  526.     JSR    _LVOSPFix(A6)
  527.     MOVE.L    D0,D4
  528.     
  529.     MOVE.L    D2,D0
  530.     JSR    _LVOSPFix(A6)
  531.     
  532.     MOVE.L    tb_GfxBase(A5),A6
  533.     
  534.     MOVE.L    A3,A1            ;draw line
  535.     MOVE.L    D4,D1
  536.     JSR    _LVODraw(A6)
  537.     
  538. .Forwar1    MOVE.L    D2,th_xPosition(A2)    ;save new position
  539.     MOVE.L    D3,th_yPosition(A2)
  540.     
  541.     BTST    #TurB_Hide,th_Flags(A2)    ;triangle visible?
  542.     BNE.S    .Forwar2            ;no
  543.  
  544.     MOVE.L    tb_FFPBase(A5),A6        ;yes, calculate coordinates
  545.     BSR.S    CalcTurtle
  546.     
  547.     MOVE.L    A2,A0            ;and draw it
  548.     MOVE.L    A5,A6
  549.     BSR    DrawTurtle
  550.     
  551. .Forwar2    MOVEM.L    (SP)+,D2-D6/A2-A3/A5-A6
  552.     RTS
  553.  
  554. CalcTurtle:
  555.     ;calculate points of Turtle triangle
  556.     ;
  557.     ;D2: x position (FFP)
  558.     ;D3: y position (FFP)
  559.     ;D5: sine
  560.     ;D6: cosine
  561.     ;A2: pointer to TurtleHandle
  562.     ;A6: pointer to MathFFP library
  563.     ;
  564.     ;This function is private and is not contained in the jump table
  565.     ;
  566.     ;Do take care! Register contents are changed!
  567.     ;
  568.     MOVE.L    D2,D0            ;convert position to integer
  569.     JSR    _LVOSPFix(A6)
  570.     MOVE.W    D0,th_PointArray+4(A2)
  571.     
  572.     MOVE.L    D3,D0
  573.     JSR    _LVOSPFix(A6)
  574.     MOVE.W    D0,th_PointArray+6(A2)    ;2nd point
  575.     
  576.     MOVE.L    D2,D0            ;x position
  577.     MOVE.L    D6,D1
  578.     ADDQ.B    #3,D1            ; cos*8
  579.     BTST    #TurB_xComp,th_Flags(A2)    ;  x compression?
  580.     BEQ.S    .CalcTu1            ;  no
  581.     SUBQ.B    #1,D1            ; cos*4
  582. .CalcTu1    JSR    _LVOSPSub(A6)        ;xpos - c*cos
  583.     MOVE.L    D0,D2            ;as x coordinate of center of baseline
  584.     
  585.     MOVE.L    D3,D0            ;y position
  586.     MOVE.L    D5,D1
  587.     ADDQ.B    #3,D1            ; sin*8
  588.     BTST    #TurB_yComp,th_Flags(A2)    ;  y compression?
  589.     BEQ.S    .CalcTu2            ;  no
  590.     SUBQ.B    #1,D1            ; sin*4
  591. .CalcTu2    JSR    _LVOSPAdd(A6)        ;ypos - c*sin
  592.     MOVE.L    D0,D3            ;as y coordinate of center of baseline
  593.     
  594.     MOVE.L    D2,D0            ;x center
  595.     MOVE.L    D5,D1
  596.     ADDQ.B    #2,D1            ; sin*4
  597.     BTST    #TurB_xComp,th_Flags(A2)    ;  x compression?
  598.     BEQ.S    .CalcTu3            ;  no
  599.     SUBQ.B    #1,D1            ; sin*2
  600. .CalcTu3    MOVE.L    D1,D4            ; save sine
  601.     JSR    _LVOSPSub(A6)        ;x center - sin
  602.     
  603.     JSR    _LVOSPFix(A6)        ;to integer
  604.     MOVE.W    D0,th_PointArray+0(A2)    ;x coordinate of 1st point
  605.     
  606.     MOVE.L    D2,D0
  607.     MOVE.L    D4,D1
  608.     JSR    _LVOSPAdd(A6)        ;x center + sin
  609.     
  610.     JSR    _LVOSPFix(A6)
  611.     MOVE.W    D0,th_PointArray+8(A2)    ;x coordinate of 3rd point
  612.     
  613.     MOVE.L    D3,D0            ;y center
  614.     MOVE.L    D6,D1
  615.     ADDQ.B    #2,D1
  616.     BTST    #TurB_yComp,th_Flags(A2)
  617.     BEQ.S    .CalcTu4
  618.     SUBQ.B    #1,D1
  619. .CalcTu4    MOVE.L    D1,D4
  620.     JSR    _LVOSPSub(A6)        ;y center - cos
  621.     
  622.     JSR    _LVOSPFix(A6)
  623.     MOVE.W    D0,th_PointArray+2(A2)    ;y coordinate of 1st point
  624.     
  625.     MOVE.L    D3,D0
  626.     MOVE.L    D4,D1
  627.     JSR    _LVOSPAdd(A6)        ;y center + cos
  628.     
  629.     JSR    _LVOSPFix(A6)
  630.     MOVE.W    D0,th_PointArray+10(A2)    ;y coordinate of 3rd point
  631.     
  632.     BSET    #TurB_TValid,th_Flags(A2)    ;triangle valid
  633.     RTS
  634.     
  635. DrawTurtle:
  636.     ;draw Turtle triangle
  637.     ;
  638.     ;A0: pointer to TurtleHandle
  639.     ;
  640.     ;This function is provate and not contained in the jump table
  641.     ;
  642.     ;Register contents are not changed!
  643.     ;
  644.     BTST    #TurB_Hide,th_Flags(A0)    ;triangle hidden?
  645.     BEQ.S    .DrawTu2            ;no, draw it
  646.     
  647.     RTS
  648.     
  649. .DrawTu2    MOVEM.L    D0-D6/A0-A3/A5-A6,-(SP)
  650.     
  651.     MOVE.L    A0,A2            ;TurtleHandle
  652.     MOVE.L    th_RastPort(A2),A3    ;RastPort
  653.     MOVE.L    A6,A5            ;Library Base
  654.     
  655.     BTST    #TurB_TValid,th_Flags(A2)    ;triangle valid?
  656.     BNE.S    .DrawTu1            ;yes
  657.     
  658.     MOVE.L    tb_FFPBase(A5),A6
  659.         
  660.     MOVE.W    th_Angle(A2),D0        ;convert angle
  661.     EXT.L    D0
  662.     JSR    _LVOSPFlt(A6)
  663.     
  664.     MOVE.L    #$8EFA353B,D1        ;to radians
  665.     JSR    _LVOSPMul(A6)
  666.     
  667.     MOVE.L    tb_FFPTBase(A5),A6
  668.     
  669.     SUBQ.L    #4,SP
  670.     MOVE.L    SP,D1
  671.     JSR    _LVOSPSinCos(A6)
  672.     MOVE.L    D0,D5            ;sine to D5,
  673.     MOVE.L    (SP)+,D6            ;cosine to D6
  674.     
  675.     MOVE.L    th_xPosition(A2),D2    ;x position to D2
  676.     MOVE.L    th_yPosition(A2),D3    ;y position to D3
  677.     
  678.     MOVE.L    tb_FFPBase(A5),A6        ;calculate points
  679.     BSR    CalcTurtle
  680.     
  681. .DrawTu1    MOVE.L    tb_GfxBase(A5),A6
  682.     
  683.     MOVE.B    rp_FgPen(A3),-(SP)    ;save FgPen and DrawMode of RastPort
  684.     MOVE.B    rp_DrawMode(A3),-(SP)
  685.     
  686.     MOVE.L    A3,A1            ;draw into all planes
  687.     MOVEQ    #-1,D0
  688.     JSR    _LVOSetAPen(A6)
  689.     
  690.     MOVE.L    A3,A1            ;new DrawMode
  691.     MOVEQ    #RP_JAM1|RP_COMPLEMENT,D0
  692.     JSR    _LVOSetDrMd(A6)
  693.     
  694.     MOVE.L    A3,A1            ;graphics cursor to 1st point
  695.     MOVE.W    th_PointArray+0(A2),D0
  696.     MOVE.W    th_PointArray+2(A2),D1
  697.     JSR    _LVOMove(A6)
  698.     
  699.     MOVE.L    A3,A1            ;draw triangle
  700.     MOVEQ    #2,D0
  701.     LEA    th_PointArray+4(A2),A0
  702.     JSR    _LVOPolyDraw(A6)
  703.     
  704.     MOVE.L    A3,A1            ;restore DrawMode
  705.     MOVE.B    (SP)+,D0
  706.     JSR    _LVOSetDrMd(A6)
  707.     
  708.     MOVE.L    A3,A1            ;and FgPen
  709.     MOVE.B    (SP)+,D0
  710.     JSR    _LVOSetAPen(A6)
  711.     
  712.     MOVEM.L    (SP)+,D0-D6/A0-A3/A5-A6
  713.     RTS
  714.  
  715. EndCode:
  716.  
  717.