View Full Version : SPIN Beginner questions

01-20-2008, 11:28 PM
I just received my Propeller Yesterday, and I am very impressed with it. I have a few spin related questions that I can not seem to find the answer to in the manual or in peoples published code.

1) IS there anyway for me to read/write one bit of a byte/word/long variable? I would like to do this so I could have one BYTE/WORD/LONG declared that could contain all my boolean expressions. i.e:

BYTE Check

PUB Start
Check := %11000101

And have a program read/write to only one bit of that byte?

2) Is there any way to store character strings easily into an array? It seems daunting to have to declare one Character at a time

3) Is there no way to have multiple "commands" per line? Like how you can declare multiple Bytes in VAR/CON or does the IDE rely on the CR/LF to compile the code?

Thanks for your help, I look forward to enjoy many good times coding with the Propeller as I have had with the Basic Stamp

01-20-2008, 11:49 PM
(1) No
(2) No
(3) No
http://forums.parallax.com/images/smilies/smile.gif But there is more to it...

(1) You have lots of memory in the propeller, so in many cases you can live with using bytes...
Bits can easily be used with the so called SPR ("special purpose registers") as OUTA, DIRA, INA. The syntax is
DIRA[bitnumber ] := bit
OUTA[firstBit..lastBit] := someBits

Bit is is not so difficult to extract single Bits from general longs: Ex.:
bitN :=( aLong>>N)&1

Set bit N:
aLong |= |<N

Clear bit N:
aLong &= !|<N

(2) You can copy strings with BYTEMOVE, however you have to find its length before.... You can allocate and use strings with the STRING(..) directive, or do it directly in the DAT section
str BYTE "hallo, world!",0

(3) Well, this is just so...

Mike Green
01-21-2008, 12:15 AM
A little more detail ...
2) The STRSIZE() function returns the length of a zero-terminated string which then can be used with BYTEMOVE. There are some library routines (from the Propeller Object Exchange ... accessible from the main Parallax Propeller webpage) that will do a bit more string manipulation for you.
3) You can declare several bytes / words / longs on a line in the VAR section. You can declare only one constant per line in the CON section with the exception of a sequence of enumerations (see the manual's CON section description). You can declare only one label per line in the DAT section, but that label can refer to the first address in a block of data specified on that line.

The Spin language uses indenting to delineate nesting levels, so you get only one statement per line. You can continue from one line to another by using {} type comments to enclose the CR/LF at the end of the line (end a line with { and start the next line with }).

01-22-2008, 07:55 AM
Thank you very much for that helpful information.

1) This worked perfectly DeSilva, thank you very much. Didnt much realize the use in the |< and |> Functions, but now I can see how they can become very useful!

3) This wasn't really important, Im just used to cleaning up my code by sorting it a certain way


2) Im not quite clear on this one. I am using char_mode_10 from the Object exchange as a Text based NTSC T.V. driver as my output to display strings. The code looks something like this

TV.PrintStrAt(X,Y,FG,BG,String("Look at me, I'm on TV!"),0)

Where X/Y are character positions on the screen, FG/BG are Foreground and background colours respectively, The string to be sent, and finally weather or to invert FG/BG (0 = Do not invert). I am trying to replace the String("asdafasda") section with a variable that I can set elsewhere and have it display different text with a single command.

But I just can seem to get it to work.

Also, Mike, I looked through the Object exchanged but found no obvious String Manipulation objects to be had. Any specific names come to mind? Thanks.


Just seconds after I posted this what you were saying became clear. To make a PUB/PRI that takes input from a String(), get its string size, and bytemove the whole thing to a variable name also passed to the PU/PRI. Works like a charm, thanks Guys!

Post Edited (lungdart) : 1/22/2008 1:29:55 AM GMT