home *** CD-ROM | disk | FTP | other *** search
/ AMOS PD CD / amospdcd.iso / 451-475 / apd459 / amoscli.amos / amoscli.amosSourceCode
AMOS Source Code  |  1994-01-01  |  12KB  |  359 lines

  1. '******************************************************************* 
  2. '*        A M O S   C L I    By Gary Fearn                         * 
  3. '******************************************************************* 
  4. '
  5. '* Rename this program to CLI.Acc                                  *   
  6. '
  7. '* This Utility is most effective if assigned to the Help key      * 
  8. '* to replace the Help.Acc. You can do this by using Config.Amos   * 
  9. '* on the program disc. Select the < Help Accesory name > from the * 
  10. '* menu and change the two top strings to "CLI.Acc",and the last   * 
  11. '* string to "Cannot find CLI.ACC".                                * 
  12. '* 
  13. '* Pressing return at prompt displays last command entered         * 
  14. '* typing ? <return> displays all commands available               * 
  15. '* typing a command with ? as a parameter displays command template* 
  16. '
  17. '******************** 1/2 MEG MACHINES ***************************** 
  18. '* At present this is a tight fit into memory. I suggest you edit out
  19. '* some commands and mess about with set buffer and other memory   
  20. '* saving commands.    
  21. '********************************************************************
  22. '
  23. '
  24. If Fast Free=0
  25.    Close Workbench : Close Editor 
  26.    Screen Open 7,640,256,4,Hires
  27. Else 
  28.    Screen Open 7,640,256,8,Hires
  29. End If 
  30. _INTRO
  31. Wind Open 1,16,10,74,30,1
  32. Palette $12,$34,$AF,$FF
  33. Curs Off : Flash Off 
  34. COMMAND$="" : FIRST$=" " : SEC$=" " : COMNUM=18 : Rem COMNUM=number of commands
  35. Dim COMNAME$(COMNUM)
  36. Restore NAMES
  37. For A=0 To COMNUM-1
  38.    Read COMNAME$(A)
  39. Next A
  40. Global COMMAND$,COMNAME$(),COMNUM,FIRST$,SEC$
  41. Centre "A M O S  C L I" : Print : Print 
  42. Print Pen$(2)+"Type ? <Return> for list of commands."
  43. Print "Type the CommandName followed by a ? for the Template."
  44. Print "Press Return at prompt to edit the last command."
  45. Print : Print 
  46. '
  47. BEGIN:
  48. Do 
  49. Input "> ";COMMAND$
  50. If COMMAND$="" Then Put Key KEYBUFF$
  51. KEYBUFF$=COMMAND$
  52. COMMAND$=Upper$(COMMAND$)
  53. Proc PARSE
  54. Loop 
  55. '
  56. Procedure _INTRO
  57. VERSION$="V1.2"
  58. Wind Open 1,96,20,50,10,1
  59. Curs Off : Flash Off 
  60. Palette $12,$34,$AF,$FF
  61. Centre "Presenting the AMOS CLI" : Print 
  62. Print : Centre Pen$(0)+"By Gary Fearn" : Print 
  63. Print : Locate 17, : Print VERSION$+"  3-9-92"
  64. Do 
  65. If Mouse Key<>0 Then Exit 
  66. If Inkey$<>"" Then Exit 
  67. Loop 
  68. Wind Close 
  69. End Proc
  70. Procedure PARSE
  71. If Len(COMMAND$)=0 Then Pop Proc
  72. POS=Instr(COMMAND$," ")
  73. If POS=0 Then FIRST$=COMMAND$ : SEC$="" : Goto MISSIT
  74.    FIRST$=Left$(COMMAND$,POS-1)
  75.    SEC$=Right$(COMMAND$,Len(COMMAND$)-POS)
  76. MISSIT:
  77.    Proc CHECK_COMS
  78. End Proc
  79. Procedure CHECK_COMS
  80.    R=Match(COMNAME$(0),FIRST$)
  81.    If R=>0 Then Bell 
  82.    If R<0 Then Pop Proc : Rem               * Pop Proc if command not reconized
  83.    If R=0 Then Proc COM0
  84.    On R Proc COM1,COM2,COM3,COM4,COM5,COM6,COM7,COM8,COM9,COM10,COM11,COM12,COM13,COM14,COM15,COM16,COM17
  85. End Proc
  86. '
  87. '************************  
  88. '** Command Procedures **
  89. '************************
  90. '                              * ? (Prints out list of commands)     
  91. Procedure COM0
  92.    For A=0 To COMNUM-1
  93.       Print COMNAME$(A)
  94.    Next A
  95. End Proc
  96. '                              * CD (CHANGE Directory)       
  97. Procedure COM1
  98.    If SEC$="" Then Print Dir$ : Pop Proc
  99.    If SEC$="/" Then Parent : Pop Proc
  100.    If SEC$="?" Then Print "CD | CD / | CD ? | CD <Pathname>" : Pop Proc
  101.    If Exist(SEC$)
  102.       Dir$=SEC$
  103.    Else 
  104.       Print "Does not Exist !"
  105.    End If 
  106. End Proc
  107. '                              * Cls ( clear the screen & cursor home) 
  108. Procedure COM2
  109.    If SEC$="?" Then Print "No Parameters" : Pop Proc
  110.    Clw : Home 
  111. End Proc
  112. '                              * Copy (copies a file)  
  113. Procedure COM3
  114.    If SEC$="" Then Pop Proc
  115.    If SEC$="?" Then Print "Copy ? | Copy <filename> <filename> | copy <Path+filename> <Drive>" : Pop Proc
  116.    POS=Instr(SEC$," ")
  117.    If POS=0 Then Print "Invalid parameters" : Pop Proc
  118.       FIR$=Left$(SEC$,POS-1)
  119.       SEC$=Right$(SEC$,Len(SEC$)-POS)
  120.    If Exist(FIR$)
  121.       Open In 1,FIR$
  122.       FILELEN=Lof(1)
  123.       Close 1
  124.       Reserve As Work 6,FILELEN
  125.       Bload FIR$,6
  126.       If Len(SEC$)=4
  127.          POS=Instr(FIR$,":")
  128.          If POS<>0
  129.             FIR$=Right$(FIR$,Len(FIR$)-4)
  130.          End If 
  131.          SEC$=SEC$+FIR$
  132.       End If 
  133.       Print "copying ";FIR$;" as ";SEC$;"..."
  134.       Bsave SEC$,Start(6) To Start(6)+FILELEN
  135.       Erase 6
  136.    Else 
  137.       Print FIR$;" does not exist."
  138.    End If 
  139. End Proc
  140. '                              * Dfree (? remaining disk/mem space   
  141. Procedure COM4
  142.    If SEC$="?" Then Print "Dfree | Dfree MEM" : Pop Proc
  143.    If SEC$="" Then Print Dir$;" ";Dfree;" bytes remaining." : Pop Proc
  144.    If SEC$="MEM"
  145.       Print Chip Free;" bytes of chip ram available"
  146.       Print Fast Free;" bytes of fast ram available"
  147.       Print : Print "Total = ";Chip Free+Fast Free
  148.    End If 
  149. End Proc
  150. '                              * Dir (Directory of files)  
  151. Procedure COM5
  152.    If SEC$="?" Then Print "Dir | Dir <Pathname>" : Pop Proc
  153.    If SEC$=""
  154.       Dir 
  155.    Else 
  156.       Dir SEC$
  157.    End If 
  158. End Proc
  159. '                              * Exist (Checks if a file exists)   
  160. Procedure COM6
  161.    If SEC$="" Then Print "Do I Exist ?" : Pop Proc
  162.    If SEC$="?" Then Print "Exist <Filename>" : Pop Proc
  163.    If Exist(SEC$)
  164.       Print "Yes ";SEC$;" does exist"
  165.    Else 
  166.       Print "No ";SEC$;" does not exist"
  167.    End If 
  168. End Proc
  169. '                              * Ftype (Displays the type of files in a directory
  170. Procedure COM7
  171.    If SEC$="?" Then Print "Ftype | Ftype <pathname> " : Pop Proc
  172.    If SEC$<>"" Then Dir$=SEC$
  173.    FILE$=Dir First$("")
  174.    While FILE$<>""
  175.       FTYPE[FILE$]
  176.       FILE$=Dir Next$
  177.    Wend 
  178. End Proc
  179. '                              * IFF (Load an iff picture)   
  180. Procedure COM8
  181.    If SEC$="?" Then Print "IFF | IFF <filename>" : Pop Proc
  182.    If SEC$="" Then SEC$=Fsel$("","","Select a picture")
  183.    If SEC$="" Then Pop Proc
  184.    Open In 1,SEC$ : L=Lof(1) : E$=Input$(1,100) : Close 1
  185.    POS=Hunt(Varptr(E$) To Varptr(E$)+Len(E$),"Pac.Pic")
  186. '                                      Just to see if its a packed picture 
  187.    If POS<>0
  188.       Print "Picture is in a packed format"
  189.       Reserve As Work 6,L
  190.       Load SEC$,6
  191.       Unpack 6 To 6
  192.       Erase 6
  193.    Else 
  194.       Load Iff SEC$,6
  195.    End If 
  196.    Flash Off : Curs Off : Hide 
  197. Do 
  198.    A$=Inkey$
  199.    If Mouse Key<>0 Then Exit 
  200.    If A$<>"" Then Exit 
  201. Loop 
  202.    Show 
  203.    Screen Close 6
  204. End Proc
  205. '                              * Kill (deletes a file) 
  206. Procedure COM9
  207.    If SEC$="?" Then Print "Kill | Kill <filename>" : Pop Proc
  208.    If SEC$="" Then SEC$=Fsel$("*.*","","Delete a file")
  209.    If SEC$="" Then Pop Proc
  210.    If Exist(SEC$)
  211.       Kill SEC$
  212.       Print SEC$;" Deleted ..."
  213.    Else 
  214.       Print SEC$;" does not exist"
  215.    End If 
  216. End Proc
  217. '                              * MKdir ( Make a directory)   
  218. Procedure COM10
  219.    If SEC$="?" Then Print "Mkdir <DirectoryName>" : Pop Proc
  220.    If SEC$="" Then Print "name required" : Pop Proc
  221.    Mkdir SEC$
  222. End Proc
  223. '                              * Music (Play Music in background)  
  224. Procedure COM11
  225.    If SEC$="?" Then Print "Music | Music <filename> | Music OFF" : Pop Proc
  226.    If SEC$="OFF" Then Music Off : Pop Proc
  227.    If SEC$="" Then SEC$=Fsel$("*.*","","Play a Music file")
  228.    If SEC$="" Then Pop Proc
  229.    Load SEC$
  230.    Music 1
  231. End Proc
  232. '                              * Quit ( Ends this program)   
  233. Procedure COM12
  234.    If SEC$="?" Then Print "Bye Bye " : Pop Proc
  235.    End 
  236. End Proc
  237. '                              * Rename (Renames a file) 
  238. Procedure COM13
  239. If SEC$="?" Then Print "Rename <filename1> <filename2>" : Pop Proc
  240. POS=Instr(SEC$," ")
  241. If POS=0 Then Print "Invalid parameters" : Pop Proc
  242.    FIR$=Left$(SEC$,POS-1)
  243.    SEC$=Right$(SEC$,Len(SEC$)-POS)
  244.    If Exist(FIR$)
  245.       Rename FIR$ To SEC$
  246.    End If 
  247. End Proc
  248. '                              * Run ( Runs a program from disk/mem) 
  249. Procedure COM14
  250.    If SEC$="?" Then Print "Run | Run <Filename> | Run DISK " : Pop Proc
  251.    If SEC$="DISK"
  252.       F$=Fsel$("*.AMOS","","Run a file")
  253.       Run F$
  254.    End If 
  255.    N$=Psel$("*.*",SEC$,"Run A FILE IN MEM")
  256.    If N$="" Then Pop Proc
  257.    Prun N$
  258.    Screen Open 7,640,256,8,Hires
  259.    Curs Off : Flash Off 
  260.    Wind Open 1,16,10,74,30,1
  261. End Proc
  262. '                              * Sample (plays a sample bank)  
  263. Procedure COM15
  264.    If SEC$="?" Then Print "Sample | Sample <filename> | Sample BANK | (Use Cursor Keys)" : Pop Proc
  265.    If SEC$="" Then SEC$=Fsel$("*.abk","","Select a Sample bank ")
  266.    If SEC$="BANK" Then SNUM=Deek(Start(5)) : Goto SAMMAIN
  267.    If SEC$="" Then Pop Proc
  268.    Open In 1,SEC$ : L=Lof(1) : E$=Input$(1,24) : Close 1
  269.    POS=Hunt(Varptr(E$) To Varptr(E$)+Len(E$),"Samples")
  270.    If POS<>0
  271.       SNUM=Deek(Varptr(E$)+20) : Rem     Snum= the amount of samples in bank  
  272.       Load SEC$
  273. SAMMAIN:
  274.       X=1 : Sam Play 1 : PLFLAG=0
  275.       While X=>1 and X<=SNUM
  276.          If PLFLAG=1 : Sam Play X : PLFLAG=0 : End If 
  277.          Locate 30,Y Curs-1 : Print Using "##";X; : Print " "; : Print Using "##";SNUM
  278.          If Key State(79)=True : Dec X : PLFLAG=1 : Wait 10 : End If 
  279.          If Key State(78)=True : Inc X : PLFLAG=1 : Wait 10 : End If 
  280.          If Mouse Key=1 : Exit : End If 
  281.       Wend 
  282.       Erase 5
  283.    Else 
  284.       Print "Sorry This is not a Sample Bank"
  285.    End If 
  286. End Proc
  287. '                              * Scankey ( prints ASCII and scancode for keypresses  
  288. Procedure COM16
  289.    If SEC$="?" Then Print "No Parameters" : Pop Proc
  290.    Print "press mouse buttons to quit" : Print 
  291.    While Mouse Key=0
  292.    A$=Inkey$
  293.    If A$<>"" Then Print "chr$ =";A$;" scancode =";Scancode;" ASCII =";Asc(A$)
  294.    Wend 
  295. End Proc
  296. '                              * Sprite (displays sprites)   
  297. Procedure COM17
  298.    If SEC$="?" Then Print "Sprite | Sprite <filename> | Sprite BANK | (Use Cursor Keys)" : Pop Proc
  299.    If SEC$="" Then SEC$=Fsel$("*.abk","","Load a Sprite bank ")
  300.    If SEC$="" Then Pop Proc
  301.    If SEC$="BANK" Then Bgrab 1 : Goto NOLOAD
  302.    Load SEC$
  303. NOLOAD:
  304.    Screen Open 6,320,256,16,Lowres
  305.    Curs Off : Flash Off : Hide 
  306.    Get Sprite Palette 
  307.    SLEN=Length(1) : X=1
  308. While X=>1 and X<=SLEN
  309.    If Mouse Key<>0 Then Exit 
  310.    Wait 10
  311.    Locate 20,0 : Print Using "##";X; : Print " "; : Print Using "##";SLEN
  312.    Sprite 8,X Mouse,Y Mouse,X
  313.    If Key State(79)=True Then Dec X
  314.    If Key State(78)=True Then Inc X
  315. Wend 
  316.    Sprite Off 
  317.    Show 
  318.    Screen Close 6
  319. End Proc
  320. '
  321. '
  322. '
  323. '
  324. '* Data for Command names must be uppercase and in alphabetical order *  
  325. NAMES:
  326. Data "?","CD","CLS","COPY","DFREE","DIR","EXIST","FTYPE","IFF","KILL","MKDIR","MUSIC","QUIT"
  327. Data "RENAME","RUN","SAMPLE","SCANKEY","SPRITE"
  328. '
  329. '************************* 
  330. '** External Procedures **   
  331. '************************* 
  332. '
  333. Procedure FTYPE[FILE$]
  334.    If Left$(FILE$,1)="*" Then Print FILE$ : Pop Proc
  335.    FILE$=Right$(FILE$,Len(FILE$)-1)
  336.    POS=Instr(FILE$," ",1)
  337.    FILE$=Left$(FILE$,POS-1)
  338.    Open In 1,FILE$ : L=Lof(1) : FROM$=Input$(1,30) : Close 1
  339.    _GETSTR[FROM$,FILE$,"Samples","  (Sample Bank)"]
  340.    If Param=1 Then Pop Proc
  341.    _GETSTR[FROM$,FILE$,"AmSp","  (Sprite Bank)"]
  342.    If Param=1 Then Pop Proc
  343.    _GETSTR[FROM$,FILE$,"AMOS Basic","  (Basic program)"]
  344.    If Param=1 Then Pop Proc
  345.    _GETSTR[FROM$,FILE$,"FORM","  (IFF file)"]
  346.    If Param=1 Then Pop Proc
  347.    _GETSTR[FROM$,FILE$,"Pac.Pic","  (Packed file)"]
  348.    If Param=1 Then Pop Proc
  349.    _GETSTR[FROM$,FILE$,"Music","  (Music Bank)"]
  350.    If Param=1 Then Pop Proc
  351.    _GETSTR[FROM$,FILE$,"AmIc","  (Icons Bank)"]
  352.    If Param=1 Then Pop Proc
  353.    Print FILE$,"  (Unknown)"
  354. End Proc
  355. Procedure _GETSTR[FROM$,FILE$,LOOK$,MESSAGE$]
  356.    POS=Hunt(Varptr(FROM$) To Varptr(FROM$)+Len(FROM$),LOOK$)
  357.    If POS<>0 Then Print FILE$;"  ";MESSAGE$ : YES=1
  358. End Proc[YES]
  359. '