DemonSeed's Weekly Dumb Question (tm) (Development Foros MSX)MSX Resource Center PassionMSX MSX2 contest           
                       
English Nederlands Español Português Russian                  
 Noticias
   Página principal
  Almacén de noticias
  Temas de noticias

 Recursos
   Foros MSX
  Artículos
  Analisis
  Informe de ferias/RUs
  Álbum de fotos
  Ferias y encuentros
  Encuestas
  Enlaces
  Buscar

 Software
   Descargas
  Tienda Online

 MRC
   Quiénes somos
  Únete a nuestro equipo
  Donar
  Políticas
  Contacta con nosotros
  Enlázanos
  Estadísticas

 Buscar
 
  

  

 Login
 

Login

Contraseña




¿Aún no tienes una cuenta? ¡Conviértete en miembro del MSX Resource Center! ¡Únete a nosotros!.


 Estadísticas
 

Hay 91 invitados y 0 miembros en línea

Eres un usuario anónimo.
 

Foros MSX


Foros MSX

Development - DemonSeed's Weekly Dumb Question (tm)

Ir a la página ( 1 | 2 Siguiente página )
Autor

DemonSeed's Weekly Dumb Question (tm)

DemonSeed
msx professional
Mensajes: 883
Publicado: Abril 26 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
Mensajes: 2960
Publicado: Abril 26 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
Mensajes: 2960
Publicado: Abril 26 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
Mensajes: 2960
Publicado: Abril 26 2008, 17:06   
Test results:
NMS8255 GOTO: 385
NMS8255 GOSUB: 370

FS-A1GT GOTO: 1912
FS-A1GT GOSUB: 1843
DemonSeed
msx professional
Mensajes: 883
Publicado: Abril 26 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
Mensajes: 2960
Publicado: Abril 26 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
msx addict
Mensajes: 507
Publicado: Abril 26 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
Mensajes: 2960
Publicado: Abril 26 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
Mensajes: 883
Publicado: Abril 26 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
Mensajes: 2960
Publicado: Abril 27 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
Mensajes: 1474
Publicado: Abril 28 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
Mensajes: 2960
Publicado: Abril 28 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
Mensajes: 1474
Publicado: Abril 29 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
Mensajes: 1217
Publicado: Abril 29 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
Mensajes: 1474
Publicado: Abril 29 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.

 
Ir a la página ( 1 | 2 Siguiente página )
 







(c) 1994 - 2008 Fundación MSX Resource Center. MSX es una marca registrada de MSX Licensing Corporation