Schrijver
| Help with MSX Basic
|
nokkieja msx friend Berichten: 1 | Geplaatst: 07 Mei 2007, 21:45   |
Hello there,
I Need some help with some old basic code.
I am translating a game (written in msx basic ) in Visual Basic.
Most of the code can be used as written
But there are some pieces in the code that i can't figure out.
Those pieces are:
1) if x or y then return
2) if not S then
3) p=gv+d1+10*(gv=30 and c=0) + (gv=3 and p=0)
4) SW=P=5
I have many years experience in programming but never saw code like this before.
Any one who can help me??
Thanx
|
|
cax
 msx professional Berichten: 1017 | Geplaatst: 07 Mei 2007, 22:06   |
>I have many years experience in programming
Really ?
"=", "or", "not" are boolean operations
Try to execute statements like
PRINT 5=5
PRINT not 6=7
and you will know what to expect.
|
|
AuroraMSX
 msx master Berichten: 1248 | Geplaatst: 07 Mei 2007, 22:36   |
Quote:
| Hello there,
I Need some help with some old basic code.
I am translating a game (written in msx basic ) in Visual Basic.
Most of the code can be used as written
But there are some pieces in the code that i can't figure out.
Those pieces are:
1) if x or y then return
2) if not S then
3) p=gv+d1+10*(gv=30 and c=0) + (gv=3 and p=0)
4) SW=P=5
I have many years experience in programming but never saw code like this before.
|
Then you've never seen (MSX) BASIC before
Any boolean expression--like (X OR Y) or (P=5)--returns either 0, when false, or -1, when true. Not only in BASIC, but also in a lot of other 3rd gen programming languages! So, if P really equals 5, the expression (P=5) equals -1, else it is 0.
maybe you'd feel more confy with the following equivalents of the above statements:
1) IF X<>0 OR Y<>0 THEN RETURN
2) IF S=0 THEN
3) IF GV=30 AND C=0 THEN
P=GV+D1+10*-1 + 0 ' If GV=30, GV cannot be 3, so the expression (GV=3 AND P=0) is false and therefore 0
ELSE
IF GV=3 AND P=0 THEN
P=GV+D1+10 * 0 + -1 'see comment above
ELSE
P=GV+D1+10 * 0 + 0
4) IF P=5 THEN SW=-1 ELSE SW=0
But that's real n00b and you won't find code like that in a program written by someone with years of programming experience
|
|
manuel msx guru Berichten: 3447 | Geplaatst: 07 Mei 2007, 22:38   |
Boolean expressions in basic result in -1 (true) or 0 (false).
1) plain boolean logic, but consider x and y as booleans, like this: if (x==-1 || y==-1)
2) see 1)
3) use the -1 and 0
4) this is just chain-assignment. sw=5  =5 This is also valid in C, e.g.
EDIT: darn, Auroor was just before me. You'll see constructions like this a lot in one-liners, because it's the only way to avoid if...then |
|
AuroraMSX
 msx master Berichten: 1248 | Geplaatst: 07 Mei 2007, 22:39   |
Quote:
| 4) this is just chain-assignment. sw=5  =5 This is also valid in C, e.g.
|
Buzz!
Edit: Oh, and Buzz! on your 1), too  |
|
arnold_m msx lover Berichten: 81 | Geplaatst: 07 Mei 2007, 22:51   |
Quote:
|
"=", "or", "not" are boolean operations
|
Actually "or", "not" and "and" are bitwise operators in MSX basic. (1 and 2) yields 0 not true.
The "=" can have two roles
- assignment as in 'a=38' or 'SW =P=5'
- comparison as in 'if a=42 then ...' of 'SW=P =5'
the first role is only used when the "+" is only preceded by a variable (or the keyword "let" plus a variable name).
The value of (x=y) is -1 if x and y are equal and 0 otherwise.
In memory -1 is represented with all bits equal to one, so this choice ensures that (not (x=y)) has the same value as (x<>y).
Msx basic does not have an Iif function or ?: operator, but with some arithmetic operations you can often avoid using 'if..then..' when what you want to have can achieved with the ?: operator. It's not good for readability though.
Edited: bold ='s, added: hmm, two people beat me to posting a reaction, fixed typo. |
|
flyguille msx master Berichten: 1202 | Geplaatst: 08 Mei 2007, 02:03   |
Quote:
| Hello there,
I Need some help with some old basic code.
I am translating a game (written in msx basic ) in Visual Basic.
Most of the code can be used as written
But there are some pieces in the code that i can't figure out.
Those pieces are:
1) if x or y then return
2) if not S then
3) p=gv+d1+10*(gv=30 and c=0) + (gv=3 and p=0)
4) SW=P=5
I have many years experience in programming but never saw code like this before.
Any one who can help me??
Thanx
|
all those sentences are directly executable in VB5 or 6 (also QBASIC) |
|
poke-1,170 msx professional Berichten: 862 | Geplaatst: 08 Mei 2007, 02:05   |
I think you scared the new kid away  |
|
arnold_m msx lover Berichten: 81 | Geplaatst: 08 Mei 2007, 20:14   |
BUZZ!
2) IF S <> -1 THEN
Remember "NOT" is a bitwise operator in MSX Basic |
|
|
|
|