ugBASIC 1.18
An isomorphic BASIC language compiler for retrocomputers
Loading...
Searching...
No Matches
_var.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#include <math.h>
37
38/****************************************************************************
39 * CODE SECTION
40 ****************************************************************************/
41
42extern char BANK_TYPE_AS_STRING[][16];
43extern char DATATYPE_AS_STRING[][16];
44
45static void variable_cleanup_entry( Environment * _environment, Variable * _first ) {
46
47 Variable * variable = _first;
48
49 while( variable ) {
50
51 if ( ( !variable->assigned || ( variable->assigned && !variable->temporary ) ) && !variable->imported && !variable->memoryArea ) {
52
53 if ( variable->memoryArea && _environment->debuggerLabelsFile ) {
54 fprintf( _environment->debuggerLabelsFile, "%4.4x %s\r\n", variable->absoluteAddress, variable->realName );
55 }
56
57 switch( variable->type ) {
58 case VT_CHAR:
59 case VT_BYTE:
60 case VT_SBYTE:
61 case VT_COLOR:
62 case VT_THREAD:
63 if ( variable->memoryArea ) {
64 // outhead2("%s = $%4.4x", variable->realName, variable->absoluteAddress);
65 } else {
66 vars_emit_byte( _environment, variable->realName, variable->initialValue );
67 }
68 break;
69 case VT_DOJOKA:
70 if ( variable->memoryArea ) {
71 // outhead2("%s = $%4.4x", variable->realName, variable->absoluteAddress);
72 } else {
73 outhead1("%s: .res 4,0", variable->realName);
74 }
75 break;
76 case VT_WORD:
77 case VT_SWORD:
78 case VT_POSITION:
79 case VT_ADDRESS:
80 if ( variable->memoryArea ) {
81 // outhead2("%s = $%4.4x", variable->realName, variable->absoluteAddress);
82 } else {
83 vars_emit_word( _environment, variable->realName, variable->initialValue );
84 }
85 break;
86 case VT_DWORD:
87 case VT_SDWORD:
88 if ( variable->memoryArea ) {
89 // outhead2("%s = $%4.4x", variable->realName, variable->absoluteAddress);
90 } else {
91 vars_emit_dword( _environment, variable->realName, variable->initialValue );
92 }
93 break;
94 case VT_FLOAT:
95 if ( variable->memoryArea ) {
96 // outhead2("%s = $%4.4x", variable->realName, variable->absoluteAddress);
97 } else {
98 outhead1("%s: .res 4,0", variable->realName);
99 }
100 break;
101 case VT_NUMBER:
102 if ( variable->memoryArea ) {
103 // outhead2("%s = $%4.4x", variable->realName, variable->absoluteAddress);
104 } else {
105 outhead2("%s: .res %d,0", variable->realName, _environment->numberConfig.maxBytes);
106 }
107 break;
108 case VT_STRING:
109 if ( variable->memoryArea ) {
110 // outhead2("%s = $%4.4x", variable->realName, variable->absoluteAddress);
111 } else {
112 outhead2("%s = cstring%d", variable->realName, variable->valueString->id );
113 }
114 break;
115 case VT_DSTRING:
116 if ( variable->memoryArea ) {
117 // outhead2("%s = $%4.4x", variable->realName, variable->absoluteAddress);
118 } else {
119 outhead1("%s: .res 1,0", variable->realName);
120 }
121 break;
122 case VT_TILE:
123 case VT_SPRITE:
124 case VT_MSPRITE:
125 case VT_TILESET:
126 if ( variable->memoryArea ) {
127 // outhead2("%s = $%4.4x", variable->realName, variable->absoluteAddress);
128 } else {
129 outhead1("%s: .res 1,0", variable->realName);
130 }
131 break;
132 case VT_TILES:
133 if ( variable->memoryArea ) {
134 // outhead2("%s = $%4.4x", variable->realName, variable->absoluteAddress);
135 } else {
136 outhead1("%s: .res 4,0", variable->realName);
137 }
138 break;
139 case VT_IMAGEREF:
140 if ( variable->memoryArea ) {
141 // outhead2("%s = $%4.4x", variable->realName, variable->absoluteAddress);
142 } else {
143 outhead1("%s: .res 14,0", variable->realName);
144 }
145 break;
146 case VT_PATH:
147 if ( variable->memoryArea ) {
148 // outhead2("%s = $%4.4x", variable->realName, variable->absoluteAddress);
149 } else {
150 outhead1("%s: .res 16,0", variable->realName);
151 }
152 break;
153 case VT_VECTOR2:
154 if ( variable->memoryArea ) {
155 // outhead2("%s = $%4.4x", variable->realName, variable->absoluteAddress);
156 } else {
157 outhead1("%s: .res 4,0", variable->realName);
158 }
159 break;
160 case VT_IMAGE:
161 case VT_IMAGES:
162 case VT_SEQUENCE:
163 if ( variable->usedImage ) {
164 if ( variable->bankAssigned != -1 ) {
165 outhead2("; relocated on bank %d (at %4.4x)", variable->bankAssigned, variable->absoluteAddress );
166 outhead1("%s: .byte $0", variable->realName );
167 } else {
168 if ( ! variable->absoluteAddress ) {
169 if ( variable->valueBuffer ) {
170 if ( variable->printable ) {
171 char * string = malloc( variable->size + 1 );
172 memset( string, 0, variable->size + 1 );
173 memcpy( string, variable->valueBuffer, variable->size );
174 outhead2("%s: .byte %s", variable->realName, escape_newlines( string ) );
175 } else {
176 out1("%s: .byte ", variable->realName);
177 int i=0;
178 for (i=0; i<(variable->size-1); ++i ) {
179 if ( (i+1) % 16 == 0 ) {
180 outline1("$%2.2x", (unsigned char)(variable->valueBuffer[i] & 0xff ) );
181 out0(" .byte ");
182 } else {
183 out1("$%2.2x,", (unsigned char)(variable->valueBuffer[i] & 0xff ) );
184 }
185
186 }
187 outline1("$%2.2x", (unsigned char)(variable->valueBuffer[(variable->size-1)] & 0xff ) );
188 }
189 } else {
190 outhead2("%s: .res %d,0", variable->realName, variable->size);
191 }
192 } else {
193 if ( ! variable->memoryArea && variable->valueBuffer ) {
194 outhead2("%s = $%4.4x", variable->realName, variable->absoluteAddress);
195 if ( variable->printable ) {
196 char * string = malloc( variable->size + 1 );
197 memset( string, 0, variable->size + 1 );
198 memcpy( string, variable->valueBuffer, variable->size );
199 outhead2("%scopy: .byte %s", variable->realName, escape_newlines( string ) );
200 } else {
201 out1("%scopy: .byte ", variable->realName);
202 int i=0;
203 for (i=0; i<(variable->size-1); ++i ) {
204 out1("$%2.2x,", (unsigned char)(variable->valueBuffer[i] & 0xff ) );
205 }
206 outline1("$%2.2x", (unsigned char)(variable->valueBuffer[(variable->size-1)] & 0xff ) );
207 }
208 }
209 }
210 }
211
212 }
213 break;
214 case VT_MUSIC:
215 case VT_BUFFER:
216 case VT_TYPE:
217 if ( variable->bankAssigned != -1 ) {
218 outhead2("; relocated on bank %d (at %4.4x)", variable->bankAssigned, variable->absoluteAddress );
219 outhead1("%s: .byte $0", variable->realName );
220 } else {
221 if ( ! variable->absoluteAddress ) {
222 if ( variable->valueBuffer ) {
223 if ( variable->printable ) {
224 char * string = malloc( variable->size + 1 );
225 memset( string, 0, variable->size + 1 );
226 memcpy( string, variable->valueBuffer, variable->size );
227 outhead2("%s: .byte %s", variable->realName, escape_newlines( string ) );
228 } else {
229 out1("%s: .byte ", variable->realName);
230 int i=0;
231 for (i=0; i<(variable->size-1); ++i ) {
232 if ( (i+1) % 16 == 0 ) {
233 outline1("$%2.2x", (unsigned char)(variable->valueBuffer[i] & 0xff ) );
234 out0(" .byte ");
235 } else {
236 out1("$%2.2x,", (unsigned char)(variable->valueBuffer[i] & 0xff ) );
237 }
238
239 }
240 outline1("$%2.2x", (unsigned char)(variable->valueBuffer[(variable->size-1)] & 0xff ) );
241 }
242 } else {
243 outhead2("%s: .res %d,0", variable->realName, variable->size);
244 }
245 } else {
246 if ( ! variable->memoryArea && variable->valueBuffer ) {
247 outhead2("%s = $%4.4x", variable->realName, variable->absoluteAddress);
248 if ( variable->printable ) {
249 char * string = malloc( variable->size + 1 );
250 memset( string, 0, variable->size + 1 );
251 memcpy( string, variable->valueBuffer, variable->size );
252 outhead2("%scopy: .byte %s", variable->realName, escape_newlines( string ) );
253 } else {
254 out1("%scopy: .byte ", variable->realName);
255 int i=0;
256 for (i=0; i<(variable->size-1); ++i ) {
257 out1("$%2.2x,", (unsigned char)(variable->valueBuffer[i] & 0xff ) );
258 }
259 outline1("$%2.2x", (unsigned char)(variable->valueBuffer[(variable->size-1)] & 0xff ) );
260 }
261 }
262 }
263 }
264 break;
265 case VT_BLIT:
266 break;
267 case VT_TILEMAP:
268 case VT_TARRAY: {
269 if ( variable->bankAssigned != -1 ) {
270 outhead4("; relocated on bank %d (at %4.4x) for %d bytes (uncompressed: %d)", variable->bankAssigned, variable->absoluteAddress, variable->size, variable->uncompressedSize );
271 if ( variable->type == VT_TARRAY ) {
272 if (VT_BITWIDTH( variable->arrayType ) == 0 ) {
274 }
275 // force +1 byte if size is odd
276 outhead2("%s: .res %d, $00", variable->realName, (VT_BITWIDTH( variable->arrayType )>>3) );
277 } else {
278 if (VT_BITWIDTH( variable->type ) == 0 ) {
279 CRITICAL_DATATYPE_UNSUPPORTED( "BANKED", DATATYPE_AS_STRING[ variable->type ] );
280 }
281 // force +1 byte if size is odd
282 outhead2("%s: .res %d, $00", variable->realName, (VT_BITWIDTH( variable->type )>>3) );
283 }
284 } else {
285 if ( ! variable->memoryArea && variable->valueBuffer ) {
286 out1("%s: .byte ", variable->realName);
287 int i=0;
288 for (i=0; i<(variable->size-1); ++i ) {
289 out1("$%2.2x,", (unsigned char) ( variable->valueBuffer[i] & 0xff ) );
290 }
291 outline1("$%2.2x", (unsigned char) ( variable->valueBuffer[(variable->size-1)] & 0xff ) );
292 } else if ( variable->memoryArea && ! variable->value ) {
293 // outhead2("%s = $%4.4x", variable->realName, variable->absoluteAddress);
294 } else {
295 if ( variable->value ) {
296 switch( VT_BITWIDTH( variable->arrayType ) ) {
297 case 32: {
298 out1("%s: .byte ", variable->realName );
299 for( int i=0; i<(variable->size/4)-1; ++i ) {
300 out4("$%2.2x, $%2.2x, $%2.2x, $%2.2x, ", (unsigned int)( variable->value & 0xff ), (unsigned int)( ( variable->value >> 8 ) & 0xff ), (unsigned int)( ( variable->value >> 16 ) & 0xff ), (unsigned int)( ( variable->value >> 24 ) & 0xff ) );
301 }
302 out4("$%2.2x, $%2.2x, $%2.2x, $%2.2x", (unsigned int)( variable->value & 0xff ), (unsigned int)( ( variable->value >> 8 ) & 0xff ), (unsigned int)( ( variable->value >> 16 ) & 0xff ), (unsigned int)( ( variable->value >> 24 ) & 0xff ) );
303 outline0("");
304 break;
305 }
306 case 16: {
307 out1("%s: .byte ", variable->realName );
308 for( int i=0; i<(variable->size/2)-1; ++i ) {
309 out2("$%2.2x, $%2.2x,", (unsigned int)( variable->value & 0xff ), (unsigned int)( ( variable->value >> 8 ) & 0xff ) );
310 }
311 out2("$%2.2x, $%2.2x", (unsigned int)( variable->value & 0xff ), (unsigned int)( ( variable->value >> 8 ) & 0xff ) );
312 outline0("");
313 break;
314 }
315 case 8:
316 outhead3("%s: .res %d, $%2.2x", variable->realName, variable->size, (unsigned char)(variable->value&0xff) );
317 break;
318 case 1:
319 outhead3("%s: .res %d, $%2.2x", variable->realName, variable->size, (unsigned char)(variable->value?0xff:0x00));
320 break;
321 }
322
323 } else {
324 outhead2("%s: .res %d, 0", variable->realName, variable->size);
325 }
326 }
327 }
328 }
329
330 break;
331 }
332
333 if( variable->type == VT_IMAGES ) {
334 if ( variable->strips ) {
335 vars_emit_strips( _environment, variable->realName, variable->strips );
336 }
337 }
338
339 }
340 variable = variable->next;
341 }
342
343}
344
345static void variable_cleanup_memory_mapped( Environment * _environment, Variable * _variable ) {
346
347 outhead2("; %s (%4.4x)", _variable->realName, _variable->absoluteAddress );
348 outhead1("%s:", _variable->realName );
349
350 switch( _variable->type ) {
351 case VT_CHAR:
352 case VT_BYTE:
353 case VT_SBYTE:
354 case VT_COLOR:
355 case VT_THREAD:
356 vars_emit_byte( _environment, NULL, _variable->initialValue );
357 break;
358 case VT_DOJOKA:
359 outline0(" .res 4, 0");
360 break;
361 case VT_WORD:
362 case VT_SWORD:
363 case VT_POSITION:
364 case VT_ADDRESS:
365 vars_emit_word( _environment, NULL, _variable->initialValue );
366 break;
367 case VT_DWORD:
368 case VT_SDWORD:
369 vars_emit_dword( _environment, NULL, _variable->initialValue );
370 break;
371 case VT_NUMBER:
372 vars_emit_number( _environment, NULL, _variable->initialValue );
373 break;
374 case VT_FLOAT: {
375 int bytes = VT_FLOAT_BITWIDTH( _variable->precision ) >> 3;
376 // int * data = malloc( bytes * sizeof( int ) );
377 // switch( _variable->precision ) {
378 // case FT_FAST:
379 // cpu_float_fast_from_double_to_int_array( _environment, _variable->valueFloating, data );
380 // break;
381 // case FT_SINGLE:
382 // cpu_float_single_from_double_to_int_array( _environment, _variable->valueFloating, data );
383 // break;
384 // }
385 // for( int i=0; i<bytes; ++i ) {
386 // outline1(" .byte $%2.2x", (unsigned char)( ( data[i] ) & 0xff ) );
387 // }
388 outhead1("%s: .res 4,0", _variable->realName);
389 break;
390 }
391 case VT_STRING:
392 break;
393 case VT_DSTRING:
394 case VT_MSPRITE:
395 case VT_SPRITE:
396 case VT_TILE:
397 case VT_TILESET:
398 outline0(" .byte 0" );
399 break;
400 case VT_TILES:
401 outline0(" .byte 0, 0, 0, 0" );
402 break;
403 case VT_IMAGE:
404 case VT_IMAGES:
405 case VT_SEQUENCE:
406 if ( _variable->usedImage ) {
407 if ( _variable->bankAssigned != -1 ) {
408 outhead2("; relocated on bank %d (at %4.4x)", _variable->bankAssigned, _variable->absoluteAddress );
409 } else {
410 if ( _variable->valueBuffer ) {
411 if ( _variable->printable ) {
412 char * string = malloc( _variable->size + 1 );
413 memset( string, 0, _variable->size + 1 );
414 memcpy( string, _variable->valueBuffer, _variable->size );
415 outline1(" .byte %s", escape_newlines( string ) );
416 } else {
417 out0(" .byte ");
418 int i=0;
419 for (i=0; i<(_variable->size-1); ++i ) {
420 out1("$%2.2x,", (unsigned char)(_variable->valueBuffer[i] & 0xff ) );
421 }
422 outline1("$%2.2x", (unsigned char)(_variable->valueBuffer[(_variable->size-1)] & 0xff ) );
423 }
424 } else {
425 outline1(" .res %d,0", _variable->size);
426 }
427 }
428 }
429 break;
430 case VT_MUSIC:
431 case VT_BUFFER:
432 case VT_TYPE:
433 if ( _variable->bankAssigned != -1 ) {
434 outhead2("; relocated on bank %d (at %4.4x)", _variable->bankAssigned, _variable->absoluteAddress );
435 } else {
436 if ( _variable->valueBuffer ) {
437 if ( _variable->printable ) {
438 char * string = malloc( _variable->size + 1 );
439 memset( string, 0, _variable->size + 1 );
440 memcpy( string, _variable->valueBuffer, _variable->size );
441 outline1(" .byte %s", escape_newlines( string ) );
442 } else {
443 out0(" .byte ");
444 int i=0;
445 for (i=0; i<(_variable->size-1); ++i ) {
446 out1("$%2.2x,", (unsigned char)(_variable->valueBuffer[i] & 0xff ) );
447 }
448 outline1("$%2.2x", (unsigned char)(_variable->valueBuffer[(_variable->size-1)] & 0xff ) );
449 }
450 } else {
451 outline1(" .res %d,0", _variable->size);
452 }
453 }
454 break;
455 case VT_BLIT:
456 break;
457 case VT_TILEMAP:
458 case VT_TARRAY: {
459 if ( _variable->valueBuffer ) {
460 out0(" .byte ");
461 int i=0;
462 for (i=0; i<(_variable->size-1); ++i ) {
463 out1("$%2.2x,", (unsigned char) ( _variable->valueBuffer[i] & 0xff ) );
464 }
465 outline1("$%2.2x", (unsigned char) ( _variable->valueBuffer[(_variable->size-1)] & 0xff ) );
466 } else {
467 if ( _variable->value ) {
468 switch( VT_BITWIDTH( _variable->arrayType ) ) {
469 case 32: {
470 out1("%s: .byte ", _variable->realName );
471 for( int i=0; i<(_variable->size/4)-1; ++i ) {
472 out4("$%2.2x, $%2.2x, $%2.2x, $%2.2x, ", (unsigned int)( _variable->value & 0xff ), (unsigned int)( ( _variable->value >> 8 ) & 0xff ), (unsigned int)( ( _variable->value >> 16 ) & 0xff ), (unsigned int)( ( _variable->value >> 24 ) & 0xff ) );
473 }
474 out4("$%2.2x, $%2.2x, $%2.2x, $%2.2x", (unsigned int)( _variable->value & 0xff ), (unsigned int)( ( _variable->value >> 8 ) & 0xff ), (unsigned int)( ( _variable->value >> 16 ) & 0xff ), (unsigned int)( ( _variable->value >> 24 ) & 0xff ) );
475 outline0("");
476 break;
477 }
478 case 16: {
479 out1("%s: .byte ", _variable->realName );
480 for( int i=0; i<(_variable->size/2)-1; ++i ) {
481 out2("$%2.2x, $%2.2x,", (unsigned int)( _variable->value & 0xff ), (unsigned int)( ( _variable->value >> 8 ) & 0xff ) );
482 }
483 out2("$%2.2x, $%2.2x", (unsigned int)( _variable->value & 0xff ), (unsigned int)( ( _variable->value >> 8 ) & 0xff ) );
484 outline0("");
485 break;
486 }
487 case 8:
488 outhead3("%s: .res %d, $%2.2x", _variable->realName, _variable->size, (unsigned char)(_variable->value&0xff) );
489 break;
490 case 1:
491 outhead3("%s: .res %d, $%2.2x", _variable->realName, _variable->size, (unsigned char)(_variable->value?0xff:0x00));
492 break;
493 }
494 } else {
495 outline1(" .res %d, 0", _variable->size);
496 }
497 }
498 break;
499 }
500 }
501
502 if( _variable->type == VT_IMAGES ) {
503 if ( _variable->strips ) {
504 vars_emit_strips( _environment, _variable->realName, _variable->strips );
505 }
506 }
507
508}
509
510static void variable_cleanup_entry_bit( Environment * _environment, Variable * _first ) {
511
512 Variable * variable = _first;
513
514 int bitCount = 0;
515
516 while( variable ) {
517
518 if ( ( !variable->assigned || ( variable->assigned && !variable->temporary ) ) && !variable->imported && !variable->memoryArea ) {
519
520 if ( variable->memoryArea && _environment->debuggerLabelsFile ) {
521 fprintf( _environment->debuggerLabelsFile, "%4.4x %s\r\n", variable->absoluteAddress, variable->realName );
522 }
523
524 switch( variable->type ) {
525 case VT_BIT:
526 if ( variable->memoryArea ) {
527 // outhead2("%s = $%4.4x", variable->realName, variable->absoluteAddress);
528 } else {
529 outhead1("%s:", variable->realName);
530 }
531 ++bitCount;
532 if ( bitCount == 8 ) {
533 outline0(" .res 1,0");
534 }
535 break;
536 }
537
538 }
539
540 variable = variable->next;
541
542 }
543
544 if ( bitCount > 0 ) {
545 outline0(" .res 1,0");
546 }
547
548}
549
559void variable_cleanup( Environment * _environment ) {
560 int i=0;
561
562 if ( _environment->dojoOnFujiNet || _environment->dojoOnVirtualizedFujiNet ) {
563 dojo_fujinet_init( _environment );
564 }
565
566 vars_emit_constants( _environment );
567
568 if ( _environment->dataSegment ) {
569 outhead1("DATAFIRSTSEGMENT = %s", _environment->dataSegment->realName );
570 if ( _environment->readDataUsed && _environment->restoreDynamic ) {
571 outhead0("DATASEGMENTNUMERIC:" );
572 DataSegment * actual = _environment->dataSegment;
573 while( actual ) {
574 if ( actual->isNumeric ) {
575 outhead2( ".word $%4.4x, %s", actual->lineNumber, actual->realName );
576 }
577 actual = actual->next;
578 }
579 outline0( ".word $ffff, DATAPTRE" );
580 }
581 }
582
583 if ( _environment->offsetting ) {
584 Offsetting * actual = _environment->offsetting;
585 while( actual ) {
586 out1("OFFSETS%4.4x: .word ", actual->size );
587 for( i=0; i<actual->count; ++i ) {
588 out1("$%4.4x", i * actual->size );
589 if ( i < ( actual->count - 1 ) ) {
590 out0(",");
591 } else {
592 outline0("");
593 }
594 }
595 if ( actual->variables ) {
596 OffsettingVariable * actualVariable = actual->variables;
597 while( actualVariable ) {
598 if ( actualVariable->sequence ) {
599 outhead1("%soffsetsequence:", actualVariable->variable->realName );
600 } else {
601 outhead1("%soffsetframe:", actualVariable->variable->realName );
602 }
603 actualVariable = actualVariable->next;
604 }
605 outhead1("fs%4.4xoffsetsequence:", actual->size );
606 outhead1("fs%4.4xsoffsetframe:", actual->size );
607 outline1("LDA #<OFFSETS%4.4x", actual->size );
608 outline0("STA MATHPTR1" );
609 outline1("LDA #>OFFSETS%4.4x", actual->size );
610 outline0("STA MATHPTR1+1" );
611 outline0("CLC" );
612 outline0("LDA MATHPTR0" );
613 outline0("ASL" );
614 outline0("TAY" );
615 outline0("LDA TMPPTR" );
616 outline0("ADC (MATHPTR1), Y" );
617 outline0("STA TMPPTR" );
618 outline0("INY" );
619 outline0("LDA TMPPTR+1" );
620 outline0("ADC (MATHPTR1), Y" );
621 outline0("STA TMPPTR+1" );
622 outline0("RTS" );
623 }
624 actual = actual->next;
625 }
626
627 int values[MAX_TEMPORARY_STORAGE];
628 char * address[MAX_TEMPORARY_STORAGE];
629
630 actual = _environment->offsetting;
631 int count = 0;
632 while( actual ) {
633 values[count] = actual->size;
634 address[count] = malloc( MAX_TEMPORARY_STORAGE );
635 sprintf( address[count], "fs%4.4xsoffsetframe", actual->size );
636 actual = actual->next;
637 ++count;
638 }
639
640 cpu_address_table_build( _environment, "EXECOFFSETS", values, address, count );
641
642 cpu_address_table_lookup( _environment, "EXECOFFSETS", count );
643
644 }
645
646 generate_cgoto_address_table( _environment );
647
648 banks_generate( _environment );
649
650 for(i=0; i<BANK_TYPE_COUNT; ++i) {
651 Bank * actual = _environment->banks[i];
652 while( actual ) {
653 if ( actual->type == BT_VARIABLES ) {
654 // cfgline3("# BANK %s %s AT $%4.4x", BANK_TYPE_AS_STRING[actual->type], actual->name, actual->address);
655 // cfgline2("%s: load = MAIN, type = ro, optional = yes, start = $%4.4x;", actual->name, actual->address);
656 // outhead1(".segment \"%s\"", actual->name);
657 Variable * variable = _environment->variables;
658
659 variable_cleanup_entry( _environment, variable );
660
661 variable_cleanup_entry_bit( _environment, variable );
662
663 } else if ( actual->type == BT_TEMPORARY ) {
664 // cfgline3("# BANK %s %s AT $%4.4x", BANK_TYPE_AS_STRING[actual->type], actual->name, actual->address);
665 // cfgline2("%s: load = MAIN, type = ro, optional = yes, start = $%4.4x;", actual->name, actual->address);
666 // outhead1(".segment \"%s\"", actual->name);
667 if ( _environment->bitmaskNeeded ) {
668 outhead0("BITMASK: .byte $01,$02,$04,$08,$10,$20,$40,$80");
669 outhead0("BITMASKN: .byte $fe,$fd,$fb,$f7,$ef,$df,$bf,$7f");
670 }
671 if ( _environment->deployed.dstring ) {
672 outhead1("max_free_string = $%4.4x", _environment->dstring.space == 0 ? DSTRING_DEFAULT_SPACE : _environment->dstring.space );
673 }
674
675 for( int j=0; j< (_environment->currentProcedure+1); ++j ) {
676 Variable * variable = _environment->tempVariables[j];
677 variable_cleanup_entry( _environment, variable );
678 variable_cleanup_entry_bit( _environment, variable );
679 }
680
681 Variable * variable = _environment->tempResidentVariables;
682
683 variable_cleanup_entry( _environment, variable );
684 variable_cleanup_entry_bit( _environment, variable );
685
686 // } else if ( actual->type == BT_STRINGS ) {
687 // cfgline3("# BANK %s %s AT $%4.4x", BANK_TYPE_AS_STRING[actual->type], actual->name, actual->address);
688 // cfgline2("%s: load = MAIN, type = ro, optional = yes, start = $%4.4x;", actual->name, actual->address);
689 } else {
690
691 }
692 actual = actual->next;
693 }
694 }
695
696 if ( _environment->descriptors ) {
697 outhead0("UDCCHAR:" );
698 int i=0,j=0;
699 for(i=0;i<_environment->descriptors->count;++i) {
700 outhead1("; $%2.2x ", i);
701 out0(".byte " );
702 for(j=0;j<7;++j) {
703 out1("$%2.2x,", ((unsigned char)_environment->descriptors->data[_environment->descriptors->first+i].data[j]) );
704 }
705 outline1("$%2.2x", ((unsigned char)_environment->descriptors->data[_environment->descriptors->first+i].data[j]) );
706 }
707 outhead0(".segment \"CODE\"" );
708 outhead0("GTIAUDCCHAR:" );
709 char startAddress[MAX_TEMPORARY_STORAGE]; sprintf( startAddress, "$B000+$%4.4x", ( _environment->descriptors->first * 8) );
710 cpu_mem_move_direct_size( _environment, "UDCCHAR", startAddress, _environment->descriptors->count*8 );
711 outline0("LDA #$B0" );
712 outline0("STA $2F4" );
713 outline0("RTS" );
714 } else {
715 outhead0("UDCCHAR = $E000" );
716 outhead0("GTIAUDCCHAR:" );
717 outline0("RTS" );
718 }
719
720 if ( _environment->memoryAreas ) {
721 MemoryArea * memoryArea = _environment->memoryAreas;
722 while( memoryArea ) {
723 // if ( memoryArea->type == MAT_RAM ) {
724 // cfgline3("MA%3.3x: load = RAM%3.3x, type = overwrite, optional = yes, start = $%4.4x;", memoryArea->id, memoryArea->id, memoryArea->start);
725 // } else {
726 // cfgline2("MA%3.3x: load = MAIN, type = overwrite, optional = yes, start = $%4.4x;", memoryArea->id, memoryArea->start);
727 // }
728 outhead1(".segment \"MA%3.3x\"", memoryArea->id );
729 for( i=memoryArea->start; i<memoryArea->end; ++i ) {
730 Variable * variable = _environment->variables;
731 while( variable ) {
732 if ( !variable->assigned && variable->memoryArea == memoryArea && variable->absoluteAddress == i ) {
733 variable_cleanup_memory_mapped( _environment, variable );
734 variable->staticalInit = ( memoryArea->type == MAT_RAM ? 0 : 1 );
735 break;
736 }
737 variable = variable->next;
738 }
739 for( int j=0; j< (_environment->currentProcedure+1); ++j ) {
740 Variable * variable = _environment->tempVariables[j];
741 while( variable ) {
742 if ( !variable->assigned && variable->memoryArea == memoryArea && variable->absoluteAddress == i ) {
743 variable_cleanup_memory_mapped( _environment, variable );
744 variable->staticalInit = ( memoryArea->type == MAT_RAM ? 0 : 1 );
745 break;
746 }
747 variable = variable->next;
748 }
749 }
750 variable = _environment->tempResidentVariables;
751 while( variable ) {
752 if ( !variable->assigned && variable->memoryArea == memoryArea && variable->absoluteAddress == i ) {
753 variable_cleanup_memory_mapped( _environment, variable );
754 variable->staticalInit = ( memoryArea->type == MAT_RAM ? 0 : 1 );
755 break;
756 }
757 variable = variable->next;
758 }
759 }
760 memoryArea = memoryArea->next;
761 }
762
763 }
764
765 outhead0(".segment \"CODE\"" );
766
767 variable_on_memory_init( _environment, 0 );
768
769 DataSegment * dataSegment = _environment->dataSegment;
770 while( dataSegment ) {
771 int i=0;
772 if ( dataSegment->data ) {
773 out1("%s: .BYTE ", dataSegment->realName );
774 } else {
775 outhead1("%s: ", dataSegment->realName );
776 }
777 DataDataSegment * dataDataSegment = dataSegment->data;
778 while( dataDataSegment ) {
779 int binary = 0;
780 for(int j=0; j<dataDataSegment->size; ++j ) {
781 if (dataDataSegment->data[j] == 34 || dataDataSegment->data[j] < 32 || dataDataSegment->data[j] > 128 ) {
782 binary = 1;
783 break;
784 }
785 }
786 if ( dataSegment->type ) {
787 if ( dataDataSegment->type == VT_STRING || dataDataSegment->type == VT_DSTRING ) {
788 if ( binary ) {
789 out1("$%2.2x,", (unsigned char)(dataDataSegment->size) );
790 for( i=0; i<(dataDataSegment->size-1); ++i ) {
791 out1("$%2.2x,", (unsigned char)(dataDataSegment->data[i]&0xff) );
792 }
793 out1("$%2.2x", (unsigned char)(dataDataSegment->data[i]&0xff) );
794 } else {
795 out1("$%2.2x,", (unsigned char)(dataDataSegment->size) );
796 out1("\"%s\"", dataDataSegment->data );
797 }
798 } else {
799 for( i=0; i<(dataDataSegment->size-1); ++i ) {
800 out1("$%2.2x,", (unsigned char)(dataDataSegment->data[i]&0xff) );
801 }
802 out1("$%2.2x", (unsigned char)(dataDataSegment->data[i]&0xff) );
803 }
804 } else {
805 if ( dataDataSegment->type == VT_STRING || dataDataSegment->type == VT_DSTRING ) {
806 if ( binary ) {
807 out1("$%2.2x,", (unsigned char)(dataDataSegment->type) );
808 out1("$%2.2x,", (unsigned char)(dataDataSegment->size) );
809 for( i=0; i<(dataDataSegment->size-1); ++i ) {
810 out1("$%2.2x,", (unsigned char)(dataDataSegment->data[i]&0xff) );
811 }
812 out1("$%2.2x", (unsigned char)(dataDataSegment->data[i]&0xff) );
813 } else {
814 out1("$%2.2x,", (unsigned char)(dataDataSegment->type) );
815 out1("$%2.2x,", (unsigned char)(dataDataSegment->size) );
816 out1("\"%s\"", dataDataSegment->data );
817 }
818 } else {
819 out1("$%2.2x,", (unsigned char)(dataDataSegment->type) );
820 for( i=0; i<(dataDataSegment->size-1); ++i ) {
821 out1("$%2.2x,", (unsigned char)(dataDataSegment->data[i]&0xff) );
822 }
823 out1("$%2.2x", (unsigned char)(dataDataSegment->data[i]&0xff) );
824 }
825 }
826 dataDataSegment = dataDataSegment->next;
827 if ( dataDataSegment ) {
828 out0(",");
829 }
830 }
831 outline0("");
832 dataSegment = dataSegment->next;
833 }
834
835 if ( _environment->dataNeeded || _environment->dataSegment || _environment->deployed.read_data_unsafe ) {
836 outhead0("DATAPTRE:");
837 }
838
839 StaticString * staticStrings = _environment->strings;
840 while( staticStrings ) {
841 outhead3("cstring%d: .byte %d, %s", staticStrings->id, (int)strlen(staticStrings->value), escape_newlines( staticStrings->value ) );
842 staticStrings = staticStrings->next;
843 }
844
845 for( i=0; i<MAX_RESIDENT_SHAREDS; ++i ) {
846 if ( _environment->maxExpansionBankSize[i] ) {
847 outhead1("BANKWINDOWID%2.2x: .byte $FF, $FF", i );
848 outhead2("BANKWINDOW%2.2x: .res %d", i, _environment->maxExpansionBankSize[i]);
849 }
850 }
851
852 if ( _environment->deployed.dojo || _environment->deployed.dojo_fujinet ) {
853 outhead0("DOJOERROR: .byte $00" );
854 outhead0("DOJOPACKET:" );
855 outhead0("DOJOPACKET_CMD:" );
856 outhead0("DOJOPACKET_STATUS:" );
857 outline0(".BYTE $0" );
858 outhead0("DOJOPACKET_PAR1:" );
859 outhead0("DOJOPACKET_RSIZE:" );
860 outline0(".BYTE $0" );
861 outhead0("DOJOPACKET_PAR2:" );
862 outline0(".BYTE $0" );
863 outhead0("DOJOPACKET_SIZE:" );
864 outline0(".BYTE $0" );
865 }
866
867 buffered_push_output( _environment );
868
869 outhead0(".segment \"CODE\"");
870 outhead0(".proc MAINENTRY");
871 outline0("JMP CODESTART");
872
873 if ( _environment->chainUsed ) {
874 outhead0("CHAINLOADADDRESS=$2000-6");
875 deploy_preferred( dcommon, src_hw_atari_dcommon_asm );
876 deploy_inplace_preferred( dcommon, src_hw_atari_dcommon_asm );
877 _environment->deployed.dcommon = 0;
878 deploy_preferred( dload, src_hw_atari_dload_asm );
879 deploy_inplace_preferred( dload, src_hw_atari_dload_asm );
880 _environment->deployed.dload = 0;
881 deploy_preferred( chain, src_hw_atari_chain_asm );
882 deploy_inplace_preferred( chain, src_hw_atari_chain_asm );
883 _environment->deployed.chain = 0;
884 outhead0("CHAINEDSTART:");
885 outline0("JMP CODESTART");
886 }
887
888 deploy_inplace_preferred( vars, src_hw_atari_vars_asm);
889 deploy_inplace_preferred( startup, src_hw_atari_startup_asm);
890 deploy_inplace_preferred( gtiavars, src_hw_gtia_vars_asm );
891 deploy_inplace_preferred( gtiastartup, src_hw_gtia_startup_asm );
892 deploy_inplace_preferred( pokeystartup, src_hw_pokey_startup_asm );
893 deploy_inplace_preferred( vScrollText, src_hw_gtia_vscroll_text_asm );
894 deploy_inplace_preferred( textHScroll, src_hw_gtia_hscroll_text_asm );
895 deploy_inplace_preferred( dcommon, src_hw_atari_dcommon_asm );
896 deploy_inplace_preferred( dload, src_hw_atari_dload_asm );
897 deploy_inplace_preferred( chain, src_hw_atari_chain_asm );
898
899 outhead0("CODESTART:");
900
901 if ( _environment->dojoOnFujiNet || _environment->dojoOnVirtualizedFujiNet ) {
902 fujinet_define( _environment, FN_SIO );
903 }
904
905 buffered_prepend_output( _environment );
906
907}
void vars_emit_constants(Environment *_environment)
Definition _vars.c:58
void vars_emit_strips(Environment *_environment, char *_name, Strip *_strips)
Definition _vars.c:118
void cpu_address_table_build(Environment *_environment, char *_table, int *_values, char *_address[], int _count)
Definition 6309.c:7344
void cpu_mem_move_direct_size(Environment *_environment, char *_source, char *_destination, int _size)
Definition 6309.c:4798
void cpu_address_table_lookup(Environment *_environment, char *_table, int _count)
Definition 6309.c:7353
void vars_emit_word(Environment *_environment, char *_name, int _value)
Definition _vars.c:92
void vars_emit_dword(Environment *_environment, char *_name, int _value)
Definition _vars.c:100
void vars_emit_number(Environment *_environment, char *_name, int _value)
Definition _vars.c:108
#define VT_FLOAT_BITWIDTH(p)
Definition 6309.h:38
void vars_emit_byte(Environment *_environment, char *_name, int _value)
Definition _vars.c:84
void buffered_prepend_output(Environment *_environment)
char * escape_newlines(char *_string)
void buffered_push_output(Environment *_environment)
void variable_cleanup(Environment *_environment)
Emit source and configuration lines for variables.
Definition _var.c:559
char BANK_TYPE_AS_STRING[][16]
Description of BANK TYPE, in readable format.
void chain(Environment *_environment, char *_filename)
Definition chain.c:101
void dload(Environment *_environment, char *_filename, char *_offset, char *_address, char *_bank, char *_size)
Emit code for DLOAD(...).
Definition dload.c:60
void dojo_fujinet_init(Environment *_environment)
#define DSTRING_DEFAULT_SPACE
Definition atari.h:152
void banks_generate(Environment *_environment)
Definition _banks.c:45
void generate_cgoto_address_table(Environment *_environment)
Definition _var.c:122
void variable_on_memory_init(Environment *_environment, int _imported_too)
Definition _var.c:41
void end(Environment *_environment)
Emit ASM code for END.
Definition end.c:91
void fujinet_define(Environment *_environment, FujiNetDefine _mode)
struct _Bank * next
Definition ugbc.h:185
BankType type
Definition ugbc.h:162
int space
Definition ugbc.h:1970
struct _DataDataSegment * next
Definition ugbc.h:2181
char * data
Definition ugbc.h:2178
VariableType type
Definition ugbc.h:2175
struct _DataSegment * next
Definition ugbc.h:2198
DataDataSegment * data
Definition ugbc.h:2196
int lineNumber
Definition ugbc.h:2193
VariableType type
Definition ugbc.h:2187
int isNumeric
Definition ugbc.h:2189
char * realName
Definition ugbc.h:2192
int dload
Definition ugbc.h:1934
int dojo_fujinet
Definition ugbc.h:1952
int read_data_unsafe
Definition ugbc.h:1923
int chain
Definition ugbc.h:1957
int dojo
Definition ugbc.h:1951
int dcommon
Definition ugbc.h:1933
int dstring
Definition ugbc.h:1789
Variable * tempResidentVariables
Definition ugbc.h:2595
int chainUsed
Definition ugbc.h:3287
Offsetting * offsetting
Definition ugbc.h:2937
Bank * banks[BANK_TYPE_COUNT]
Definition ugbc.h:2514
int dojoOnVirtualizedFujiNet
Definition ugbc.h:3245
int maxExpansionBankSize[MAX_RESIDENT_SHAREDS]
Definition ugbc.h:3010
Variable * tempVariables[MAX_PROCEDURES]
Definition ugbc.h:2606
DataSegment * dataSegment
Definition ugbc.h:2568
FILE * debuggerLabelsFile
Definition ugbc.h:3319
StaticString * strings
Definition ugbc.h:2641
MemoryArea * memoryAreas
Definition ugbc.h:2689
int restoreDynamic
Definition ugbc.h:2573
int bitmaskNeeded
Definition ugbc.h:2659
int currentProcedure
Definition ugbc.h:2601
NumberConfig numberConfig
Definition ugbc.h:2410
DString dstring
Definition ugbc.h:2405
Variable * variables
Definition ugbc.h:2616
int dataNeeded
Definition ugbc.h:2557
int dojoOnFujiNet
Definition ugbc.h:3244
TileDescriptors * descriptors
Definition ugbc.h:2939
int readDataUsed
Definition ugbc.h:2578
Deployed deployed
Definition ugbc.h:2921
int start
Definition ugbc.h:737
struct _MemoryArea * next
Definition ugbc.h:760
int id
Definition ugbc.h:732
MemoryAreaType type
Definition ugbc.h:757
int maxBytes
Definition ugbc.h:2261
int size
Definition ugbc.h:892
struct _Offsetting * next
Definition ugbc.h:905
int count
Definition ugbc.h:897
OffsettingVariable * variables
Definition ugbc.h:902
struct _Variable * variable
Definition ugbc.h:880
struct _OffsettingVariable * next
Definition ugbc.h:883
char * value
Definition ugbc.h:337
struct _StaticString * next
Definition ugbc.h:342
char data[8]
Definition ugbc.h:2141
TileData data[512]
Definition ugbc.h:2153
int bankAssigned
Definition ugbc.h:1172
unsigned char * valueBuffer
Definition ugbc.h:1061
int printable
Definition ugbc.h:1097
Strip * strips
Definition ugbc.h:1215
FloatTypePrecision precision
Definition ugbc.h:991
StaticString * valueString
Definition ugbc.h:1041
int assigned
Definition ugbc.h:1020
struct _Variable * next
Definition ugbc.h:1225
int initialValue
Definition ugbc.h:1030
int size
Definition ugbc.h:1077
int absoluteAddress
Definition ugbc.h:1092
int usedImage
Definition ugbc.h:1220
VariableType type
Definition ugbc.h:988
int staticalInit
Definition ugbc.h:1139
MemoryArea * memoryArea
Definition ugbc.h:1107
int uncompressedSize
Definition ugbc.h:1082
int value
Definition ugbc.h:1025
int imported
Definition ugbc.h:1014
VariableType arrayType
Definition ugbc.h:1125
int temporary
Definition ugbc.h:996
char * realName
Definition ugbc.h:982
void * malloc(YYSIZE_T)
#define out4(s, a, b, c, d)
Definition ugbc.h:4263
#define deploy_inplace_preferred(s, e)
Definition ugbc.h:4313
#define BANK_TYPE_COUNT
Maximum number of bank types.
Definition ugbc.h:145
#define MAX_TEMPORARY_STORAGE
Definition ugbc.h:563
struct _Offsetting Offsetting
@ MAT_RAM
Definition ugbc.h:726
@ FN_SIO
Definition ugbc.h:377
#define MAX_RESIDENT_SHAREDS
Definition ugbc.h:572
struct _Variable Variable
Structure of a single variable.
struct _Environment Environment
Structure of compilation environment.
struct _MemoryArea MemoryArea
@ VT_THREAD
Definition ugbc.h:492
@ VT_DOJOKA
Definition ugbc.h:534
@ VT_TILE
Definition ugbc.h:504
@ VT_FLOAT
Definition ugbc.h:522
@ VT_BLIT
Definition ugbc.h:519
@ VT_TARRAY
Definition ugbc.h:480
@ VT_WORD
Definition ugbc.h:455
@ VT_POSITION
Definition ugbc.h:468
@ VT_NUMBER
Definition ugbc.h:549
@ VT_SDWORD
Definition ugbc.h:462
@ VT_MSPRITE
Definition ugbc.h:531
@ VT_STRING
Definition ugbc.h:474
@ VT_TILEMAP
Definition ugbc.h:525
@ VT_TILES
Definition ugbc.h:507
@ VT_SWORD
Definition ugbc.h:457
@ VT_BYTE
Definition ugbc.h:450
@ VT_DWORD
Definition ugbc.h:460
@ VT_BIT
Definition ugbc.h:528
@ VT_IMAGEREF
Definition ugbc.h:537
@ VT_VECTOR2
Definition ugbc.h:543
@ VT_CHAR
Definition ugbc.h:498
@ VT_BUFFER
Definition ugbc.h:477
@ VT_SPRITE
Definition ugbc.h:501
@ VT_SBYTE
Definition ugbc.h:452
@ VT_IMAGES
Definition ugbc.h:495
@ VT_MUSIC
Definition ugbc.h:516
@ VT_TYPE
Definition ugbc.h:546
@ VT_ADDRESS
Definition ugbc.h:465
@ VT_COLOR
Definition ugbc.h:471
@ VT_TILESET
Definition ugbc.h:510
@ VT_DSTRING
Definition ugbc.h:483
@ VT_PATH
Definition ugbc.h:540
@ VT_IMAGE
Definition ugbc.h:489
@ VT_SEQUENCE
Definition ugbc.h:513
struct _OffsettingVariable OffsettingVariable
#define deploy_preferred(s, e)
Definition ugbc.h:4299
#define outhead0(s)
Definition ugbc.h:4246
#define outhead4(s, a, b, c, d)
Definition ugbc.h:4250
#define out0(s)
Definition ugbc.h:4259
#define outhead3(s, a, b, c)
Definition ugbc.h:4249
@ BT_VARIABLES
Definition ugbc.h:126
@ BT_TEMPORARY
Definition ugbc.h:129
#define out2(s, a, b)
Definition ugbc.h:4261
#define outline0(s)
Definition ugbc.h:4252
struct _StaticString StaticString
Structure of a single (static) string.
#define outhead2(s, a, b)
Definition ugbc.h:4248
#define CRITICAL_DATATYPE_UNSUPPORTED(k, v)
Definition ugbc.h:3447
struct _DataDataSegment DataDataSegment
#define out1(s, a)
Definition ugbc.h:4260
#define outline1(s, a)
Definition ugbc.h:4253
struct _DataSegment DataSegment
#define VT_BITWIDTH(t)
Definition ugbc.h:595
struct _Bank Bank
Structure of a single bank.
#define outhead1(s, a)
Definition ugbc.h:4247
char DATATYPE_AS_STRING[][16]