Converting P1 Spin to P2 PASM using Eric's FlexGUI/Fastspin Tools (WIP)
Cluso99
Posts: 18,069
I would like this thread to become a "How to do it" tutorial thread.
I had sorta hoped spin2 might be ready but it seems it's still a way off.
As an exercise I am going to use a modified version of Kye's FAT Driver that I use in my P1 Prop OS.
It has a couple of extra spin calls, and I have the P2 PASM cog driver version of the P1 PASM driver working.
For reference: I have attached the whole P1 OS v114 source but we are interested in _SD_FAT2.spin (reduced version of _SD_FAT.spin) and _SD_PASM.spin (P2ASM working without interface to _SD_FAT).
I had sorta hoped spin2 might be ready but it seems it's still a way off.
As an exercise I am going to use a modified version of Kye's FAT Driver that I use in my P1 Prop OS.
It has a couple of extra spin calls, and I have the P2 PASM cog driver version of the P1 PASM driver working.
For reference: I have attached the whole P1 OS v114 source but we are interested in _SD_FAT2.spin (reduced version of _SD_FAT.spin) and _SD_PASM.spin (P2ASM working without interface to _SD_FAT).
zip
550K
Comments
@ersmith ,
Please help, where do I start ??? - I am giving it a go, so see below of where I am up to
BTW I am reading the SpinPasmIntegration.md, spin.pdf, and Fastspin.pdf that came with Flexgui 4.0.6 in the doc folder.
First I've disabled to two OBJ references (_hubdef.spin and _SD_PASM.spin). I'll deal with them later
BTW my fastspin.exe is called F406.exe (for version 4.0.6)
Win10: from the command prompt
These errors are from a spin multiline statement... so I can fix this simply.
Anyway, before trying to convert to PASM the first step is definitely to get it running as Spin with the fastspin compiler.
(Any particular reason you want to eventually convert it to PASM as opposed to leaving it as Spin?)
I will disable this for now by commenting it out (141).
Note: Since a pointer to a parameter block in hub is passed to the _SD_PASM cog, no direct references in _hubdef.spin are used in this program, so the removal of this object is ok.
The error is this line, a PRI routine with no parameters
The problem is this routine. I will reduce the parameters as some are no longer used.
I now have pasm code to look at
I'm just looking over the cog pasm code that fastspin produced.
Thanks for all your work! I'll let you know how it goes
I was even re-thinking my spin1 interpreter for P2 as I think that would be easier.
Anyway, seems we might have spin2 before I'd get either done
I know my documentation isn't always clear, and sometimes we miss the really obvious things. Just to make sure: you are aware that you can compile a Spin1 program with fastspin to run on P2 with hubexec, right (as long as the assembly code is translated, of course)? This is in fact the default, so in general just doing "fastspin -2 foo.spin" will produce a "foo.binary" that will run on P2. As a side effect it also produces a "foo.p2asm" which is the P2 hubexec assembly code.
The "-w" option is a fairly specialized use for converting (small) sets of functions to run in cog mode. It's really just intended for P1, where it can produce a significant speedup. The output is also intended for use with any Spin compiler. But on P2 the advantage of cog mode is much less.
There are fastspin options to let you build the .binary file with a different base address, so you could for example build a "main" OS binary to run at address 0, and then build your utility programs to run at say address 64K. The main would load the sub-program from disk to 64K and then jump to it (or coginit it... that might actually be easier). The startup code fastspin produces expects a stack pointer to be passed in ptra, with entry point and parameters pushed on to it. I think @msrobots has done some work related to this where he ran fastspin code from TAQOZ... is that right Mike?
The "-9." option to loadp2 enables the 9P file server which lets the P2 read files from the host over the serial line. The main.spin program uses that to load P2 binaries from the host and run them. The runnable binaries are given a ".biz" extension (sorry, it's easy to change!). So for example to run "hello.biz" just type "hello" at the prompt, and then carriage return.
The .biz files are built with fastspin options "-H 0x10000 -E" which cause them to be created to run at 64K and skip some normal startup code. See "make.bat" for how they're built. I built them with fastspin 4.1.0 beta. There seems to be a problem where the "ls.biz" program can only run once, I haven't figured that one out yet (probably a bug in my code).
The commands I've provided are:
blink.biz: blinks pin 56 a few times
hello.biz: prints "hello, world"
ls.biz: lists the files on the host