P1 to P2 Guide needed..

Had been on P1 for so long that now starting with P2, I'm a bit lost...
Spin2 code seems very neat! E.g. this code
debug(`term message pos 2000 200 size 12 4 textsize 40 rgbi8x)
Does "debug" use a cog?
Had been on P1 for so long that now starting with P2, I'm a bit lost...
Spin2 code seems very neat! E.g. this code
debug(`term message pos 2000 200 size 12 4 textsize 40 rgbi8x)
Does "debug" use a cog?
Comments
Debug doesn't use another cog. It is something like a software interrupt instruction, which calls the debug code placed at the last 16 kB of HUB RAM. Normally this code is generated by the compiler.
Thanks.
It won't take long to get used to the P2, but there are differences that you have to account for. I've written a LOT of P1 code (it's my job) over the years, so I have a lot of code to translate. This is my normal process.
PASM code will have to be manually translated. It's worth the effort, though, as PASM for P2 is easier and you can do more work with fewer instructions. This has been my experience, anyway. In some cases where you might be launching a cog for a tiny bit of code, you can sometimes do that inline with the P2. I use this feature a lot.
As I'm working my way through a Python training course I wrote a little program that will read in a P1 file and provide suggestions for changes for porting to the P2. This may help you until you learn the different operators and changes to some others. Make sure you have Python 3 installed and that it's in your path so you can call it from anywhere. Here's what operation looks like on my computer. Note that Python uses \ for escapes so you'll have to change them to / in your path to the P1 program.
D:\programming\python\p1_to_p2_hints>python p2_hints_1v6.py D:/programming/P1_Spin/jm_max7219_demo.spin Processing D:/programming/P1_Spin/jm_max7219_demo.spin 0061 time : "jm_time_80" ' timing and delays (80MHz) ---- ^ * Col 010 (p1) "jm_time_80" (p2) usually not needed 0062 prng : "jm_prng" ' pseudo-random number generation ---- ^ * Col 010 (p1) "jm_prng" (p2) "jm_random" 0101 time.pause(125) ---- ^ * Col 009 (p1) time.pause (p2) waitms 0107 time.pause(125) ---- ^ * Col 007 (p1) time.pause (p2) waitms 0110 time.pause(125) ---- ^ * Col 007 (p1) time.pause (p2) waitms 0113 time.pause(500) ---- ^ * Col 005 (p1) time.pause (p2) waitms 0126 time.pause(delay) ' hold ---- ^ * Col 005 (p1) time.pause (p2) waitms 0137 time.pause(1000) ---- ^ * Col 003 (p1) time.pause (p2) waitms 0139 t := cnt ---- ^ * Col 008 (p1) cnt (p2) getct() 0142 waitcnt(t += constant(100 * MS_001)) ' hold 1/10th second ---- ^ ^ * Col 005 (p1) waitcnt (p2) waitct * Col 018 (p1) constant (p2) N/A 0144 time.pause(1000) ---- ^ * Col 003 (p1) time.pause (p2) waitms 0157 time.pause(250) ---- ^ * Col 005 (p1) time.pause (p2) waitms 0170 time.pause(250) ---- ^ * Col 005 (p1) time.pause (p2) waitms 0196 time.pause(100) ---- ^ * Col 007 (p1) time.pause (p2) waitms 0198 time.pause(1000) ---- ^ * Col 003 (p1) time.pause (p2) waitms 0207 prng.seed(-cnt, -cnt ~> 2, $CAFE_BABE, cnt <- 2, cnt) ' seed randomizer ---- ^ ^ ^ ^ ^ ^ ^ * Col 003 (p1) prng.seed (p2) not needed for xrandom() * Col 014 (p1) cnt (p2) getct() * Col 020 (p1) cnt (p2) getct() * Col 024 (p1) ~> (p2) sar * Col 042 (p1) cnt (p2) getct() * Col 046 (p1) <- (p2) rol * Col 052 (p1) cnt (p2) getct() Done. 23 suggestions in 16 lines.
The program is very simple: it goes line-by-line looking for text from the P1 dictionary and outputs suggestions from the P2 dictionary. It's not perfect, but it is helpful, and being Python it is very easy to customize for things that you typically do. I've attached the Python (3) file, as well as my P2 template in case that's helpful.
Thanks, Jon, these are very helpful!