Porting Propeller 1 code to Propeller 2
- Notes on converting code from Spin1 to Spin2
- Setting clock is different:
- Instead of
- Do this:
- All functions (PUB and PRI) now require parenthesis, even if doesn't
have parameters
- Instead of "PUB main" use "PUB main()"
- All functions that return a value must declare the return value
- Instead of "PUB GetByte" do "PUB GetByte():r" where "r" is the
value to be returned.
- Use "jm_fullduplexserial.spin2" instead of
"fullduplexserial.spin"
- Note that there may be an issue with function name "fdec", just
rename it to "fdec2" or something as "fdec" has become a reserved
word.
- Can use "ser.tstart(baud)" where baud might be 115200 to use
usual pins and settings
- There are some slight differences/improvements in this P2
version
- The way to drive pins has changed a bit
- P1 way was like: to
set a pin low. You can still do it that way and there is even
a OUTB and DIRB and INB now. But, syntax is now
OUTA.[PinResetn]~~. Note you have to add the "." to get it to
work.
- But, new way is with commands like:
where the pin number argument
can range from 0 to 63.
- There is also pinh, pinf, pinr, etc.
- You can also use "addpins" to affect multiple sequential
pins at once.
- The way to do delays based on clock ticks has changed
- The old way: doesn't
work
- An easy way now is to use waitms(500) to do same thing with P2
- The below posted to tricks & traps forum discussion
here.
- Common substitutions that need to be made in
PASM2:
- PAR --> PTRA
- MINS --> FGES
- MAXS --> FLES
- MOVS --> SETS
- ":" --> "." (sometimes in many places, the local variable indicator
has changed.)
- SETD --> SETD2 (SETD is an instruction in P2)
- cmps wc,wr --> subs wc
- command := cmd << 16 + argptr --> command := cmd << 24 + argptr
(pointer space is now larger than 16 bits, but can still use upper 8
bits for something else)
- Using QROTATE to fix missing sin table
- Used MUL to speed multiply
- SUB with wz,nr cannot be used as there is no "NR" now. Use CMP
instead.
- waitcnt x,#0 --> waitx x
- The usual wait sequence:
- mov t7,cnt
add t7,delaycnt2
waitcnt t7,#0
- Is Now:
- getct t7
addct1 t7,delaycnt2
waitct1
- New way to do byte jump
table (search link in top line)
-
Note that self-generating code must be kept in cog and not used in hubexec
mode
- For Spin code:
- All function
must use "()" parenthesis in definition and
call
- Return values need to
be declared explicitely. Can usually
just add a ":r".
- You only need to set _clkfreq now, no crystal
setting needed.
-
There is a Port B in P2 now, so...
- You might need to
change INA/OUTA/DIRA to match your actual setup
- Be careful if there's
any INA/OUTB/DIRB usage in your spin1 code, you may need to change that