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