Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Programming (http://www.chiefdelphi.com/forums/forumdisplay.php?f=51)
-   -   Need list of feature for PBASIC emulator. (http://www.chiefdelphi.com/forums/showthread.php?t=4604)

rbayer 08-06-2002 00:30

Need list of features for PBASIC emulator.
 
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?

srawls 08-06-2002 11:55

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.

VanWEric 08-06-2002 22:15

<<>>
 
I like using << and >>

aand make sure it truncates the numbers "correctly" we don't want any emulator that is better at math than the real thing...

Ian W. 09-06-2002 00:13

lol

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...

Code:

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.

srawls 09-06-2002 10:32

type casting
 
How about just using type casting instead. For example

Code:

int x;

x = 5.9; //this would give you a warning like in your example
x = int(5.9); //this truncates correctly, and gives no warning

Stephen

VanWEric 09-06-2002 11:39

word up homies
 
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/2*2=4, not 5. C++ will do all the math out with some ungodly precision and then truncate. you may need to change x=x/2*2 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

rbayer 09-06-2002 14:04

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?

srawls 09-06-2002 14:20

from the manual (it would be var_name.<entry from below>)
Code:

lowbyte
highbyte
byte0
byte1
lownib
highnib
nib0
nib1
nib2
nib3

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.

Stephen

Jnadke 09-06-2002 17:59

variable renaming
lookup/lookdown
gosub

That's all I used that wasn't in your list...

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....

Jnadke 09-06-2002 18:02

1 Attachment(s)
Our code.

rbayer 09-06-2002 19:10

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!

Jnadke 10-06-2002 12:14

Yup... that's exactly what I mean... Thanks!

rbayer 10-06-2002 22:11

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.

Ian W. 10-06-2002 22:40

BRANCH? never heard of it. of course, i've only used the easy commands, cause i didn't know anything this year :D.

Ulibrium 10-06-2002 23:14

Can you elaborate on the architecture of this emulator? Is it going to interpret object code or is it going to parse PBASIC code?


All times are GMT -5. The time now is 00:10.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi