New pictures of our new game (Development MSX Fora)MSX Resource Center            
            
English Nederlands Espa�ol Portugu�s Russian         
 Nieuws
   Voorpagina
  Nieuws archief
  Nieuws onderwerpen

 Informatie
   MSX Fora
  Artikelen
  Recensies
  Beursverslagen
  Fotoreportages
  Beurzen en meetings
  Enquêtes
  Links
  Zoek

 Software
   Downloads
  Webshop

 MRC
   Wie we zijn
  Kom bij ons team
  Doneren
  Policies
  Contact met het MRC
  Link naar Ons
  Statistieken

 Zoek
 
  

  

 Login
 

Gebruikersnaam

Wachtwoord




Ben je nog niet lid? Klik hier en word MSX vriend!


 Statistieken
 

Er zijn 51 gasten en 1 MSX vriend online

Je bent een anonieme bezoeker.
 

MSX Fora


MSX Fora

Development - New pictures of our new game

Ga naar pagina ( Vorige pagina 1 | 2 | 3 | 4 | 5 | 6 | 7 Volgende pagina )
Schrijver

New pictures of our new game

[D-Tail]

msx guru
Berichten: 3019
Geplaatst: 07 Mei 2004, 23:10   
Some other things (AFAIK, undocumented )

Ex.: IF A=3 GOTO 50
The 'THEN' directive can be omitted. Only works when you test and directly jump. Eg. the following is *illegal*:
Ex.: IF A=3 GOSUB 50

I think the '<>0' issue from flyguille should be described in some more [D-Tail] (hence the name ):
If you have a statement like this:
Ex.: IF A+B<>0 GOTO 50
it will only execute the part after the equation (if A+B evaluate to non-zero), so that is 'GOTO 50' in this case.

You can omit the '<>0'. Why is that? BASIC uses -not fully exposed- boolean variables. If you've seen some part of Java, C or PHP code (or whatever), you'll often see something like this:

boolean Truth=false;

or

$truth=false;

Well, BASIC uses a kind of similar boolean system as well, except for the fact that BASIC doesn't have reserved keywords for that. Instead, it uses integer values. More specific, '-1' is considered a true value, and '0' is a false value. In case of the IF statement, they (Micro$oft) have relaxed this setting. If A+B happens to be 3, it is neither false nor true. To make things easy, they stated that anything non-false should be considered as true. Note that this doesn't declare 3==-1!
[D-Tail]

msx guru
Berichten: 3019
Geplaatst: 07 Mei 2004, 23:12   
Don't know WHY the hell they chose '-1' for being a true value... '1' would seem more logical to me...
Vincent van Dam
msx addict
Berichten: 382
Geplaatst: 07 Mei 2004, 23:30   
Any value not 0 should be considered true, this is also the implementation in MSX Basic:

1 remarks not included
2 a=10
3 if a then print "a=true"

flyguille
msx master
Berichten: 1223
Geplaatst: 08 Mei 2004, 00:33   
a integer value -1 is &B1111111111111111 , all bits set to 1, so, that is true. But as all bit are tested at the same time, any bit on 1 will trigger the TRUE event.

on all programming language a value that is not 0 is true... bacause don't exist other state than TRUE or FALSE in a binary math.

On assembler programming the TRUE or FALSE is tested with the ZERO flag, so, when a math operation return as result = 0 the ZERO FLAG is activated, so the jump is executed for the ELSE (JRZ) part or THEN part (JRNZ).

So, starting from the assembler programming the BASIC think is "all value than is not 0 is true". Also on "C" programming indeed, and of course in basic programming...

Now, if you want to give to some integer value other meaning you are free to programing that. but that is more slow and complicated..


By example, if you want the following status.

-1 = TRUE
0 = FALSE
1 = NON_TEST_YET

if you mixed all this value in one variable, you need all the time write sentences as:

if x =-1 then
if x = 0 then
if x= 1 then

But you can use a second variable for:

if xt = 0 then 'non tested else 'tested

..... (on tested)
if x then 'true else 'false


and you can repeat quickly several time that verification
also allow you to use the value in math formulas. Without the x=1 (untested) value that can return wrong results.

ex:

z=x*y

when z, x and y are integer variables with boolean values.









[D-Tail]

msx guru
Berichten: 3019
Geplaatst: 08 Mei 2004, 00:54   
Nope, that's not true (f*king word ) at all.
[edit]<-- referring to Vincent van Dam[/edit]

For instance, say
PRINT 2=2
result:
-1
files


Why is this? '2=2' is considered a statement, an equation and not an assignment . I say '2 equals 2'. BASIC agrees with that and says 'true'. What you said with your rule no. 2:
A=10
it's different. It isn't a statement, it's an assignment. You say: 'A becomes 10', and BASIC agrees with that. It doesn't say 'true', however. Y'see, that's the difference between assignment and statements. A=10 is different from ?A=10. In other programming languages it's much easier to distinguish assignments from equations. Hence the double '='-sign in many languages.

So, anything that is evaluated 'non-false' can be considered 'not-completely-true' OR 'true'.

As stated before, BASIC reads a line like this (Ex. with the 'if'-thingy):
10 A=2
20 IF A THEN END
30 GOTO 30

This program will end, because:
You assign the value 2 to the variable A. Then you say: 'IF A'. BASIC sees that A != 0, so BASIC says, A is not false. It's neither completely true, but that doesn't matter, thinks BASIC. So BASIC happily executes the 'THEN END'.

[edit]flyguille, your explanation's quite nice! [/edit]

Moral of the story: Don't expect your programs to always work properly in one go, in the way you coded them. If it doesn't work, buy another BASIC interpreter, which distincts 'not false' from completely true
flyguille
msx master
Berichten: 1223
Geplaatst: 08 Mei 2004, 01:00   
inside of a IF THEN sentence, A=10 mean a comparation, not a asignation.
flyguille
msx master
Berichten: 1223
Geplaatst: 08 Mei 2004, 01:07   
until i know, the VB .NET not do that distincts....

IF a then

still having that eternal rule

ofcourse, the VB got boolean variable. On assembler level that mean to wasted 1 byte (all bits) to give to that only one meaning. True or False something..... Very used for speed up the routines on z80. Because

LD A,(val)
AND A

is more faster and short than

LD A,(val)
BIT x,A




[D-Tail]

msx guru
Berichten: 3019
Geplaatst: 08 Mei 2004, 01:12   
Quote:

if x =-1 then
if x = 0 then
if x= 1 then



Concerning BASIC, I know a faster way to handle this (maybe not faster speaking in terms of Math, but faster in interpreting, and that's what counts, in this case).

ON (x+2) GOTO <line1>,<line2>,<line3>

This statement works like this. First, BASIC evaluates 'x'. if X is 1, it will proceed to the first mentioned line, in this case <line1>. If it is 2, it will proceed to the 2nd mentioned line, <line2>. The thing-between-parentheses must be an integer expression, ranging between 0 and 255 (otherwise, an Illegal function call is issued). If the integer expression equals 0 (false), or is greater (integer-wise) than the number of following line numbers, it will proceed to the next executable instruction. Otherwise, evaluate the integer expression, and take the respective line number.

So, why x+2? Because the INT expression must be in the range 0 <= x <= 255. Since the important values were -1, 0 and 1, we should add it by 2 to make it 'special'.


Programming example:

10 A$="": A=INT(RND(-TIME)*200+1)
20 ON A GOTO 40, 50, 60, 70
30 A=A-1: A$="or greater": GOTO 20

40 PRINT "A equals 1": END
50 PRINT "A equals 2": END
60 PRINT "A equals 3": END
70 PRINT "A equals 4"+A$: END


Don't look at the functionality of this piece-a-crap We'd do it much shorter than that

Conclusion: is ON x GOTO really necessary? If you'd take mine answer, I'd say 'No!'. IF-THEN works fine, and things could be accelerated with NBASIC. Nevertheless, ON x GOTO is very nice and handy for lazy people who don't like to type that much, and for people who don't wanna learn about NBASIC. Furthermore, without NBASIC, it's proven faster than an awesome lot of 'IF-THEN' sequences.
[D-Tail]

msx guru
Berichten: 3019
Geplaatst: 08 Mei 2004, 01:18   
Actually, you can do some nice things with NPR (NestorPReter):


@DEFINE	true	-1
@DEFINE	false	0

~
		A=INT(RND(1)*4+1):
		B=INT(RND(1)*2+5):
		if (A+B)=@true
		then
		print "Yeah! A+B was REALLY true!"
		else
		if (A+B)=@false
		then
		print "Yeah! A+B was FALSE!"
		else
		print "Well... A+B is true. Not really true, but true enough to be considered true ;)"


Hehe... Nice piece-a-code, methinks
flyguille
msx master
Berichten: 1223
Geplaatst: 08 Mei 2004, 01:28   
ON (x+2) GOTO <line1>,<line2>,<line3>


yeah, i use that , is faster.



That is faster every if you need to GOTO somewhere on all proposes

because when the BASIC interpreter do a GOTO , or when it change to execute the next line, the basic interprete do some work, like, check for all events like ON STOP GOSUB, ON INTERVAL GOSUB, ON SPRITE GOSUB, ON KEY GOSUB, upgrading some variables , etc. Do that allway, if you not used that events, allway need check if you are using the event or not.

So, if faster this:


IF A then X=Y else X=Z

than

IF A goto 100 else 200

100 X=Y
....
200 X=Z


EDITED: because that, on a animation routine, is very important to use few lines numbers than got a readable code. About speed. And on the possible, NOT INSERT SPACES

IFaTHEN

is faster than

IF A THEN

THENX=1
putsprite1,(x,y)

in that, the MSX-BASIC is great, it allow to erase the spaces...
On other hand , a space use a byte, and you got a longer basic program.
GuyveR800
msx guru
Berichten: 3048
Geplaatst: 08 Mei 2004, 02:43   
Quote:

Some other things (AFAIK, undocumented )

Ex.: IF A=3 GOTO 50


This is documented

Quote:

Don't know WHY the hell they chose '-1' for being a true value... '1' would seem more logical to me...


No, -1 is more logical.
All bits set 0 or all bits set 1.

tniASM uses -1/0 true/false logic too. It allows you to use binary operators in stead of boolean operators. And allows stuff like: x*(1+2*(x<0)) which is equivalent to ABS(x)
It has all kinds of other advantages too, like switch true/false is just a CPL in assembly

Vincent van Dam
msx addict
Berichten: 382
Geplaatst: 08 Mei 2004, 09:30   
Quote:

You assign the value 2 to the variable A. Then you say: 'IF A'. BASIC sees that A != 0, so BASIC says, A is not false. It's neither completely true, but that doesn't matter, thinks BASIC.



That's basicly what I wanted to show, that any value not 0 is evaluated as true. Anyway, the post was redundant (you already stated that in the post before my post, but I read over it). I agree with GuyveR800 that -1 makes more sense.
flyguille
msx master
Berichten: 1223
Geplaatst: 08 Mei 2004, 15:45   
x*(1+2*(x<0)) which is equivalent to ABS(x)

that's basicaly just that i show when i say, if you got 2 meanings on one variable (0 and -1) you can use this on math formula. If you insert a 3erd meaning, that 3erd 'not-completely-true' can bothered.
flyguille
msx master
Berichten: 1223
Geplaatst: 08 Mei 2004, 15:48   
the 14 last replies, are off this topic, maybe an @ want to translate this replies to other thread, with a more acurate topic like "tricks for fast basic programming"
[D-Tail]

msx guru
Berichten: 3019
Geplaatst: 08 Mei 2004, 17:45   
Of course, about that 'all bits are set'... I could have figured myself

About the speed of the ON x GOTO statement:
It's also faster because BASIC only has to read the INT value once. If you've something like this:

IF X=2 THEN 200
ELSE
IF X=3 THEN 500
ELSE
IF X=6000 THEN 20

The X will be read thrice from memory. Variable handling is just a 'little' bit slow in BASIC (unless they're integers, of course. But still then they're read thrice. ON x GOTO will be MUCH faster because the variable's only accessed once).
 
Ga naar pagina ( Vorige pagina 1 | 2 | 3 | 4 | 5 | 6 | 7 Volgende pagina )
 







(c) 1994 - 2008 Stichting MSX Resource Center. MSX is een trademark van MSX Licensing Corporation.