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(__msx1__) || defined(__coleco__) || defined(__sc3000__) || defined(__sg1000__)
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 #if !defined(__coleco__)
82 char bankWindowName[MAX_TEMPORARY_STORAGE];
83 sprintf( bankWindowName, "BANKWINDOW%2.2x", image->residentAssigned );
84 outline1( "LD HL, %s", bankWindowName );
85 outline0( "LD (IX+6), L" );
86 outline0( "LD (IX+7), H" );
87 #endif
88
89 // TABLE1
90
91 // outline1( "LDX #%soffsetframe", image->realName );
92 // outline1( "STX %s+8", imageRef->realName );
93
94 // TABLE2
95
96 // outline1( "LDX #%soffsetsequence", image->realName );
97 // outline1( "STX %s+10", imageRef->realName );
98
99 } else {
100
101 // BASE
102
103 outline1( "LD HL, %s", image->realName );
104 outline0( "LD (IX), L" );
105 outline0( "LD (IX+1), H" );
106
107 // SIZE
108
109 outline1( "LD HL, $%4.4x", image->frameSize );
110 outline0( "LD (IX+2), L" );
111 outline0( "LD (IX+3), H" );
112
113 // BANK
114
115 // outline1( "LDA #$%2.2x", image->bankAssigned );
116 // outline1( "STA %s+4", imageRef->realName );
117
118 // INFO
119
120 outline0( "LD A, $03" );
121 outline0( "LD (IX+5), A" );
122
123 // RESIDENT
124
125 // char bankWindowName[MAX_TEMPORARY_STORAGE];
126 // sprintf( bankWindowName, "BANKWINDOW%2.2x", image->residentAssigned );
127
128 // outline1( "LDX #%s", bankWindowName );
129 // outline1( "STX %s+6", imageRef->realName );
130
131 // TABLE1
132
133 // outline1( "LDX #%soffsetframe", image->realName );
134 // outline1( "STX %s+8", imageRef->realName );
135
136 // TABLE2
137
138 // outline1( "LDX #%soffsetsequence", image->realName );
139 // outline1( "STX %s+10", imageRef->realName );
140
141 }
142
143 break;
144
145 case VT_IMAGES:
146 if ( image->bankAssigned != -1 ) {
147
148 // BASE
149
150 outline1( "LD HL, #$%4.4x", image->absoluteAddress );
151 outline0( "LD (IX), L" );
152 outline0( "LD (IX+1), H" );
153
154 // SIZE
155
156 outline1( "LD HL, $%4.4x", image->frameSize );
157 outline0( "LD (IX+2), L" );
158 outline0( "LD (IX+3), H" );
159
160 // BANK
161
162 outline1( "LD A, $%2.2x", image->bankAssigned );
163 outline0( "LD (IX+4), A" );
164
165 // INFO
166
167 outline0( "LD A, $0f" );
168 outline0( "LD (IX+5), A" );
169
170 // RESIDENT
171
172 #if !defined(__coleco__)
173 char bankWindowName[MAX_TEMPORARY_STORAGE];
174 sprintf( bankWindowName, "BANKWINDOW%2.2x", image->residentAssigned );
175 outline1( "LD HL, %s", bankWindowName );
176 outline0( "LD (IX+6), L" );
177 outline0( "LD (IX+7), H" );
178 #endif
179
180 // TABLE1
181
182 outline1( "LD HL, %soffsetframe", image->realName );
183 outline0( "LD (IX+8), L" );
184 outline0( "LD (IX+9), H" );
185
186 // TABLE2
187
188 // outline1( "LDX #%soffsetsequence", image->realName );
189 // outline1( "STX %s+10", imageRef->realName );
190
191 } else {
192
193 // BASE
194
195 outline1( "LD HL, %s", image->realName );
196 outline0( "LD (IX), L" );
197 outline0( "LD (IX+1), H" );
198
199 // SIZE
200
201 outline1( "LD HL, $%4.4x", image->frameSize );
202 outline0( "LD (IX+2), L" );
203 outline0( "LD (IX+3), H" );
204
205 // BANK
206
207 // outline1( "LDA #$%2.2x", image->bankAssigned );
208 // outline1( "STA %s+4", imageRef->realName );
209
210 // INFO
211
212 outline0( "LD A, $03" );
213 outline0( "LD (IX+5), A" );
214
215 // RESIDENT
216
217 // char bankWindowName[MAX_TEMPORARY_STORAGE];
218 // sprintf( bankWindowName, "BANKWINDOW%2.2x", image->residentAssigned );
219
220 // outline1( "LDX #%s", bankWindowName );
221 // outline1( "STX %s+6", imageRef->realName );
222
223 // TABLE1
224
225 outline1( "LD HL, %soffsetframe", image->realName );
226 outline0( "LD (IX+8), L" );
227 outline0( "LD (IX+9), H" );
228
229 // TABLE2
230
231 // outline1( "LDX #%soffsetsequence", image->realName );
232 // outline1( "STX %s+10", imageRef->realName );
233
234 }
235
236 break;
237
238 case VT_SEQUENCE:
239 if ( image->bankAssigned != -1 ) {
240
241 // BASE
242
243 outline1( "LD HL, $%4.4x", image->absoluteAddress );
244 outline0( "LD (IX), L" );
245 outline0( "LD (IX+1), H" );
246
247 // SIZE
248
249 outline1( "LD HL, $%4.4x", image->frameSize );
250 outline0( "LD (IX+2), L" );
251 outline0( "LD (IX+3), H" );
252
253 // BANK
254
255 outline1( "LD A, $%2.2x", image->bankAssigned );
256 outline0( "LD (IX+4), HL" );
257
258 // INFO
259
260 outline0( "LD A, $0f" );
261 outline0( "LD (IX+5), A" );
262
263 // RESIDENT
264
265 #if !defined(__coleco__)
266 char bankWindowName[MAX_TEMPORARY_STORAGE];
267 sprintf( bankWindowName, "BANKWINDOW%2.2x", image->residentAssigned );
268 outline1( "LD HL, %s", bankWindowName );
269 outline0( "LD (IX+6), L" );
270 outline0( "LD (IX+7), H" );
271 #endif
272
273 // TABLE1
274
275 outline1( "LD HL, %soffsetframe", image->realName );
276 outline0( "LD (IX+8), L" );
277 outline0( "LD (IX+8), H" );
278
279 // TABLE2
280
281 outline1( "LD HL, %soffsetsequence", image->realName );
282 outline0( "LD (IX+8), L" );
283 outline0( "LD (IX+8), H" );
284
285 } else {
286
287 // BASE
288
289 outline1( "LD HL, %s", image->realName );
290 outline0( "LD (IX), L" );
291 outline0( "LD (IX+1), H" );
292
293 // SIZE
294
295 outline1( "LD HL, #$%4.4x", image->frameSize );
296 outline0( "LD (IX+2), L" );
297 outline0( "LD (IX+3), H" );
298
299 // BANK
300
301 // outline1( "LDA #$%2.2x", image->bankAssigned );
302 // outline1( "STA %s+4", imageRef->realName );
303
304 // INFO
305
306 outline0( "LD A, #$03" );
307 outline0( "LD (IX+5), A" );
308
309 // RESIDENT
310
311 // char bankWindowName[MAX_TEMPORARY_STORAGE];
312 // sprintf( bankWindowName, "BANKWINDOW%2.2x", image->residentAssigned );
313
314 // outline1( "LDX #%s", bankWindowName );
315 // outline1( "STX %s+6", imageRef->realName );
316
317 // TABLE1
318
319 outline1( "LD HL, #%soffsetframe", image->realName );
320 outline0( "LD (IX+8), L" );
321 outline0( "LD (IX+9), H" );
322
323 // TABLE2
324
325 outline1( "LD HL, #%soffsetsequence", image->realName );
326 outline0( "LD (IX+8), L" );
327 outline0( "LD (IX+9), H" );
328
329 }
330
331 break;
332
333 default:
335 }
336
337 // FRAME WIDTH
338 outline1( "LD A, $%2.2x", image->frameWidth );
339 outline1( "LD (%s+12), A", imageRef->realName );
340
341 // FRAME WIDTH
342 outline1( "LD A, $%2.2x", image->frameHeight );
343 outline1( "LD (%s+13), A", imageRef->realName );
344
345 return imageRef;
346
347}
348
349#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