ugBASIC 1.18
An isomorphic BASIC language compiler for retrocomputers
Loading...
Searching...
No Matches
image_ref.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(__coco__) || defined(__d32__) || defined(__d64__)
42
43Variable * image_ref( Environment * _environment, char * _image ) {
44
45 Variable * image = variable_retrieve( _environment, _image );
46
47 Variable * imageRef = variable_temporary( _environment, VT_IMAGEREF, "(imageref)" );
48
49 image->usedImage = 1;
50
51 switch( image->type ) {
52 case VT_IMAGE:
53 if ( image->bankAssigned != -1 ) {
54
55 // BASE
56
57 outline1( "LDX #$%4.4x", image->absoluteAddress );
58 outline1( "STX %s", imageRef->realName );
59
60 // SIZE
61
62 outline1( "LDD #$%4.4x", image->frameSize );
63 outline1( "STD %s+2", imageRef->realName );
64
65 // BANK
66
67 outline1( "LDA #$%2.2x", image->bankAssigned );
68 outline1( "STA %s+4", imageRef->realName );
69
70 // INFO
71
72 outline0( "LDA #$0f" );
73 outline1( "STA %s+5", imageRef->realName );
74
75 // RESIDENT
76
77 char bankWindowName[MAX_TEMPORARY_STORAGE];
78 sprintf( bankWindowName, "BANKWINDOW%2.2x", image->residentAssigned );
79
80 outline1( "LDX #%s", bankWindowName );
81 outline1( "STX %s+6", imageRef->realName );
82
83 // TABLE1
84
85 // outline1( "LDX #%soffsetframe", image->realName );
86 // outline1( "STX %s+8", imageRef->realName );
87
88 // TABLE2
89
90 // outline1( "LDX #%soffsetsequence", image->realName );
91 // outline1( "STX %s+10", imageRef->realName );
92
93 } else {
94
95 // BASE
96
97 outline1( "LDX #%s", image->realName );
98 outline1( "STX %s", imageRef->realName );
99
100 // SIZE
101
102 outline1( "LDD #$%4.4x", image->frameSize );
103 outline1( "STD %s+2", imageRef->realName );
104
105 // BANK
106
107 // outline1( "LDA #$%2.2x", image->bankAssigned );
108 // outline1( "STA %s+4", imageRef->realName );
109
110 // INFO
111
112 outline0( "LDA #$03" );
113 outline1( "STA %s+5", imageRef->realName );
114
115 // RESIDENT
116
117 // char bankWindowName[MAX_TEMPORARY_STORAGE];
118 // sprintf( bankWindowName, "BANKWINDOW%2.2x", image->residentAssigned );
119
120 // outline1( "LDX #%s", bankWindowName );
121 // outline1( "STX %s+6", imageRef->realName );
122
123 // TABLE1
124
125 // outline1( "LDX #%soffsetframe", image->realName );
126 // outline1( "STX %s+8", imageRef->realName );
127
128 // TABLE2
129
130 // outline1( "LDX #%soffsetsequence", image->realName );
131 // outline1( "STX %s+10", imageRef->realName );
132
133 }
134
135 break;
136
137 case VT_IMAGES:
138 if ( image->bankAssigned != -1 ) {
139
140 // BASE
141
142 outline1( "LDX #$%4.4x", image->absoluteAddress );
143 outline1( "STX %s", imageRef->realName );
144
145 // SIZE
146
147 outline1( "LDD #$%4.4x", image->frameSize );
148 outline1( "STD %s+2", imageRef->realName );
149
150 // BANK
151
152 outline1( "LDA #$%2.2x", image->bankAssigned );
153 outline1( "STA %s+4", imageRef->realName );
154
155 // INFO
156
157 outline0( "LDA #$1f" );
158 outline1( "STA %s+5", imageRef->realName );
159
160 // RESIDENT
161
162 char bankWindowName[MAX_TEMPORARY_STORAGE];
163 sprintf( bankWindowName, "BANKWINDOW%2.2x", image->residentAssigned );
164
165 outline1( "LDX #%s", bankWindowName );
166 outline1( "STX %s+6", imageRef->realName );
167
168 // TABLE1
169
170 outline1( "LDX #%soffsetframe", image->realName );
171 outline1( "STX %s+8", imageRef->realName );
172
173 // TABLE2
174
175 // outline1( "LDX #%soffsetsequence", image->realName );
176 // outline1( "STX %s+10", imageRef->realName );
177
178 } else {
179
180 // BASE
181
182 outline1( "LDX #%s", image->realName );
183 outline1( "STX %s", imageRef->realName );
184
185 // SIZE
186
187 outline1( "LDD #$%4.4x", image->frameSize );
188 outline1( "STD %s+2", imageRef->realName );
189
190 // BANK
191
192 // outline1( "LDA #$%2.2x", image->bankAssigned );
193 // outline1( "STA %s+4", imageRef->realName );
194
195 // INFO
196
197 outline0( "LDA #$13" );
198 outline1( "STA %s+5", imageRef->realName );
199
200 // RESIDENT
201
202 // char bankWindowName[MAX_TEMPORARY_STORAGE];
203 // sprintf( bankWindowName, "BANKWINDOW%2.2x", image->residentAssigned );
204
205 // outline1( "LDX #%s", bankWindowName );
206 // outline1( "STX %s+6", imageRef->realName );
207
208 // TABLE1
209
210 outline1( "LDX #%soffsetframe", image->realName );
211 outline1( "STX %s+8", imageRef->realName );
212
213 // TABLE2
214
215 // outline1( "LDX #%soffsetsequence", image->realName );
216 // outline1( "STX %s+10", imageRef->realName );
217
218 }
219
220 break;
221
222 case VT_SEQUENCE:
223 if ( image->bankAssigned != -1 ) {
224
225 // BASE
226
227 outline1( "LDX #$%4.4x", image->absoluteAddress );
228 outline1( "STX %s", imageRef->realName );
229
230 // SIZE
231
232 outline1( "LDD #$%4.4x", image->frameSize );
233 outline1( "STD %s+2", imageRef->realName );
234
235 // BANK
236
237 outline1( "LDA #$%2.2x", image->bankAssigned );
238 outline1( "STA %s+4", imageRef->realName );
239
240 // INFO
241
242 outline0( "LDA #$3f" );
243 outline1( "STA %s+5", imageRef->realName );
244
245 // RESIDENT
246
247 char bankWindowName[MAX_TEMPORARY_STORAGE];
248 sprintf( bankWindowName, "BANKWINDOW%2.2x", image->residentAssigned );
249
250 outline1( "LDX #%s", bankWindowName );
251 outline1( "STX %s+6", imageRef->realName );
252
253 // TABLE1
254
255 outline1( "LDX #%soffsetframe", image->realName );
256 outline1( "STX %s+8", imageRef->realName );
257
258 // TABLE2
259
260 outline1( "LDX #%soffsetsequence", image->realName );
261 outline1( "STX %s+10", imageRef->realName );
262
263 } else {
264
265 // BASE
266
267 outline1( "LDX #%s", image->realName );
268 outline1( "STX %s", imageRef->realName );
269
270 // SIZE
271
272 outline1( "LDD #$%4.4x", image->frameSize );
273 outline1( "STD %s+2", imageRef->realName );
274
275 // BANK
276
277 // outline1( "LDA #$%2.2x", image->bankAssigned );
278 // outline1( "STA %s+4", imageRef->realName );
279
280 // INFO
281
282 outline0( "LDA #$33" );
283 outline1( "STA %s+5", imageRef->realName );
284
285 // RESIDENT
286
287 // char bankWindowName[MAX_TEMPORARY_STORAGE];
288 // sprintf( bankWindowName, "BANKWINDOW%2.2x", image->residentAssigned );
289
290 // outline1( "LDX #%s", bankWindowName );
291 // outline1( "STX %s+6", imageRef->realName );
292
293 // TABLE1
294
295 outline1( "LDX #%soffsetframe", image->realName );
296 outline1( "STX %s+8", imageRef->realName );
297
298 // TABLE2
299
300 outline1( "LDX #%soffsetsequence", image->realName );
301 outline1( "STX %s+10", imageRef->realName );
302
303 }
304
305 break;
306
307 default:
309 }
310
311 // FRAME WIDTH
312 outline1( "LDA #$%2.2x", image->frameWidth );
313 outline1( "STA %s+12", imageRef->realName );
314
315 // FRAME WIDTH
316 outline1( "LDA #$%2.2x", image->frameHeight );
317 outline1( "STA %s+13", imageRef->realName );
318
319 return imageRef;
320
321}
322
323#endif
Variable * variable_retrieve(Environment *_environment, char *_name)
Variable * variable_temporary(Environment *_environment, VariableType _type, char *_meaning)
Define a temporary variable.
Variable * image_ref(Environment *_environment, char *_image)
Definition image_ref.c:43
int bankAssigned
Definition ugbc.h:1172
int residentAssigned
Definition ugbc.h:1175
int absoluteAddress
Definition ugbc.h:1092
int usedImage
Definition ugbc.h:1220
VariableType type
Definition ugbc.h:988
int frameSize
Definition ugbc.h:1134
int frameWidth
Definition ugbc.h:1162
int frameHeight
Definition ugbc.h:1164
char * realName
Definition ugbc.h:982
#define MAX_TEMPORARY_STORAGE
Definition ugbc.h:563
#define CRITICAL_IMAGEREF_ON_NON_IMAGE(v)
Definition ugbc.h:3755
struct _Variable Variable
Structure of a single variable.
struct _Environment Environment
Structure of compilation environment.
@ VT_IMAGEREF
Definition ugbc.h:537
@ VT_IMAGES
Definition ugbc.h:495
@ VT_IMAGE
Definition ugbc.h:489
@ VT_SEQUENCE
Definition ugbc.h:513
#define outline0(s)
Definition ugbc.h:4252
#define outline1(s, a)
Definition ugbc.h:4253