Spin2

11214161718

Comments

  • RaymanRayman Posts: 10,424
    edited 2020-02-11 - 15:04:48
    Sorry, one more thing... Is there a list of the Spin2 operators somewhere?

    I thought that "=>" was going to change to ">=", like C++, but I think Fastspin didn't make this change, so I wonder about Spin2...

    Also, I'm getting an error on this:
    value := ||(value+x)
    

    So, I think absolute value operator has changed...

    I found the 2018 proposed operators here: https://forums.parallax.com/discussion/166416/spin2-operator-syntax/p17
    Seems || is now ABS...
  • BTW: Maybe it is a good idea to keep variables separate...
    After changing "x" to "x99" in my assembly code, I got an error here:
    PUB  CreateP1TvColors()|i,x,p,y,r,g,b 'create colors used by graphics demo, starting at index #128
        repeat i from 0 to 14
            x:=((i+4)&$F)*$10 + $C 'mid brightness colors that start and green and run through yellow, red, purple, blue and then back to green
    
            repeat j from 0 to 256
    

    The variable "j" was being used without being declared as a local variable.
    So, I guess it was using the long declared in the assembly block.

    Actually, once that assembly driver is started, maybe this is perfectly fine.
    Perhaps I should have gone the other route and just not defined i,j,k,x,y etc as local and just left them in the assembly code :)
  • Rayman wrote: »
    This syntax is not recognized by Fastspin:
        pinclear(av_base_pin_ addpins 4)
    

    Wouldn't that be better with commas?

    "addpins" is one of the new operators, and it's recognized by fastspin 4.1.3. "av_basepin_ addpins 4" is the same as "av_basepin_ | (4<<6)". This may be a case where having a lot of operators obscures what's going on.
  • RaymanRayman Posts: 10,424
    edited 2020-02-11 - 14:51:55
    I'm glad to see chip using 297 MHz clock in these demos.
    That's what I'm using, but I spent an hour or so deliberating whether or not this is a good idea...
    I might have to take a heat gun to it and see if this is going to work if the AC goes out during summer time...
  • Is "result" no longer a Spin keyword?
    I copied over a "DEC" routine from Spin1 that has this in it:
          result~~                                          'flag non-zero found
        elseif result or i == 1
    

    Gives me an error in Spin2....
  • RaymanRayman Posts: 10,424
    edited 2020-02-11 - 15:25:58
    Yeah! I got my 1551 ling long driver file to compile.

    Now, I have to work on the top file...
    Spin2 does not like how I include "smartserial" in my OBJ section:
    OBJ
        VGA : "1080p_TileDriver_3n.spin2"  'Note:  You must set the fclk constant in this file to match _clkfreq
        gr  : "Graphics2b.spin2"
        usb1: "OneCogKbM_rja2b"   'Note:  You must change basepin and _FCLKFREQ settings in this file to match your setup
        ser: "spin/SmartSerial"
    

    It also doesn't like me putting the ".spin2" in the filenames...
  • Is there no CogNew in Spin2?
    I get an error on this:
    okay := cog := cognew(@loop, @command) + 1
    

    I see the example does this:
    okay := cog := coginit(16, @driver, @background0_) + 1
    

    I guess the "16" means use the next free cog?
  • JRetSapDoogJRetSapDoog Posts: 836
    edited 2020-02-11 - 16:02:45
    Rayman wrote: »
    Sorry, one more thing... Is there a list of the Spin2 operators somewhere?
    You've probably found them by now, but I saw a .txt file attachment with the operators in Chip's 2020-2-9 15:28:40 post a couple pages back. And I think that file is in the latest zip file, too.
  • Thanks, I think Chip just added this and some other things to the latest .zip file.

    Does spin2 support preprocessor commands?
    I'm getting an error in garryj's USB code on this line:
    #ifndef USB_PORTB ' PortA is the default.
    
  • RaymanRayman Posts: 10,424
    edited 2020-02-11 - 18:14:31
    Minor note: FastSpin will let you redefine a constant later on but Spin will not...
    I had two instances of this:
    USB_V2MODE     = %1_11011_0 + 1 << 16 ' In P2 silicon v2 all USB smart pin modes are consolidated to %11011.
    

    This might be trouble:
    ' USB CRC constants:
            USB5_POLY      = %0_0101 >< 5           ' USB5 polynomial is reflected when calculating CRC
            USB5_RESIDUAL  = %0_1100 >< 5           ' Expected CRC5 residual value when checking received data
            USB16_POLY     = $8005 >< 16            ' USB16 polynomial is reflected when calculating CRC
            USB16_RESIDUAL = $800d >< 16            ' Expected CRC16 residual value when checking received data
    

    Hope REV is same as ><
  • RaymanRayman Posts: 10,424
    edited 2020-02-11 - 18:29:51
    I'm not sure why I'm getting this error in the USB code (attached).
    I guess you can't use . labels in hubexec?


    Strange... I replace the DJNZ with sub wz and if_nz jmp and its ok with that. These are the same, right?
                    'djnz    htmp2, #.loop  'PNUT doesn't like this?
                    sub     htmp2,#1 wz
            if_nz   jmp     #.loop
    
    568 x 539 - 29K
  • REV is not the same as ><. "x REV y" is the same as "x >< (y+1)", if I remember correctly.
  • It's not liking "dirl_" either:
        dirl_(USB_EVENT_REPO)                               ' DIR bit low puts smart pin in reset mode
        wrpin_(SP_REPO1_MODE, USB_EVENT_REPO)               ' Set "long repository" mode to act as an event mailbox
        dirh_(USB_EVENT_REPO)                               ' Enable the event mailbox smart pin (will raise IN)
    

    What to do here?
  • garryjgarryj Posts: 304
    edited 2020-02-11 - 18:36:12
    Edit: "x REV (y - 1)" is the same as "x >< y".
  • "pinfloat" will set the direction to low (like dirl_) and "pinlow" will set the direction to high (like dirh_). Use just plain "wrpin" instead of "wrpin_". fastspin 4.1.3 should accept all of those.
  • RaymanRayman Posts: 10,424
    edited 2020-02-11 - 19:02:23
    Thanks, it took that.

    Spin2 doesn't seem to like this:
    PUB str(s = string("")) | c
    

    Doesn't like waitx() either:
    waitx(1000) ' wait to settle
    
    Think this might be waitct
  • Anybody know how to do inline assembly in Spin2?
    ASM..ENDASM doesn't seem to work...
  • Skipping Smartserial integration for now...

    I thought it would compile now, but I get this (attached image).
    No idea what to do about that...
    600 x 309 - 18K
  • Rayman wrote: »
    Anybody know how to do inline assembly in Spin2?
    ASM..ENDASM doesn't seem to work...
    PUB go() | i
    
      repeat
    
    	org
    _ret_	add	i,#1
    	end
    
        pinwrite(56 addpins 7, !i)
        waitms(100)
    
  • Rayman wrote: »
    Thanks, it took that.

    Spin2 doesn't seem to like this:
    PUB str(s = string("")) | c
    

    Doesn't like waitx() either:
    waitx(1000) ' wait to settle
    
    Think this might be waitct

    In Spin2, there are three waits:

    WAITCT(ct_target)
    WAITUS(microseconds)
    WAITMS(milliseconds)

    There is also:

    POLLCT(ct_target) 'returns true if past ct_target
  • Rayman wrote: »
    It's not liking "dirl_" either:
        dirl_(USB_EVENT_REPO)                               ' DIR bit low puts smart pin in reset mode
        wrpin_(SP_REPO1_MODE, USB_EVENT_REPO)               ' Set "long repository" mode to act as an event mailbox
        dirh_(USB_EVENT_REPO)                               ' Enable the event mailbox smart pin (will raise IN)
    

    What to do here?

    There are register variables, same as in PASM: DIRA/DIRB/OUTA/OUTB/INA/INB.

    WRPIN/WXPIN/WYPIN/etc can be used in Spin2, as well as in PASM.
  • Here are some files to reproduce the "Invalid Object File" error.

    Graphics2c_Spin2.spin2 compiles OK
    The barebones file that calls it "GraphicsTest1a.spin2" gives this error message...
  • Rayman, I'm looking it over now. I'm getting the same error, of course. I'll figure out the problem.
  • Okay. It's finding constant symbols that start with underscores, and for some reason I disallowed this in the object interface. I can't remember why. Let me change this...
  • Is "test" reserved or something? Got a "expected unique variable name" error on this:
     long  test
    
  • RaymanRayman Posts: 10,424
    edited 2020-02-12 - 01:38:09
    I guess you can't do this:
    b := data.byte[0]
    

    or this
    x := ~byte[@data][1]           '~data.byte[1]
    

    Also, looks like to call a function that returns multiple results, you shouldn't put them in parenthesis like this does:
    (ptr, val) := usb1.getDebugInfo()
    
  • Interesting... I commented out a "case" and now it gives me a "block is empty" error
        other:
          'ser.printf("Event%u: %u\n", portnum, event)
    
  • All right, I finally got it to compile my 1080p code...
    Didn't work though.

    First problem seems to be with the clock setting...
    Got VGA output after changing this part:
    {
    CON  'RJA:  new for real P2 - you can use different xdiv and xmul to set clock frequency:  /10*125 -> 250 MHz
      _XTALFREQ     = 20_000_000                                    ' crystal frequency
      _XDIV         = 20                                            ' crystal divider to give 1MHz
      _XMUL         = 297                                          ' crystal / div * mul
      _XDIVP        = 1                                             ' crystal / div * mul /divp to give _CLKFREQ (1,2,4..30)
      _XOSC         = %10                                  'OSC    ' %00=OFF, %01=OSC, %10=15pF, %11=30pF
      _XSEL         = %11                                   'XI+PLL ' %00=rcfast(20+MHz), %01=rcslow(~20KHz), %10=XI(5ms), %11=XI+PLL(10ms)
      _XPPPP        = ((_XDIVP>>1) + 15) & $F                       ' 1->15, 2->0, 4->1, 6->2...30->14
      _CLOCKFREQ    = _XTALFREQ / _XDIV * _XMUL / _XDIVP            ' internal clock frequency                
      _SETFREQ      = 1<<24 + (_XDIV-1)<<18 + (_XMUL-1)<<8 + _XPPPP<<4 + _XOSC<<2  ' %0000_000e_dddddd_mmmmmmmmmm_pppp_cc_00  ' setup  oscillator
      _ENAFREQ      = _SETFREQ + _XSEL                                             ' %0000_000e_dddddd_mmmmmmmmmm_pppp_cc_ss  ' enable oscillator
    
      _clkmode = _SETFREQ
      _clkfreq = _CLOCKFREQ
      
      ''NOTE:  You must manually change clock freq in both mouse and VGA drivers to match the above.
      
    }
      
    CON _clkfreq = 297_000_000
    

    and also removing this:
        'First, set the clock
        'clkset(_clkmode, _clkfreq)
        'waitct(clkfreq*3)'waitcnt(clkfreq + cnt*3)
    
  • cgraceycgracey Posts: 12,607
    edited 2020-02-12 - 02:33:48
    Rayman, there are ways of achieving all these things in the PNut version of Spin2.

    byte[base][index] 'look up a byte

    To set up the clock, you only need to specify:

    CON _clkfreq = 250_000_000 'assumes 20MHz crystal if no _xtlfreq specified
    CON _xtlfreq = 16_000_000 'if your crystal frequency is not 20MHz, specify _xtlfreq

    The compiler will pick the optimal PLL setting for you. You can see what it is in your code by using the constant clkmode_ and clkfreq_. Also Ctrl-L shows it.

    And TEST is a PASM instruction, so it is a reserved word.

    Until I get the documentation together for Spin2, there will be some ambiguities.
Sign In or Register to comment.