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:
PUBCreateP1TvColors()|i,x,p,y,r,g,b'create colors used by graphics demo, starting at index #128repeat i from0to14
x:=((i+4)&$F)*$10 + $C'mid brightness colors that start and green and run through yellow, red, purple, blue and then back to greenrepeat j from0to256
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
"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.
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...
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...
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.
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 v2all 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
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)
"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.
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.
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...
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.
Comments
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:
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...
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
"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.
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...
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....
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...
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?
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.
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 ><
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
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?
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 waitctASM..ENDASM doesn't seem to work...
I thought it would compile now, but I get this (attached image).
No idea what to do about that...
PUB go() | i repeat org _ret_ add i,#1 end pinwrite(56 addpins 7, !i) waitms(100)
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
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.
Graphics2c_Spin2.spin2 compiles OK
The barebones file that calls it "GraphicsTest1a.spin2" gives this error message...
https://drive.google.com/file/d/1HWnhswX2fd3W9H1gYSFqNeWToBMO7N7T/view?usp=sharing
long test
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:
other: 'ser.printf("Event%u: %u\n", portnum, event)
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)
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.