DemonSeed's Weekly Dumb Question (tm) (Development MSX Fora)MSX Resource Center MRC MEGA Challenge - Win one of 3 free One Chip MSX computers!           
            
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 166 gasten en 5 MSX vrienden online

Je bent een anonieme bezoeker.
 

MSX Fora


MSX Fora

Development - DemonSeed's Weekly Dumb Question (tm)

Ga naar pagina ( 1 | 2 Volgende pagina )
Schrijver

DemonSeed's Weekly Dumb Question (tm)

DemonSeed
msx professional
Berichten: 850
Geplaatst: 26 April 2008, 16:31   
In BASIC:

If you just as well can use:

ON [parameter] GOTO ...., ...., ...., etc.

...could you simply assume it's always faster than:

ON [parameter] GOSUB ...., ...., ...., etc.

?

It's hard to test it...
[D-Tail]

msx guru
Berichten: 2925
Geplaatst: 26 April 2008, 16:50   
I would guess that depends on the [parameter] part. But as long as [parameter] is the same, the ON [parameter] GOTO is indeed faster. It is a powerful BASIC construct that I almost never use, because it is not easy to use. I recall the first target would comply to the value "1", the second to "2", so in case of e.g. a fast keyboard input method it is already getting quite complex:

A$ = INPUT$(1)
ON asc(A$) - 64 GOTO 50, 100, 150, 20, ...

This piece of crap demonstrates the usage with capitals A, B, C, ... and it's not very intuitively as "A" has ASC#65. So why subtract 64?
[D-Tail]

msx guru
Berichten: 2925
Geplaatst: 26 April 2008, 17:00   
Here's a way to test it though:
10 PRINT "Press any key and wait for 20s": A$ = INPUT$(1): A = 0
20 R = RND(-TIME): TIME = 0
30 N = INT(RND(1) * 8) + 1
40 A = A + 1
50 ON N GOTO 80, 90, 100, 110, 120, 130, 140, 150
60 IF TIME < 500 GOTO 30
70 PRINT "ON x GOTO: ";A: GOTO 160
80 GOTO 60
90 GOTO 60
100 GOTO 60
110 GOTO 60
120 GOTO 60
130 GOTO 60
140 GOTO 60
150 GOTO 60
160 A = 0: TIME = 0
170 N = INT(RND(1) * 8) + 1
180 A = A + 1
190 ON N GOSUB 220, 230, 240, 250, 260, 270, 280, 290
200 IF TIME < 500 GOTO 170
210 PRINT "ON x GOSUB: ";A: PRINT "[Higher is better]": END
220 RETURN
230 RETURN
240 RETURN
250 RETURN
260 RETURN
270 RETURN
280 RETURN
290 RETURN

[D-Tail]

msx guru
Berichten: 2925
Geplaatst: 26 April 2008, 17:06   
Test results:
NMS8255 GOTO: 385
NMS8255 GOSUB: 370

FS-A1GT GOTO: 1912
FS-A1GT GOSUB: 1843
DemonSeed
msx professional
Berichten: 850
Geplaatst: 26 April 2008, 17:13   
Thanks very much!

The ON ... GOTO / GOSUB command has proven to be very useful in control / directional routines BTW.

For instance when: [parameter] = STICK (0)

Works like a charm, as these values can only range from 0 to 8; zero sorting no effect and no errors. It just does nothing.
[D-Tail]

msx guru
Berichten: 2925
Geplaatst: 26 April 2008, 18:01   
That's true, and that was the only useful application that I could come up with

Actually, even that doesn't work for me in many occasions, as I usually want 1P controls with cursors and joystick A at the same time.
SLotman
online
msx addict
Berichten: 479
Geplaatst: 26 April 2008, 18:23   
Quote:

Actually, even that doesn't work for me in many occasions, as I usually want 1P controls with cursors and joystick A at the same time.



What about doing S=STICK(0) or STICK(1) : ON S GOTO ...? That should enable both cursor keys and joy1 at the same time, with minimum overhead
[D-Tail]

msx guru
Berichten: 2925
Geplaatst: 26 April 2008, 19:50   
SLotman: you do have a point here, but what if STICK(0) reads 1 [north] and STICK(1) reads 5 [south]? I'd like to make no movement then, as the two cancel each other out. Using your suggestion, it would read 5 -> down. It gets even worse when STICK(0) reads 2 [north east] and STICK(1) reads 5 [south]. Together that would add up to 7, which is [west], while neither of the sticks was pointing in that direction.

More off topic: in this case it'd be better to make two ON STICK(x) GOTO clauses, where each line associates dx and dy with a value.
DemonSeed
msx professional
Berichten: 850
Geplaatst: 26 April 2008, 23:05   
If it's not a very 'heavy' routine and you want independent results for keys and joy1, is there any merit in putting it in a FOR_NEXT loop with the affected values in DIMensions?
[D-Tail]

msx guru
Berichten: 2925
Geplaatst: 27 April 2008, 02:42   
It might be me [and it probably is, 'cuz I had a couple of beers] but I don't seem to get a hold of your vision here. Do you mean something like DIM D(3): FOR I = 0 TO 2: D(I) = STICK(I): NEXT ? Because I don't know what kind of profit you'd gain by doing stuff like this. Except of course, you put STICK() in a variable, which saves time. But that is common practice, so...
NYYRIKKI
msx master
Berichten: 1467
Geplaatst: 28 April 2008, 16:15   
How about something like:
FORS=1TO8:AX(S)=(S>5)-((S>1)AND(S<5)):AY(S)=(S<3)-((S>3)AND(S<7))+(S=8):NEXT

Usage is something like...
S=STICK(1): X=X+AX(S):Y=Y+AY(S)

... and in case of multiple input devices:
FOR I=0 TO 2:S=STICK(I): X=X+AX(S):Y=Y+AY(S):NEXT

[D-Tail]

msx guru
Berichten: 2925
Geplaatst: 28 April 2008, 22:06   
NYY: that's a compact version of a routine that I regularly use. Although mine checks the ports for mice as well [hotplugging, mind you!]. My code is nowhere near as incomprehensible though
NYYRIKKI
msx master
Berichten: 1467
Geplaatst: 29 April 2008, 10:20   
Hmm... Actually this is faster, more compact and more easy to understand version:
FORI=2TO8:T=SGN(I-5):AX(I)=-T:AY(1+((I+5)and7))=T:NEXT



AuroraMSX

msx master
Berichten: 1214
Geplaatst: 29 April 2008, 17:09   
Shouldn't that read:
FORI=2TO8:T=SGN(5-I):AX(I)=T:AY((I+1)AND7+1)=T:NEXT
?
NYYRIKKI
msx master
Berichten: 1467
Geplaatst: 29 April 2008, 21:29   
Nope, that can't work... How ever I see, you have a good point in there...
(AND7+1=AND8)

I think correct formula is:
FORI=2TO8:T=SGN(5-I):AX(I)=T:AY((I+1AND7)+1)=T:NEXT

... but I can't check at the moment.

 
Ga naar pagina ( 1 | 2 Volgende pagina )
 







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