Craig (Bender MX) asked: >How do I write a routine to parse anything typed after an Ampersand. >Specifically to give 'command line' functionality (even within a program) >to the & command > >For Example: > >like in Renumber: &F100,I100,etc I find your question very timely, since I just completed an ampersand command parser. ;-) I pieced the information together from several sources, most notably "All About Applesoft" in Call-A.P.P.L.E.'s In Depth series of books. It has examples of ampersand command parsers and lists of ROM entry points that you will need to call. You will need to call ROM parsing functions to evaluate formulas, look up (and possibly create) variables, etc., and these entry points were never formally documented. Unfortunately, the descriptions provided did not have sufficient detail to allow me to code just from the book. I also had to refer to the commented disassembly of Applesoft that was produced with the SOURCEROR disassembler on the Merlin assembler disk. The condition on its use is that the user must posess an authorized Apple II ROM to disassemble. It is a large listing, but should be easy to handle in an emulator that can redirect printer output to a text file, like Apple II Oasis. I'll be making my source public soon, if another example would be useful and you can afford to wait a week or two. ;-) My parser handles 12 commands in 462 bytes of tables & code, and supports any number of value parameters and up to one "output" parameter (a variable whose value is set by the command). Of course, most of the "execute" routines are external to the parser, being part of NadaNet. I found that making it table-driven was the only way to keep the size under control. I can add a new command in about 10 bytes of table plus the code for its execution. All commands are of the form: &COMMAND(P1,P2,...,Pn) where one of the parameters may be specified as a variable into which will return a value. (The scheme I use could support more than one return value, but it wasn't necessary in my application, and supporting only 0 or 1 return values shortened the code.) -michael Check out parallel computing for 8-bit Apples on my Home page: http://members.aol.com/MJMahon/ Bender MX wrote: > How do I write a routine to parse anything typed after an Ampersand. > Specifically to give 'command line' functionality (even within a program) > to the & command > > For Example: > > like in Renumber: &F100,I100,etc I have written ampersand libraries and can answer specific questions and post sample code. The key to ampersand routines is CHRGET and CHRGOT. You can find an article on writing Applesoft ampersand routines at www.syndicomm.com/~a2.ryan/GenieLamp_A2Pro/Text/1996/aplp9601.txt There is a disassembly of Applesoft at http://cosmicwolf.com/AppleII/AppleSoft_Commented.htm The following Apple Tech Info Library (TIL) articles are useful: 57 Applesoft Internals: Program storage format http://docs.info.apple.com/article.html?artnum=57 72 Applesoft Internals: Using Applesoft ROM Subroutines (1 of 2) 73 Applesoft Internals: Using Applesoft ROM Subroutines (2 of 2) 74 Applesoft Internals: Floating Point Math Package (1 of 2) 75 Applesoft Internals: Floating Point Math Package (2 of 2) 77 Applesoft Internals: String Utilities 83 Applesoft Internals: Index to Routines (1 of 2) 84 Applesoft Internals: Index to Routines (2 of 2) 92 Applesoft Internals: Page Zero Memory Map 1798 Applesoft Internals: Where to find routines Use the routine descriptions from the TIL articles above to understand the samples below. SAMPLE #1: given "& x,y" do "POKE x,y" where x and y are numbers or numeric expressions. If you trace the POKE command at $E77B you will see this code. 0300 20 67 DD JSR $DD67 ;FRMNUM 0303 20 52 E7 JSR $E752 ;GETADR 0306 20 BE DE JSR $DEBE ;CHKCOM 0309 20 F8 E6 JSR $E6F8 ;GETBYT 030C 8A TXA 030D A0 00 LDY #$00 030F 91 50 STA ($50),Y ;LINNUM 0311 60 RTS SAMPLE #2: given "& x,v" do "v=PEEK(x)" where x is a number or numeric expression and v is an integer or floating point variable. 0312 20 67 DD JSR $DD67 ;FRMNUM 0315 20 52 E7 JSR $E752 ;GETADR 0318 A0 00 LDY #$00 031A B1 50 LDA ($50),Y ;LINNUM 031C 48 PHA ;save value 031D 20 BE DE JSR $DEBE ;CHKCOM 0320 20 E3 DF JSR $DFE3 ;PTRGET 0323 A6 11 LDX $11 ;VALTYP 0325 F0 03 BEQ $032A ;=>numeric, okay 0327 4C C9 DE JMP $DEC9 ;SYNERR 032A A6 12 LDX $12 ;INTFLG 032C F0 0A BEQ $0338 ;=>real 032E A0 01 LDY #$01 0330 68 PLA ;restore value 0331 91 83 STA ($83),Y ;VARPNT 0333 88 DEY 0334 98 TYA 0335 91 83 STA ($83),Y ;VARPNT 0337 60 RTS 0338 68 PLA ;restore value 0339 A8 TAY 033A 20 01 E3 JSR $E301 ;SNGFLT 033D A6 83 LDX $83 ;VARPNT 033F A4 84 LDY $84 ;VARPNT+1 0341 4C 2B EB JMP $EB2B ;MOVMF -- Paul R. Santa-Maria Monroe, Michigan USA In article <41919DBA.6509F202@buckeye-express.com>, "Paul R. Santa-Maria" wrote: > Bender MX wrote: > > How do I write a routine to parse anything typed after an Ampersand. > > Specifically to give 'command line' functionality (even within a program) > > to the & command > > > > For Example: > > > > like in Renumber: &F100,I100,etc > > I have written ampersand libraries and can answer > specific questions and post sample code. > > The key to ampersand routines is CHRGET and CHRGOT. > > You can find an article on writing Applesoft ampersand routines at > www.syndicomm.com/~a2.ryan/GenieLamp_A2Pro/Text/1996/aplp9601.txt > > There is a disassembly of Applesoft at > http://cosmicwolf.com/AppleII/AppleSoft_Commented.htm > > The following Apple Tech Info Library (TIL) articles are useful: > 57 Applesoft Internals: Program storage format > http://docs.info.apple.com/article.html?artnum=57 > 72 Applesoft Internals: Using Applesoft ROM Subroutines (1 of 2) > 73 Applesoft Internals: Using Applesoft ROM Subroutines (2 of 2) > 74 Applesoft Internals: Floating Point Math Package (1 of 2) > 75 Applesoft Internals: Floating Point Math Package (2 of 2) > 77 Applesoft Internals: String Utilities > 83 Applesoft Internals: Index to Routines (1 of 2) > 84 Applesoft Internals: Index to Routines (2 of 2) > 92 Applesoft Internals: Page Zero Memory Map > 1798 Applesoft Internals: Where to find routines > > Use the routine descriptions from the TIL articles above > to understand the samples below. > > SAMPLE #1: given "& x,y" do "POKE x,y" where x and y > are numbers or numeric expressions. In addition, you can use Applesoft's tokens (page 121 of the Applesoft Reference manual) directly in your expressions. For example, "& PEEK x, y" will be stored with a one-byte token ($E2) after the ampersand: * & PEEK x, y Command1 CMP #$E2 BNE Command2 JSR CHRGET ... * & POKE x, y Command2 CMP #$B9 BNE Command3 JSR GHRGET ... [...] > -- > Paul R. Santa-Maria > Monroe, Michigan USA -- John ---- jmatthews at wright dot edu www dot wright dot edu/~john.matthews/ John B. Matthews wrote: >In addition, you can use Applesoft's tokens (page 121 of the >Applesoft Reference manual) directly in your expressions. For >example, "& PEEK x, y" will be stored with a one-byte token ($E2) >after the ampersand: > >* & PEEK x, y >Command1 CMP #$E2 > BNE Command2 > JSR CHRGET > ... >* & POKE x, y >Command2 CMP #$B9 > BNE Command3 > JSR GHRGET And, for completeness, you can also mix ASCII characters with Applesoft tokens, as in &PEEKINC. The Applesoft "parser" replaces all un-quoted substrings that match a token spelling with a single byte token. When a program is LISTed, the tokens will be reconstituted as their ASCII spelling, set off by spaces. (So &PEEKINC will LIST as: & PEEK INC but what is stored in the Applesoft "text" is: <& token $AF>INC -michael Check out parallel computing for 8-bit Apples on my Home page: http://members.aol.com/MJMahon/ John B. Matthews wrote: >In addition, you can use Applesoft's tokens (page 121 of the "Michael J. Mahon" wrote: > And, for completeness, you can also mix ASCII characters with > Applesoft tokens, as in &PEEKINC. All true. I was trying to keep my examples simple. Here is an ampersand command parser that uses tokens and ASCII: ldx #0 ;init CmdTbl index stx CmdNum ldy #0 ;init TXTPTR index lda CmdTbl ; *! repeat cmp #$FF ;end of table? *! if do.n jmp SyntaxErr ;yes, error *! endi cmp (AS.TXTPTR),y ;char in line *! if do.n *! repeat inx lda CmdTbl,x ;char from table *! loop until do.n inc CmdNum ldy #$FF *! endi iny ;incr TXTPTR index inx ;incr CmdTbl index lda CmdTbl,x ;get cmd char *! loop until do.n ; jsr AS.ADDON ;fix-up TXTPTR lsl CmdNum ;times 2 for 2-byte adr ldx CmdNum lda CmdAdrTbl+1,x pha lda CmdAdrTbl,x pha rts ; ; local data for parser ; CmdNum .block 1 ;local data ; msb off CmdTbl equ * ; .ascii 'BUZZ' .byte 0 ;BUZZ ; .byte 189,0 ;CLEAR ; .byte 150,0 ;HTAB ; .ascii 'SWAP' .byte 208,0 ;SWAP= ; .byte 181,0 ;WAIT ; .byte 228,0 ;STR$ ; .byte 137,0 ;TEXT ; .byte 132,0 ;INPUT ; .byte $FF ;end of table marker ; CmdAdrTbl equ * .word Buzz-1 .word ClearArray-1 .word HTAB-1 .word Swap-1 .word Wate-1 .word StringFunc-1 .word Text-1 .word Input-1 ; & BUZZ ; ; & CLEAR { , } ; clear an array to zeros or null strings. ; ; & HTAB N ; an HTAB that really works for 40/80 columns ; ; & SWAP = , ; swap two variables of any one type ; ; & WAIT N ; pauses for N tenths of a second ; ; & STR$ ; string functions ; 0,S$,N sets S$ to N formatted with S$ ; 1,S$ change blanks to sticky spaces in string ; 2,S$ remove blanks from string ; 3,S$ capitalize string ; 4,S$ remove leading and trailing blanks from a string ; ; & TEXT ; 80 column text screen functions ; 0,Top,Left,Bottom,Right clear window ; 1,Top,Left,Bottom,Right scroll window up ; 2,Top,Left,Bottom,Right scroll window down ; 3,Top,Left,Bottom,Right scroll window left ; 4,Top,Left,Bottom,Right scroll window right ; 5,Top,Left,Bottom,Right inverse window ; ; & INPUT S$,N ; fancy keyboard input routine ; S$ = default input string -- Paul R. Santa-Maria Monroe, Michigan USA "John B. Matthews" wrote: > I am unfamiliar with some of the > syntax. Are those macros? Can you elaborate? *! repeat *! if do.n *! endi *! if do.n *! repeat *! loop until do.n *! endi *! loop until do.n They are commands to a preprocessor I wrote called SALP (Structured Assembly Language Preprocessor). SALP only generates branches and labels so no registers or flags are changed. SALP is written in SALP. I released SALP v1.0 at Kansasfest 1991. The command parser is written using Edasm and an early version of SALP. The release version of SALP works with Merlin and the above structure commands changed to: *! loop *! if *! endi *! if *! loop *! until *! endi *! until SALP and documentation are online at http://www.apple2.org.za/mirrors/ground.icaen.uiowa.edu/upl1998/Nov98/ -- Paul R. Santa-Maria Monroe, Michigan USA