amforth-shell.py replaces known mcu register names with their values. This makes it very easy to create a file like this and upload it to the mcu (in this case avr8)
#include ms.frt : low ( mask port -- ) dup c@ rot invert and swap c! ; : high ( mask port -- ) dup c@ rot or swap c! ; : blink ( -- ) #32 DDRB high begin #32 PORTB low 1000 ms #32 PORTB high 1000 ms key? until ; connecting via serial and typing blink makes the led on pin 13 of an uno blink until a key is pressed. However, the Forth system knows nothing about DDRB or PORTB as these were substituted on-the-fly by amforth-shell.py during the upload. This does save some flash memory and does simplify writing code, but it is not always what you want. If you wanted to use PORTB at the interpreter prompt, you can't as it does not exist as a constant. Adding #37 constant PORTB will not help either, as amforth-shell.py still substitutes on-the-fly creating a new word $25, as ' $25 execute . will show. I looked to see if I could turn this behaviour off, but I couldn't find an option to do this. The patch below changes this, adding the option --no-regsub, -X Do NOT replace mcu registers with their values. The default behaviour remains unchanged, with register names substituted on-the-fly. --- ../amforth-6.93/tools/amforth-shell.py 2020-12-03 15:29:07.000000000 +0000 +++ ../amforth-6.93/tools/new-shell.py 2020-12-16 17:42:48.000000000 +0000 @@ -648,9 +648,12 @@ help="Add Include directory") parser.add_argument("--uploaded-wl", "-U", action="store_true", default=False, help="Keep the list of uploaded filenames in the dictionary.") + parser.add_argument("--no-regsub", "-X", action="store_true", default=False, + help="Do NOT replace mcu registers with their values.") parser.add_argument("files", nargs="*", help="may be found via the environment variable AMFORTH_LIB") arg = parser.parse_args() + self.noregsub = arg.no_regsub self.debug = arg.debug_serial self.max_line_length = arg.line_length self._serial_port = arg.port @@ -917,7 +920,7 @@ continue if w in self._appl_defs: w = self._appl_defs[w] - elif w in self._amforth_regs: + elif w in self._amforth_regs and not self.noregsub : w = self._amforth_regs[w] elif w.upper() in self.stdwords: w = w.lower() _______________________________________________ Amforth-devel mailing list for http://amforth.sf.net/ Amforth-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/amforth-devel