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
51/* <usermanual>
52@keyword FLIP IMAGE
53@target c64reu
54</usermanual> */
55void flip_image_vars( Environment * _environment, char * _image, char * _frame, char * _sequence, char * _direction ) {
56
57 if ( _environment->emptyProcedure ) {
58 return;
59 }
60
61 Variable * image = variable_retrieve( _environment, _image );
62
63 Resource * resource = build_resource_for_sequence( _environment, _image, _frame, _sequence );
64
65 Variable * frame = NULL;
66 if ( _frame) {
67 frame = variable_retrieve_or_define( _environment, _frame, VT_BYTE, 0 );
68 }
69 Variable * sequence = NULL;
70 if ( _sequence) {
71 sequence = variable_retrieve_or_define( _environment, _sequence, VT_BYTE, 0 );
72 }
73
74 switch( resource->type ) {
75 case VT_SEQUENCE:
76 if ( image->bankAssigned != -1 ) {
77
78 Variable * frameSize = variable_temporary( _environment, VT_WORD, "(temporary)");
79 variable_store( _environment, frameSize->name, image->frameSize );
80 Variable * offset = variable_temporary( _environment, VT_ADDRESS, "(temporary)");
81
82 if ( !sequence ) {
83 if ( !frame ) {
84 vic2_calculate_sequence_frame_offset(_environment, offset->realName, "", "", image->frameSize, image->frameCount );
85 } else {
86 vic2_calculate_sequence_frame_offset(_environment, offset->realName, "", frame->realName, image->frameSize, image->frameCount );
87 }
88 } else {
89 if ( !frame ) {
90 vic2_calculate_sequence_frame_offset(_environment, offset->realName, sequence->realName, "", image->frameSize, image->frameCount );
91 } else {
92 vic2_calculate_sequence_frame_offset(_environment, offset->realName, sequence->realName, frame->realName, image->frameSize, image->frameCount );
93 }
94 }
95
96 Variable * address = variable_temporary( _environment, VT_ADDRESS, "(temporary)");
97 variable_store( _environment, address->name, image->absoluteAddress );
98 variable_add_inplace_vars( _environment, address->name, offset->name );
99
100 Resource resource;
101 resource.realName = strdup( address->realName );
102 resource.bankNumber = image->bankAssigned;
103 resource.isAddress = 1;
104
105 vic2_flip_image( _environment, &resource, NULL, NULL, image->frameSize, 0, _direction );
106
107 } else {
108 if ( !sequence ) {
109 if ( !frame ) {
110 vic2_flip_image( _environment, resource, "", "", image->frameSize, image->frameCount, _direction );
111 } else {
112 vic2_flip_image( _environment, resource, frame->realName, "", image->frameSize, image->frameCount, _direction );
113 }
114 } else {
115 if ( !frame ) {
116 vic2_flip_image( _environment, resource, "", sequence->realName, image->frameSize, image->frameCount, _direction );
117 } else {
118 vic2_flip_image( _environment, resource, frame->realName, sequence->realName, image->frameSize, image->frameCount, _direction );
119 }
120 }
121 }
122 break;
123 case VT_IMAGES:
124 if ( image->bankAssigned != -1 ) {
125
126 Variable * frameSize = variable_temporary( _environment, VT_WORD, "(temporary)");
127 variable_store( _environment, frameSize->name, image->frameSize );
128 Variable * offset = variable_temporary( _environment, VT_ADDRESS, "(temporary)");
129
130 if ( !frame ) {
131 vic2_calculate_sequence_frame_offset(_environment, offset->realName, NULL, "", image->frameSize, 0 );
132 } else {
133 vic2_calculate_sequence_frame_offset(_environment, offset->realName, NULL, frame->realName, image->frameSize, 0 );
134 }
135
136 Variable * address = variable_temporary( _environment, VT_ADDRESS, "(temporary)");
137 variable_store( _environment, address->name, image->absoluteAddress );
138 variable_add_inplace_vars( _environment, address->name, offset->name );
139
140 Resource resource;
141 resource.realName = strdup( address->realName );
142 resource.bankNumber = image->bankAssigned;
143 resource.isAddress = 1;
144
145 vic2_flip_image( _environment, &resource, NULL, NULL, image->frameSize, 0, _direction );
146
147 } else {
148 if ( !frame ) {
149 vic2_flip_image( _environment, resource, "", NULL, image->frameSize, 0, _direction );
150 } else {
151 vic2_flip_image( _environment, resource, frame->realName, NULL, image->frameSize, 0, _direction );
152 }
153 }
154 break;
155 case VT_IMAGE:
156 case VT_TARRAY:
157 if ( image->bankAssigned != -1 ) {
158
159 Variable * address = variable_temporary( _environment, VT_ADDRESS, "(temporary)");
160 variable_store( _environment, address->name, image->absoluteAddress );
161
162 Resource resource;
163 resource.realName = strdup( address->realName );
164 resource.bankNumber = image->bankAssigned;
165 resource.isAddress = 1;
166
167 vic2_flip_image( _environment, &resource, NULL, NULL, 0, 0, _direction );
168 } else {
169 vic2_flip_image( _environment, resource, NULL, NULL, 0, 0, _direction );
170 }
171 break;
172 default:
174 }
175
176
177}
178
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
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
int bankAssigned
Definition ugbc.h:1172
char * name
Definition ugbc.h:979
int absoluteAddress
Definition ugbc.h:1092
VariableType type
Definition ugbc.h:988
int frameSize
Definition ugbc.h:1134
int frameCount
Definition ugbc.h:1137
char * realName
Definition ugbc.h:982
struct _Resource Resource
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_FLIP_IMAGE_UNSUPPORTED(v, t)
Definition ugbc.h:3723
char DATATYPE_AS_STRING[][16]
void vic2_flip_image(Environment *_environment, Resource *_image, char *_frame, char *_sequence, int _frame_size, int _frame_count, char *_direction)
Definition vic2.c:4388
void vic2_calculate_sequence_frame_offset(Environment *_environment, char *_offset, char *_sequence, char *_frame, int _frame_size, int _frame_count)
Definition vic2.c:3931