home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 437a.lha / Mandel_v1.0 / source / gui.asm < prev    next >
Encoding:
Assembly Source File  |  1990-11-09  |  110.1 KB  |  4,020 lines

  1.  
  2. * This file: gui v1.00
  3.  
  4. * (c) 1990 by H. Helminen
  5.  
  6. * linkage information:
  7. * blink gui.o brot.o pipe.o to mandel lib amiga.lib
  8.  
  9. * And now for something completely different:
  10. * A graphical user interface for MandelBrot.
  11.  
  12. * of course by The DM (Hannu Helminen, dm@stekt.oulu.fi)
  13.  
  14. * BUGS: many, including
  15. * - coordinates in screen title may trash window title bar
  16. * - if not enough memory, 56 bytes will disappear.
  17.  
  18.             NOLIST
  19.             INCLUDE  "macros.i"
  20.             INCLUDE  "mbrot.i"
  21.             INCLUDE  "iff.i"
  22.             INCLUDE  "exec/lists.i"
  23.             INCLUDE  "exec/memory.i"
  24.             INCLUDE  "exec/ports.i"
  25.             INCLUDE  "exec/alerts.i"
  26.             INCLUDE  "devices/timer.i"
  27.             INCLUDE  "libraries/dos.i"
  28.             INCLUDE  "libraries/dosextens.i"
  29.             INCLUDE  "intuition/screens.i"
  30.             INCLUDE  "intuition/intuition.i"
  31.             INCLUDE  "workbench/workbench.i"
  32.             INCLUDE  "workbench/startup.i"
  33.  
  34.             XREF     _LVOAlert
  35.  
  36. * Misc defines
  37.  
  38. DEPTH       EQU   5     ; # of bitplanes (use at least 3 (2 is minimum))
  39. SCREEN      EQU   0
  40.  
  41. * SCREEN: Select one of the following:
  42.  
  43. *        non-lace lace
  44. * lores     0       2
  45. * hires     1       3
  46.  
  47. * SCREEN determines VIEWMODE, screen size and mb_dx/mb_dy scaling.
  48. * NOTE: if SCREEN > 0, max. magnification will be 28
  49.  
  50.          ifeq  SCREEN-0
  51. VIEWMODE    EQU   0
  52. XSIZE       EQU   320      ; Size of screen
  53. YSIZE       EQU   256
  54.          endc
  55.          ifeq  SCREEN-1
  56. VIEWMODE    EQU   V_HIRES
  57. XSIZE       EQU   640
  58. YSIZE       EQU   256
  59.          endc
  60.          ifeq  SCREEN-2
  61. VIEWMODE    EQU   V_LACE
  62. XSIZE       EQU   320
  63. YSIZE       EQU   512
  64.          endc
  65.          ifeq  SCREEN-3
  66. VIEWMODE    EQU   V_HIRES|V_LACE
  67. XSIZE       EQU   640
  68. YSIZE       EQU   512
  69.          endc
  70.  
  71. WINX        EQU   20      ; Place & size of info window
  72. WINY        EQU   20
  73. WINW        EQU   148
  74. WINH        EQU   80
  75.  
  76. RASSIZE     EQU   ((XSIZE+15)/16*2)*YSIZE
  77. MAXVECT     EQU   6553  ; Cant get bigger than this. (Sigh.)
  78.  
  79. NORMAL_X    EQU   0
  80. NORMAL_Y    EQU   0
  81. NORMAL_JX   EQU   0
  82. NORMAL_JY   EQU   0
  83. NORMAL_I    EQU   100
  84. NORMAL_ZOOM EQU   $010000
  85. NORMAL_M    EQU   $060000
  86. MIN_M       EQU   $050000
  87.  
  88.          ifeq  SCREEN
  89. MAX_M       EQU   $1d0000
  90.          endc
  91.          ifgt  SCREEN
  92. MAX_M       EQU   $1c0000
  93.          endc
  94.  
  95. FLAGS1      EQU   ACTIVATE|BACKDROP|BORDERLESS|REPORTMOUSE|RMBTRAP|NOCAREREFRESH
  96. FLAGS2      EQU   WINDOWCLOSE|WINDOWDRAG|RMBTRAP|NOCAREREFRESH
  97.  
  98. IDCMP1      EQU   MOUSEMOVE|MOUSEBUTTONS|RAWKEY
  99. IDCMP2      EQU   GADGETUP|GADGETDOWN|CLOSEWINDOW|RAWKEY
  100.  
  101. FAKECLASS   EQU   3  ; This pretends to be one of IDCMP classes
  102.  
  103. ZOOM        EQU   0  ; these internal tokens represent method of zooming
  104. REDRAW      EQU   1
  105. RESET       EQU   2
  106.  
  107. TRUE        EQU   1
  108. FALSE       EQU   0
  109.  
  110. * Import brot entry point
  111.             XREF  MandelBrot
  112.  
  113. * A simple macro that converts letters to upper case
  114. toupper  macro
  115.          cmp.b #'a',\1
  116.          blo.s no\@
  117.          sub.b #'a'-'A',\1
  118. no\@:    ds.w  0           ; needed for assembler's sake.
  119.          endm
  120.  
  121.  
  122.             LIST
  123.  
  124.  
  125.             SECTION  main,CODE
  126.  
  127. * This is where the actual code begins.
  128.          push     d1-d7/a0-a6
  129.  
  130.          move.l   a0,a3
  131.          move.w   d0,d3
  132.  
  133. * We need to find out whether we have been invoked from CLI or WorkBench
  134.          sub.l    a1,a1
  135.          Base     Exec
  136.          Call     FindTask
  137.          move.l   d0,a0          ; This is a process, right?
  138.          move.l   pr_CLI(a0),d0
  139.          beq.s    from_WB
  140.  
  141.          clr.b    -1(a3,d3.w)
  142.          clr.l    WBmessage      ; from CLI
  143.          move.l   d0,a0
  144.          add.l    a0,a0          ; BPTR conversion
  145.          add.l    a0,a0
  146.          move.l   cli_CommandName(a0),a0  ; BSTR
  147.          add.l    a0,a0          ; BPTR conversion
  148.          add.l    a0,a0          ; now here we'll find a BCPL string...
  149.          move.b   (a0)+,d0       ; get len and goto first character
  150.          move.l   a0,MyName      ; save name
  151.          ext.w    d0
  152.          move.w   d0,MyNameLen   ; and length
  153.  
  154.          bra.s    common_code
  155. from_WB:
  156.          lea      pr_MsgPort(a0),a3
  157.          move.l   a3,a0
  158.          Call     WaitPort
  159.          move.l   a3,a0
  160.          Call     GetMsg
  161.          move.l   d0,WBmessage   ; Do not reply until ready to exit.
  162.  
  163.          move.l   d0,a0
  164.          move.l   sm_ArgList(a0),d0 ; Argument list
  165.          beq.s    common_code
  166.          move.l   d0,a0
  167.          move.l   wa_Lock(a0),d2    ; lock to current directory
  168.          move.l   wa_Name(a0),a0
  169.          move.l   a0,MyName         ; save name
  170.          moveq    #-1,d1
  171. 1$
  172.          addq.w   #1,d1
  173.          tst.b    (a0)+
  174.          bne.s    1$
  175.          move.w   d1,MyNameLen      ; and length
  176.  
  177. common_code:
  178.  
  179. * Open some libraries
  180.          lea      _DosLib,a1
  181.          moveq    #0,d0
  182.          Call     OpenLibrary
  183.          move.l   d0,_DosBase
  184.          bne.s    dos_ok
  185.          ALERT    AG_OpenLib|AO_DOSLib
  186.          bra      nodos
  187. dos_ok:
  188.          tst.l    WBmessage
  189.          beq.s    1$
  190.          move.l   d2,d1
  191.          Base     Dos
  192.          Call     CurrentDir
  193.          Base     Exec
  194. 1$
  195.          lea      _IntuitionLib,a1
  196.          moveq    #0,d0
  197.          Call     OpenLibrary
  198.          move.l   d0,_IntuitionBase
  199.          bne.s    intui_ok
  200.          ALERT    AG_OpenLib|AO_Intuition
  201.          bra      nointui
  202. intui_ok:
  203.          lea      _GfxLib,a1
  204.          moveq    #0,d0
  205.          Call     OpenLibrary
  206.          move.l   d0,_GfxBase
  207.          bne.s    gfx_ok
  208.          ALERT    AG_OpenLib|AO_GraphicsLib
  209.          bra      nogfx
  210. gfx_ok:
  211.  
  212. * Open timer.device
  213.          lea      _TimerDev,a0
  214.          moveq    #UNIT_VBLANK,d0
  215.          lea      IOreq,a1
  216.          moveq    #0,d1
  217.          Call     OpenDevice
  218.          tst.b    d0
  219.          beq.s    timer_ok
  220.          ALERT    AG_OpenDev|AO_TimerDev
  221.          bra      timererr
  222. timer_ok:
  223. * initialize msgport
  224.          lea      MsgPort,a2
  225.          move.b   #NT_MSGPORT,LN_TYPE(a2)
  226.          clr.b    LN_PRI(a2)
  227.          clr.l    LN_NAME(a2)
  228.          move.b   #PA_SIGNAL,MP_FLAGS(a2)    ; signal me when done
  229.  
  230.          moveq    #-1,d0
  231.          move.b   #ERROR_nosignal,error
  232.          Call     AllocSignal          ; get a signal bit
  233.          tst.b    d0
  234.          bmi      nosignal
  235.          move.b   d0,MP_SIGBIT(a2)
  236.  
  237.          sub.l    a1,a1
  238.          Call     FindTask
  239.          move.l   d0,MP_SIGTASK(a2)
  240.                                        ; task to be signalled
  241.          lea      MP_MSGLIST(a2),a0
  242.          NEWLIST  a0                   ; init link fields
  243.          lea      IOreq,a0
  244.          move.l   a2,MN_REPLYPORT(a0)
  245.          clr.l    UseReq               ; mark it as not being in use
  246.  
  247.          move.l   a3,a0
  248.  
  249.          lea      MyMandelBrot,a4
  250.  
  251.          move.w   #0,mb_x1(a4)
  252.          move.w   #0,mb_y1(a4)
  253.          move.w   #XSIZE-1,mb_x2(a4)
  254.          move.w   #YSIZE-1,mb_y2(a4)
  255.  
  256. * Defaults
  257.          move.b   #ERROR_none,error
  258.          move.w   #NORMAL_I,mb_i(a4)
  259.          move.b   #MBF_AUTOPREC|MBF_AUTOCRAWL,mb_flags(a4)
  260.          move.b   #TRUE,inter
  261.          move.b   #ZOOM,method
  262.          clr.b    isdrawn
  263.          clr.w    Counter
  264.          clr.b    saveit
  265.  
  266.          move.l   #NORMAL_ZOOM,Zoom    ; 2^(-1) = 50%
  267.          move.l   #NORMAL_M,Magnify    ; 2^(-6) = 1/64
  268.          move.l   #NORMAL_X,CurrentX
  269.          move.l   #NORMAL_Y,CurrentY
  270.          move.l   #NORMAL_JX,mb_jx(a4)
  271.          move.l   #NORMAL_JY,mb_jy(a4)
  272.  
  273.          lea      CtrlC,a1
  274.          move.l   a1,mb_break(a4)   ; Call-back procedure
  275.  
  276.          move.w   #(1<<DEPTH)-2,mb_colors(a4)
  277.  
  278. * This is again WB/CLI specific code, option processing
  279.          tst.l    WBmessage
  280.          beq      CLI_1
  281.  
  282. * WB option stuff
  283.          Base     Exec
  284.          lea      _IconLib,a1
  285.          moveq    #0,d0
  286.          Call     OpenLibrary
  287.          tst.l    d0
  288.          bne.s    iconlib_ok
  289. * Currently this error is not reported...
  290.          move.b   #ERROR_iconlib,error
  291.          bra      options_done
  292. iconlib_ok
  293.          move.l   d0,a6
  294.          move.l   MyName,a0
  295.          Call     GetDiskObject
  296.          tst.l    d0
  297.          bne.s    diskobject_ok
  298.          move.b   #ERROR_noicon,error
  299.          bra.s    close_icon_lib
  300. diskobject_ok
  301.          move.l   d0,a5          ; disk object
  302.          lea      WBjumptable,a2
  303.          lea      WBoptions,a3
  304. browse_tools
  305.          tst.b    (a3)              ; The last in line?
  306.          beq.s    icons_done
  307.          move.l   do_ToolTypes(a5),a0
  308.          move.l   a3,a1
  309.          Call     FindToolType
  310.          move.l   (a2)+,a1          ; The actual address to jump to
  311.          tst.l    d0
  312.          beq.s    tool_notfound
  313.          move.l   d0,a0
  314.          jsr      (a1)
  315.          beq.s    wrong_option
  316. tool_notfound
  317.          tst.b    (a3)+
  318.          bne.s    tool_notfound     ; Find next tool type
  319.          bra.s    browse_tools
  320. wrong_option
  321.          move.b   #ERROR_tooltype,error
  322. icons_done
  323.          move.l   a5,a0
  324.          Call     FreeDiskObject
  325. close_icon_lib
  326.          move.l   a6,a1
  327.          Base     Exec
  328.          Call     CloseLibrary
  329.          tst.b    error
  330.          bne      nosignal
  331.          bra.s    options_done
  332.  
  333. CLI_1
  334.          lea      LongUsage,a3
  335.          move.l   #LongLen,d3
  336.          tst.b    (a0)
  337.          beq.s    options_done
  338.          cmp.b    #'?',(a0)
  339.          beq.s    usage
  340.  
  341.          move.b   #ERROR_cmdline,error
  342.          lea      ShortUsage,a3
  343.          move.l   #ShortLen,d3
  344. getnext:
  345.          move.b   (a0)+,d0
  346.          beq.s    options_done
  347.          cmp.b    #' ',d0
  348.          beq.s    getnext
  349.          cmp.b    #8,d0
  350.          beq.s    getnext
  351.          cmp.b    #'-',d0
  352.          bne.s    usage
  353.  
  354.          move.b   (a0)+,d0
  355.          lea      options,a1
  356.          lea      jumptable,a2
  357.  
  358.          toupper  d0
  359. getopt:
  360.          move.l   (a2)+,a5
  361.          cmp.b    (a1)+,d0
  362.          bne.s    next
  363.          jsr      (a5)
  364.          beq.s    usage          ; a result of zero means wrong option
  365.          bra.s    getnext
  366. next:
  367.          tst.b    (a1)
  368.          bne.s    getopt
  369. usage:
  370.          Base     Dos
  371.          Call     Output
  372.          move.l   d0,d1
  373.          move.l   a3,d2
  374.          Call     Write
  375.          bra      noscreen       ; draw nothing
  376. options_done:
  377.  
  378. * Screen to display the new map.
  379.          lea      MyNewScreen,a0
  380.          Base     Intuition
  381.          Call     OpenScreen
  382.          move.b   #ERROR_noscreen,error
  383.          move.l   d0,MyScreen
  384.          beq      noscreen
  385.          move.l   d0,a2
  386.  
  387.          move.l   a2,InsertScreen1
  388.          move.l   a2,InsertScreen2
  389.  
  390.          lea      sc_ViewPort(a2),a3
  391.  
  392. * First window that takes over entire screen
  393.          lea      MyNewWindow1,a0
  394.          Call     OpenWindow
  395.          move.b   #ERROR_nowindow,error
  396.          move.l   d0,MyWindow1
  397.          beq      nowindow
  398.  
  399. * This version fetches windows rastport.
  400.          move.l   d0,a0
  401.          move.l   wd_RPort(a0),a2
  402.          move.l   a2,mb_RastPort(a4)
  403.  
  404.          move.l   a3,a0
  405.          lea      Colors,a1
  406.          moveq    #(1<<DEPTH),d0
  407.          Base     Gfx
  408.          Call     LoadRGB4
  409.  
  410. * Now get a TmpRas to screen
  411.          move.l   #RASSIZE,d0
  412.          moveq    #MEMF_CHIP,d1
  413.          move.l   d1,d2
  414.          Base     Exec
  415.          Call     AllocMem
  416.          move.b   #ERROR_nomem,error
  417.          move.l   d0,Mem1
  418.          beq      nomem1
  419.          lea      MyTmpRas,a3
  420.          move.l   d0,a1
  421.          move.l   a3,a0
  422.          move.l   d2,d0
  423.          Base     Gfx
  424.          Call     InitTmpRas
  425.          move.l   a3,rp_TmpRas(a2)
  426.  
  427.          move.l   #MAXVECT*5,d0
  428.          moveq    #0,d1
  429.          Base     Exec
  430.          Call     AllocMem
  431.          move.l   d0,Mem2
  432.          beq      nomem2
  433.          lea      MyAreaInfo,a3
  434.          move.l   a3,a0
  435.          move.l   d0,a1
  436.          move.l   #MAXVECT,d0
  437.          Base     Gfx
  438.          Call     InitArea
  439.          move.l   a3,rp_AreaInfo(a2)
  440.  
  441.          move.b   #ERROR_none,error
  442. * main loop if 'interactive'
  443. loop:
  444.          move.l   Magnify,d0
  445.          move.l   #MAX_M,d1
  446.          cmp.l    d1,d0
  447.          bls.s    1$
  448.          move.l   d1,d0
  449. 1$:
  450.          move.l   #MIN_M,d1
  451.          cmp.l    d1,d0
  452.          bhs.s    2$
  453.          move.l   d1,d0
  454. 2$:
  455.          move.l   d0,Magnify
  456.          bsr      Transform
  457.          move.l   Magnify,OldMagnify
  458.  
  459. * This is why we did all the above... and will be doing all the below...
  460. * Draw mandelbrot!
  461.          move.l   a4,a0
  462.          jsr      MandelBrot
  463.  
  464.          tst.b    inter
  465.          beq      exit        ; user didnt want us to be interactive.
  466.  
  467. * A friend of mine once pointed out that the doings of my
  468. * programs are often commented to be done by "we". Don't know why.
  469.  
  470. * Perhaps I think my program is a person, and we are doing the
  471. * thing together, I by designing the program, and the program
  472. * in turn by running it.
  473.  
  474. * One of these days, I may actually begin to talk to my programs.
  475. * Is that all right to you, my tiny little proggie?
  476.  
  477.          bsr      calculate
  478. reopen:
  479. * Open another window
  480.          lea      MyNewWindow2,a0
  481.          Base     Intuition
  482.          Call     OpenWindow
  483.          move.l   d0,MyWindow2
  484.          beq      exit_dont_save      ; could not get memory
  485. * Thenafter, refresh allll gadgets.
  486.  
  487. * This gives refresh_m and refresh_z a hassle-free operation
  488.          move.b   method,d7
  489.          move.b   #RESET,method
  490.  
  491.          move.l   CurrentX,d0
  492.          bsr      refresh_x
  493.          move.l   CurrentY,d0
  494.          bsr      refresh_y
  495.          move.l   Magnify,d0
  496.          bsr      refresh_m
  497.          move.w   mb_i(a4),d0
  498.          bsr      refresh_i
  499.          move.l   Zoom,d0
  500.          bsr      refresh_z
  501.  
  502.          move.b   d7,method
  503.  
  504.          bsr      refresh_set
  505.          bsr      refresh_zoom   ; this does also DrawGrid
  506.  
  507. msgloop:
  508.          bsr      GetMessage
  509.          bne      exitloop        ; nonzero if user issued break
  510. gotmessage:
  511.          Base     Intuition
  512.          cmp.l    #CLOSEWINDOW,d2
  513.          bne.s    no_close
  514.  
  515.  
  516. * Info window is about to be closed. Hide also title bar.
  517.          move.l   MyWindow2,a0
  518.  
  519. * This copies both LeftEdge and TopEdge to NewWindow structure
  520. * This way when the window is opened again, it will be in same place.
  521.          move.l   wd_LeftEdge(a0),MyNewWindow2
  522.          Call     CloseWindow
  523.          clr.l    MyWindow2   ; This window is closed
  524.          move.l   MyScreen,a0
  525.          moveq    #FALSE,d0
  526.          Call     ShowTitle
  527.          bsr      RemoveGrid
  528.  
  529. * Resume when either button pressed
  530. get_it:  bsr      GetMessage
  531.          bne      exit        ; break, no need to close window
  532.          cmp.l    #MOUSEBUTTONS,d2
  533.          bne.s    get_it      ; wait for it to happen
  534.  
  535. * Restore all
  536.          bsr      DrawGrid
  537.          move.l   MyScreen,a0
  538.          moveq    #TRUE,d0
  539.          Base     Intuition
  540.          Call     ShowTitle
  541.          bra      reopen      ; resume window
  542.  
  543.  
  544. no_close:
  545.          cmp.l    #MOUSEMOVE,d2
  546.          bne.s    no_move
  547.          bsr      dispCoords  ; All we do here is to display current
  548.          bra.s    msgloop     ; coordinates
  549.  
  550.  
  551. no_move:
  552.          cmp.l    #MOUSEBUTTONS,d2
  553.          bne.s    no_buttons
  554.          cmp.w    #SELECTDOWN,d3
  555.          bne.s    no_left_button
  556.          bsr      LeftButton     ; 3 things might get returned:
  557.          beq      msgloop     ; finished
  558.          bmi      exitloop    ; ^C
  559.          bra      zoom_draw   ; There has been a double-click -> Draw!
  560. no_left_button:
  561.          cmp.w    #MENUDOWN,d3
  562.          bne.s    no_buttons
  563.          bsr      RightButton
  564.          bne      exitloop
  565.          bra      msgloop
  566. no_buttons:
  567.  
  568.          cmp.w    #GADGETDOWN,d2
  569.          bne.s    no_gadg_down
  570.          move.w   gg_GadgetID(a5),d1   ; Gadget's ID.
  571.          move.w   d1,d0
  572.          and.w    #STRING,d0
  573.          beq.s    not_string_gadget
  574.  
  575.          bsr      StringGadgetDown  ; we also get one message here.
  576.          bne      exitloop          ; sigh. (l)user wants to get rid of us
  577.          bra      gotmessage        ; yeah, we've already got one.
  578. not_string_gadget:
  579.          bsr      OtherGadgetDown   ; Three things might return from this:
  580.          bmi.s    zoom_draw         ; negative if zoom
  581.          bne      exitloop          ; positive if exit
  582.  
  583. no_gadg_down:
  584.          cmp.l    #RAWKEY,d2
  585.          bne.s    no_rawkey
  586.          cmp.w    #$21,d3           ; RAW key code for 'S'
  587.          bne.s    no_rawkey
  588.          btst     #IEQUALIFIERB_CONTROL,d4
  589.          beq.s    no_rawkey
  590.          move.l   MyWindow2,a0
  591.          move.l   wd_LeftEdge(a0),MyNewWindow2  ; See previous CloseWindow
  592.          Call     CloseWindow
  593.          clr.l    MyWindow2      ; This window is closed
  594.          move.l   MyScreen,a0
  595.          moveq    #FALSE,d0
  596.          Call     ShowTitle
  597.          bsr      RemoveGrid
  598.  
  599.          bsr      SavePicture
  600.  
  601.          bsr      DrawGrid
  602.          move.l   MyScreen,a0
  603.          moveq    #TRUE,d0
  604.          Base     Intuition
  605.          Call     ShowTitle
  606.          bra      reopen      ; open window again
  607.  
  608. no_rawkey:
  609.          bra      msgloop           ; and zero if nothing
  610.  
  611. zoom_draw:
  612.          move.l   MyWindow2,a0
  613.          Base     Intuition
  614.          move.l   wd_LeftEdge(a0),MyNewWindow2  ; See previous CloseWindow
  615.          Call     CloseWindow
  616.          bsr      RemoveGrid
  617.          cmp.b    #ZOOM,method
  618.          beq.s    1$
  619.          cmp.b    #REDRAW,method
  620.          beq.s    2$
  621.          move.l   #NORMAL_M,Magnify
  622.          move.l   #NORMAL_X,CurrentX
  623.          move.l   #NORMAL_Y,CurrentY
  624.          bra      loop
  625. 1$:
  626.          move.l   Zoom,d0
  627.          add.l    d0,Magnify
  628. 2$:
  629.          bra      loop
  630.  
  631.  
  632.  
  633.  
  634. exitloop:
  635. * Close window
  636.          move.l   MyWindow2,a0
  637.          Base     Intuition
  638.          Call     CloseWindow
  639.          bsr      RemoveGrid
  640.  
  641. * Leave ship
  642. exit:
  643. * If non-interactive and user explicitely set -s option, save picture.
  644.          tst.b    inter
  645.          bne.s    exit_dont_save
  646.          tst.b    saveit
  647.          beq.s    exit_dont_save
  648.          bsr      SavePicture
  649. exit_dont_save
  650.          move.l   MyScreen,a0
  651.          moveq    #FALSE,d0
  652.          Base     Intuition
  653.          Call     ShowTitle
  654.  
  655.          move.l   Mem2,a1
  656.          move.l   #5*MAXVECT,d0
  657.          Base     Exec
  658.          Call     FreeMem
  659. nomem2:
  660.          move.l   Mem1,a1
  661.          move.l   #RASSIZE,d0
  662.          Base     Exec
  663.          Call     FreeMem
  664. nomem1:
  665.          Base     Intuition
  666.          move.l   MyWindow1,a0
  667.          Call     CloseWindow
  668. nowindow:
  669.          move.l   MyScreen,a0
  670.          Call     CloseScreen
  671. noscreen:
  672.          lea      MsgPort,a0
  673.          move.b   MP_SIGBIT(a0),d0
  674.          Base     Exec
  675.          Call     FreeSignal
  676. nosignal:
  677.          lea      IOreq,a1
  678.          Call     CloseDevice
  679. timererr:
  680.          move.l   _GfxBase,a1
  681.          Call     CloseLibrary
  682. nogfx:
  683.          move.l   _IntuitionBase,a1
  684.          Call     CloseLibrary
  685. nointui:
  686.          tst.b    error
  687.          beq.s    close_dos   ; no error
  688.  
  689.          Base     Dos
  690.          tst.l    WBmessage
  691.          beq.s    CLI_2
  692.          lea      stdout_name,a0
  693.          move.l   a0,d1
  694.          move.l   #MODE_NEWFILE,d2
  695.          Call     Open
  696.          tst.l    d0
  697.          beq.s    close_dos
  698.          bra.s    common_code2
  699. CLI_2
  700.          Call     Output
  701. common_code2
  702.          move.l   d0,d4       ; save file handle for further use
  703.  
  704. * First, output our name.
  705.          move.l   d4,d1
  706.          move.l   MyName,d2
  707.          move.w   MyNameLen,d3
  708.          ext.l    d3
  709.          Call     Write
  710.  
  711. * Then, the error message.
  712.          move.l   d4,d1
  713.          move.b   error,d0
  714.          ext.w    d0
  715.          lsl.w    #2,d0
  716.          lea      errors,a0
  717.          move.l   0(a0,d0.w),a0
  718.          move.l   a0,d2
  719.          moveq    #-1,d3
  720. 1$
  721.          addq.l   #1,d3
  722.          tst.b    (a0)+
  723.          bne.s    1$
  724.          Call     Write
  725.  
  726.          tst.l    WBmessage
  727.          beq.s    close_dos
  728.          move.l   #2*TICKS_PER_SECOND,d1
  729. * REM ALLOW TIME FOR USER TO RELEASE BUTTON FROM LAST PUSH
  730.          Call     Delay
  731.          move.l   d4,d1
  732.          Call     Close       ; close stdout window
  733. close_dos
  734.          Base     Exec
  735.          move.l   _DosBase,a1
  736.          Call     CloseLibrary
  737.          move.l   WBmessage,d0
  738.          beq.s    nodos
  739.          Call     Forbid
  740.          move.l   d0,a1
  741.          Call     ReplyMsg       ; Now WB knows we are safe to get rid of
  742. nodos:
  743.          moveq    #0,d0
  744.          move.b   error,d0
  745.          beq.s    2$
  746.          moveq    #RETURN_FAIL,d0
  747. 2$:
  748.          pull     d1-d7/a0-a6
  749.          rts
  750.  
  751. RemoveGrid:
  752.          tst.b    isdrawn
  753.          beq      nothing_to_remove
  754.  
  755.          push     d0-d2/a0-a2/a6
  756.  
  757.          Base     Intuition
  758.          move.l   MyWindow1,a0
  759.          move.l   wd_RPort(a0),a2
  760.  
  761. * DrawGrid has conveniently set up some values for me. How nice of him!
  762.          move.w   centerx,d0
  763.          move.w   centery,d1
  764.          move.l   pic_c,a1
  765.          bsr.s    remove_1
  766.  
  767.          move.w   lowx,d0
  768.          move.w   lowy,d1
  769.          move.l   pic_tl,a1
  770.          bsr.s    remove_1
  771.  
  772.          move.w   lowx,d0
  773.          move.w   highy,d1
  774.          move.l   pic_bl,a1
  775.          bsr.s    remove_1
  776.  
  777.          move.w   highx,d0
  778.          move.w   lowy,d1
  779.          move.l   pic_tr,a1
  780.          bsr.s    remove_1
  781.  
  782.          move.w   highx,d0
  783.          move.w   highy,d1
  784.          move.l   pic_br,a1
  785.          bsr.s    remove_1
  786.  
  787.          clr.b    isdrawn
  788.          pull     d0-d2/a0-a2/a6
  789. nothing_to_remove:
  790.          rts
  791.  
  792. remove_1:
  793.          move.l   a2,a0
  794.          move.l   a1,d2
  795.          beq.s    1$
  796.          Call     DrawBorder
  797. 1$:      rts
  798.  
  799.  
  800. DrawGrid:
  801.          bsr      RemoveGrid
  802.          cmp.b    #ZOOM,method
  803.          beq.s    draw_yes
  804.          cmp.b    #RESET,method
  805.          beq      draw_over
  806.          move.l   Magnify,d0
  807.          cmp.l    OldMagnify,d0
  808.          bne      draw_over
  809. draw_yes:
  810.          push     a0-a2/a6/d0-d7
  811.          move.l   prex,d0
  812.          move.l   prey,d1
  813.          move.b   #TRUE,isdrawn
  814.  
  815.          move.l   d0,prex
  816.          move.l   d1,prey
  817.          move.l   #$8000,d2      ; round
  818.          add.l    d2,d0
  819.          add.l    d2,d1
  820.  
  821.          move.l   d0,d4
  822.          move.l   d1,d5
  823.  
  824.          swap     d0
  825.          swap     d1
  826.  
  827.          moveq    #0,d2          ; record # of crossings
  828.          Base     Intuition
  829.          lea      Cross,a1
  830.          move.l   MyWindow1,a0
  831.          move.l   wd_RPort(a0),a2
  832.  
  833.          cmp.w    mb_x1(a4),d0
  834.          bge.s    1$
  835.          move.w   mb_x1(a4),d0
  836.          lea      LeftLeft,a1
  837.          addq.w   #1,d2
  838. 1$:
  839.          cmp.w    mb_x2(a4),d0
  840.          ble.s    2$
  841.          move.w   mb_x2(a4),d0
  842.          lea      RightRight,a1
  843.          addq.w   #1,d2
  844. 2$:
  845.          cmp.w    mb_y1(a4),d1
  846.          bge.s    3$
  847.          move.w   mb_y1(a4),d1
  848.          lea      UpUp,a1
  849.          addq.w   #1,d2
  850. 3$:
  851.          cmp.w    mb_y2(a4),d1
  852.          ble.s    4$
  853.          move.w   mb_y2(a4),d1
  854.          lea      DownDown,a1
  855.          addq.w   #1,d2
  856. 4$:
  857.          cmp.w    #1,d2       ; only 1 crossing allowed
  858.          bls.s    ok_to_disp
  859.          clr.l    pic_c
  860.          bra.s    cross_over
  861. ok_to_disp:
  862.          move.w   d0,centerx
  863.          move.w   d1,centery
  864.  
  865.          move.l   a2,a0
  866.          move.l   a1,pic_c
  867.          Call     DrawBorder
  868. cross_over:
  869.          move.w   mb_x2(a4),d0
  870.          sub.w    mb_x1(a4),d0
  871.          move.l   Zoom,d3
  872.  
  873.          cmp.b    #REDRAW,method ; if redraw, grid has size of screen
  874.          bne.s    revolution
  875.          moveq    #0,d3
  876. revolution:
  877.          add.l    #$10000,d3
  878.          bmi      pig_big
  879.  
  880.          moveq    #0,d1
  881.          moveq    #0,d2
  882.          bsr      Power2
  883. * Hey! What are you doing?
  884. * We will find how long the side of the grid should be.
  885. * If Zoom < -$10000, it wont fit on the screen same time as
  886. * crosshairs. And adding $10000 means halving the distance,
  887. * and as it happens, that is just what we want!
  888.          move.l   d0,d6
  889.  
  890.          move.w   mb_y2(a4),d0
  891.          sub.w    mb_y1(a4),d0
  892.          bsr      Power2         ; d1-d3 remain!
  893.          move.l   d0,d7
  894.  
  895.          move.l   d4,d2
  896.          move.l   d5,d3
  897.          sub.l    d6,d2          ; note! d7 has a remainder similar to
  898.          sub.l    d7,d3          ; that of d4
  899.          add.l    d6,d4
  900.          add.l    d7,d5
  901.          swap     d2
  902.          swap     d3
  903.          swap     d4
  904.          swap     d5
  905.  
  906.          moveq    #0,d6
  907.          move.w   mb_x1(a4),d0
  908.          move.w   mb_x2(a4),d1
  909.          cmp.w    d0,d2
  910.          bge.s    1$
  911.          move.w   d0,d2
  912.          bset     #0,d6
  913. 1$:
  914.          cmp.w    d1,d2
  915.          bgt      pig_big
  916.          cmp.w    d1,d4
  917.          ble.s    2$
  918.          move.w   d1,d4
  919.          bset     #1,d6
  920. 2$:
  921.          cmp.w    d0,d4
  922.          blt      pig_big
  923.          move.w   mb_y1(a4),d0
  924.          move.w   mb_y2(a4),d1
  925.          cmp.w    d0,d3
  926.          bge.s    3$
  927.          move.w   d0,d3
  928.          bset     #2,d6
  929. 3$:
  930.          cmp.w    d1,d3
  931.          bgt      pig_big
  932.          cmp.w    d1,d5
  933.          ble.s    4$
  934.          move.w   d1,d5
  935.          bset     #3,d6
  936. 4$:
  937.          cmp.w    d0,d5
  938.          blt      pig_big
  939.  
  940.          move.w   d2,lowx
  941.          move.w   d3,lowy
  942.          move.w   d4,highx
  943.          move.w   d5,highy
  944.  
  945. * process the corners.
  946.          push     a3-a5    ; NEED some workspace
  947.          lea      TopLeft,a1
  948.          lea      BottomLeft,a3
  949.          lea      TopRight,a4
  950.          lea      BottomRight,a5
  951.          btst.b   #0,d6
  952.          beq      no_left
  953.          lea      LeftLeft,a1
  954.          move.l   a1,a3
  955. no_left:
  956.          btst.b   #1,d6
  957.          beq.s    no_right
  958.          lea      RightRight,a4
  959.          move.l   a4,a5
  960. no_right:
  961.          btst.b   #2,d6
  962.          beq.s    no_up
  963.          lea      UpUp,a1
  964.          move.l   a1,a4
  965. no_up:
  966.          btst.b   #3,d6
  967.          beq.s    no_down
  968.          lea      DownDown,a3
  969.          move.l   a3,a5
  970. no_down:
  971.          not.b    d6
  972.          move.b   d6,d0
  973.          and.b    #%0101,d0
  974.          bne.s    skip_tl
  975.          sub.l    a1,a1
  976. skip_tl:
  977.          move.b   d6,d0
  978.          and.b    #%1001,d0
  979.          bne.s    skip_bl
  980.          sub.l    a3,a3
  981. skip_bl:
  982.          move.b   d6,d0
  983.          and.b    #%0110,d0
  984.          bne.s    skip_tr
  985.          sub.l    a4,a4
  986. skip_tr:
  987.          and.b    #%1010,d6
  988.          bne.s    skip_br
  989.          sub.l    a5,a5
  990. skip_br:
  991.          move.l   a2,a0
  992.          move.l   a1,pic_tl
  993.          beq.s    no_tl
  994.          move.w   d2,d0
  995.          move.w   d3,d1
  996.          Call     DrawBorder
  997. no_tl:
  998.          move.l   a3,a1
  999.          move.l   a2,a0
  1000.          move.l   a1,pic_bl
  1001.          beq.s    no_bl
  1002.          move.w   d2,d0
  1003.          move.w   d5,d1
  1004.          Call     DrawBorder
  1005. no_bl:
  1006.          move.l   a4,a1
  1007.          move.l   a2,a0
  1008.          move.l   a1,pic_tr
  1009.          beq.s    no_tr
  1010.          move.w   d4,d0
  1011.          move.w   d3,d1
  1012.          Call     DrawBorder
  1013. no_tr:
  1014.          move.l   a5,a1
  1015.          move.l   a2,a0
  1016.          move.l   a1,pic_br
  1017.          beq.s    no_br
  1018.          move.w   d4,d0
  1019.          move.w   d5,d1
  1020.          Call     DrawBorder
  1021. no_br:
  1022.          pull     a3-a5
  1023.          bra.s    draw_pulling
  1024. pig_big:
  1025.          clr.l    pic_tl
  1026.          clr.l    pic_bl
  1027.          clr.l    pic_tr
  1028.          clr.l    pic_br
  1029. draw_pulling:
  1030.          pull     a0-a2/a6/d0-d7
  1031. draw_over:
  1032.          rts
  1033.  
  1034. calculate:
  1035. * Calculate centerpoint coordinates.
  1036. * Only needed when string gadget updated.
  1037. * The formula we use is (CurrentX - mb_x(a4)) / mb_dx(a4) (for x)
  1038. * and because I would have to use 32-bit division which my processor
  1039. * does unfortunately not have any instructions for, we use 16-bit
  1040. * division, which is much more tricky!
  1041.  
  1042. * Another problem occurs when user enters a number that is NOT
  1043. * in the visible area. Because our number system can only represent
  1044. * numbers from -4 to 4, we have no reliable way of telling whether
  1045. * user wants to see grid to be (arrows!) to the LEFT, for instance,
  1046. * or to the RIGHT.
  1047.  
  1048. * Currently any such numbers map to RIGHT and DOWN. One could try
  1049. * to fix it by choosing numbers that are as close to previous prex
  1050. * and prey as possible.
  1051. * I wont try to code that, however, my hair is grey enough now.
  1052.  
  1053.          push     d0-d4
  1054.          move.l   mb_dx(a4),d2
  1055.          move.l   CurrentX,d4
  1056.          sub.l    mb_x0(a4),d4
  1057. fix_div_x:
  1058.          cmp.l    #$10000,d2
  1059.          blo.s    fixed_x
  1060.          lsr.l    #1,d2
  1061.          lsr.l    #1,d4
  1062.          bra.s    fix_div_x
  1063. fixed_x:
  1064.          divu     d2,d4
  1065.          move.l   d4,d0    ; renormalize remainder
  1066.          clr.w    d0
  1067.          divu     d2,d0
  1068.          swap     d0
  1069.          move.w   d4,d0
  1070.  
  1071.          move.l   mb_dy(a4),d2
  1072.          move.l   mb_y0(a4),d4
  1073.          sub.l    CurrentY,d4
  1074. fix_div_y:
  1075.          cmp.l    #$10000,d2
  1076.          blo.s    fixed_y
  1077.          lsr.l    #1,d2
  1078.          lsr.l    #1,d4
  1079.          bra.s    fix_div_y
  1080. fixed_y:
  1081.          divu     d2,d4
  1082.          move.l   d4,d1
  1083.          clr.w    d1
  1084.          divu     d2,d1
  1085.          swap     d1
  1086.          move.w   d4,d1
  1087.  
  1088.          swap     d0
  1089.          swap     d1
  1090.  
  1091.          move.l   d0,prex
  1092.          move.l   d1,prey
  1093.          pull     d0-d4
  1094.          rts
  1095.  
  1096. StringGadgetDown:
  1097. * GadgetID in d1
  1098.          and.w    #IDMASK,d1
  1099.  
  1100. * We will wait for another message, thenafter we know the user has
  1101. * finished playing with the string gadget. This message could be the
  1102. * GADGETUP of same gadget, but then again, it could be something
  1103. * else.
  1104. * We must preserve the message (so that main loop may handle it).
  1105.          move.l   a5,a1       ; save gadget
  1106.          bsr      GetMessage
  1107.  
  1108.          move.l   gg_SpecialInfo(a1),a0
  1109.          move.l   si_Buffer(a0),a0        ; addr of the actual string
  1110.  
  1111.          cmp.w    #GAD_X,d1
  1112.          beq.s    gadget_x
  1113.          cmp.w    #GAD_Y,d1
  1114.          beq.s    gadget_y
  1115.          cmp.w    #GAD_M,d1
  1116.          beq      gadget_m
  1117.          cmp.w    #GAD_Z,d1
  1118.          beq.s    gadget_z
  1119. * now it must be IGadget
  1120.          bsr      GetNum
  1121.          beq.s    2$
  1122.          tst.b    (a0)
  1123.          beq.s    1$
  1124. 2$:
  1125.          move.w   mb_i(a4),d0
  1126. 1$:      move.w   d0,mb_i(a4)
  1127.          bsr      refresh_i
  1128.          bra.s    gadget_done
  1129.  
  1130. gadget_x:
  1131.          bsr      GetFixed
  1132.          beq.s    2$
  1133.          tst.b    (a0)     ; if user entered some ugly stuff after numbers
  1134.          beq.s    1$
  1135. 2$:
  1136.          move.l   CurrentX,d0 ; invalid -> get previous
  1137. 1$:      move.l   d0,CurrentX
  1138.          bsr      calculate
  1139.          bsr      refresh_x
  1140.          bsr      DrawGrid
  1141.          bra.s    gadget_done
  1142.  
  1143. gadget_y:
  1144.          bsr      GetFixed
  1145.          beq.s    2$
  1146.          tst.b    (a0)
  1147.          beq.s    1$
  1148. 2$:
  1149.          move.l   CurrentY,d0
  1150. 1$:      move.l   d0,CurrentY
  1151.          bsr      calculate
  1152.          bsr      refresh_y
  1153.          bsr      DrawGrid
  1154.          bra.s    gadget_done
  1155.  
  1156. gadget_z:
  1157.          bsr      GetSMagnify
  1158.          beq.s    2$
  1159.          tst.b    (a0)
  1160.          beq.s    1$
  1161. 2$:
  1162.          move.l   Zoom,d0
  1163. 1$:      move.l   d0,Zoom
  1164.          bsr      refresh_z
  1165.          bra.s    gadget_done
  1166. gadget_m:
  1167.          bsr      GetMagnify
  1168.          beq.s    2$
  1169.          tst.b    (a0)
  1170.          beq.s    1$
  1171. 2$:
  1172.          move.l   Magnify,d0
  1173. 1$:      move.l   d0,Magnify
  1174.          bsr      refresh_m
  1175.  
  1176. gadget_done:
  1177.          moveq    #0,d0
  1178.  
  1179. get_rid_of_us:
  1180.          rts
  1181.  
  1182.  
  1183. OtherGadgetDown:
  1184. * GadgetID in d1
  1185.          move.w   d1,d0
  1186.          and.w    #ZOOMTYPE,d0
  1187.          beq      not_zoom_gadget
  1188.          and.w    #IDMASK,d1
  1189.  
  1190.          move.b   #ZOOM,d0
  1191.          cmp.w    #GAD_ZOOM,d1
  1192.          beq.s    1$
  1193.  
  1194.          move.b   #REDRAW,d0
  1195.          cmp.w    #GAD_DRAW,d1
  1196.          beq.s    1$
  1197.  
  1198.          move.b   #RESET,d0
  1199. 1$:
  1200.          move.b   d0,method
  1201.          bsr      refresh_zoom
  1202. * Double-click to start drawing
  1203.          move.l   OldSecs,d0
  1204.          move.l   OldMicros,d1
  1205.          move.l   a2,d2
  1206.          move.l   a3,d3
  1207.          move.l   a2,OldSecs
  1208.          move.l   a3,OldMicros
  1209.          Call     DoubleClick
  1210.          tst.w    d0
  1211.          beq.s    not_yet
  1212.          moveq    #-1,d0         ; result is negative
  1213. not_yet:
  1214.          rts
  1215.  
  1216. not_zoom_gadget:
  1217.          move.w   d1,d0
  1218.          and.w    #SETTYPE,d0
  1219.          beq.s    not_set_gadget
  1220.          and.w    #IDMASK,d1
  1221.  
  1222.          bclr.b   #MBB_JULIA,mb_flags(a4)
  1223.          cmp.w    #GAD_MANDEL,d1
  1224.          beq.s    1$
  1225.          bset.b   #MBB_JULIA,mb_flags(a4)
  1226. 1$:
  1227.          bsr      refresh_set
  1228.  
  1229.          moveq    #FALSE,d0
  1230.          rts
  1231.  
  1232. not_set_gadget:
  1233.          cmp.w    #GAD_QUIT,d1
  1234.          bne.s    not_quit_gadget
  1235. * Double-click to exit
  1236.          move.l   OldSecs,d0
  1237.          move.l   OldMicros,d1
  1238.          move.l   a2,d2
  1239.          move.l   a3,d3
  1240.          move.l   a2,OldSecs
  1241.          move.l   a3,OldMicros
  1242.          Call     DoubleClick
  1243.          tst.w    d0
  1244.          beq.s    first_click
  1245.          moveq    #TRUE,d0          ; +1 -> quitting
  1246. first_click:
  1247.          rts
  1248.  
  1249. not_quit_gadget:
  1250.          and.w    #IDMASK,d1
  1251.          moveq    #0,d7
  1252.          move.w   d1,d7
  1253. it_was_timer:
  1254.          bsr      plus_minus
  1255.          lea      IOreq,a1
  1256.  
  1257. * Shortage of registers -- we must use upper half of d7
  1258.          swap     d7
  1259.          move.l   #400000,d0  ; .4 seconds initial delay
  1260.          tst.w    d7
  1261.          beq.s    huu_haa_joo_jaa
  1262.          move.l   #100000,d0  ; .1 seconds next 9
  1263.          cmp.w    #9,d7
  1264.          blo.s    huu_haa_joo_jaa
  1265.          move.l   #020000,d0  ; 1/25 seconds
  1266.          move.w   #-2,d7      ; neverending!
  1267. huu_haa_joo_jaa:
  1268.          addq.w   #1,d7
  1269.          swap     d7
  1270.  
  1271.          move.w   #TR_ADDREQUEST,IO_COMMAND(a1)
  1272.          move.l   #0,IOTV_TIME+TV_SECS(a1)
  1273.          move.l   d0,IOTV_TIME+TV_MICRO(a1)
  1274.          move.l   a1,UseReq
  1275.          Base     Exec
  1276.          Call     SendIO
  1277.          bsr      GetMessage
  1278.          bne.s    1$             ; that old ^C
  1279.          cmp.w    #FAKECLASS,d2
  1280.          beq.s    it_was_timer
  1281.          moveq    #FALSE,d7
  1282.          bra.s    2$
  1283. 1$:
  1284.          moveq    #TRUE,d7
  1285. 2$:
  1286.          move.l   UseReq,a1
  1287.          Call     AbortIO
  1288.          move.l   UseReq,a1
  1289.          Call     WaitIO
  1290.          clr.l    UseReq
  1291.          tst.w    d7
  1292.          rts
  1293.  
  1294.          moveq    #0,d0
  1295.          rts
  1296.  
  1297. plus_minus:
  1298. * GadgetID in d2
  1299.          push     d0-d1
  1300.          move.w   d7,d0
  1301.          moveq    #1,d1
  1302.          and.w    #$7fff,d0
  1303.          cmp.w    #GAD_X,d0
  1304.          bne.s    skip_x
  1305.  
  1306.          move.l   mb_dx(a4),d0
  1307.          swap     d1
  1308.          tst.w    d7
  1309.          bpl.s    1$
  1310.          neg.l    d0
  1311.          neg.l    d1
  1312. 1$:
  1313.          add.l    d0,CurrentX
  1314.          add.l    d1,prex
  1315.          move.l   CurrentX,d0
  1316.          bsr      refresh_x
  1317.          bsr      DrawGrid
  1318.          bra      plus_minus_done
  1319. skip_x:
  1320.          cmp.w    #GAD_Y,d0
  1321.          bne.s    skip_y
  1322.  
  1323.          move.l   mb_dy(a4),d0
  1324.          swap     d1
  1325.          tst.w    d7
  1326.          bpl.s    1$
  1327.          neg.l    d0
  1328.          neg.l    d1
  1329. 1$:
  1330.          add.l    d0,CurrentY
  1331.          sub.l    d1,prey
  1332.          move.l   CurrentY,d0
  1333.          bsr      refresh_y
  1334.          bsr      DrawGrid
  1335.          bra.s    plus_minus_done
  1336. skip_y:
  1337.          cmp.w    #GAD_M,d0
  1338.          bne.s    skip_m
  1339.  
  1340.          move.l   #$1999,d0
  1341.          tst.w    d7
  1342.          bpl.s    1$
  1343.          neg.l    d0
  1344. 1$:
  1345.          add.l    d0,Magnify
  1346.          move.l   Magnify,d0
  1347.          bsr      refresh_m
  1348.          bra.s    plus_minus_done
  1349. skip_m:
  1350.          cmp.w    #GAD_Z,d0
  1351.          bne.s    skip_z
  1352.  
  1353.          move.l   #$1999,d0
  1354.          tst.w    d7
  1355.          bpl.s    1$
  1356.          neg.l    d0
  1357. 1$:
  1358.          add.l    d0,Zoom
  1359.          move.l   Zoom,d0
  1360.          bsr      refresh_z
  1361.          bra.s    plus_minus_done
  1362. skip_z:
  1363.          cmp.w    #GAD_I,d0
  1364.          bne.s    plus_minus_done
  1365.  
  1366.          tst.w    d7
  1367.          bpl.s    1$
  1368.          neg.l    d1
  1369. 1$:
  1370.          add.w    d1,mb_i(a4)
  1371.          move.w   mb_i(a4),d0
  1372.          bsr      refresh_i
  1373. plus_minus_done:
  1374.          pull     d0-d1
  1375.          rts
  1376.  
  1377.  
  1378.  
  1379. * This group of routines updates whatever visual clues the user might
  1380. * have about the current situation.
  1381.  
  1382. * NOTE: a DrawGrid is needed after every refresh_x or refresh_y.
  1383. * (To avoid drawing it twice if both coords updated)
  1384.  
  1385. * d0 is the fresh number.
  1386. * Preserves all registers.
  1387. refresh_x:
  1388.          push     d0-d2/d7/a0-a3/a6
  1389.          move.l   MyWindow2,a2   ; save thing from being overwritten
  1390.          lea      XGadget,a3
  1391. * If in MANDEL mode, alter c = jx + jy settings.
  1392. * So user may set jx,jy, enter JULIA mode and still
  1393. * select another point.
  1394.          btst.b   #MBB_JULIA,mb_flags(a4)
  1395.          bne.s    1$
  1396.          move.l   d0,mb_jx(a4)
  1397. 1$:
  1398.          move.l   d0,d2
  1399.  
  1400.          move.l   a2,a0          ; window
  1401.          move.l   a3,a1          ; gadget
  1402.          Base     Intuition
  1403.          Call     RemoveGadget   ; remove, modify, add back.
  1404. * Later we will insert this gadget back to its original place.
  1405. * That is why d2 gets position. toDec needs number in d0.
  1406.          exg.l    d0,d2
  1407.  
  1408.          move.l   gg_SpecialInfo(a3),a0
  1409.          move.l   si_Buffer(a0),a0
  1410.  
  1411.          move.l   mb_dx(a4),d7   ; delta (see toDec why)
  1412.          bsr      toDec
  1413.          clr.b    (a0)
  1414.  
  1415.          bsr      refresh_add_gadget
  1416.          pull     d0-d2/d7/a0-a3/a6
  1417.          rts
  1418. refresh_y:
  1419.          push     d0-d2/d7/a0-a3/a6
  1420.          move.l   MyWindow2,a2   ; save things from being overwritten
  1421.          lea      YGadget,a3
  1422.  
  1423.          btst.b   #MBB_JULIA,mb_flags(a4)
  1424.          bne.s    1$
  1425.          move.l   d0,mb_jy(a4)
  1426. 1$:
  1427.          move.l   d0,d2
  1428.  
  1429.          move.l   a2,a0          ; window
  1430.          move.l   a3,a1          ; gadget
  1431.          Base     Intuition
  1432.          Call     RemoveGadget   ; remove, modify, add back.
  1433.  
  1434.          exg.l    d0,d2
  1435.  
  1436.          move.l   gg_SpecialInfo(a3),a0
  1437.          move.l   si_Buffer(a0),a0
  1438.  
  1439.          move.l   mb_dy(a4),d7   ; delta (see toDec why)
  1440.          bsr      toDec
  1441.          clr.b    (a0)
  1442.  
  1443.          bsr      refresh_add_gadget
  1444.          pull     d0-d2/d7/a0-a3/a6
  1445.          rts
  1446. refresh_z:
  1447.          push     d0-d2/a0-a3/a6
  1448.          move.l   MyWindow2,a2   ; save thing from being overwritten
  1449.          lea      ZGadget,a3
  1450.          move.l   d0,d2
  1451.  
  1452.          move.l   a2,a0          ; window
  1453.          move.l   a3,a1          ; gadget
  1454.          Base     Intuition
  1455.          Call     RemoveGadget   ; remove, modify, add back.
  1456. * Later we will insert this gadget back to its original place.
  1457. * That is why d2 gets position. toDec needs number in d0.
  1458.          exg.l    d0,d2
  1459.  
  1460.          move.l   gg_SpecialInfo(a3),a0
  1461.          move.l   si_Buffer(a0),a0
  1462.  
  1463.          move.b   #'+',d1
  1464.          tst.l    d0
  1465.          bpl.s    1$
  1466.          neg.l    d0
  1467.          move.b   #'-',d1
  1468. 1$:
  1469.          move.b   d1,(a0)+
  1470.  
  1471.          bsr      toMag
  1472.          clr.b    (a0)
  1473.  
  1474.          bsr      refresh_add_gadget
  1475.  
  1476.          cmp.b    #REDRAW,method
  1477.          bne.s    2$
  1478.          move.l   OldMagnify,d0
  1479.          move.l   d0,Magnify
  1480.          bsr      refresh_m         ; to show magnify is again normal
  1481.          move.b   #ZOOM,method      ; NOTE: this must be AFTER refresh_m
  1482.          bsr      refresh_zoom      ; does also DrawGrid
  1483.          bra.s    3$                ; so dont waste time doing it again
  1484. 2$:
  1485.          bsr      DrawGrid
  1486. 3$:
  1487.          pull     d0-d2/a0-a3/a6
  1488.          rts
  1489. refresh_i:
  1490.          push     d0-d2/a0-a3/a6
  1491.          move.l   MyWindow2,a2   ; save thing from being overwritten
  1492.          lea      IGadget,a3
  1493.          move.l   d0,d2
  1494.  
  1495.          move.l   a2,a0          ; window
  1496.          move.l   a3,a1          ; gadget
  1497.          Base     Intuition
  1498.          Call     RemoveGadget   ; remove, modify, add back.
  1499. * Later we will insert this gadget back to its original place.
  1500. * That is why d2 gets position. toDec needs number in d0.
  1501.          exg.l    d0,d2
  1502.  
  1503.          move.l   gg_SpecialInfo(a3),a0
  1504.          move.l   si_Buffer(a0),a0
  1505.  
  1506.          bsr      toInt
  1507.          clr.b    (a0)
  1508.  
  1509.          bsr.s    refresh_add_gadget
  1510.          pull     d0-d2/a0-a3/a6
  1511.          rts
  1512. refresh_m:
  1513.          push     d0-d2/a0-a3/a6
  1514.          move.l   MyWindow2,a2   ; save thing from being overwritten
  1515.          lea      MGadget,a3
  1516.          move.l   d0,d2
  1517.  
  1518.          move.l   a2,a0          ; window
  1519.          move.l   a3,a1          ; gadget
  1520.          Base     Intuition
  1521.          Call     RemoveGadget   ; remove, modify, add back.
  1522. * Later we will insert this gadget back to its original place.
  1523. * That is why d2 gets position. toDec needs number in d0.
  1524.          exg.l    d0,d2
  1525.  
  1526.          move.l   gg_SpecialInfo(a3),a0
  1527.          move.l   si_Buffer(a0),a0
  1528.  
  1529.          bsr      toMag
  1530.          clr.b    (a0)
  1531.  
  1532.          bsr.s    refresh_add_gadget
  1533.  
  1534.          cmp.b    #ZOOM,method
  1535.          bne.s    1$
  1536.          move.b   #REDRAW,method
  1537.          bsr      refresh_zoom   ; does also DrawGrid,
  1538.          bra.s    2$             ; so dont repeat it.
  1539. 1$:
  1540.          bsr      DrawGrid
  1541. 2$:
  1542.          pull     d0-d2/a0-a3/a6
  1543.          rts
  1544.  
  1545. * This is common to all above.
  1546. refresh_add_gadget:
  1547.          move.l   gg_SpecialInfo(a3),a0
  1548.          clr.w    si_BufferPos(a0)
  1549.          clr.w    si_DispPos(a0)
  1550.          move.l   a2,a0          ; window
  1551.          move.l   a3,a1          ; gadget
  1552.          move.l   d2,d0          ; the very same position
  1553.          Call     AddGadget
  1554.          move.l   a3,a0          ; gadget
  1555.          move.l   a2,a1          ; window
  1556.          sub.l    a2,a2          ; "requester / no requester"
  1557.          moveq    #1,d0
  1558.          Call     RefreshGList   ; actually just one
  1559.          rts
  1560.  
  1561. * Hah haa! Still more refreshing routines:
  1562.  
  1563. refresh_set:
  1564.          push     d0-d2/a0-a3/a5/a6
  1565.          Base     Intuition
  1566.          move.l   MyWindow2,a0
  1567.          move.l   a0,a5
  1568.          lea      MANDELGadget,a1
  1569.          move.l   a1,a3
  1570.          moveq    #2,d0
  1571.          Call     RemoveGList
  1572.  
  1573.          lea      JULIAGadget,a1
  1574.          btst.b   #MBB_JULIA,mb_flags(a4)
  1575.          beq.s    it_is_mandel
  1576.  
  1577.          or.w     #SELECTED,gg_Flags(a1)
  1578.          and.w    #~SELECTED,gg_Flags(a3)
  1579.          bra.s    put_them_back
  1580. it_is_mandel:
  1581.          and.w    #~SELECTED,gg_Flags(a1)
  1582.          or.w     #SELECTED,gg_Flags(a3)
  1583. put_them_back:
  1584.          move.l   a5,a0       ; window
  1585.          move.l   a3,a1       ; gadget
  1586.          sub.l    a2,a2       ; requester
  1587.          ; d0 is all right (RemoveGList...)
  1588.          moveq    #2,d1
  1589.          Call     AddGList
  1590.  
  1591.          move.l   a3,a0       ; gadget
  1592.          move.l   a5,a1       ; window
  1593.          ; a2 is still 0. (Dunno if it should be 0 anyway?)
  1594.          moveq    #2,d0
  1595.          Call     RefreshGList
  1596.  
  1597.          pull     d0-d2/a0-a3/a5/a6
  1598.          rts
  1599.  
  1600. refresh_zoom:
  1601.          push     d0-d2/a0-a3/a5/a6
  1602.          Base     Intuition
  1603.          move.l   MyWindow2,a0
  1604.          move.l   a0,a5
  1605.          lea      ZOOMGadget,a1
  1606.          move.l   a1,a3
  1607.          moveq    #3,d0
  1608.          Call     RemoveGList
  1609.  
  1610.          lea      DRAWGadget,a2
  1611.          lea      RESETGadget,a1
  1612.  
  1613.          move.b   method,d1
  1614.          cmp.b    #REDRAW,d1
  1615.          beq.s    it_is_draw
  1616.          cmp.b    #RESET,d1
  1617.          beq.s    it_is_reset
  1618.  
  1619.          or.w     #SELECTED,gg_Flags(a3)  ; zoom
  1620.          and.w    #~SELECTED,gg_Flags(a2)
  1621.          and.w    #~SELECTED,gg_Flags(a1)
  1622.          bra.s    complex_and_unique_label
  1623. it_is_draw:
  1624.          and.w    #~SELECTED,gg_Flags(a3)
  1625.          or.w     #SELECTED,gg_Flags(a2)  ; draw
  1626.          and.w    #~SELECTED,gg_Flags(a1)
  1627.          bra.s    complex_and_unique_label
  1628. it_is_reset:
  1629.          and.w    #~SELECTED,gg_Flags(a3)
  1630.          and.w    #~SELECTED,gg_Flags(a2)
  1631.          or.w     #SELECTED,gg_Flags(a1)  ; reset
  1632. complex_and_unique_label:
  1633.          move.l   a5,a0       ; window
  1634.          move.l   a3,a1       ; gadget
  1635.          sub.l    a2,a2       ; requester
  1636.          ; d0 is all right (RemoveGList...)
  1637.          moveq    #3,d1
  1638.          Call     AddGList
  1639.  
  1640.          move.l   a3,a0       ; gadget
  1641.          move.l   a5,a1       ; window
  1642.          ; a2 is still 0. (Dunno if it should be 0 anyway?)
  1643.          moveq    #3,d0
  1644.          Call     RefreshGList
  1645.  
  1646.          pull     d0-d2/a0-a3/a5/a6
  1647.          bsr      DrawGrid          ; if something changed, show it.
  1648.          rts
  1649.  
  1650.  
  1651. GetSMagnify:
  1652.          move.b   (a0)+,d0
  1653.          cmp.b    #'+',d0
  1654.          beq.s    1$
  1655.          cmp.b    #'-',d0
  1656.          beq.s    2$
  1657.          subq.l   #1,a0
  1658. 1$:
  1659.          bsr      GetMagnify
  1660.          rts
  1661. 2$:
  1662.          bsr      GetMagnify
  1663.          beq.s    3$
  1664.          neg.l    d0
  1665. 3$:
  1666.          rts
  1667.  
  1668. RightButton:
  1669.          clr.b    method         ; == move.b #ZOOM,method
  1670.                                  ; so RMB is a shorthand for ZOOM
  1671.          bsr      refresh_zoom
  1672.          move.w   d5,d0
  1673.          move.w   d6,d1
  1674.  
  1675.          push     d5/d6
  1676.          swap     d5
  1677.          swap     d6
  1678.          clr.w    d5
  1679.          clr.w    d6
  1680.          bsr      refresh_pos
  1681.          pull     d5/d6
  1682.  
  1683. * a few words of explanation:
  1684. * Because we cannot process MOUSEMOVE events fast enough, we do
  1685. * the following: Loop CheckMessage, saving d5/d6 each turn,
  1686. * until it returns event that isn't of class MOUSEMOVE.
  1687. * Then process saved d5/d6 (they represent the position mouse was
  1688. * in BEFORE this message arrived).
  1689. * If message is of class NULL (no messages), start it all again.
  1690.  
  1691. rightloop:
  1692.          move.w   d5,tmpx
  1693.          move.w   d6,tmpy
  1694.          push     d0-d1
  1695.          bsr      CheckMessage
  1696.          pull     d0-d1
  1697.          bne      do_the_wrong_thing
  1698.  
  1699. we_have_already_got_one:
  1700.          cmp.l    #MOUSEMOVE,d2
  1701.          beq.s    rightloop
  1702.  
  1703.          push     d0-d2/d5/d6    ; so as not to trash current message
  1704.  
  1705. * Uh oh... When I thought it would be nice if user could use
  1706. * magnification instead of deltas, I knew I would have to
  1707. * code 2^(-mag) in mach lang. But it never occured to me that
  1708. * I would have to code log2 somewhere....
  1709. * There is only one word to describe this: disqusting
  1710.          push     d0/d1          ; again!
  1711.          sub.w    tmpx,d0
  1712.          bpl.s    notneg1
  1713.          neg.w    d0
  1714. notneg1:
  1715.          sub.w    tmpy,d1
  1716.          bpl.s    notneg2
  1717.          neg.w    d1
  1718. notneg2:
  1719.          bne.s    r_isnonzero
  1720.          tst.w    d0
  1721.          beq.s    r_iszero
  1722. r_isnonzero:
  1723.          move.w   mb_x2(a4),d2
  1724.          sub.w    mb_x1(a4),d2
  1725.          swap     d0
  1726.          clr.w    d0
  1727.          divu     d2,d0
  1728.          bvc.s    no_overf_1
  1729.          moveq    #-1,d0
  1730. no_overf_1:
  1731.          move.w   mb_y2(a4),d2
  1732.          sub.w    mb_y1(a4),d2
  1733.          swap     d1
  1734.          clr.w    d1
  1735.          divu     d2,d1
  1736.          bvc.s    no_overf_2
  1737.          moveq    #-1,d1
  1738. no_overf_2:
  1739.          cmp.w    d1,d0
  1740.          bhi.s    d0_is_higher
  1741.          move.w   d1,d0
  1742. d0_is_higher:
  1743.          bsr      log2        ; I will code it later, ok?
  1744.          move.l   d0,Zoom
  1745. r_iszero:
  1746.          pull     d0/d1
  1747.          move.w   tmpx,d5
  1748.          move.w   tmpy,d6
  1749.          add.w    d0,d5
  1750.          add.w    d1,d6
  1751.          swap     d5
  1752.          swap     d6
  1753.          clr.w    d5
  1754.          clr.w    d6
  1755.  
  1756.          move.l   mb_dx(a4),d1
  1757.          move.l   mb_dy(a4),d2
  1758.          lsr.l    #1,d1
  1759.          lsr.l    #1,d2
  1760.  
  1761.          lsr.l    #1,d5
  1762.          tst.w    d5
  1763.          bmi.s    1$
  1764.          moveq    #0,d1
  1765. 1$:
  1766.          lsr.l    #1,d6
  1767.          tst.w    d6
  1768.          bmi.s    2$
  1769.          moveq    #0,d2
  1770. 2$:
  1771.          move.l   d5,prex
  1772.          move.l   d6,prey
  1773.          swap     d5
  1774.          swap     d6
  1775.          bsr      Position
  1776.          add.l    d1,d5
  1777.          sub.l    d2,d6
  1778.          move.l   d5,CurrentX
  1779.          move.l   d6,CurrentY
  1780.          move.l   d5,d0
  1781.          bsr      refresh_x
  1782.          move.l   d6,d0
  1783.          bsr      refresh_y
  1784.          move.l   Zoom,d0
  1785.          bsr      refresh_z   ; This will do DrawGrid also.
  1786.          pull     d0-d2/d5/d6
  1787.          tst.l    d2
  1788.          bne.s    exit_right_button    ; probably MENUUP
  1789.  
  1790. * How cute!!! LOVELY!!! Even here, this proggie refuses to busywait!!!!
  1791.          bsr      GetMessage     ; (ya see, no CheckMessage!)
  1792.          bne.s    do_the_wrong_thing
  1793.          cmp.l    #MOUSEMOVE,d2
  1794.          bne.s    exit_right_button
  1795.          move.w   d5,tmpx
  1796.          move.w   d6,tmpy
  1797.          bra      we_have_already_got_one
  1798.  
  1799. exit_right_button:
  1800.          moveq    #0,d0
  1801. do_the_wrong_thing:
  1802.          rts
  1803.  
  1804. refresh_pos:
  1805.          push     d0
  1806.          move.l   d5,prex
  1807.          move.l   d6,prey
  1808.          swap     d5
  1809.          swap     d6
  1810.          bsr      Position
  1811.          move.l   d5,CurrentX
  1812.          move.l   d6,CurrentY
  1813.          move.l   d5,d0
  1814.          bsr      refresh_x
  1815.          move.l   d6,d0
  1816.          bsr      refresh_y
  1817.          bsr      DrawGrid
  1818.          pull     d0
  1819.          rts
  1820.  
  1821. LeftButton:
  1822.          move.l   OldSecs,d0
  1823.          move.l   OldMicros,d1
  1824.          move.l   a2,d2
  1825.          move.l   a3,d3
  1826.          move.l   a2,OldSecs
  1827.          move.l   a3,OldMicros
  1828.          Call     DoubleClick
  1829.          tst.w    d0
  1830.          bne.s    left_double
  1831.  
  1832. * We use a loop similar to RightButton's.
  1833. leftloop
  1834.          move.w   d5,tmpx
  1835.          move.w   d6,tmpy
  1836.          bsr      CheckMessage
  1837.          bne      left_aborted   ; ^C
  1838. left_gotmessage
  1839.          cmp.l    #MOUSEMOVE,d2
  1840.          beq.s    leftloop
  1841.  
  1842.          push     d5/d6
  1843.          swap     d5
  1844.          swap     d6
  1845.          clr.w    d5
  1846.          clr.w    d6
  1847.          bsr      refresh_pos
  1848.          pull     d5/d6
  1849.  
  1850.          tst.l    d2
  1851.          bne.s    left_exit      ; probably SELECTUP
  1852.  
  1853.          bsr      GetMessage
  1854.          bne.s    left_aborted
  1855.          cmp.l    #MOUSEMOVE,d2
  1856.          bne.s    left_exit
  1857.          move.w   d5,tmpx
  1858.          move.w   d6,tmpy
  1859.          bra      left_gotmessage
  1860. left_exit
  1861.          moveq    #FALSE,d0   ; return zero
  1862.          bra.s    left_return
  1863. left_double
  1864.          swap     d5
  1865.          swap     d6
  1866.          clr.w    d5
  1867.          clr.w    d6
  1868.          bsr      refresh_pos
  1869.          moveq    #TRUE,d0    ; return positive nonzero
  1870.          bra.s    left_return
  1871. left_aborted
  1872.          moveq    #-TRUE,d0   ; return negative nonzero
  1873. left_return
  1874.          rts
  1875.  
  1876.  
  1877. * Converts an integer from d0.w to a string (a0)+.
  1878. * Grr.. Why don't we have most significant digit last?
  1879. toInt:
  1880.          push     d0-d2
  1881.          move.w   #10000,d1
  1882.          moveq    #FALSE,d2
  1883. 1$:
  1884.          and.l    #$ffff,d0
  1885.          divu     d1,d0
  1886.          bne.s    4$
  1887.          tst.w    d2    ; discard leading zeros
  1888.          beq.s    2$
  1889. 4$:
  1890.          add.b    #'0',d0
  1891.          move.b   d0,(a0)+
  1892.          moveq    #TRUE,d2
  1893. 2$:
  1894.          swap     d0
  1895.          ext.l    d1
  1896.          divu     #10,d1
  1897.          bne.s    1$
  1898.  
  1899.          tst.w    d2
  1900.          bne.s    3$
  1901.          move.b   #'0',(a0)+  ; if d0=0, display at least a 0.
  1902. 3$:
  1903.          pull     d0-d2
  1904.          rts
  1905.  
  1906. * Still one more conversion routine. (for Magnify's internal format)
  1907. toMag:
  1908.          push     d0-d2
  1909.          move.l   d0,d1
  1910.          swap     d0
  1911.          bsr.s    toInt
  1912.          move.b   #'.',(a0)+
  1913.  
  1914.          moveq    #3,d2
  1915. 1$:
  1916.          mulu     #10,d1
  1917.          swap     d1
  1918.          add.b    #'0',d1
  1919.          move.b   d1,(a0)+
  1920.          swap     d1
  1921.          dbf      d2,1$
  1922.  
  1923.          tst.w    d1
  1924.          bpl.s    2$       ; if < $8000, no rounding needed
  1925.          bsr      Round
  1926. 2$:
  1927.          pull     d0-d2
  1928.          rts
  1929.  
  1930.  
  1931. dispCoords:
  1932. * This routine displays the coordinates of current mouse position
  1933. * in screen title bar.
  1934.          bsr.s    Position
  1935.          lea      CoordText,a0
  1936.          move.l   d5,d0
  1937.          move.l   mb_dx(a4),d7
  1938.          bsr.s    toDec
  1939.          move.b   #' ',(a0)+
  1940.          move.l   d6,d0
  1941.          move.l   mb_dy(a4),d7
  1942.          bsr.s    toDec
  1943.          clr.b    (a0)+
  1944. * There was a time when I used SetWindowTitles here.
  1945. * But the flashing... and the speed (or rather lack of)...
  1946.  
  1947.          move.l   MyScreen,a0
  1948.          lea      sc_RastPort(a0),a0
  1949.          lea      Coords,a1
  1950.          moveq    #80,d0
  1951.          moveq    #0,d1
  1952.          Call     PrintIText
  1953.  
  1954.          rts
  1955.  
  1956. * Fetch absolute position in complex plane when d5/d6 has
  1957. * mouse position. Return result also in d5/d6.
  1958. Position:
  1959.          push     d0
  1960.          move.w   d5,d0
  1961.          mulu     mb_dx(a4),d5
  1962.          swap     d5
  1963.          clr.w    d5
  1964.          mulu     2+mb_dx(a4),d0
  1965.          add.l    d0,d5
  1966.          add.l    mb_x0(a4),d5
  1967.  
  1968.          move.w   d6,d0
  1969.          mulu     mb_dy(a4),d6
  1970.          swap     d6
  1971.          clr.w    d6
  1972.          mulu     2+mb_dy(a4),d0
  1973.          add.l    d0,d6
  1974.          neg.l    d6
  1975.          add.l    mb_y0(a4),d6
  1976.          pull     d0
  1977.  
  1978.          rts
  1979.  
  1980. * toDec is the reverse of GetFixed. I will use a couple look-up tables
  1981. * here, too.
  1982. * INPUTS fixed point in d0, buffer in a0, delta in d7.
  1983. * RETURN next a0 in a0.
  1984.  
  1985. toDec:
  1986.          push     a1-a3/d0-d6
  1987.          move.b   #'+',d2
  1988.          tst.l    d0
  1989.          bpl.s    1$
  1990.  
  1991.          move.b   #'-',d2
  1992.          neg.l    d0
  1993. 1$:      move.b   d2,(a0)+
  1994.  
  1995.          move.b   #'0',d2
  1996. 3$:      cmp.l    #$20000000,d0
  1997.          blo.s    2$
  1998.          sub.l    #$20000000,d0
  1999.          addq.b   #1,d2
  2000.          bra.s    3$
  2001. 2$:
  2002.          move.b   d2,(a0)+
  2003.          move.b   #'.',(a0)+
  2004.  
  2005.          lea      4+NumberHi,a1
  2006.          lea      4+NumberLo,a2
  2007.          move.l   #-1,a3         ; for precision determining.
  2008.          moveq    #0,d1          ; use 64 bits of precision (SHIT! why?)
  2009. outerloop:
  2010.          move.b   #'0',d2
  2011.          move.l   (a1)+,d3
  2012.          move.l   (a2)+,d4
  2013. innerloop:
  2014.          move.l   d0,d5
  2015.          move.l   d1,d6
  2016.          sub.l    d4,d6
  2017.          subx.l   d3,d5
  2018.          bmi.s    below0
  2019.          move.l   d5,d0
  2020.          move.l   d6,d1
  2021.          addq.b   #1,d2
  2022.          bra.s    innerloop
  2023. below0:
  2024.          cmp.l    a3,d7
  2025.          move.l   -4(a1),a3
  2026.          bhi.s    it_is_over  ; it sayz: being too accurate
  2027.          move.b   d2,(a0)+
  2028.          bra.s    outerloop
  2029. it_is_over:
  2030.  
  2031. * Now we round the number. This was added because it was frustrating
  2032. * when user entered, say, 0.7 and got back 0.69.
  2033. * This is an ascii round.
  2034.          cmp.b    #'5',d2
  2035.          blo.s    no_round
  2036.          bsr.s    Round
  2037.  
  2038. no_round:
  2039.          pull     a1-a3/d0-d6
  2040.          rts
  2041.  
  2042. * This is an ASCII round.
  2043. Round:   push     a0/d0
  2044. 1$:      move.b   -(a0),d0
  2045.          cmp.b    #'.',d0
  2046.          beq.s    1$
  2047.          cmp.b    #'9',d0
  2048.          bne.s    2$
  2049.          move.b   #'0',(a0)
  2050.          bra.s    1$
  2051. 2$:
  2052.          addq.b   #1,(a0)
  2053.          pull     a0/d0
  2054.          rts
  2055.  
  2056. * Wait() for an IDCMP message from either of the windows,
  2057. * or timer I/O to complete.
  2058. * Handle ^C explicitely.
  2059.  
  2060. GetMessage:
  2061.          push     d0-d1/a0-a1
  2062.  
  2063. test_messages:
  2064.          bsr      CheckMessage
  2065.          bne.s    found_one      ; of class ^C
  2066.          tst.l    d2             ; which class? (0 = none found)
  2067.          bne.s    set_Z_exit
  2068.  
  2069. * No messages. Wait for them.
  2070.          bset     #SIGBREAKB_CTRL_C,d0
  2071.          Base     Exec
  2072.          Call     Wait
  2073.          btst     #SIGBREAKB_CTRL_C,d0
  2074.          bne.s    found_one      ; ^C (return with Z clear)
  2075.  
  2076.          bra.s    test_messages  ; Now there's a message for us. Fetch it.
  2077. set_Z_exit:
  2078.          moveq    #0,d0
  2079. found_one:
  2080.          pull     d0-d1/a0-a1
  2081.          rts
  2082.  
  2083. * This routine just gets a message if it IS here, but does not
  2084. * Wait() for it. However, returns with signal mask in d0 if
  2085. * caller wishes to wait.
  2086.  
  2087. CheckMessage:
  2088. * Test if any messages arrived
  2089.          Base     Exec
  2090.          moveq    #0,d2             ; Signal mask
  2091.  
  2092. * First window
  2093.          move.l   MyWindow1,a0      ; This is always open
  2094.          move.l   wd_UserPort(a0),a0
  2095.          move.b   MP_SIGBIT(a0),d0
  2096.          bset     d0,d2
  2097.          Call     GetMsg
  2098.          tst.l    d0
  2099.          bne.s    foundmsg
  2100.  
  2101. * Second window
  2102.          move.l   MyWindow2,a0
  2103.          move.l   a0,d0
  2104.          beq.s    1$                ; check if open
  2105.          move.l   wd_UserPort(a0),a0
  2106.          move.b   MP_SIGBIT(a0),d0
  2107.          bset     d0,d2
  2108.          Call     GetMsg
  2109.          tst.l    d0
  2110.          bne.s    foundmsg
  2111. 1$:
  2112. * Timer I/O
  2113.          move.l   UseReq,a1
  2114.          move.l   a1,d0
  2115.          beq.s    2$          ; no request pending
  2116.          move.l   MN_REPLYPORT(a1),a0
  2117.          move.b   MP_SIGBIT(a0),d0
  2118.          bset     d0,d2
  2119.          Call     CheckIO
  2120.          tst.l    d0
  2121.          bne.s    foundio
  2122. 2$:
  2123. * No messages! Return with 0 in d2, signal set in d0.
  2124.          exg.l    d0,d2
  2125.          rts
  2126.  
  2127. foundmsg:
  2128.          move.l   d0,a1
  2129.          move.l   im_Class(a1),d2
  2130.          move.w   im_Code(a1),d3
  2131.          move.w   im_Qualifier(a1),d4
  2132.          move.l   im_IAddress(a1),a5
  2133.          move.w   im_MouseX(a1),d5
  2134.          move.w   im_MouseY(a1),d6
  2135.          move.l   im_Seconds(a1),a2
  2136.          move.l   im_Micros(a1),a3
  2137.          Call     ReplyMsg
  2138.          cmp.l    #RAWKEY,d2
  2139.          bne.s    nobreak
  2140.          cmp.w    #$33,d3      ; RAW keycode for 'c'
  2141.          bne.s    nobreak
  2142.          btst     #IEQUALIFIERB_CONTROL,d4
  2143.          beq.s    nobreak
  2144. break:
  2145.          moveq    #TRUE,d0
  2146.          rts
  2147. foundio:
  2148.          move.l   UseReq,a1
  2149.          Call     WaitIO
  2150.          clr.l    UseReq
  2151.          moveq    #FAKECLASS,d2
  2152. nobreak:
  2153.          moveq    #FALSE,d0
  2154.          rts
  2155.  
  2156. Transform:
  2157. * Firsty: Magnify is useless to brot. Need to calculate
  2158. * 2 ^ (-Magnify). That, again, is very very inconvenient.
  2159.  
  2160. * Lets do it in a subroutine. Someone else might need it.
  2161.          move.w   #$2000,d0
  2162.          moveq    #$0000,d1   ; d0/d1 form 1 (fixed),
  2163.          moveq    #$0000,d2   ; d2 is just extension
  2164.          move.l   Magnify,d3
  2165.          bsr.s    Power2
  2166.  
  2167.          ifeq     SCREEN-0
  2168.          move.l   d0,mb_dx(a4)
  2169.          move.l   d0,mb_dy(a4)
  2170.          endc
  2171.          ifeq     SCREEN-1
  2172.          asr.l    #1,d0
  2173.          move.l   d0,mb_dx(a4)
  2174.          asl.l    #1,d0
  2175.          move.l   d0,mb_dy(a4)
  2176.          endc
  2177.          ifeq     SCREEN-2
  2178.          asr.l    #1,d0
  2179.          move.l   d0,mb_dy(a4)
  2180.          asl.l    #1,d0
  2181.          move.l   d0,mb_dx(a4)
  2182.          endc
  2183.          ifeq     SCREEN-3
  2184.          asr.l    #1,d0
  2185.          move.l   d0,mb_dx(a4)
  2186.          move.l   d0,mb_dy(a4)
  2187.          endc
  2188.  
  2189. * 'brot' expects to see z = x0 + y0 i to be upper lefthand corner
  2190. * whereas this program has until now assumed it is centerpoint.
  2191. * I wont use mulX instructions here because we are not in such a
  2192. * hurry. And secondly, on low magnification levels this is more
  2193. * accurate. (OK, that sounded nice. The real reason was that
  2194. * I am too lazy to find out what was wrong with that mulu!)
  2195.  
  2196.          move.w   mb_x1(a4),d0
  2197.          add.w    mb_x2(a4),d0
  2198.          move.l   CurrentX,d1
  2199.          move.l   mb_dx(a4),d2
  2200.          lsr.w    #1,d0
  2201.          bcc.s    1$
  2202.  
  2203.          move.l   d2,d3
  2204.          asr.l    #1,d3
  2205.          sub.l    d3,d1
  2206. 1$:
  2207.          tst.w    d0
  2208.          beq.s    2$
  2209.          sub.l    d2,d1
  2210.          subq.w   #1,d0
  2211.          bra.s    1$
  2212. 2$:      move.l   d1,mb_x0(a4)
  2213.  
  2214.          move.w   mb_y1(a4),d0
  2215.          add.w    mb_y2(a4),d0
  2216.          move.l   CurrentY,d1
  2217.          move.l   mb_dy(a4),d2
  2218.          lsr.w    #1,d0
  2219.          bcc.s    3$
  2220.  
  2221.          move.l   d2,d3
  2222.          asr.l    #1,d3
  2223.          add.l    d3,d1
  2224. 3$:
  2225.          tst.w    d0
  2226.          beq.s    4$
  2227.          add.l    d2,d1
  2228.          subq.w   #1,d0
  2229.          bra.s    3$
  2230. 4$:      move.l   d1,mb_y0(a4)
  2231.  
  2232.          rts
  2233.  
  2234. Power2:
  2235. * I must be a masochist...
  2236. * Right now I have no idea how to code this routine. Hm. let's see.
  2237.  
  2238. * This routine should be called with Magnify (or Zoom) in d3.
  2239. * d0/d1/d2 should be set to value to be multiplied by 2^(-d3).
  2240. * Returns d0.
  2241.  
  2242.          push     d1-d4/a0
  2243.  
  2244. * I seem to break the calculation into smaller ones, like
  2245. * 2¯¹ x 2¯¹ x ... x 2¯¹ x 2^(-1/2) x 2^(-1/4) x ...
  2246. * Each bit corresponds to one multiplication.
  2247.  
  2248.          swap     d3
  2249.          tst.w    d3
  2250. minusone:
  2251.          beq.s    skip_power
  2252.          lsr.w    #1,d0    ; This is  x 2¯¹
  2253.          roxr.w   #1,d1
  2254.          roxr.w   #1,d2
  2255.          subq.w   #1,d3
  2256.          bra.s    minusone
  2257. skip_power:
  2258.  
  2259.          swap     d3
  2260.          lea      NumberP,a0
  2261. minusfrac:
  2262.          move.w   (a0)+,d4
  2263.          asl.w    #1,d3
  2264.          bcc.s    dont_multi
  2265.  
  2266.          mulu     d4,d0
  2267.          mulu     d4,d1
  2268.          mulu     d4,d2
  2269.          swap     d2
  2270.          add.w    d1,d2
  2271.          swap     d1
  2272.          addx.w   d0,d1
  2273.          swap     d0
  2274.          moveq    #0,d4
  2275.          addx.w   d4,d0
  2276. dont_multi:
  2277.          tst.w    d3
  2278.          bne    minusfrac
  2279.  
  2280. * Ha! It was easy!
  2281.          swap     d0
  2282.          move.w   d1,d0
  2283.  
  2284.          pull     d1-d4/a0
  2285.          rts
  2286.  
  2287. * Oooooh how I wish I had a C-compiler!
  2288. * Inverse of Power2, that is,
  2289. * log  ( d2 )  in zoom/magnify fixed point format.
  2290. *    2
  2291. log2:
  2292.          push     d1-d4/a0
  2293.          moveq    #0,d1       ; this gets the answer
  2294. log_int:
  2295.          tst.w    d0
  2296.          bmi.s    log_frac
  2297.          addq.w   #1,d1
  2298.          lsl.w    #1,d0
  2299.          bra.s    log_int
  2300. log_frac:
  2301.          swap     d1
  2302.          lea      NumberL,a0
  2303.          moveq    #15,d2
  2304. log_loop:
  2305.          lsl.w    #1,d1       ; go through 16 bits
  2306.          move.w   (a0)+,d3
  2307.          moveq    #0,d4
  2308.          move.w   d0,d4
  2309.          swap     d4
  2310.          mulu     d0,d3
  2311.          add.l    d3,d4
  2312.          bcs.s    log_overflow
  2313. * That multiplication was "valid" -> record intermediate result
  2314. * in d0. Bit in d1 collects final result.
  2315.          or.b     #1,d1
  2316.          swap     d4
  2317.          bpl.s    1$
  2318.          add.w    #1,d4
  2319. 1$:
  2320.          move.w   d4,d0
  2321. log_overflow:
  2322.          dbf      d2,log_loop
  2323.          move.l   d1,d0
  2324.          pull     d1-d4/a0
  2325.  
  2326. * AMAZING! UNBELIEVABLE! I think I got it right THE VERY FIRST TIME
  2327. * I CODED IT! This must have been the 1st routine that didnt
  2328. * need to be debugged! And I thought this would be hard...
  2329.  
  2330.          rts
  2331.  
  2332.  
  2333. CtrlC:
  2334.          push     a0-a1/d0-d1/a6
  2335.          Base     Exec
  2336.          move.l   MyWindow1,a0
  2337.          move.l   wd_UserPort(a0),a0
  2338.          Call     GetMsg
  2339.          tst.l    d0
  2340.          beq.s    no_c
  2341.          move.l   d0,a1
  2342.          cmp.l    #RAWKEY,im_Class(a1)
  2343.          bne.s    reply_c
  2344.          cmp.w    #$33,im_Code(a1)
  2345.          bne.s    reply_c
  2346.          move.w   im_Qualifier(a1),d0
  2347.          btst     #IEQUALIFIERB_CONTROL,d0
  2348.          beq.s    reply_c
  2349.          Call     ReplyMsg
  2350.          moveq    #-1,d0
  2351.          bra.s    exit_c
  2352. reply_c:
  2353.          Call     ReplyMsg
  2354. no_c:
  2355.          moveq    #0,d0
  2356.          moveq    #0,d1
  2357.          Call     SetSignal
  2358.          btst     #SIGBREAKB_CTRL_C,d0
  2359. exit_c:
  2360.          pull     a0-a1/d0-d1/a6
  2361.          rts
  2362.  
  2363.  
  2364.  
  2365. * This routine gets decimal number ( -4.0 .. 4.0 ) from (a0)+ to d0.
  2366. * Format is fixed point.
  2367.  
  2368. * If Z bit is set (indicating zero result) no number was found.
  2369.  
  2370. * This may be one of the stupidest routines I've written. But
  2371. * it doesnot matter. This way I will always be accurate enough.
  2372. * (For those meatheads that do not understand what I mean:
  2373. * I use internally 64 bits of precision, the final result
  2374. * will have only 32...)
  2375.  
  2376. GetFixed:
  2377.          push     a1-a3/d1-d5
  2378.          move.l   a0,a3
  2379.          moveq    #0,d1
  2380.          moveq    #0,d3
  2381.          move.l   #$80000000,d2
  2382.          lea      NumberHi,a1
  2383.          lea      NumberLo,a2
  2384. 1$:
  2385.          move.b   (a0)+,d0
  2386.          cmp.b    #'+',d0
  2387.          beq.s    1$
  2388.          cmp.b    #'-',d0
  2389.          bne.s    2$
  2390.          bset     #15,d3   ; Now this is negative
  2391.          bra.s    1$
  2392. 2$:
  2393.          cmp.b    #'.',d0
  2394.          bne.s    3$
  2395.          bset     #7,d3    ; Remember: now we have gone past
  2396.          bra.s    1$
  2397. 3$:
  2398.          cmp.b    #'0',d0
  2399.          blo.s    4$
  2400.          cmp.b    #'9',d0
  2401.          bhi.s    4$
  2402.  
  2403.          bset     #0,d3
  2404.          cmp.l    (a1)+,(a2)+ ; go to next number position
  2405.          tst.b    d3
  2406.          bmi.s    5$
  2407.          lea      NumberHi,a1 ; We will patiently stuck with these until
  2408.          lea      NumberLo,a2 ; decimal point found
  2409. 5$:
  2410.          sub.b    #'0'+1,d0
  2411.          bmi.s    1$
  2412.          ext.w    d0
  2413.          move.l   (a1),d4
  2414.          move.l   (a2),d5
  2415. 6$:
  2416.          add.l    d5,d2
  2417.          addx.l   d4,d1
  2418.          dbf      d0,6$
  2419.          bra.s    1$
  2420.  
  2421. 4$:
  2422.          subq.l   #1,a0
  2423.          bsr.s    SkipBlk
  2424.          tst.w    d3
  2425.          bpl.s    7$
  2426.          neg.l    d1
  2427. 7$:
  2428.          move.l   d1,d0
  2429.          btst     #0,d3
  2430.          bne.s    8$
  2431.          move.l   a3,a0 ; if error, go to where we started from
  2432. 8$:
  2433.          pull     a1-a3/d1-d5
  2434.          rts
  2435.  
  2436. * This routine gets number from (a0)+ to d0.w
  2437.  
  2438. GetNum:
  2439.          push     d1/d2/a1
  2440.          move.l   a0,a1
  2441.          moveq    #FALSE,d2      ; no valid number yet
  2442.          moveq    #0,d0
  2443. 2$:
  2444.          move.b   (a0)+,d1
  2445.          cmp.b    #'0',d1
  2446.          blo.s    1$
  2447.          cmp.b    #'9',d1
  2448.          bhi.s    1$
  2449.  
  2450.          sub.b    #'0',d1
  2451.          ext.w    d1
  2452.          mulu     #10,d0
  2453.          add.w    d1,d0
  2454.          moveq    #TRUE,d2       ; valid number
  2455.          bra.s    2$
  2456.  
  2457. 1$:
  2458.          subq.l   #1,a0
  2459.          bsr.s    SkipBlk
  2460.  
  2461.          tst.w    d2          ; invalid?
  2462.          bne.s    3$
  2463.          move.l   a1,a0       ; if error, get back where to we started from
  2464. 3$:
  2465.          pull     d1/d2/a1
  2466.          rts
  2467.  
  2468. * This will skip all spaces and tabs.
  2469.  
  2470. SkipBlk:
  2471.          push     d0
  2472. 1$:
  2473.          move.b   (a0)+,d0
  2474.          cmp.b    #' ',d0
  2475.          beq.s    1$
  2476.          subq.l   #1,a0
  2477.          pull     d0
  2478.          rts
  2479.  
  2480. * A subroutine for each of the options
  2481. opt_x:   bsr      GetFixed
  2482.          beq.s    opt_xx
  2483.          move.l   d0,CurrentX
  2484.          moveq    #TRUE,d0
  2485.          rts
  2486. opt_xx
  2487. * This is just -x meaning exit when drawn.
  2488.          clr.b    inter
  2489.          moveq    #TRUE,d0
  2490.          rts
  2491.  
  2492. opt_y:   bsr      GetFixed
  2493.          beq.s    1$
  2494.          move.l   d0,CurrentY
  2495.          moveq    #TRUE,d0
  2496. 1$:      rts
  2497.  
  2498. * This option is a very special one (internally) because it uses
  2499. * still one different number format (scaled by 2^16).
  2500. * This is converted to actual mb_dx and mb_dy values later...
  2501. opt_m:   bsr.s    GetMagnify
  2502.          beq.s    opt_mm
  2503.          move.l   d0,Magnify
  2504.          moveq    #TRUE,d0
  2505.          rts
  2506. opt_mm
  2507. * This is only -m meaning mandelbrot sets
  2508.          bclr.b   #MBB_JULIA,mb_flags(a4)
  2509.          moveq    #TRUE,d0
  2510.          rts
  2511.  
  2512. GetMagnify:
  2513.          push     a1-a2/d1-d2
  2514.          move.l   a1,a2
  2515.          bsr      GetNum
  2516.          swap     d0             ; integer part go to high 16 bits
  2517.          cmp.b    #'.',(a0)+
  2518.          bne.s    m_space        ; number had ONLY integer part
  2519.          moveq    #0,d1          ; collect number here
  2520.          moveq    #0,d2          ; clear extra bits
  2521.          clr.w    d0
  2522. m_find_end:
  2523.          move.b   (a0)+,d2
  2524.          addq.w   #1,d0          ; low word has a temporary role as counter
  2525.          cmp.b    #'0',d2
  2526.          blo.s    m_end_found
  2527.          cmp.b    #'9',d2
  2528.          bls.s    m_find_end
  2529. m_end_found:
  2530.          lea      -1(a0),a1
  2531. m_loop:
  2532.          subq.w   #1,d0
  2533.          beq.s    m_got_it
  2534.          move.b   -(a1),d2
  2535.          sub.b    #'0',d2
  2536.          swap     d1
  2537.          move.w   d2,d1
  2538.          swap     d1
  2539.          divu     #10,d1
  2540.          bra.s    m_loop
  2541. m_got_it:
  2542.          move.w   d1,d0
  2543.  
  2544. m_space:
  2545.          subq.l   #1,a0
  2546.          bsr      SkipBlk
  2547.          cmp.l    #$001d0000,d0  ; greater than 2^29?
  2548.          bhi.s    m_error
  2549.          moveq    #TRUE,d1
  2550.          bra.s    m_exit
  2551. m_error:
  2552.          moveq    #FALSE,d0
  2553.          move.l   a2,a1
  2554. m_exit:  pull     a1-a2/d1-d2
  2555.          rts
  2556.  
  2557.  
  2558. opt_i:   bsr      GetNum
  2559.          beq.s    1$
  2560.          move.w   d0,mb_i(a4)
  2561.          moveq    #TRUE,d0
  2562. 1$:      rts
  2563.  
  2564.  
  2565. opt_l:   bclr.b   #MBB_AUTOPREC,mb_flags(a4)
  2566.          bclr.b   #MBB_HIGH,mb_flags(a4)
  2567.          moveq    #TRUE,d0
  2568.          rts
  2569.  
  2570. opt_h:   bclr.b   #MBB_AUTOPREC,mb_flags(a4)
  2571.          bset.b   #MBB_HIGH,mb_flags(a4)
  2572.          moveq    #TRUE,d0
  2573.          rts
  2574.  
  2575. opt_a:   bset.b   #MBB_AUTOPREC,mb_flags(a4)
  2576.          moveq    #TRUE,d0
  2577.          rts
  2578.  
  2579.  
  2580. opt_c:   bclr.b   #MBB_AUTOCRAWL,mb_flags(a4)
  2581.          bset.b   #MBB_CRAWL,mb_flags(a4)
  2582.          moveq    #TRUE,d0
  2583.          rts
  2584.  
  2585. opt_w:   bclr.b   #MBB_AUTOCRAWL,mb_flags(a4)
  2586.          bclr.b   #MBB_CRAWL,mb_flags(a4)
  2587.          moveq    #TRUE,d0
  2588.          rts
  2589.  
  2590. opt_p:   bset.b   #MBB_AUTOCRAWL,mb_flags(a4)
  2591.          moveq    #TRUE,d0
  2592.          rts
  2593.  
  2594. opt_g:   move.b   #TRUE,inter
  2595.          rts
  2596.  
  2597.  
  2598. opt_j:   move.b   (a0)+,d0
  2599.          toupper  d0
  2600.  
  2601.          cmp.b    #'X',d0
  2602.          bne.s    j_no_x
  2603. opt_jx      ; WB options enter this routine here
  2604.          bsr      GetFixed
  2605.          beq.s    1$
  2606.          move.l   d0,mb_jx(a4)
  2607.          moveq    #TRUE,d0
  2608. 1$:      rts
  2609.  
  2610. j_no_x:  cmp.b    #'Y',d0
  2611.          bne.s    j_no_y
  2612. opt_jy      ; WB entry point
  2613.          bsr      GetFixed
  2614.          beq.s    1$
  2615.          move.l   d0,mb_jy(a4)
  2616.          moveq    #TRUE,d0
  2617. 1$:      rts
  2618.  
  2619.  
  2620. j_no_y
  2621. * This is just -j meaning julia sets
  2622.          subq.l   #1,a0
  2623. opt_jj      ; WB entry
  2624.          bset.b   #MBB_JULIA,mb_flags(a4)
  2625.          moveq    #TRUE,d0
  2626.          rts
  2627.  
  2628. opt_s
  2629.          lea      NameBuffer,a1
  2630. s_endstr
  2631.          move.b   (a0)+,d0
  2632.          beq.s    s_over
  2633.          cmp.b    #' ',d0
  2634.          beq.s    s_over
  2635.          move.b   d0,(a1)+
  2636.          bra.s    s_endstr
  2637. s_over
  2638.          subq.l   #1,a0
  2639.          clr.b    (a1)
  2640.          move.l   a1,NameEnd
  2641.          bsr      SkipBlk
  2642.          move.b   #TRUE,d0
  2643.          move.b   d0,saveit
  2644.          rts
  2645.  
  2646.  
  2647. * For WB use, e.g. FLAGS=xc\0
  2648. opt_flags
  2649.          move.b   (a0)+,d0
  2650.          beq.s    no_more_flags
  2651.          toupper  d0
  2652.  
  2653. * This will return use in this routine.
  2654.          pea      opt_flags
  2655.          cmp.b    #'L',d0
  2656.          beq      opt_l
  2657.          cmp.b    #'H',d0
  2658.          beq      opt_h
  2659.          cmp.b    #'A',d0
  2660.          beq      opt_a
  2661.          cmp.b    #'C',d0
  2662.          beq      opt_c
  2663.          cmp.b    #'W',d0
  2664.          beq      opt_w
  2665.          cmp.b    #'P',d0
  2666.          beq      opt_p
  2667.          cmp.b    #'G',d0
  2668.          beq      opt_g
  2669.          cmp.b    #'J',d0
  2670.          beq      opt_jj      ; not opt_j
  2671.          cmp.b    #'M',d0
  2672.          beq      opt_mm      ; not opt_m
  2673.          cmp.b    #'X',d0
  2674.          beq      opt_xx      ; not opt_x
  2675. * Wrong option!
  2676.          addq.l   #4,a7
  2677.          moveq    #FALSE,d0
  2678.          rts
  2679. no_more_flags
  2680.          moveq    #TRUE,d0
  2681.          rts
  2682.  
  2683. SavePicture:
  2684.          lea      NameBuffer,a0
  2685.          move.l   a0,d2
  2686.  
  2687.          move.l   NameEnd,a0
  2688.          move.w   Counter,d0
  2689.          beq.s    first_time
  2690. * When 2nd etc. file saved, use a running number as an identifier
  2691.          bsr      toInt
  2692.          clr.b    (a0)        ; 0 terminates string
  2693. first_time:
  2694.          addq.w   #1,Counter
  2695.  
  2696.          lea      _IffLib,a1
  2697.          moveq    #0,d0
  2698.          Base     Exec
  2699.          Call     OpenLibrary
  2700.          tst.l    d0
  2701.          beq.s    noifflib
  2702.          move.l   d0,a6
  2703.  
  2704.          move.l   MyScreen,a0
  2705.          move.l   sc_ViewPort+vp_ColorMap(a0),a2
  2706.          move.l   cm_ColorTable(a2),a2          ; colortable
  2707.          move.l   sc_RastPort+rp_BitMap(a0),a1  ; bitmap
  2708.          move.l   d2,a0                         ; filename
  2709.  
  2710.          move.w   mb_x1(a4),d1
  2711.          move.w   mb_y1(a4),d2
  2712.          move.w   mb_x2(a4),d3
  2713.          move.w   mb_y2(a4),d4
  2714.  
  2715.          lsr.w    #3,d1       ; no of BYTES
  2716.          add.w    #7,d3
  2717.          lsr.w    #3,d3
  2718.  
  2719.          sub.w    d1,d3
  2720.          sub.w    d2,d4
  2721.          addq.w   #1,d3       ; width and heigth
  2722.          addq.w   #1,d4
  2723.  
  2724.          moveq    #1,d0       ; run-length compression
  2725.  
  2726.          jsr      SaveClip(a6)
  2727.          move.l   d0,d2
  2728.  
  2729.          move.l   a6,a1
  2730.          Base     Exec
  2731.          Call     CloseLibrary
  2732.  
  2733.          tst.l    d2
  2734.          bne.s    exit_save
  2735.          move.b   #ERROR_ifflib,error
  2736.          bra.s    exit_save
  2737. noifflib:
  2738.          move.b   #ERROR_noifflib,error
  2739. exit_save:
  2740.          rts
  2741.  
  2742.    SECTION  data,DATA
  2743. * First elements form $20000000 00000000 (represents 1)
  2744. * then 1/10, 1/100 etc.
  2745. NumberHi:
  2746.          dc.l  $20000000,$03333333,$0051EB85,$00083126
  2747.          dc.l  $0000D1B7,$000014F8,$00000218,$00000035
  2748.          dc.l  $00000005,$00000000,$00000000,$00000000
  2749.          dc.l  $00000000,$00000000,$00000000,$00000000
  2750. NumberLo:
  2751.          dc.l  $00000000,$33333333,$1EB851EB,$E978D4FD
  2752.          dc.l  $1758E219,$B588E368,$DEF416BD,$AFE53579
  2753.          dc.l  $5E63B88C,$89705F41,$0DBE6FEC,$015FD7FE
  2754.          dc.l  $00232F33,$000384B8,$00005A12,$00000901
  2755.  
  2756. * Still one table. This time: 2^(-1/2) , 2^(-1/4) ... times $10000.
  2757. NumberP:
  2758.          dc.w  $b505,$d745,$eac1,$f525,$fa84,$fd3e,$fe9e,$ff4f
  2759.          dc.w  $ffa7,$ffd4,$ffea,$fff5,$fffa,$fffd,$ffff,$ffff
  2760. * Inverse of former: 2^(1/2), 2^(1/4) etc.
  2761. * Implied highest "1" has been deleted.
  2762. * (Example: 2^(1/2) = sqrt(2) = 1.4142 x $10000 = $16a0a -> $6a0a)
  2763. NumberL:
  2764.          dc.w  $6A0A,$3070,$172C,$0B56,$059B,$02CA,$0164,$00B2
  2765.          dc.w  $0059,$002C,$0016,$000B,$0006,$0003,$0001,$0001
  2766.  
  2767.  
  2768. Colors:
  2769.          ifeq  DEPTH-5
  2770.             dc.w  $888,$000
  2771.             dc.w  $f00,$f30,$f60,$f90,$fc0,$ff0,$cf0,$9f0,$6f0,$3f0
  2772.             dc.w  $0f0,$0f3,$0f6,$0f9,$0fc,$0ff,$0cf,$09f,$06f,$03f
  2773.             dc.w  $00f,$30f,$60f,$90f,$c0f,$f0f,$f0c,$f09,$f06,$f03
  2774.          endc
  2775.          ifeq  DEPTH-4
  2776.             dc.w  $888,$000
  2777.             dc.w  $f00,$f80,$ff0,$8f0
  2778.             dc.w  $0f0,$0f6,$0fc,$0cf,$06f
  2779.             dc.w  $00f,$60f,$c0f,$f0c,$f06
  2780.          endc
  2781.          ifeq  DEPTH-3
  2782.             dc.w  $888,$000,$f00,$ff0,$0f0,$0ff,$00f,$f0f
  2783.          endc
  2784.          ifeq  DEPTH-2
  2785.             dc.w  $888,$000,$f00,$00f
  2786.          endc
  2787. MyNewScreen:
  2788.          dc.w  0,0            ; offsets
  2789.          dc.w  XSIZE,YSIZE    ; size x * y
  2790.          dc.w  DEPTH          ; planes
  2791.          dc.b  1,2            ; default pens
  2792.          dc.w  VIEWMODE
  2793.          dc.w  CUSTOMSCREEN
  2794.          dc.l  0,ScreenTitle,0          ; font,title,gadgets
  2795.  
  2796. MyNewWindow1:
  2797.          dc.w  0,0
  2798.          dc.w  XSIZE,YSIZE       ; width, heigth
  2799.          dc.b  1,2               ; pens
  2800.          dc.l  IDCMP1            ; IDCMP
  2801.          dc.l  FLAGS1
  2802.          dc.l  0,0,0             ; gadgets, checkmark, title
  2803. InsertScreen1:
  2804.          ds.l  1                 ; screen (to be inserted later)
  2805.          dc.l  0                 ; bitmap
  2806.          dc.w  -1,-1,-1,-1       ; min/max size
  2807.          dc.w  CUSTOMSCREEN      ; screen type
  2808.  
  2809. MyNewWindow2:
  2810.          dc.w  WINX,WINY         ; place (to be modified later)
  2811.          dc.w  WINW,WINH         ; width, heigth
  2812.          dc.b  1,2               ; pens
  2813.          dc.l  IDCMP2            ; IDCMP
  2814.          dc.l  FLAGS2
  2815.          dc.l  XGadget           ; ... gadgets ... (lots of them!)
  2816.          dc.l  0,0               ; checkmark, title
  2817. InsertScreen2:
  2818.          ds.l  1                 ; screen (to be inserted later)
  2819.          dc.l  0                 ; bitmap
  2820.          dc.w  -1,-1,-1,-1       ; min/max size
  2821.          dc.w  CUSTOMSCREEN      ; screen type
  2822.  
  2823. uniqueID SET   0
  2824. MakeID   macro
  2825. \1       EQU   uniqueID
  2826. uniqueID SET   uniqueID+1
  2827.          endm
  2828.  
  2829.          MakeID   GAD_X
  2830.          MakeID   GAD_Y
  2831.          MakeID   GAD_M
  2832.          MakeID   GAD_Z
  2833.          MakeID   GAD_I
  2834.          MakeID   GAD_ZOOM
  2835.          MakeID   GAD_DRAW
  2836.          MakeID   GAD_RESET
  2837.          MakeID   GAD_MANDEL
  2838.          MakeID   GAD_JULIA
  2839.          MakeID   GAD_QUIT
  2840. MINUS    EQU      $8000
  2841. STRING   EQU      $4000
  2842. ZOOMTYPE EQU      $2000
  2843. SETTYPE  EQU      $1000
  2844. IDMASK   EQU      $8fff    ; so as not to mask sign
  2845.  
  2846. XGadget:
  2847.          dc.l  YGadget     ; link to next
  2848.          dc.w  39,13,104,8 ; place & size
  2849.          dc.w  GADGHCOMP
  2850.          dc.w  RELVERIFY|GADGIMMEDIATE
  2851.          dc.w  STRGADGET
  2852.          dc.l  XYBorder    ; image for gadget
  2853.          dc.l  0
  2854.          dc.l  XText
  2855.          dc.l  0           ; MutualExclude
  2856.          dc.l  XString     ; specialinfo
  2857.          dc.w  STRING|GAD_X ; ID
  2858.          dc.l  0
  2859. XString:
  2860.          dc.l  XBuffer
  2861.          dc.l  0
  2862.          dc.w  0
  2863.          dc.w  13
  2864.          dc.w  0
  2865.          dc.w  0,0,0,0,0
  2866.          dc.l  0
  2867.          dc.l  0,0
  2868. XText:
  2869.          dc.b  1,2      ; pens
  2870.          dc.b  RP_JAM1,0   ; drawmodes
  2871.          dc.w  -10,0     ; offsets
  2872.          dc.l  0        ; default font
  2873.          dc.l  XLetter  ; (yeah, just one letter)
  2874.          dc.l  0        ; no more text
  2875. YGadget:
  2876.          dc.l  YPLUSGadget     ; the next one
  2877.          dc.w  39,26,104,8 ; place & size
  2878.          dc.w  GADGHCOMP
  2879.          dc.w  RELVERIFY|GADGIMMEDIATE
  2880.          dc.w  STRGADGET
  2881.          dc.l  XYBorder
  2882.          dc.l  0
  2883.          dc.l  YText
  2884.          dc.l  0
  2885.          dc.l  YString     ; specialinfo
  2886.          dc.w  STRING|GAD_Y ; ID
  2887.          dc.l  0
  2888. YString:
  2889.          dc.l  YBuffer
  2890.          dc.l  0
  2891.          dc.w  0
  2892.          dc.w  13
  2893.          dc.w  0
  2894.          dc.w  0,0,0,0,0
  2895.          dc.l  0
  2896.          dc.l  0,0
  2897. YText:
  2898.          dc.b  1,2      ; pens
  2899.          dc.b  RP_JAM1,0   ; drawmodes
  2900.          dc.w  -10,0    ; offsets
  2901.          dc.l  0        ; default font
  2902.          dc.l  YLetter  ; (yeah, just one letter)
  2903.          dc.l  0        ; no more text
  2904. XYBorder:
  2905.          dc.w  -2,-2 ; place
  2906.          dc.b  1,0   ; pens
  2907.          dc.b  RP_JAM1
  2908.          dc.b  5     ; # of pairs
  2909.          dc.l  XYPairs  ; the actual data
  2910.          dc.l  0
  2911. XYPairs:
  2912.          dc.w  0,0
  2913.          dc.w  107,0
  2914.          dc.w  107,11
  2915.          dc.w  0,11
  2916.          dc.w  0,0
  2917. YPLUSGadget:
  2918.          dc.l  YMINUSGadget ; and the next one.
  2919.          dc.w  10,11,11,6  ; place & size
  2920.          dc.w  GADGHCOMP|GADGIMAGE
  2921.          dc.w  RELVERIFY|GADGIMMEDIATE
  2922.          dc.w  BOOLGADGET
  2923.          dc.l  UPimage
  2924.          dc.l  0,0,0
  2925.          dc.l  0           ; specialinfo
  2926.          dc.w  GAD_Y       ; ID
  2927.          dc.l  0
  2928. YMINUSGadget:
  2929.          dc.l  XMINUSGadget ; and the next one.
  2930.          dc.w  10,30,11,6  ; place & size
  2931.          dc.w  GADGHCOMP|GADGIMAGE
  2932.          dc.w  RELVERIFY|GADGIMMEDIATE
  2933.          dc.w  BOOLGADGET
  2934.          dc.l  DOWNimage
  2935.          dc.l  0,0,0
  2936.          dc.l  0           ; specialinfo
  2937.          dc.w  GAD_Y|MINUS ; ID
  2938.          dc.l  0
  2939. XMINUSGadget:
  2940.          dc.l  XPLUSGadget ; and the next one.
  2941.          dc.w  3,18,6,11   ; place & size
  2942.          dc.w  GADGHCOMP|GADGIMAGE
  2943.          dc.w  RELVERIFY|GADGIMMEDIATE
  2944.          dc.w  BOOLGADGET
  2945.          dc.l  LEFTimage
  2946.          dc.l  0,0,0
  2947.          dc.l  0           ; specialinfo
  2948.          dc.w  GAD_X|MINUS ; ID
  2949.          dc.l  0
  2950. XPLUSGadget:
  2951.          dc.l  MGadget     ; and the next one.
  2952.          dc.w  22,18,6,11  ; place & size
  2953.          dc.w  GADGHCOMP|GADGIMAGE
  2954.          dc.w  RELVERIFY|GADGIMMEDIATE
  2955.          dc.w  BOOLGADGET
  2956.          dc.l  RIGHTimage
  2957.          dc.l  0,0,0
  2958.          dc.l  0           ; specialinfo
  2959.          dc.w  GAD_X       ; ID
  2960.          dc.l  0
  2961. MGadget:
  2962.          dc.l  MPLUSGadget ; more to come...
  2963.          dc.w  23,42,40,8 ; place & size
  2964.          dc.w  GADGHCOMP
  2965.          dc.w  RELVERIFY|GADGIMMEDIATE
  2966.          dc.w  STRGADGET
  2967.          dc.l  MBorder
  2968.          dc.l  0
  2969.          dc.l  MText
  2970.          dc.l  0
  2971.          dc.l  MString     ; specialinfo
  2972.          dc.w  STRING|GAD_M ; ID
  2973.          dc.l  0
  2974. MString:
  2975.          dc.l  MBuffer
  2976.          dc.l  0
  2977.          dc.w  0
  2978.          dc.w  9
  2979.          dc.w  0
  2980.          dc.w  0,0,0,0,0
  2981.          dc.l  0
  2982.          dc.l  0,0
  2983. MText:
  2984.          dc.b  1,2      ; pens
  2985.          dc.b  RP_JAM1,0   ; drawmodes
  2986.          dc.w  -18,0    ; offsets
  2987.          dc.l  0        ; default font
  2988.          dc.l  MLetter  ; (yeah, just one letter)
  2989.          dc.l  0        ; no more text
  2990. MBorder:
  2991.          dc.w  -2,-2 ; place
  2992.          dc.b  1,0   ; pens
  2993.          dc.b  RP_JAM1
  2994.          dc.b  5     ; # of pairs
  2995.          dc.l  MPairs   ; the actual data
  2996.          dc.l  0
  2997. MPairs:
  2998.          dc.w  0,0
  2999.          dc.w  43,0
  3000.          dc.w  43,11
  3001.          dc.w  0,11
  3002.          dc.w  0,0
  3003. MPLUSGadget:
  3004.          dc.l  MMINUSGadget ; and the next one.
  3005.          dc.w  14,40,6,11   ; place & size
  3006.          dc.w  GADGHCOMP|GADGIMAGE
  3007.          dc.w  RELVERIFY|GADGIMMEDIATE
  3008.          dc.w  BOOLGADGET
  3009.          dc.l  LEFTimage
  3010.          dc.l  0,0,0
  3011.          dc.l  0           ; specialinfo
  3012.          dc.w  GAD_M       ; ID
  3013.          dc.l  0
  3014. MMINUSGadget:
  3015.          dc.l  ZGadget     ; and the next one.
  3016.          dc.w  66,40,6,11  ; place & size
  3017.          dc.w  GADGHCOMP|GADGIMAGE
  3018.          dc.w  RELVERIFY|GADGIMMEDIATE
  3019.          dc.w  BOOLGADGET
  3020.          dc.l  RIGHTimage
  3021.          dc.l  0,0,0
  3022.          dc.l  0           ; specialinfo
  3023.          dc.w  GAD_M|MINUS ; ID
  3024.          dc.l  0
  3025. ZGadget:
  3026.          dc.l  ZPLUSGadget ; more to come...
  3027.          dc.w  23,55,40,8  ; place & size
  3028.          dc.w  GADGHCOMP
  3029.          dc.w  RELVERIFY|GADGIMMEDIATE|STRINGRIGHT
  3030.          dc.w  STRGADGET
  3031.          dc.l  ZBorder
  3032.          dc.l  0
  3033.          dc.l  ZText
  3034.          dc.l  0
  3035.          dc.l  ZString     ; specialinfo
  3036.          dc.w  STRING|GAD_Z ; ID
  3037.          dc.l  0
  3038. ZString:
  3039.          dc.l  ZBuffer
  3040.          dc.l  0
  3041.          dc.w  0
  3042.          dc.w  9
  3043.          dc.w  0
  3044.          dc.w  0,0,0,0,0
  3045.          dc.l  0
  3046.          dc.l  0,0
  3047. ZText:
  3048.          dc.b  1,2      ; pens
  3049.          dc.b  RP_JAM1,0   ; drawmodes
  3050.          dc.w  -18,0    ; offsets
  3051.          dc.l  0        ; default font
  3052.          dc.l  ZLetter  ; (yeah, just one letter)
  3053.          dc.l  0        ; no more text
  3054. * These are same as ZBorder. One could optimize. Why should one?
  3055. ZBorder:
  3056.          dc.w  -2,-2 ; place
  3057.          dc.b  1,0   ; pens
  3058.          dc.b  RP_JAM1
  3059.          dc.b  5     ; # of pairs
  3060.          dc.l  ZPairs   ; the actual data
  3061.          dc.l  0
  3062. ZPairs:
  3063.          dc.w  0,0
  3064.          dc.w  43,0
  3065.          dc.w  43,11
  3066.          dc.w  0,11
  3067.          dc.w  0,0
  3068. ZPLUSGadget:
  3069.          dc.l  ZMINUSGadget ; and the next one.
  3070.          dc.w  14,53,6,11  ; place & size
  3071.          dc.w  GADGHCOMP|GADGIMAGE
  3072.          dc.w  RELVERIFY|GADGIMMEDIATE
  3073.          dc.w  BOOLGADGET
  3074.          dc.l  LEFTimage
  3075.          dc.l  0,0,0
  3076.          dc.l  0           ; specialinfo
  3077.          dc.w  GAD_Z       ; ID
  3078.          dc.l  0
  3079. ZMINUSGadget:
  3080.          dc.l  IGadget     ; still these to go
  3081.          dc.w  66,53,6,11  ; place & size
  3082.          dc.w  GADGHCOMP|GADGIMAGE
  3083.          dc.w  RELVERIFY|GADGIMMEDIATE
  3084.          dc.w  BOOLGADGET
  3085.          dc.l  RIGHTimage
  3086.          dc.l  0,0,0
  3087.          dc.l  0           ; specialinfo
  3088.          dc.w  GAD_Z|MINUS ; ID
  3089.          dc.l  0
  3090. IGadget:
  3091.          dc.l  IMINUSGadget ; more to come...
  3092.          dc.w  27,68,32,8 ; place & size
  3093.          dc.w  GADGHCOMP
  3094.          dc.w  RELVERIFY|GADGIMMEDIATE|STRINGRIGHT
  3095.          dc.w  STRGADGET
  3096.          dc.l  IBorder
  3097.          dc.l  0
  3098.          dc.l  IText
  3099.          dc.l  0
  3100.          dc.l  IString     ; specialinfo
  3101.          dc.w  STRING|GAD_I ; ID
  3102.          dc.l  0
  3103. IString:
  3104.          dc.l  IBuffer
  3105.          dc.l  0
  3106.          dc.w  0
  3107.          dc.w  6
  3108.          dc.w  0
  3109.          dc.w  0,0,0,0,0
  3110.          dc.l  0
  3111.          dc.l  0,0
  3112. IText:
  3113.          dc.b  1,2      ; pens
  3114.          dc.b  RP_JAM1,0   ; drawmodes
  3115.          dc.w  -22,0    ; offsets
  3116.          dc.l  0        ; default font
  3117.          dc.l  ILetter  ; (yeah, just one letter)
  3118.          dc.l  0        ; no more text
  3119. * This is actually same as ZBorder & ZPairs, but who cares?
  3120. IBorder:
  3121.          dc.w  -2,-2    ; place
  3122.          dc.b  1,0      ; pens
  3123.          dc.b  RP_JAM1
  3124.          dc.b  5        ; # of pairs
  3125.          dc.l  IPairs   ; the actual data
  3126.          dc.l  0
  3127. IPairs:
  3128.          dc.w  0,0
  3129.          dc.w  35,0
  3130.          dc.w  35,11
  3131.          dc.w  0,11
  3132.          dc.w  0,0
  3133. IMINUSGadget:
  3134.          dc.l  IPLUSGadget ; and the next one.
  3135.          dc.w  18,66,6,11  ; place & size
  3136.          dc.w  GADGHCOMP|GADGIMAGE
  3137.          dc.w  RELVERIFY|GADGIMMEDIATE
  3138.          dc.w  BOOLGADGET
  3139.          dc.l  LEFTimage
  3140.          dc.l  0,0,0
  3141.          dc.l  0           ; specialinfo
  3142.          dc.w  GAD_I|MINUS ; ID
  3143.          dc.l  0
  3144. IPLUSGadget:
  3145.          dc.l  ZOOMGadget  ; and still more.
  3146.          dc.w  62,66,6,11  ; place & size
  3147.          dc.w  GADGHCOMP|GADGIMAGE
  3148.          dc.w  RELVERIFY|GADGIMMEDIATE
  3149.          dc.w  BOOLGADGET
  3150.          dc.l  RIGHTimage
  3151.          dc.l  0,0,0
  3152.          dc.l  0              ; specialinfo
  3153.          dc.w  GAD_I          ; ID
  3154.          dc.l  0
  3155. ZOOMGadget:
  3156.          dc.l  DRAWGadget     ; and still more.
  3157.          dc.w  73,40,32,12    ; place & size
  3158.          dc.w  GADGHIMAGE|GADGIMAGE
  3159.          dc.w  GADGIMMEDIATE
  3160.          dc.w  BOOLGADGET
  3161.          dc.l  ZOOMimage0
  3162.          dc.l  ZOOMimage1
  3163.          dc.l  0,0
  3164.          dc.l  0              ; specialinfo
  3165.          dc.w  GAD_ZOOM|ZOOMTYPE ; ID
  3166.          dc.l  0
  3167. DRAWGadget:
  3168.          dc.l  RESETGadget    ; and still more.
  3169.          dc.w  73,53,32,12    ; place & size
  3170.          dc.w  GADGHIMAGE|GADGIMAGE
  3171.          dc.w  GADGIMMEDIATE
  3172.          dc.w  BOOLGADGET
  3173.          dc.l  DRAWimage0
  3174.          dc.l  DRAWimage1
  3175.          dc.l  0,0
  3176.          dc.l  0              ; specialinfo
  3177.          dc.w  GAD_DRAW|ZOOMTYPE ; ID
  3178.          dc.l  0
  3179. RESETGadget:
  3180.          dc.l  MANDELGadget   ; and still more.
  3181.          dc.w  73,66,32,12    ; place & size
  3182.          dc.w  GADGHIMAGE|GADGIMAGE
  3183.          dc.w  GADGIMMEDIATE
  3184.          dc.w  BOOLGADGET
  3185.          dc.l  RESETimage0
  3186.          dc.l  RESETimage1
  3187.          dc.l  0,0
  3188.          dc.l  0              ; specialinfo
  3189.          dc.w  GAD_RESET|ZOOMTYPE ; ID
  3190.          dc.l  0
  3191. MANDELGadget:
  3192.          dc.l  JULIAGadget    ; and still more.
  3193.          dc.w  106,40,19,25   ; place & size
  3194.          dc.w  GADGHIMAGE|GADGIMAGE
  3195.          dc.w  GADGIMMEDIATE
  3196.          dc.w  BOOLGADGET
  3197.          dc.l  MANDELimage0   ; gadgetrender
  3198.          dc.l  MANDELimage1   ; selectrender
  3199.          dc.l  0,0
  3200.          dc.l  0              ; specialinfo
  3201.          dc.w  GAD_MANDEL|SETTYPE ; ID
  3202.          dc.l  0
  3203. JULIAGadget:
  3204.          dc.l  QUITGadget     ; and still more.
  3205.          dc.w  126,40,19,25   ; place & size
  3206.          dc.w  GADGHIMAGE|GADGIMAGE
  3207.          dc.w  GADGIMMEDIATE
  3208.          dc.w  BOOLGADGET
  3209.          dc.l  JULIAimage0    ; gadgetrender
  3210.          dc.l  JULIAimage1    ; selectrender
  3211.          dc.l  0,0
  3212.          dc.l  0              ; specialinfo
  3213.          dc.w  GAD_JULIA|SETTYPE ; ID
  3214.          dc.l  0
  3215. QUITGadget:
  3216.          dc.l  0              ; This was the end (Thank Goddess) (see below)
  3217.          dc.w  106,66,39,12   ; place & size
  3218.          dc.w  GADGHIMAGE|GADGIMAGE
  3219.          dc.w  GADGIMMEDIATE|RELVERIFY
  3220.          dc.w  BOOLGADGET
  3221.          dc.l  QUITimage0
  3222.          dc.l  QUITimage1
  3223.          dc.l  0,0
  3224.          dc.l  0              ; specialinfo
  3225.          dc.w  GAD_QUIT       ; ID
  3226.          dc.l  0
  3227.  
  3228. * That was God awful!!! Gadget after gadget, structure after structure...
  3229. * Uhh... It must've been a real pain to code a program like preferences
  3230. * with thousands of gadgets.
  3231.  
  3232. UPimage:
  3233.          dc.w  0,0         ; offsets
  3234.          dc.w  11,6        ; w, h
  3235.          dc.w  DEPTH       ; depth
  3236.          dc.l  UParrow     ; actual image
  3237.          dc.b  %00011      ; planepick
  3238.          dc.b  %00000      ; planeonoff
  3239.          dc.l  0           ; nextimage
  3240. * The nextimage field seems to be important. Forget it and you
  3241. * will have to debug your program for weeks.
  3242. DOWNimage:
  3243.          dc.w  0,0         ; offsets
  3244.          dc.w  11,6        ; w, h
  3245.          dc.w  DEPTH       ; depth
  3246.          dc.l  DOWNarrow   ; actual image
  3247.          dc.b  %00011      ; planepick
  3248.          dc.b  %00000      ; planeonoff
  3249.          dc.l  0           ; nextimage
  3250. LEFTimage:
  3251.          dc.w  0,0         ; offsets
  3252.          dc.w  6,11        ; w, h
  3253.          dc.w  DEPTH       ; depth
  3254.          dc.l  LEFTarrow   ; actual image
  3255.          dc.b  %00011      ; planepick
  3256.          dc.b  %00000      ; planeonoff
  3257.          dc.l  0           ; nextimage
  3258. RIGHTimage:
  3259.          dc.w  0,0         ; offsets
  3260.          dc.w  6,11        ; w, h
  3261.          dc.w  DEPTH       ; depth
  3262.          dc.l  RIGHTarrow  ; actual image
  3263.          dc.b  %00011      ; planepick
  3264.          dc.b  %00000      ; planeonoff
  3265.          dc.l  0           ; nextimage
  3266. ZOOMimage0:
  3267.          dc.w  0,0         ; offsets
  3268.          dc.w  32,12       ; w, h
  3269.          dc.w  DEPTH       ; depth
  3270.          dc.l  ZOOMpict    ; actual image
  3271.          dc.b  %00001      ; planepick
  3272.          dc.b  %00000      ; planeonoff
  3273.          dc.l  0           ; nextimage
  3274. ZOOMimage1:
  3275.          dc.w  0,0         ; offsets
  3276.          dc.w  32,12       ; w, h
  3277.          dc.w  DEPTH       ; depth
  3278.          dc.l  ZOOMpict    ; actual image
  3279.          dc.b  %00011      ; planepick
  3280.          dc.b  %00000      ; planeonoff
  3281.          dc.l  0           ; nextimage
  3282. DRAWimage0:
  3283.          dc.w  0,0         ; offsets
  3284.          dc.w  32,12       ; w, h
  3285.          dc.w  DEPTH       ; depth
  3286.          dc.l  DRAWpict    ; actual image
  3287.          dc.b  %00001      ; planepick
  3288.          dc.b  %00000      ; planeonoff
  3289.          dc.l  0           ; nextimage
  3290. DRAWimage1:
  3291.          dc.w  0,0         ; offsets
  3292.          dc.w  32,12       ; w, h
  3293.          dc.w  DEPTH       ; depth
  3294.          dc.l  DRAWpict    ; actual image
  3295.          dc.b  %00011      ; planepick
  3296.          dc.b  %00000      ; planeonoff
  3297.          dc.l  0           ; nextimage
  3298. RESETimage0:
  3299.          dc.w  0,0         ; offsets
  3300.          dc.w  32,12       ; w, h
  3301.          dc.w  DEPTH       ; depth
  3302.          dc.l  RESETpict   ; actual image
  3303.          dc.b  %00001      ; planepick
  3304.          dc.b  %00000      ; planeonoff
  3305.          dc.l  0           ; nextimage
  3306. RESETimage1:
  3307.          dc.w  0,0         ; offsets
  3308.          dc.w  32,12       ; w, h
  3309.          dc.w  DEPTH       ; depth
  3310.          dc.l  RESETpict   ; actual image
  3311.          dc.b  %00011      ; planepick
  3312.          dc.b  %00000      ; planeonoff
  3313.          dc.l  0           ; nextimage
  3314. JULIAimage0:
  3315.          dc.w  0,0         ; offsets
  3316.          dc.w  19,25       ; w, h
  3317.          dc.w  DEPTH       ; depth
  3318.          dc.l  JULIApict   ; actual image
  3319.          dc.b  %00001      ; planepick
  3320.          dc.b  %00000      ; planeonoff
  3321.          dc.l  0           ; nextimage
  3322. JULIAimage1:
  3323.          dc.w  0,0         ; offsets
  3324.          dc.w  19,25       ; w, h
  3325.          dc.w  DEPTH       ; depth
  3326.          dc.l  JULIApict   ; actual image
  3327.          dc.b  %00011      ; planepick
  3328.          dc.b  %00000      ; planeonoff
  3329.          dc.l  0           ; nextimage
  3330. MANDELimage0:
  3331.          dc.w  0,0         ; offsets
  3332.          dc.w  19,25       ; w, h
  3333.          dc.w  DEPTH       ; depth
  3334.          dc.l  MANDELpict  ; actual image
  3335.          dc.b  %00001      ; planepick
  3336.          dc.b  %00000      ; planeonoff
  3337.          dc.l  0           ; nextimage
  3338. MANDELimage1:
  3339.          dc.w  0,0         ; offsets
  3340.          dc.w  19,25       ; w, h
  3341.          dc.w  DEPTH       ; depth
  3342.          dc.l  MANDELpict  ; actual image
  3343.          dc.b  %00011      ; planepick
  3344.          dc.b  %00000      ; planeonoff
  3345.          dc.l  0           ; nextimage
  3346. QUITimage0:
  3347.          dc.w  0,0         ; offsets
  3348.          dc.w  39,12       ; w, h
  3349.          dc.w  DEPTH       ; depth
  3350.          dc.l  QUITpict    ; actual image
  3351.          dc.b  %00001      ; planepick
  3352.          dc.b  %00000      ; planeonoff
  3353.          dc.l  0           ; nextimage
  3354. QUITimage1:
  3355.          dc.w  0,0         ; offsets
  3356.          dc.w  39,12       ; w, h
  3357.          dc.w  DEPTH       ; depth
  3358.          dc.l  QUITpict    ; actual image
  3359.          dc.b  %00011      ; planepick
  3360.          dc.b  %00000      ; planeonoff
  3361.          dc.l  0           ; nextimage
  3362.  
  3363. Cross:
  3364.          dc.w  0,0         ; place
  3365.          dc.b  31,0        ; pens
  3366.          dc.b  RP_COMPLEMENT
  3367.          dc.b  2           ; # of pairs
  3368.          dc.l  CrossVPairs ; the actual data
  3369.          dc.l  CrossH      ; next
  3370. CrossVPairs:
  3371.          dc.w  -10,0
  3372.          dc.w  10,0
  3373. CrossH:
  3374.          dc.w  0,0         ; place
  3375.          dc.b  31,0        ; pens
  3376.          dc.b  RP_COMPLEMENT
  3377.          dc.b  2           ; # of pairs
  3378.          dc.l  CrossHPairs ; the actual data
  3379.          dc.l  0           ; next
  3380. CrossHPairs:
  3381.          dc.w  0,-10
  3382.          dc.w  0,10
  3383.  
  3384. TopLeft:
  3385.          dc.w  0,0         ; place
  3386.          dc.b  31,0        ; pens
  3387.          dc.b  RP_COMPLEMENT
  3388.          dc.b  3           ; # of pairs
  3389.          dc.l  TopLeftPairs ; the actual data
  3390.          dc.l  0
  3391. TopLeftPairs:
  3392.          dc.w  0,10
  3393.          dc.w  0,0
  3394.          dc.w  10,0
  3395. TopRight:
  3396.          dc.w  0,0         ; place
  3397.          dc.b  31,0        ; pens
  3398.          dc.b  RP_COMPLEMENT
  3399.          dc.b  3           ; # of pairs
  3400.          dc.l  TopRightPairs ; the actual data
  3401.          dc.l  0
  3402. TopRightPairs:
  3403.          dc.w  0,10
  3404.          dc.w  0,0
  3405.          dc.w  -10,0
  3406. BottomLeft:
  3407.          dc.w  0,0         ; place
  3408.          dc.b  31,0        ; pens
  3409.          dc.b  RP_COMPLEMENT
  3410.          dc.b  3           ; # of pairs
  3411.          dc.l  BottomLeftPairs ; the actual data
  3412.          dc.l  0
  3413. BottomLeftPairs:
  3414.          dc.w  0,-10
  3415.          dc.w  0,0
  3416.          dc.w  10,0
  3417. BottomRight:
  3418.          dc.w  0,0         ; place
  3419.          dc.b  31,0        ; pens
  3420.          dc.b  RP_COMPLEMENT
  3421.          dc.b  3           ; # of pairs
  3422.          dc.l  BottomRightPairs ; the actual data
  3423.          dc.l  0
  3424. BottomRightPairs:
  3425.          dc.w  0,-10
  3426.          dc.w  0,0
  3427.          dc.w  -10,0
  3428. LeftLeft:
  3429.          dc.w  0,0         ; place
  3430.          dc.b  31,0        ; pens
  3431.          dc.b  RP_COMPLEMENT
  3432.          dc.b  3           ; # of pairs
  3433.          dc.l  LeftLeftPairs ; the actual data
  3434.          dc.l  LeftVLine
  3435. LeftLeftPairs:
  3436.          dc.w  5,5
  3437.          dc.w  0,0
  3438.          dc.w  5,-5
  3439. LeftVLine:
  3440.          dc.w  0,0         ; place
  3441.          dc.b  31,0        ; pens
  3442.          dc.b  RP_COMPLEMENT
  3443.          dc.b  2           ; # of pairs
  3444.          dc.l  LeftVPairs  ; the actual data
  3445.          dc.l  0
  3446. LeftVPairs:
  3447.          dc.w  1,0
  3448.          dc.w  10,0
  3449. RightRight:
  3450.          dc.w  0,0         ; place
  3451.          dc.b  31,0        ; pens
  3452.          dc.b  RP_COMPLEMENT
  3453.          dc.b  3           ; # of pairs
  3454.          dc.l  RightRightPairs ; the actual data
  3455.          dc.l  RightVLine
  3456. RightRightPairs:
  3457.          dc.w  -5,5
  3458.          dc.w  0,0
  3459.          dc.w  -5,-5
  3460. RightVLine:
  3461.          dc.w  0,0         ; place
  3462.          dc.b  31,0        ; pens
  3463.          dc.b  RP_COMPLEMENT
  3464.          dc.b  2           ; # of pairs
  3465.          dc.l  RightVPairs  ; the actual data
  3466.          dc.l  0
  3467. RightVPairs:
  3468.          dc.w  -1,0
  3469.          dc.w  -10,0
  3470. UpUp:
  3471.          dc.w  0,0         ; place
  3472.          dc.b  31,0        ; pens
  3473.          dc.b  RP_COMPLEMENT
  3474.          dc.b  3           ; # of pairs
  3475.          dc.l  UpUpPairs   ; the actual data
  3476.          dc.l  UpHLine
  3477. UpUpPairs:
  3478.          dc.w  -5,5
  3479.          dc.w  0,0
  3480.          dc.w  5,5
  3481. UpHLine:
  3482.          dc.w  0,0         ; place
  3483.          dc.b  31,0        ; pens
  3484.          dc.b  RP_COMPLEMENT
  3485.          dc.b  2           ; # of pairs
  3486.          dc.l  UpHPairs    ; the actual data
  3487.          dc.l  0
  3488. UpHPairs:
  3489.          dc.w  0,1
  3490.          dc.w  0,10
  3491. DownDown:
  3492.          dc.w  0,0         ; place
  3493.          dc.b  31,0        ; pens
  3494.          dc.b  RP_COMPLEMENT
  3495.          dc.b  3           ; # of pairs
  3496.          dc.l  DownDownPairs ; the actual data
  3497.          dc.l  DownHLine
  3498. DownDownPairs:
  3499.          dc.w  -5,-5
  3500.          dc.w  0,0
  3501.          dc.w  5,-5
  3502. DownHLine:
  3503.          dc.w  0,0         ; place
  3504.          dc.b  31,0        ; pens
  3505.          dc.b  RP_COMPLEMENT
  3506.          dc.b  2           ; # of pairs
  3507.          dc.l  DownHPairs    ; the actual data
  3508.          dc.l  0
  3509. DownHPairs:
  3510.          dc.w  0,-1
  3511.          dc.w  0,-10
  3512. Coords:
  3513.          dc.b  1,2         ; pens
  3514.          dc.b  RP_JAM2,0      ; drawmode, (wordalign)
  3515.          dc.w  1,1         ; offsets
  3516.          dc.l  0           ; font (use default)
  3517.          dc.l  CoordText   ; the actual text
  3518.          dc.l  0           ; no more text
  3519.  
  3520. * These options are for CLI usage.
  3521. * Note: There are currently three synonyms in these options, namely
  3522. * -j# -j  -x# -x  -m# -m
  3523. * The presence of a number determines how they are interpreted.
  3524. * It is entirely safe to add new options here.
  3525.  
  3526. jumptable:
  3527.          dc.l  opt_x,opt_y,opt_m,opt_i
  3528.          dc.l  opt_l,opt_h,opt_a
  3529.          dc.l  opt_c,opt_w,opt_p
  3530.          dc.l  opt_g
  3531.          dc.l  opt_j
  3532.          dc.l  opt_s
  3533.  
  3534. options: dc.b  'XYMILHACWPGJS',0  ; These in UPPER CASE...
  3535.          ds.w  0
  3536.  
  3537. * And now for WB usage. The synonyms do no longer exists, so
  3538. * entry points are now slightly different.
  3539. * Also, flags lhacwpgx are entered from WB with a sinle FLAGS=
  3540. * tooltype.
  3541. * I try to organize my program in such a way that you may
  3542. * insert new entries here if you like.
  3543. WBjumptable
  3544.          dc.l  opt_x,opt_y,opt_m,opt_i,opt_jx,opt_jy
  3545.          dc.l  opt_flags,opt_s
  3546. WBoptions
  3547.          dc.b  'X',0
  3548.          dc.b  'Y',0
  3549.          dc.b  'M',0
  3550.          dc.b  'I',0
  3551.          dc.b  'JX',0
  3552.          dc.b  'JY',0
  3553.          dc.b  'FLAGS',0   ; LHA, CWP, XG, JM
  3554.          dc.b  'SAVE',0
  3555.          dc.b  0           ; This means end
  3556.          ds.w  0
  3557.  
  3558. ERROR_none     EQU   0
  3559. ERROR_nosignal EQU   1
  3560. ERROR_cmdline  EQU   2
  3561. ERROR_noscreen EQU   3
  3562. ERROR_nowindow EQU   4
  3563. ERROR_nomem    EQU   5
  3564. ERROR_noifflib EQU   6
  3565. ERROR_ifflib   EQU   7
  3566. ERROR_iconlib  EQU   8
  3567. ERROR_noicon   EQU   9
  3568. ERROR_tooltype EQU   10
  3569.  
  3570. errors:
  3571.          dc.l  msg_none,msg_nosignal,msg_cmdline,msg_noscreen,msg_nowindow
  3572.          dc.l  msg_nomem,msg_noifflib,msg_ifflib,msg_iconlib,msg_noicon
  3573.          dc.l  msg_tooltype
  3574.  
  3575. msg_none:      dc.b  0
  3576. msg_nosignal:  dc.b  ': Could not allocate signal bit',10,0
  3577. msg_cmdline:   dc.b  ': Error in command line options',10,0
  3578. msg_noscreen:  dc.b  ': Could not open screen',10,0
  3579. msg_nowindow:  dc.b  ': Could not open window',10,0
  3580. msg_nomem:     dc.b  ': Could not allocate memory',10,0
  3581. msg_noifflib:  dc.b  ': You need iff.library in your libs: directory'
  3582.                dc.b  ' to save pictures',10,0
  3583. msg_ifflib:    dc.b  ': iff.library returned error on save command',10,0
  3584. msg_iconlib    dc.b  ': Could not open icon.library',10,0
  3585. msg_noicon     dc.b  ': Could not check icon (for tool types)',10,0
  3586. msg_tooltype   dc.b  ': Error in tooltype options',10,0
  3587.  
  3588.  
  3589. XBuffer: dc.b  '+0.000000000',0
  3590. YBuffer: dc.b  '+0.000000000',0
  3591. MBuffer: dc.b  '00.00000',0
  3592. ZBuffer: dc.b  '+0.00000',0
  3593. IBuffer: dc.b  '00000',0
  3594. XLetter: dc.b  'x',0
  3595. YLetter: dc.b  'y',0
  3596. MLetter: dc.b  'M',0
  3597. ZLetter: dc.b  'Z',0
  3598. ILetter: dc.b  'i',0
  3599.  
  3600. ScreenTitle:
  3601.          dc.b  'MandelBrot',0
  3602.  
  3603. CoordText:
  3604.          dc.b  '+0.000000000 +0.000000000',0
  3605.  
  3606.  
  3607. _GfxLib        dc.b  'graphics.library',0
  3608. _IntuitionLib  dc.b  'intuition.library',0
  3609. _DosLib        dc.b  'dos.library',0
  3610. _IconLib       dc.b  'icon.library',0
  3611. _IffLib        dc.b  'iff.library',0
  3612. _TimerDev      dc.b  'timer.device',0
  3613.  
  3614. LongUsage:
  3615.    dc.b  10
  3616.    dc.b  'This program draws the Mandelbrot and Julia sets'
  3617.    dc.b                                       ' (z -> z² + c)',10
  3618.    dc.b  'using a smart contour-crawling method'
  3619.    dc.b                   ' and fast 32-bit fixed point math.',10
  3620.    dc.b  'Author: Hannu "the DM" Helminen',10
  3621.    dc.b  10
  3622.    dc.b  'Freely distributable version 1.00',10
  3623.    dc.b  10
  3624.    dc.b  ' z =  x +  y i is the centerpoint of the set',10
  3625.    dc.b  ' c = jx + jy i is a constant only for Julia sets',10
  3626.    dc.b  ' m is magnification, 5 - 29 (log scale)',10
  3627.    dc.b  ' i is the maximum number of iterations, i <= 65535',10
  3628.    dc.b  'Save pictures to filename by CTRL-S',10
  3629.    dc.b  10
  3630.    dc.b  'Flags: -l low    -h high  -a auto precision',10
  3631.    dc.b  '       -c crawl  -w walk  -p crawl if possible',10
  3632.    dc.b  '       -x exit   -g use GUI',10
  3633.    dc.b  '       -j julia  -m mandelbrot',10
  3634. ShortUsage:
  3635.    dc.b  10
  3636.    dc.b  'Usage: mandel  or  mandel ?',10
  3637.    dc.b  '   or  mandel '
  3638.    dc.b  '{-x',$1b,'[4mx',$1b,'[0m'
  3639.    dc.b  ' -y',$1b,'[4my',$1b,'[0m'
  3640.    dc.b  ' -m',$1b,'[4mm',$1b,'[0m'
  3641.    dc.b  ' -i',$1b,'[4mi',$1b,'[0m'
  3642.    dc.b  ' -l-h-a -c-w-p -x-g -j-m'
  3643.    dc.b  10,'              '
  3644.    dc.b  ' -jx',$1b,'[4mjx',$1b,'[0m'
  3645.    dc.b  ' -jy',$1b,'[4mjy',$1b,'[0m'
  3646.    dc.b  ' -s',$1b,'[4m<filename>',$1b,'[0m'
  3647.    dc.b  '}'
  3648.  
  3649.    dc.b  10
  3650. LongLen     EQU   *-LongUsage
  3651. ShortLen    EQU   *-ShortUsage
  3652.  
  3653. stdout_name
  3654.    dc.b  'con:0/50/640/100/ mandel  by DM  1990 ',0
  3655.  
  3656. NameBuffer  dc.b  'mandel.picture'
  3657. Null        dc.b  0
  3658.             ds.b  256      ; enough for any filename to be stored here.
  3659.  
  3660. NameEnd     dc.l  Null     ; pointer to end of string
  3661.  
  3662.  
  3663.  
  3664.    SECTION  images,DATA,CHIP
  3665. UParrow:
  3666.          dc.w  %0000010000000000
  3667.          dc.w  %0000101000000000
  3668.          dc.w  %0001000100000000
  3669.          dc.w  %0010000010000000
  3670.          dc.w  %0100000001000000
  3671.          dc.w  %1111111111100000
  3672.  
  3673.          dc.w  %0000000000000000
  3674.          dc.w  %0000010000000000
  3675.          dc.w  %0000111000000000
  3676.          dc.w  %0001111100000000
  3677.          dc.w  %0011111110000000
  3678.          dc.w  %0000000000000000
  3679. DOWNarrow:
  3680.          dc.w  %1111111111100000
  3681.          dc.w  %0100101001000000
  3682.          dc.w  %0010000010000000
  3683.          dc.w  %0001000100000000
  3684.          dc.w  %0000101000000000
  3685.          dc.w  %0000010000000000
  3686.  
  3687.          dc.w  %0000000000000000
  3688.          dc.w  %0011111110000000
  3689.          dc.w  %0001111100000000
  3690.          dc.w  %0000111000000000
  3691.          dc.w  %0000010000000000
  3692.          dc.w  %0000000000000000
  3693. LEFTarrow:
  3694.          dc.w  %0000010000000000
  3695.          dc.w  %0000110000000000
  3696.          dc.w  %0001010000000000
  3697.          dc.w  %0010010000000000
  3698.          dc.w  %0100010000000000
  3699.          dc.w  %1000010000000000
  3700.          dc.w  %0100010000000000
  3701.          dc.w  %0010010000000000
  3702.          dc.w  %0001010000000000
  3703.          dc.w  %0000110000000000
  3704.          dc.w  %0000010000000000
  3705.  
  3706.          dc.w  %0000000000000000
  3707.          dc.w  %0000000000000000
  3708.          dc.w  %0000100000000000
  3709.          dc.w  %0001100000000000
  3710.          dc.w  %0011100000000000
  3711.          dc.w  %0111100000000000
  3712.          dc.w  %0011100000000000
  3713.          dc.w  %0001100000000000
  3714.          dc.w  %0000100000000000
  3715.          dc.w  %0000000000000000
  3716.          dc.w  %0000000000000000
  3717. RIGHTarrow:
  3718.          dc.w  %1000000000000000
  3719.          dc.w  %1100000000000000
  3720.          dc.w  %1010000000000000
  3721.          dc.w  %1001000000000000
  3722.          dc.w  %1000100000000000
  3723.          dc.w  %1000010000000000
  3724.          dc.w  %1000100000000000
  3725.          dc.w  %1001000000000000
  3726.          dc.w  %1010000000000000
  3727.          dc.w  %1100000000000000
  3728.          dc.w  %1000000000000000
  3729.  
  3730.          dc.w  %0000000000000000
  3731.          dc.w  %0000000000000000
  3732.          dc.w  %0100000000000000
  3733.          dc.w  %0110000000000000
  3734.          dc.w  %0111000000000000
  3735.          dc.w  %0111100000000000
  3736.          dc.w  %0111000000000000
  3737.          dc.w  %0110000000000000
  3738.          dc.w  %0100000000000000
  3739.          dc.w  %0000000000000000
  3740.          dc.w  %0000000000000000
  3741.  
  3742. ZOOMpict:
  3743.          dc.w  %0000000000000000,%0000000000000000
  3744.          dc.w  %0000000000000000,%0000000000000000
  3745.          dc.w  %0000000000000000,%0000001111111100
  3746.          dc.w  %0111001000100101,%0000001000000100
  3747.          dc.w  %0001010101010111,%0000001001100100
  3748.          dc.w  %0010010101010101,%0000011110010100
  3749.          dc.w  %0100010101010101,%0000011110010100
  3750.          dc.w  %0111001000100101,%0000001001100100
  3751.          dc.w  %0000000000000000,%0000001000000100
  3752.          dc.w  %0000000000000000,%0000001111111100
  3753.          dc.w  %0000000000000000,%0000000000000000
  3754.          dc.w  %0000000000000000,%0000000000000000
  3755.  
  3756.          dc.w  %1111111111111111,%1111111111111111
  3757.          dc.w  %1111111111111111,%1111111111111111
  3758.          dc.w  %1111111111111111,%1111110000000011
  3759.          dc.w  %1000110111011010,%1111110000000011
  3760.          dc.w  %1110101010101000,%1111110000000011
  3761.          dc.w  %1101101010101010,%1111100000000011
  3762.          dc.w  %1011101010101010,%1111100000000011
  3763.          dc.w  %1000110111011010,%1111110000000011
  3764.          dc.w  %1111111111111111,%1111110000000011
  3765.          dc.w  %1111111111111111,%1111110000000011
  3766.          dc.w  %1111111111111111,%1111111111111111
  3767.          dc.w  %1111111111111111,%1111111111111111
  3768.  
  3769. DRAWpict:
  3770.          dc.w  %0000000000000000,%0000000000000000
  3771.          dc.w  %0000000000000000,%0000011111111100
  3772.          dc.w  %0000000000000000,%0000010000000100
  3773.          dc.w  %0110011001110101,%0111111010000100
  3774.          dc.w  %0101010101010101,%0100010000000100
  3775.          dc.w  %0101011001110101,%0100010010000100
  3776.          dc.w  %0101010101010111,%0100010000000100
  3777.          dc.w  %0110010101010101,%0100010010000100
  3778.          dc.w  %0000000000000000,%0100011111111100
  3779.          dc.w  %0000000000000000,%0100000010000000
  3780.          dc.w  %0000000000000000,%0111111110000000
  3781.          dc.w  %0000000000000000,%0000000000000000
  3782.  
  3783.          dc.w  %1111111111111111,%1111111111111111
  3784.          dc.w  %1111111111111111,%1111100000000011
  3785.          dc.w  %1111111111111111,%1111100000000011
  3786.          dc.w  %1001100110001010,%1000000000000011
  3787.          dc.w  %1010101010101010,%1000000000000011
  3788.          dc.w  %1010100110001010,%1000000000000011
  3789.          dc.w  %1010101010101000,%1000000000000011
  3790.          dc.w  %1001101010101010,%1000000000000011
  3791.          dc.w  %1111111111111111,%1000000000000011
  3792.          dc.w  %1111111111111111,%1000000001111111
  3793.          dc.w  %1111111111111111,%1000000001111111
  3794.          dc.w  %1111111111111111,%1111111111111111
  3795. RESETpict:
  3796.          dc.w  %0000000000000000,%0000000000000000
  3797.          dc.w  %0000000000000000,%0000000000000000
  3798.          dc.w  %0000000000000000,%0000001110011100
  3799.          dc.w  %0110011100110111,%0111001100001100
  3800.          dc.w  %0101010001000100,%0010001010010100
  3801.          dc.w  %0110011000100110,%0010000000000000
  3802.          dc.w  %0101010000010100,%0010000000000000
  3803.          dc.w  %0101011101100111,%0010001010010100
  3804.          dc.w  %0000000000000000,%0000001100001100
  3805.          dc.w  %0000000000000000,%0000001110011100
  3806.          dc.w  %0000000000000000,%0000000000000000
  3807.          dc.w  %0000000000000000,%0000000000000000
  3808.  
  3809.          dc.w  %1111111111111111,%1111111111111111
  3810.          dc.w  %1111111111111111,%1111111111111111
  3811.          dc.w  %1111111111111111,%1111110001100011
  3812.          dc.w  %1001100011001000,%1000110011110011
  3813.          dc.w  %1010101110111011,%1101110101101011
  3814.          dc.w  %1001100111011001,%1101111111111111
  3815.          dc.w  %1010101111101011,%1101111111111111
  3816.          dc.w  %1010100010011000,%1101110101101011
  3817.          dc.w  %1111111111111111,%1111110011110011
  3818.          dc.w  %1111111111111111,%1111110001100011
  3819.          dc.w  %1111111111111111,%1111111111111111
  3820.          dc.w  %1111111111111111,%1111111111111111
  3821.  
  3822. MANDELpict:
  3823.          dc.w  %0000000000000000,%0000000000000000
  3824.          dc.w  %0000000000000000,%0000000000000000
  3825.          dc.w  %0010101110110011,%0000000000000000
  3826.          dc.w  %0011101010101010,%1000000000000000
  3827.          dc.w  %0010101110101010,%1000000000000000
  3828.          dc.w  %0010101010101010,%1000000000000000
  3829.          dc.w  %0010101010101011,%0000000000000000
  3830.          dc.w  %0000000000000000,%0000000000000000
  3831.          dc.w  %0000000000000000,%0000000000000000
  3832.          dc.w  %0000000000000000,%0000000000000000
  3833.          dc.w  %0000000000000000,%0000000000000000
  3834.          dc.w  %0000000000010000,%0000000000000000
  3835.          dc.w  %0000000001101100,%0000000000000000
  3836.          dc.w  %0000000010000010,%0000000000000000
  3837.          dc.w  %0000011010000010,%0000000000000000
  3838.          dc.w  %0000100100000010,%0000000000000000
  3839.          dc.w  %0011100000000100,%0000000000000000
  3840.          dc.w  %0000100100000010,%0000000000000000
  3841.          dc.w  %0000011010000010,%0000000000000000
  3842.          dc.w  %0000000010000010,%0000000000000000
  3843.          dc.w  %0000000001101100,%0000000000000000
  3844.          dc.w  %0000000000010000,%0000000000000000
  3845.          dc.w  %0000000000000000,%0000000000000000
  3846.          dc.w  %0000000000000000,%0000000000000000
  3847.          dc.w  %0000000000000000,%0000000000000000
  3848.  
  3849.          dc.w  %1111111111111111,%1110000000000000
  3850.          dc.w  %1111111111111111,%1110000000000000
  3851.          dc.w  %1101010001001100,%1110000000000000
  3852.          dc.w  %1100010101010101,%0110000000000000
  3853.          dc.w  %1101010001010101,%0110000000000000
  3854.          dc.w  %1101010101010101,%0110000000000000
  3855.          dc.w  %1101010101010100,%1110000000000000
  3856.          dc.w  %1111111111111111,%1110000000000000
  3857.          dc.w  %1111111111111111,%1110000000000000
  3858.          dc.w  %1111111111111111,%1110000000000000
  3859.          dc.w  %1111111111111111,%1110000000000000
  3860.          dc.w  %1111111111101111,%1110000000000000
  3861.          dc.w  %1111111110010011,%1110000000000000
  3862.          dc.w  %1111111101111101,%1110000000000000
  3863.          dc.w  %1111100101111101,%1110000000000000
  3864.          dc.w  %1111011011111101,%1110000000000000
  3865.          dc.w  %1100011111111011,%1110000000000000
  3866.          dc.w  %1111011011111101,%1110000000000000
  3867.          dc.w  %1111100101111101,%1110000000000000
  3868.          dc.w  %1111111101111101,%1110000000000000
  3869.          dc.w  %1111111110010011,%1110000000000000
  3870.          dc.w  %1111111111101111,%1110000000000000
  3871.          dc.w  %1111111111111111,%1110000000000000
  3872.          dc.w  %1111111111111111,%1110000000000000
  3873.          dc.w  %1111111111111111,%1110000000000000
  3874.  
  3875. JULIApict:
  3876.          dc.w  %0000000000000000,%0000000000000000
  3877.          dc.w  %0000000000000000,%0000000000000000
  3878.          dc.w  %0001010101000101,%1100000000000000
  3879.          dc.w  %0001010101000101,%0100000000000000
  3880.          dc.w  %0001010101000101,%1100000000000000
  3881.          dc.w  %0101010101000101,%0100000000000000
  3882.          dc.w  %0111011101110101,%0100000000000000
  3883.          dc.w  %0000000000000000,%0000000000000000
  3884.          dc.w  %0000000000000000,%0000000000000000
  3885.          dc.w  %0000000000000000,%0000000000000000
  3886.          dc.w  %0000000000000000,%0000000000000000
  3887.          dc.w  %0000011110000000,%0000000000000000
  3888.          dc.w  %0000100001000000,%0000000000000000
  3889.          dc.w  %0001100000100000,%0000000000000000
  3890.          dc.w  %0000010000100000,%0000000000000000
  3891.          dc.w  %0000010000010000,%0000000000000000
  3892.          dc.w  %0000001000010000,%0000000000000000
  3893.          dc.w  %0000001000001000,%0000000000000000
  3894.          dc.w  %0000000100000110,%0000000000000000
  3895.          dc.w  %0000000010000100,%0000000000000000
  3896.          dc.w  %0000000001111000,%0000000000000000
  3897.          dc.w  %0000000000000000,%0000000000000000
  3898.          dc.w  %0000000000000000,%0000000000000000
  3899.          dc.w  %0000000000000000,%0000000000000000
  3900.          dc.w  %0000000000000000,%0000000000000000
  3901.  
  3902.          dc.w  %1111111111111111,%1110000000000000
  3903.          dc.w  %1111111111111111,%1110000000000000
  3904.          dc.w  %1110101010111010,%0010000000000000
  3905.          dc.w  %1110101010111010,%1010000000000000
  3906.          dc.w  %1110101010111010,%0010000000000000
  3907.          dc.w  %1010101010111010,%1010000000000000
  3908.          dc.w  %1000100010001010,%1010000000000000
  3909.          dc.w  %1111111111111111,%1110000000000000
  3910.          dc.w  %1111111111111111,%1110000000000000
  3911.          dc.w  %1111111111111111,%1110000000000000
  3912.          dc.w  %1111111111111111,%1110000000000000
  3913.          dc.w  %1111100001111111,%1110000000000000
  3914.          dc.w  %1111011110111111,%1110000000000000
  3915.          dc.w  %1110011111011111,%1110000000000000
  3916.          dc.w  %1111101111011111,%1110000000000000
  3917.          dc.w  %1111101111101111,%1110000000000000
  3918.          dc.w  %1111110111101111,%1110000000000000
  3919.          dc.w  %1111110111110111,%1110000000000000
  3920.          dc.w  %1111111011111001,%1110000000000000
  3921.          dc.w  %1111111101111011,%1110000000000000
  3922.          dc.w  %1111111110000111,%1110000000000000
  3923.          dc.w  %1111111111111111,%1110000000000000
  3924.          dc.w  %1111111111111111,%1110000000000000
  3925.          dc.w  %1111111111111111,%1110000000000000
  3926.          dc.w  %1111111111111111,%1110000000000000
  3927. QUITpict:
  3928.          dc.w  %0000000000000000,%0000000000000000,%0000000000000000
  3929.          dc.w  %0000000000000000,%0000000000000000,%0000000000000000
  3930.          dc.w  %0000000000000000,%0000000000001111,%1111000000000000
  3931.          dc.w  %0011101010101110,%0000000000001000,%0001000000000000
  3932.          dc.w  %0010101010100100,%0000000000001010,%0101000000000000
  3933.          dc.w  %0010101010100100,%0000000000001001,%1001000000000000
  3934.          dc.w  %0010101010100100,%0000000000001001,%1001000000000000
  3935.          dc.w  %0011101110100100,%0000000000001010,%0101000000000000
  3936.          dc.w  %0000100000000000,%0000000000001000,%0001000000000000
  3937.          dc.w  %0000000000000000,%0000000000001111,%1111000000000000
  3938.          dc.w  %0000000000000000,%0000000000000000,%0000000000000000
  3939.          dc.w  %0000000000000000,%0000000000000000,%0000000000000000
  3940.  
  3941.          dc.w  %1111111111111111,%1111111111111111,%1111111000000000
  3942.          dc.w  %1111111111111111,%1111111111111111,%1111111000000000
  3943.          dc.w  %1111111111111111,%1111111111110000,%0000111000000000
  3944.          dc.w  %1100010101010001,%1111111111110000,%0000111000000000
  3945.          dc.w  %1101010101011011,%1111111111110000,%0000111000000000
  3946.          dc.w  %1101010101011011,%1111111111110000,%0000111000000000
  3947.          dc.w  %1101010101011011,%1111111111110000,%0000111000000000
  3948.          dc.w  %1100010001011011,%1111111111110000,%0000111000000000
  3949.          dc.w  %1111011111111111,%1111111111110000,%0000111000000000
  3950.          dc.w  %1111111111111111,%1111111111110000,%0000111000000000
  3951.          dc.w  %1111111111111111,%1111111111111111,%1111111000000000
  3952.          dc.w  %1111111111111111,%1111111111111111,%1111111000000000
  3953.  
  3954.    SECTION  pointers,BSS
  3955.  
  3956. * Nimi:                  Ja se on:
  3957.  
  3958. _GfxBase       ds.l  1
  3959. _IntuitionBase ds.l  1
  3960. _DosBase       ds.l  1
  3961. _ExecBase      EQU   $4
  3962. _TimerBase     ds.l  1
  3963.  
  3964. MyScreen:   ds.l  1  ; screen structure
  3965. MyWindow1:  ds.l  1  ; window
  3966. MyWindow2:  ds.l  1  ; another window, non-zero if valid
  3967. UseReq:     ds.l  1  ; timer iOreq, non-zero if request pending
  3968. Mem1:       ds.l  1  ; TmpRas bitmap pointer
  3969. Mem2:       ds.l  1  ; mem for AreaInfo table
  3970. WBmessage:  ds.l  1  ; Workbench startup message (null if from CLI)
  3971. MyName:     ds.l  1  ; self-explanatory
  3972.  
  3973. OldSecs:    ds.l  1  ; to test double-click
  3974. OldMicros:  ds.l  1  ; -"-
  3975. Magnify:    ds.l  1  ; temp storages for: magnification
  3976. OldMagnify: ds.l  1  ;
  3977. CurrentX:   ds.l  1  ; x-coordinate
  3978. CurrentY:   ds.l  1  ; y-coordinate
  3979. Zoom:       ds.l  1  ; zooming
  3980. Counter:    ds.w  1  ; identify each save-file with a number
  3981. MyNameLen:  ds.w  1  ; works with MyName above
  3982.  
  3983.  
  3984. * Some stuff to make RemoveGrid easier
  3985. centerx     ds.w  1
  3986. centery     ds.w  1
  3987. lowx        ds.w  1
  3988. lowy        ds.w  1
  3989. highx       ds.w  1
  3990. highy       ds.w  1
  3991. pic_c       ds.l  1
  3992. pic_tl      ds.l  1
  3993. pic_tr      ds.l  1
  3994. pic_bl      ds.l  1
  3995. pic_br      ds.l  1
  3996.  
  3997. prex        ds.l  1
  3998. prey        ds.l  1
  3999.  
  4000. * We seem to need MANY temporary buffers for x/y coordinates.
  4001. * This one for RightButton.
  4002. tmpx        ds.w  1
  4003. tmpy        ds.w  1
  4004.  
  4005. * Huh! My very own structure.
  4006. MyMandelBrot:
  4007.             ds.b  mb_SIZEOF
  4008. MyTmpRas:   ds.b  tr_SIZEOF
  4009. MyAreaInfo: ds.b  ai_SIZEOF
  4010. IOreq:      ds.b  IOTV_SIZE
  4011. MsgPort:    ds.b  MP_SIZE
  4012.  
  4013. inter:      ds.b  1     ; Boolean: are we interactive
  4014. error:      ds.b  1     ; general error code
  4015. method:     ds.b  1     ; method of zooming (ZOOM, REDRAW or RESET)
  4016. isdrawn:    dc.b  1     ; Boolean: is grid drawn?
  4017. saveit:     dc.b  1     ; Boolean: do we have to save picture?
  4018.          end
  4019.  
  4020.