ugBASIC 1.18
An isomorphic BASIC language compiler for retrocomputers
Loading...
Searching...
No Matches
bell.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(__c128z__)
42
52/* <usermanual>
53@keyword BELL
54
55@english
56
57The ''BELL'' command makes the computer emit a sound, usually a short beep,
58through the internal speaker or audio chipset. This sound serves as an
59acoustic signal to the user, indicating that an action has been completed,
60reporting an error, or simply to attract attention.
61
62It can be used alone, or specifying characteristics of the sound to be produced.
63When you use ''BELL'' with parameters, ugBASIC generates a sine wave with the
64frequency specified by the ''value'', and of ''duration'' length.
65The higher the value, the higher the pitch. The greater ''duration'', the
66greater time the sound will last.
67
68The ability to specify the frequency opens up many creative possibilities: by combining
69several ''BELL'' commands with different frequencies, you can create short melodies;
70you could simulate the sounds of explosions, pops, or other effects, depending on
71the frequency and duration of the sound; you can create specific beeps to indicate
72different conditions or events in your program.
73
74The supported frequency range may vary depending on the hardware of target computer.
75Typically, the duration of the sound produced by ''BELL'' is short and can be
76controlled by another, additional, parameter. Moreover, you can select a specific
77channel for audio output.
78
79Executing the command may or may not interrupt program execution, depending on the
80setting of ''DEFINE AUDIO SYNC''. Not all targets support all settings (synchronous
81and asynchronous).
82
83@italian
84Il comando ''BELL'' fa sì che il computer emetta un suono, solitamente un
85breve segnale acustico, tramite l'altoparlante interno o il chipset audio.
86Questo suono funge da segnale acustico per l'utente, indicando che un'azione
87è stata completata, segnalando un errore o semplicemente per attirare l'attenzione.
88
89Può essere utilizzato da solo o specificando le caratteristiche del suono da produrre.
90Quando si utilizza ''BELL'' con parametri, ugBASIC genera un'onda sinusoidale con la
91frequenza specificata dal ''valore'' e di lunghezza ''duration''. Più alto è il valore,
92più alto è il tono. Maggiore è la ''duration'', maggiore sarà la durata del suono.
93
94La possibilità di specificare la frequenza apre molte possibilità creative:
95combinando diversi comandi ''BELL'' con frequenze diverse, è possibile creare
96brevi melodie; è possibile simulare i suoni di esplosioni, scoppi o altri effetti,
97a seconda della frequenza e della durata del suono; è possibile creare segnali
98acustici specifici per indicare diverse condizioni o eventi nel programma.
99
100La gamma di frequenza supportata può variare a seconda dell'hardware del computer
101di destinazione. In genere, la durata del suono prodotto da ''BELL'' è breve e
102può essere controllata da un altro parametro aggiuntivo. Inoltre, è possibile
103selezionare un canale specifico per l'uscita audio.
104
105L'esecuzione del comando può interrompere o meno l'esecuzione del programma,
106a seconda dell'impostazione di DEFINE AUDIO SYNC. Non tutti i target supportano
107tutte le impostazioni (sincrone e asincrone).
108
109@syntax BELL
110@syntax BELL note
111@syntax BELL note, duration
112@syntax BELL note, duration ON channels
113
114@example BELL 42
115@example BELL #42 ON #%001
116
117@target c128
118</usermanual> */
119void bell( Environment * _environment, int _note, int _duration, int _channels ) {
120
121 sidz_start( _environment, _channels );
122 sidz_set_program( _environment, _channels, IMF_INSTRUMENT_GLOCKENSPIEL );
123 sidz_set_note( _environment, _channels, _note );
124
125 long durationInTicks = ( _duration / 20 ) & 0xff;
126
127 sidz_set_duration( _environment, _channels, durationInTicks );
128
129 if ( ! _environment->audioConfig.async ) {
130 sidz_wait_duration( _environment, _channels );
131 }
132
133}
134
144/* <usermanual>
145@keyword BELL
146
147@target c128
148</usermanual> */
149void bell_vars( Environment * _environment, char * _note, char * _duration, char * _channels, int _sync ) {
150
151 Variable * note = variable_retrieve_or_define( _environment, _note, VT_WORD, 42 );
152 if ( _channels ) {
153 Variable * channels = variable_retrieve_or_define( _environment, _channels, VT_WORD, 0x07 );
154 sidz_start_var( _environment, channels->realName );
156 sidz_set_note_vars( _environment, channels->realName, note->realName );
157 if ( _duration ) {
158 Variable * duration = variable_retrieve_or_define( _environment, _duration, VT_WORD, 0x07 );
159 Variable * durationInTicks = variable_div_const( _environment, duration->name, 20, NULL );
160 sidz_set_duration_vars( _environment, channels->realName, durationInTicks->realName );
161 } else {
162 sidz_set_duration_vars( _environment, channels->realName, NULL );
163 }
164 if ( ! _environment->audioConfig.async || _sync ) {
165 sidz_wait_duration_vars( _environment, channels->realName );
166 }
167 } else {
168 sidz_start_var( _environment, NULL );
170 sidz_set_note_vars( _environment, NULL, note->realName );
171 if ( _duration ) {
172 Variable * duration = variable_retrieve_or_define( _environment, _duration, VT_WORD, 0x07 );
173 Variable * durationInTicks = variable_div_const( _environment, duration->name, 20, NULL );
174 sidz_set_duration_vars( _environment, NULL, durationInTicks->realName );
175 } else {
176 sidz_set_duration_vars( _environment, NULL, NULL );
177 }
178 if ( ! _environment->audioConfig.async || _sync ) {
179 sidz_wait_duration_vars( _environment, NULL );
180 }
181 }
182
183}
184
185#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 bell_vars(Environment *_environment, char *_note, char *_duration, char *_channels, int _sync)
Emit ASM code for BELL ....
Definition bell.c:86
void bell(Environment *_environment, int _note, int _duration, int _channels)
Emit ASM code for BELL ....
Definition bell.c:56
void sidz_wait_duration_vars(Environment *_environment, char *_channels)
Definition sidz.c:948
void sidz_set_program(Environment *_environment, int _channels, int _program)
Definition sidz.c:344
void sidz_set_note_vars(Environment *_environment, char *_channels, char *_note)
Definition sidz.c:846
void sidz_start(Environment *_environment, int _channels)
Definition sidz.c:65
void sidz_set_note(Environment *_environment, int _channels, int _note)
Definition sidz.c:554
void sidz_set_duration(Environment *_environment, int _channels, int _duration)
Definition sidz.c:909
void sidz_wait_duration(Environment *_environment, int _channels)
Definition sidz.c:918
void sidz_set_duration_vars(Environment *_environment, char *_channels, char *_duration)
Definition sidz.c:927
void sidz_start_var(Environment *_environment, char *_channels)
Definition sidz.c:569
void sidz_set_program_semi_var(Environment *_environment, char *_channels, int _program)
Definition sidz.c:608
int async
Definition ugbc.h:2076
AudioConfig audioConfig
Definition ugbc.h:2420
char * name
Definition ugbc.h:979
char * realName
Definition ugbc.h:982
#define IMF_INSTRUMENT_GLOCKENSPIEL
Definition ugbc.h:4583
struct _Variable Variable
Structure of a single variable.
struct _Environment Environment
Structure of compilation environment.
@ VT_WORD
Definition ugbc.h:455