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