I’m currently working on my OI/RC emulator for testing code with, and I’m wondering how much of the PBASIC language people actually use. I just ask because I don’t want to spend hours coding support for an obscure command that nobody is using. On the other hand, even if only one person is using it, I would be happy to add support.
Here is the list of the obvious ones I have come up with so far:
+,-,*,/, =
and, or
&, |, ~, ^
Min, Max
Serin, Serout
VAR, CON
Output (for LEDs)
store, load
goto, labels
if
Other ones I’m not sure about (I haven’t used them, but I can see where some teams might):
Lookup, Lookdown
Trig functions
for loops
Anyway, that’s all I’ve been able to come up with so far. Others?
put/get
write
gosub (I’ve never personally been organized enough to break my pbasic into subrotines, but I have seen robot code that does)
That’s all I can think of now. BTW, good luck with your emulator.
Stephen
P.S just in case it slipped your mind (it probably didn’t, but just making sure), make sure in your VAR command you have the functionality to go var_name.bit0, etc.
easy way i’ve found to truncate numbers in C++ like you do in PBASIC. declare a ‘double’ (probably works with ‘float’ too) variable which takes in the number, then just declare an ‘int’ variable, whcih then assumes the value of the double. like this…
double x;
int y;
x = 5.9;
y = x;
cout << y;
that would print out a 5. you will get a warning, but that’s the best way i’ve found to truncate the numbers in C++. i’m sure there’s some class that does it better, but i’ve yet to find it.
don’t use any floats or doubles anywhere in the program. at all. not even one. the 2sx doesn’t have the foggiest of what a decimal point was. What i was trying to say is that although an int will truncate correctly when all is said and told, the math inbetween will not. for example, in pbasic, 5/22=4, not 5. C++ will do all the math out with some ungodly precision and then truncate. you may need to change x=x/22 to x=x/2; x=x*2.
Also, declaring it as an unsigned might be better, so that you automatically get wrapping up top and below, ie 267 doesnt exist and neither does -6. don’t know how to handle the 255 thing with out anal checking in the code.
BTW - i have used words as well (hence the title of the post) and have accessed specific bits in a byte. ie
var variable= 126
variable.bit5=1
good luck getting that to work. I think you’ll need to use bit masking or some other craziness
Thanks for all the suggestions! PBASIC is not overly complicated (no order of operations!), so none of it should be too technically difficult. As for the 255 thing, I’m not going to check it. After all, if your code ends up producing 255’s, you probably want to know! The way I’ve planned out the tokenizer, expressions such as x=5*y/z will be evaluated in two steps, so truncating shouldn’t be an issue. The way I’m planning on doing individual bit assignments is to use different algorithms for 1 and 0. For setting a bit to 1, I will use | with everything set to 0’s except the bit that needs setting. For clearing a bit, I will use & with a mask of all 1’s except for the bit that needs clearing.
One more questions: has anyone ever had a need to access a specific nibble in a byte, or a specific byte in word? Is this even possible?
i don’t think it’d ever be nescasary to access a single byte in a word in the robot code since inputs and outputs are limited to bytes. maybe as a clever optimization or something, though.
Here’s our code that I created. The grabber subroutine is totally inefficent code-wise, but it works flawlessly. Our grabber is totally automated with 2 rocker switches… Also the code meshes well…
By renaming, I assume you mean:
newVarName VAR oldVarName
If not, please explain as I just finished coding the support for the above type of operation (including .bitX, .nibX, .byteX, etc) and would like to be finished with this section ASAP because everything else depends on it.
My brain hurts from all the binary math, but other than that, everything seems to be working!
*Originally posted by Ulibrium *
**Can you elaborate on the architecture of this emulator? Is it going to interpret object code or is it going to parse PBASIC code? **
I’m not quite sure what you mean by object code, but basically it will let you take a PBASIC program and “run” it on a regular computer, thus letting you see what it does without the need for a $1200 OI/RC pair, so I guess it would fall under the “parse PBASIC” category.
I make frequent use of looking at bits in a byte or word, but i have never needed to look at the nibble. now for thi biggest feature – communicate with the serial port and control the bot!
Recently, I’ve worked on an expression evaluator in C++. It would solve mathematical expressions in the correct order of operations. For example, I could input a string like “2*(5+4)^(1/2)” and it would output “6”. If you would like to collaborate, I would be glad to help. If I can get the source code to my program (I worked on it in school and we, the senior class, are pretty much done, so I haven’t showed up in a while). then I can provide you with my engine for parsing strings.
*Originally posted by rbayer *
**Anyone use BRANCH? This will be in there for sure (now that I know about it, I’m definately going to use it next year), but I’m trying to prioritize. **
my old team did, as well as multiple program slots.
debug would be nice, although probably not necessary.