ugBASIC 1.18
An isomorphic BASIC language compiler for retrocomputers
Loading...
Searching...
No Matches
music_load.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
47/* <usermanual>
48@keyword LOAD MUSIC
49
50@english
51
52The ''LOAD MUSIC'' command allows you to load a music file from the file system
53of the host system and use it, as music, directly in the program. Loading occurs
54at compile time: there is no access to the target system's file system. If multiple
55uploads are made to the same file, a single buffer will still be generated.
56
57Since it is possible to upload only one file of the same type at a time, it is necessary
58to be able to indicate an "alias" with which to exceed this limit. In this regard, there is also
59the ''AS'' syntax, which allows you to load the same file several times but with different names.
60
61@italian
62
63@syntax = LOAD MUSIC( filename )
64@syntax = LOAD MUSIC( filename AS alias )
65
66@example fugue = LOAD MUSIC("fugue.imf")
67@example fugueAnotherCopy = LOAD MUSIC("fugue.imf" as "fugue2")
68
69@target all
70</usermanual> */
71Variable * music_load( Environment * _environment, char * _filename, char * _alias, int _bank_expansion ) {
72
73 Variable * final = variable_temporary( _environment, VT_MUSIC, 0 );
74
75 if ( _environment->emptyProcedure ) {
76 return final;
77 }
78
79 if ( _environment->tenLinerRulesEnforced ) {
81 }
82
83 if ( _environment->sandbox ) {
84 CRITICAL_SANDBOX_ENFORCED( "LOAD MUSIC");
85 }
86
87 LoadedFile * first = _environment->loadedFiles;
88 char *lookfor = _filename;
89 if ( _alias ) {
90 lookfor = _alias;
91 }
92 while( first ) {
93 if ( strcmp(lookfor, first->fileName ) == 0 ) {
94 return first->variable;
95 }
96 first = first->next;
97 }
98
99 Variable * result = music_load_to_variable( _environment, _filename, _alias, _bank_expansion );
100
101 LoadedFile * loaded = malloc( sizeof( LoadedFile ) );
102 loaded->next = first;
103 loaded->variable = result;
104 loaded->fileName = lookfor;
105 _environment->loadedFiles = loaded;
106
107 if ( _alias ) {
108 const_define_numeric( _environment, _alias, UNIQUE_ID );
109 }
110
111 result->readonly = 1;
112
113 return result;
114
115}
void const_define_numeric(Environment *_environment, char *_name, int _value)
Variable * variable_temporary(Environment *_environment, VariableType _type, char *_meaning)
Define a temporary variable.
Variable * music_load_to_variable(Environment *_environment, char *_filename, char *_alias, int _bank_expansion)
Definition _music.c:732
Variable * music_load(Environment *_environment, char *_filename, char *_alias, int _bank_expansion)
Emit code for LOAD MUSIC(...).
Definition music_load.c:71
LoadedFile * loadedFiles
Definition ugbc.h:2636
int sandbox
Definition ugbc.h:2990
int tenLinerRulesEnforced
Definition ugbc.h:2985
int emptyProcedure
Definition ugbc.h:2932
char * fileName
Definition ugbc.h:1481
struct _LoadedFile * next
Definition ugbc.h:1486
Variable * variable
Definition ugbc.h:1483
int readonly
Definition ugbc.h:1195
void * malloc(YYSIZE_T)
#define CRITICAL_10_LINE_RULES_ENFORCED(v)
Definition ugbc.h:3550
#define UNIQUE_ID
Definition ugbc.h:3349
struct _Variable Variable
Structure of a single variable.
struct _Environment Environment
Structure of compilation environment.
@ VT_MUSIC
Definition ugbc.h:516
#define CRITICAL_SANDBOX_ENFORCED(v)
Definition ugbc.h:3687
struct _LoadedFile LoadedFile