A simple MSX Basic question

Page 2/2
1 |

By Josb

Master (196)

Josb's picture

04-11-2018, 12:13

thanks for your help, I will take it a look thoroughly.

Just a last question, do you know if DIM A makes code as fast as A=0?

By theNestruo

Expert (108)

theNestruo's picture

04-11-2018, 12:19

Not sure about that... probably for direct access DIM will make slower variables (as you have already veified)...

...but in real usage scenarios, they may be faster that the alternative of locating which variable is to be read/set. I mean, that probably this:
A(I)=B
is faster than:

100 ON I GOTO 120,130
110 A0=B:GOTO 140
120 A1=B:GOTO 140
130 A2=B
140 REM ...

By Josb

Master (196)

Josb's picture

04-11-2018, 12:29

I reckon that DIM A is just to make room in memory for A that should be totally different from DIM A(20) where the BASIC interpreter has to look for every index to find its value when using. Obviously, I don't know or the way of checking it.

Anyway, I'm grateful of your support. There are two ideas of you that I will use. The way of playing music and the sprite collision check Smile

By theNestruo

Expert (108)

theNestruo's picture

04-11-2018, 12:46

Oh! I see your point now about DIM A!! Actually, I've never tested it :/
In fact, this kind of optimizations are noticeable only where there is a large amount of code (are quite difficult to test in an isolated environment such as small programs in MSXpen). But maybe you can use Pérez the Mouse to test it, changing the first line to DIMs and running the game to see if it goes faster or slower.

And, of course, feel free to use any routine / optimization trick you find useful; that was the point of commenting the source code!! Smile

Page 2/2
1 |