ugBASIC 1.18
An isomorphic BASIC language compiler for retrocomputers
Loading...
Searching...
No Matches
image_ref.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
41#if defined(__cpc__)
42
43Variable * image_ref( Environment * _environment, char * _image ) {
44
45 Variable * image = variable_retrieve( _environment, _image );
46
47 Variable * imageRef = variable_temporary( _environment, VT_IMAGEREF, "(imageref)" );
48
49 image->usedImage = 1;
50
51 outline1( "LD IX, %s", imageRef->realName );
52
53 switch( image->type ) {
54 case VT_IMAGE:
55 if ( image->bankAssigned != -1 ) {
56
57 // BASE
58
59 outline1( "LD HL, $%4.4x", image->absoluteAddress );
60 outline0( "LD (IX), L" );
61 outline0( "LD (IX+1), H" );
62
63 // SIZE
64
65 outline1( "LD HL, $%4.4x", image->frameSize );
66 outline0( "LD (IX+2), L" );
67 outline0( "LD (IX+3), H" );
68
69 // BANK
70
71 outline1( "LDA $%2.2x", image->bankAssigned );
72 outline0( "LD (IX+4), A" );
73
74 // INFO
75
76 outline0( "LD A, $0f" );
77 outline0( "LD (IX+5), A" );
78
79 // RESIDENT
80
81 char bankWindowName[MAX_TEMPORARY_STORAGE];
82 sprintf( bankWindowName, "BANKWINDOW%2.2x", image->residentAssigned );
83 outline1( "LD HL, %s", bankWindowName );
84 outline0( "LD (IX+6), L" );
85 outline0( "LD (IX+7), H" );
86
87 // TABLE1
88
89 // outline1( "LDX #%soffsetframe", image->realName );
90 // outline1( "STX %s+8", imageRef->realName );
91
92 // TABLE2
93
94 // outline1( "LDX #%soffsetsequence", image->realName );
95 // outline1( "STX %s+10", imageRef->realName );
96
97 } else {
98
99 // BASE
100
101 outline1( "LD HL, %s", image->realName );
102 outline0( "LD (IX), L" );
103 outline0( "LD (IX+1), H" );
104
105 // SIZE
106
107 outline1( "LD HL, $%4.4x", image->frameSize );
108 outline0( "LD (IX+2), L" );
109 outline0( "LD (IX+3), H" );
110
111 // BANK
112
113 // outline1( "LDA #$%2.2x", image->bankAssigned );
114 // outline1( "STA %s+4", imageRef->realName );
115
116 // INFO
117
118 outline0( "LD A, $03" );
119 outline0( "LD (IX+5), A" );
120
121 // RESIDENT
122
123 // char bankWindowName[MAX_TEMPORARY_STORAGE];
124 // sprintf( bankWindowName, "BANKWINDOW%2.2x", image->residentAssigned );
125
126 // outline1( "LDX #%s", bankWindowName );
127 // outline1( "STX %s+6", imageRef->realName );
128
129 // TABLE1
130
131 // outline1( "LDX #%soffsetframe", image->realName );
132 // outline1( "STX %s+8", imageRef->realName );
133
134 // TABLE2
135
136 // outline1( "LDX #%soffsetsequence", image->realName );
137 // outline1( "STX %s+10", imageRef->realName );
138
139 }
140
141 break;
142
143 case VT_IMAGES:
144 if ( image->bankAssigned != -1 ) {
145
146 // BASE
147
148 outline1( "LD HL, #$%4.4x", image->absoluteAddress );
149 outline0( "LD (IX), L" );
150 outline0( "LD (IX+1), H" );
151
152 // SIZE
153
154 outline1( "LD HL, $%4.4x", image->frameSize );
155 outline0( "LD (IX+2), L" );
156 outline0( "LD (IX+3), H" );
157
158 // BANK
159
160 outline1( "LD A, $%2.2x", image->bankAssigned );
161 outline0( "LD (IX+4), A" );
162
163 // INFO
164
165 outline0( "LD A, $0f" );
166 outline0( "LD (IX+5), A" );
167
168 // RESIDENT
169
170 char bankWindowName[MAX_TEMPORARY_STORAGE];
171 sprintf( bankWindowName, "BANKWINDOW%2.2x", image->residentAssigned );
172 outline1( "LD HL, %s", bankWindowName );
173 outline0( "LD (IX+6), L" );
174 outline0( "LD (IX+7), H" );
175
176 // TABLE1
177
178 outline1( "LD HL, %soffsetframe", image->realName );
179 outline0( "LD (IX+8), L" );
180 outline0( "LD (IX+9), H" );
181
182 // TABLE2
183
184 // outline1( "LDX #%soffsetsequence", image->realName );
185 // outline1( "STX %s+10", imageRef->realName );
186
187 } else {
188
189 // BASE
190
191 outline1( "LD HL, %s", image->realName );
192 outline0( "LD (IX), L" );
193 outline0( "LD (IX+1), H" );
194
195 // SIZE
196
197 outline1( "LD HL, $%4.4x", image->frameSize );
198 outline0( "LD (IX+2), L" );
199 outline0( "LD (IX+3), H" );
200
201 // BANK
202
203 // outline1( "LDA #$%2.2x", image->bankAssigned );
204 // outline1( "STA %s+4", imageRef->realName );
205
206 // INFO
207
208 outline0( "LD A, $03" );
209 outline0( "LD (IX+5), A" );
210
211 // RESIDENT
212
213 // char bankWindowName[MAX_TEMPORARY_STORAGE];
214 // sprintf( bankWindowName, "BANKWINDOW%2.2x", image->residentAssigned );
215
216 // outline1( "LDX #%s", bankWindowName );
217 // outline1( "STX %s+6", imageRef->realName );
218
219 // TABLE1
220
221 outline1( "LD HL, %soffsetframe", image->realName );
222 outline0( "LD (IX+8), L" );
223 outline0( "LD (IX+9), H" );
224
225 // TABLE2
226
227 // outline1( "LDX #%soffsetsequence", image->realName );
228 // outline1( "STX %s+10", imageRef->realName );
229
230 }
231
232 break;
233
234 case VT_SEQUENCE:
235 if ( image->bankAssigned != -1 ) {
236
237 // BASE
238
239 outline1( "LD HL, $%4.4x", image->absoluteAddress );
240 outline0( "LD (IX), L" );
241 outline0( "LD (IX+1), H" );
242
243 // SIZE
244
245 outline1( "LD HL, $%4.4x", image->frameSize );
246 outline0( "LD (IX+2), L" );
247 outline0( "LD (IX+3), H" );
248
249 // BANK
250
251 outline1( "LD A, $%2.2x", image->bankAssigned );
252 outline0( "LD (IX+4), HL" );
253
254 // INFO
255
256 outline0( "LD A, $0f" );
257 outline0( "LD (IX+5), A" );
258
259 // RESIDENT
260
261 char bankWindowName[MAX_TEMPORARY_STORAGE];
262 sprintf( bankWindowName, "BANKWINDOW%2.2x", image->residentAssigned );
263 outline1( "LD HL, %s", bankWindowName );
264 outline0( "LD (IX+6), L" );
265 outline0( "LD (IX+7), H" );
266
267 // TABLE1
268
269 outline1( "LD HL, %soffsetframe", image->realName );
270 outline0( "LD (IX+8), L" );
271 outline0( "LD (IX+8), H" );
272
273 // TABLE2
274
275 outline1( "LD HL, %soffsetsequence", image->realName );
276 outline0( "LD (IX+8), L" );
277 outline0( "LD (IX+8), H" );
278
279 } else {
280
281 // BASE
282
283 outline1( "LD HL, %s", image->realName );
284 outline0( "LD (IX), L" );
285 outline0( "LD (IX+1), H" );
286
287 // SIZE
288
289 outline1( "LD HL, #$%4.4x", image->frameSize );
290 outline0( "LD (IX+2), L" );
291 outline0( "LD (IX+3), H" );
292
293 // BANK
294
295 // outline1( "LDA #$%2.2x", image->bankAssigned );
296 // outline1( "STA %s+4", imageRef->realName );
297
298 // INFO
299
300 outline0( "LD A, #$03" );
301 outline0( "LD (IX+5), A" );
302
303 // RESIDENT
304
305 // char bankWindowName[MAX_TEMPORARY_STORAGE];
306 // sprintf( bankWindowName, "BANKWINDOW%2.2x", image->residentAssigned );
307
308 // outline1( "LDX #%s", bankWindowName );
309 // outline1( "STX %s+6", imageRef->realName );
310
311 // TABLE1
312
313 outline1( "LD HL, #%soffsetframe", image->realName );
314 outline0( "LD (IX+8), L" );
315 outline0( "LD (IX+9), H" );
316
317 // TABLE2
318
319 outline1( "LD HL, #%soffsetsequence", image->realName );
320 outline0( "LD (IX+8), L" );
321 outline0( "LD (IX+9), H" );
322
323 }
324
325 break;
326
327 default:
329 }
330
331 // FRAME WIDTH
332 outline1( "LD A, $%2.2x", image->frameWidth );
333 outline1( "LD (%s+12), A", imageRef->realName );
334
335 // FRAME WIDTH
336 outline1( "LD A, $%2.2x", image->frameHeight );
337 outline1( "LD (%s+13), A", imageRef->realName );
338
339 return imageRef;
340
341}
342
343#endif
Variable * variable_retrieve(Environment *_environment, char *_name)
Variable * variable_temporary(Environment *_environment, VariableType _type, char *_meaning)
Define a temporary variable.
Variable * image_ref(Environment *_environment, char *_image)
Definition image_ref.c:43
int bankAssigned
Definition ugbc.h:1172
int residentAssigned
Definition ugbc.h:1175
int absoluteAddress
Definition ugbc.h:1092
int usedImage
Definition ugbc.h:1220
VariableType type
Definition ugbc.h:988
int frameSize
Definition ugbc.h:1134
int frameWidth
Definition ugbc.h:1162
int frameHeight
Definition ugbc.h:1164
char * realName
Definition ugbc.h:982
#define MAX_TEMPORARY_STORAGE
Definition ugbc.h:563
#define CRITICAL_IMAGEREF_ON_NON_IMAGE(v)
Definition ugbc.h:3755
struct _Variable Variable
Structure of a single variable.
struct _Environment Environment
Structure of compilation environment.
@ VT_IMAGEREF
Definition ugbc.h:537
@ VT_IMAGES
Definition ugbc.h:495
@ VT_IMAGE
Definition ugbc.h:489
@ VT_SEQUENCE
Definition ugbc.h:513
#define outline0(s)
Definition ugbc.h:4252
#define outline1(s, a)
Definition ugbc.h:4253