ugBASIC 1.18
An isomorphic BASIC language compiler for retrocomputers
Loading...
Searching...
No Matches
put_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 put_image_vars_original( Environment * _environment, char * _image, char * _x1, char * _y1, char * _x2, char * _y2, char * _frame, char * _sequence, char * _flags ) {
54
55 if ( _environment->emptyProcedure ) {
56 return;
57 }
58
59 Variable * image = variable_retrieve( _environment, _image );
60
61 Resource * resource = build_resource_for_sequence( _environment, _image, _frame, _sequence );
62
63 Variable * x1 = variable_retrieve_or_define( _environment, _x1, VT_POSITION, 0 );
64 Variable * y1 = variable_retrieve_or_define( _environment, _y1, VT_POSITION, 0 );
65 Variable * realFrame = NULL;
66 Variable * frame = NULL;
67 if ( _frame) {
68 frame = variable_retrieve_or_define( _environment, _frame, VT_BYTE, 0 );
69 realFrame = frame;
70 }
71 Variable * sequence = NULL;
72 if ( _sequence) {
73 sequence = variable_retrieve_or_define( _environment, _sequence, VT_BYTE, 0 );
74 realFrame = frame;
75 }
76
77 switch( resource->type ) {
78 case VT_SEQUENCE:
79 if ( !sequence ) {
80 if ( !frame ) {
81 tms9918_put_image( _environment, resource, x1->realName, y1->realName, "", "", image->frameSize, image->frameCount, _flags );
82 } else {
83 tms9918_put_image( _environment, resource, x1->realName, y1->realName, frame->realName, "", image->frameSize, image->frameCount, _flags );
84 }
85 } else {
86 if ( !frame ) {
87 tms9918_put_image( _environment, resource, x1->realName, y1->realName, "", sequence->realName, image->frameSize, image->frameCount, _flags );
88 } else {
89 tms9918_put_image( _environment, resource, x1->realName, y1->realName, frame->realName, sequence->realName, image->frameSize, image->frameCount, _flags );
90 }
91 }
92 break;
93 case VT_IMAGES:
94 if ( sequence ) {
95 if ( image->strips ) {
96 realFrame = variable_temporary( _environment, VT_BYTE, "(real frame)" );
97 outline0("PUSH HL");
98 outline0("PUSH AF");
99 outline1("LD HL, %sstrip", image->realName );
100 outline1("LD A, (%s)", sequence->realName );
101 outline0("SLA A" );
102 outline0("LD E, A" );
103 outline0("LD D, 0" );
104 outline0("ADD HL, DE");
105 outline0("LD A, (HL)");
106 outline0("LD E, A");
107 outline0("INC HL");
108 outline0("LD A, (HL)");
109 outline0("LD E, A");
110 outline0("LD A, (DE)");
111 outline0("LD L, A");
112 outline0("INC DE");
113 outline0("LD A, (DE)");
114 outline0("LD H, A");
115 outline1("LD A, (%s)", frame->realName );
116 outline0("LD E, A" );
117 outline0("LD D, 0" );
118 outline0("ADD HL, DE");
119 outline0("LD A, (HL)");
120 outline1("LD (%s), A", realFrame->realName );
121 outline0("POP AF");
122 outline0("POP HL");
123 } else {
125 }
126 }
127
128 if ( !frame ) {
129 tms9918_put_image( _environment, resource, x1->realName, y1->realName, "", NULL, image->frameSize, 0, _flags );
130 } else {
131 tms9918_put_image( _environment, resource, x1->realName, y1->realName, realFrame->realName, NULL, image->frameSize, 0, _flags );
132 }
133 break;
134 case VT_IMAGE:
135 case VT_TARRAY:
136 tms9918_put_image( _environment, resource, x1->realName, y1->realName, NULL, NULL, 1, 0, _flags );
137 break;
138 default:
140 }
141
142}
143
144void put_image_vars_imageref( Environment * _environment, char * _image, char * _x1, char * _y1, char * _x2, char * _y2, char * _frame, char * _sequence, char * _flags ) {
145
147
148 Variable * image = variable_retrieve( _environment, _image );
149
150 Variable * x1 = variable_retrieve_or_define( _environment, _x1, VT_POSITION, 0 );
151 Variable * y1 = variable_retrieve_or_define( _environment, _y1, VT_POSITION, 0 );
152 Variable * frame = NULL;
153 if ( _frame) {
154 frame = variable_retrieve_or_define( _environment, _frame, VT_BYTE, 0 );
155 }
156 Variable * sequence = NULL;
157 if ( _sequence) {
158 sequence = variable_retrieve_or_define( _environment, _sequence, VT_BYTE, 0 );
159 }
160
161 Variable * address = variable_temporary( _environment, VT_ADDRESS, "(stub)" );
162
163 if ( !_environment->putImageRefUnsafe ) {
164 outline1("LD A, (%s)", address_displacement( _environment, image->realName, "5") );
165 outline0("CP 0");
166 outline1("JP Z, %sskip", label );
167 }
168
169 // Y = OFFSET
170
171 if ( !_sequence && !_frame ) {
172 outline1("LD HL, (%s)", image->realName );
173 } else {
174 outline1("LD HL, (%s)", image->realName );
175
176 if ( _sequence ) {
177 outline0("LD DE, $0003" );
178 outline0("ADD HL, DE" );
179 if ( strlen(_sequence) == 0 ) {
180
181 } else {
182 outline1("LD A, (%s)", sequence->realName );
183 outline0("PUSH HL" );
184 outline0("POP IX" );
185 cpu_call_indirect( _environment, address_displacement( _environment, image->realName, "10") );
186 }
187 if ( _frame ) {
188 if ( strlen(_frame) == 0 ) {
189
190 } else {
191 outline1("LD A, (%s)", frame->realName );
192 outline0("PUSH HL" );
193 outline0("POP IX" );
194 cpu_call_indirect( _environment, address_displacement( _environment, image->realName, "8") );
195 }
196 }
197
198 } else {
199
200 if ( _frame ) {
201 outline0("LD DE, $0003" );
202 outline0("ADD HL, DE" );
203 if ( strlen(_frame) == 0 ) {
204
205 } else {
206 outline0("PUSH HL" );
207 outline0("POP IX" );
208 outline1("LD A, (%s)", frame->realName );
209 cpu_call_indirect( _environment, address_displacement( _environment, image->realName, "8") );
210 }
211 }
212
213 }
214
215 }
216 outline1("LD (%s), HL", address->realName );
217
218 Resource resource;
219 resource.realName = strdup( address->realName );
220 resource.isAddress = 1;
221
222 tms9918_put_image( _environment, &resource, x1->realName, y1->realName, NULL, NULL, 0, 0, _flags );
223
224 if ( !_environment->putImageRefUnsafe ) {
225 outhead1("%sskip:", label );
226 }
227
228}
229
230void put_image_vars( Environment * _environment, char * _image, char * _x1, char * _y1, char * _x2, char * _y2, char * _frame, char * _sequence, char * _flags ) {
231
232 if ( _environment->emptyProcedure ) {
233 return;
234 }
235
236 Variable * image = variable_retrieve( _environment, _image );
237
238 switch( image->type ) {
239 case VT_IMAGE:
240 case VT_IMAGES:
241 case VT_SEQUENCE:
242 case VT_ADDRESS:
243 put_image_vars_original( _environment, _image, _x1, _y1, _x2, _y2, _frame, _sequence, _flags );
244 break;
245 case VT_IMAGEREF:
246 put_image_vars_imageref( _environment, _image, _x1, _y1, _x2, _y2, _frame, _sequence, _flags );
247 break;
248 default:
250 }
251
252}
253
254void put_image_vars_flags( Environment * _environment, char * _image, char * _x1, char * _y1, char * _x2, char * _y2, char * _frame, char * _sequence, int _flags ) {
255
256 char flagsConstantName[MAX_TEMPORARY_STORAGE]; sprintf( flagsConstantName, "PUTIMAGEFLAGS%4.4x", _flags );
257 char flagsConstantParameter[MAX_TEMPORARY_STORAGE]; sprintf( flagsConstantParameter, "PUTIMAGEFLAGS%4.4x", _flags );
258
259 Constant * flagsConstant = constant_find( _environment, flagsConstantName );
260
261 if ( !flagsConstant ) {
262 flagsConstant = malloc( sizeof( Constant ) );
263 memset( flagsConstant, 0, sizeof( Constant ) );
264 flagsConstant->name = strdup( flagsConstantName );
265 flagsConstant->realName = strdup( flagsConstantName );
266 flagsConstant->value = _flags;
267 flagsConstant->type = CT_INTEGER;
268 flagsConstant->next = _environment->constants;
269 _environment->constants = flagsConstant;
270 }
271
272 put_image_vars( _environment, _image, _x1, _y1, _x2, _y2, _frame, _sequence, flagsConstantParameter );
273}
void cpu_call_indirect(Environment *_environment, char *_value)
Definition 6309.c:3765
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)
Variable * variable_temporary(Environment *_environment, VariableType _type, char *_meaning)
Define a temporary variable.
char * address_displacement(Environment *_environment, char *_address, char *_displacement)
Constant * constant_find(Environment *_environment, char *_name)
void put_image_vars_original(Environment *_environment, char *_image, char *_x1, char *_y1, char *_x2, char *_y2, char *_frame, char *_sequence, char *_flags)
Emit ASM code for PUT IMAGE [image] AT [int],[int].
Definition put_image.c:53
void put_image_vars_imageref(Environment *_environment, char *_image, char *_x1, char *_y1, char *_x2, char *_y2, char *_frame, char *_sequence, char *_flags)
Definition put_image.c:289
void put_image_vars_flags(Environment *_environment, char *_image, char *_x1, char *_y1, char *_x2, char *_y2, char *_frame, char *_sequence, int _flags)
Definition put_image.c:430
void put_image_vars(Environment *_environment, char *_image, char *_x1, char *_y1, char *_x2, char *_y2, char *_frame, char *_sequence, char *_flags)
Definition put_image.c:406
char * name
Definition ugbc.h:800
int value
Definition ugbc.h:815
ConstantType type
Definition ugbc.h:805
struct _Constant * next
Definition ugbc.h:832
char * realName
Definition ugbc.h:803
int putImageRefUnsafe
Definition ugbc.h:3271
Constant * constants
Definition ugbc.h:2611
int emptyProcedure
Definition ugbc.h:2932
int isAddress
Definition ugbc.h:557
VariableType type
Definition ugbc.h:559
char * realName
Definition ugbc.h:555
Strip * strips
Definition ugbc.h:1215
char * name
Definition ugbc.h:979
VariableType type
Definition ugbc.h:988
int frameSize
Definition ugbc.h:1134
int frameCount
Definition ugbc.h:1137
char * realName
Definition ugbc.h:982
void tms9918_put_image(Environment *_environment, Resource *_image, char *_x, char *_y, char *_frame, char *_sequence, int _frame_size, int _frame_count, char *_flags)
Definition tms9918.c:2313
void * malloc(YYSIZE_T)
struct _Resource Resource
#define MAX_TEMPORARY_STORAGE
Definition ugbc.h:563
@ CT_INTEGER
Definition ugbc.h:788
struct _Variable Variable
Structure of a single variable.
struct _Environment Environment
Structure of compilation environment.
@ VT_TARRAY
Definition ugbc.h:480
@ VT_POSITION
Definition ugbc.h:468
@ VT_BYTE
Definition ugbc.h:450
@ VT_IMAGEREF
Definition ugbc.h:537
@ VT_IMAGES
Definition ugbc.h:495
@ VT_ADDRESS
Definition ugbc.h:465
@ VT_IMAGE
Definition ugbc.h:489
@ VT_SEQUENCE
Definition ugbc.h:513
struct _Constant Constant
Structure of a single constant.
#define CRITICAL_CANNOT_PUT_IMAGE_WITHOUT_STRIP(s)
Definition ugbc.h:3855
#define outline0(s)
Definition ugbc.h:4252
#define CRITICAL_PUT_IMAGE_UNSUPPORTED(v, t)
Definition ugbc.h:3532
#define outline1(s, a)
Definition ugbc.h:4253
#define MAKE_LABEL
Definition ugbc.h:3351
#define outhead1(s, a)
Definition ugbc.h:4247
char DATATYPE_AS_STRING[][16]