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 BANK_TYPE_AS_STRING[][16];
42
52void bank_cleanup( Environment * _environment ) {
53 int i=0;
54 for(i=0; i<BANK_TYPE_COUNT; ++i) {
55 Bank * actual = _environment->banks[i];
56 while( actual ) {
57 if ( actual->type == BT_VARIABLES ) {
58
59 } else if ( actual->type == BT_TEMPORARY ) {
60
61 } else if ( actual->type == BT_STRINGS ) {
62
63 } else {
64 // if ( actual->filename ) {
65 // cfgline4("# BANK %s %s AT $%4.4x WITH \"%s\"", BANK_TYPE_AS_STRING[actual->type], actual->name, actual->address, actual->filename);
66 // } else {
67 // cfgline3("# BANK %s %s AT $%4.4x", BANK_TYPE_AS_STRING[actual->type], actual->name, actual->address);
68 // }
69 cfgline2("%s: load = MAIN, type = ro, optional = yes, start = $%4.4x;", actual->name, actual->address);
70 if ( actual->filename ) {
71 int b = 0;
72 check_if_filename_is_valid( _environment, actual->filename );
73 FILE * file = fopen(actual->filename, "rb" );
74 if ( !file ) {
75 fprintf(stderr, "Compiler error: unable to open file %s\n", actual->filename);
76 exit(EXIT_FAILURE);
77 }
78 if ( actual->filename ) {
79 outline4("; BANK %s %s AT $%4.4x WITH \"%s\" (duplicate)", BANK_TYPE_AS_STRING[actual->type], actual->name, actual->address, actual->filename);
80 } else {
81 outline3("; BANK %s %s AT $%4.4x (duplicate)", BANK_TYPE_AS_STRING[actual->type], actual->name, actual->address);
82 }
83 // TODO: customize loading of data, based on data type and target
84 outhead1(".segment \"%s\"", actual->name);
85 while( !feof( file ) ) {
86 if ( ( b % 8 ) == 0 ) {
87 out0("\n");
88 out0("\t.byte ");
89 }
90 unsigned char data = fgetc(file);
91 out1("$%2.2x", ( data & 0xff ) );
92 if ( ( ( b % 8 ) != 7 ) ) {
93 out0(",");
94 }
95 ++b;
96 }
97 out0("\n");
98 fclose(file);
99 }
100 }
101 actual = actual->next;
102 }
103 }
104}
int check_if_filename_is_valid(Environment *_environment, char *_filename)
char BANK_TYPE_AS_STRING[][16]
Description of BANK TYPE, in readable format.
void bank_cleanup(Environment *_environment)
Emit source and configuration lines for banks.
Definition bank.c:52
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
#define BANK_TYPE_COUNT
Maximum number of bank types.
Definition ugbc.h:145
#define outline3(s, a, b, c)
Definition ugbc.h:4255
struct _Environment Environment
Structure of compilation environment.
#define out0(s)
Definition ugbc.h:4259
#define cfgline2(s, a, b)
Definition ugbc.h:4275
@ BT_VARIABLES
Definition ugbc.h:126
@ BT_STRINGS
Definition ugbc.h:135
@ BT_TEMPORARY
Definition ugbc.h:129
#define out1(s, a)
Definition ugbc.h:4260
struct _Bank Bank
Structure of a single bank.
#define outline4(s, a, b, c, d)
Definition ugbc.h:4256
#define outhead1(s, a)
Definition ugbc.h:4247