ugBASIC 1.18
An isomorphic BASIC language compiler for retrocomputers
Loading...
Searching...
No Matches
every_gosub.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
48/* <usermanual>
49@keyword EVERY...GOSUB
50
51@english
52
53The ''EVERY'' allows to call a subroutine at specified intervals of time.
54It is especially useful for creating animations, handling real-time events,
55and simulating dynamic behavior in your programs. You can give the
56''value'' as number of ticks to wait for triggering the call, and
57''timer'' to select a specific timer (up to 8 timers are present).
58
59It allows you to create smooth animations by moving objects on the
60screen at regular intervals, and it is essential for managing real-time
61events, such as character movement, object collisions, and keyboard input management.
62It can be used also to simulate physical or biological phenomena that evolve
63over time., or to create dynamic visual effects, such as sparks, explosions,
64or screen transitions.
65
66The speed at which ''EVERY'' commands execute depends on the frame
67rate of your computer, and from the parameter ''value'' given. A
68higher frame rate means that actions will be executed more frequently,
69while an higher ''value'' means that actions will be executed less frequently.
70
71Note that the subroutine execution time should be less than the interval time,
72or the main program timings will be affected!
73
74There are 8 delay timers from 0 to 7 which can be specified with ''timer''.
75If omitted ''timer'' defaults to 0. In the case of parallel task has 0 the
76highest and 8 the lowest priority.
77
78With ''EVERY OFF'' and ''EVERY ON'' you can disable or enable the timed
79calls. Subroutines run as long as the main loop / program runs, even the
80main programm is paused. It is important to know or realise that
81low-priority-subroutines which occurs simultanously to higher-priority-subroutines
82are not lost. Their task remains or handled again after finishing the higher-prio interrupt.
83
84Important: the meaning of this command is not altered by ''OPTION CALL'' pragma,
85so this is always a ''GOSUB'' and not a ''GOTO''!
86
87@italian
88
89''EVERY'' consente di richiamare una subroutine ad intervalli di tempo specificati.
90È particolarmente utile per creare animazioni, gestire eventi in tempo
91reale e simulare comportamenti dinamici nei tuoi programmi. Puoi dare ''value''
92come numero di tick da attendere per l'attivazione della chiamata e ''timer''
93per selezionare un timer specifico (sono presenti fino a 8 timer).
94
95Ti consente di creare animazioni fluide spostando oggetti sullo schermo a
96intervalli regolari ed è essenziale per gestire eventi in tempo reale, come
97il movimento dei personaggi, le collisioni di oggetti e la gestione dell'input
98da tastiera. Può anche essere utilizzato per simulare fenomeni fisici o biologici
99che si evolvono nel tempo, o per creare effetti visivi dinamici, come scintille,
100esplosioni o transizioni dello schermo.
101
102La velocità con cui vengono eseguiti i comandi ''EVERY'' dipende dal frame rate
103del tuo computer e dal parametro ''value'' fornito. Un frame rate più alto significa
104che le azioni saranno eseguite più frequentemente, mentre un ''valore'' più alto
105significa che le azioni saranno eseguite meno frequentemente.
106
107Nota che il tempo di esecuzione della procedura dovrebbe essere inferiore al
108tempo di intervallo, altrimenti i tempi del programma principale saranno
109influenzati!
110
111Ci sono 8 timer di ritardo da 0 a 7 che possono essere specificati con ''timer''.
112Se omesso, ''timer'' è impostato di default su 0. Nel caso di attività parallele,
1130 ha la priorità più alta e 8 la priorità più bassa.
114
115Con ''EVERY OFF'' e ''EVERY ON'' puoi disabilitare o abilitare le chiamate
116temporizzate. Le subroutine vengono eseguite finché il ciclo/programma principale
117è in esecuzione, anche il programma principale è in pausa. È importante sapere
118o realizzare che le subroutine a bassa priorità che si verificano simultaneamente
119a subroutine a priorità più alta non vengono perse. Il loro compito rimane o viene
120gestito di nuovo dopo aver terminato l'interruzione a priorità più alta.
121
122Importante: il significato di questo comando non viene alterato dalla direttiva
123''OPTION CALL'', quindi si tratta sempre di un ''GOSUB'' e non di un ''GOTO''!
124
125@syntax EVERY value[,timer] TICKS CALL identifier
126
127@example EVERY 50 TICKS CALL changeBorderColor
128@example EVERY 50,2 TICKS CALL changeBorderColor
129
130@usedInExample control_periodic_02.bas
131@usedInExample control_periodic_03.bas
132
133@seeAlso AFTER...CALL
134@seeAlso EVERY ON
135@seeAlso EVERY OFF
136@target pccga
137</usermanual> */
138
139void every_ticks_gosub( Environment * _environment, char * _timing, char * _label, char * _timer ) {
140
141 Variable * timing = variable_retrieve_or_define( _environment, _timing, VT_WORD, 0 );
142 Variable * timer = NULL;
143 char * timerRealName = NULL;
144 if ( _timer ) {
145 timer = variable_retrieve_or_define( _environment, _timer, VT_BYTE, 0 );
146 timerRealName = timer->realName;
147 }
148
149 pccga_timer_set_address( _environment, timerRealName, _label );
150 pccga_timer_set_counter( _environment, timerRealName, timing->realName );
151 pccga_timer_set_init( _environment, timerRealName, timing->realName );
152
153}
Variable * variable_retrieve_or_define(Environment *_environment, char *_name, VariableType _type, int _value)
void every_ticks_gosub(Environment *_environment, char *_timing, char *_label, char *_timer)
Emit ASM code for EVERY ... TICKS GOSUB ....
Definition every_gosub.c:54
void pccga_timer_set_address(Environment *_environment, char *_timer, char *_address)
Definition pccga.c:236
void pccga_timer_set_init(Environment *_environment, char *_timer, char *_init)
Definition pccga.c:218
void pccga_timer_set_counter(Environment *_environment, char *_timer, char *_counter)
Definition pccga.c:200
char * realName
Definition ugbc.h:982
struct _Variable Variable
Structure of a single variable.
struct _Environment Environment
Structure of compilation environment.
@ VT_WORD
Definition ugbc.h:455
@ VT_BYTE
Definition ugbc.h:450