ugBASIC 1.18
An isomorphic BASIC language compiler for retrocomputers
Loading...
Searching...
No Matches
put_image.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];
42
53void put_image_vars_original( Environment * _environment, char * _image, char * _x1, char * _y1, char * _x2, char * _y2, char * _frame, char * _sequence, char * _flags ) {
54
55 if ( _environment->emptyProcedure ) {
56 return;
57 }
58
60
61 Variable * image = variable_retrieve( _environment, _image );
62
63 Resource * resource = build_resource_for_sequence( _environment, _image, _frame, _sequence );
64
65 Variable * x1 = variable_retrieve_or_define( _environment, _x1, VT_POSITION, 0 );
66 Variable * y1 = variable_retrieve_or_define( _environment, _y1, VT_POSITION, 0 );
67 Variable * realFrame = NULL;
68 Variable * frame = NULL;
69 if ( _frame) {
70 frame = variable_retrieve_or_define( _environment, _frame, VT_BYTE, 0 );
71 realFrame = frame;
72 }
73 Variable * sequence = NULL;
74 if ( _sequence) {
75 sequence = variable_retrieve_or_define( _environment, _sequence, VT_BYTE, 0 );
76 realFrame = frame;
77 }
78
79 switch( resource->type ) {
80 case VT_SEQUENCE:
81 if ( image->bankAssigned != -1 ) {
82
83 char alreadyLoadedLabel[MAX_TEMPORARY_STORAGE];
84 sprintf(alreadyLoadedLabel, "%salready", label );
85
86 char bankWindowId[MAX_TEMPORARY_STORAGE];
87 sprintf( bankWindowId, "BANKWINDOWID%2.2x", image->residentAssigned );
88
89 char bankWindowName[MAX_TEMPORARY_STORAGE];
90 sprintf( bankWindowName, "BANKWINDOW%2.2x", image->residentAssigned );
91
92 // cpu_compare_and_branch_16bit_const( _environment, bankWindowId, image->variableUniqueId, alreadyLoadedLabel, 1 );
93 // if ( image->uncompressedSize ) {
94 // bank_uncompress_semi_var( _environment, image->bankAssigned, image->absoluteAddress, bankWindowName );
95 // } else {
96 // bank_read_semi_var( _environment, image->bankAssigned, image->absoluteAddress, bankWindowName, image->size );
97 // }
98 // cpu_store_16bit(_environment, bankWindowId, image->variableUniqueId );
99 // cpu_label( _environment, alreadyLoadedLabel );
100
101 Variable * frameSize = variable_temporary( _environment, VT_WORD, "(temporary)");
102 variable_store( _environment, frameSize->name, image->frameSize );
103 Variable * bank = variable_temporary( _environment, VT_BYTE, "(temporary)");
104 variable_store( _environment, bank->name, image->bankAssigned );
105 Variable * offset = variable_temporary( _environment, VT_ADDRESS, "(temporary)");
106
107 if ( !sequence ) {
108 if ( !frame ) {
109 c6847_calculate_sequence_frame_offset(_environment, offset->realName, "", "", image->frameSize, image->frameCount );
110 } else {
111 c6847_calculate_sequence_frame_offset(_environment, offset->realName, "", frame->realName, image->frameSize, image->frameCount );
112 }
113 } else {
114 if ( !frame ) {
115 c6847_calculate_sequence_frame_offset(_environment, offset->realName, sequence->realName, "", image->frameSize, image->frameCount );
116 } else {
117 c6847_calculate_sequence_frame_offset(_environment, offset->realName, sequence->realName, frame->realName, image->frameSize, image->frameCount );
118 }
119 }
120
121 Variable * address = variable_temporary( _environment, VT_ADDRESS, "(temporary)");
122 variable_store( _environment, address->name, image->absoluteAddress );
123 variable_add_inplace_vars( _environment, address->name, offset->name );
124 bank_read_vars_direct( _environment, bank->name, address->name, bankWindowName, frameSize->name );
125
126 Resource resource;
127 resource.realName = strdup( bankWindowName );
128 resource.isAddress = 0;
129
130 c6847_put_image( _environment, &resource, x1->realName, y1->realName, NULL, NULL, image->frameSize, 0, _flags );
131
132 } else {
133 if ( !sequence ) {
134 if ( !frame ) {
135 c6847_put_image( _environment, resource, x1->realName, y1->realName, "", "", image->frameSize, image->frameCount, _flags );
136 } else {
137 c6847_put_image( _environment, resource, x1->realName, y1->realName, frame->realName, "", image->frameSize, image->frameCount, _flags );
138 }
139 } else {
140 if ( !frame ) {
141 c6847_put_image( _environment, resource, x1->realName, y1->realName, "", sequence->realName, image->frameSize, image->frameCount, _flags );
142 } else {
143 c6847_put_image( _environment, resource, x1->realName, y1->realName, frame->realName, sequence->realName, image->frameSize, image->frameCount, _flags );
144 }
145 }
146 }
147 break;
148 case VT_IMAGES:
149 if ( image->bankAssigned != -1 ) {
150
151 char alreadyLoadedLabel[MAX_TEMPORARY_STORAGE];
152 sprintf(alreadyLoadedLabel, "%salready", label );
153
154 char bankWindowId[MAX_TEMPORARY_STORAGE];
155 sprintf( bankWindowId, "BANKWINDOWID%2.2x", image->residentAssigned );
156
157 char bankWindowName[MAX_TEMPORARY_STORAGE];
158 sprintf( bankWindowName, "BANKWINDOW%2.2x", image->residentAssigned );
159
160 // cpu_compare_and_branch_16bit_const( _environment, bankWindowId, image->variableUniqueId, alreadyLoadedLabel, 1 );
161 // if ( image->uncompressedSize ) {
162 // bank_uncompress_semi_var( _environment, image->bankAssigned, image->absoluteAddress, bankWindowName );
163 // } else {
164 // bank_read_semi_var( _environment, image->bankAssigned, image->absoluteAddress, bankWindowName, image->size );
165 // }
166 // cpu_store_16bit(_environment, bankWindowId, image->variableUniqueId );
167 // cpu_label( _environment, alreadyLoadedLabel );
168
169 Variable * frameSize = variable_temporary( _environment, VT_WORD, "(temporary)");
170 variable_store( _environment, frameSize->name, image->frameSize );
171 Variable * bank = variable_temporary( _environment, VT_BYTE, "(temporary)");
172 variable_store( _environment, bank->name, image->bankAssigned );
173 Variable * offset = variable_temporary( _environment, VT_ADDRESS, "(temporary)");
174
175 if ( sequence ) {
176 if ( image->strips ) {
177 realFrame = variable_temporary( _environment, VT_BYTE, "(real frame)" );
178 outline0("PSHS Y,D");
179 outline1("LDY #%sstrip", image->realName );
180 outline1("LDA %s", sequence->realName );
181 outline0("LSLA" );
182 outline0("LDY A, Y");
183 outline1("LDA %s", frame->realName );
184 outline0("LDB A, Y" );
185 outline1("STB %s", realFrame->realName );
186 outline0("PULS Y,D");
187 } else {
189 }
190 }
191
192 if ( !frame ) {
193 c6847_calculate_sequence_frame_offset(_environment, offset->realName, NULL, "", image->frameSize, 0 );
194 } else {
195 c6847_calculate_sequence_frame_offset(_environment, offset->realName, NULL, realFrame->realName, image->frameSize, 0 );
196 }
197
198 Variable * address = variable_temporary( _environment, VT_ADDRESS, "(temporary)");
199 variable_store( _environment, address->name, image->absoluteAddress );
200 variable_add_inplace_vars( _environment, address->name, offset->name );
201 bank_read_vars_direct( _environment, bank->name, address->name, bankWindowName, frameSize->name );
202
203 Resource resource;
204 resource.realName = strdup( bankWindowName );
205 resource.isAddress = 0;
206
207 c6847_put_image( _environment, &resource, x1->realName, y1->realName, NULL, NULL, image->frameSize, 0, _flags );
208
209 } else {
210
211 if ( sequence ) {
212 if ( image->strips ) {
213 realFrame = variable_temporary( _environment, VT_BYTE, "(real frame)" );
214 outline0("PSHS Y,D");
215 outline1("LDY #%sstrip", image->realName );
216 outline1("LDA %s", sequence->realName );
217 outline0("LSLA" );
218 outline0("LDY A, Y");
219 outline1("LDA %s", frame->realName );
220 outline0("LDB A, Y" );
221 outline1("STB %s", realFrame->realName );
222 outline0("PULS Y,D");
223 } else {
225 }
226 }
227
228 if ( !frame ) {
229 c6847_put_image( _environment, resource, x1->realName, y1->realName, "", NULL, image->frameSize, 0, _flags );
230 } else {
231 c6847_put_image( _environment, resource, x1->realName, y1->realName, realFrame->realName, NULL, image->frameSize, 0, _flags );
232 }
233 }
234 break;
235 case VT_IMAGE:
236 case VT_TARRAY:
237 if ( image->bankAssigned != -1 ) {
238
239 char alreadyLoadedLabel[MAX_TEMPORARY_STORAGE];
240 sprintf(alreadyLoadedLabel, "%salready", label );
241
242 char bankWindowId[MAX_TEMPORARY_STORAGE];
243 sprintf( bankWindowId, "BANKWINDOWID%2.2x", image->residentAssigned );
244
245 char bankWindowName[MAX_TEMPORARY_STORAGE];
246 sprintf( bankWindowName, "BANKWINDOW%2.2x", image->residentAssigned );
247
248 cpu_compare_and_branch_16bit_const( _environment, bankWindowId, image->variableUniqueId, alreadyLoadedLabel, 1 );
249 if ( image->uncompressedSize ) {
250 bank_uncompress_semi_var( _environment, image->bankAssigned, image->absoluteAddress, bankWindowName );
251 } else {
252 bank_read_semi_var( _environment, image->bankAssigned, image->absoluteAddress, bankWindowName, image->size );
253 }
254 cpu_store_16bit(_environment, bankWindowId, image->variableUniqueId );
255 cpu_label( _environment, alreadyLoadedLabel );
256
257 Resource resource;
258 resource.realName = strdup( bankWindowName );
259 resource.isAddress = 0;
260
261 c6847_put_image( _environment, &resource, x1->realName, y1->realName, NULL, NULL, 1, 0, _flags );
262 } else {
263 c6847_put_image( _environment, resource, x1->realName, y1->realName, NULL, NULL, 1, 0, _flags );
264 }
265 break;
266 default:
268 }
269
270}
271
272void put_image_vars_imageref( Environment * _environment, char * _image, char * _x1, char * _y1, char * _x2, char * _y2, char * _frame, char * _sequence, char * _flags ) {
273
275
276 Variable * image = variable_retrieve( _environment, _image );
277
278 Variable * x1 = variable_retrieve_or_define( _environment, _x1, VT_POSITION, 0 );
279 Variable * y1 = variable_retrieve_or_define( _environment, _y1, VT_POSITION, 0 );
280 Variable * frame = NULL;
281 if ( _frame) {
282 frame = variable_retrieve_or_define( _environment, _frame, VT_BYTE, 0 );
283 }
284 Variable * sequence = NULL;
285 if ( _sequence) {
286 sequence = variable_retrieve_or_define( _environment, _sequence, VT_BYTE, 0 );
287 }
288
289 Variable * address = variable_temporary( _environment, VT_ADDRESS, "(stub)" );
290
291 if ( !_environment->putImageRefUnsafe ) {
292 outline1("LDA %s", address_displacement( _environment, image->realName, "5") );
293 outline1("LBEQ %sskip", label );
294 }
295
296 // Y = OFFSET
297
298 if ( _sequence ) {
299 outline0("LDY #$3" );
300 if ( strlen(_sequence) == 0 ) {
301 } else {
302 outline1("LDB %s", sequence->realName );
303 outline1("JSR [%s+10]", image->realName );
304 }
305 if ( _frame ) {
306 if ( strlen(_frame) == 0 ) {
307 } else {
308 outline1("LDB %s", frame->realName );
309 outline1("JSR [%s+8]", image->realName );
310 }
311 }
312 } else {
313 if ( _frame ) {
314 outline0("LDY #$3" );
315 if ( strlen(_frame) == 0 ) {
316 } else {
317 outline1("LDB %s", frame->realName );
318 outline1("JSR [%s+8]", image->realName );
319 }
320 } else {
321 outline0("LDY #$0" );
322 }
323 }
324
325 // Y = BASE + OFFSET
326 outline0( "TFR Y, D" );
327 outline1( "ADDD %s", image->realName );
328 outline0( "TFR D, Y" );
329
330 outline1("STY %s", address->realName );
331
332 Resource resource;
333 resource.realName = strdup( address->realName );
334 resource.isAddress = 1;
335
336 c6847_put_image( _environment, &resource, x1->realName, y1->realName, NULL, NULL, 0, 0, _flags );
337
338 if ( !_environment->putImageRefUnsafe ) {
339 outhead1("%sskip", label );
340 }
341
342}
343
344void put_image_vars( Environment * _environment, char * _image, char * _x1, char * _y1, char * _x2, char * _y2, char * _frame, char * _sequence, char * _flags ) {
345
346 if ( _environment->emptyProcedure ) {
347 return;
348 }
349
350 Variable * image = variable_retrieve( _environment, _image );
351
352 switch( image->type ) {
353 case VT_IMAGE:
354 case VT_IMAGES:
355 case VT_SEQUENCE:
356 case VT_ADDRESS:
357 put_image_vars_original( _environment, _image, _x1, _y1, _x2, _y2, _frame, _sequence, _flags );
358 break;
359 case VT_IMAGEREF:
360 put_image_vars_imageref( _environment, _image, _x1, _y1, _x2, _y2, _frame, _sequence, _flags );
361 break;
362 default:
364 }
365
366}
367
368void put_image_vars_flags( Environment * _environment, char * _image, char * _x1, char * _y1, char * _x2, char * _y2, char * _frame, char * _sequence, int _flags ) {
369
370 char flagsConstantName[MAX_TEMPORARY_STORAGE]; sprintf( flagsConstantName, "PUTIMAGEFLAGS%4.4x", _flags );
371 char flagsConstantParameter[MAX_TEMPORARY_STORAGE]; sprintf( flagsConstantParameter, "#PUTIMAGEFLAGS%4.4x", _flags );
372
373 Constant * flagsConstant = constant_find( _environment, flagsConstantName );
374
375 if ( !flagsConstant ) {
376 flagsConstant = malloc( sizeof( Constant ) );
377 memset( flagsConstant, 0, sizeof( Constant ) );
378 flagsConstant->name = strdup( flagsConstantName );
379 flagsConstant->realName = strdup( flagsConstantName );
380 flagsConstant->value = _flags;
381 flagsConstant->type = CT_INTEGER;
382 flagsConstant->next = _environment->constants;
383 _environment->constants = flagsConstant;
384 }
385
386 put_image_vars( _environment, _image, _x1, _y1, _x2, _y2, _frame, _sequence, flagsConstantParameter );
387}
void cpu_store_16bit(Environment *_environment, char *_destination, int _value)
CPU 6309: emit code to store 16 bit
Definition 6309.c:1503
void cpu_compare_and_branch_16bit_const(Environment *_environment, char *_source, int _destination, char *_label, int _positive)
CPU 6309: emit code to compare two 8 bit values and jump if they are equal/different
Definition 6309.c:1578
void cpu_label(Environment *_environment, char *_label)
Definition 6309.c:356
void c6847_put_image(Environment *_environment, Resource *_source, char *_x, char *_y, char *_frame, char *_sequence, int _frame_size, int _frame_count, char *_flags)
Definition 6847.c:2618
void c6847_calculate_sequence_frame_offset(Environment *_environment, char *_offset, char *_sequence, char *_frame, int _frame_size, int _frame_count)
Definition 6847.c:2872
Variable * variable_retrieve(Environment *_environment, char *_name)
Variable * variable_retrieve_or_define(Environment *_environment, char *_name, VariableType _type, int _value)
Resource * build_resource_for_sequence(Environment *_environment, char *_image, char *_frame, char *_sequence)
void variable_add_inplace_vars(Environment *_environment, char *_source, char *_destination)
Add two variable and return the sum of them on the first.
Variable * variable_temporary(Environment *_environment, VariableType _type, char *_meaning)
Define a temporary variable.
Variable * variable_store(Environment *_environment, char *_destination, unsigned int _value)
Store a direct value to a variable.
char * address_displacement(Environment *_environment, char *_address, char *_displacement)
Constant * constant_find(Environment *_environment, char *_name)
int offset
Definition _optimizer.c:681
void put_image_vars_original(Environment *_environment, char *_image, char *_x1, char *_y1, char *_x2, char *_y2, char *_frame, char *_sequence, char *_flags)
Emit ASM code for PUT IMAGE [image] AT [int],[int].
Definition put_image.c:53
void put_image_vars_imageref(Environment *_environment, char *_image, char *_x1, char *_y1, char *_x2, char *_y2, char *_frame, char *_sequence, char *_flags)
Definition put_image.c:289
void put_image_vars_flags(Environment *_environment, char *_image, char *_x1, char *_y1, char *_x2, char *_y2, char *_frame, char *_sequence, int _flags)
Definition put_image.c:430
void put_image_vars(Environment *_environment, char *_image, char *_x1, char *_y1, char *_x2, char *_y2, char *_frame, char *_sequence, char *_flags)
Definition put_image.c:406
void bank_read_semi_var(Environment *_environment, int _bank, int _address1, char *_address2, int _size)
Emit ASM code for instruction BANK READ ....
Definition bank_read.c:50
void bank_read_vars_direct(Environment *_environment, char *_bank, char *_address1, char *_address2, char *_size)
Definition bank_read.c:138
void bank_uncompress_semi_var(Environment *_environment, int _bank, int _address1, char *_address2)
Emit ASM code for instruction BANK UNCOMPRESS ....
char * name
Definition ugbc.h:800
int value
Definition ugbc.h:815
ConstantType type
Definition ugbc.h:805
struct _Constant * next
Definition ugbc.h:832
char * realName
Definition ugbc.h:803
int putImageRefUnsafe
Definition ugbc.h:3271
Constant * constants
Definition ugbc.h:2611
int emptyProcedure
Definition ugbc.h:2932
int isAddress
Definition ugbc.h:557
VariableType type
Definition ugbc.h:559
char * realName
Definition ugbc.h:555
char * name
Definition ugbc.h:979
VariableType type
Definition ugbc.h:988
char * realName
Definition ugbc.h:982
void * malloc(YYSIZE_T)
struct _Resource Resource
#define MAX_TEMPORARY_STORAGE
Definition ugbc.h:563
@ CT_INTEGER
Definition ugbc.h:788
struct _Variable Variable
Structure of a single variable.
struct _Environment Environment
Structure of compilation environment.
@ VT_TARRAY
Definition ugbc.h:480
@ VT_WORD
Definition ugbc.h:455
@ VT_POSITION
Definition ugbc.h:468
@ VT_BYTE
Definition ugbc.h:450
@ VT_IMAGEREF
Definition ugbc.h:537
@ VT_IMAGES
Definition ugbc.h:495
@ VT_ADDRESS
Definition ugbc.h:465
@ VT_IMAGE
Definition ugbc.h:489
@ VT_SEQUENCE
Definition ugbc.h:513
struct _Constant Constant
Structure of a single constant.
#define CRITICAL_CANNOT_PUT_IMAGE_WITHOUT_STRIP(s)
Definition ugbc.h:3855
#define outline0(s)
Definition ugbc.h:4252
#define CRITICAL_PUT_IMAGE_UNSUPPORTED(v, t)
Definition ugbc.h:3532
#define outline1(s, a)
Definition ugbc.h:4253
#define MAKE_LABEL
Definition ugbc.h:3351
#define outhead1(s, a)
Definition ugbc.h:4247
char DATATYPE_AS_STRING[][16]