This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| amforth [2007-07-09 19:20] – nik | amforth [2007-07-24 16:10] (current) – nik | ||
|---|---|---|---|
| Line 22: | Line 22: | ||
| </ | </ | ||
| + | |||
| + | |||
| ==== hello world (aka, blinking an LED) ==== | ==== hello world (aka, blinking an LED) ==== | ||
| Line 91: | Line 93: | ||
| < | < | ||
| : blink -- , blink PORTC5 for 100ms 20 35 c! 64 ms 0 35 c! 64 ms ; | : blink -- , blink PORTC5 for 100ms 20 35 c! 64 ms 0 35 c! 64 ms ; | ||
| - | </ | + | </ |
| - | + | ||
| - | </ | + | |
| NOTE: 100 is 0x64 in hex, so pauses for 100ms. | NOTE: 100 is 0x64 in hex, so pauses for 100ms. | ||
| Line 99: | Line 99: | ||
| then a word to blink multiple times: | then a word to blink multiple times: | ||
| - | | ||
| < | < | ||
| : blinks n -- , blink n times 0 do blink loops ; | : blinks n -- , blink n times 0 do blink loops ; | ||
| - | </ | + | </ |
| - | + | ||
| + | so now | ||
| < | < | ||
| Line 159: | Line 159: | ||
| </ | </ | ||
| + | |||
| ==== backing up ==== | ==== backing up ==== | ||
| Line 180: | Line 181: | ||
| ---- | ---- | ||
| - | [[/ | ||
| - | < | ||
| - | </ | + | |
| ---- | ---- | ||
| Libarynth > Libarynth Web > AmForth r4 - 09 Mar 2007 - 11:56 | Libarynth > Libarynth Web > AmForth r4 - 09 Mar 2007 - 11:56 | ||
| ---- | ---- | ||
| + | |||
| + | ==== amforth-upload.py ==== | ||
| + | < | ||
| + | |||
| + | |||
| + | # | ||
| + | |||
| + | # amforth-upload.py | ||
| + | # | ||
| + | # | ||
| + | # | ||
| + | # also waits for a prompt after each line to allow the compiler a chance to run | ||
| + | # | ||
| + | # in theory it should never overrun the input buffer on the controller, | ||
| + | # but it will easily get stuck if the output from the controller is unusual | ||
| + | # | ||
| + | # you have to kill any other processes that are accessing the serial port before running this, | ||
| + | # | ||
| + | # | ||
| + | # | ||
| + | # like x/y/zmodem for minicom (except for the difficulty of killing it when it gets confused). oh well. | ||
| + | # | ||
| + | # | ||
| + | # | ||
| + | |||
| + | |||
| + | import sys | ||
| + | import getopt | ||
| + | import os | ||
| + | import re | ||
| + | |||
| + | def write_line_flow(string, | ||
| + | # strip comments | ||
| + | # these probably will strip comment-like structures out of ." .." strings as well. | ||
| + | |||
| + | if debug: | ||
| + | print >> | ||
| + | |||
| + | string = re.sub(" | ||
| + | string = re.sub(" | ||
| + | string = re.sub(" | ||
| + | |||
| + | if re.match(" | ||
| + | if verbose: | ||
| + | print >> | ||
| + | return | ||
| + | |||
| + | if debug: | ||
| + | print >> | ||
| + | |||
| + | if verbose: | ||
| + | print >> | ||
| + | for o in list(string): | ||
| + | dest.write(o); | ||
| + | |||
| + | if o == " | ||
| + | o = " " | ||
| + | |||
| + | while True: | ||
| + | i = dest.read(1) | ||
| + | #print "<" | ||
| + | #print >> | ||
| + | sys.stdout.write(i) | ||
| + | sys.stdout.flush() | ||
| + | if i == o: | ||
| + | #print " | ||
| + | break | ||
| + | # | ||
| + | if verbose: | ||
| + | print >> | ||
| + | |||
| + | start, nl, space, o, gt = range(5) | ||
| + | |||
| + | state = start | ||
| + | |||
| + | while True: | ||
| + | #print >> | ||
| + | # | ||
| + | i = dest.read(1) | ||
| + | #print "<" | ||
| + | #print >> | ||
| + | sys.stdout.write(i) | ||
| + | sys.stdout.flush() | ||
| + | if state == start: | ||
| + | if i == " | ||
| + | state = nl | ||
| + | elif i == " ": | ||
| + | state = space | ||
| + | continue | ||
| + | elif state == nl: | ||
| + | if i == ">": | ||
| + | state = gt | ||
| + | else: | ||
| + | state = start | ||
| + | continue | ||
| + | elif state == gt: | ||
| + | if i == " ": | ||
| + | if debug: | ||
| + | print >> | ||
| + | break | ||
| + | else: | ||
| + | state = start | ||
| + | continue | ||
| + | elif state == space: | ||
| + | if i == " | ||
| + | state = o | ||
| + | else: | ||
| + | state = start | ||
| + | continue | ||
| + | elif state == o: | ||
| + | if i == " | ||
| + | if debug: | ||
| + | print >> | ||
| + | break | ||
| + | else: | ||
| + | state = start | ||
| + | |||
| + | |||
| + | |||
| + | |||
| + | def write_file_flow(in_file, | ||
| + | while(True): | ||
| + | line = in_file.readline() | ||
| + | if len(line)> | ||
| + | write_line_flow(line, | ||
| + | else: | ||
| + | break | ||
| + | |||
| + | def main(argv): | ||
| + | |||
| + | global verbose, debug | ||
| + | |||
| + | #in_file = file(" | ||
| + | #tty_dev = file("/ | ||
| + | |||
| + | tty_dev_name = "/ | ||
| + | force = False | ||
| + | verbose = False | ||
| + | debug = False | ||
| + | |||
| + | try: | ||
| + | opts, args = getopt.getopt(argv," | ||
| + | except getopt.GetoptError: | ||
| + | print >> | ||
| + | sys.exit(1) | ||
| + | |||
| + | for opt, arg in opts: | ||
| + | if opt == " | ||
| + | print >> | ||
| + | print >> | ||
| + | print >> | ||
| + | print >> | ||
| + | print >> | ||
| + | sys.exit(1) | ||
| + | elif opt == " | ||
| + | tty_dev_name = arg | ||
| + | elif opt == " | ||
| + | verbose = True | ||
| + | elif opt == " | ||
| + | force = True | ||
| + | elif opt == " | ||
| + | debug = True | ||
| + | |||
| + | if not force: | ||
| + | if not os.system(" | ||
| + | if not os.system(" | ||
| + | print >> | ||
| + | print >> | ||
| + | sys.exit(1) | ||
| + | else: | ||
| + | print >> | ||
| + | print >> | ||
| + | |||
| + | |||
| + | tty_dev = file(tty_dev_name," | ||
| + | |||
| + | if len(args)< | ||
| + | if verbose: | ||
| + | print >> | ||
| + | write_file_flow(sys.stdin, | ||
| + | else: | ||
| + | for filename in args: | ||
| + | in_file = file(filename," | ||
| + | if verbose: | ||
| + | print >> | ||
| + | write_file_flow(in_file, | ||
| + | in_file.close() | ||
| + | |||
| + | |||
| + | |||
| + | if __name__ == " | ||
| + | main(sys.argv[1: | ||
| + | |||
| + | </ | ||