ugBASIC 1.18
An isomorphic BASIC language compiler for retrocomputers
Loading...
Searching...
No Matches
flip_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 flip_image_vars( Environment * _environment, char * _image, char * _frame, char * _sequence, char * _direction ) {
54
55 if ( _environment->emptyProcedure ) {
56 return;
57 }
58
60
61 Variable * image = variable_retrieve( _environment, _image );
62
63 if ( image->uncompressedSize ) {
65 }
66
67 Resource * resource = build_resource_for_sequence( _environment, _image, _frame, _sequence );
68
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 }
77
78 switch( resource->type ) {
79 case VT_SEQUENCE:
80 if ( image->bankAssigned != -1 ) {
81
82 char alreadyLoadedLabel[MAX_TEMPORARY_STORAGE];
83 sprintf(alreadyLoadedLabel, "%salready", label );
84
85 char bankWindowId[MAX_TEMPORARY_STORAGE];
86 sprintf( bankWindowId, "BANKWINDOWID%2.2x", image->residentAssigned );
87
88 char bankWindowName[MAX_TEMPORARY_STORAGE];
89 sprintf( bankWindowName, "BANKWINDOW%2.2x", image->residentAssigned );
90
91 // cpu_compare_and_branch_16bit_const( _environment, bankWindowId, image->variableUniqueId, alreadyLoadedLabel, 1 );
92 // if ( image->uncompressedSize ) {
93 // bank_uncompress_semi_var( _environment, image->bankAssigned, image->absoluteAddress, bankWindowName );
94 // } else {
95 // bank_read_semi_var( _environment, image->bankAssigned, image->absoluteAddress, bankWindowName, image->size );
96 // }
97 // cpu_store_16bit(_environment, bankWindowId, image->variableUniqueId );
98 // cpu_label( _environment, alreadyLoadedLabel );
99
100 Variable * frameSize = variable_temporary( _environment, VT_WORD, "(temporary)");
101 variable_store( _environment, frameSize->name, image->frameSize );
102 Variable * bank = variable_temporary( _environment, VT_BYTE, "(temporary)");
103 variable_store( _environment, bank->name, image->bankAssigned );
104 Variable * offset = variable_temporary( _environment, VT_ADDRESS, "(temporary)");
105
106 if ( !sequence ) {
107 if ( !frame ) {
108 ef936x_calculate_sequence_frame_offset(_environment, offset->realName, "", "", image->frameSize, image->frameCount );
109 } else {
110 ef936x_calculate_sequence_frame_offset(_environment, offset->realName, "", frame->realName, image->frameSize, image->frameCount );
111 }
112 } else {
113 if ( !frame ) {
114 ef936x_calculate_sequence_frame_offset(_environment, offset->realName, sequence->realName, "", image->frameSize, image->frameCount );
115 } else {
116 ef936x_calculate_sequence_frame_offset(_environment, offset->realName, sequence->realName, frame->realName, image->frameSize, image->frameCount );
117 }
118 }
119
120 Variable * address = variable_temporary( _environment, VT_ADDRESS, "(temporary)");
121 variable_store( _environment, address->name, image->absoluteAddress );
122 variable_add_inplace_vars( _environment, address->name, offset->name );
123 // bank_read_vars_direct( _environment, bank->name, address->name, bankWindowName, frameSize->name );
124
125 Resource resource;
126 // resource.realName = strdup( bankWindowName );
127 resource.realName = address->realName;
128 resource.bankNumber = image->bankAssigned;
129 resource.isAddress = 1;
130
131 ef936x_flip_image( _environment, &resource, NULL, NULL, image->frameSize, 0, _direction );
132
133 // if ( ! image->readonly ) {
134 // bank_write_vars_direct( _environment, bankWindowName, bank->name, address->name, frameSize->name );
135 // }
136
137 } else {
138 if ( !sequence ) {
139 if ( !frame ) {
140 ef936x_flip_image( _environment, resource, "", "", image->frameSize, image->frameCount, _direction );
141 } else {
142 ef936x_flip_image( _environment, resource, frame->realName, "", image->frameSize, image->frameCount, _direction );
143 }
144 } else {
145 if ( !frame ) {
146 ef936x_flip_image( _environment, resource, "", sequence->realName, image->frameSize, image->frameCount, _direction );
147 } else {
148 ef936x_flip_image( _environment, resource, frame->realName, sequence->realName, image->frameSize, image->frameCount, _direction );
149 }
150 }
151 }
152 break;
153 case VT_IMAGES:
154 if ( image->bankAssigned != -1 ) {
155
156 char alreadyLoadedLabel[MAX_TEMPORARY_STORAGE];
157 sprintf(alreadyLoadedLabel, "%salready", label );
158
159 char bankWindowId[MAX_TEMPORARY_STORAGE];
160 sprintf( bankWindowId, "BANKWINDOWID%2.2x", image->residentAssigned );
161
162 char bankWindowName[MAX_TEMPORARY_STORAGE];
163 sprintf( bankWindowName, "BANKWINDOW%2.2x", image->residentAssigned );
164
165 // cpu_compare_and_branch_16bit_const( _environment, bankWindowId, image->variableUniqueId, alreadyLoadedLabel, 1 );
166 // if ( image->uncompressedSize ) {
167 // bank_uncompress_semi_var( _environment, image->bankAssigned, image->absoluteAddress, bankWindowName );
168 // } else {
169 // bank_read_semi_var( _environment, image->bankAssigned, image->absoluteAddress, bankWindowName, image->size );
170 // }
171 // cpu_store_16bit(_environment, bankWindowId, image->variableUniqueId );
172 // cpu_label( _environment, alreadyLoadedLabel );
173
174 Variable * frameSize = variable_temporary( _environment, VT_WORD, "(temporary)");
175 variable_store( _environment, frameSize->name, image->frameSize );
176 Variable * bank = variable_temporary( _environment, VT_BYTE, "(temporary)");
177 variable_store( _environment, bank->name, image->bankAssigned );
178 Variable * offset = variable_temporary( _environment, VT_ADDRESS, "(temporary)");
179
180 Variable * sequence = NULL;
181 if ( _sequence ) {
182 sequence = variable_retrieve_or_define( _environment, _sequence, VT_BYTE, 0 );
183 }
184
185 outline1("LDY #$%4.4x", image->absoluteAddress );
186
187 Variable * realFrame = NULL;
188 Variable * frame = NULL;
189 if ( _frame ) {
190 frame = variable_retrieve_or_define( _environment, _frame, VT_BYTE, 0 );
191 realFrame = frame;
192 }
193
194 if ( sequence ) {
195 if ( image->strips ) {
196 realFrame = variable_temporary( _environment, VT_BYTE, "(real frame)" );
197 outline0("PSHS Y,D");
198 outline1("LDY #%sstrip", image->realName );
199 outline1("LDA %s", sequence->realName );
200 outline0("LSLA" );
201 outline0("LDY A, Y");
202 outline1("LDA %s", frame->realName );
203 outline0("LDB A, Y" );
204 outline1("STB %s", realFrame->realName );
205 outline0("PULS Y,D");
206 } else {
208 }
209 }
210
211 if ( !frame ) {
212 ef936x_calculate_sequence_frame_offset(_environment, offset->realName, NULL, "", image->frameSize, 0 );
213 } else {
214 ef936x_calculate_sequence_frame_offset(_environment, offset->realName, NULL, realFrame->realName, image->frameSize, 0 );
215 }
216
217 Variable * address = variable_temporary( _environment, VT_ADDRESS, "(temporary)");
218 variable_store( _environment, address->name, image->absoluteAddress );
219 variable_add_inplace_vars( _environment, address->name, offset->name );
220 // bank_read_vars_direct( _environment, bank->name, address->name, bankWindowName, frameSize->name );
221
222 Resource resource;
223 //resource.realName = strdup( bankWindowName );
224 resource.realName = address->realName;
225 resource.bankNumber = image->bankAssigned;
226 resource.isAddress = 1;
227
228 ef936x_flip_image( _environment, &resource, NULL, NULL, image->frameSize, 0, _direction );
229
230 // if ( ! image->readonly ) {
231 // bank_write_vars_direct( _environment, bankWindowName, bank->name, address->name, frameSize->name );
232 // }
233
234 } else {
235
236 Variable * sequence = NULL;
237 if ( _sequence ) {
238 sequence = variable_retrieve_or_define( _environment, _sequence, VT_BYTE, 0 );
239 }
240
241 Variable * realFrame = NULL;
242 Variable * frame = NULL;
243 if ( _frame) {
244 frame = variable_retrieve_or_define( _environment, _frame, VT_BYTE, 0 );
245 realFrame = frame;
246 }
247
248 if ( sequence ) {
249 if ( image->strips ) {
250 realFrame = variable_temporary( _environment, VT_BYTE, "(real frame)" );
251 outline1("LDY #%sstrip", image->realName );
252 outline1("LDA %s", sequence->realName );
253 outline0("LSLA" );
254 outline0("LDY A, Y");
255 outline1("LDA %s", frame->realName );
256 outline0("LDB A, Y" );
257 outline1("STB %s", realFrame->realName );
258 } else {
260 }
261 }
262 if ( !frame ) {
263 ef936x_flip_image( _environment, resource, "", NULL, image->frameSize, 0, _direction );
264 } else {
265 ef936x_flip_image( _environment, resource, realFrame->realName, NULL, image->frameSize, 0, _direction );
266 }
267 }
268 break;
269 case VT_IMAGE:
270 case VT_TARRAY:
271 if ( image->bankAssigned != -1 ) {
272
273 char alreadyLoadedLabel[MAX_TEMPORARY_STORAGE];
274 sprintf(alreadyLoadedLabel, "%salready", label );
275
276 char bankWindowId[MAX_TEMPORARY_STORAGE];
277 sprintf( bankWindowId, "BANKWINDOWID%2.2x", image->residentAssigned );
278
279 char bankWindowName[MAX_TEMPORARY_STORAGE];
280 sprintf( bankWindowName, "BANKWINDOW%2.2x", image->residentAssigned );
281
282 cpu_compare_and_branch_16bit_const( _environment, bankWindowId, image->variableUniqueId, alreadyLoadedLabel, 1 );
283 if ( image->uncompressedSize ) {
284 bank_uncompress_semi_var( _environment, image->bankAssigned, image->absoluteAddress, bankWindowName );
285 } else {
286 bank_read_semi_var( _environment, image->bankAssigned, image->absoluteAddress, bankWindowName, image->size );
287 }
288 cpu_store_16bit(_environment, bankWindowId, image->variableUniqueId );
289 cpu_label( _environment, alreadyLoadedLabel );
290
291 Resource resource;
292 resource.realName = strdup( bankWindowName );
293 resource.isAddress = 0;
294
295 bank_set( _environment, image->bankAssigned );
296 ef936x_flip_image( _environment, &resource, NULL, NULL, 0, 0, _direction );
297 bank_set( _environment, 7 );
298
299 if ( ! image->readonly && ( image->uncompressedSize == 0 ) ) {
300 bank_write_semi_var( _environment, bankWindowName, image->bankAssigned, image->absoluteAddress, image->size );
301 }
302
303 } else {
304 ef936x_flip_image( _environment, resource, NULL, NULL, 0, 0, _direction );
305 }
306 break;
307 default:
309 }
310
311}
312
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
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.
int offset
Definition _optimizer.c:681
void flip_image_vars(Environment *_environment, char *_image, char *_frame, char *_sequence, char *_direction)
Emit ASM code for FLIP IMAGE X/Y/XY/YX [image].
Definition flip_image.c:56
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_set(Environment *_environment, int _bank)
Emit ASM code for instruction BANK ....
Definition bank_set.c:72
void bank_uncompress_semi_var(Environment *_environment, int _bank, int _address1, char *_address2)
Emit ASM code for instruction BANK UNCOMPRESS ....
void bank_write_semi_var(Environment *_environment, char *_address2, int _bank, int _address1, int _size)
Definition bank_write.c:127
void ef936x_calculate_sequence_frame_offset(Environment *_environment, char *_offset, char *_sequence, char *_frame, int _frame_size, int _frame_count)
Definition ef936x.c:2285
void ef936x_flip_image(Environment *_environment, Resource *_image, char *_frame, char *_sequence, int _frame_size, int _frame_count, char *_direction)
Definition ef936x.c:2389
int emptyProcedure
Definition ugbc.h:2932
int bankNumber
Definition ugbc.h:556
int isAddress
Definition ugbc.h:557
VariableType type
Definition ugbc.h:559
char * realName
Definition ugbc.h:555
char * name
Definition ugbc.h:979
char * realName
Definition ugbc.h:982
struct _Resource Resource
#define MAX_TEMPORARY_STORAGE
Definition ugbc.h:563
#define CRITICAL_CANNOT_FLIP_COMPRESSED_IMAGE(v)
Definition ugbc.h:3725
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_BYTE
Definition ugbc.h:450
@ VT_IMAGES
Definition ugbc.h:495
@ VT_ADDRESS
Definition ugbc.h:465
@ VT_IMAGE
Definition ugbc.h:489
@ VT_SEQUENCE
Definition ugbc.h:513
#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]