home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS - Coast to Coast / simteldosarchivecoasttocoast2.iso / ddjmag / ddj8611.zip / KATZ.NOV < prev    next >
Text File  |  1986-12-01  |  25KB  |  1,285 lines

  1. Listing One
  2.  
  3. ; < MandelZoom.ASM >    Sat 30 Nov '85  h. katz
  4. ;            Sun  4 May '86
  5.  
  6.  
  7. INCLUDE MacTraps.D
  8.  
  9. String_Format    3        ; pre-length DC.B and PEA Strings
  10.  
  11. XREF    Convert_2_Fixed_Point    ; Procedure defined in < Str2FP.ASM >
  12.  
  13. MACRO    Fix_Squared    Rn    =    ; a Mac-style macro
  14.     clr.l    -(sp)            ; ( Mac-Mac ? )
  15.     move.l    {Rn}, -(sp)
  16.     move.l    {Rn}, -(sp)
  17.     _FixMul
  18.     move.l    (sp)+, {Rn} |
  19.  
  20. MouseDown    EQU      1    ; for _GetNextEvent
  21. numToString    EQU      0    ; for _Pack7 conversions
  22. stringToNum    EQU      1
  23. Gray        EQU    -24    ; offset from QDVars Ptr
  24. White        EQU     -8
  25. portRect        EQU     16    ; offset from start of Window Record
  26. pnPat        EQU     58    ; offset from start of Window Record
  27.  
  28. X_Screen_Offset    equ       4
  29. Y_Screen_Offset    equ      4
  30. Row_Pixels    equ    256
  31. Col_Pixels    equ    256
  32. PenSize        equ      2
  33.  
  34. HiLite_Off    equ     0
  35. HiLite_On    equ     1
  36.  
  37. Radio_Item_1    equ     9
  38. Radio_Item_2    equ    10
  39. Radio_Item_3    equ    11
  40.  
  41. X_Org_Item    equ    12    ; Item Numbers in Params DITL
  42. Y_Org_Item    equ    13
  43. Side_Length_Item    equ    14
  44. Count_Item_1    equ    15
  45.  
  46. Org_Spacing    equ    24    ; Space tween X, Y, and S
  47. Max_Count_Digits    equ     4    ; Num Digits in 'Count' Item Strings
  48.  
  49. Count_Str_X    equ     5    ; X_coord of Counts
  50. Count_Str_Y    equ    114    ; Y_coord of 1st ( Max ) Count
  51. Count_Str_Size    equ    10    ; Bytes wide
  52.  
  53. Legend_Plot_Item    equ     1
  54. Legend_Quit_Item    equ     2
  55.  
  56. Pattern_Spacing    equ     30    ; Delta-Y for both Counts & Patts
  57. Pattern_X    equ     62    ; Left for Patts in Legend DLOG
  58. Pattern_Y    equ     86    ; Top for 1st Patt in Legend DLOG
  59. Pattern_Size    equ      8    ; Bytes
  60.  
  61. X_Org_Scr_X    equ     10
  62. X_Org_Scr_Y    equ     24
  63.  
  64. Time_Scr_X    equ     10
  65. Time_Scr_Y    equ     16
  66.  
  67.  
  68.     st    First_Entry(A5)
  69.     sf    Radio_1_State(A5)
  70.     st    Radio_2_State(A5)        ; default Pen is 2 X 2
  71.     sf    Radio_3_State(A5)
  72.  
  73.     BSR    InitManagers    
  74.     BSR    Save_Mouse_State
  75.     BSR    Draw_Menu_Title
  76.             
  77. MainLine
  78.  
  79.     BSR    Open_Params_DLOG
  80.     
  81.     tst.b    First_Entry(A5)
  82.     BNE.s    @Set_Radios    
  83.     BSR    Reload_DITL        ; 2nd time around -
  84.                     ; get old Parameters
  85. @Set_Radios
  86.  
  87.     sf    First_Entry(A5)
  88.     
  89.     BSR    Set_Radio_Buttons    
  90.     BSR    Get_Param_Items    ; Get User Choice / if OK, Toggle Radio
  91.                 ; Buttons, Convert & Save Counts
  92.     bMI    Exit_To_Shell
  93.     
  94.     BSR    Save_Param_Items ; Save Str Counts / Convert 3 Fix-Pt Nums    
  95.     pea    paramsDLOGStorage
  96.     _CloseDialog
  97.  
  98.     BSR    Draw_Mandel_Window
  99.     BSR    Open_Legend_DLOG
  100.     BSR    Draw_Patterns
  101.     BSR    Draw_Org_Strings
  102.     
  103.     BSR    Timer_On
  104.     
  105.     BSR    Do_Mandelbrot
  106.     
  107.     bMI    Exit_To_Shell    ; These 2 in case we've interrupted
  108.     bHI    Do_Another    ; plotting in the middle
  109.     
  110.     BSR    Timer_Off    
  111.     BSR    Write_Time
  112.     
  113. Wait_4_Command
  114.  
  115.     BSR    Get_Next_Event
  116.     bEQ    Wait_4_Command    ; No Event
  117.     BSR    Was_Dialog_Event
  118.     bEQ    Wait_4_Command    ; 0 => Hang Around a Bit
  119.     bMI    Exit_To_Shell    ; - => Quit
  120.                 ; + => do another
  121. Do_Another
  122.  
  123.     pea    MandelWindStorage
  124.     _CloseWindow
  125.     pea    LegendDLOGStorage
  126.     _CloseDialog
  127.  
  128.     BRA    MainLine
  129.         
  130.     
  131. Exit_To_Shell
  132.  
  133.     _ExitToShell
  134.     
  135.         
  136. Save_Mouse_State    ; if the Mouse is Down on Launch, we'll
  137.             ; _SetPat and _Line for EVERY Point
  138.             
  139.     sf    Mouse_Down(A5)
  140.     clr    -(sp)
  141.     _Button
  142.     tst    (sp)+
  143.     beq    @rts
  144.     st    Mouse_Down(A5)
  145. @rts    RTS
  146.  
  147.  
  148. Draw_Menu_Title
  149.  
  150.     move.l    #$000F0010, -(sp)
  151.     _MoveTo    
  152.     pea    MBarTitle
  153.     _DrawString
  154.     RTS
  155.  
  156. Reload_DITL
  157.  
  158.     lea    TempStr, A2
  159.     move    #0, D3
  160.  
  161.     move    #X_Org_Item, D4
  162.     BSR    Get_Item_Text
  163.     move.l    ItemHandle, -(sp)
  164.     pea    X_Org_Str
  165.     _SetIText
  166.     move    #Y_Org_Item, D4
  167.     BSR    Get_Item_Text
  168.     move.l    ItemHandle, -(sp)
  169.     pea    Y_Org_Str
  170.     _SetIText
  171.     move    #Side_Length_Item, D4
  172.     BSR    Get_Item_Text
  173.     move.l    ItemHandle, -(sp)
  174.     pea    Side_Length
  175.     _SetIText
  176.  
  177.     lea    TempStr, A2
  178.     lea    Count_Strings, A3
  179.     move    #0, D3
  180.     move    #Count_Item_1, D4
  181.  
  182. @Reset_Counts
  183.  
  184.     BSR    Get_Item_Text
  185.     move.l    ItemHandle, -(sp)
  186.     move.l    A3, -(sp)    ; Addr of Current Count_String
  187.     _SetIText
  188.     
  189.     add.l    #Count_Str_Size, A3
  190.     add    #1, D4        ; next Item Number in DLOG
  191.     add    #1, D3        ; increment loop counter
  192.     cmp    #4, D3        ; done all 4 ?
  193.     BMI    @Reset_Counts    ; no
  194.  
  195.     RTS
  196.     
  197.  
  198. Get_Next_Event
  199.  
  200.     clr    -(sp)
  201.     move    #-1, -(sp)
  202.     pea    EventRecord
  203.     _GetNextEvent
  204.     tst.b    (sp)+
  205.     RTS
  206.     
  207.  
  208. Was_Dialog_Event
  209.     
  210.     clr.b    -(sp)
  211.     pea    EventRecord
  212.     _IsDialogEvent
  213.     tst.b    (sp)+        ; EQ = No Event    
  214.     bNE.s    @1        ; NE = Was DLOG Event
  215.     RTS
  216.     
  217. @1    clr.b    -(sp)
  218.     pea    EventRecord
  219.     pea    theDialog
  220.     pea    ItemHit
  221.     _DialogSelect
  222.     tst.b    (sp)+
  223.     bNE.s    Get_Legend_DLOG_Item
  224.  
  225.     clr.b    -(sp)
  226.     pea    EventRecord
  227.     pea    ParamsDLOGStorage
  228.     pea    ItemHit
  229.     _DialogSelect
  230.     tst.b    (sp)+
  231.     move    #0, D0
  232.     RTS
  233.  
  234.  
  235. Get_Legend_DLOG_Item    
  236.     
  237.     move    ItemHit, D0
  238.     cmp    #Legend_Plot_Item, D0
  239.     bEQ    @Return_Plus
  240.     cmp    #Legend_Quit_Item, D0
  241.     bEQ    @Return_Minus
  242.     move    #0, D0
  243.     RTS
  244.     
  245.  
  246. @Return_Minus        ; = Quitting
  247.  
  248.     move    #-1, D0
  249.     RTS
  250.     
  251. @Return_Plus        ; = Do Another Mandelbrot
  252.  
  253.     move    #1, D0
  254.     RTS
  255.  
  256.  
  257. Timer_On
  258.  
  259.     clr.l    -(sp)
  260.     _TickCount
  261.     move.l    (sp)+, Start_Time(A5)
  262.     RTS
  263.  
  264.  
  265. Timer_Off
  266.  
  267.     _PenNormal    
  268.     move    #4, -(sp)    ; Wake the Poor User
  269.     _SysBeep
  270.     
  271.     clr.l    -(sp)
  272.     _TickCount
  273.     move.l    (sp)+, D3
  274.     sub.l    Start_Time(A5), D3    ; ( Stop - Start ) in Ticks
  275.     divu    #60, D3            ; Num_Seconds (in Low Word)
  276.     RTS    
  277.  
  278. MenuRect    dc    0, 10, 19, 200
  279.  
  280. Write_Time
  281.     
  282.     pea    MandelWindStorage
  283.     pea    TempSTR
  284.     _GetWTitle
  285.     
  286.     lea    TempSTR, a2
  287.     move.l    a2, a3            ; save start addr
  288.     clr.l    d5            ; clear out old junk
  289.     move.b    (a2)+, d5        ; Length Byte
  290.     adda.l    d5, a2            ; point past last Char in Str
  291.     
  292.     lea    ' :  ', a0        ; addr of length byte
  293.     clr.l    d1
  294.     move.b    (a0)+, d1        ; save new length
  295.     add.b    d1, d5
  296.     move.b    d5, (a3)        ; put back new length byte
  297.     sub    #1, d1
  298.     
  299. @Loop_1
  300.     move.b    (a0)+, (a2)+        ; add new string to end
  301.     dbra    d1, @Loop_1
  302.     
  303.     move.b    -(a2), d4        ; save last char
  304.     
  305.     ext.l    D3            ; Elapsed Time in seconds
  306.     move.l    D3, D0
  307.     move.l    a2, a0
  308.     move    #NumToString, -(sp)
  309.     _Pack7
  310.     
  311.     clr.l    d1
  312.     move.b    (a2), d1        ; save New Length Byte
  313.     move.b    d4, (a2)        ; restore last Char of 1st String
  314.  
  315.     add.b    d1, d5            ; new length    
  316.     move.b    d5, (a3)        ; and put back in Length Byte
  317.     adda.l    d1, a2            ; point to end of string
  318.     adda.l    #1, a2            ; points 1 past end
  319.         
  320.     lea    ' seconds', a1
  321.     move.b    (a1)+, d1        ; save new Length Byte
  322.     ext.w    d1
  323.     add.b    d1, d5            ; new total Length of Strings
  324.     move.b    d5, (a3)        ; put it back in Length Byte
  325.  
  326. @Loop_2
  327.     move.b    (a1)+, (a2)+        ; append 'Seconds' to end
  328.     sub    #1, d1
  329.     bhi    @Loop_2
  330.     
  331.     pea    MandelWindStorage
  332.     pea    TempSTR
  333.     _SetWTitle
  334.     
  335.     RTS
  336.     
  337.  
  338. Do_Mandelbrot
  339.     
  340.     pea    MandelWindStorage
  341.     move.l    (sp), -(sp)        ; copy WPtr for _SetWTitle trap
  342.     _SetPort            ; draw in this Window
  343.     
  344.     tst.b    Radio_1_State(A5)
  345.     beq.s    @1
  346.     pea    '1 X 1'
  347.     bra    @SetTitle
  348.     
  349. @1    tst.b    Radio_2_State(A5)
  350.     beq.s    @2
  351.     pea    '2 X 2'
  352.     bra.s    @SetTitle
  353.     
  354. @2    pea    '4 X 4'
  355.  
  356. @SetTitle
  357.     _SetWTitle
  358.         
  359. @Set_Pen_Size
  360.     move    #PenSize, D3
  361.     tst.b    Radio_2_State(A5)    ; Draw with 2 X 2 Pen ?
  362.     BNE    @Set_Pen        ; yes
  363.  
  364.     add    D3, D3            ; Pen = 4 X 4
  365.     tst.b    Radio_3_State(A5)    ; Draw with 4 X 4 ?
  366.     BNE    @Set_Pen        ; yes
  367.     move    #1, D3            ; Draw with 1 X 1
  368.     
  369. @Set_Pen
  370.     move    D3, Pix_Per_Pt(A5)
  371.     move    D3, -(sp)
  372.     move    (sp), -(sp)
  373.     _PenSize
  374.     
  375. @Set_Plot_Size
  376.  
  377.     lea    MandelWindStorage, a0
  378.     move    portRect+4(a0), d4    ; Window.Bottom
  379.     move    #Y_Screen_Offset, d0
  380.     sub    d0, d4            ; frame at Bott
  381.     sub    d3, d4            ; move up 1 PenSize from Bott
  382.     move    d4, Y_Start(a5)
  383.     sub    d0, d4            ; adjust for frame at Top
  384.     move    d4, Num_Rows(a5)
  385.     
  386.     move    portRect+6(a0), d4    ; Window.Right
  387.     move    #X_Screen_Offset, d0
  388.     asl    #1, d0            ; frame at Left & Right
  389.     sub    d0, d4
  390.     sub    d3, d4            ; allow for penWidth
  391.     move    d4, Num_Cols(a5)
  392.     
  393. @Get_C_Increment
  394.  
  395.     move.l    Y_side(A5), D0
  396.     move    Num_Rows(A5), D5
  397.     ext.l    d5
  398.     divu    Pix_Per_Pt(A5), D5    ; = # of Plottable Pts on Y-Axis
  399.     BSR    Get_Del_Factor        ; Del_Y returned as Fixed Pt
  400.     move.l    D4, Del_C_imag(A5)    ; in D4
  401.     
  402.     clr.l    -(sp)
  403.     move    Num_Cols(a5), -(sp)    ; numerator
  404.     move    Num_Rows(a5), -(sp)    ; denominator
  405.     _FixRatio            ; Fixed-Pt Ratio on stack
  406.     move.l    (sp)+, d0        ; temp save it
  407.     clr.l    -(sp)
  408.     move.l    d0, -(sp)        ; Num_Cols/Num_Rows
  409.     move.l    Y_Side(a5), -(sp)        ; x Y_Side
  410.     _FixMul                ; --------
  411.     move.l    (sp)+, X_Side(a5)        ; = X_Side
  412.     
  413.     move.l    X_Side(A5), D0
  414.     move    Num_Cols(A5), D5
  415.     ext.l    d5
  416.     divu    Pix_Per_Pt(A5), D5    ; = # of Plottable Pts on X-Axis
  417.     BSR    Get_Del_Factor
  418.     move.l    D4, Del_C_Real(A5)    
  419.     
  420.     BRA    Continue
  421.     
  422.     
  423. Get_Del_Factor
  424.  
  425.     move.l    D0, D3        ; save the fractional part
  426.     swap    D0        ; and get the whole part
  427.     clr.l    -(sp)
  428.     move    D0, -(sp)    ; side ( integer part )
  429.     move    D5, -(sp)    ; pts per side
  430.     _FixRatio        ; = length ( integer ) / point
  431.     move.l    (sp)+, D4    ; save the ( int ) fraction
  432.     
  433.     sf    D6        ; positive fraction
  434.     tst    D3
  435.     bpl    @1
  436.     st    D6        ; negative fraction
  437.     lsr    #1, D3        ; zero the hi bit so _FixRatio doesn't
  438.                 ; think the number is Negative
  439. @1    clr.l    -(sp)
  440.     move    D3, -(sp)    ; side ( fract part )
  441.     move    D5, -(sp)    ; pts per side
  442.     _FixRatio        ; = length ( fract ) / point
  443.     move.l    (sp)+, D3
  444.     
  445.     swap    D3        ; move the 'integer' part of the 'fraction'
  446.     tst.b    D6        ; back into the fractional lo word
  447.     bpl    @2
  448.     lsl    #1, D3        ; restore the 'negative' hi bit
  449.  
  450. @2    and.l    #$FFFF, D3
  451.     add.l    D3, D4
  452.     
  453.     RTS
  454.     
  455. Continue
  456.     
  457.     clr    Row_Count(A5)
  458.     move.l    Y_Origin(A5), C_Imag(A5)
  459.     move    Y_Start(a5), Y_Current(A5)
  460.     
  461.         
  462. Do_Next_Row
  463.  
  464.     clr    Col_Count(A5)
  465.  
  466.     move    #X_Screen_Offset, -(sp)    ; For next row
  467.     move    Y_Current(A5), -(sp)    ; move absolute to start
  468.     _MoveTo    
  469.  
  470.     st    First_Pt(A5)        ; 1st_Point := TRUE;
  471.     
  472.     move.l    X_Origin(A5), C_Real(A5)    ; for start of new row
  473.     
  474.     BSR    Do_Points
  475.     
  476.     move    Row_Count(A5), D0
  477.     add    Pix_Per_Pt(A5), D0
  478.     move    D0, Row_Count(A5)
  479.     cmp    Num_Rows(A5), D0    
  480.     
  481.     bMI    @CheckDLOG
  482.     move    #0, d0
  483.     BRA    @Return_To_Mainline
  484.  
  485. @CheckDLOG
  486.  
  487.     BSR    Get_Next_Event
  488.     bEQ.s    @Setup_Next_Row
  489.     BSR    Was_Dialog_Event
  490.     bEQ.s    @Setup_Next_Row
  491.  
  492. @Return_To_Mainline
  493.  
  494.     RTS
  495.     
  496. @Setup_Next_Row
  497.     
  498.     move    Pix_Per_Pt(A5), D0
  499.     sub    D0, Y_Current(A5)
  500.  
  501.     move.l    C_imag(A5), D0        ; set up Y for next row
  502.     add.l    Del_C_Imag(A5), D0
  503.     move.l    D0, C_Imag(A5)
  504.  
  505.     BRA.s    Do_Next_Row
  506.  
  507.  
  508. Do_Points
  509.                 
  510.     move.l    C_Real(A5), D5     ; Initialize Z = C for new point
  511.     move.l    C_Imag(A5), D6
  512.     move    #1, Iter_Count(A5) ; Do up to Counts(A5) times per Point
  513.     lea    Patterns, A4     ; reset Pattern Ptr
  514.     
  515. Iterate
  516.     
  517.     move.l    D5, D3            ; Save Current Z_Real
  518.     move.l    D6, D4            ; Save Current Z_Imag
  519.     
  520.     Fix_Squared    D3        ; Z_Real^2
  521.     Fix_Squared    D4        ; Z_Imag^2
  522.     move.l    D4, D7
  523.     add.l    D3, D7            ; Size^2 = Z_Real^2 + Z_Imag^2
  524.  
  525. @Test_Size        
  526.     move    Iter_Count(A5), D0    
  527.     cmp.l    #$40000, D7        ; Size^2 > 4 means TIME TO PLOT
  528.     BHI.s    @Plot
  529.  
  530. @Test_Count
  531.     add    #1, D0
  532.     move    D0, Iter_Count(A5)
  533.     cmp    Counts(A5), D0    
  534.     BPL.s    @Plot
  535.  
  536. @Get_New_Z
  537.     sub.l    D4, D3            ; Z_Real = Z_Real^2 - Z_Imag^2
  538.  
  539.     clr.l    -(sp)
  540.     move.l    D5, -(sp)    
  541.     move.l    D6, -(sp)
  542.     _FixMul        
  543.     move.l    (sp)+, D6        ; Z_Real * Z_Imag
  544.     add.l    D6, D6            ; Z_Imag = 2 * Z_Real * Z_Imag
  545.     move.l    D3, D5            ; Z_Real
  546.     
  547.     add.l    C_Real(A5), D5
  548.     add.l    C_Imag(A5), D6
  549.     BRA.s    Iterate
  550.     
  551.     
  552. @Plot    
  553.     BSR    Get_Pattern    ; A4 = Ptr to New Pattern
  554.     
  555.     tst.b    First_Pt(A5)    ; IF NOT 1st_Point
  556.     BEQ    @Test_Mouse    ;   Test_Mouse { see if batching }
  557.     sf    First_Pt(A5)        ; ELSE  
  558.                 ;    1st_Point = FALSE;
  559.     move.l    A4, A2        ;    Old_Pat := New_Pat;
  560.     BRA    @Set_Pattern
  561.     
  562. @Test_Mouse
  563.  
  564.     tst.b    Mouse_Down(A5)    ; IF NOT Batch_Plot
  565.     BNE.s    @Draw_Line    ;    Draw_Line ( Old_Pat )
  566.     cmp.l    A2, A4        ; ELSE
  567.     BNE    @Draw_Line    ;    IF NOT ( New_Pat = Old_Pat )
  568.                 ;       Draw_Line ( Old_Pat )
  569.                 ;    ELSE
  570.                 ;       Init_Line_Amount;
  571.     add    Pix_Per_Pt(A5), A3;       Do_Next_Pt;
  572.     BRA    @Skip_Draw
  573.     
  574. @Draw_Line
  575.  
  576.     move    A3, -(sp)
  577.     move    #0, -(sp)
  578.     _Line            ; Draw_Line ( Old_Pat )
  579.  
  580. @Set_Pattern
  581.  
  582.     move.l    A4, -(sp)    ; set the New Pattern
  583.     _PenPat
  584.  
  585.     move.l    A4, A2        ; Old_Pat := New_Pat
  586.     move    Pix_Per_Pt(A5), A3
  587.  
  588. @Skip_Draw
  589.  
  590.     move    Col_Count(A5), D0
  591.     add    Pix_Per_Pt(A5), D0
  592.     move    D0, Col_Count(A5)
  593.     
  594.     cmp    Num_Cols(A5), D0
  595.     BMI.s    @Update_Z_Real
  596.     
  597. ; we've finished the Line - if we need to draw to finish up
  598. ; do it here
  599.  
  600.     cmp    Pix_Per_Pt(A5), A3
  601.     BEQ    @rts            ; we've just drawn
  602.     
  603.     move    A3, -(sp)        ; else draw what we didn't
  604.     move    #0, -(sp)
  605.     _Line
  606.         
  607. @rts    RTS
  608.     
  609.     
  610. @Update_Z_Real
  611.     move.l    C_Real(A5), D0
  612.     add.l    Del_C_Real(A5), D0
  613.     move.l    D0, C_Real(A5)
  614.  
  615.     BRA    Do_Points
  616.     
  617.  
  618. Get_Pattern    ; Point to a New PenPat, according to which 
  619.         ; Range the Iter_Count ( D0 ) falls in
  620.     
  621.     cmp    0+Counts(A5), D0    ; >= Black
  622.     BPL.s    @0
  623.     
  624.     add    #8, A4
  625.     cmp    2+Counts(A5), D0    ; >= DarkGray
  626.     BPL.s    @0
  627.     add    #8, A4
  628.     cmp    4+Counts(A5), D0    ; >= LtGray
  629.     BPL.s    @0    
  630.     add    #8, A4
  631.     cmp    6+Counts(A5), D0    ; >= White
  632.     BPL.s    @0    
  633.     add    #8, A4        ; <  Gray
  634.     
  635. @0    RTS
  636.  
  637.  
  638.  
  639. Open_Params_DLOG
  640.  
  641.     clr.l    -(sp)        ; space for funct result
  642.     move    #100, -(sp)
  643.     pea    ParamsDLOGStorage
  644.     move.l    #-1, -(sp)    ; in front of everything
  645.     _GetNewDialog
  646.     move.l    (sp)+, d0
  647.     RTS
  648.  
  649.  
  650. Set_Radio_Buttons
  651.  
  652.     move    #HiLite_On, D3
  653.     
  654.     tst.b    Radio_1_State(A5)
  655.     BPL    @2
  656.     move    #Radio_Item_1, D4
  657.     BRA    HiLite_Control
  658.     
  659. @2    tst.b    Radio_2_State(A5)
  660.     BPL    @3
  661.     move    #Radio_Item_2, D4
  662.     BRA    HiLite_Control
  663.     
  664. @3    move    #Radio_Item_3, D4
  665.     BRA    HiLite_Control
  666.         
  667.  
  668. HiLite_Control
  669.  
  670.     pea    ParamsDLOGStorage
  671.     move    D4, -(sp)    ; ItemNumber
  672.     pea    ItemType
  673.     pea    ItemHandle
  674.     pea    ItemBox
  675.     _GetDItem
  676.     move.l    ItemHandle, -(sp)
  677.     move    D3, -(sp)
  678.     _SetCtlValue
  679.     
  680.     RTS
  681.  
  682.  
  683. Get_Param_Items
  684.  
  685.     pea    ParamsDLOGStorage    ; Select 'X_Org' Parameter
  686.     move    #X_Org_Item, -(sp)    ; for Quick Replacement
  687.     move    #0, -(sp)
  688.     move    #32767, -(sp)
  689.     _SelIText
  690.  
  691. ModalDLOG
  692.  
  693.     clr.l    -(sp)        ; no filterProc
  694.     pea    ItemHit
  695.     _ModalDialog
  696.     
  697.     move    ItemHit, D0
  698.     tst    D0
  699.     BEQ    ModalDLOG
  700.     cmp    #1, D0        ; Clicked 'OK' = We're Done Dialoging ?
  701.     BEQ    Validate_Items    ; yes - Validate & Convert numeric entries    
  702.     cmp    #2, D0        ; Clicked 'Quit' ?
  703.     BEQ    Set_Exit_Flag    ; yes - tell MainLine
  704.     
  705.     cmp    #Radio_Item_1, D0 ; Clicked a Radio Button for penSize ?
  706.     bMI    ModalDLOG    ; no - wait for 'OK' or 'Quit'
  707.     cmp    #Radio_Item_3, D0
  708.     bHI    ModalDLOG        ; no - wait for 'OK' or 'Quit'
  709.     BSR    Toggle_Radio_Buttons    ; yes
  710.     BRA    ModalDLOG        ; and wait for 'OK' or 'Quit'
  711.  
  712.  
  713. Set_Exit_Flag
  714.  
  715.     move    #-1, D0
  716.     RTS
  717.     
  718.     
  719. Toggle_Radio_Buttons
  720.  
  721.     move    D0, D5            ; ( D0 gets trashed by ROM calls )
  722.     move    #HiLite_Off, D3        ; 
  723.     move    #Radio_Item_1, D4    ; turn off Everything
  724.     BSR    HiLite_Control
  725.     move    #Radio_Item_2, D4
  726.     BSR    HiLite_Control
  727.     move    #Radio_Item_3, D4
  728.     BSR    HiLite_Control
  729.     
  730.     sf    Radio_1_State(A5)    ; Flag them as OFF
  731.     sf    Radio_2_State(A5)
  732.     sf    Radio_3_State(A5)
  733.  
  734.     move    #HiLite_On, D3        ; turn ON the Radio Item
  735.     move    D5, D4            ; that was Clicked
  736.     BSR    HiLite_Control
  737.     
  738.     cmp    #Radio_Item_1, D5    ; and Flag the apt Item
  739.     BNE    @2            ; as ON
  740.     st    Radio_1_State(A5)
  741.     RTS
  742.     
  743. @2    cmp    #Radio_Item_2, D5
  744.     BNE    @3
  745.     st    Radio_2_State(A5)
  746.     RTS
  747.     
  748. @3    st    Radio_3_State(A5)
  749.     RTS
  750.     
  751.     
  752. Validate_Items
  753.  
  754.     move    #0, D3        ; Count - 1
  755.     lea    Count_Strings, A2    
  756.     move    #Count_Item_1, D4    ; Item # of 1st Count (MaxCount)
  757.  
  758. @0    BSR    Get_Item_Text    ; get the next Item Text
  759.     BSR    Convert_2_Int    ; Convert theString to Integer
  760.  
  761.     add    #10, A2        ; point to next String
  762.     add    #1, D4        ; and its Item Number
  763.     add    #1, D3        ; for Next Count Range
  764.     cmp    #4, D3        ; Done all 4 Count Ranges ?
  765.     BMI    @0        ; not yet
  766.     
  767.     RTS            ; Return to MainLine
  768.  
  769.     
  770. Get_Item_Text    ; A2 points to the String
  771.  
  772.     pea    ParamsDLOGStorage    ; DLOG Ptr
  773.     move    D4, -(sp)        ; Item Number
  774.     pea    ItemType        ; Not Used
  775.     pea    ItemHandle    ; passed to following ROM call
  776.     pea    ItemBox        ; Not Used
  777.     _GetDItem
  778.     
  779.     move.l    ItemHandle, -(sp)
  780.     move.l    A2, -(sp)
  781.     _GetIText
  782.     
  783.     RTS
  784.  
  785.  
  786. Convert_2_Int
  787.     
  788.     move.l    A2, A0
  789.     move    #StringToNum, -(sp)
  790.     _Pack7            ; Convert Count to Numeric
  791.     move    D3, D5        ; Which Count Range ?
  792.     add    D5, D5        ; Words => Bytes for Offset
  793.     lea    Counts(A5), A0
  794.     move    D0, 0(A0, D5)    ; Index & Save the Count
  795.                 ; ( Ignore the Hi Byte )
  796.     RTS
  797.         
  798.  
  799. Save_Param_Items
  800.  
  801.     move    #0, D3            ; D3 not used here
  802.     move    #X_Org_Item, D4
  803.     lea    X_Org_Str, A2        ; Following routine deposits
  804.     BSR    Get_Item_Text        ; DITL text in (A2)
  805.     
  806.     ; A2 (input) points to Decimal DITL String
  807.     ; D0 (returned) contains Fixed-Point Conversion
  808.                     
  809.     BSR    Convert_2_Fixed_Point    ; XREF routine to convert from
  810.     move.l    D0, X_Origin(A5)    ; STR format to Fixed-Point
  811.                     ; format via SANE intermediary
  812.     move    #Y_Org_Item, D4
  813.     lea    Y_Org_Str, A2
  814.     BSR    Get_Item_Text
  815.     BSR    Convert_2_Fixed_Point
  816.     move.l    D0, Y_Origin(A5)    
  817.  
  818.     move    #Side_Length_Item, D4
  819.     lea    Side_Length, A2
  820.     BSR    Get_Item_Text
  821.     BSR    Convert_2_Fixed_Point
  822.     move.l    D0, Y_Side(A5)
  823.         
  824.     RTS
  825.     
  826.  
  827. Draw_Org_Strings
  828.         
  829.     move    #X_Org_Scr_X, -(sp)
  830.     move    #X_Org_Scr_Y, D3    
  831.     move    D3, -(sp)
  832.     _MoveTo
  833.     pea    'X   '
  834.     _DrawString
  835.     pea    X_Org_Str
  836.     _DrawString
  837.     
  838.     move    #X_Org_Scr_X, -(sp)
  839.     add    #Org_Spacing, D3
  840.     move    D3, -(sp)
  841.     _MoveTo
  842.     pea    'Y   '
  843.     _DrawString
  844.     pea    Y_Org_Str
  845.     _DrawString
  846.  
  847.     move    #X_Org_Scr_X, -(sp)
  848.     add    #Org_Spacing, D3
  849.     move    D3, -(sp)
  850.     _MoveTo
  851.     pea    'S   '
  852.     _DrawString
  853.     pea    Side_Length
  854.     _DrawString
  855.  
  856.     RTS
  857.     
  858.  
  859. Open_Legend_DLOG
  860.  
  861.     clr.l    -(sp)        ; space for Funct result
  862.     move    #101, -(sp)
  863.     pea    LegendDLOGStorage
  864.     move.l    #-1, -(sp)    ; in front of everything
  865.     _GetNewDialog
  866.     move.l    (sp), -(sp)
  867.     _SetPort        ; so Title prints
  868.     _SelectWindow        ; so _DialogSelect works
  869.     
  870.     RTS
  871.  
  872.  
  873. Draw_Patterns
  874.  
  875.     clr    -(sp)        ; Save Digit Char Width
  876.     move    #'1', -(sp)    ; in D4 for Right-Justifying
  877.     _CharWidth
  878.     move    (sp)+, D4
  879.  
  880.     move    #Count_Str_Y, Legend_Y_Pos(A5)
  881.     move    #0, D3
  882.     lea    Count_Strings, A3    ; Addr of 1st Count Str
  883.     
  884. @Draw_Counts
  885.  
  886.     move    #Count_Str_X, -(sp)
  887.     move    Legend_Y_Pos(A5), -(sp)
  888.     _MoveTo
  889.     
  890.     cmp.b    #Max_Count_Digits, (A3)    ; Truncate STRs if too long
  891.     BMI    @0
  892.     move.b    #Max_Count_Digits, (A3)
  893.     
  894. @0    clr.l    D0        ; Right-Justify Count_Strings
  895.     move    #Max_Count_Digits, D0
  896.     clr    D1
  897.     move.b    (A3), D1    ; Byte Count for String
  898.     sub    D1, D0        ; Del_Digits = Max_Digits - Actual Digits
  899.     mulu    D4, D0        ; times Digit Char_Width
  900.     move.l    D0, -(sp)    ; = amount to space over
  901.     _Move            ; Relative Move
  902.     
  903.     move.l    A3, -(sp)
  904.     _DrawString        ; Write the Count Range Str
  905.  
  906.     move.l    (A5), A2        ; QD Vars Ptr
  907.     pea    Gray(A2)
  908.     _PenPat
  909.     move.l    #$FFFB0006, -(sp)    ; Move Up & Over a Bit
  910.     _Move                ; Draw a Short Gray Line to
  911.     move.l    #$0000000D, -(sp)    ;  separate the Patt_Rects
  912.     _Line
  913.     _PenNormal            ; Back to Black for Next String
  914.     
  915.     move    Legend_Y_Pos(A5), D0    ; move down for Next String
  916.     add    #Pattern_Spacing, D0
  917.     move    D0, Legend_Y_Pos(A5)
  918.     add.l    #Count_Str_Size, A3    ; point to Next String
  919.     
  920.     add    #1, D3
  921.     cmp    #4, D3
  922.     BMI    @Draw_Counts
  923.     
  924.     move    #Pattern_Y, Legend_Y_Pos(A5)
  925.     move    #0, D3
  926.     lea    Patterns, A3
  927.  
  928. @Draw_Patterns
  929.  
  930.     move    Legend_Y_Pos(A5), D0    ; Top
  931.     swap    D0        
  932.     move    #Pattern_X, D0        ; Left
  933.     
  934.     lea    TempRect, A0
  935.     move.l    D0, (A0)+        ; TopLeft
  936.     add.l    #$00130013, D0        ; 19 X 19
  937.     move.l    D0, (A0)        ; BottomRight
  938.     
  939.     pea    TempRect
  940.     move.l    (sp), -(sp)        ; push 2 copies of Rect Addr
  941.     move.l    (sp), -(sp)
  942.     _FrameRect
  943.     move.l    #$00010001, -(sp)
  944.     _InsetRect
  945.     move.l    A3, -(sp)
  946.     _FillRect
  947.     
  948.     move    Legend_Y_Pos(A5), D0    ; move down for Next String
  949.     add    #Pattern_Spacing, D0
  950.     move    D0, Legend_Y_Pos(A5)
  951.     add.l    #Pattern_Size, A3    ; point to Next Pattern
  952.     
  953.     add    #1, D3
  954.     cmp    #5, D3
  955.     BMI    @Draw_Patterns
  956.  
  957.     RTS
  958.     
  959.  
  960. Draw_Mandel_Window
  961.  
  962.     clr.l    -(sp)
  963.     move    #101, -(sp)
  964.     pea    MandelWindStorage
  965.     move.l    #-1, -(sp)
  966.     _GetNewWindow
  967.     _SetPort        ; nuthin hops if we don't do this
  968.     
  969.     lea    MandelWindStorage, A0
  970.     pea    portRect(A0)
  971.     _EraseRect
  972.     
  973.     RTS
  974.         
  975.  
  976. InitManagers
  977.  
  978.     pea    -4(A5)
  979.     _InitGraf
  980.     _InitFonts
  981.     _InitWindows
  982.     _InitMenus
  983.     clr.l    -(sp)
  984.     _InitDialogs
  985.     _TEInit
  986.     _InitCursor    ; the slings and arrows . . .
  987.     RTS
  988.  
  989.  
  990. ; -----------------  Constants ( in Code Space )  -------------------
  991.  
  992. MBarTitle    dc.b    'Dr. Dobb''s MandelZoom'
  993.  
  994. .ALIGN 2
  995.  
  996. MandelWindStorage    dcb.b    156, 0
  997. ParamsDLOGStorage    dcb.b    170, 0
  998. LegendDLOGStorage    dcb.b    170, 0
  999.  
  1000. ItemHit        dc.w    0
  1001. ItemType        dc.w    0    ; Not Used
  1002. ItemHandle    dc.l    0    ; passed from _GetDItem to _GetIText
  1003. ItemBox        dcb.l    2, 0    ; Not Used
  1004. theString    dcb.b    256, 0
  1005. theDialog    dc.l    0    ; for dialogPtr returned by _IsDialogEvent
  1006.  
  1007. X_Org_Str    dcb.b    10, 0
  1008. Y_Org_Str    dcb.b    10, 0
  1009. Side_Length    dcb.b    10, 0
  1010.  
  1011. Count_Strings    dcb.b    40, 0    ; 4 X 10 Bytes each
  1012.  
  1013. TempRect        dcb.l    2,  0    ; holds the Patt Rects for the Legend
  1014. TempSTR        dcb.b    40, 0
  1015. EventRecord
  1016.    What:        dc.w    0
  1017.    Message:    dc.l    0
  1018.    When:        dc.l    0
  1019.    Where:    dc.l    0
  1020.    Modifiers:    dc.w    0
  1021.  
  1022. Patterns
  1023.     dc.l    $FFFFFFFF    ; 4 pixels per 4 = black
  1024.     dc.l    $FFFFFFFF    
  1025.     
  1026.     dc.l    $FFAAFFAA    ; 3 pixels per 4 = dark gray
  1027.     dc.l    $FFAAFFAA    
  1028.  
  1029.     dc.l    $AA00AA00    ; 1 pixel  per 4 = light gray    
  1030.     dc.l    $AA00AA00
  1031.  
  1032.     dc.l    $00000000    ; 0 pixels per 4 = pure white    
  1033.     dc.l    $00000000
  1034.  
  1035.     dc.l    $AA55AA55    ; 2 pixels per 4 = gray    
  1036.     dc.l    $AA55AA55
  1037.  
  1038.  
  1039. ; ------------------  Variables ( off A5 )  ----------------------
  1040.  
  1041. X_Origin        ds.l    1    ; Fixed-Pt conversions from
  1042. Y_Origin        ds.l    1    ; User Entries in Params DLOG
  1043. X_Side        ds.l    1
  1044. Y_Side        ds.l    1    ; Set to X_Side for now
  1045.  
  1046. Y_Start        ds    1    ; where Pen first Plots
  1047.  
  1048. Num_Rows        ds    1
  1049. Num_Cols        ds    1
  1050. Pix_Per_Pt    ds    1
  1051.  
  1052. Counts        ds.w    4    ; 4 INTEGERs dividing the Iterative
  1053.                 ; Domain into 5 Ranges (& Patterns)
  1054. Iter_Count    ds.w    1
  1055. Row_Count    ds.w    1
  1056. Col_Count    ds.w    1
  1057.  
  1058. y_current    ds.w    1
  1059. x_current    ds.w    1
  1060.  
  1061. C_Real        ds.w    1
  1062.         ds.w    1
  1063. C_imag        ds.w    1
  1064.         ds.w    1
  1065.  
  1066. Z_Real        ds.w    1
  1067.         ds.w    1
  1068. Z_imag        ds.w    1
  1069.         ds.w    1
  1070.  
  1071. Del_C_Real    ds.l    1    
  1072. Del_C_imag    ds.l    1
  1073.  
  1074. Legend_Y_Pos    ds.w    1
  1075.  
  1076. Start_Time    ds.l    1
  1077.  
  1078. Radio_1_State    ds.b    1
  1079. Radio_2_State    ds.b    1
  1080. Radio_3_State    ds.b    1
  1081.  
  1082. First_Entry    ds.b    1
  1083. Mouse_Down    ds.b    1
  1084. First_Pt        ds.b    1
  1085.  
  1086.     END
  1087.  
  1088.  
  1089.  
  1090.  
  1091. Listing Two
  1092.  
  1093. ; < Str2FP.INC >    Thur 10 April '86   h. katz
  1094. ;            Mon  14 April '86
  1095.  
  1096.  
  1097. ; This File is Linked with MandelZoom.ASM to provide String-to Floating-Point
  1098. ; and Floating-Point to Fixed-Point Conversions for the 
  1099. ; X_Org, Y_Org, and Side_Len DITL Parameters
  1100.  
  1101. ; At present only Single-Precision SANE Conversions are used
  1102.  
  1103. ; A2 = ptr to the Decimal String on Input
  1104. ; D0 = the Fixed-Pt Number for Output
  1105.  
  1106.  
  1107. String_Format 3
  1108.  
  1109. Include MacTraps.D
  1110. Include SANEMacs.Txt
  1111.  
  1112. XDEF    Convert_2_Fixed_Point    
  1113.  
  1114. Sign        EQU    0    ; Byte Offsets in Decimal Record
  1115. Exp        EQU    2
  1116. Sig        EQU    4
  1117.     
  1118. FP_Sign        EQU    31    ; Bit Offsets in Single-Precision Result
  1119. FP_Exp        EQU    30
  1120. FP_Sig        EQU    22
  1121.  
  1122. SP_Exp_Bias    EQU    127
  1123. DP_Exp_Bias    EQU    1023    ; Code for Double-Precision not written
  1124.     
  1125.  
  1126. Convert_2_Fixed_Point
  1127.  
  1128.     lea    Temp_String, a0        ; make a copy of incoming string
  1129.     move.b    (a2), d0        ; its length
  1130. @0    move.b    (a2)+, (a0)+
  1131.     DBRA    d0, @0
  1132.     lea    Temp_String, a0        ; replace ptr to theString
  1133.     
  1134.     BSR    Build_Decimal_Record
  1135.     
  1136.     pea    Decimal_Record
  1137.     pea    FP_Num
  1138.     FDEC2S                ; a SANE 'trap'
  1139.  
  1140.     BSR    Build_Fixed_Pt
  1141.         
  1142.     RTS                ; to Mandelbrot
  1143.     
  1144.  
  1145. Build_Fixed_Pt
  1146.  
  1147.     sf    d2            ; assume Positive
  1148.     lea    FP_Num, a0
  1149.     move.l    (a0), d1        ; save the Exponent
  1150.     lsl.l    #1, d1            ; shift Sign into Carry
  1151.     bcc    @1            ; was Positve
  1152.     st    d2            ; flag as Negative
  1153.  
  1154. @1    swap    d1            ; move Exp into Low Word
  1155.     lsr.w    #8, d1            ; shift Exp to Right
  1156.     sub.b    #SP_Exp_Bias, d1    ; unbias it
  1157.     
  1158.     move.l    (a0), d0        ; move orig FP_Num into register
  1159.     and.l    #$007FFFFF, d0        ; clear Exp
  1160.     bset.l    #23, d0            ; add the leading '1' bit
  1161.     tst.b    d2
  1162.     beq    @2            ; num is +
  1163.     neg.l    d0
  1164.  
  1165. @2    sub.b    #7, d1            ; Neg(7-Exp) is amount to shift
  1166.     neg.b    d1
  1167.     bmi    @Shift_Left
  1168.     asr.l    d1, d0
  1169.     bra    @rts
  1170.     
  1171. @Shift_Left    
  1172.     neg.b    d1        ; Max Left Shift not checked for yet
  1173.     asl.l    d1, d0
  1174.     
  1175. @rts    RTS
  1176.     
  1177.     
  1178. Build_Decimal_Record
  1179.  
  1180.     ; Strip the Sign Char
  1181.     ; Strip the Decimal_Pt and Decrease the Exponent Accordingly
  1182.     ; Finally Strip Leading Zeroes
  1183.     
  1184.     lea    Decimal_Record, a1    ; Zero the Record
  1185.     move.l    #0, (a1)+
  1186.     move.l    #0, (a1)+
  1187.     move.l    #0, (a1)+
  1188.     move.l    #0, (a1)+
  1189.     lea    Decimal_Record, a1    
  1190.  
  1191.     cmp.b    #'+', 1(a0)        ; Strip the Plus Sign, if any
  1192.     BNE    @Strip_Minus_Sign
  1193.     BSR    Shift_Count_Byte
  1194.     bra    Strip_Decimal_Pt
  1195.  
  1196. @Strip_Minus_Sign
  1197.  
  1198.     cmp.b    #'-', 1(a0)
  1199.     BNE    Strip_Decimal_Pt
  1200.     move.b    #1, Sign(a1)        ; Mark Dec_Rec Sign as Negative
  1201.     BSR    Shift_Count_Byte
  1202.  
  1203. Strip_Decimal_Pt
  1204.  
  1205.     move.b    (a0), Sig(a1)        ; move Count to Decimal_Record
  1206.     lea    1+Sig(a1), a2        ; point to 1st Digit
  1207.     add.l    #1, a0            ; points to 1st Digit in Src Str
  1208.     clr    d0    
  1209.     move.b    Sig(a1), d0        ; length of String
  1210.     sub.b    #1, d0            ; - 1 for DBRA
  1211.     sf    d1            ; Passed_Decimal_Pt Flag = FALSE
  1212.     
  1213. @0    cmp.b    #'.', (a0)
  1214.     beq    @Found_Decimal_Pt
  1215.     move.b    (a0)+, (a2)+        ; shift the digit to Decimal_Rec
  1216.     tst.b    d1            ; are we past the Decimal Pt ?
  1217.     beq    @Test_EOStr
  1218.     sub    #1, Exp(a1)
  1219.     bra    @Test_EOStr
  1220.     
  1221. @Found_Decimal_Pt
  1222.  
  1223.     st    d1
  1224.     add.l    #1, a0            ; point past decimal point
  1225.     sub.b    #1, Sig(a1)        ; Count := Count - 1
  1226.  
  1227. @Test_EOStr
  1228.  
  1229.     DBRA    d0, @0
  1230.     
  1231.     
  1232. Strip_Leading_Zeroes
  1233.  
  1234.     lea    Sig(a1), a0        ; point @ Count Byte in
  1235.     move.b    (a0), d0        ; Decimal_Record Sig Field
  1236.     sub.b    #1, d0            ; setup for DBRA
  1237.     ext.w    d0
  1238.     sf    d1            ; No Leading Zeroes (yet)
  1239.     
  1240. @Loop_1
  1241.     cmp.b    #'0', 1(a0)
  1242.     BNE    @Test_4_Shift        ; Encountered a Signif Digit -> Done
  1243.     st    d1
  1244.     BSR    Shift_Count_Byte
  1245.     DBRA    d0, @Loop_1
  1246.     
  1247.  
  1248. @Test_4_Shift
  1249.  
  1250.     tst.b    d1        ; Any Non-Significant Zeroes Found ?
  1251.     BEQ    @rts        ; no
  1252.     
  1253.     lea    Sig(a1), a1    ; point to Sig Count Byte
  1254.     move.b    (a0), d0    ; a0 is Count Byte (wherever it is)
  1255.     ext.w    d0        
  1256.     
  1257. @Loop_2
  1258.     move.b    (a0)+, (a1)+    ; shift Count + Digits to Left
  1259.     DBRA    d0, @Loop_2
  1260.     
  1261. @rts    RTS
  1262.  
  1263.     
  1264. Shift_Count_Byte
  1265.  
  1266.     sub.b    #1, (a0)    ; Length = Length - 1
  1267.     move.b    (a0)+, (a0)    ; move Count Byte over one
  1268.     RTS
  1269.     
  1270.  
  1271. ; ----------------------------------------------------------
  1272.  
  1273.  
  1274. FP_Num        dc.b    8, 0    ; working space for both 
  1275.                 ; Single & Double Precision numbers
  1276. Decimal_Record        
  1277.         dc.w     0    ; Sign
  1278.         dc.w     0    ; Exp
  1279.         dcb.b    12, 0    ; Sig
  1280.  
  1281. Temp_String    dcb.b    12, 0
  1282.  
  1283.  
  1284. END
  1285.