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->bankAssigned != -1 ) {
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 // // tms9918_calculate_sequence_frame_offset(_environment, offset->realName, "", "", image->frameSize, image->frameCount );
109 } else {
110 // // tms9918_calculate_sequence_frame_offset(_environment, offset->realName, "", frame->realName, image->frameSize, image->frameCount );
111 }
112 } else {
113 if ( !frame ) {
114 // // tms9918_calculate_sequence_frame_offset(_environment, offset->realName, sequence->realName, "", image->frameSize, image->frameCount );
115 } else {
116 // // tms9918_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 // // tms9918_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
137 if ( !sequence ) {
138 if ( !frame ) {
139 // // tms9918_flip_image( _environment, resource, "", "", image->frameSize, image->frameCount, _direction );
140 } else {
141 // // tms9918_flip_image( _environment, resource, frame->realName, "", image->frameSize, image->frameCount, _direction );
142 }
143 } else {
144 if ( !frame ) {
145 // // tms9918_flip_image( _environment, resource, "", sequence->realName, image->frameSize, image->frameCount, _direction );
146 } else {
147 // // tms9918_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 // // tms9918_calculate_sequence_frame_offset(_environment, offset->realName, NULL, "", image->frameSize, 0 );
181 } else {
182 // // tms9918_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 // // tms9918_flip_image( _environment, &resource, NULL, NULL, image->frameSize, 0, _direction );
195
196 if ( ! image->readonly ) {
197 bank_write_vars_direct( _environment, bankWindowName, bank->name, address->name, frameSize->name );
198 }
199
200 } else {
201 if ( !frame ) {
202 // // tms9918_flip_image( _environment, resource, "", NULL, image->frameSize, 0, _direction );
203 } else {
204 // // tms9918_flip_image( _environment, resource, frame->realName, NULL, image->frameSize, 0, _direction );
205 }
206 }
207 break;
208 case VT_IMAGE:
209 case VT_TARRAY:
210 if ( image->residentAssigned ) {
211
212 char alreadyLoadedLabel[MAX_TEMPORARY_STORAGE];
213 sprintf(alreadyLoadedLabel, "%salready", label );
214
215 char bankWindowId[MAX_TEMPORARY_STORAGE];
216 sprintf( bankWindowId, "BANKWINDOWID%2.2x", image->residentAssigned );
217
218 char bankWindowName[MAX_TEMPORARY_STORAGE];
219 sprintf( bankWindowName, "BANKWINDOW%2.2x", image->residentAssigned );
220
221 cpu_compare_and_branch_16bit_const( _environment, bankWindowId, image->variableUniqueId, alreadyLoadedLabel, 1 );
222 if ( image->uncompressedSize ) {
223 bank_uncompress_semi_var( _environment, image->bankAssigned, image->absoluteAddress, bankWindowName );
224 } else {
225 bank_read_semi_var( _environment, image->bankAssigned, image->absoluteAddress, bankWindowName, image->size );
226 }
227 cpu_store_16bit(_environment, bankWindowId, image->variableUniqueId );
228 cpu_label( _environment, alreadyLoadedLabel );
229
230 Resource resource;
231 resource.realName = strdup( bankWindowName );
232 resource.isAddress = 0;
233
234 // // tms9918_flip_image( _environment, &resource, NULL, NULL, 0, 0, _direction );
235
236 } else {
237 // // tms9918_flip_image( _environment, resource, NULL, NULL, 0, 0, _direction );
238 }
239 break;
240 default:
242 }
243
244
245}
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
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
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]