ugBASIC 1.18
An isomorphic BASIC language compiler for retrocomputers
Loading...
Searching...
No Matches
bank.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
41extern char DATATYPE_AS_STRING[][16];
42extern char BANK_TYPE_AS_STRING[][16];
43
70/* <usermanual>
71@keyword BANK...AT
72
73@english
74
75Define a bank of memory named ''id'', starting from ''address''
76and of type ''type''. Optionally, fill the bank of memory with static
77data coming from a specific ''filename''.
78
79Available ''type'': ''CODE'' for executable code (binary), ''VARIABLES''
80for program's variables, ''TEMPORARY'' for temporary variables and
81''DATA'' for unspecified data.
82
83If ''id'' is missing, the bank will have an unique name.
84If ''type'' is missing, the default type is ''DATA''.
85If ''filename'' is missing, the default is a simply memory reservation.
86
87@italian
88
89Definisce un banco di memoria denominata ''id'', che inizia da ''address''
90e di tipo ''type''. Facoltativamente, riempie il banco di memoria con dati statici
91da un ''filename'' specificato.
92
93Valori di''type'' accettabili: ''CODE'' per codice eseguibile (binario), ''VARIABLES''
94per variabili di programma, ''TEMPORARY'' per variabili temporanee e ''DATA'' per dati non specificati.
95
96Se ''id'' manca, la banca avrà un nome univoco.
97Se ''type'' manca, il tipo predefinito è ''DATA''.
98Se ''filename'' manca, il valore predefinito è una semplice prenotazione di memoria.
99
100@syntax BANK [id] AT #address [AS type] [WITH filename]
101
102@example BANK VARIABLES AT $c000
103
104@seeAlso VAR
105
106@deprecated
107 </usermanual> */
108Bank * bank_define( Environment * _environment, char * _name, BankType _type, int _address, char * _filename ) {
109
110 Bank * bank = NULL;
111 if ( _name != NULL ) {
112 bank = bank_find( _environment->banks[_type], _name );
113 } else {
114 char temporaryName[MAX_TEMPORARY_STORAGE];
115 sprintf(temporaryName, "bank%4.4d", UNIQUE_ID );
116 _name = strdup( temporaryName );
117 }
118 if ( bank ) {
119 // if ( _filename ) {
120 // outline4("; BANK %s %s AT $%4.4x WITH \"%s\" (duplicate)", BANK_TYPE_AS_STRING[_type], _name, _address, _filename);
121 // } else {
122 // outline3("; BANK %s %s AT $%4.4x (duplicate)", BANK_TYPE_AS_STRING[_type], _name, _address);
123 // }
124 } else {
125 if ( _filename ) {
126
127 } else {
128
129 }
130 bank = malloc( sizeof( Bank ) );
131 memset( bank, 0, sizeof( Bank ) );
132 bank->name = strdup( _name );
133 bank->type = _type;
134 bank->filename = _filename;
135 bank->address = _address;
136 // if ( bank->type == BT_STRINGS ) {
137 // variable_store( _environment, "stringsAddress", bank->address );
138 // }
139 bank->next = _environment->banks[_type];
140 _environment->banks[_type] = bank;
141 }
142 return bank;
143}
Bank * bank_find(Bank *_first, char *_name)
char BANK_TYPE_AS_STRING[][16]
Description of BANK TYPE, in readable format.
Bank * bank_define(Environment *_environment, char *_name, BankType _type, int _address, char *_filename)
Implementation for BANK xxx AT [WITH yyy].
Definition bank.c:108
int address
Definition ugbc.h:159
char * name
Definition ugbc.h:156
struct _Bank * next
Definition ugbc.h:185
BankType type
Definition ugbc.h:162
char * filename
Definition ugbc.h:165
Bank * banks[BANK_TYPE_COUNT]
Definition ugbc.h:2514
void * malloc(YYSIZE_T)
#define MAX_TEMPORARY_STORAGE
Definition ugbc.h:563
#define UNIQUE_ID
Definition ugbc.h:3349
struct _Environment Environment
Structure of compilation environment.
enum _BankType BankType
Type of memory banks.
struct _Bank Bank
Structure of a single bank.
char DATATYPE_AS_STRING[][16]