ugBASIC 1.18
An isomorphic BASIC language compiler for retrocomputers
Loading...
Searching...
No Matches
every_call.c
Go to the documentation of this file.
1/*****************************************************************************
2 * ugBASIC - an isomorphic BASIC language compiler for retrocomputers *
3 *****************************************************************************
4 * Copyright 2021-2026 Marco Spedaletti (asimov@mclink.it)
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 *----------------------------------------------------------------------------
18 * Concesso in licenza secondo i termini della Licenza Apache, versione 2.0
19 * (la "Licenza"); è proibito usare questo file se non in conformità alla
20 * Licenza. Una copia della Licenza è disponibile all'indirizzo:
21 *
22 * http://www.apache.org/licenses/LICENSE-2.0
23 *
24 * Se non richiesto dalla legislazione vigente o concordato per iscritto,
25 * il software distribuito nei termini della Licenza è distribuito
26 * "COSÌ COM'È", SENZA GARANZIE O CONDIZIONI DI ALCUN TIPO, esplicite o
27 * implicite. Consultare la Licenza per il testo specifico che regola le
28 * autorizzazioni e le limitazioni previste dalla medesima.
29 ****************************************************************************/
30
31/****************************************************************************
32 * INCLUDE SECTION
33 ****************************************************************************/
34
35#include "../../ugbc.h"
36
37/****************************************************************************
38 * CODE SECTION
39 ****************************************************************************/
40
41/* <usermanual>
42@keyword EVERY...CALL
43
44@english
45
46The ''EVERY'' allows to execute a procedure at specified intervals of time.
47It is especially useful for creating animations, handling real-time events,
48and simulating dynamic behavior in your programs. You can give the
49''value'' as number of ticks to wait for triggering the call, and
50''timer'' to select a specific timer (up to 8 timers are present).
51
52It allows you to create smooth animations by moving objects on the
53screen at regular intervals, and it is essential for managing real-time
54events, such as character movement, object collisions, and keyboard input management.
55It can be used also to simulate physical or biological phenomena that evolve
56over time., or to create dynamic visual effects, such as sparks, explosions,
57or screen transitions.
58
59The speed at which ''EVERY'' commands execute depends on the frame
60rate of your computer, and from the parameter ''value'' given. A
61higher frame rate means that actions will be executed more frequently,
62while an higher ''value'' means that actions will be executed less frequently.
63
64Note that the procedure execution time should be less than the interval time,
65or the main program timings will be affected!
66
67There are 8 delay timers from 0 to 7 which can be specified with ''timer''.
68If omitted ''timer'' defaults to 0. In the case of parallel task has 0 the
69highest and 8 the lowest priority.
70
71With ''EVERY OFF'' and ''EVERY ON'' you can disable or enable the timed
72calls. Procedures run as long as the main loop / program runs, even the
73main programm is paused. It is important to know or realise that
74low-priority-procedures which occurs simultanously to higher-priority-procedures
75are not lost. Their task remains or handled again after finishing the higher-prio interrupt.
76
77Important: the meaning of this command is not altered by ''OPTION CALL'' pragma,
78so this will always work like a ''CALL'' command and never as an unconditional
79jump to a label (''GOTO'').
80
81@italian
82
83''EVERY'' consente di eseguire azioni a intervalli di tempo specificati.
84È particolarmente utile per creare animazioni, gestire eventi in tempo
85reale e simulare comportamenti dinamici nei tuoi programmi. Puoi dare ''value''
86come numero di tick da attendere per l'attivazione della chiamata e ''timer''
87per selezionare un timer specifico (sono presenti fino a 8 timer).
88
89Ti consente di creare animazioni fluide spostando oggetti sullo schermo a
90intervalli regolari ed è essenziale per gestire eventi in tempo reale, come
91il movimento dei personaggi, le collisioni di oggetti e la gestione dell'input
92da tastiera. Può anche essere utilizzato per simulare fenomeni fisici o biologici
93che si evolvono nel tempo, o per creare effetti visivi dinamici, come scintille,
94esplosioni o transizioni dello schermo.
95
96La velocità con cui vengono eseguiti i comandi ''EVERY'' dipende dal frame rate
97del tuo computer e dal parametro ''value'' fornito. Un frame rate più alto significa
98che le azioni saranno eseguite più frequentemente, mentre un ''valore'' più alto
99significa che le azioni saranno eseguite meno frequentemente.
100
101Nota che il tempo di esecuzione della procedura dovrebbe essere inferiore al
102tempo di intervallo, altrimenti i tempi del programma principale saranno
103influenzati!
104
105Ci sono 8 timer di ritardo da 0 a 7 che possono essere specificati con ''timer''.
106Se omesso, ''timer'' è impostato di default su 0. Nel caso di attività parallele,
1070 ha la priorità più alta e 8 la priorità più bassa.
108
109Con ''EVERY OFF'' e ''EVERY ON'' puoi disabilitare o abilitare le chiamate
110temporizzate. Le procedure vengono eseguite finché il ciclo/programma principale
111è in esecuzione, anche il programma principale è in pausa. È importante sapere
112o realizzare che le procedure a bassa priorità che si verificano simultaneamente
113a procedure a priorità più alta non vengono perse. Il loro compito rimane o viene
114gestito di nuovo dopo aver terminato l'interruzione a priorità più alta.
115
116Importante: il significato di questo comando non viene alterato dalla direttiva
117''OPTION CALL'', quindi si tratta sempre di un ''GOSUB'' e non di un ''GOTO''!
118
119@syntax EVERY value[,timer] TICKS CALL identifier
120
121@example EVERY 50 TICKS CALL changeBorderColor
122@example EVERY 50,2 TICKS CALL changeBorderColor
123
124@usedInExample control_periodic_02.bas
125@usedInExample control_periodic_03.bas
126
127@seeAlso AFTER...GOSUB
128@seeAlso EVERY ON
129@seeAlso EVERY OFF
130@target coleco
131</usermanual> */
132void every_ticks_call( Environment * _environment, char * _timing, char * _name, char * _timer ) {
133
134 Procedure * procedure = _environment->procedures;
135
136 while( procedure ) {
137 if ( strcmp( procedure->name, _name ) == 0 ) {
138 break;
139 }
140 procedure = procedure->next;
141 }
142
143 if ( !procedure ) {
145 }
146
147 if ( procedure->protothread ) {
149 }
150
151 Variable * timing = variable_retrieve_or_define( _environment, _timing, VT_WORD, 0 );
152 Variable * timer = NULL;
153 char * timerRealName = NULL;
154 if ( _timer ) {
155 timer = variable_retrieve_or_define( _environment, _timer, VT_BYTE, 0 );
156 timerRealName = timer->realName;
157 }
158
159 coleco_timer_set_address( _environment, timerRealName, procedure->realName );
160 coleco_timer_set_counter( _environment, timerRealName, timing->realName );
161 coleco_timer_set_init( _environment, timerRealName, timing->realName );
162
163}
164
Variable * variable_retrieve_or_define(Environment *_environment, char *_name, VariableType _type, int _value)
void every_ticks_call(Environment *_environment, char *_timing, char *_name, char *_timer)
Definition every_call.c:46
void coleco_timer_set_init(Environment *_environment, char *_timer, char *_init)
void coleco_timer_set_address(Environment *_environment, char *_timer, char *_address)
void coleco_timer_set_counter(Environment *_environment, char *_timer, char *_counter)
Procedure * procedures
Definition ugbc.h:2621
struct _Procedure * next
Definition ugbc.h:1327
int protothread
Definition ugbc.h:1289
char * name
Definition ugbc.h:1256
char * realName
Definition ugbc.h:1259
char * realName
Definition ugbc.h:982
struct _Variable Variable
Structure of a single variable.
#define CRITICAL_PROCEDURE_MISSING(n)
Definition ugbc.h:3483
struct _Environment Environment
Structure of compilation environment.
@ VT_WORD
Definition ugbc.h:455
@ VT_BYTE
Definition ugbc.h:450
#define CRITICAL_PARALLEL_PROCEDURE_CANNOT_BE_CALLED(c)
Definition ugbc.h:3521
struct _Procedure Procedure