Shop OBEX P1 Docs P2 Docs Learn Events
PropellerForth — Parallax Forums

PropellerForth

Cliff L. BiffleCliff L. Biffle Posts: 206
edited 2007-04-02 12:27 in Propeller 1
Over the past week or so, I've been working on PropellerForth, a mostly ANS-compliant Forth for the P8X32 chip. This is a trial balloon to see if there are any Forthies in the audience. (Or, for that matter, anyone who would like to have an interactive development environment on the Propeller itself, and is willing to learn Forth to get there.)

RATIONALE
I really dig the Propeller, but I don't really like writing large applications in assembler. For a while, I considered developing a typesafe, optimized version of Spin (which has very nice attributes, like the component [noparse][[/noparse]n
«1

Comments

  • Eviatar TsadokEviatar Tsadok Posts: 6
    edited 2006-11-01 18:36
    Hay Cliff

    Interactive Forth sound cool.
    I worked with RSC-Forth long time ago, I will be happy to work with this kind of solution.

    Eviatar
  • Paul BakerPaul Baker Posts: 6,351
    edited 2006-11-01 19:06
    Looking forward to your release. Forth is a language I've played around with and written a couple bastardized versions for microcontrollers, but never had an opportunity to use it·much for application development. Too bad PForth is already taken for a name.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Paul Baker
    Propeller Applications Engineer

    Parallax, Inc.
  • cgraceycgracey Posts: 14,133
    edited 2006-11-01 19:33
    Yeah, Cliff!

    I think if you could make this stand-alone, it would be especially interesting. Host computers are always orphaning projects. One that would still be accessible 30 years from now might be useful.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔


    Chip Gracey
    Parallax, Inc.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2006-11-01 19:46
    Cliff,

    Who's your father? Chuck Moore? wink.gif

    Seriously, this looks really cool! Forth can be an excellent bridge language between the user and the metal when speed is of the essence. It's often gotten a bad rap for being unreadable and, in truth, it's very easy to write unreadable code with it. But that's true of almost any language.

    One thing I'd like to see, unless you're an ANSI Forth purist, is a wrap-around expression stack. Stack maintenance is the bane of Forth programmers. It would be nice just to be able to abandon a non-empty stack when you're done with it, rather than having to remember how much stuff to pop off. Implementing the stack like a queue might solve this problem, in that stuff that's not needed eventually just gets pushed off the end. Also stack overflow and underflow go away -- although this would be a bad thing for debugging. An alternative would be what Postscript does with its mark and cleartomark operators. Postscript is strongly typed, though, so a mark can be unique. In Forth, you'd have to keep separate track of any that were on the stack. (It's been awhile since I've done anything with Forth, so maybe this has been addressed in a later standard.)

    Anyway, good luck with the project! I'm anxious to see more! And I've already got an app (four-axis mill) I wrote years ago in Forth for Zilog's Super-8 that I'd love to port to the Propeller.

    -Phil
  • Cliff L. BiffleCliff L. Biffle Posts: 206
    edited 2006-11-01 22:58
    Glad folks are interested.
    Chip Gracey said...
    I think if you could make this stand-alone, it would be especially interesting.

    That's the goal. It's already standalone if you have a serial terminal. smile.gif

    I'm working with your TV and VGA drivers, trying to embed them. (As I mentioned in a previous post, the main stumbling block is propasm's lack of constant expression support.) I'm not confident that Forth will be fast enough to drive the display itself -- not at 1.4m words/sec. It'll have to be native code.

    My ultimate goal involves TV, PS/2, and SD mass storage -- but I won't overcommit until I get the thing shipped.
    Phil Pilgrim said...
    Who's your father? Chuck Moore?

    No, though they do have stories about each other.
    Phil Pilgrim said...
    Seriously, this looks really cool! Forth can be an excellent bridge language between the user and the metal when speed is of the essence. It's often gotten a bad rap for being unreadable and, in truth, it's very easy to write unreadable code with it. But that's true of almost any language.

    Forth is the essence of what we now call "domain-specific languages." It can be evolved to look like just about anything. If a programmer doesn't put thought into it, it can become far worse than Perl.

    But in skilled hands, it produces some of the most elegant code I've seen. (Yes, I would rank it with or above Smalltalk.)
    Phil Pilgrim said...
    One thing I'd like to see, unless you're an ANSI Forth purist, is a wrap-around expression stack.

    I'm not an ANS purist, but that's pushing it. smile.gif

    It's pretty straightforward to define words that reset the stack to a previously stored location, like in Postscript. They're used in some of the try/finally type constructs for writing guard blocks.

    (Incidentally, what the hell were you doing writing Postscript? You've passed even my geek threshold here.)

    There are other approaches -- ANS forth supports local variables, for example -- but in general, if stack management is becoming a chore, your word definitions are too long. This is something I keep relearning over and over, and never really applying. smile.gif
    Paul Baker said...
    Too bad PForth is already taken for a name.

    Hey, now. I don't think PropellerForth is so bad. smile.gif

    The directory on my disk is actually called P8x32Forth, so it can certainly be worse....
  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2006-11-01 23:26
    Goodonya (well done) Cliffe! Yes, I had started to write a token threaded Forth but alas I have been moving and setting-up this past month or so. Not only that but where I am is not Broadband enabled (maybe wireless) and connecting to the net at 28.8K is painful. I have written Forths for many 8/16/32-bit processors and most of my high-level embedded apps are written in it. Can we work together on developing this Forth? I am looking at making the spinning 8-bladed propeller dohickey go completely pcless and run development totally from the PS/2 keyboard and VGA with SD card storage.


    *Peter*
  • Cliff L. BiffleCliff L. Biffle Posts: 206
    edited 2006-11-01 23:40
    Peter Jakacki said...
    Can we work together on developing this Forth?

    When PropellerForth is released (after I do some more testing and iron out some kinks), it will be under an open source license, and hosted on one of the collaborative development sites (probably Google Code, but possible SourceForge). At that point, I'm happy to accept enhancements, bugfixes, additions, and the like from anyone on the 'net.

    I will be passing out prerelease archives on the forums shortly, and I encourage you (and everyone else) to bang on them and tell me what I screwed up. smile.gif
  • mike101videomike101video Posts: 43
    edited 2006-11-01 23:54
    Cliff,
    This will be wonderful. I have always liked the interactive development in Forth.

    Really looking forward to getting my hands on it.

    Mike
  • vandysvandys Posts: 4
    edited 2006-11-02 02:25
    I'm a hard core Forth'er (see www.forthos.org)... I think this would be awesome to shake out!
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2006-11-02 03:44
    Cliff L. Biffle said...
    Incidentally, what the hell were you doing writing Postscript?
    For a time, many years ago, I was blessed with a Postscript laser printer and cursed with a DOS computer, while all the Cool People had those new-fangled Macs. So programming Postscript was the only way I could get decent graphical output. I still use it occasionally to produce code wheels for encoders and the like.

    -Phil
  • CCraigCCraig Posts: 163
    edited 2006-11-02 13:28
    I'm normally on the BS2 side. I think this could be a great thing to draw people over to the Propeller. Forth would be a great addition to the tools. Sign me up.

    Chris
  • Cliff L. BiffleCliff L. Biffle Posts: 206
    edited 2006-11-06 05:41
    Brief status update:

    I've got most of the useful words from the ANS core set working, and have been doing a lot of reworking and simplification.

    What Works:
    - Interpreted interactive exploration (including defining words)
    - Most necessary primitives (including hub operations and doubleword multiplication)
    - Host "compilation" of words into the image (really just a Ruby preprocessor to assembler, I'm not using a Forth cross-compiler).
    - Most interesting Propeller-specific functions (I/O, control of the counters, Cog control)
    - A small subset of the ANS String word set.

    What Doesn't:

    The main stumbling block at this point is storage. I don't have any extra EEPROMs strung off the Propeller and the SD module I wanted (at SparkFun) is out of stock. Without mass storage, there's no realistic way to store, compile, and recompile the sources on the Propeller itself -- so this is taking priority over other self-hosting issues (such as keyboard and TV).

    I'm considering writing elementary serial file transfer support (XMODEM or ZMODEM) and faking it that way, but we'll see.

    Other elementary things that aren't working include:
    - Multitasking, either within a Cog or across Cogs. (Not all the USER vars are being accessed through USER currently, so I can't separate tasks. This should be fixed this evening; I'm most of the way there.)
    - Handy programming tools like DUMP, FORGET, and SEE.
    - Direct EEPROM access.


    I'm doing this primarily for fun and to learn the architecture, so I'm hesitant to involve others too early; however, I encourage interested parties to contact me. I'll have code for testing soon.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2006-11-06 06:05
    Cliff,

    Just out of curiosity, how are you storing dictionary symbols? The first three letters and a length, or the whole enchelada?

    Also, my own preference as a potential user would be to forget the Propeller-resident editing and file ops for now (which I'd likely never use), in favor of a complete and rich set of native words, including strings and conversions.

    Thanks,
    -Phil
  • Cliff L. BiffleCliff L. Biffle Posts: 206
    edited 2006-11-06 06:46
    Phil Pilgrim said...
    Just out of curiosity, how are you storing dictionary symbols?

    Length+7, case preserved (though user input is case-insensitive). My older Forths tended to use length+3, but I kept running into conflicts; a lot of Forth-83s used Length+7 and I think I've got the RAM to spare here.

    I am currently storing all symbol information in the dictionary, but I plan to split it out so an image can optionally be stripped. (My embedded applications rarely use EVAL or INTERPRET.)
    Phil Pilgrim said...
    Also, my own preference as a potential user would be to forget the Propeller-resident editing and file ops for now (which I'd likely never use), in favor of a complete and rich set of native words, including strings and conversions.

    Well, that's certainly where I'm headed now, but it's mostly for lack of spare parts. smile.gif

    We currently have decent String support (.", S", COMPARE, and some other goodies). I'm eschewing counted-string support in favor of the c-addr +u strings that the ANS folks like -- of course, any user could add counted string support trivially.

    I don't have any of the pictured numeric output words working (<# #>); I only recently got division working, so base conversion and formatting were pretty far down on the list. smile.gif

    So, keeping in mind that the only way to compile Forth properly is Forth, how would you want to do your development? I can certainly document the dictionary layout and primitives, which would allow you (or others) to write a hosted cross-compiler in some other Forth.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2006-11-06 07:58
    Cliff,

    The way I'd prefer to develop for a system like this is to use an editor like UltraEdit. If you had a shell command which then uploaded the raw source to the Propeller (e.g. fterm -f mysource.forth), your resident firmware could compile it as it came in. fterm would dump the stuff that comes back to STDOUT (which UltraEdit captures). Once uploading is complete, it could pop up an interactive terminal window (maybe only if a -t modifier were present on the command line) for testing words, etc. Anything entered or received would also get dumped to STDOUT.

    Forth itself would have to have a built-in word to transfer the compiled image to EEPROM. That way it could be done interactively in the terminal window. Or the "store" command could be placed at the end of the source code.

    -Phil

    Post Edited (Phil Pilgrim (PhiPi)) : 11/6/2006 8:02:26 AM GMT
  • Cliff L. BiffleCliff L. Biffle Posts: 206
    edited 2006-11-06 16:00
    Phil Pilgrim said...
    The way I'd prefer to develop for a system like this is to use an editor like UltraEdit.

    UltraEdit?! Holy Smile, is it still around? Neat! I actually remember it from back when I was on Windows!

    I'm a vi guy myself for everything but Java (mmm, Eclipse), so I can't blame you.
    Phil Pilgrim said...
    If you had a shell command which then uploaded the raw source to the Propeller (e.g. fterm -f mysource.forth), your resident firmware could compile it as it came in. fterm would dump the stuff that comes back to STDOUT (which UltraEdit captures).

    This is pretty much the hack I was proposing when I referenced XMODEM, though I was going to use an actual transfer protocol (with error correction and such) rather than just piping it.

    I could hide that behind the script, of course. I'll see what I can do.


    For me, of course, I'd rather write all my code in a Forth, even if it means I have to give up vi. Filing in Forth sources can have a lot of unintended side effects, since the source includes executable commands (or, really, is executable commands). If there's a syntax error halfway through, you can't roll the previous changes back.

    (Sure, there's FORGET, but that's not complete. This pickiness probably comes from my day job working on transactional systems.)

    Creating a word at a time in Forth helps prevent this.
  • rokickirokicki Posts: 1,000
    edited 2006-11-06 17:48
    I live very close to you (I am in Palo Alto) and I would be delighted to lend you my SD card setup.
    I would even be happy to contribute in some small way to the programming, if you felt that would
    be worthwhile.

    The SD card setup is just the SparkFun socket with a .1" header soldered to it so it can be plugged
    in to a breadboard, along with all the resistors needed to make it all fly on the demo board.

    You can email me at rokicki at gmail.com if you are interested.

    (Actually at some point it might be interesting to do a Bay Area Propeller Group or some such,
    maybe in conjunction with the robot club or maybe separately.)
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2006-11-06 17:53
    Cliff,

    I think XMODEM would be overkill here and waste too many precious Propeller resources. But I do get your point about unintended side effects. One bad word, and you get a whole cascade of errors. Perhaps the PC-resident uploader could me made just a little bit smart and stop uploading when it saw the first error. Or define a Forth word that sets a flag that terminates compiling and enters flush mode on the first error.

    In this environment, I'm not terribly concerned about rolling changes back, or even using FORGET, since I can just make my corrections in UltraEdit and upload the whole thing again. If I wanted to be interactive, I'd just run fterm -t without the -f and enter stuff by hand.

    The main point, I guess, is to keep from having to store any raw source in the Propeller. You'll run out of room way too soon. Hence the upload-with-compile-on-the-fly suggestion. This is the way I developed with Forth on the Zilog Super8 (may it rest in peace), and it worked quite well.

    -Phil
  • Cliff L. BiffleCliff L. Biffle Posts: 206
    edited 2006-11-06 20:22
    rokicki said...
    I live very close to you (I am in Palo Alto) and I would be delighted to lend you my SD card setup.
    I would even be happy to contribute in some small way to the programming, if you felt that would
    be worthwhile.

    Rock on. Which SD board do you have -- the raw breakout board, or the DOSonCHIP FAT controller? (I'm looking at the latter; all the automation of the GHI controllers, with a less stupid protocol. I'm trying not to have a FAT implementation on the Propeller if I can help it.)
    rokicki said...
    (Actually at some point it might be interesting to do a Bay Area Propeller Group or some such,
    maybe in conjunction with the robot club or maybe separately.)

    I'd be interested.
  • Cliff L. BiffleCliff L. Biffle Posts: 206
    edited 2006-11-06 20:31
    Phil Pilgrim said...
    I think XMODEM would be overkill here and waste too many precious Propeller resources.

    XMODEM is remarkably simple, too much so for most purposes. It's either that, or reinvent it (write my own protocol with some basic handshaking and CRCs).

    Using XMODEM would also let Windows users use HyperTerminal or whatever, and allow Unix folks to use standard tools. (Why anyone uses HyperTerminal for anything is beyond me, I admit.) I'm not super interested in writing a cross-platform terminal emulator -- or even a platform-specific one -- when there are so many good open source ones available. I'd rather just use Minicom.

    The scheme I'm working on would have the PC upload a chunk of source, and the Propeller compile it; repeat as necessary. I'm using the word "chunk" to distinguish it from Forth's traditional "block" -- this would not be a 64x16 grid of characters, but rather a text segment with normal line endings.

    At the most granular level, this would be a single colon def, variable definition, etc. More realistically, individual source files of a kilobyte or three could be sent. A simple script could automate your transfer program to upload a directory of source files in a defined order.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2006-11-06 21:00
    Cliff,

    I assume, even with the XMODEM option, that a straight-ASCII, line-oriented, compile-on-the-fly mode will still be there by default, since this is Forth's normal mode of operation — right? Will the compiler be fast enough not to require serial handshaking at, say, 9600 baud, if it were being force-fed?

    -Phil
  • Cliff L. BiffleCliff L. Biffle Posts: 206
    edited 2006-11-06 22:18
    Phil Pilgrim said...
    I assume, even with the XMODEM option, that a straight-ASCII, line-oriented, compile-on-the-fly mode will still be there by default, since this is Forth's normal mode of operation — right?

    Yes -- in fact, this works right now, though it has a couple deviations from ANS that I'm working on.

    Currently the terminal is 19200 8n1, and works just fine. I've tried pasting sources into HyperTerminal (to simulate what most users will experience) and it mangles them really, really badly. I blame HyperTerminal; I'll try it in minicom when I get home to the hardware.

    Feeding sources this way (from a competent terminal emulator) should be possible, but like most traditional Forth compilers, mine is O(size of dictionary) for speed -- each lookup must traverse a linked list. So, you might want to introduce a brief delay between lines (a few bytes worth of bit periods should be fine).

    I'm going to play with this more tonight when I'm home, and I'll post results. (And also possibly pass out binaries.)
  • Cliff L. BiffleCliff L. Biffle Posts: 206
    edited 2006-11-07 00:27
    So, an update to what I said before:

    Currently, files can be "typed" into PropellerForth by using your terminal emulator's "send as ASCII" feature. The compiler will process your file a line at a time, storing no more than 80 characters in RAM at any point. This lets you build up the dictionary in-place without any mass storage.

    It's less than ideal, but it works.

    There's one main caveat: the terminal routines are in Forth, have not been optimized, and are not terribly fast. At 19200bps (the default terminal speed), you'll want a character-to-character delay of about 1ms, and a line-to-line delay of 50ms. Most terminal emulators support this.

    Yes, this is annoying. Yes, it will be fixed.
  • Cliff L. BiffleCliff L. Biffle Posts: 206
    edited 2006-11-09 07:31
    As of tonight, I've squashed a number of lurking bugs and finished separating all task-specific state into Forth's USER area. This means PropellerForth now has multitasking.

    Currently, it has the ability to execute no-argument words on other Cogs, but I'm working on cooperative multitasking within the Cogs as well. (They're based on the same mechanism, after all.)

    In terms of ANS Forth, I've implemented most of the Core words, many of the Core Ext words, all of the Exception words, and a number of the Programming Tools words.

    Here's a binary suitable for loading with Propeller Tool. It will bring up a serial console (19200, 8n1) on the standard pins (31 and 30, as used on the demo board).

    Demo board users should see some LEDs come on and a prompt. Users of other boards beware: PropellerForth currently takes great liberties with pins 16-23, which drive debug LEDs on the demo board. These would be bad pins to use for, say, your atomic death ray.

    I'll post some documentation soon, and work on cleaning up the sources for release. In the meantime, to help folks see results, here's some demo code to try. A note on the non-standard Propeller words:
    - All the Propeller registers (CNT, CTRA, etc.) are defined as Forth words that return the in-Cog address.
    - In-Cog addresses like this can be read with L@ and written with L!, by analogy to @ and ! for the shared RAM. (L is for Local, because C for Cog was taken.)

    Paste this into your terminal emulator, or into a text file and send it as raw ASCII. Remember that my terminal code sucks, so set a character-to-character delay of at least 2ms, and an end-of-line delay of at least 50ms.

    \ Sets up CTRA to generate audible frequencies.
    \ Run before any of the following words.
    : sound-init
      1  10 lshift  dira L@  or dira L!   \ make pin 10, the left sound channel, an output
      4  26 lshift  10 or  ctra L!  \ set counter A to pin 10, NCO mode
      0  frqa L! ;
    
    \ Beeps for 1/10sec.  Takes a counter increment, not Hertz.
    \ Convert Hertz to counter increment using the HZ library word, like this:
    \    440 HZ BEEP
    : beep  ( counter-increment -- )
      frqa L!
      100 milliseconds wait
      0 frqa L! ;
    
    \ Plays a short note.
    : note  ( frequency -- )
      HZ  beep
      400 milliseconds wait ;
    
    : rest   500 milliseconds wait ;
    
    : sunshine
      784 note
      1046 note
      1174 note
      1319 note
      rest
      1319 note
      rest rest
      1319 note
      1174 note
      1319 note
      1046 note
      rest
      1046 note ;
    
    



    Once that's all entered, attach speakers and try:

    sound-init sunshine
    
    



    Note: it will be loud. I'm not doing PWM yet, as you can see.
  • GavinGavin Posts: 134
    edited 2006-11-09 12:34
    Going to need to relearn Forth.
    Last time I was interested was when the Harris forth chip came out.
    Looking·forward to forth on the prop.
    A lot of the early space stuff was writen in forth, they seemed to work without crashing into things.

    Hmm Prop robot running forth?
    And the price has droped on the chip too.
    Hmm ballbot with prop controller?
  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2006-11-09 12:54
    Well Cliff, after I saw that you had released something I could actually play with I just had to try it even though I'm still in the middle of unpacking and setting up my office. The fact that I can actually write some code and examine the prop guts is great. I couldn't find WORDS plus some other stuff so I wrote a couple of Q&D words and here is the word list. I'll play with it some more when I have some time and BTW I can contribute some code, especially the SD card file system etc if you like.

    *Peter*


    1BAA: SECONDS  1B84: HZ       1B6C: MILLISE  1B58: REBOOT
    1B42: LOCKRET  1B2C: COGSTOP  1B14: COGID    1AFE: CLKSET
    1AD4: LEDEMIT  1AC2: SECOND   1AB4: VSCL     1AA6: VCFG
    1A98: PHSB     1A8A: PHSA     1A7C: FRQB     1A6E: FRQA
    1A60: CTRB     1A52: CTRA     1A44: DIRA     1A36: OUTA
    1A28: INA      1A1A: CNT      1A0C: PAR      19FE: 'CLKFRE
    19A6: COLD     194E: FIND     192C: .S       1900: THROW
    18D2: CATCH    18BC: \        18A6: (        1882: S"
    1856: (S")     183A: ."       1812: (.")     17F8: +LOOP
    17DE: LOOP     17C8: DO       17AE: REPEAT   1798: WHILE
    1782: AGAIN    1772: BEGIN    1758: ELSE     1748: THEN
    1732: IF       171C: .(       16FA: '        16B8: POSTPON
    169A: !COLON   1678: !CONSTA  1660: [noparse][[/noparse]']      1648: ;
    1634: CONSTAN  161E: :        15A2: CREATE   1580: IMMEDIA
    155E: REVEAL   153C: HIDE     14E6: NAME-MA  14BE: 3DUP
    1468: COMPARE  140E: CASE-CO  13EA: >LOWERC  138C: QUIT
    136C: ?REFILL  1306: INTERPR  12E0: DIGIT>N  1256: >NUMBER
    11F6: NUMBER?  11AC: DIGIT?   1178: MAX-DIG  114A: BETWEEN
    111A: PARSE-W  1102: [noparse][[/noparse]CHAR]   10EC: CHAR     1086: PARSE
    1010: ]        0FFA: [noparse][[/noparse]        0FE6: ABORT    0FD0: ?DUP
    0FAA: ACCEPT2  0EFE: ACCEPT   0E94: .        0E7C: RUBOUT
    0E64: PAD      0E36: STRING,  0E12: XALIGNE  0DFE: HALIGNE
    0DEA: ALIGNED  0DD4: HALIGN   0DBE: ALIGN    0D94: DIGIT
    0D68: TYPE     0D54: <RESOLV  0D44: MARK>    0D2C: <MARK
    0D16: RESOLVE  0D02: NFA>LFA  0CEE: NFA>CFA  0CDA: CFA>NFA
    0CCA: COMPILE  0CB0: C,       0C96: H,       0C7C: ,
    0C64: ALLOT    0C52: HERE     0C40: SPACE    0C20: PARSE-A
    0C0C: SOURCE   0BF6: DECIMAL  0BE0: HEX      0BD2: BL
    0BC0: S>D      0BB0: D>S      0B92: /MOD     0B80: /
    0B6E: <>       0B5C: TUCK     0B42: +!       0B2E: CR
    0B1C: *        0B0A: 2DROP    0AF8: 2DUP     0AE8: HALFCEL
    0AD4: CELLS    0AC6: CHARS    0AB6: TIB      0AA6: HANDLER
    0A96: FIRST-W  0A86: RSP0     0A76: SP0      0A66: SOURCEC
    0A56: >IN      0A46: STATE    0A34: BASE     0A26: FALSE
    0A18: TRUE     0A00: PAGE     09E6: DP       09D8: TIBSIZE
    09CA: 'KERNEL  09BA: LATEST   09AA: BYE      099E: HUBOP
    0992: WAIT     0986: RSP@     097A: SP@      096E: U0
    0962: RSP!     0956: SP!      094A: I        093E: (+LOOP)
    0932: (LOOP)   0926: BRANCH   091A: 0BRANCH  090E: ?BRANCH
    0902: 1-       08F6: 1+       08EA: (/MOD)   08DE: M*
    08D2: U<       08C6: 0=       08BA: 0<       08AE: >
    08A2: =        0896: <        088A: INVERTA  087E: INVERT
    0872: OR       0866: AND      085A: MIN      084E: MAX
    0842: RSHIFT   0836: LSHIFT   082A: NEGATE   081E: 2/
    0812: 2*       0806: -        07FA: +        07EE: KEY
    07E2: EMIT     07D6: L@       07CA: L!       07BE: @
    07B2: H@       07A6: C@       079A: !        078E: H!
    0782: C!       0776: 2>R      076A: R@       075E: R>
    0752: >R       0746: NIP      073A: ROT      072E: OVER
    0722: DROP     0716: DUP      070A: SWAP     06FE: DOVAR32
    06F2: DOVAR    06E6: DOUSER   06DA: DOCON    06CE: EXECUTE
    06C2: LIT16    06B6: LITERAL  06AA: EXIT     069E: ENTER
    0692: NEXT
    
    
  • Ym2413aYm2413a Posts: 630
    edited 2006-11-09 15:53
    Come on now, I always connect my atomic death ray to pins 16 through 23. *laughs*
    I ran your code and it blow up my house by miss-firing evil rays of death from my demoboard. jumpin.gif

    Forth looks cool!
    The sad thing is I never programmed in it before, nor do I know its syntax.
    But I'd be excited to see some Propeller-IDEs.
  • Cliff L. BiffleCliff L. Biffle Posts: 206
    edited 2006-11-09 16:14
    Peter Jakacki said...
    I couldn't find WORDS plus some other stuff so I wrote a couple of Q&D words and here is the word list.

    Yeah, WORDS and a few others are part of a source file I'm manually loading each time I flash the board, as a test of the compiler. So they're not in the standard image. (FORGET is missing too, you'll note.)

    I'm absolutely interested in whatever help I can get. I've been hoping to do most of the kernel fundamentals myself, since it's been a while since I've written one and it's about as far as I can get from my day job -- but that's mostly done now, so I'll be releasing what I've got, and I'd love your help.

    I'm actually pretty impressed that you put together WORDS without any docs. Can you post your source?
  • Cliff L. BiffleCliff L. Biffle Posts: 206
    edited 2006-11-09 16:15
    Ym2413a said...
    Come on now, I always connect my atomic death ray to pins 16 through 23. *laughs*
    I ran your code and it blow up my house by miss-firing evil rays of death from my demoboard.

    Dude! What'd I tell you?!

    Nobody listens. smile.gif

    Edit: Fixed some markup problems. mCode is silly. Why every CMS on the internet needs its own markup language is beyond me.
  • Cliff L. BiffleCliff L. Biffle Posts: 206
    edited 2006-11-09 16:46
    So, since a couple folks seem to have actually downloaded that image, here are some very brief docs on the Propeller bits.

    Remember that PropellerForth is case-insensitive for user input, so these words don't have to be entered in SCREAMING UPPERCASE.

    ( Edit: My snarky comment about every forum needing their own markup language? Well, one of the advantages of a standard one is that I know which HTML tags stop my lines from wrapping. The code tag here apparently does too. Fixed. )
    Local register words: PAR CNT INA OUTA DIRA CTRA CTRB FRQA FRQB PHSA PHSB VCFG VSCL
    Local register/memory access words: L@ L!
    Shared RAM halfcell (16-bit) access words: H@ H!
      (PropellerForth uses halfcells for execution tokens and link fields in the dictionary; it's the size of a memory address.)
    
    WAIT ( u -- )
      Waits for some number of cycles (plus some execution overhead).  Uses waitcnt under the hood,
    but is not directly analogous (the argument is a cycle count, not an absolute clock value).
    
    'CLKFREQ  ( -- a-addr)
      Pushes the address of the clock frequency in shared RAM (access with @ and !)
    
    SECOND  ( -- +u )
      Pushes the number of clock ticks in a second.  This will be renamed to /SECOND in a later release.
    Uses 'CLKFREQ so you don't have to.
    
    LEDEMIT ( c -- )
      Pops a value and displays its low-order eight bits on the debug LEDs.  Many words in the dictionary
    use this internally at the moment.
    
    INVERTAND ( n1 -- n2 )
      A Forth equivalent of the Propeller's much-loved andn instruction.
    
    HUBOP  ( value command -- result )
      Executes a hub operation (such as the LOCK* and COG* ops).  Used as a primitive behind many
    other words.  Does not expose the value of C after the op (which some ops, like lockset and cognew,
    require -- grrrrr).
    
    CLKSET  ( clkval -- )
      Sets the system clock register; specifics on p.28 of the Propeller Manual.  Uses Hubop.
    
    COGID  ( -- cogid )
      Pushes the ID of the current Cog, which is a small integer.  Uses Hubop.
    
    COGSTOP ( cogid -- )
      Kills a cog.  The sequence "COGID COGSTOP" will shut down the current core.
    
    REBOOT ( -- )
      Reboots the entire chip, reloading code from EEPROM.  This is your new favorite word.  When you
    hose the dictionary or nuke the interpreter code by poking around in RAM, this word will save you --
    if you can still run it.  Otherwise, there's always the reset button.
    
    SECONDS  ( n1 -- n2 )
      Converts from seconds to clockticks, for use with WAIT or the counters.  Usage: " 5 seconds "
    
    MILLISECONDS ( n1 -- n2 )
      Converts from milliseconds to clockticks, for use with WAIT or the counters.  Usage: "500 milliseconds"
    
    HZ ( n1 -- n2 )
      Converts a value from Hertz to a counter increment.  Usage: " 440 HZ "
    
    'KERNEL ( -- a-addr )
      Pushes the shared-RAM address of the Forth native code kernel.  This is a useful building block for
    spawning processes on other cores.  (Though to do it properly, you must also know the layout of the
    USER area; see below).
    
    
    



    The USER area is Forth's per-task storage area (C/C++/Java programmers would call it Thread Local). PropellerForth's current USER area layout is:

    Offset
    $00 BASE - task's initial number base for I/O
    $04 STATE - task's initial interpretation (0) or compilation (-1) state.
    $08 >IN - task's initial parse position in its input - should be 0
    $0C SOURCECOUNT - number of bytes initially in task's input - should be 0
    $10 SP0 - pointer to base of task's data stack
    $14 RSP0 - pointer to base of task's return stack
    $18 FIRST-WORD - execution token (right-justified in a cell) of the first word this task runs
    $1C TIB - task's terminal input buffer

    All these are cell-sized variables, accessible with @ and !, except for TIB -- which is an 84-byte character buffer.

    For the purposes of starting a new task, one must
    1. Pick a block of RAM for the task's USER area. PropellerForth leaves most of high RAM, up to around $7000, free; I tend to use $6000 for the second task's USER base.
    2. Pick sections for your data and return stacks. The space required will depend on your task, and no, from that other thread, we can't statically determine it. smile.gif I tend to use $606E for the data stack and $616E for the return stack; this leaves a sizeable space for both.
    3. Set at least SP0, RSP0, and FIRST-WORD, like this:
    HEX
    606E 6010 !
    616E 6014 !
    ' word-you-want-to-run 6018 !
    
    



    4. The USER area is passed to a new Cog in its PAR field, which is a 14-bit address in the high-order bits of coginit's argument. Using this knowledge and 'KERNEL, we can construct the word:
    ( still in hex )
    6000    DECIMAL 16 LSHIFT    'KERNEL 2 LSHIFT  OR   8 OR  ( set the new-cog flag )
    
    


    5. And start the cog. I don't have coginit packaged into a word, because (as you've noticed) this process is laborious and stupid. PropellerForth's COGINIT word will do most of this work for you.
    ( 2 is the hubop for coginit, as per the Propeller Manual p.366 )
    2 hubop .
    
    


    It'll display the ID of the cog you just started; you can stop it again by entering "the-cog-id-goes-here cogstop".

    Happy hacking!
Sign In or Register to comment.