home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 16 / amigaformatcd16.iso / -readerstuff- / mike_archer / multimenu / source.lzx / MultiMenu.s
Encoding:
Text File  |  1995-09-04  |  24.0 KB  |  1,110 lines

  1.  
  2. ;   This source code is provided for reference only, do not use it to make
  3. ; your own unauthorised versions of MultiMenu. Doing so is a breach of my
  4. ; copyright. If I see unauthorised versions of any of my programs I will
  5. ; stop providing the source code with them. So Don't spoil it for others!
  6.  
  7.  
  8. ;*********************************
  9. ;**** Necessary Start Up Bits ****
  10. ;*********************************
  11.  
  12.     ;Clear the BSS data to Zero
  13.         LEA.L    BssPtr,A1
  14.         MOVE.L    #BssLen-1,D1
  15. ClearLoop:    CLR.L    (A1)+
  16.         DBNE    D1,ClearLoop
  17.  
  18.     ;Store away the CLI parameter pointers
  19.         MOVE.L    A0,ParmPtr
  20.         MOVE.L    D0,ParmLen
  21.  
  22.     ;Find this Task
  23.         MOVE.L    4,A6
  24.         SUB.L    A1,A1
  25.         JSR    _LVOFindTask(A6)
  26.         MOVE.L    D0,TaskPtr
  27.         
  28.     ;Create "SpecialID" string for Batch file
  29.     ;  This is based on the task address, If two copies of MultiMenu
  30.     ;  are running simultaneously they will be at different addresses
  31.     ;  so will create their own unique MM_Batch file.
  32.         MOVE.L    D0,D2
  33.         MOVE.L    D2,D1
  34.         AND.L    #7,D1
  35.         ADD.B    D1,SpecialID
  36.  
  37.         ASR.L    #3,D2
  38.         MOVE.L    D2,D1
  39.         AND.L    #7,D1
  40.         ADD.B    D1,SpecialID+1 
  41.  
  42.         ASR.L    #3,D2
  43.         MOVE.L    D2,D1
  44.         AND.L    #7,D1
  45.         ADD.B    D1,SpecialID+2
  46.         
  47.         ASR.L    #3,D2
  48.         MOVE.L    D2,D1
  49.         AND.L    #7,D1
  50.         ADD.B    D1,SpecialID+3
  51.         
  52.     ;Store to Current Directory Lock
  53.         MOVE.L    D0,A4
  54.         MOVE.L    pr_CurrentDir(A4),OldDirectory
  55.  
  56.     ;Test if run from CLI or Workbench
  57.         TST.L    pr_CLI(A4)
  58.         BNE    FromCLI
  59.         
  60.     ;Get the message from Workbench
  61.         LEA    pr_MsgPort(A4),A0
  62.         JSR    _LVOWaitPort(a6)
  63.         JSR    _LVOGetMsg(A6)
  64.         MOVE.L    D0,Message
  65. FromCLI:        
  66.  
  67. ;***************************************
  68. ;**** Open all the libraries needed ****
  69. ;***************************************
  70.  
  71.     ;Open the Dos Library
  72.         MOVE.L    4,A6
  73.         LEA    DosLibName,A1
  74.         CLR.L    D0
  75.         JSR    _LVOOpenLibrary(A6)
  76.         MOVE.L    D0,DosBase
  77.         BEQ    ExitQuick
  78.         
  79.     ;Open the Intuition library
  80.         MOVE.L    4,A6
  81.         LEA    IntLibName,A1
  82.         CLR.L    D0
  83.         JSR    _LVOOpenLibrary(A6)
  84.         MOVE.L    D0,IntBase
  85.         BEQ    ExitQuick
  86.         
  87.     ;Open the Graphics library
  88.         MOVE.L    4,A6
  89.         LEA    GfxLibName,A1
  90.         CLR.L    D0
  91.         JSR    _LVOOpenLibrary(A6)
  92.         MOVE.L    D0,GrxBase
  93.         BEQ    ExitQuick
  94.         
  95.     ;Open the Icon library
  96.         MOVE.L    4,A6
  97.         LEA    IconLibName,A1
  98.         CLR.L    D0
  99.         JSR    _LVOOpenLibrary(A6)
  100.         MOVE.L    D0,IconBase
  101.         BEQ    ExitQuick
  102.         
  103. ;**********************************
  104. ;**** Interpret the parameters ****
  105. ;**********************************
  106.  
  107.     ;Test if run from Workbench or CLI
  108.         TST.L    Message
  109.         BEQ    GetCliArgs
  110.     
  111.     ;Get the Workbench arguments
  112.         MOVE.L    Message,A0
  113.         MOVE.L    $24(A0),A0
  114.         MOVE.L    8(A0),DirectoryLock
  115.         BEQ    NoProjFile
  116.         MOVE.L    12(A0),FileNamePtr
  117.         BNE    SkipCliArgs
  118.  
  119.     ;No Project File so use "default" file
  120. NoProjFile:    CLR.L    DirectoryLock
  121.         JSR    UseDefaultName
  122.         BRA    SkipCliArgs
  123.  
  124.     ;Test which version of Dos we are using.        
  125. GetCliArgs:    MOVE.L    DosBase,A0
  126.         CMP.W    #37,20(A0)
  127.         BLO    GetOldDosArgs
  128.         
  129.     ;Using New Dos we should parse command line properly
  130.         MOVE.L    DosBase,A6
  131.         MOVE.L    #ArgTemplate,D1
  132.         MOVE.L    #ArgArray,D2
  133.         MOVE.L    #0,D3
  134.         JSR    _LVOReadArgs(A6)
  135.         MOVE.L    D0,RdArgs
  136.         BEQ    ArgsError        
  137.  
  138.     ;Get the filename
  139.         MOVE.L    ArgArray,D0
  140.         BEQ    NoArgGiven
  141.         MOVE.L    D0,FileNamePtr
  142.         BRA    SkipCliArgs
  143.         
  144.     ;No argument given so set to "default" file name.
  145. NoArgGiven:    JSR    UseDefaultName
  146.         BRA    SkipCliArgs
  147.  
  148.     ;For Old Dos the whole argument list is treated as the filename!
  149.     ;We must ensure that it is NULL terminated though.
  150. GetOldDosArgs:    MOVE.L    ParmPtr,A0
  151.         ADD.L    ParmLen,A0
  152.         SUB.L    #1,A0
  153. StripLoop:    SUB.L    #1,A0
  154.         CMP.B    #' ',(A0)
  155.         BEQ    StripLoop
  156.         MOVE.B    #0,1(A0)
  157.         MOVE.L    ParmPtr,A0
  158.         MOVE.L    A0,FileNamePtr
  159.  
  160.     ;If no parameter set to "default" filename
  161.         TST.B    (A0)
  162.         BNE    SkipCliArgs
  163.         JSR    UseDefaultName
  164.         
  165. SkipCliArgs:
  166.     ;Test if a directory lock exists
  167.         TST.L    DirectoryLock
  168.         BNE    SkipDefaultDir
  169.         
  170.     ;No so get one on the default directory
  171. TryAgain:    MOVE.L    DosBase,A6
  172.         MOVE.L    #DefaultPath,D1
  173.         MOVE.L    #ACCESS_READ,D2
  174.         JSR    _LVOLock(A6)
  175.         MOVE.L    D0,DirectoryLock
  176.         BNE    SkipDefaultDir
  177.         
  178.     ;Failed to find default path so use the current directory
  179.         CLR.L    DirectoryLock
  180.         BRA    SkipChangeDir
  181.  
  182.     ;Change to the directory    
  183. SkipDefaultDir:    MOVE.L    DosBase,A6
  184.         MOVE.L    DirectoryLock,D1
  185.         JSR    _LVOCurrentDir(a6)
  186.  
  187.     ;Get a LOCK on the filename
  188. SkipChangeDir:    MOVE.L    DosBase,A6
  189.         MOVE.L    FileNamePtr,D1
  190.         MOVE.L    #ACCESS_READ,D2
  191.         JSR    _LVOLock(A6)
  192.         MOVE.L    D0,FileLock
  193.         BNE    GotLock
  194.  
  195.     ;We Couldn't Get a lock, are we using "default" ?
  196.         CMP.L    #DefaultName,FileNamePtr
  197.         BEQ    FailedToOpen
  198.         
  199.     ;OK try to get "DEFAULT" instead
  200.         MOVE.L    #DefaultName,FileNamePtr
  201.         BRA    TryAgain
  202.     
  203.     ;Examine the file
  204. GotLock:    MOVE.L    DosBase,A6
  205.         MOVE.L    FileLock,D1
  206.         MOVE.L    #InfoBlock,D2
  207.         JSR    _LVOExamine(A6)
  208.         
  209.     ;Get the file length
  210.         MOVE.L    InfoBlock+fib_Size,FileSize
  211.  
  212.     ;Release the Lock on the file
  213.         MOVE.L    DosBase,A6
  214.         MOVE.L    FileLock,D1
  215.         JSR    _LVOUnLock(A6)
  216.     
  217.     ;Attempt to Allocate Memory
  218.         MOVE.L    4,A6
  219.         MOVE.L    FileSize,D0
  220.         ADD.L    #3,D0
  221.         MOVE.L    #MEMF_PUBLIC,D1
  222.         JSR    _LVOAllocMem(A6)
  223.         MOVE.L    D0,MemPtr
  224.         BEQ    FileTooBig
  225.         
  226.     ;Open the File for reading
  227.         MOVE.L    DosBase,A6
  228.         MOVE.L    FileNamePtr,D1
  229.         MOVE.L    #1005,D2
  230.         JSR    _LVOOpen(A6)
  231.         MOVE.L    D0,Handle
  232.         BEQ    FailedToOpen
  233.         
  234.     ;Read the file into the allocated memory
  235.         MOVE.L    DosBase,A6
  236.         MOVE.L    Handle,D1
  237.         MOVE.L    MemPtr,D2
  238.         MOVE.L    FileSize,D3
  239.         JSR    _LVORead(A6)
  240.  
  241.     ;Close the filename
  242.         MOVE.L    DosBase,A6
  243.         MOVE.L    Handle,D1
  244.         JSR    _LVOClose(A6)
  245.  
  246.     ;Check if the very first character is '#'
  247.         MOVE.L    MemPtr,A0
  248.         CMP.B    #'#',(A0)
  249.         BEQ    FileWasEmpty
  250.  
  251.     ;Ensure the last 3 bytes of file are 10,'#',10
  252.         ADD.L    FileSize,A0
  253.         MOVE.B    #10,(A0)+
  254.         MOVE.B    #'#',(A0)+
  255.         MOVE.B    #10,(A0)+
  256.  
  257.     ;Open a screen to put the menu on
  258.         MOVE.L    IntBase,A6
  259.         LEA    NewScreenDef,A0
  260.         JSR    _LVOOpenScreen(A6)
  261.         MOVE.L    D0,ScreenBase
  262.         BEQ    FailedScreen
  263.  
  264.     ;Open a window to put the menu on
  265.         MOVE.L    IntBase,A6
  266.         LEA    NewWindowDef,A0
  267.         JSR    _LVOOpenWindow(A6)
  268.         MOVE.L    D0,WindowBase
  269.         BEQ    FailedWindow
  270.  
  271.     ;Store away the RastPort address for the Window
  272.         MOVE.L    WindowBase,A0
  273.         MOVE.L    50(A0),RastBase
  274.         
  275.     ;Add a menu to the window
  276.         MOVE.L    WindowBase,A0
  277.         LEA    MenuDef,A1
  278.         JSR    _LVOSetMenuStrip(A6)
  279.  
  280.     ;Initialise Values for Printing Routine
  281.         MOVE.L    #8,Y_Pos
  282.         MOVE.L    MemPtr,TextPtr
  283.         
  284.     ;Set the A Pen colour
  285.         MOVE.L    GrxBase,A6
  286.         MOVE.L    RastBase,A1
  287.         MOVE.L    #1,D0
  288.         JSR    _LVOSetAPen(A6)
  289.         
  290.     ;Position the Gfx Cursor    
  291. PrintLoop:    MOVE.L    GrxBase,A6
  292.         MOVE.L    #0,D0
  293.         MOVE.L    Y_Pos,D1
  294.         MOVE.L    RastBase,A1
  295.           JSR    _LVOMove(A6)
  296.  
  297.     ;Increase the Y Position
  298.         ADD.L    #8,Y_Pos
  299.         
  300.     ;Calculate the Text Length
  301.         MOVE.L    TextPtr,A0
  302. CalcLoop:    CMP.B    #$A,(A0)+
  303.         BNE    CalcLoop
  304.         MOVE.L    A0,D0
  305.         SUB.L    TextPtr,D0
  306.         MOVE.L    D0,TextLen
  307.  
  308.     ;Only write the text if Y_Pos < 260
  309.         CMP.L    #264,Y_Pos
  310.         BGT    SkipTextWrite
  311.         
  312.     ;Write the text
  313.         MOVE.L    GrxBase,A6
  314.         MOVE.L    RastBase,A1
  315.         MOVE.L    TextPtr,A0
  316.         MOVE.L    TextLen,D0
  317.         SUB.L    #1,D0        ;Don't write the LF
  318.         CMP.L    #80,D0
  319.         BLE    LineLengthOK
  320.         MOVE.L    #80,D0        ;Only write 80 chars max.
  321. LineLengthOK:    JSR    _LVOText(A6)
  322.  
  323.     ;Calculate the new text pointer * Loop if needed
  324. SkipTextWrite:    MOVE.L    TextPtr,A0
  325.         ADD.L    TextLen,A0
  326.         MOVE.L    A0,TextPtr
  327.         CMP.B    #'#',(A0)
  328.         BNE    PrintLoop
  329.         
  330.     ;Set all the values in ValidKeys array for the keys to scan
  331.         LEA    ValidKeys,A1
  332.         MOVE.L    TextPtr,A0
  333.         SUB.L    #1,A0
  334. PullKeysLoop:    CMP.B    #10,(A0)+
  335.         BNE    PullKeysLoop
  336.         CMP.B    #'#',(A0)
  337.         BNE    PullKeysLoop
  338.         ADD.L    #1,A0
  339.         CMP.B    #10,(A0)
  340.         BEQ    DonePKLoop
  341.         CLR.L    D0
  342.         MOVE.B    (A0)+,D0
  343.         MOVE.B    #1,0(A1,D0)
  344.         BRA    PullKeysLoop
  345.         
  346.     ;Ensure that ESC is always a valid key
  347. DonePKLoop:    MOVE.B    #1,27(A1)
  348.         
  349.     ;Wait for an IDCMP event to occur
  350. WaitKeyLoop:    MOVE.L    WindowBase,A0
  351.         MOVE.L    wd_UserPort(A0),A0
  352.         MOVE.L    A0,-(A7)
  353.         CLR.L    D1
  354.         MOVE.B    MP_SIGBIT(A0),D1
  355.         MOVE.L    #1,D0
  356.         ASL.L    D1,D0
  357.         MOVE.L    4,A6
  358.         JSR    _LVOWait(A6)
  359.         
  360.     ;Get the IDCMP message
  361.         MOVE.L    (A7)+,A0
  362.         JSR    _LVOGetMsg(A6)
  363.         MOVE.L    D0,A1
  364.         MOVE.W    im_Code(A1),EventCode
  365.         MOVE.L    im_Class(A1),EventClass
  366.     
  367.     ;Tell exec that we got the message
  368.         JSR    _LVOReplyMsg(A6)
  369.  
  370.     ;Test for Menu Item Picked
  371.         CMP.L    #MENUPICK,EventClass
  372.         BNE    NoMenuPicked
  373.         CMP.W    #63488,EventCode
  374.         BEQ    PickedEdit
  375.         CMP.W    #63520,EventCode
  376.         BEQ    PickedAbout
  377.         CMP.W    #63552,EventCode
  378.         BEQ    PickedQuit
  379.         BRA    WaitKeyLoop
  380.  
  381.     ;Display the About Requester
  382. PickedAbout:    JSR    AboutThisProg
  383.         BRA    WaitKeyLoop
  384.  
  385.     ;If Edit was selected then Launch ED and exit
  386.     ;To do this we set EventCode to 0
  387.     ;And Exit as if the program was executing a Menu Selection
  388. PickedEdit:    MOVE.W    #0,EventCode
  389.         BRA    SkipKeyTest
  390.  
  391.     ;If Quit was selected then we simply put ESC in the EventCode
  392.     ;And act as if ESC had been pressed
  393. PickedQuit:    MOVE.W    #27,EventCode
  394.         
  395.     ;Test for a valid key
  396. NoMenuPicked:    LEA    ValidKeys,A0
  397.         MOVE.W    EventCode,D0
  398. TestItAgain:    TST.L    0(A0,D0.W)
  399.         BNE    SkipKeyTest
  400.         
  401.     ;If it was an UPPERCASE letter then make it lower & try again
  402.         CMP.W    #'A',D0
  403.         BMI    WaitKeyLoop
  404.         CMP.W    #'Z',D0
  405.         BGT    WaitKeyLoop
  406.         ADD.W    #$20,D0
  407.         MOVE.W    D0,EventCode
  408.         BRA    TestItAgain
  409.         
  410.     ;Close the Menu
  411. SkipKeyTest:    MOVE.L    IntBase,A6
  412.         MOVE.L    WindowBase,A0
  413.         JSR    _LVOClearMenuStrip(A6)
  414.         
  415.     ;Close the Window
  416.         MOVE.L    IntBase,A6
  417.         MOVE.L    WindowBase,A0
  418.         JSR    _LVOCloseWindow(A6)
  419.  
  420.     ;Close the Screen
  421. FailedWindow:    MOVE.L    IntBase,a6
  422.         MOVE.L    ScreenBase,A0
  423.         JSR    _LVOCloseScreen(A6)
  424.  
  425.     ;Test if ESC was pressed
  426.         CMP.W    #27,EventCode
  427.         BEQ    PressedEsc
  428.         
  429.     ;Test if EDIT was selected
  430.         TST.W    EventCode
  431.         BNE    SkipDoEdit
  432.     
  433.     ;Edit was selected so create a Batch to EDIT the menu file
  434.         LEA    EditCommand,A0
  435.         MOVE.L    A0,A1
  436.         MOVE.W    #'ED',(A1)+
  437.         MOVE.B    #' ',(A1)+
  438.         
  439.     ;Transfer the FileName to our command
  440.         MOVE.L    FileNamePtr,A2
  441. TransLoop:    MOVE.B    (A2)+,(A1)+
  442.         TST.B    (A2)
  443.         BNE    TransLoop
  444.         
  445.         MOVE.B    #10,(A1)+
  446.         MOVE.B    #'#',(A1)+
  447.         MOVE.B    #10,(A1)+
  448.                 
  449.         BRA    SkipOverIt    
  450.         
  451.     ;Find the key in the Multi Menu file
  452. SkipDoEdit:    MOVE.L    TextPtr,A0
  453.         SUB.L    #1,A0
  454.         MOVE.B    EventCode+1,D0
  455. FindKeyLoop:     CMP.B    #10,(A0)+
  456.         BNE    FindKeyLoop
  457.         CMP.B    #'#',(A0)
  458.         BNE    FindKeyLoop
  459.         ADD.L    #1,A0
  460.         CMP.B    (A0),D0
  461.         BNE    FindKeyLoop
  462.         
  463.     ;We've found the entry, now skip past the Line Feed
  464. SkipLF:        CMP.B    #10,(A0)+
  465.         BNE    SkipLF
  466.         
  467.     ;Store away the pointer
  468. SkipOverIt:    MOVE.L    A0,TextPtr
  469.         
  470.     ;Open a File to store the Batch Commands in.
  471.         MOVE.L    DosBase,A6
  472.         MOVE.L    #BatchName,D1
  473.         MOVE.L    #MODE_NEWFILE,D2
  474.         JSR    _LVOOpen(A6)
  475.         MOVE.L    D0,Handle
  476.         BEQ    NoBatchFile
  477.         
  478.     ;Find the next #10,'#' after TextPtr
  479.         MOVE.L    TextPtr,A0
  480. FindEndLoop:    CMP.B    #10,(A0)+
  481.         BNE    FindEndLoop
  482.         CMP.B    #'#',(A0)
  483.         BNE    FindEndLoop
  484.         
  485.     ;Calculate the Length of Batch Text
  486.         MOVE.L    A0,D3
  487.         SUB.L    TextPtr,D3
  488.         
  489.     ;Write the Batch File
  490.         MOVE.L    DosBase,A6
  491.         MOVE.L    Handle,D1
  492.         MOVE.L    TextPtr,D2
  493.         JSR    _LVOWrite(A6)
  494.     
  495.     ;Close the file
  496.         MOVE.L    DosBase,A6
  497.         MOVE.L    Handle,D1
  498.         JSR    _LVOClose(A6)
  499.  
  500.     ;Check if the process was run from CLI or Workbench
  501.         MOVE.L    TaskPtr,A0
  502.         TST.L    pr_CLI(A0)
  503.         BNE    GotOutputNow
  504.  
  505.     ;Open the Default Output for running from Workbench
  506.         MOVE.L    DosBase,A6
  507.         MOVE.L    #ConName,D1
  508.         MOVE.L    #MODE_NEWFILE,D2
  509.         JSR    _LVOOpen(A6)
  510.         MOVE.L    D0,ConHandle
  511.  
  512.     ;Execute the Batch File
  513. GotOutputNow:    MOVE.L    DosBase,A6
  514.         MOVE.L    #Command,D1
  515.         CLR.L    D2
  516.         MOVE.L    ConHandle,D3
  517.         JSR    _LVOExecute(A6)
  518.             
  519.     ;Delete the Batch File
  520.         MOVE.L    DosBase,A1
  521.         MOVE.L    #BatchName,D1
  522.         JSR    _LVODeleteFile(A6)
  523.             
  524.         BRA    PressedEsc
  525.  
  526. NoBatchFile:    LEA    NoBatchErr,A0
  527.         JSR    ReportError
  528.  
  529.     ;Free the memory
  530. FileWasEmpty:
  531. PressedEsc:    
  532. FailedScreen:    MOVE.L    4,A6
  533.         MOVE.L    MemPtr,A1
  534.         MOVE.L    FileSize,D0
  535.         ADD.L    #3,D0
  536.         JSR    _LVOFreeMem(A6)
  537.  
  538.         BRA    ExitQuick
  539.         
  540. FailedToOpen:    LEA    FailedOpenErr,A0
  541.         JSR    ReportError
  542.         BRA    ExitQuick
  543.         
  544. FileTooBig:    LEA    FileTooBigErr,A0
  545.         JSR    ReportError
  546.  
  547. ;*****************************
  548. ;**** Close the libraries ****
  549. ;*****************************
  550.     ;Free the Lock on CD0:
  551. ExitQuick:    MOVE.L    DosBase,A6
  552.         MOVE.L    CdLock,D1
  553.         BEQ    NoCdLock
  554.         JSR    _LVOUnLock(A6)
  555.         
  556.     ;Change back to the old directory
  557. NoCdLock:    MOVE.L    DosBase,A6
  558.         MOVE.L    OldDirectory,D1
  559.         BEQ    NoOldDir
  560.         JSR    _LVOCurrentDir(A6)
  561.  
  562.     ;Free the RdArgs structure
  563. NoOldDir:    MOVE.L    DosBase,A6
  564.         MOVE.L    RdArgs,D1
  565.         BEQ    NoRdArgs
  566.         JSR    _LVOFreeArgs(A6)
  567.         
  568.     ;Close the Icon library
  569. NoRdArgs:    MOVE.L    4,A6
  570.         MOVE.L    IconBase,A1
  571.         BEQ    NoIconLib
  572.         JSR    _LVOCloseLibrary(A6)
  573.     
  574.     ;Close the Graphics library    
  575. NoIconLib:    MOVE.L    4,A6
  576.         MOVE.L    GrxBase,A1
  577.         BEQ    NoGfxLib
  578.         JSR    _LVOCloseLibrary(A6)
  579.         
  580.     ;Close the Intuition library
  581. NoGfxLib:    MOVE.L    4,A6
  582.         MOVE.L    IntBase,A1
  583.         BEQ    NoIntLib
  584.         JSR    _LVOCloseLibrary(A6)
  585.         
  586.     ;Close the Dos library
  587. NoIntLib:    MOVE.L    4,A6
  588.         MOVE.L    DosBase,A1
  589.         BEQ    NoDosLib
  590.         JSR    _LVOCloseLibrary(A6)
  591.         
  592.     ;Test if program was run from Workbench
  593. NoDosLib:    TST.L    Message
  594.         BEQ    Exit
  595.         
  596.     ;Yes so Reply to workbench that program has finished
  597.         MOVE.L    4,A6
  598.         JSR    _LVOForbid(A6)
  599.         MOVE.L    Message,A1
  600.         JSR    _LVOReplyMsg(A6)
  601.         
  602.     ;Exit to CLI or Workbench with clear return code
  603. Exit:        CLR.L    D0
  604.         RTS
  605.         
  606.     ;Incorrect arguments were given so give an error
  607. ArgsError:    MOVE.L    DosBase,A6
  608.         MOVE.L    #ArgErrorTxt,D1
  609.         JSR    _LVOPutStr(A6)
  610.         
  611.         BRA    ExitQuick
  612.     
  613.  
  614. ;***********************************************************************
  615. ;**** This routine attempts to get name of CD0: if a MultiMenu file ****
  616. ;**** is found under this name then it is used, otherwise "Default" ****
  617. ;***********************************************************************
  618.  
  619. UseDefaultName:    
  620.     ;Disable Worbench Requesters while attempting to get the lock
  621.         MOVE.L    TaskPtr,A0
  622.         MOVE.L    pr_WindowPtr(A0),-(A7)
  623.         MOVE.L    #-1,pr_WindowPtr(A0)
  624.     
  625.     ;Get a Lock on CD0:
  626.         MOVE.L    DosBase,A6
  627.         MOVE.L    #CdName,D1
  628.         MOVE.L    #ACCESS_READ,D2
  629.         JSR    _LVOLock(A6)
  630.         MOVE.L    D0,CdLock
  631.  
  632.     ;Enable Workbench Requesters again
  633.         MOVE.L    TaskPtr,A0
  634.         MOVE.L    (A7)+,pr_WindowPtr(A0)
  635.  
  636.     ;Check if we got a Lock or not
  637.         TST.L    CdLock
  638.         BEQ    UDN_NoLock
  639.         
  640.     ;Examine the Lock
  641.         MOVE.L    DosBase,A6
  642.         MOVE.L    CdLock,D1
  643.         MOVE.L    #CdInfoBlock,D2
  644.         JSR    _LVOExamine(A6)
  645.  
  646.     ;Get the Volume Name
  647.         MOVE.L    #CdInfoBlock+8,FileNamePtr        
  648.         RTS
  649.  
  650. SetToDefault:
  651. UDN_NoLock:    MOVE.L    #DefaultName,FileNamePtr
  652.         RTS
  653.  
  654. ;*******************************************************************
  655. ;**** The following routine opens a small window containin info ****
  656. ;**** about this program & the author                           ****
  657. ;*******************************************************************
  658.  
  659. AboutThisProg:
  660.     ;Remove the Menu from the Window
  661.         MOVE.L    IntBase,A6
  662.         MOVE.L    WindowBase,A0
  663.         JSR    _LVOClearMenuStrip(A6)
  664.  
  665.     ;Open a window to display the information in
  666.         MOVE.L    IntBase,A6
  667.         LEA    ATP_WindowDef,A0
  668.         MOVE.L    ScreenBase,ATP_ScreenBase
  669.         JSR    _LVOOpenWindow(A6)
  670.         MOVE.L    D0,ATP_WindowBase    
  671.         BEQ    ATP_NoWindow
  672.  
  673.     ;Get the windows RastPort
  674.         MOVE.L    ATP_WindowBase,A0
  675.         MOVE.L    50(A0),ATP_RastPort
  676.         
  677.     ;Set A Pen to Colour 2
  678.         MOVE.L    GrxBase,A6
  679.         MOVE.L    ATP_RastPort,A1
  680.         MOVE.L    #2,D0
  681.         JSR    _LVOSetAPen(A6)
  682.         
  683.     ;Move Graphics cursor to 0,0
  684.         MOVE.L    GrxBase,A6
  685.         MOVE.L    ATP_RastPort,A1
  686.         CLR.L    D0
  687.         CLR.L    D1
  688.         JSR    _LVOMove(A6)
  689.         
  690.     ;Draw a line across top of window
  691.         MOVE.L    GrxBase,A6
  692.         MOVE.L    ATP_RastPort,A1
  693.         MOVE.L    #320,D0
  694.         CLR.L    D1
  695.         JSR    _LVODraw(A6)
  696.  
  697.     ;Move Graphics cursor to 0,0
  698.         MOVE.L    GrxBase,A6
  699.         MOVE.L    ATP_RastPort,A1
  700.         CLR.L    D0
  701.         CLR.L    D1
  702.         JSR    _LVOMove(A6)
  703.  
  704.     ;Draw a line down left of window
  705.         MOVE.L    GrxBase,A6
  706.         MOVE.L    ATP_RastPort,A1
  707.         CLR.L    D0
  708.         MOVE.L    #100,D1
  709.         JSR    _LVODraw(A6)
  710.  
  711.     ;Set A Pen to Colour 1
  712.         MOVE.L    GrxBase,A6
  713.         MOVE.L    ATP_RastPort,A1
  714.         MOVE.L    #1,D0
  715.         JSR    _LVOSetAPen(A6)
  716.         
  717.     ;Move Graphics cursor to 0,99
  718.         MOVE.L    GrxBase,A6
  719.         MOVE.L    ATP_RastPort,A1
  720.         CLR.L    D0
  721.         MOVE.L    #99,D1
  722.         JSR    _LVOMove(A6)
  723.         
  724.     ;Draw a line across top of window
  725.         MOVE.L    GrxBase,A6
  726.         MOVE.L    ATP_RastPort,A1
  727.         MOVE.L    #320,D0
  728.         MOVE.L    #99,D1
  729.         JSR    _LVODraw(A6)
  730.  
  731.     ;Move Graphics cursor to 319,0
  732.         MOVE.L    GrxBase,A6
  733.         MOVE.L    ATP_RastPort,A1
  734.         MOVE.L    #319,D0
  735.         CLR.L    D1
  736.         JSR    _LVOMove(A6)
  737.  
  738.     ;Draw a line down left of window
  739.         MOVE.L    GrxBase,A6
  740.         MOVE.L    ATP_RastPort,A1
  741.         MOVE.L    #319,D0
  742.         MOVE.L    #100,D1
  743.         JSR    _LVODraw(A6)
  744.         
  745.     ;Write the IntuiText to the window
  746.         MOVE.L    IntBase,A6
  747.         MOVE.L    ATP_RastPort,A0
  748.         LEA    ATP_TextDef,A1
  749.         MOVE.L    #0,D0
  750.         MOVE.L    #0,D1
  751.         JSR    _LVOPrintIText(A6)
  752.  
  753.     ;Wait for an IDCMP event to occur
  754.         MOVE.L    ATP_WindowBase,A0
  755.         MOVE.L    wd_UserPort(A0),A0
  756.         MOVE.L    A0,-(A7)
  757.         CLR.L    D1
  758.         MOVE.B    MP_SIGBIT(A0),D1
  759.         MOVE.L    #1,D0
  760.         ASL.L    D1,D0
  761.         MOVE.L    4,A6
  762.         JSR    _LVOWait(A6)
  763.  
  764.     ;Get the IDCMP message
  765.         MOVE.L    (A7)+,A0
  766.         JSR    _LVOGetMsg(A6)
  767.     
  768.     ;Tell exec that we got the message
  769.         MOVE.L    D0,A1
  770.         JSR    _LVOReplyMsg(A6)
  771.         
  772.     ;Exit now, we don't need to check the IDCMP event as our window
  773.     ;Only checks for the gadget clicks & only has one gadget!
  774.         
  775.     ;Close the window
  776.         MOVE.L    IntBase,A6
  777.         MOVE.L    ATP_WindowBase,A0
  778.         JSR    _LVOCloseWindow(A6)
  779.  
  780.     ;Add back the Menu Strip
  781.         MOVE.L    IntBase,A6
  782.         MOVE.L    WindowBase,A0
  783.         LEA    MenuDef,A1
  784.         JSR    _LVOSetMenuStrip(A6)
  785.         
  786. ATP_NoWindow:    RTS
  787.         
  788.         
  789. ;***************************************************************    
  790. ;**** This routine informs the user of an error.            ****
  791. ;****                                                       ****
  792. ;**** On entry A0 points to a NULL terminated error message ****
  793. ;***************************************************************
  794.  
  795. ReportError:    TST.L    Message
  796.         BEQ    RE_ErrorToCLI
  797.     
  798.     ;Create a Workbench Requestor with the error in it
  799.         MOVE.L    IntBase,A6
  800.         MOVE.L    A0,ErrorPtr
  801.         MOVE.L    TaskPtr,A0
  802.         MOVE.L    pr_WindowPtr(A0),A0
  803.         LEA    ReqBodyText,A1
  804.         LEA    ReqOkayText,A2
  805.         LEA    ReqOkayText,A3
  806.         CLR.L    D0
  807.         CLR.L    D1
  808.         MOVE.L    #640,D2
  809.         MOVE.L    #150,D3
  810.         JSR    _LVOAutoRequest(A6)
  811.         RTS
  812.         
  813.     ;Firstly we must find the length of the error message
  814. RE_ErrorToCLI:    MOVE.L    A0,A1
  815. FindNull:    TST.B    (A1)+
  816.         BNE    FindNull
  817.         SUB.L    #1,A1
  818.         SUB.L    A0,A1
  819.         
  820.     ;Store the Pointer & Length on the Stack
  821.         MOVE.L    A0,-(A7)
  822.         MOVE.L    A1,-(A7)
  823.     
  824.     ;Get the Default Output
  825.         MOVE.L    DosBase,A6
  826.         JSR    _LVOOutput(A6)
  827.         MOVE.L    D0,ErrorPtr
  828.         
  829.     ;Write the Error message
  830.         MOVE.L    DosBase,A6
  831.         MOVE.L    D0,D1        ;File Handle
  832.         MOVE.L    (A7)+,D3    ;Text Length
  833.         MOVE.L    (A7)+,D2    ;Text Start Address
  834.         JSR    _LVOWrite(A6)
  835.         
  836.     ;Write a Line Feed too.
  837.         MOVE.L    DosBase,A6
  838.         MOVE.L    ErrorPtr,D1
  839.         MOVE.L    #LineFeed,D2
  840.         MOVE.L    #1,D3
  841.         JSR    _LVOWrite(A6)
  842.         
  843.         RTS
  844.     
  845.         SECTION data,data
  846.  
  847. ReqBodyText:    DC.B    1        ;Front Pen
  848.         DC.B    0        ;Back Pen
  849.         DC.B    RP_JAM1        ;Draw Mode
  850.         DC.W    0,0        ;Left Edge/Top Edge
  851.         DC.L    FontDef        ;Font Pointer
  852. ErrorPtr:    DC.L    0        ;Text for item
  853.         DC.L    0        ;Next Structure
  854.  
  855. ReqOkayText:    DC.B    1        ;Front Pen
  856.         DC.B    0        ;Back Pen
  857.         DC.B    RP_JAM1        ;Draw Mode
  858.         DC.W    0,0        ;Left Edge/Top Edge
  859.         DC.L    FontDef        ;Font Pointer
  860.         DC.L    ATP_GadText    ;Text for item
  861.         DC.L    0        ;Next Structure
  862.  
  863.     
  864.  
  865. NewScreenDef:    DC.W    0,0,640,258    ;X,Y,W,H
  866.         DC.W    2        ;Depth
  867.         DC.B    1,2        ;Detail / Block Pen
  868.         DC.W    V_HIRES        ;View Modes
  869.         DC.W    CUSTOMSCREEN    ;Screen Type
  870.         DC.L    FontDef        ;Screen Font
  871.         DC.L    0        ;Screen Title
  872.         DC.L    0        ;Gadgets
  873.         DC.L    0        ;Bitmap
  874.  
  875. NewWindowDef:    DC.W    0,0,640,258    ;X,Y,W,H
  876.         DC.B    1,2        ;Detail / Block Pen
  877.         DC.L    IDCMP_VANILLAKEY+IDCMP_MENUPICK    ;IDCMP Flags
  878.         DC.L    WFLG_BORDERLESS+WFLG_ACTIVATE    ;Window Flags
  879.         DC.L    0        ;Gadget
  880.         DC.L    0        ;Check Mark
  881.         DC.L    0        ;Title
  882. ScreenBase:    DC.L    0        ;Screen
  883.         DC.L    0        ;Bitmap
  884.         DC.W    0,0,0,0        ;Min W,Min H,Max W,Max H
  885.         DC.W    CUSTOMSCREEN    ;Window Type
  886.  
  887. ATP_WindowDef:    DC.W    160,78,320,100    ;X,Y,W,H
  888.         DC.B    1,0        ;Detail / Block Pen
  889.         DC.L    IDCMP_GADGETUP    ;IDCMP Flags
  890.         DC.L    WFLG_ACTIVATE+WFLG_BORDERLESS    ;Window Flags
  891.         DC.L    ATP_GadgetDef    ;Gadget
  892.         DC.L    0        ;Check Mark
  893.         DC.L    0        ;Title
  894. ATP_ScreenBase:    DC.L    0        ;Screen
  895.         DC.L    0        ;Bitmap
  896.         DC.W    0,0,0,0        ;Min W,Min H,Max W,Max H
  897.         DC.W    CUSTOMSCREEN    ;Window Type
  898.  
  899. ATP_GadgetDef:    DC.L    0        ;Pointer to Next Gadget
  900.         DC.W    140,80,40,11    ;X,Y,H,W of Click Region
  901.         DC.W    GADGHIMAGE    ;Gadget has a Click Image
  902.         DC.W    RELVERIFY    ;Flags
  903.         DC.W    BOOLGADGET    ;Gadget Type
  904.         DC.L    ATP_GadBorder   ;Pointer to Border Definition
  905.         DC.L    ATP_ActBorder    ;Pointer to Active Border
  906.         DC.L    ATP_GadTextDef    ;Pointer to IntuiText
  907.         DC.L    0,0,0,0        ;Not used (Gadget ID = 0)
  908.  
  909. ATP_GadBorder:    DC.W    0,0        ;X,Y
  910.         DC.B    2,0        ;Detail / Block Pen
  911.         DC.B    RP_JAM1        ;Draw Mode
  912.         DC.B    3        ;# of coords
  913.         DC.L    ATP_GadCoords    ;Pointer to the Coords
  914.         DC.L    ATP_GadBorder2    ;Pointer to Next Border Def
  915.  
  916. ATP_GadBorder2:    DC.W    0,0        ;X,Y
  917.         DC.B    1,0        ;Detail / Block Pen
  918.         DC.B    RP_JAM1        ;Draw Mode
  919.         DC.B    3        ;# of coords
  920.         DC.L    ATP_GadCoords2    ;Pointer to the Coords
  921.         DC.L    0        ;Pointer to Next Border Def
  922.         
  923. ATP_ActBorder:    DC.W    0,0        ;X,Y
  924.         DC.B    1,0        ;Detail / Block Pen
  925.         DC.B    RP_JAM1        ;Draw Mode
  926.         DC.B    3        ;# of coords
  927.         DC.L    ATP_GadCoords    ;Pointer to the Coords
  928.         DC.L    ATP_ActBorder2    ;Pointer to Next Border Def
  929.  
  930. ATP_ActBorder2:    DC.W    0,0        ;X,Y
  931.         DC.B    2,0        ;Detail / Block Pen
  932.         DC.B    RP_JAM1        ;Draw Mode
  933.         DC.B    3        ;# of coords
  934.         DC.L    ATP_GadCoords2    ;Pointer to the Coords
  935.         DC.L    0        ;Pointer to Next Border Def
  936.         
  937.         
  938. ATP_GadCoords:    DC.W    0,10, 0,0, 38,0
  939. ATP_GadCoords2:    DC.W    1,10, 39,10, 39,0
  940.  
  941. ATP_GadTextDef:    DC.B    1        ;Front Pen
  942.         DC.B    0        ;Back Pen
  943.         DC.B    RP_JAM1        ;Draw Mode
  944.         DC.W    4,2        ;Left Edge/Top Edge
  945.         DC.L    FontDef        ;Font Pointer
  946.         DC.L    ATP_GadText    ;Text for item
  947.         DC.L    0        ;Next Structure
  948.  
  949.  
  950. FontDef:    DC.L    TopazName    ;Pointer to font name
  951.         DC.W    8        ;Font Height
  952.         DC.B    0        ;Font Style
  953.         DC.B    0        ;Font Flags
  954.  
  955. MenuDef:    DC.L    0        ;Pointer to next Menu Structure
  956.         DC.W    0,0,100,0    ;X,Y,W,H
  957.         DC.W    MENUENABLED    ;Flags
  958.         DC.L    MenuName    ;Pointer to MenuName
  959.         DC.L    MenuItem1    ;Pointer to first item
  960.         DC.W    0,0,0,0        ;Internal use
  961.         
  962. MenuItem1:    DC.L    MenuItem2    ;Pointer to next Menu Item
  963.         DC.W    0,0,95,11    ;X,Y,W,H
  964.         DC.W    ITEMTEXT|COMMSEQ|ITEMENABLED|HIGHCOMP
  965.         DC.L    0        ;Mutual Exlude
  966.         DC.L    ItemName1    ;Item Fill
  967.         DC.L    0        ;Select Fill
  968.         DC.B    'E'        ;Hot Key
  969.         DC.L    0        ;Sub Item
  970.         DC.W    0        ;Next Select
  971.         
  972. ItemName1:    DC.B    1        ;Front Pen
  973.         DC.B    0        ;Back Pen
  974.         DC.B    RP_JAM1        ;Draw Mode
  975.         DC.W    2,2        ;Left Edge/Top Edge
  976.         DC.L    FontDef        ;Font Pointer
  977.         DC.L    ItemText1    ;Text for item
  978.         DC.L    0        ;Next Structure
  979.  
  980. MenuItem2:    DC.L    MenuItem3    ;Pointer to next Menu Item
  981.         DC.W    0,12,95,11    ;X,Y,W,H
  982.         DC.W    ITEMTEXT|COMMSEQ|ITEMENABLED|HIGHCOMP
  983.         DC.L    0        ;Mutual Exlude
  984.         DC.L    ItemName2    ;Item Fill
  985.         DC.L    0        ;Select Fill
  986.         DC.B    'A'        ;Hot Key
  987.         DC.L    0        ;Sub Item
  988.         DC.W    0        ;Next Select
  989.         
  990. ItemName2:    DC.B    1        ;Front Pen
  991.         DC.B    0        ;Back Pen
  992.         DC.B    RP_JAM1        ;Drap Mode
  993.         DC.W    2,2        ;Left Edge/Top Edge
  994.         DC.L    FontDef        ;Font Pointer
  995.         DC.L    ItemText2    ;Text for item
  996.         DC.L    0        ;Next Structure
  997.  
  998. MenuItem3:    DC.L    0        ;Pointer to next Menu Item
  999.         DC.W    0,24,95,11    ;X,Y,W,H
  1000.         DC.W    ITEMTEXT|COMMSEQ|ITEMENABLED|HIGHCOMP
  1001.         DC.L    0        ;Mutual Exlude
  1002.         DC.L    ItemName3    ;Item Fill
  1003.         DC.L    0        ;Select Fill
  1004.         DC.B    'Q'        ;Hot Key
  1005.         DC.L    0        ;Sub Item
  1006.         DC.W    0        ;Next Select
  1007.         
  1008. ItemName3:    DC.B    1        ;Front Pen
  1009.         DC.B    0        ;Back Pen
  1010.         DC.B    RP_JAM1        ;Drap Mode
  1011.         DC.W    2,2        ;Left Edge/Top Edge
  1012.         DC.L    FontDef        ;Font Pointer
  1013.         DC.L    ItemText3    ;Text for item
  1014.         DC.L    0        ;Next Structure
  1015.  
  1016. ATP_TextDef:    DC.B    1        ;Front Pen
  1017.         DC.B    0        ;Back Pen
  1018.         DC.B    RP_JAM1        ;Draw Mode
  1019.         DC.W    4,8        ;Left Edge/Top Edge
  1020.         DC.L    FontDef        ;Font Pointer
  1021.         DC.L    ATP_Text1    ;Text for item
  1022.         DC.L    ATP_TextDef2    ;Next Structure
  1023.  
  1024. ATP_TextDef2:    DC.B    1        ;Front Pen
  1025.         DC.B    0        ;Back Pen
  1026.         DC.B    RP_JAM1        ;Draw Mode
  1027.         DC.W    4,24        ;Left Edge/Top Edge
  1028.         DC.L    FontDef        ;Font Pointer
  1029.         DC.L    ATP_Text2    ;Text for item
  1030.         DC.L    ATP_TextDef3    ;Next Structure
  1031.  
  1032. ATP_TextDef3:    DC.B    1        ;Front Pen
  1033.         DC.B    0        ;Back Pen
  1034.         DC.B    RP_JAM1        ;Draw Mode
  1035.         DC.W    4,56        ;Left Edge/Top Edge
  1036.         DC.L    FontDef        ;Font Pointer
  1037.         DC.L    ATP_Text3    ;Text for item
  1038.         DC.L    0        ;Next Structure
  1039.  
  1040.  
  1041. ATP_Text1:    DC.B    "            Multi Menu V1.0            ",0
  1042. ATP_Text2:    DC.B    "          ©1997 - Mike Archer          ",0
  1043. ATP_Text3:    DC.B    "       This program is FreeWare.       ",0
  1044. FailedOpenErr:    DC.B    "Could not open Menu File.",0
  1045. FileTooBigErr:    DC.B    "Ran out of memory loading menu file.",0
  1046. NoBatchErr:    DC.B    "Could not create temp batch file, check T: assignment.",0
  1047. ATP_GadText:    DC.B    "OKAY",0
  1048. LineFeed:    DC.B    10
  1049. MenuName:    DC.B    "Menu",0
  1050. ItemText1:    DC.B    "Edit",0
  1051. ItemText2:    DC.B    "About",0
  1052. ItemText3:    Dc.B    "Quit",0
  1053. TopazName:    DC.B    "topaz.font",0
  1054. DosLibName:    DC.B    "dos.library",0        
  1055. IconLibName:    DC.B    "icon.library",0
  1056. IntLibName:    DC.B    "intuition.library",0
  1057. GfxLibName:    DC.B    "graphics.library",0
  1058. CdName:        DC.B    "CD0:",0
  1059. ArgTemplate:    DC.B    "MENUNAME",0
  1060. ArgErrorTxt:    DC.B    "Incorrect parameters, please read the user guide.",10,0        
  1061. DefaultName:    DC.B    "Default",0        
  1062. DefaultPath:    DC.B    "S:MultiMenu",0
  1063. ConName:    DC.B    "CON:0/0/640/100/Multi Menu V1.0/WAIT/CLOSE/AUTO",0
  1064. Command:    DC.B    "EXECUTE "
  1065. BatchName:    DC.B    "T:MM_Batch."
  1066. SpecialID:    DC.B    "0000",0        
  1067.     
  1068.         SECTION    bss,bss
  1069. BssPtr:    
  1070. ParmPtr:    DS.L    1
  1071. ParmLen:    DS.L    1
  1072. DosBase:    DS.L    1
  1073. IconBase:    DS.L    1
  1074. GrxBase:    DS.L    1
  1075. IntBase:    DS.L    1
  1076. WindowBase:    DS.L    1
  1077. ATP_WindowBase:    DS.L    1
  1078. ATP_RastPort    DS.L    1
  1079. RastBase:    DS.L    1
  1080. TextLen:    DS.L    1
  1081. Message:    DS.L    1    
  1082. FileNamePtr:    DS.L    1    
  1083. MemPtr:        DS.L    1    
  1084. ArgArray:    DS.L    1        
  1085. RdArgs:        DS.L    1    
  1086. DirectoryLock:    DS.L    1
  1087. OldDirectory:    DS.L    1
  1088. CdLock:        DS.L    1
  1089. Handle:        DS.L    1
  1090. FileSize:    DS.L    1
  1091. Y_Pos:        DS.L    1
  1092. ConHandle:    DS.L    1
  1093. TextPtr:    DS.L    1
  1094. TaskPtr:    DS.L    1
  1095. EventClass:    DS.L    1
  1096.  
  1097. InfoBlock:    DS.B    260
  1098.  
  1099. CdInfoBlock:    DS.B    260
  1100.  
  1101.  
  1102. ValidKeys:    DS.B    256
  1103.  
  1104. EditCommand:    DS.B    350     ;A buffer to create the Edit Command in.
  1105.  
  1106. EventCode:    DS.W    1
  1107.     
  1108. BssLen        EQU    (*-BssPtr)/4
  1109.         
  1110.