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(__c64__) || defined(__c64reu__) || defined(__c128__)
42
43/* <usermanual>
44@keyword IMAGEREF (function)
45
46@english
47
48With the ''IMAGEREF'' instruction you can retrieve the reference to an image, an
49''ATLAS'' or a ''SEQUENCE'', which can then be used in place of the original
50image, as a placeholder. This instruction is very useful when you want to diversify
51the graphics to use, while maintaining the same game logic.
52
53@italian
54
55Con l'istruzione ''IMAGEREF'' è possibile recuperare il riferimento a una immagine,
56un ''ATLAS'' o una ''SEQUENCE'', da poter poi essere usato al posto dell'immagine
57originale, come un segnaposto. Questa istruzione risulta molto utile nel momento
58in cui si vogliano diversificare le grafiche da utilizzare, pur mantenendo la
59stessa logica di gioco.
60
61@syntax ... = IMAGEREF( atlas )
62
63@example airplane := LOAD ATLAS( "airplane.png" )
64@example elicopter := LOAD ATLAS( "elicopter.png" )
65@example DIM vehicle AS IMAGEREF
66@example IF vehicleType = 0 THEN
67@example vehicle = IMAGEREF( airplane )
68@example ELSE
69@example vehicle = IMAGEREF( elicopter )
70@example ENDIF
71@example PUT IMAGE vehicle FRAME 1 AT 0, 0
72
73</usermanual> */
74
75Variable * image_ref( Environment * _environment, char * _image ) {
76
77 Variable * image = variable_retrieve( _environment, _image );
78
79 Variable * imageRef = variable_temporary( _environment, VT_IMAGEREF, "(imageref)" );
80
81 image->usedImage = 1;
82
83 switch( image->type ) {
84 case VT_IMAGE:
85 if ( image->bankAssigned != -1 ) {
86
87 // BASE
88
89 outline1( "LDA #$%2.2x", (unsigned char)(image->absoluteAddress & 0xff));
90 outline1( "STA %s", imageRef->realName );
91 outline1( "LDA #$%2.2x", (unsigned char)((image->absoluteAddress>>8) & 0xff));
92 outline1( "STA %s", address_displacement( _environment, imageRef->realName, "1" ) );
93
94 // SIZE
95
96 outline1("LDA #$%2.2x", (unsigned char)( image->frameSize & 0xff ) );
97 outline1( "STA %s", address_displacement( _environment, imageRef->realName, "2" ) );
98 outline1("LDA #$%2.2x", (unsigned char)( ( image->frameSize >> 8 ) & 0xff ) );
99 outline1( "STA %s", address_displacement( _environment, imageRef->realName, "3" ) );
100
101 // BANK
102
103 outline1( "LDA #$%2.2x", image->bankAssigned );
104 outline1( "STA %s", address_displacement( _environment, imageRef->realName, "4" ) );
105
106 // INFO
107
108 outline0( "LDA #$07" );
109 outline1( "STA %s", address_displacement( _environment, imageRef->realName, "5" ) );
110
111 // RESIDENT
112
113 #if !defined(__c64reu__)
114 char bankWindowName[MAX_TEMPORARY_STORAGE];
115 sprintf( bankWindowName, "BANKWINDOW%2.2x", image->residentAssigned );
116 outline1("LDA #<%s", bankWindowName);
117 outline1( "STA %s", address_displacement( _environment, imageRef->realName, "6" ) );
118 outline1("LDA #>%s", bankWindowName);
119 outline1( "STA %s", address_displacement( _environment, imageRef->realName, "7" ) );
120 #endif
121
122 // TABLE1
123
124 // outline1( "LDX #%soffsetframe", image->realName );
125 // outline1( "STX %s+8", imageRef->realName );
126
127 // TABLE2
128
129 // outline1( "LDX #%soffsetsequence", image->realName );
130 // outline1( "STX %s+10", imageRef->realName );
131
132 } else {
133
134 // BASE
135
136 outline1("LDA #<%s", image->realName);
137 outline1( "STA %s", imageRef->realName );
138 outline1("LDA #>%s", image->realName);
139 outline1( "STA %s", address_displacement( _environment, imageRef->realName, "1" ) );
140
141 // SIZE
142
143 outline1("LDA #$%2.2x", (unsigned char)( image->frameSize & 0xff ) );
144 outline1( "STA %s", address_displacement( _environment, imageRef->realName, "2" ) );
145 outline1("LDA #$%2.2x", (unsigned char)( ( image->frameSize >> 8 ) & 0xff ) );
146 outline1( "STA %s", address_displacement( _environment, imageRef->realName, "3" ) );
147
148 // BANK
149
150 // outline1( "LDA #$%2.2x", image->bankAssigned );
151 // outline1( "STA %s+4", imageRef->realName );
152
153 // INFO
154
155 outline0( "LDA #$03" );
156 outline1( "STA %s", address_displacement( _environment, imageRef->realName, "5" ) );
157
158 // RESIDENT
159
160 // char bankWindowName[MAX_TEMPORARY_STORAGE];
161 // sprintf( bankWindowName, "BANKWINDOW%2.2x", image->residentAssigned );
162
163 // outline1( "LDX #%s", bankWindowName );
164 // outline1( "STX %s+6", imageRef->realName );
165
166 // TABLE1
167
168 // outline1( "LDX #%soffsetframe", image->realName );
169 // outline1( "STX %s+8", imageRef->realName );
170
171 // TABLE2
172
173 // outline1( "LDX #%soffsetsequence", image->realName );
174 // outline1( "STX %s+10", imageRef->realName );
175
176 }
177
178
179 break;
180
181 case VT_IMAGES:
182
183 if ( image->bankAssigned != -1 ) {
184
185 // BASE
186
187 outline1("LDA #$%2.2x", (unsigned char)( image->absoluteAddress & 0xff ) );
188 outline1( "STA %s", imageRef->realName );
189 outline1("LDA #$%2.2x", (unsigned char)( (image->absoluteAddress>>8) & 0xff ) );
190 outline1( "STA %s", address_displacement( _environment, imageRef->realName, "1" ) );
191
192 // SIZE
193
194 outline1("LDA #$%2.2x", (unsigned char)( image->frameSize & 0xff ) );
195 outline1( "STA %s", address_displacement( _environment, imageRef->realName, "2" ) );
196 outline1("LDA #$%2.2x", (unsigned char)( ( image->frameSize >> 8 ) & 0xff ) );
197 outline1( "STA %s", address_displacement( _environment, imageRef->realName, "3" ) );
198
199 // BANK
200
201 outline1( "LDA #$%2.2x", image->bankAssigned );
202 outline1( "STA %s", address_displacement( _environment, imageRef->realName, "4" ) );
203
204 // INFO
205
206 outline0( "LDA #$17" );
207 outline1( "STA %s", address_displacement( _environment, imageRef->realName, "5" ) );
208
209 // RESIDENT
210
211 #if !defined(__c64reu__)
212 char bankWindowName[MAX_TEMPORARY_STORAGE];
213 sprintf( bankWindowName, "BANKWINDOW%2.2x", image->residentAssigned );
214 outline1("LDA #<%s", bankWindowName);
215 outline1( "STA %s", address_displacement( _environment, imageRef->realName, "6" ) );
216 outline1("LDA #>%s", bankWindowName);
217 outline1( "STA %s", address_displacement( _environment, imageRef->realName, "7" ) );
218 #endif
219
220 // TABLE1
221
222 outline1("LDA #<%soffsetframe", image->realName);
223 outline1( "STA %s", address_displacement( _environment, imageRef->realName, "8" ) );
224 outline1("LDA #>%soffsetframe", image->realName);
225 outline1( "STA %s", address_displacement( _environment, imageRef->realName, "9" ) );
226
227 // TABLE2
228
229 // outline1( "LDX #%soffsetsequence", image->realName );
230 // outline1( "STX %s+10", imageRef->realName );
231
232 } else {
233
234 // BASE
235
236 outline1("LDA #<%s", image->realName);
237 outline1( "STA %s", imageRef->realName );
238 outline1("LDA #>%s", image->realName);
239 outline1( "STA %s", address_displacement( _environment, imageRef->realName, "1" ) );
240
241 // SIZE
242
243 outline1("LDA #$%2.2x", (unsigned char)( image->frameSize & 0xff ) );
244 outline1( "STA %s", address_displacement( _environment, imageRef->realName, "2" ) );
245 outline1("LDA #$%2.2x", (unsigned char)( ( image->frameSize >> 8 ) & 0xff ) );
246 outline1( "STA %s", address_displacement( _environment, imageRef->realName, "3" ) );
247
248 // BANK
249
250 // outline1( "LDA #$%2.2x", image->bankAssigned );
251 // outline1( "STA %s+4", imageRef->realName );
252
253 // INFO
254
255 outline0( "LDA #$13" );
256 outline1( "STA %s", address_displacement( _environment, imageRef->realName, "5" ) );
257
258 // RESIDENT
259
260 // char bankWindowName[MAX_TEMPORARY_STORAGE];
261 // sprintf( bankWindowName, "BANKWINDOW%2.2x", image->residentAssigned );
262
263 // BANK
264
265 outline1( "LDA #$%2.2x", (unsigned char)(image->bankAssigned&0xff) );
266 outline1( "STA %s", address_displacement( _environment, imageRef->realName, "4" ) );
267
268 // INFO
269
270 outline0( "LDA #$13" );
271 outline1( "STA %s", address_displacement( _environment, imageRef->realName, "5" ) );
272
273 // RESIDENT
274
275 // #if !defined(__c64reu__)
276 // char bankWindowName[MAX_TEMPORARY_STORAGE];
277 // sprintf( bankWindowName, "BANKWINDOW%2.2x", image->residentAssigned );
278 // outline1("LDA #<%s", bankWindowName);
279 // outline1( "STA %s", address_displacement( _environment, imageRef->realName, "6" ) );
280 // outline1("LDA #>%s", bankWindowName);
281 // outline1( "STA %s", address_displacement( _environment, imageRef->realName, "7" ) );
282 // #endif
283
284 // TABLE1
285
286 outline1("LDA #<%soffsetframe", image->realName);
287 outline1( "STA %s", address_displacement( _environment, imageRef->realName, "8" ) );
288 outline1("LDA #>%soffsetframe", image->realName);
289 outline1( "STA %s", address_displacement( _environment, imageRef->realName, "9" ) );
290
291 // TABLE2
292
293 // outline1( "LDX #%soffsetsequence", image->realName );
294 // outline1( "STX %s+10", imageRef->realName );
295
296 }
297
298 break;
299
300 case VT_SEQUENCE:
301
302 if ( image->bankAssigned != -1 ) {
303
304 // BASE
305
306 outline1("LDA #$%2.2x", (unsigned char)( image->absoluteAddress & 0xff ) );
307 outline1( "STA %s", imageRef->realName );
308 outline1("LDA #$%2.2x", (unsigned char)( (image->absoluteAddress>>8) & 0xff ) );
309 outline1( "STA %s", address_displacement( _environment, imageRef->realName, "1" ) );
310
311 // SIZE
312
313 outline1("LDA #$%2.2x", (unsigned char)( image->frameSize & 0xff ) );
314 outline1( "STA %s", address_displacement( _environment, imageRef->realName, "2" ) );
315 outline1("LDA #$%2.2x", (unsigned char)( ( image->frameSize >> 8 ) & 0xff ) );
316 outline1( "STA %s", address_displacement( _environment, imageRef->realName, "3" ) );
317
318 // BANK
319
320 outline1( "LDA #$%2.2x", (unsigned char)(image->bankAssigned&0xff) );
321 outline1( "STA %s", address_displacement( _environment, imageRef->realName, "4" ) );
322
323 // INFO
324
325 outline0( "LDA #$37" );
326 outline1( "STA %s", address_displacement( _environment, imageRef->realName, "5" ) );
327
328 // RESIDENT
329
330 #if !defined(__c64reu__)
331 char bankWindowName[MAX_TEMPORARY_STORAGE];
332 sprintf( bankWindowName, "BANKWINDOW%2.2x", image->residentAssigned );
333 outline1("LDA #<%s", bankWindowName);
334 outline1( "STA %s", address_displacement( _environment, imageRef->realName, "6" ) );
335 outline1("LDA #>%s", bankWindowName);
336 outline1( "STA %s", address_displacement( _environment, imageRef->realName, "7" ) );
337 #endif
338
339 // TABLE1
340
341 outline1("LDA #<%soffsetframe", image->realName);
342 outline1( "STA %s", address_displacement( _environment, imageRef->realName, "8" ) );
343 outline1("LDA #>%soffsetframe", image->realName);
344 outline1( "STA %s", address_displacement( _environment, imageRef->realName, "9" ) );
345
346 // TABLE2
347
348 outline1("LDA #<%soffsetsequence", image->realName);
349 outline1( "STA %s", address_displacement( _environment, imageRef->realName, "10" ) );
350 outline1("LDA #>%soffsetsequence", image->realName);
351 outline1( "STA %s", address_displacement( _environment, imageRef->realName, "11" ) );
352
353 } else {
354
355 // BASE
356
357 outline1("LDA #<%s", image->realName);
358 outline1( "STA %s", imageRef->realName );
359 outline1("LDA #>%s", image->realName);
360 outline1( "STA %s", address_displacement( _environment, imageRef->realName, "1" ) );
361
362 // SIZE
363
364 outline1("LDA #$%2.2x", (unsigned char)( image->frameSize & 0xff ) );
365 outline1( "STA %s", address_displacement( _environment, imageRef->realName, "2" ) );
366 outline1("LDA #$%2.2x", (unsigned char)( ( image->frameSize >> 8 ) & 0xff ) );
367 outline1( "STA %s", address_displacement( _environment, imageRef->realName, "3" ) );
368
369 // BANK
370
371 // outline1( "LDA #$%2.2x", image->bankAssigned );
372 // outline1( "STA %s+4", imageRef->realName );
373
374 // INFO
375
376 outline0( "LDA #$13" );
377 outline1( "STA %s", address_displacement( _environment, imageRef->realName, "5" ) );
378
379 // RESIDENT
380
381 // char bankWindowName[MAX_TEMPORARY_STORAGE];
382 // sprintf( bankWindowName, "BANKWINDOW%2.2x", image->residentAssigned );
383
384 // outline1( "LDX #%s", bankWindowName );
385 // outline1( "STX %s+6", imageRef->realName );
386
387 // TABLE1
388
389 outline1("LDA #<%soffsetframe", image->realName);
390 outline1( "STA %s", address_displacement( _environment, imageRef->realName, "8" ) );
391 outline1("LDA #>%soffsetframe", image->realName);
392 outline1( "STA %s", address_displacement( _environment, imageRef->realName, "9" ) );
393
394 // TABLE2
395
396 outline1("LDA #<%soffsetsequence", image->realName);
397 outline1( "STA %s", address_displacement( _environment, imageRef->realName, "10" ) );
398 outline1("LDA #>%soffsetsequence", image->realName);
399 outline1( "STA %s", address_displacement( _environment, imageRef->realName, "11" ) );
400
401 }
402
403 break;
404
405 default:
407 }
408
409 // FRAME WIDTH
410 outline1( "LDA #$%2.2x", image->frameWidth );
411 outline1( "STA %s+12", imageRef->realName );
412
413 // FRAME WIDTH
414 outline1( "LDA #$%2.2x", image->frameHeight );
415 outline1( "STA %s+13", imageRef->realName );
416
417 return imageRef;
418
419}
420
421#endif
Variable * variable_retrieve(Environment *_environment, char *_name)
Variable * variable_temporary(Environment *_environment, VariableType _type, char *_meaning)
Define a temporary variable.
char * address_displacement(Environment *_environment, char *_address, char *_displacement)
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