Jumping from 2.7 to 5.7
artkennedy
Posts: 174
in Propeller 1
From JUNO Extend:
\ Define common variable sizes
pub DOUBLE 8 4 [C] AVAR ; IMMEDIATE
pub LONG 4 4 [C] AVAR ; IMMEDIATE
pub WORD 2 2 [C] AVAR ; IMMEDIATE
---
pub BYTE 1 1 [C] AVAR ; IMMEDIATE
How is this done in 5v7.
p.s. - I am digging before I ask but am stumped.
\ Define common variable sizes
pub DOUBLE 8 4 [C] AVAR ; IMMEDIATE
pub LONG 4 4 [C] AVAR ; IMMEDIATE
pub WORD 2 2 [C] AVAR ; IMMEDIATE
---
pub BYTE 1 1 [C] AVAR ; IMMEDIATE
How is this done in 5v7.
p.s. - I am digging before I ask but am stumped.
Comments
Tachyon is an embedded Forth for the Propeller and not only has to reliably run in products 24/7, but it has very little memory to do it in compared to many micros, even small micros. So Tachyon separates code, dictionary headers, and data both for reliability and also for managing memory better. The dictionary can have private "pri" headers that can be stripped out and the dictionary shrunk, and whole data structures can be erased in one hit since the memory locations are contiguous, rather than variable by variable.
Now back to what this means for variables and for tables.
In Tachyon if you want to have a variable for a single byte you say "byte myvar". If you want 16 bytes you say that too with "16 bytes myvars". If you want a 16-bit word or a long or many of them you do the same. But TABLE is different, unlike variables that can change and be lost on power-ups (if not backed up), the contents of the table are meant to be fixed constants, such as a look-up or conversion table. So when you say "TABLE mytable" it creates a "variable" in code space but does not allocate any memory. It is up to you to fill that table with as much as it needs. This is what the | and || and , does in that it will take that value and compile it as a byte, or word, or long, into the next location in the table in code memory. The more you add, the more it uses, there is no need to preallocate memory with ALLOT which really is not what you want. In fact there is no way to "compile" values into that memory that has been allocated, you can only store it there by indexing the table etc which is what I do for more complex methods of generating table values. Otherwise don't do it.
Don't forget to interact and play "what ifs" with Tachyon, even just for a sanity check.
Confirm where the code pointer is:
Create a new 32-bit variable
Confirm that it is indeed not in code memory:
Try some more and confirm that the address advances accordingly:
Now double check what TABLE does:
Sp no memory was allocated for the table except for the code that returns with the table address.
BTW, uses lower case for byte/word/long etc. V3 still used upper-case for this whereas V5 has it in lower case and doesn't try to convert upper and lower since this can be the source of many code bugs when variables and code have the same name but different case.
btw - Conventional Forths use C, and W, perhaps to compile byte and word values, just like it does when it uses , to compile a 32-bit value (for 32-bit Forths). But I found that makes for a very messy looking table and hard to read. Which is easier to read?:
or
it is a pitty that interesting comments by @"Peter Jakacki" like the one above get lost in the forum threads,
especially if new ones are started all the time and not the main Tachyon threads are used.
I have been a bit lazy recently collecting those snippets in THIS document.
some parts are a bit old, but maybe still helpful.
I want to operate the clock for the system only when needed which will be a very small percentage of the time in order to save power. So I want to be able to run the clock cog only when it is needed. Using this code I can run the clock and stop it but when I attempt to restart there is not response. I could use a workaround for this but it would be better if it is possible to restart the cog. Can this be done?
Perhaps the cog is not really stopped because .TASKS still lists it but it is no longer switching the pin.
: RFCLOCK --- runs independently except for starting and stopping
rfclkdur W@ --- nominal duration of clock pulse
5 - --- adjust for processing delays
2 / --- 50% duty cycle
BEGIN --- begin
0 HIGH DUP us --- leading edge
0 LOW DUP us --- trailing edge
AGAIN --- until COGSTOP
; ---
600 rfclkdur W!
: CLOCKSTART ' RFCLOCK 6 RUN ;
: CLOCKSTOP 6 COGSTOP ;
When you want to stop it: