ugBASIC 1.18
An isomorphic BASIC language compiler for retrocomputers
Loading...
Searching...
No Matches
music.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
49/* <usermanual>
50@keyword MUSIC
51
52@english
53
54The ''MUSIC'' command starts a piece of music from the music variable. This
55music will be played independently of your program, without affecting it in the
56slightest.
57
58Normally, it's possible to store several complete arrangements.
59Each composition is assigned its own individual music variable.
60
61The music system is intelligent, and will automatically suspend your music for the
62duration of any subsequent sound effects on the current channel. When the sound has
63finished, your tune will be restarted from its previous position.
64
65The command accepts an additional keyword, ''LOOP'', which allows you to indicate that
66the piece of music must be played without ever ending playback: ugBASIC will make it
67start again from the beginning, once playback has finished.
68
69Finally, the command accepts the indication of the ''format'' in which the music is stored
70in the variable. This specification is necessary only if the audio file was not loaded
71by the ''LOAD MUSIC'' command. The ''LOAD MUSIC'' command takes care of converting one
72of the supported formats into the internal (''IAF'') ugBASIC format. However,
73ugBASIC can play formats compatible with your audio hardware. In this case, by specifying
74the format in which the data is prepared, it is possible to follow up on this request.
75
76Each target has a specific list of supported audio formats.
77
78@italian
79
80Il comando ''MUSIC'' avvia un brano musicale dalla variabile music. Questa musica
81verrà riprodotta indipendentemente dal tuo programma, senza influenzarlo minimamente.
82
83Normalmente è possibile memorizzare diversi arrangiamenti completi. Ad ogni composizione
84viene assegnata la propria variabile musicale individuale.
85
86Il sistema musicale è intelligente e sospenderà automaticamente la musica per la
87durata di eventuali effetti sonori successivi sul canale corrente. Una volta terminato
88il suono, la melodia verrà riavviata dalla posizione precedente.
89
90Il comando accetta una keyword aggiuntiva, LOOP, che permette di indicare che il brano
91musicale deve essere suonato senza mai terminare la riproduzione: ugBASIC lo farà
92ricominciare dall'inizio, una volta terminata la riproduzione.
93
94Infine, il comando accetta l'indicazione del formato (''format'') in cui la musica è memorizzata
95nella variabile. Questa specifica è necessaria solo ed unicamente se il file audio
96non è stato caricato dal comando LOAD MUSIC. Il comando LOAD MUSIC si occupa di
97convertire uno dei formati supportati nel formato interno di ugBASIC. Tuttavia, ugBASIC
98è in grado di riprodurre formati compatibili con l'hardware audio. In tal caso,
99specificando il formato con cui sono preparati i dati, è possibile dar seguito
100a tale richiesta.
101
102Ogni target ha uno specifico elenco di formati audio supportati.
103
104@syntax MUSIC [LOOP] music [format]
105@syntax MUSIC music [format] [LOOP]
106
107@example MUSIC fugue
108@example MUSIC backmusic LOOP
109@example MUSIC soundtrack PSG
110
111@target c128
112</usermanual> */
113void music_var( Environment * _environment, char * _music, int _loop, int _music_type ) {
114
115 if ( _environment->emptyProcedure ) {
116 return;
117 }
118
119 Variable * music = variable_retrieve( _environment, _music );
120
121 if ( _music_type == MUSIC_TYPE_AUTO ) {
122
123 if ( music->type != VT_MUSIC ) {
124 CRITICAL_CANNOT_MUSIC( _music );
125 }
126
127 if ( ! music->sidFile ) {
128 sid_start( _environment, 0xff );
129 sid_music( _environment, music->realName, music->size, _loop );
130 } else {
131 if ( music->sidFile->initAddress && music->sidFile->playAddress ) {
132 sid_player_init( _environment, music->sidFile->initAddress );
133 sid_player_play( _environment, music->sidFile->playAddress );
134 }
135 }
136
137 }
138
139}
140
141/* <usermanual>
142@keyword MUSIC PAUSE
143
144@english
145
146The ''MUSIC PAUSE'' command allows you to temporarily suspend the performance of a piece of music.
147The suspension is carried out either by interrupting the execution of the notes and by setting
148the volume to zero. The music can be reactivated using the command ''MUSIC RESUME''.
149
150@italian
151
152Il comando ''MUSIC PAUSE'' permette di sospendere temporaneamente l'esecuzione di un brano musicale.
153La sospensione è svolta sia interrompendo l'esecuzione delle note che ponendo il volume a zero.
154La musica potrà essere riattivata utilizzando il comando ''MUSIC RESUME''.
155
156@syntax MUSIC PAUSE
157
158@example MUSIC PAUSE: WAIT KEY: MUSIC RESUME
159
160@target c128
161</usermanual> */
162void music_pause( Environment * _environment ) {
163
165
166 variable_store( _environment, "SIDMUSICPAUSE", 0xff );
167 volume( _environment, 0, 0x7 );
168
169}
170
171/* <usermanual>
172@keyword MUSIC RESUME
173
174@english
175
176The ''MUSIC RESUME'' command allows you to resume a suspended performance of a piece of music.
177The music can be suspended using the command ''MUSIC PAUSE''.
178
179@italian
180
181Il comando ''MUSIC RESUME'' permette di riprendere l'esecuzione di un brano musicale.
182La musica viene sospesa dal comando ''MUSIC PAUSE''.
183
184@syntax MUSIC RESUME
185
186@example MUSIC PAUSE: WAIT KEY: MUSIC RESUME
187
188@target c128
189</usermanual> */
190void music_resume( Environment * _environment ) {
191
193
194 variable_store( _environment, "SIDMUSICPAUSE", 0x0 );
195 volume( _environment, 255, 0x7 );
196
197}
198
199/* <usermanual>
200@keyword MUSIC STOP
201
202@english
203
204The ''MUSIC STOP'' command allows you to halt definitively the performance of a piece of music.
205
206@italian
207
208Il comando ''MUSIC STOP'' permette di fermare in modo definitivo l'esecuzione di un brano musicale.
209
210@syntax MUSIC STOP
211
212@example MUSIC STOP
213
214@target c128
215</usermanual> */
216void music_stop( Environment * _environment ) {
217
219
220 cpu_store_8bit( _environment, "SIDMUSICLOOP", 0x0 );
221 cpu_store_8bit( _environment, "SIDMUSICREADY", 0x0 );
222 volume( _environment, 0, 0x7 );
223
224}
225
226/* <usermanual>
227@keyword MUSIC SEEK
228
229@english
230
231The ''MUSIC SEEK'' command allows you to move the reproduction to a specific position.
232
233@italian
234
235Il comando ''MUSIC SEEK'' permette di spostare l'esecuzione a una posizione specifica.
236
237@syntax MUSIC SEEK position
238
239@example MUSIC SEEK 42
240
241@target c128
242</usermanual> */
243void music_seek_var( Environment * _environment, char * _position ) {
244
246
247 Variable * position = variable_retrieve_or_define( _environment, _position, VT_WORD, 0 );
248
249 cpu_move_8bit( _environment, address_displacement( _environment, position->realName, "1" ), "SN76489BLOCKS" );
250 cpu_move_8bit( _environment, position->realName, "SIDLASTBLOCK" );
251
252}
253
void cpu_store_8bit(Environment *_environment, char *_destination, int _value)
CPU 6309: emit code to store 8 bit
Definition 6309.c:761
void cpu_move_8bit(Environment *_environment, char *_source, char *_destination)
CPU 6309: emit code to move 8 bit
Definition 6309.c:743
Variable * variable_retrieve(Environment *_environment, char *_name)
Variable * variable_retrieve_or_define(Environment *_environment, char *_name, VariableType _type, int _value)
Variable * variable_store(Environment *_environment, char *_destination, unsigned int _value)
Store a direct value to a variable.
char * address_displacement(Environment *_environment, char *_address, char *_displacement)
void music_var(Environment *_environment, char *_music, int _loop, int _music_type)
Emit ASM code for MUSIC ....
Definition music.c:54
void music_pause(Environment *_environment)
Definition music.c:81
void music_seek_var(Environment *_environment, char *_position)
Definition music.c:124
void music_stop(Environment *_environment)
Definition music.c:109
void music_resume(Environment *_environment)
Definition music.c:95
void volume(Environment *_environment, int _volume, int _channels)
Emit ASM code for VOLUME ....
Definition volume.c:70
unsigned char src_hw_sid_music_asm[]
void sid_player_play(Environment *_environment, int _play_address)
Definition sid.c:909
void sid_start(Environment *_environment, int _channels)
Definition sid.c:65
void sid_player_init(Environment *_environment, int _init_address)
Definition sid.c:899
void sid_music(Environment *_environment, char *_music, int _size, int _loop)
Definition sid.c:824
int emptyProcedure
Definition ugbc.h:2932
int initAddress
Definition sid_file.h:37
int playAddress
Definition sid_file.h:38
SIDFILE * sidFile
Definition ugbc.h:1213
int size
Definition ugbc.h:1077
VariableType type
Definition ugbc.h:988
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_MUSIC
Definition ugbc.h:516
@ MUSIC_TYPE_AUTO
Definition ugbc.h:241
#define CRITICAL_CANNOT_MUSIC(v)
Definition ugbc.h:3572
#define deploy(s, e)
Definition ugbc.h:4288