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 coco3b
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 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 gime_calculate_sequence_frame_offset(_environment, offset->realName, "", "", image->frameSize, image->frameCount );
109 } else {
110 gime_calculate_sequence_frame_offset(_environment, offset->realName, "", frame->realName, image->frameSize, image->frameCount );
111 }
112 } else {
113 if ( !frame ) {
114 gime_calculate_sequence_frame_offset(_environment, offset->realName, sequence->realName, "", image->frameSize, image->frameCount );
115 } else {
116 gime_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.isAddress = 0;
128
129 gime_flip_image( _environment, &resource, NULL, NULL, image->frameSize, 0, _direction );
130
131 if ( ! image->readonly ) {
132 bank_write_vars_direct( _environment, bankWindowName, bank->name, address->name, frameSize->name );
133 }
134
135 } else {
136 if ( !sequence ) {
137 if ( !frame ) {
138 gime_flip_image( _environment, resource, "", "", image->frameSize, image->frameCount, _direction );
139 } else {
140 gime_flip_image( _environment, resource, frame->realName, "", image->frameSize, image->frameCount, _direction );
141 }
142 } else {
143 if ( !frame ) {
144 gime_flip_image( _environment, resource, "", sequence->realName, image->frameSize, image->frameCount, _direction );
145 } else {
146 gime_flip_image( _environment, resource, frame->realName, sequence->realName, image->frameSize, image->frameCount, _direction );
147 }
148 }
149 }
150 break;
151 case VT_IMAGES:
152 if ( image->bankAssigned != -1 ) {
153
154 char alreadyLoadedLabel[MAX_TEMPORARY_STORAGE];
155 sprintf(alreadyLoadedLabel, "%salready", label );
156
157 char bankWindowId[MAX_TEMPORARY_STORAGE];
158 sprintf( bankWindowId, "BANKWINDOWID%2.2x", image->residentAssigned );
159
160 char bankWindowName[MAX_TEMPORARY_STORAGE];
161 sprintf( bankWindowName, "BANKWINDOW%2.2x", image->residentAssigned );
162
163 // cpu_compare_and_branch_16bit_const( _environment, bankWindowId, image->variableUniqueId, alreadyLoadedLabel, 1 );
164 // if ( image->uncompressedSize ) {
165 // bank_uncompress_semi_var( _environment, image->bankAssigned, image->absoluteAddress, bankWindowName );
166 // } else {
167 // bank_read_semi_var( _environment, image->bankAssigned, image->absoluteAddress, bankWindowName, image->size );
168 // }
169 // cpu_store_16bit(_environment, bankWindowId, image->variableUniqueId );
170 // cpu_label( _environment, alreadyLoadedLabel );
171
172 Variable * frameSize = variable_temporary( _environment, VT_WORD, "(temporary)");
173 variable_store( _environment, frameSize->name, image->frameSize );
174 Variable * bank = variable_temporary( _environment, VT_BYTE, "(temporary)");
175 variable_store( _environment, bank->name, image->bankAssigned );
176 Variable * offset = variable_temporary( _environment, VT_ADDRESS, "(temporary)");
177
178 if ( !frame ) {
179 gime_calculate_sequence_frame_offset(_environment, offset->realName, NULL, "", image->frameSize, 0 );
180 } else {
181 gime_calculate_sequence_frame_offset(_environment, offset->realName, NULL, frame->realName, image->frameSize, 0 );
182 }
183
184 Variable * address = variable_temporary( _environment, VT_ADDRESS, "(temporary)");
185 variable_store( _environment, address->name, image->absoluteAddress );
186 variable_add_inplace_vars( _environment, address->name, offset->name );
187 bank_read_vars_direct( _environment, bank->name, address->name, bankWindowName, frameSize->name );
188
189 Resource resource;
190 resource.realName = strdup( bankWindowName );
191 resource.isAddress = 0;
192
193 gime_flip_image( _environment, &resource, NULL, NULL, image->frameSize, 0, _direction );
194
195 if ( ! image->readonly ) {
196 bank_write_vars_direct( _environment, bankWindowName, bank->name, address->name, frameSize->name );
197 }
198
199 } else {
200 if ( !frame ) {
201 gime_flip_image( _environment, resource, "", NULL, image->frameSize, 0, _direction );
202 } else {
203 gime_flip_image( _environment, resource, frame->realName, NULL, image->frameSize, 0, _direction );
204 }
205 }
206 break;
207 case VT_IMAGE:
208 case VT_TARRAY:
209 if ( image->bankAssigned != -1 ) {
210
211 char alreadyLoadedLabel[MAX_TEMPORARY_STORAGE];
212 sprintf(alreadyLoadedLabel, "%salready", label );
213
214 char bankWindowId[MAX_TEMPORARY_STORAGE];
215 sprintf( bankWindowId, "BANKWINDOWID%2.2x", image->residentAssigned );
216
217 char bankWindowName[MAX_TEMPORARY_STORAGE];
218 sprintf( bankWindowName, "BANKWINDOW%2.2x", image->residentAssigned );
219
220 cpu_compare_and_branch_16bit_const( _environment, bankWindowId, image->variableUniqueId, alreadyLoadedLabel, 1 );
221 if ( image->uncompressedSize ) {
222 bank_uncompress_semi_var( _environment, image->bankAssigned, image->absoluteAddress, bankWindowName );
223 } else {
224 bank_read_semi_var( _environment, image->bankAssigned, image->absoluteAddress, bankWindowName, image->size );
225 }
226 cpu_store_16bit(_environment, bankWindowId, image->variableUniqueId );
227 cpu_label( _environment, alreadyLoadedLabel );
228
229 Resource resource;
230 resource.realName = strdup( bankWindowName );
231 resource.isAddress = 0;
232
233 gime_flip_image( _environment, &resource, NULL, NULL, 0, 0, _direction );
234
235 if ( ! image->readonly && ( image->uncompressedSize == 0 ) ) {
236 bank_write_semi_var( _environment, bankWindowName, image->bankAssigned, image->absoluteAddress, image->size );
237 }
238
239 } else {
240 gime_flip_image( _environment, resource, NULL, NULL, 0, 0, _direction );
241 }
242 break;
243 default:
245 }
246
247}
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_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 ....
void bank_write_vars_direct(Environment *_environment, char *_address1, char *_bank, char *_address2, char *_size)
Definition bank_write.c:80
void bank_write_semi_var(Environment *_environment, char *_address2, int _bank, int _address1, int _size)
Definition bank_write.c:127
void gime_calculate_sequence_frame_offset(Environment *_environment, char *_offset, char *_sequence, char *_frame, int _frame_size, int _frame_count)
Definition gime.c:3010
void gime_flip_image(Environment *_environment, Resource *_image, char *_frame, char *_sequence, int _frame_size, int _frame_count, char *_direction)
Definition gime.c:3057
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
char * realName
Definition ugbc.h:982
struct _Resource Resource
#define MAX_TEMPORARY_STORAGE
Definition ugbc.h:563
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]