PropBasic SUB, Parameter passing
FriedV
Posts: 77
In PropBasic Subroutines, how can I calculate the lenght of a HUB string?
Address is passed as __param1, but LEN does not work?
Is there a PropBasic Forum?
Regards, Fried
SendDate SUB 1
SUB SendData
bcc VAR LONG
i VAR LONG
bufadr VAR LONG
ch VAR LONG
lenght VAR LONG
bufadr = __param1
lenght = len bufadr
I2CSTART SDA, SCL
i2cwrite SDA,SCL,$DE
i2cwrite SDA,SCL,$11
bcc = $11
i2cwrite SDA,SCL,length
bcc = bcc + length
for i = 1 to lenght
RDBYTE bufadr, ch
i2cwrite SDA,SCL,ch
bcc = bcc + ch
INC bufadr
next
i2cwrite SDA,SCL,bcc
i2cstop SDA,SCL
i2cstart SDA, SCL
i2cwrite SDA,SCL,$DF
i2cread SDA,SCL,ch,0
i2cstop SDA, SCL
ENDSUB
Address is passed as __param1, but LEN does not work?
Is there a PropBasic Forum?
Regards, Fried
SendDate SUB 1
SUB SendData
bcc VAR LONG
i VAR LONG
bufadr VAR LONG
ch VAR LONG
lenght VAR LONG
bufadr = __param1
lenght = len bufadr
I2CSTART SDA, SCL
i2cwrite SDA,SCL,$DE
i2cwrite SDA,SCL,$11
bcc = $11
i2cwrite SDA,SCL,length
bcc = bcc + length
for i = 1 to lenght
RDBYTE bufadr, ch
i2cwrite SDA,SCL,ch
bcc = bcc + ch
INC bufadr
next
i2cwrite SDA,SCL,bcc
i2cstop SDA,SCL
i2cstart SDA, SCL
i2cwrite SDA,SCL,$DF
i2cread SDA,SCL,ch,0
i2cstop SDA, SCL
ENDSUB
Comments
The LEN function works with strings. What you have is the "address" of the string. So you need to defererence the variable like this:
Here is the note from the PDF file
Bean
Yes, Fried is my real name, it is short for Friedrich in German.
BTW is it possible to use ViewPort to debug PropBasic? I tried some tricks with inline ASM (OBJ vp:"Conduit"), but no succes.
Fried
So you would have to RDLONG a variable to a HUB var, so ViewPort could "see" it.
I'll look into it when I get a chance.
Bean
Yes, Bean is correct (as usual). ViewPort works by sharing variables stored in HUB with the PC using the "conduit" object. To get VP to work you would need to:
- ensure Prop is running at full speed by setting clock constants (PropBasic may do this for you?)
- reference the "Conduit" object
- call the "share" function with the begin and end of memory you would like to share.
Is that enough to get you going?
Hanno
Thanks for those tips. I'll give it a try when I get the chance. And let everyone know how to do it.
Bean
up to now I'm working my way trough Spin and the objects.
But I intend to use Propbasic in the long run, I just got the feeling that it is useful (necessary?) to gain some knowledge about Spin and the underlying object model.
Fried