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
53
54void put_image_vars_original( Environment * _environment, char * _image, char * _x1, char * _y1, char * _x2, char * _y2, char * _frame, char * _sequence, char * _flags ) {
55
56 if ( _environment->emptyProcedure ) {
57 return;
58 }
59
61
62 Variable * image = variable_retrieve( _environment, _image );
63
64 Resource * resource = build_resource_for_sequence( _environment, _image, _frame, _sequence );
65
66 Variable * x1 = variable_retrieve_or_define( _environment, _x1, VT_POSITION, 0 );
67 Variable * y1 = variable_retrieve_or_define( _environment, _y1, VT_POSITION, 0 );
68 Variable * realFrame = NULL;
69 Variable * frame = NULL;
70 if ( _frame) {
71 frame = variable_retrieve_or_define( _environment, _frame, VT_BYTE, 0 );
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 // // tms9918_calculate_sequence_frame_offset(_environment, offset->realName, "", "", image->frameSize, image->frameCount );
110 } else {
111 // // tms9918_calculate_sequence_frame_offset(_environment, offset->realName, "", frame->realName, image->frameSize, image->frameCount );
112 }
113 } else {
114 if ( !frame ) {
115 // // tms9918_calculate_sequence_frame_offset(_environment, offset->realName, sequence->realName, "", image->frameSize, image->frameCount );
116 } else {
117 // // tms9918_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 // // tms9918_put_image( _environment, &resource, x1->realName, y1->realName, NULL, NULL, image->frameSize, 0, _flags );
131
132 } else {
133 if ( !sequence ) {
134 if ( !frame ) {
135 // // tms9918_put_image( _environment, resource, x1->realName, y1->realName, "", "", image->frameSize, image->frameCount, _flags );
136 } else {
137 // // tms9918_put_image( _environment, resource, x1->realName, y1->realName, frame->realName, "", image->frameSize, image->frameCount, _flags );
138 }
139 } else {
140 if ( !frame ) {
141 // // tms9918_put_image( _environment, resource, x1->realName, y1->realName, "", sequence->realName, image->frameSize, image->frameCount, _flags );
142 } else {
143 // // tms9918_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("PUSH HL");
179 // outline0("PUSH AF");
180 // outline1("LD HL, %sstrip", image->realName );
181 // outline1("LD A, (%s)", sequence->realName );
182 // outline0("SLA A" );
183 // outline0("LD E, A" );
184 // outline0("LD D, 0" );
185 // outline0("ADD HL, DE");
186 // outline0("LD A, (HL)");
187 // outline0("LD E, A");
188 // outline0("INC HL");
189 // outline0("LD A, (HL)");
190 // outline0("LD E, A");
191 // outline0("LD A, (DE)");
192 // outline0("LD L, A");
193 // outline0("INC DE");
194 // outline0("LD A, (DE)");
195 // outline0("LD H, A");
196 // outline1("LD A, (%s)", frame->realName );
197 // outline0("LD E, A" );
198 // outline0("LD D, 0" );
199 // outline0("ADD HL, DE");
200 // outline0("LD A, (HL)");
201 // outline1("LD (%s), A", realFrame->realName );
202 // outline0("POP AF");
203 // outline0("POP HL");
204 } else {
206 }
207 }
208
209 if ( !frame ) {
210 // // tms9918_calculate_sequence_frame_offset(_environment, offset->realName, NULL, "", image->frameSize, 0 );
211 } else {
212 // // tms9918_calculate_sequence_frame_offset(_environment, offset->realName, NULL, realFrame->realName, image->frameSize, 0 );
213 }
214
215 Variable * address = variable_temporary( _environment, VT_ADDRESS, "(temporary)");
216 variable_store( _environment, address->name, image->absoluteAddress );
217 variable_add_inplace_vars( _environment, address->name, offset->name );
218 bank_read_vars_direct( _environment, bank->name, address->name, bankWindowName, frameSize->name );
219
220 Resource resource;
221 resource.realName = strdup( bankWindowName );
222 resource.isAddress = 0;
223
224 // // tms9918_put_image( _environment, &resource, x1->realName, y1->realName, NULL, NULL, image->frameSize, 0, _flags );
225
226 } else {
227 if ( !frame ) {
228 // // tms9918_put_image( _environment, resource, x1->realName, y1->realName, "", NULL, image->frameSize, 0, _flags );
229 } else {
230 // // tms9918_put_image( _environment, resource, x1->realName, y1->realName, frame->realName, NULL, image->frameSize, 0, _flags );
231 }
232 }
233 break;
234 case VT_IMAGE:
235 case VT_TARRAY:
236 if ( image->bankAssigned != -1 ) {
237
238 char alreadyLoadedLabel[MAX_TEMPORARY_STORAGE];
239 sprintf(alreadyLoadedLabel, "%salready", label );
240
241 char bankWindowId[MAX_TEMPORARY_STORAGE];
242 sprintf( bankWindowId, "BANKWINDOWID%2.2x", image->residentAssigned );
243
244 char bankWindowName[MAX_TEMPORARY_STORAGE];
245 sprintf( bankWindowName, "BANKWINDOW%2.2x", image->residentAssigned );
246
247 cpu_compare_and_branch_16bit_const( _environment, bankWindowId, image->variableUniqueId, alreadyLoadedLabel, 1 );
248 if ( image->uncompressedSize ) {
249 bank_uncompress_semi_var( _environment, image->bankAssigned, image->absoluteAddress, bankWindowName );
250 } else {
251 bank_read_semi_var( _environment, image->bankAssigned, image->absoluteAddress, bankWindowName, image->size );
252 }
253 cpu_store_16bit(_environment, bankWindowId, image->variableUniqueId );
254 cpu_label( _environment, alreadyLoadedLabel );
255
256 Resource resource;
257 resource.realName = strdup( bankWindowName );
258 resource.isAddress = 0;
259
260 // // tms9918_put_image( _environment, &resource, x1->realName, y1->realName, NULL, NULL, 0, 0, _flags );
261 } else {
262 // // tms9918_put_image( _environment, resource, x1->realName, y1->realName, NULL, NULL, 0, 0, _flags );
263 }
264 break;
265 default:
267 }
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 // Y = OFFSET
292
293 if ( !_sequence && !_frame ) {
294 outline1("LD HL, (%s)", image->realName );
295 } else {
296 outline1("LD HL, (%s)", image->realName );
297
298 if ( _sequence ) {
299 outline0("LD DE, $0003" );
300 outline0("ADD HL, DE" );
301 if ( strlen(_sequence) == 0 ) {
302
303 } else {
304 outline1("LD A, (%s)", sequence->realName );
305 outline0("PUSH HL" );
306 outline0("POP IX" );
307 cpu_call_indirect( _environment, address_displacement( _environment, image->realName, "10") );
308 }
309 if ( _frame ) {
310 if ( strlen(_frame) == 0 ) {
311
312 } else {
313 outline1("LD A, (%s)", frame->realName );
314 outline0("PUSH HL" );
315 outline0("POP IX" );
316 cpu_call_indirect( _environment, address_displacement( _environment, image->realName, "8") );
317 }
318 }
319
320 } else {
321
322 if ( _frame ) {
323 outline0("LD DE, $0003" );
324 outline0("ADD HL, DE" );
325 if ( strlen(_frame) == 0 ) {
326
327 } else {
328 outline0("PUSH HL" );
329 outline0("POP IX" );
330 outline1("LD A, (%s)", frame->realName );
331 cpu_call_indirect( _environment, address_displacement( _environment, image->realName, "8") );
332 }
333 }
334
335 }
336
337 }
338 outline1("LD (%s), HL", address->realName );
339
340 Resource resource;
341 resource.realName = strdup( address->realName );
342 resource.isAddress = 1;
343
344 // // tms9918_put_image( _environment, &resource, x1->realName, y1->realName, NULL, NULL, 0, 0, _flags );
345
346}
347
348void put_image_vars( Environment * _environment, char * _image, char * _x1, char * _y1, char * _x2, char * _y2, char * _frame, char * _sequence, char * _flags ) {
349
350 if ( _environment->emptyProcedure ) {
351 return;
352 }
353
354 Variable * image = variable_retrieve( _environment, _image );
355
356 switch( image->type ) {
357 case VT_IMAGE:
358 case VT_IMAGES:
359 case VT_SEQUENCE:
360 case VT_ADDRESS:
361 put_image_vars_original( _environment, _image, _x1, _y1, _x2, _y2, _frame, _sequence, _flags );
362 break;
363 case VT_IMAGEREF:
364 put_image_vars_imageref( _environment, _image, _x1, _y1, _x2, _y2, _frame, _sequence, _flags );
365 break;
366 default:
368 }
369
370}
371
372void put_image_vars_flags( Environment * _environment, char * _image, char * _x1, char * _y1, char * _x2, char * _y2, char * _frame, char * _sequence, int _flags ) {
373
374 char flagsConstantName[MAX_TEMPORARY_STORAGE]; sprintf( flagsConstantName, "PUTIMAGEFLAGS%4.4x", _flags );
375 char flagsConstantParameter[MAX_TEMPORARY_STORAGE]; sprintf( flagsConstantParameter, "PUTIMAGEFLAGS%4.4x", _flags );
376
377 Constant * flagsConstant = constant_find( _environment, flagsConstantName );
378
379 if ( !flagsConstant ) {
380 flagsConstant = malloc( sizeof( Constant ) );
381 memset( flagsConstant, 0, sizeof( Constant ) );
382 flagsConstant->name = strdup( flagsConstantName );
383 flagsConstant->realName = strdup( flagsConstantName );
384 flagsConstant->value = _flags;
385 flagsConstant->type = CT_INTEGER;
386 flagsConstant->next = _environment->constants;
387 _environment->constants = flagsConstant;
388 }
389
390 put_image_vars( _environment, _image, _x1, _y1, _x2, _y2, _frame, _sequence, flagsConstantParameter );
391}
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
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
char DATATYPE_AS_STRING[][16]