ugBASIC 1.18
An isomorphic BASIC language compiler for retrocomputers
Loading...
Searching...
No Matches
boom.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#if defined(__c128__) || defined(__c64__) || defined(__c64reu__)
42
51/* <usermanual>
52@keyword BOOM
53
54@english
55This command makes the computer emit an explosion-like sound. It is possible to indicate
56the duration of sound effect and on which voices the system should emit the sound. If omitted, it will be issued on all.
57
58Note that the execution of the effect can be synchronous or asynchronous, depending on the target.
59Synchronous execution means that the program will wait for the effect to complete before returning;
60on the contrary, asynchronous execution requires the program to continue executing subsequent instructions.
61
62The behavior can be modified by the ''DEFINE AUDIO SYNC'' and ''DEFINE AUDIO ASYNC''
63pragmas, which however may not be available for the target in question.
64
65@italian
66Questo comando fa emettere al computer un suono simile a una esplosione. E' possibile
67indicare la durata dell'effetto e su quali voci il sistema dovrà emettere il suono. Se omesso, sarà emesso su tutte.
68
69Da notare che l'esecuzione dell'effetto può essere sincrono o asincrono, a seconda
70del target. L'esecuzione sincrona implica che il programma attenderà che l'effetto
71si completi prima di tornare; al contrario, l'esecuzione asincrona prevede che il
72programma continui ad eseguire le successive istruzioni.
73
74Il comportamento può essere modificato dai pragma ''DEFINE AUDIO SYNC'' e
75''DEFINE AUDIO ASYNC'', che tuttavia potrebbe non essere disponibile per
76il target in oggetto.
77
78@syntax BOOM [duration [MS]] [ON channel]
79
80@example BOOM 1000 MS
81@example BOOM 100 MS ON %001
82
83@target c128
84@target c64
85</usermanual> */
86void boom( Environment * _environment, int _duration, int _channels ) {
87
88 sid_set_program( _environment, _channels, IMF_INSTRUMENT_EXPLOSION );
89 sid_start( _environment, _channels );
90 sid_set_frequency( _environment, _channels, 1000 );
91
92 long durationInTicks = ( _duration / 20 ) & 0xff;
93
94 sid_set_duration( _environment, _channels, durationInTicks );
95
96 if ( ! _environment->audioConfig.async ) {
97 sid_wait_duration( _environment, _channels );
98 }
99
100}
101
110/* <usermanual>
111@keyword BOOM
112@target c128
113@target c64
114</usermanual> */
115void boom_var( Environment * _environment, char * _duration, char * _channels ) {
116
117 if ( _channels ) {
118 Variable * channels = variable_retrieve_or_define( _environment, _channels, VT_WORD, 0x07 );
119 sid_start_var( _environment, channels->realName );
121 if ( _duration ) {
122 Variable * duration = variable_retrieve_or_define( _environment, _duration, VT_WORD, 0x07 );
123 Variable * durationInTicks = variable_div_const( _environment, duration->name, 20, NULL );
124 sid_set_duration_vars( _environment, channels->realName, durationInTicks->realName );
125 } else {
126 sid_set_duration_vars( _environment, channels->realName, NULL );
127 }
128 if ( ! _environment->audioConfig.async ) {
129 sid_wait_duration_vars( _environment, channels->realName );
130 }
131 } else {
132 sid_start_var( _environment, NULL );
134 if ( _duration ) {
135 Variable * duration = variable_retrieve_or_define( _environment, _duration, VT_WORD, 0x07 );
136 Variable * durationInTicks = variable_div_const( _environment, duration->name, 20, NULL );
137 sid_set_duration_vars( _environment, NULL, durationInTicks->realName );
138 } else {
139 sid_set_duration_vars( _environment, NULL, NULL );
140 }
141 if ( ! _environment->audioConfig.async ) {
142 sid_wait_duration_vars( _environment, NULL );
143 }
144 }
145
146}
147
148#endif
Variable * variable_retrieve_or_define(Environment *_environment, char *_name, VariableType _type, int _value)
Variable * variable_div_const(Environment *_environment, char *_source, int _destination, char *_remainder)
void boom_var(Environment *_environment, char *_duration, char *_channels)
Emit ASM code for BOOM ....
Definition boom.c:84
void boom(Environment *_environment, int _duration, int _channels)
Emit ASM code for BOOM ....
Definition boom.c:55
void sid_set_frequency(Environment *_environment, int _channels, int _frequency)
Definition sid.c:473
void sid_wait_duration(Environment *_environment, int _channels)
Definition sid.c:855
void sid_set_program(Environment *_environment, int _channels, int _program)
Definition sid.c:281
void sid_start_var(Environment *_environment, char *_channels)
Definition sid.c:506
void sid_set_program_semi_var(Environment *_environment, char *_channels, int _program)
Definition sid.c:545
void sid_start(Environment *_environment, int _channels)
Definition sid.c:65
void sid_wait_duration_vars(Environment *_environment, char *_channels)
Definition sid.c:884
void sid_set_duration_vars(Environment *_environment, char *_channels, char *_duration)
Definition sid.c:864
void sid_set_duration(Environment *_environment, int _channels, int _duration)
Definition sid.c:846
int async
Definition ugbc.h:2076
AudioConfig audioConfig
Definition ugbc.h:2420
char * name
Definition ugbc.h:979
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
#define IMF_INSTRUMENT_EXPLOSION
Definition ugbc.h:4573