Shop OBEX P1 Docs P2 Docs Learn Events
Converting P1 Spin to P2 PASM using Eric's FlexGUI/Fastspin Tools (WIP) — Parallax Forums

Converting P1 Spin to P2 PASM using Eric's FlexGUI/Fastspin Tools (WIP)

Cluso99Cluso99 Posts: 18,069
edited 2020-01-11 02:25 in Propeller 2
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).

Comments

  • Cluso99Cluso99 Posts: 18,069
    edited 2020-01-11 03:34
    I am unsure of just where to start and how to convert the P1 Spin code to P2 pasm. So, I've attached the _SD_FAT2.spin and _hubdef.spin here too.

    @ersmith ,
    Please help, where do I start ??? - I am giving it a go, so see below of where I am up to :smiley:

    BTW I am reading the SpinPasmIntegration.md, spin.pdf, and Fastspin.pdf that came with Flexgui 4.0.6 in the doc folder.
  • Cluso99Cluso99 Posts: 18,069
    edited 2020-01-11 03:35
    I have started a trial conversion...

    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
    C:\P2\Propeller II OS2>f406 -w -2 _SD_FAT2.spin2
    Propeller Spin/PASM Compiler 'FastSpin' (c) 2011-2019 Total Spectrum Software Inc.
    Version 4.0.6 Compiled on: Dec 30 2019
    _SD_FAT2.spin2
    _SD_FAT2.spin2:143: error: syntax error, unexpected indentation
    _SD_FAT2.spin2:150: error: syntax error, unexpected lack of indentation
    _SD_FAT2.spin2:247: error: syntax error, unexpected indentation
    _SD_FAT2.spin2:250: error: syntax error, unexpected lack of indentation
    _SD_FAT2.spin2:1016: error: syntax error, unexpected indentation
    _SD_FAT2.spin2:1021: error: syntax error, unexpected indentation
    _SD_FAT2.spin2:1040: error: syntax error, unexpected lack of indentation
    _SD_FAT2.spin2:1047: error: syntax error, unexpected lack of indentation
    
    C:\P2\Propeller II OS2>
    

    These errors are from a spin multiline statement...
      if( (dataOutPin <> clockPin) and (dataOutPin <> dataInPin) and (dataOutPin <> chipSelectPin) and {
        } (clockPin <> dataInPin) and (clockPin <> chipSelectPin) and (dataInPin <> chipSelectPin) and {
        } (writeProtectPin <> dataOutPin) and (writeProtectPin <> chipSelectPin) and {
        } (cardDetectPin <> dataOutPin) and (cardDetectPin <> chipSelectPin) and {
        } (++cardLockID) and (++cardCogID) and (chipver == 1) )
    
    so I can fix this simply.
  • I'd start by getting the Spin code to run with FlexGUI as Spin code. To do that you'll need to implement translate the assembly in the _SD_PASM.spin file from P1 to P2. I'm not sure how hard that'll be, it isn't in the code you posted. The next step would be getting the Spin code to compile. Normally there's no work to do for that, but I see Kye has some unusual commenting that seems to be confusing fastspin's parser. Ah, I see what it is: he's using { <NL> } to extend lines, but fastspin is actually noticing the newlines inside the {} comments. I'll need to fix that bug, but for now you could manually join the lines.

    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?)
  • Cluso99Cluso99 Posts: 18,069
    edited 2020-01-11 03:46
    Next errors are from trying to start _SD_PASM.spin in another cog.
    C:\P2\Propeller II OS2>f406 -w -2 _SD_FAT2.spin2
    Propeller Spin/PASM Compiler 'FastSpin' (c) 2011-2019 Total Spectrum Software Inc.
    Version 4.0.6 Compiled on: Dec 30 2019
    _SD_FAT2.spin2
    _SD_FAT2.spin2:141: error: request for member init in something that is not an object
    
    C:\P2\Propeller II OS2>
    

    I will disable this for now by commenting it out (141).
      cardCogID := sd.init(@CIDPointer)                     ' start the cog, returns cog ???+1
    

    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.
  • Cluso99Cluso99 Posts: 18,069
    edited 2020-01-11 04:35
    This error I will have to search for as Fastspin isn't telling me where the problem is.
    C:\P2\Propeller II OS2>f406 -w -2 _SD_FAT2.spin2
    Propeller Spin/PASM Compiler 'FastSpin' (c) 2011-2019 Total Spectrum Software Inc.
    Version 4.0.6 Compiled on: Dec 30 2019
    _SD_FAT2.spin2
    error: .cog.spin functions may not have more than 8 arguments
    
    C:\P2\Propeller II OS2>
    

    The error is this line, a PRI routine with no parameters
    The problem is this routine.
    PUB FATEngineStart(DOPin, CLKPin, DIPin, CSPin, WPPin, CDPin, RTCReserved1, RTCReserved2, RTCReserved3) '' 15 Stack Longs
    
    I will reduce the parameters as some are no longer used.
  • Cluso99 wrote: »
    Next errors are from trying to start _SD_PASM.spin in another cog.
    C:\P2\Propeller II OS2>f406 -w -2 _SD_FAT2.spin2
    Propeller Spin/PASM Compiler 'FastSpin' (c) 2011-2019 Total Spectrum Software Inc.
    Version 4.0.6 Compiled on: Dec 30 2019
    _SD_FAT2.spin2
    _SD_FAT2.spin2:141: error: request for member init in something that is not an object
    
    I think that's because you commented out the OBJ statement that defined "sd". Maybe a quicker path would be to enable the OBJs but to #ifdef out all the P1 specific assembly code (except for the entry label or whatever it needs)?

  • Cluso99Cluso99 Posts: 18,069
    Compile Success :smiley:
    I now have pasm code to look at :wink:
  • Cluso99Cluso99 Posts: 18,069
    ersmith wrote: »
    Cluso99 wrote: »
    Next errors are from trying to start _SD_PASM.spin in another cog.
    C:\P2\Propeller II OS2>f406 -w -2 _SD_FAT2.spin2
    Propeller Spin/PASM Compiler 'FastSpin' (c) 2011-2019 Total Spectrum Software Inc.
    Version 4.0.6 Compiled on: Dec 30 2019
    _SD_FAT2.spin2
    _SD_FAT2.spin2:141: error: request for member init in something that is not an object
    
    I think that's because you commented out the OBJ statement that defined "sd". Maybe a quicker path would be to enable the OBJs but to #ifdef out all the P1 specific assembly code (except for the entry label or whatever it needs)?
    Thanks Eric. The SD object is fine being commented out - I've done a P2PASM version already and the only calls are to load (start) and unload (stop) the pasm cog so it's fine. The other object _hubdef isn't actually used in this program so not a problem either.

    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 :smiley:
  • Cluso99Cluso99 Posts: 18,069
    I've just been pouring over the p2asm code. There is way too much code for cog/lut so it would have to be hubexec.

    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 :smiley:
  • Let's step back a minute... why were you wanting this to be cogexec rather than hubexec?

    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?
  • Here's a really simple "operating system" that runs programs from disk. This is completely brain dead and just enough to show how programs can be loaded and run. I don't have SD code, so I use the host file system instead. Just unzip myos.zip somewhere convenient, change to the directory where the files were unpacked, and run using the commands from run.bat, e.g.:
    loadp2 main.binary -b230400 -9.
    

    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
  • ersmithersmith Posts: 6,053
    edited 2020-01-12 00:53
    Ah, I figured out what's wrong with ls.biz: it isn't closing down its connection with the file server, so when it runs a second time it gets a "file in use" error. You can fix it by adding one line to the end of the PUB demo method in ls.spin, right after "fs.fs_close(@myfd)":
      fs.fs_close(fs.fs_getroot)
    
Sign In or Register to comment.