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 vdcz_calculate_sequence_frame_offset(_environment, offset->realName, "", "", image->frameSize, image->frameCount );
110 } else {
111 vdcz_calculate_sequence_frame_offset(_environment, offset->realName, "", frame->realName, image->frameSize, image->frameCount );
112 }
113 } else {
114 if ( !frame ) {
115 vdcz_calculate_sequence_frame_offset(_environment, offset->realName, sequence->realName, "", image->frameSize, image->frameCount );
116 } else {
117 vdcz_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 vdcz_put_image( _environment, &resource, x1->realName, y1->realName, NULL, NULL, image->frameSize, 0, _flags );
131
132 } else {
133
134 if ( !sequence ) {
135 if ( !frame ) {
136 vdcz_put_image( _environment, resource, x1->realName, y1->realName, "", "", image->frameSize, image->frameCount, _flags );
137 } else {
138 vdcz_put_image( _environment, resource, x1->realName, y1->realName, frame->realName, "", image->frameSize, image->frameCount, _flags );
139 }
140 } else {
141 if ( !frame ) {
142 vdcz_put_image( _environment, resource, x1->realName, y1->realName, "", sequence->realName, image->frameSize, image->frameCount, _flags );
143 } else {
144 vdcz_put_image( _environment, resource, x1->realName, y1->realName, frame->realName, sequence->realName, image->frameSize, image->frameCount, _flags );
145 }
146 }
147 }
148 break;
149 case VT_IMAGES:
150 if ( image->bankAssigned != -1 ) {
151
152 char alreadyLoadedLabel[MAX_TEMPORARY_STORAGE];
153 sprintf(alreadyLoadedLabel, "%salready", label );
154
155 char bankWindowId[MAX_TEMPORARY_STORAGE];
156 sprintf( bankWindowId, "BANKWINDOWID%2.2x", image->residentAssigned );
157
158 char bankWindowName[MAX_TEMPORARY_STORAGE];
159 sprintf( bankWindowName, "BANKWINDOW%2.2x", image->residentAssigned );
160
161 // cpu_compare_and_branch_16bit_const( _environment, bankWindowId, image->variableUniqueId, alreadyLoadedLabel, 1 );
162 // if ( image->uncompressedSize ) {
163 // bank_uncompress_semi_var( _environment, image->bankAssigned, image->absoluteAddress, bankWindowName );
164 // } else {
165 // bank_read_semi_var( _environment, image->bankAssigned, image->absoluteAddress, bankWindowName, image->size );
166 // }
167 // cpu_store_16bit(_environment, bankWindowId, image->variableUniqueId );
168 // cpu_label( _environment, alreadyLoadedLabel );
169
170 Variable * frameSize = variable_temporary( _environment, VT_WORD, "(temporary)");
171 variable_store( _environment, frameSize->name, image->frameSize );
172 Variable * bank = variable_temporary( _environment, VT_BYTE, "(temporary)");
173 variable_store( _environment, bank->name, image->bankAssigned );
174 Variable * offset = variable_temporary( _environment, VT_ADDRESS, "(temporary)");
175
176 if ( sequence ) {
177 if ( image->strips ) {
178 realFrame = variable_temporary( _environment, VT_BYTE, "(real frame)" );
179 outline0("PUSH HL");
180 outline0("PUSH AF");
181 outline1("LD HL, %sstrip", image->realName );
182 outline1("LD A, (%s)", sequence->realName );
183 outline0("SLA A" );
184 outline0("LD E, A" );
185 outline0("LD D, 0" );
186 outline0("ADD HL, DE");
187 outline0("LD A, (HL)");
188 outline0("LD E, A");
189 outline0("INC HL");
190 outline0("LD A, (HL)");
191 outline0("LD E, A");
192 outline0("LD A, (DE)");
193 outline0("LD L, A");
194 outline0("INC DE");
195 outline0("LD A, (DE)");
196 outline0("LD H, A");
197 outline1("LD A, (%s)", frame->realName );
198 outline0("LD E, A" );
199 outline0("LD D, 0" );
200 outline0("ADD HL, DE");
201 outline0("LD A, (HL)");
202 outline1("LD (%s), A", realFrame->realName );
203 outline0("POP AF");
204 outline0("POP HL");
205 } else {
207 }
208 }
209
210 if ( !frame ) {
211 vdcz_calculate_sequence_frame_offset(_environment, offset->realName, NULL, "", image->frameSize, 0 );
212 } else {
213 vdcz_calculate_sequence_frame_offset(_environment, offset->realName, NULL, realFrame->realName, image->frameSize, 0 );
214 }
215
216 Variable * address = variable_temporary( _environment, VT_ADDRESS, "(temporary)");
217 variable_store( _environment, address->name, image->absoluteAddress );
218 variable_add_inplace_vars( _environment, address->name, offset->name );
219 bank_read_vars_direct( _environment, bank->name, address->name, bankWindowName, frameSize->name );
220
221 Resource resource;
222 resource.realName = strdup( bankWindowName );
223 resource.isAddress = 0;
224
225 vdcz_put_image( _environment, &resource, x1->realName, y1->realName, NULL, NULL, image->frameSize, 0, _flags );
226
227 } else {
228
229 if ( sequence ) {
230 if ( image->strips ) {
231 realFrame = variable_temporary( _environment, VT_BYTE, "(real frame)" );
232 outline0("PUSH HL");
233 outline0("PUSH AF");
234 outline1("LD HL, %sstrip", image->realName );
235 outline1("LD A, (%s)", sequence->realName );
236 outline0("SLA A" );
237 outline0("LD E, A" );
238 outline0("LD D, 0" );
239 outline0("ADD HL, DE");
240 outline0("LD A, (HL)");
241 outline0("LD E, A");
242 outline0("INC HL");
243 outline0("LD A, (HL)");
244 outline0("LD E, A");
245 outline0("LD A, (DE)");
246 outline0("LD L, A");
247 outline0("INC DE");
248 outline0("LD A, (DE)");
249 outline0("LD H, A");
250 outline1("LD A, (%s)", frame->realName );
251 outline0("LD E, A" );
252 outline0("LD D, 0" );
253 outline0("ADD HL, DE");
254 outline0("LD A, (HL)");
255 outline1("LD (%s), A", realFrame->realName );
256 outline0("POP AF");
257 outline0("POP HL");
258 } else {
260 }
261 }
262
263 if ( !frame ) {
264 vdcz_put_image( _environment, resource, x1->realName, y1->realName, "", NULL, image->frameSize, 0, _flags );
265 } else {
266 vdcz_put_image( _environment, resource, x1->realName, y1->realName, realFrame->realName, NULL, image->frameSize, 0, _flags );
267 }
268 }
269 break;
270 case VT_IMAGE:
271 case VT_TARRAY:
272 if ( image->residentAssigned ) {
273
274 char alreadyLoadedLabel[MAX_TEMPORARY_STORAGE];
275 sprintf(alreadyLoadedLabel, "%salready", label );
276
277 char bankWindowId[MAX_TEMPORARY_STORAGE];
278 sprintf( bankWindowId, "BANKWINDOWID%2.2x", image->residentAssigned );
279
280 char bankWindowName[MAX_TEMPORARY_STORAGE];
281 sprintf( bankWindowName, "BANKWINDOW%2.2x", image->residentAssigned );
282
283 cpu_compare_and_branch_16bit_const( _environment, bankWindowId, image->variableUniqueId, alreadyLoadedLabel, 1 );
284 if ( image->uncompressedSize ) {
285 bank_uncompress_semi_var( _environment, image->bankAssigned, image->absoluteAddress, bankWindowName );
286 } else {
287 bank_read_semi_var( _environment, image->bankAssigned, image->absoluteAddress, bankWindowName, image->size );
288 }
289 cpu_store_16bit(_environment, bankWindowId, image->variableUniqueId );
290 cpu_label( _environment, alreadyLoadedLabel );
291
292 Resource resource;
293 resource.realName = strdup( bankWindowName );
294 resource.isAddress = 0;
295
296 vdcz_put_image( _environment, &resource, x1->realName, y1->realName, NULL, NULL, 1, 0, _flags );
297 } else {
298 vdcz_put_image( _environment, resource, x1->realName, y1->realName, NULL, NULL, 1, 0, _flags );
299 }
300 break;
301 default:
303 }
304
305
306}
307
308void put_image_vars_imageref( Environment * _environment, char * _image, char * _x1, char * _y1, char * _x2, char * _y2, char * _frame, char * _sequence, char * _flags ) {
309
311
312 Variable * image = variable_retrieve( _environment, _image );
313
314 Variable * x1 = variable_retrieve_or_define( _environment, _x1, VT_POSITION, 0 );
315 Variable * y1 = variable_retrieve_or_define( _environment, _y1, VT_POSITION, 0 );
316 Variable * frame = NULL;
317 if ( _frame) {
318 frame = variable_retrieve_or_define( _environment, _frame, VT_BYTE, 0 );
319 }
320 Variable * sequence = NULL;
321 if ( _sequence) {
322 sequence = variable_retrieve_or_define( _environment, _sequence, VT_BYTE, 0 );
323 }
324
325 Variable * address = variable_temporary( _environment, VT_ADDRESS, "(stub)" );
326
327 if ( !_environment->putImageRefUnsafe ) {
328 outline1("LD A, (%s)", address_displacement( _environment, image->realName, "5") );
329 outline0("CP 0");
330 outline1("JP Z, %sskip", label );
331 }
332
333 // Y = OFFSET
334
335 if ( !_sequence && !_frame ) {
336 outline1("LD HL, (%s)", image->realName );
337 } else {
338 outline1("LD HL, (%s)", image->realName );
339
340 if ( _sequence ) {
341 outline0("LD DE, $0003" );
342 outline0("ADD HL, DE" );
343 if ( strlen(_sequence) == 0 ) {
344
345 } else {
346 outline1("LD A, (%s)", sequence->realName );
347 outline0("PUSH HL" );
348 outline0("POP IX" );
349 cpu_call_indirect( _environment, address_displacement( _environment, image->realName, "10") );
350 }
351 if ( _frame ) {
352 if ( strlen(_frame) == 0 ) {
353
354 } else {
355 outline1("LD A, (%s)", frame->realName );
356 outline0("PUSH HL" );
357 outline0("POP IX" );
358 cpu_call_indirect( _environment, address_displacement( _environment, image->realName, "8") );
359 }
360 }
361
362 } else {
363
364 if ( _frame ) {
365 outline0("LD DE, $0003" );
366 outline0("ADD HL, DE" );
367 if ( strlen(_frame) == 0 ) {
368
369 } else {
370 outline0("PUSH HL" );
371 outline0("POP IX" );
372 outline1("LD A, (%s)", frame->realName );
373 cpu_call_indirect( _environment, address_displacement( _environment, image->realName, "8") );
374 }
375 }
376
377 }
378
379 }
380 outline1("LD (%s), HL", address->realName );
381
382 Resource resource;
383 resource.realName = strdup( address->realName );
384 resource.isAddress = 1;
385
386 vdcz_put_image( _environment, &resource, x1->realName, y1->realName, NULL, NULL, 1, 0, _flags );
387
388 if ( !_environment->putImageRefUnsafe ) {
389 outhead1("%sskip:", label );
390 }
391
392}
393
394void put_image_vars( Environment * _environment, char * _image, char * _x1, char * _y1, char * _x2, char * _y2, char * _frame, char * _sequence, char * _flags ) {
395
396 if ( _environment->emptyProcedure ) {
397 return;
398 }
399
400 Variable * image = variable_retrieve( _environment, _image );
401
402 switch( image->type ) {
403 case VT_IMAGE:
404 case VT_IMAGES:
405 case VT_SEQUENCE:
406 case VT_ADDRESS:
407 put_image_vars_original( _environment, _image, _x1, _y1, _x2, _y2, _frame, _sequence, _flags );
408 break;
409 case VT_IMAGEREF:
410 put_image_vars_imageref( _environment, _image, _x1, _y1, _x2, _y2, _frame, _sequence, _flags );
411 break;
412 default:
414 }
415
416}
417
418void put_image_vars_flags( Environment * _environment, char * _image, char * _x1, char * _y1, char * _x2, char * _y2, char * _frame, char * _sequence, int _flags ) {
419
420 char flagsConstantName[MAX_TEMPORARY_STORAGE]; sprintf( flagsConstantName, "PUTIMAGEFLAGS%4.4x", _flags );
421 char flagsConstantParameter[MAX_TEMPORARY_STORAGE]; sprintf( flagsConstantParameter, "PUTIMAGEFLAGS%4.4x", _flags );
422
423 Constant * flagsConstant = constant_find( _environment, flagsConstantName );
424
425 if ( !flagsConstant ) {
426 flagsConstant = malloc( sizeof( Constant ) );
427 memset( flagsConstant, 0, sizeof( Constant ) );
428 flagsConstant->name = strdup( flagsConstantName );
429 flagsConstant->realName = strdup( flagsConstantName );
430 flagsConstant->value = _flags;
431 flagsConstant->type = CT_INTEGER;
432 flagsConstant->next = _environment->constants;
433 _environment->constants = flagsConstant;
434 }
435
436 put_image_vars( _environment, _image, _x1, _y1, _x2, _y2, _frame, _sequence, flagsConstantParameter );
437}
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 cpu_call_indirect(Environment *_environment, char *_value)
Definition 6309.c:3765
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]
void vdcz_calculate_sequence_frame_offset(Environment *_environment, char *_offset, char *_sequence, char *_frame, int _frame_size, int _frame_count)
Definition vdcz.c:2739
void vdcz_put_image(Environment *_environment, Resource *_image, char *_x, char *_y, char *_frame, char *_sequence, int _frame_size, int _frame_count, char *_flags)
Definition vdcz.c:2880