!pr0
!lm12
!rm75
Amper-Monitor..............................Bob Sander-Cederlof

It would be nice to be able to use monitor commands from within Applesoft, both in direct commands and within running Applesoft programs.  At least Kraig Arnett, from Homestead, Florida, thinks so.

I agree, and so I whipped out another handy-dandy &-subroutine for just that purpose.  I call it Amper-Monitor.  You can install it by BRUNning it from a binary file, or by adding some POKEs to your Applesoft program.  My listing shows it residing at the ever popular $300 address, but it can be reassebled to run anywhere.  Just remember to connect it properly to the Ampersand Vector.

Once Amper-Monitor is installed and hooked to the ampersand vector, you call it by typing an ampersand, a quotation mark, and a monitor command.  Here is a sample program showing some uses of the Amper-Monitor.

!lm+5
100 FOR I = 768 TO 855
110 READ D : POKE I,D : NEXT
120 CALL 768

130 &"300.357
140 &"380:12 34 56 78 9A BC DE F0
150 &"FBE2G
160 &"300L 380.387

200 DATA 169,11,141,246,3,169,3,141,247,3,96
210 DATA 201,34,208,70,32,177,0,160,0,177,184,201,0
220 DATA 240,8,9,128,153,0,2,200,208,242,169,141
230 DATA 153,0,2,152,24,101,184,133,184,144,2,230
240 DATA 185,32,199,255,32,167,255,132,52,160,23
250 DATA 136,48,23,217,204,255,208,248,192,21,240
260 DATA 8,32,190,255,164,52,76,52,3,32,197,255
270 DATA 76,0,254,76,201,222
!lm-5

Why did I choose to require the quotation mark after the ampersand?  Because normally Applesoft would parse the line, eliminating blanks, changing DEF to a token instead of three hex digits, using ":" to end a line, and so on.  Using the "-mark prevents all this, leaving the line in raw ASCII form.  Here is a listing of the program in assembly language:
!np


































Lines 1200-1240 link in the ampersand vector.  This is the only part that would have to be changed if you move the routine.

When Applesoft sees an "&", it will JSR to AMPER.MONITOR.  The A-register will hold the character following the "&", which we hope is a quotation mark.  Lines 1270 and 1280 do this hoping.

Lines 1290-1380 copy the characters following the quotation mark into the monitor buffer starting at $200.  If you typed in the &"... as a direct command, it is already in the monitor buffer but starts at $202, so it gets shifted over two bytes.  If the command is in a program, it will be copied out of program space into $200.  Applesoft has stripped off the sign bit from every byte, so my loop adds the sign bit back in to satisfy the monitor's requirements.  Applesoft ends the line with a $00 byte, and the monitor wants $8D, so I fix that up too.  I don't let colon terminate the line, because colon is a valid character in a monitor command line.  I use "LDA (TXTPTR),Y" rather than repeated calls to AS.CHRGET because AS.CHRGET would eliminate blanks.

Lines 1390-1440 adjust the Applesoft pointer to the end of the line, so upon returning we won't get false syntax errors and the Applesoft program can continue executing.

Lines 1450-1590 parse the command line one command at a time, call on the monitor to execute each command, and finally return to Applesoft after the last command on the line.  (The idea for this code came originally from code Steve Wozniak wrote for the mini-assembler in the old Apple monitor ROM.)  Note that an illegal monitor command will result in a syntax error.

I thought it would now be possible to use the Amper-Monitor to write hex dumps on text files...BUT:  Unfortunately DOS uses some critical zero page locations which prevent using the Amper-Monitor while writing on a text file.  Monitor commands use locations $3D through $42, and so does DOS.  I tried using the &"300.357 to do a hex dump into a text file, but DOS went wild and clobbered itself.  Sorry, but I see no solution without changing DOS or recoding the entire monitor.
