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
53/* <usermanual>
54@keyword FLIP IMAGE
55@target mo5
56</usermanual> */
57void flip_image_vars( Environment * _environment, char * _image, char * _frame, char * _sequence, char * _direction ) {
58
59 if ( _environment->emptyProcedure ) {
60 return;
61 }
62
64
65 Variable * image = variable_retrieve( _environment, _image );
66
67 if ( image->uncompressedSize ) {
69 }
70
71 Resource * resource = build_resource_for_sequence( _environment, _image, _frame, _sequence );
72
73 Variable * frame = NULL;
74 if ( _frame) {
75 frame = variable_retrieve_or_define( _environment, _frame, VT_BYTE, 0 );
76 }
77 Variable * sequence = NULL;
78 if ( _sequence) {
79 sequence = variable_retrieve_or_define( _environment, _sequence, VT_BYTE, 0 );
80 }
81
82 switch( resource->type ) {
83 case VT_SEQUENCE:
84 if ( image->bankAssigned != -1 ) {
85
86 char alreadyLoadedLabel[MAX_TEMPORARY_STORAGE];
87 sprintf(alreadyLoadedLabel, "%salready", label );
88
89 char bankWindowId[MAX_TEMPORARY_STORAGE];
90 sprintf( bankWindowId, "BANKWINDOWID%2.2x", image->residentAssigned );
91
92 char bankWindowName[MAX_TEMPORARY_STORAGE];
93 sprintf( bankWindowName, "BANKWINDOW%2.2x", image->residentAssigned );
94
95 // cpu_compare_and_branch_16bit_const( _environment, bankWindowId, image->variableUniqueId, alreadyLoadedLabel, 1 );
96 // if ( image->uncompressedSize ) {
97 // bank_uncompress_semi_var( _environment, image->bankAssigned, image->absoluteAddress, bankWindowName );
98 // } else {
99 // bank_read_semi_var( _environment, image->bankAssigned, image->absoluteAddress, bankWindowName, image->size );
100 // }
101 // cpu_store_16bit(_environment, bankWindowId, image->variableUniqueId );
102 // cpu_label( _environment, alreadyLoadedLabel );
103
104 Variable * frameSize = variable_temporary( _environment, VT_WORD, "(temporary)");
105 variable_store( _environment, frameSize->name, image->frameSize );
106 Variable * bank = variable_temporary( _environment, VT_BYTE, "(temporary)");
107 variable_store( _environment, bank->name, image->bankAssigned );
108 Variable * offset = variable_temporary( _environment, VT_ADDRESS, "(temporary)");
109
110 if ( !sequence ) {
111 if ( !frame ) {
112 ef936x_calculate_sequence_frame_offset(_environment, offset->realName, "", "", image->frameSize, image->frameCount );
113 } else {
114 ef936x_calculate_sequence_frame_offset(_environment, offset->realName, "", frame->realName, image->frameSize, image->frameCount );
115 }
116 } else {
117 if ( !frame ) {
118 ef936x_calculate_sequence_frame_offset(_environment, offset->realName, sequence->realName, "", image->frameSize, image->frameCount );
119 } else {
120 ef936x_calculate_sequence_frame_offset(_environment, offset->realName, sequence->realName, frame->realName, image->frameSize, image->frameCount );
121 }
122 }
123
124 Variable * address = variable_temporary( _environment, VT_ADDRESS, "(temporary)");
125 variable_store( _environment, address->name, image->absoluteAddress );
126 variable_add_inplace_vars( _environment, address->name, offset->name );
127 // bank_read_vars_direct( _environment, bank->name, address->name, bankWindowName, frameSize->name );
128
129 Resource resource;
130 // resource.realName = strdup( bankWindowName );
131 resource.realName = address->realName;
132 resource.bankNumber = image->bankAssigned;
133 resource.isAddress = 1;
134
135 ef936x_flip_image( _environment, &resource, NULL, NULL, image->frameSize, 0, _direction );
136
137 // if ( ! image->readonly ) {
138 // bank_write_vars_direct( _environment, bankWindowName, bank->name, address->name, frameSize->name );
139 // }
140
141 } else {
142 if ( !sequence ) {
143 if ( !frame ) {
144 ef936x_flip_image( _environment, resource, "", "", image->frameSize, image->frameCount, _direction );
145 } else {
146 ef936x_flip_image( _environment, resource, frame->realName, "", image->frameSize, image->frameCount, _direction );
147 }
148 } else {
149 if ( !frame ) {
150 ef936x_flip_image( _environment, resource, "", sequence->realName, image->frameSize, image->frameCount, _direction );
151 } else {
152 ef936x_flip_image( _environment, resource, frame->realName, sequence->realName, image->frameSize, image->frameCount, _direction );
153 }
154 }
155 }
156 break;
157 case VT_IMAGES:
158 if ( image->bankAssigned != -1 ) {
159
160 char alreadyLoadedLabel[MAX_TEMPORARY_STORAGE];
161 sprintf(alreadyLoadedLabel, "%salready", label );
162
163 char bankWindowId[MAX_TEMPORARY_STORAGE];
164 sprintf( bankWindowId, "BANKWINDOWID%2.2x", image->residentAssigned );
165
166 char bankWindowName[MAX_TEMPORARY_STORAGE];
167 sprintf( bankWindowName, "BANKWINDOW%2.2x", image->residentAssigned );
168
169 // cpu_compare_and_branch_16bit_const( _environment, bankWindowId, image->variableUniqueId, alreadyLoadedLabel, 1 );
170 // if ( image->uncompressedSize ) {
171 // bank_uncompress_semi_var( _environment, image->bankAssigned, image->absoluteAddress, bankWindowName );
172 // } else {
173 // bank_read_semi_var( _environment, image->bankAssigned, image->absoluteAddress, bankWindowName, image->size );
174 // }
175 // cpu_store_16bit(_environment, bankWindowId, image->variableUniqueId );
176 // cpu_label( _environment, alreadyLoadedLabel );
177
178 Variable * frameSize = variable_temporary( _environment, VT_WORD, "(temporary)");
179 variable_store( _environment, frameSize->name, image->frameSize );
180 Variable * bank = variable_temporary( _environment, VT_BYTE, "(temporary)");
181 variable_store( _environment, bank->name, image->bankAssigned );
182 Variable * offset = variable_temporary( _environment, VT_ADDRESS, "(temporary)");
183
184 if ( !frame ) {
185 ef936x_calculate_sequence_frame_offset(_environment, offset->realName, NULL, "", image->frameSize, 0 );
186 } else {
187 ef936x_calculate_sequence_frame_offset(_environment, offset->realName, NULL, frame->realName, image->frameSize, 0 );
188 }
189
190 Variable * address = variable_temporary( _environment, VT_ADDRESS, "(temporary)");
191 variable_store( _environment, address->name, image->absoluteAddress );
192 variable_add_inplace_vars( _environment, address->name, offset->name );
193 // bank_read_vars_direct( _environment, bank->name, address->name, bankWindowName, frameSize->name );
194
195 Resource resource;
196 //resource.realName = strdup( bankWindowName );
197 resource.realName = address->realName;
198 resource.bankNumber = image->bankAssigned;
199 resource.isAddress = 1;
200
201 ef936x_flip_image( _environment, &resource, NULL, NULL, image->frameSize, 0, _direction );
202
203 // if ( ! image->readonly ) {
204 // bank_write_vars_direct( _environment, bankWindowName, bank->name, address->name, frameSize->name );
205 // }
206
207 } else {
208 if ( !frame ) {
209 ef936x_flip_image( _environment, resource, "", NULL, image->frameSize, 0, _direction );
210 } else {
211 ef936x_flip_image( _environment, resource, frame->realName, NULL, image->frameSize, 0, _direction );
212 }
213 }
214 break;
215 case VT_IMAGE:
216 case VT_TARRAY:
217 if ( image->bankAssigned != -1 ) {
218
219 char alreadyLoadedLabel[MAX_TEMPORARY_STORAGE];
220 sprintf(alreadyLoadedLabel, "%salready", label );
221
222 char bankWindowId[MAX_TEMPORARY_STORAGE];
223 sprintf( bankWindowId, "BANKWINDOWID%2.2x", image->residentAssigned );
224
225 char bankWindowName[MAX_TEMPORARY_STORAGE];
226 sprintf( bankWindowName, "BANKWINDOW%2.2x", image->residentAssigned );
227
228 cpu_compare_and_branch_16bit_const( _environment, bankWindowId, image->variableUniqueId, alreadyLoadedLabel, 1 );
229 if ( image->uncompressedSize ) {
230 bank_uncompress_semi_var( _environment, image->bankAssigned, image->absoluteAddress, bankWindowName );
231 } else {
232 bank_read_semi_var( _environment, image->bankAssigned, image->absoluteAddress, bankWindowName, image->size );
233 }
234 cpu_store_16bit(_environment, bankWindowId, image->variableUniqueId );
235 cpu_label( _environment, alreadyLoadedLabel );
236
237 Resource resource;
238 resource.realName = strdup( bankWindowName );
239 resource.isAddress = 0;
240
241 bank_set( _environment, image->bankAssigned );
242 ef936x_flip_image( _environment, &resource, NULL, NULL, 0, 0, _direction );
243 bank_set( _environment, 7 );
244
245 if ( ! image->readonly && ( image->uncompressedSize == 0 ) ) {
246 bank_write_semi_var( _environment, bankWindowName, image->bankAssigned, image->absoluteAddress, image->size );
247 }
248
249 } else {
250 ef936x_flip_image( _environment, resource, NULL, NULL, 0, 0, _direction );
251 }
252 break;
253 default:
255 }
256
257}
258
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_PUT_IMAGE_UNSUPPORTED(v, t)
Definition ugbc.h:3532
#define MAKE_LABEL
Definition ugbc.h:3351
char DATATYPE_AS_STRING[][16]