home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 4 / FreshFish_May-June1994.bin / new / amigalibdisks / d984 / icontoclip / icontoclip.s < prev    next >
Text File  |  1994-04-04  |  23KB  |  1,196 lines

  1. ***************************************************
  2. * IconToClip                                      *
  3. *    by Douglas Nelson                            *
  4. *                                                 *
  5. * Assemble with Macro68                           *
  6. *                                                 *
  7. * Object size = 3598 ($0E0E) bytes                *
  8. * Output file size = 4052 bytes                   *
  9. *                                                 *
  10. ***************************************************
  11.  
  12.     strict
  13.     default    _absolute,_pcrel
  14.     exeobj
  15.     errfile    ram:assem.output
  16.     objfile    ram:I2C.exe
  17.     listfile    ram:listfile
  18.     incpath    mac:includes
  19.     incpath    ram:includes
  20.     macfile    alllibraryoffsets.i
  21.     macfile    dos/dosextens.i
  22.     macfile    exec/alerts.i
  23.     macfile    exec/ports.i
  24.     macfile    intuition/intuition.i
  25.     macfile    libraries/iffparse.i
  26.     macfile    libraries/gadtools.i
  27.     macfile    workbench/workbench.i
  28.     macfile    workbench/startup.i
  29.  
  30. ***** startup
  31.     move.l    sp,(initialSP)
  32.     move.l    d0,d7    ;store dosCmdLen
  33.     movea.l    (4).w,a6
  34.     move.l    a6,(execbase)
  35.  
  36. * open dos
  37.     lea    dosname,a1
  38.     move.l    #37,d0
  39.     jsr    (_LVOOpenLibrary,a6)
  40.     move.l    d0,(dosbase)
  41.     bne.b    gotdos
  42.     move.l    #AG_OpenLib!AO_DOSLib,d7
  43.     jsr    (_LVOAlert,a6)
  44. failexit    tst.l    d7
  45.     bne.b    fail2
  46.     bsr.b    getWbMsg
  47.     bsr.b    replyWbMsg
  48. fail2    moveq    #20,d0    ;FAIL
  49.     rts
  50.  
  51. exit    movea.l    (execbase),a6
  52.     movea.l    (dosbase),a1
  53.     jsr    (_LVOCloseLibrary,a6)
  54.     tst.l    (WBenchMsg)
  55.     beq.b    exit2
  56.     bsr.b    replyWbMsg
  57. exit2    move.l    (rc),d0
  58.     movea.l    (initialSP),sp
  59.     rts
  60.  
  61. * the next two subroutines here appear to allow byte branches
  62.  
  63. replyWbMsg    movea.l    (execbase),a6
  64.     jsr    (_LVOForbid,a6)
  65.     movea.l    (WBenchMsg),a1
  66.     jsr    (_LVOReplyMsg,a6)
  67.     rts
  68.  
  69. getWbMsg    suba.l    a1,a1
  70.     jsr    (_LVOFindTask,a6)
  71.     movea.l    d0,a5
  72.     lea    (pr_MsgPort,a5),a0
  73.     jsr    (_LVOWaitPort,a6)
  74.     lea    (pr_MsgPort,a5),a0
  75.     jsr    (_LVOGetMsg,a6)
  76.     move.l    d0,(WBenchMsg)
  77.     rts
  78.  
  79. gotdos    move.l    #10,(rc)    ;ERROR for early exit
  80.     tst.l    d7    ;dosCmdLen
  81.     beq.b    WBstart
  82.  
  83. * read command line
  84.     lea    template,a0
  85.     move.l    a0,d1
  86.     lea    pathname,a0
  87.     move.l    a0,d2
  88.     moveq    #0,d3    ;no optional RdArgs
  89.     movea.l    (dosbase),a6
  90.     jsr    (_LVOReadArgs,a6)
  91.     move.l    d0,d1
  92.     jsr    (_LVOFreeArgs,a6)
  93.  
  94.     bra    main
  95.  
  96. WBstart
  97.     bsr.b    getWbMsg
  98. * read WBArgs
  99.     movea.l    d0,a2
  100.     movea.l    (sm_ArgList,a2),a2
  101.     move.l    (wa_Lock,a2),d1
  102.     movea.l    (dosbase),a6
  103.     jsr    (_LVOCurrentDir,a6)
  104.     move.l    d0,d7    ;store old dir
  105.  
  106. * open icon.library
  107.     lea    iconname,a1
  108.     move.l    #37,d0
  109.     movea.l    (execbase),a6
  110.     jsr    (_LVOOpenLibrary,a6)
  111.     move.l    d0,(iconbase)
  112.     beq.b    endicon
  113.  
  114. *read ToolTypes
  115.     movea.l    d0,a6
  116.     movea.l    (wa_Name,a2),a0
  117.     jsr    (_LVOGetDiskObject,a6)
  118.     tst.l    d0
  119.     beq.b    closeicon
  120.     movea.l    d0,a2
  121.     movea.l    (do_ToolTypes,a2),a0
  122.     lea    pathnamename,a1
  123.     jsr    (_LVOFindToolType,a6)
  124.     tst.l    d0
  125.     beq.b    checkcolumn
  126.     moveq    #1,d0
  127.     move.l    d0,(pathname)
  128.  
  129. checkcolumn    movea.l    (do_ToolTypes,a2),a0
  130.     lea    columnname,a1
  131.     jsr    (_LVOFindToolType,a6)
  132.     tst.l    d0
  133.     beq.b    checkwindow
  134.     moveq    #1,d0
  135.     move.l    d0,(column)
  136.  
  137. checkwindow    movea.l    (do_ToolTypes,a2),a0
  138.     lea    windowname,a1
  139.     jsr    (_LVOFindToolType,a6)
  140.     tst.l    d0
  141.     beq.b    freediskobj
  142.     moveq    #1,d0
  143.     move.l    d0,(window)
  144.  
  145. freediskobj
  146.     movea.l    (iconbase),a6
  147.     movea.l    a2,a0
  148.     jsr    (_LVOFreeDiskObject,a6)
  149.  
  150. closeicon    movea.l    (iconbase),a1
  151.     movea.l    (execbase),a6
  152.     jsr    (_LVOCloseLibrary,a6)
  153.  
  154. * restore old dir
  155. endicon    move.l    d7,d1
  156.     movea.l    (dosbase),a6
  157.     jsr    (_LVOCurrentDir,a6)
  158.  
  159.  
  160. ***** main program
  161. main    movea.l    (execbase),a6
  162.  
  163.     lea    workbenchname,a1    ;open workbench
  164.     moveq    #37,d0
  165.     jsr    (_LVOOpenLibrary,a6)
  166.     move.l    d0,(workbenchbase)
  167.     beq    cleanup
  168.     lea    intuitionname,a1    ;open intuition
  169.     moveq    #37,d0
  170.     jsr    (_LVOOpenLibrary,a6)
  171.     move.l    d0,(intuibase)
  172.     beq    cleanup
  173.     lea    iffparsename,a1    ;open iffparse
  174.     moveq    #37,d0
  175.     jsr    (_LVOOpenLibrary,a6)
  176.     move.l    d0,(iffparsebase)
  177.     beq    cleanup
  178.     lea    gadtoolsname,a1    ;open gadtools
  179.     moveq    #37,d0
  180.     jsr    (_LVOOpenLibrary,a6)
  181.     move.l    d0,(gadtoolsbase)
  182.     beq    cleanup
  183.     lea    diskfontname,a1    ;open diskfont
  184.     moveq    #37,d0
  185.     jsr    (_LVOOpenLibrary,a6)
  186.     move.l    d0,(diskfontbase)
  187.     beq    cleanup
  188.     lea    graphicsname,a1    ;open gfx
  189.     moveq    #37,d0
  190.     jsr    (_LVOOpenLibrary,a6)
  191.     move.l    d0,(gfxbase)
  192.     beq    cleanup
  193.  
  194. * create our two MsgPorts
  195.     movea.l    (execbase),a6
  196.     jsr    (_LVOCreateMsgPort,a6)
  197.     move.l    d0,(WorkbenchMP)
  198.     beq    cleanup
  199.     jsr    (_LVOCreateMsgPort,a6)
  200.     move.l    d0,(WindowMP)
  201.     beq    cleanup
  202.  
  203. * add item to Tools menu
  204.     moveq    #1,d0
  205.     moveq    #0,d1
  206.     lea    menuname,a0
  207.     movea.l    (WorkbenchMP),a1
  208.     suba.l    a2,a2
  209.     movea.l    (workbenchbase),a6
  210.     jsr    (_LVOAddAppMenuItemA,a6)
  211.     move.l    d0,(appmenuitem)
  212.     beq    cleanup
  213.  
  214. * cleared all obstacles, so set return code to success
  215.     moveq    #0,d0
  216.     move.l    d0,(rc)
  217.  
  218. * store signal masks
  219.     movea.l    (WindowMP),a0
  220.     moveq    #0,d1
  221.     move.b    (MP_SIGBIT,a0),d1
  222.     moveq    #1,d0
  223.     lsl.l    d1,d0
  224.     move.l    d0,(windowsignal)
  225.  
  226.     movea.l    (WorkbenchMP),a0
  227.     moveq    #0,d1
  228.     move.b    (MP_SIGBIT,a0),d1
  229.     moveq    #1,d0
  230.     lsl.l    d1,d0
  231.     move.l    d0,(wbsignal)
  232.  
  233. * calculate union of all signal masks
  234.     or.l    (windowsignal),d0
  235.     or.l    (breaksignal),d0
  236.     move.l    d0,(allsignals)
  237.  
  238. * open window if user specifies
  239.     tst.l    (window)    ;did user ask for window?
  240.     beq.b    eventloop
  241.     bsr    SetupScreen
  242.     tst.l    d0
  243.     beq.b    nowinbeep
  244.     bsr    OpenI2CWindow
  245.     tst.l    d0
  246.     bne.b    eventloop
  247. nowinbeep    movea.l    (intuibase),a6
  248. *    moveq    #0,d0    ;d0 is zero anyway
  249.     jsr    (_LVODisplayBeep,a6)    ;warn that window is not available
  250.  
  251. eventloop    move.l    (allsignals),d0
  252.     movea.l    (execbase),a6
  253.     jsr    (_LVOWait,a6)
  254.     move.l    d0,d7    ;store signal mask
  255.  
  256. * is signal from WorkbenchMP?
  257.     move.l    (wbsignal),d0
  258.     and.l    d7,d0
  259.     beq.b    testwindowsignal
  260.             bsr    HandleAppMsg
  261.  
  262. * is signal from WindowMP?
  263. testwindowsignal
  264.     move.l    (windowsignal),d0
  265.     and.l    d7,d0
  266.     beq.b    testbreaksignal
  267.     bsr    HandleGadget
  268.     tst.l    d0
  269.     beq.b    cleanup    ;user selected QUIT gadget
  270.  
  271. * is signal a CTRL-C?
  272. testbreaksignal
  273.     move.l    (breaksignal),d0
  274.     and.l    d7,d0
  275.     bne.b    cleanup    ;got BREAK signal
  276.  
  277.     bra    eventloop    ;wait for next event
  278.  
  279. * prepare to quit
  280. cleanup    tst.l    (appmenuitem)
  281.     beq    closewindow
  282.  
  283. * clear pending AppMsgs
  284. clearappmsg    movea.l    (WorkbenchMP),a0
  285.     movea.l    (execbase),a6
  286.     jsr    (_LVOGetMsg,a6)
  287.     tst.l    d0    ;did we get a message?
  288.     beq.b    killappmenu
  289.     movea.l    d0,a1
  290.     jsr    (_LVOReplyMsg,a6)
  291.     bra.b    clearappmsg
  292.  
  293.  
  294. * remove Tools menu item; safe to call with NULL pointer
  295. killappmenu    movea.l    (appmenuitem),a0
  296.     movea.l    (workbenchbase),a6
  297.     jsr    (_LVORemoveAppMenuItem,a6)
  298.  
  299. * close window if open
  300. closewindow    bsr    CloseI2CWindow
  301.     bsr    CloseDownScreen
  302.  
  303. * close MsgPorts
  304.     movea.l    (execbase),a6
  305.     move.l    (WindowMP),d0
  306.     beq.b    closeWorkbenchMP
  307.     movea.l    d0,a0
  308.     jsr    (_LVODeleteMsgPort,a6)
  309.  
  310. closeWorkbenchMP
  311.     move.l    (WorkbenchMP),d0
  312.     beq.b    closelibs
  313.     movea.l    d0,a0
  314.     jsr    (_LVODeleteMsgPort,a6)
  315.  
  316. closelibs    move.l    (gfxbase),d0
  317.     beq.b    closediskfont
  318.     movea.l    d0,a1
  319.     jsr    (_LVOCloseLibrary,a6)
  320.  
  321. closediskfont
  322.     move.l    (diskfontbase),d0
  323.     beq.b    closegadtools
  324.     movea.l    d0,a1
  325.     jsr    (_LVOCloseLibrary,a6)
  326.  
  327. closegadtools
  328.     move.l    (gadtoolsbase),d0
  329.     beq.b    closeiffparse
  330.     movea.l    d0,a1
  331.     jsr    (_LVOCloseLibrary,a6)
  332.  
  333. closeiffparse
  334.     move.l    (iffparsebase),d0
  335.     beq.b    closeintui
  336.     movea.l    d0,a1
  337.     jsr    (_LVOCloseLibrary,a6)
  338.  
  339. closeintui    move.l    (intuibase),d0
  340.     beq.b    closeworkbench
  341.     movea.l    d0,a1
  342.     jsr    (_LVOCloseLibrary,a6)
  343.  
  344. closeworkbench
  345.     move.l    (workbenchbase),d0
  346.     beq.b    allclosed
  347.     movea.l    d0,a1
  348.     jsr    (_LVOCloseLibrary,a6)
  349.  
  350. allclosed
  351.     bra    exit
  352.  
  353.  
  354.  
  355. ***** subroutine HandleAppMsg
  356. * returns NULL in d0 if anything fails
  357. HandleAppMsg
  358.     movea.l    (WorkbenchMP),a0
  359.     movea.l    (execbase),a6
  360.     jsr    (_LVOGetMsg,a6)
  361.     move.l    d0,(appmsg)
  362.     beq    endHandleAppMsg
  363.  
  364.     sf    (separate)    ;first name, so no separator
  365.     movea.l    d0,a0
  366.     move.l    (am_ArgList,a0),(arglist)
  367.     move.l    (am_NumArgs,a0),(numargs)
  368.     bne    IconIsHilited
  369.  
  370. * user selected menu with no icons hilited, so open window
  371.     move.l    (I2CWnd),d0
  372.     beq.b    openwindow
  373.  
  374. * window is open so move it to front
  375.     movea.l    d0,a0
  376.     movea.l    (intuibase),a6
  377.     jsr    (_LVOWindowToFront,a6)
  378.     bra    NextAppMsg
  379.  
  380. * must call SetupScreen() each time before opening window, since sneaky user
  381. * may have changed Workbench screen
  382.  
  383. openwindow    bsr    SetupScreen
  384.     tst.l    d0
  385.     beq.b    nowindow
  386.     bsr    OpenI2CWindow
  387.     tst.l    d0
  388.     bne    NextAppMsg    ;window opened successfully
  389.  
  390. nowindow    movea.l    (intuibase),a6
  391. *    moveq    #0,d0    ;d0 is zero anyway
  392.     jsr    (_LVODisplayBeep,a6)      ;warn that window is not available
  393.     bra    NextAppMsg
  394.  
  395.  
  396. IconIsHilited
  397.     tst.l    (column)
  398.     beq.b    lineformat
  399.     move.b    #$A,(separator)    ;separate names with linefeed
  400.     bra.b    tryInitClip
  401.  
  402. lineformat    move.b    #' ',(separator)    ;separate names with space
  403.  
  404.  
  405. tryInitClip    bsr    Init