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
95 if ( sequence ) {
96 if ( image->strips ) {
97 realFrame = variable_temporary( _environment, VT_BYTE, "(real frame)" );
98 outline0("PUSH HL");
99 outline0("PUSH AF");
100 outline1("LD HL, %sstrip", image->realName );
101 outline1("LD A, (%s)", sequence->realName );
102 outline0("SLA A" );
103 outline0("LD E, A" );
104 outline0("LD D, 0" );
105 outline0("ADD HL, DE");
106 outline0("LD A, (HL)");
107 outline0("LD E, A");
108 outline0("INC HL");
109 outline0("LD A, (HL)");
110 outline0("LD E, A");
111 outline0("LD A, (DE)");
112 outline0("LD L, A");
113 outline0("INC DE");
114 outline0("LD A, (DE)");
115 outline0("LD H, A");
116 outline1("LD A, (%s)", frame->realName );
117 outline0("LD E, A" );
118 outline0("LD D, 0" );
119 outline0("ADD HL, DE");
120 outline0("LD A, (HL)");
121 outline1("LD (%s), A", realFrame->realName );
122 outline0("POP AF");
123 outline0("POP HL");
124 } else {
126 }
127 }
128
129 if ( !frame ) {
130 tms9918_put_image( _environment, resource, x1->realName, y1->realName, "", NULL, image->frameSize, 0, _flags );
131 } else {
132 tms9918_put_image( _environment, resource, x1->realName, y1->realName, realFrame->realName, NULL, image->frameSize, 0, _flags );
133 }
134 break;
135 case VT_IMAGE:
136 case VT_TARRAY:
137 tms9918_put_image( _environment, resource, x1->realName, y1->realName, NULL, NULL, 1, 0, _flags );
138 break;
139 default:
141 }
142
143}
144
145void put_image_vars_imageref( Environment * _environment, char * _image, char * _x1, char * _y1, char * _x2, char * _y2, char * _frame, char * _sequence, char * _flags ) {
146
148
149 Variable * image = variable_retrieve( _environment, _image );
150
151 Variable * x1 = variable_retrieve_or_define( _environment, _x1, VT_POSITION, 0 );
152 Variable * y1 = variable_retrieve_or_define( _environment, _y1, VT_POSITION, 0 );
153 Variable * frame = NULL;
154 if ( _frame) {
155 frame = variable_retrieve_or_define( _environment, _frame, VT_BYTE, 0 );
156 }
157 Variable * sequence = NULL;
158 if ( _sequence) {
159 sequence = variable_retrieve_or_define( _environment, _sequence, VT_BYTE, 0 );
160 }
161
162 Variable * address = variable_temporary( _environment, VT_ADDRESS, "(stub)" );
163
164 if ( !_environment->putImageRefUnsafe ) {
165 outline1("LD A, (%s)", address_displacement( _environment, image->realName, "5") );
166 outline0("CP 0");
167 outline1("JP Z, %sskip", label );
168 }
169
170 // Y = OFFSET
171
172 if ( !_sequence && !_frame ) {
173 outline1("LD HL, (%s)", image->realName );
174 } else {
175 outline1("LD HL, (%s)", image->realName );
176
177 if ( _sequence ) {
178 outline0("LD DE, $0003" );
179 outline0("ADD HL, DE" );
180 if ( strlen(_sequence) == 0 ) {
181
182 } else {
183 outline1("LD A, (%s)", sequence->realName );
184 outline0("PUSH HL" );
185 outline0("POP IX" );
186 cpu_call_indirect( _environment, address_displacement( _environment, image->realName, "10") );
187 }
188 if ( _frame ) {
189 if ( strlen(_frame) == 0 ) {
190
191 } else {
192 outline1("LD A, (%s)", frame->realName );
193 outline0("PUSH HL" );
194 outline0("POP IX" );
195 cpu_call_indirect( _environment, address_displacement( _environment, image->realName, "8") );
196 }
197 }
198
199 } else {
200
201 if ( _frame ) {
202 outline0("LD DE, $0003" );
203 outline0("ADD HL, DE" );
204 if ( strlen(_frame) == 0 ) {
205
206 } else {
207 outline0("PUSH HL" );
208 outline0("POP IX" );
209 outline1("LD A, (%s)", frame->realName );
210 cpu_call_indirect( _environment, address_displacement( _environment, image->realName, "8") );
211 }
212 }
213
214 }
215
216 }
217 outline1("LD (%s), HL", address->realName );
218
219 Resource resource;
220 resource.realName = strdup( address->realName );
221 resource.isAddress = 1;
222
223 tms9918_put_image( _environment, &resource, x1->realName, y1->realName, NULL, NULL, 0, 0, _flags );
224
225 if ( !_environment->putImageRefUnsafe ) {
226 outhead1("%sskip:", label );
227 }
228
229}
230
231void put_image_vars( Environment * _environment, char * _image, char * _x1, char * _y1, char * _x2, char * _y2, char * _frame, char * _sequence, char * _flags ) {
232
233 if ( _environment->emptyProcedure ) {
234 return;
235 }
236
237 Variable * image = variable_retrieve( _environment, _image );
238
239 switch( image->type ) {
240 case VT_IMAGE:
241 case VT_IMAGES:
242 case VT_SEQUENCE:
243 case VT_ADDRESS:
244 put_image_vars_original( _environment, _image, _x1, _y1, _x2, _y2, _frame, _sequence, _flags );
245 break;
246 case VT_IMAGEREF:
247 put_image_vars_imageref( _environment, _image, _x1, _y1, _x2, _y2, _frame, _sequence, _flags );
248 break;
249 default:
251 }
252
253}
254
255void put_image_vars_flags( Environment * _environment, char * _image, char * _x1, char * _y1, char * _x2, char * _y2, char * _frame, char * _sequence, int _flags ) {
256
257 char flagsConstantName[MAX_TEMPORARY_STORAGE]; sprintf( flagsConstantName, "PUTIMAGEFLAGS%4.4x", _flags );
258 char flagsConstantParameter[MAX_TEMPORARY_STORAGE]; sprintf( flagsConstantParameter, "PUTIMAGEFLAGS%4.4x", _flags );
259
260 Constant * flagsConstant = constant_find( _environment, flagsConstantName );
261
262 if ( !flagsConstant ) {
263 flagsConstant = malloc( sizeof( Constant ) );
264 memset( flagsConstant, 0, sizeof( Constant ) );
265 flagsConstant->name = strdup( flagsConstantName );
266 flagsConstant->realName = strdup( flagsConstantName );
267 flagsConstant->value = _flags;
268 flagsConstant->type = CT_INTEGER;
269 flagsConstant->next = _environment->constants;
270 _environment->constants = flagsConstant;
271 }
272
273 put_image_vars( _environment, _image, _x1, _y1, _x2, _y2, _frame, _sequence, flagsConstantParameter );
274}
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]