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
37/****************************************************************************
38 * CODE SECTION
39 ****************************************************************************/
40
41extern char BANK_TYPE_AS_STRING[][16];
42extern char DATATYPE_AS_STRING[][16];
43
44static void variable_cleanup_entry( Environment * _environment, Variable * _first ) {
45
46 Variable * variable = _first;
47
48 while( variable ) {
49
50 if ( ( !variable->assigned || ( variable->assigned && !variable->temporary ) ) && !variable->imported && !variable->memoryArea ) {
51
52 if ( variable->memoryArea && _environment->debuggerLabelsFile ) {
53 fprintf( _environment->debuggerLabelsFile, "%4.4x %s\r\n", variable->absoluteAddress, variable->realName );
54 }
55
56 switch( variable->type ) {
57 case VT_CHAR:
58 case VT_BYTE:
59 case VT_SBYTE:
60 case VT_COLOR:
61 case VT_THREAD:
62 if ( variable->memoryArea ) {
63 // outhead2("%s = $%4.4x", variable->realName, variable->absoluteAddress);
64 } else {
65 vars_emit_byte( _environment, variable->realName, variable->initialValue);
66 }
67 break;
68 case VT_DOJOKA:
69 if ( variable->memoryArea ) {
70 // outhead2("%s = $%4.4x", variable->realName, variable->absoluteAddress);
71 } else {
72 outhead1("%s: .res 4,0", variable->realName);
73 }
74 break;
75 case VT_IMAGEREF:
76 if ( variable->memoryArea ) {
77 // outhead2("%s = $%4.4x", variable->realName, variable->absoluteAddress);
78 } else {
79 outhead1("%s: .res 14,0", variable->realName);
80 }
81 break;
82 case VT_PATH:
83 if ( variable->memoryArea ) {
84 // outhead2("%s = $%4.4x", variable->realName, variable->absoluteAddress);
85 } else {
86 outhead1("%s: .res 16,0", variable->realName);
87 }
88 break;
89 case VT_VECTOR2:
90 if ( variable->memoryArea ) {
91 // outhead2("%s = $%4.4x", variable->realName, variable->absoluteAddress);
92 } else {
93 outhead1("%s: .res 4,0", variable->realName);
94 }
95 break;
96 case VT_WORD:
97 case VT_SWORD:
98 case VT_POSITION:
99 case VT_ADDRESS:
100 if ( variable->memoryArea ) {
101 // outhead2("%s = $%4.4x", variable->realName, variable->absoluteAddress);
102 } else {
103 vars_emit_word( _environment, variable->realName, variable->initialValue);
104 }
105 break;
106 case VT_DWORD:
107 case VT_SDWORD:
108 if ( variable->memoryArea ) {
109 // outhead2("%s = $%4.4x", variable->realName, variable->absoluteAddress);
110 } else {
111 vars_emit_dword( _environment, variable->realName, variable->initialValue);
112 }
113 break;
114 case VT_NUMBER:
115 if ( variable->memoryArea ) {
116 // outhead2("%s = $%4.4x", variable->realName, variable->absoluteAddress);
117 } else {
118 vars_emit_number( _environment, variable->realName, variable->initialValue);
119 }
120 break;
121 case VT_FLOAT:
122 if ( variable->memoryArea && !variable->bankAssigned ) {
123 // outhead2("%s = $%4.4x", variable->realName, variable->absoluteAddress);
124 } else {
125 outhead1("%s: .res 4,0", variable->realName);
126 }
127 break;
128 case VT_STRING:
129 if ( variable->memoryArea ) {
130 // outhead2("%s = $%4.4x", variable->realName, variable->absoluteAddress);
131 } else {
132 outhead2("%s = cstring%d", variable->realName, variable->valueString->id );
133 }
134 break;
135 case VT_DSTRING:
136 if ( variable->memoryArea ) {
137 // outhead2("%s = $%4.4x", variable->realName, variable->absoluteAddress);
138 } else {
139 outhead1("%s: .res 1,0", variable->realName);
140 }
141 break;
142 case VT_TILE:
143 case VT_TILESET:
144 case VT_MSPRITE:
145 case VT_SPRITE:
146 if ( variable->memoryArea ) {
147 // outhead2("%s = $%4.4x", variable->realName, variable->absoluteAddress);
148 } else {
149 outhead1("%s: .res 1,0", variable->realName);
150 }
151 break;
152 case VT_TILES:
153 if ( variable->memoryArea ) {
154 // outhead2("%s = $%4.4x", variable->realName, variable->absoluteAddress);
155 } else {
156 outhead1("%s: .res 4,0", variable->realName);
157 }
158 break;
159 case VT_BLIT:
160 break;
161 case VT_IMAGE:
162 case VT_IMAGES:
163 case VT_SEQUENCE:
164 case VT_MUSIC:
165 case VT_BUFFER:
166 case VT_TYPE:
167 if ( variable->bankAssigned != -1 ) {
168 outhead2("; relocated on bank %d (at %4.4x)", variable->bankAssigned, variable->absoluteAddress );
169 outhead1("%s: .byte $0", variable->realName );
170 } else {
171 if ( ! variable->absoluteAddress ) {
172 if ( variable->valueBuffer ) {
173 if ( variable->printable ) {
174 char * string = malloc( variable->size + 1 );
175 memset( string, 0, variable->size + 1 );
176 memcpy( string, variable->valueBuffer, variable->size );
177 outhead2("%s: .byte %s", variable->realName, escape_newlines( string ) );
178 } else {
179 out1("%s: .byte ", variable->realName);
180 int i=0;
181 for (i=0; i<(variable->size-1); ++i ) {
182 if ( ( ( i + 1 ) % 16 ) == 0 ) {
183 outline1("$%2.2x", variable->valueBuffer[i]);
184 out0(" .byte ");
185 } else {
186 out1("$%2.2x,", variable->valueBuffer[i]);
187 }
188 }
189 outline1("$%2.2x", variable->valueBuffer[(variable->size-1)]);
190 }
191 } else {
192 outhead2("%s: .res %d,0", variable->realName, variable->size);
193 }
194 } else {
195 if ( ! variable->memoryArea && variable->valueBuffer ) {
196 outhead2("%s = $%4.4x", variable->realName, variable->absoluteAddress);
197 if ( variable->printable ) {
198 char * string = malloc( variable->size + 1 );
199 memset( string, 0, variable->size + 1 );
200 memcpy( string, variable->valueBuffer, variable->size );
201 outhead2("%scopy: .byte %s", variable->realName, escape_newlines( string ) );
202 } else {
203 out1("%scopy: .byte ", variable->realName);
204 int i=0;
205 for (i=0; i<(variable->size-1); ++i ) {
206 out1("%d,", variable->valueBuffer[i]);
207 }
208 outline1("%d", variable->valueBuffer[(variable->size-1)]);
209 }
210 }
211 }
212 }
213 break;
214 case VT_TILEMAP:
215 case VT_TARRAY: {
216 if ( variable->bankAssigned != -1 ) {
217 outhead4("; relocated on bank %d (at %4.4x) for %d bytes (uncompressed: %d)", variable->bankAssigned, variable->absoluteAddress, variable->size, variable->uncompressedSize );
218 if ( variable->type == VT_TARRAY ) {
219 if (VT_BITWIDTH( variable->arrayType ) == 0 ) {
221 }
222 // force +1 byte if size is odd
223 outhead2("%s: .res %d, $00", variable->realName, (VT_BITWIDTH( variable->arrayType )>>3) );
224 } else {
225 if (VT_BITWIDTH( variable->type ) == 0 ) {
226 CRITICAL_DATATYPE_UNSUPPORTED( "BANKED", DATATYPE_AS_STRING[ variable->type ] );
227 }
228 // force +1 byte if size is odd
229 outhead2("%s: .res %d, $00", variable->realName, (VT_BITWIDTH( variable->type )>>3) );
230 }
231 } else {
232
233 if ( ! variable->memoryArea && variable->valueBuffer ) {
234 out1("%s: .byte ", variable->realName);
235 int i=0;
236 for (i=0; i<(variable->size-1); ++i ) {
237 out1("%d,", variable->valueBuffer[i]);
238 }
239 outline1("%d", variable->valueBuffer[(variable->size-1)]);
240 } else if ( variable->memoryArea && ! variable->value ) {
241 // outhead2("%s = $%4.4x", variable->realName, variable->absoluteAddress);
242 } else {
243 if ( variable->value ) {
244
245 switch( VT_BITWIDTH( variable->arrayType ) ) {
246 case 32: {
247 out1("%s: .byte ", variable->realName );
248 for( int i=0; i<(variable->size/4)-1; ++i ) {
249 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 ) );
250 }
251 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 ) );
252 outline0("");
253 break;
254 }
255 case 16: {
256 out1("%s: .byte ", variable->realName );
257 for( int i=0; i<(variable->size/2)-1; ++i ) {
258 out2("$%2.2x, $%2.2x,", (unsigned int)( variable->value & 0xff ), (unsigned int)( ( variable->value >> 8 ) & 0xff ) );
259 }
260 out2("$%2.2x, $%2.2x", (unsigned int)( variable->value & 0xff ), (unsigned int)( ( variable->value >> 8 ) & 0xff ) );
261 outline0("");
262 break;
263 }
264 case 8:
265 outhead3("%s: .res %d, $%2.2x", variable->realName, variable->size, (unsigned char)(variable->value&0xff) );
266 break;
267 case 1:
268 outhead3("%s: .res %d, $%2.2x", variable->realName, variable->size, (unsigned char)(variable->value?0xff:0x00));
269 break;
270 }
271
272 } else {
273 outhead2("%s: .res %d,0", variable->realName, variable->size);
274 }
275 }
276 }
277
278 break;
279 }
280 }
281
282 if( variable->type == VT_IMAGES ) {
283 if ( variable->strips ) {
284 vars_emit_strips( _environment, variable->realName, variable->strips );
285 }
286 }
287
288
289 }
290 variable = variable->next;
291 }
292
293}
294
295static void variable_cleanup_memory_mapped( Environment * _environment, Variable * _variable ) {
296
297 outhead2("; %s (%4.4x)", _variable->realName, _variable->absoluteAddress );
298 outhead1("%s:", _variable->realName );
299
300 switch( _variable->type ) {
301 case VT_CHAR:
302 case VT_BYTE:
303 case VT_SBYTE:
304 case VT_COLOR:
305 case VT_THREAD:
306 vars_emit_byte( _environment, NULL, _variable->initialValue);
307 break;
308 case VT_DOJOKA:
309 outline0(" .res 4" );
310 break;
311 case VT_IMAGEREF:
312 outline0(" .res 14" );
313 break;
314 case VT_PATH:
315 outline0(" .res 16" );
316 break;
317 case VT_VECTOR2:
318 outline0(" .res 4" );
319 break;
320 case VT_WORD:
321 case VT_SWORD:
322 case VT_POSITION:
323 case VT_ADDRESS:
324 vars_emit_word( _environment, NULL, _variable->initialValue);
325 break;
326 case VT_DWORD:
327 case VT_SDWORD:
328 vars_emit_dword( _environment, NULL, _variable->initialValue);
329 break;
330 case VT_NUMBER:
331 vars_emit_number( _environment, NULL, _variable->initialValue);
332 break;
333 case VT_FLOAT: {
334 int bytes = VT_FLOAT_BITWIDTH( _variable->precision ) >> 3;
335 int * data = malloc( bytes * sizeof( int ) );
336 switch( _variable->precision ) {
337 case FT_FAST:
338 cpu_float_fast_from_double_to_int_array( _environment, _variable->valueFloating, data );
339 break;
340 case FT_SINGLE:
341 cpu_float_single_from_double_to_int_array( _environment, _variable->valueFloating, data );
342 break;
343 }
344 for( int i=0; i<bytes; ++i ) {
345 outline1(" .byte $%2.2x", (unsigned char)( ( data[i] ) & 0xff ) );
346 }
347 break;
348 }
349 case VT_STRING:
350 outhead2("%s = cstring%d", _variable->realName, _variable->valueString->id );
351 break;
352 case VT_DSTRING:
353 case VT_MSPRITE:
354 case VT_SPRITE:
355 case VT_TILE:
356 case VT_TILESET:
357 outline0(" .byte 0" );
358 break;
359 case VT_TILES:
360 outline0(" .byte 0, 0, 0, 0" );
361 break;
362 case VT_BLIT:
363 break;
364 case VT_IMAGE:
365 case VT_IMAGES:
366 case VT_SEQUENCE:
367 case VT_MUSIC:
368 case VT_BUFFER:
369 case VT_TYPE:
370 if ( _variable->bankAssigned != -1 ) {
371 outhead2("; relocated on bank %d (at %4.4x)", _variable->bankAssigned, _variable->absoluteAddress );
372 outhead1("%s: .byte $0", _variable->realName );
373 } else {
374 if ( _variable->valueBuffer ) {
375 if ( _variable->printable ) {
376 char * string = malloc( _variable->size + 1 );
377 memset( string, 0, _variable->size + 1 );
378 memcpy( string, _variable->valueBuffer, _variable->size );
379 outline1(" .byte %s", escape_newlines( string ) );
380 } else {
381 out0(" .byte ");
382 int i=0;
383 for (i=0; i<(_variable->size-1); ++i ) {
384 out1("%d,", _variable->valueBuffer[i]);
385 }
386 outline1("%d", _variable->valueBuffer[(_variable->size-1)]);
387 }
388 } else {
389 outline1(" .res %d,0", _variable->size);
390 }
391 }
392 break;
393 case VT_TILEMAP:
394 case VT_TARRAY: {
395 if ( _variable->bankAssigned != -1 ) {
396 outhead4("; relocated on bank %d (at %4.4x) for %d bytes (uncompressed: %d)", _variable->bankAssigned, _variable->absoluteAddress, _variable->size, _variable->uncompressedSize );
397 if ( _variable->type == VT_TARRAY ) {
398 if (VT_BITWIDTH( _variable->arrayType ) == 0 ) {
400 }
401 // force +1 byte if size is odd
402 outhead2("%s: .res %d, $00", _variable->realName, (VT_BITWIDTH( _variable->arrayType )>>3) );
403 } else {
404 if (VT_BITWIDTH( _variable->type ) == 0 ) {
405 CRITICAL_DATATYPE_UNSUPPORTED( "BANKED", DATATYPE_AS_STRING[ _variable->type ] );
406 }
407 // force +1 byte if size is odd
408 outhead2("%s: .res %d, $00", _variable->realName, (VT_BITWIDTH( _variable->type )>>3) );
409 }
410 } else {
411
412 if ( _variable->valueBuffer ) {
413 out0(" .byte ");
414 int i=0;
415 for (i=0; i<(_variable->size-1); ++i ) {
416 out1("%d,", _variable->valueBuffer[i]);
417 }
418 outline1("%d", _variable->valueBuffer[(_variable->size-1)]);
419 } else {
420 if ( _variable->value ) {
421 outhead2(" .res %d, $%2.2x", _variable->size, (unsigned char)(_variable->value&0xff));
422 } else {
423 outline1(" .res %d,0", _variable->size);
424 }
425 }
426 }
427
428 if( _variable->type == VT_IMAGES ) {
429 if ( _variable->strips ) {
430 vars_emit_strips( _environment, _variable->realName, _variable->strips );
431 }
432 }
433
434
435 break;
436 }
437 }
438
439}
440
441static void variable_cleanup_entry_bit( Environment * _environment, Variable * _first ) {
442
443 Variable * variable = _first;
444
445 int bitCount = 0;
446
447 while( variable ) {
448
449 if ( ( !variable->assigned || ( variable->assigned && !variable->temporary ) ) && !variable->imported && !variable->memoryArea ) {
450
451 if ( variable->memoryArea && _environment->debuggerLabelsFile ) {
452 fprintf( _environment->debuggerLabelsFile, "%4.4x %s\r\n", variable->absoluteAddress, variable->realName );
453 }
454
455 switch( variable->type ) {
456 case VT_BIT:
457 if ( variable->memoryArea ) {
458 // outhead2("%s = $%4.4x", variable->realName, variable->absoluteAddress);
459 } else {
460 outhead1("%s:", variable->realName);
461 }
462 ++bitCount;
463 if ( bitCount == 8 ) {
464 outline0(" .res 1,0");
465 }
466 break;
467 }
468
469 }
470
471 variable = variable->next;
472
473 }
474
475 if ( bitCount > 0 ) {
476 outline0(" .res 1,0");
477 }
478
479}
480
490void variable_cleanup( Environment * _environment ) {
491 int i=0;
492
493 vars_emit_constants( _environment );
494
495 if ( _environment->dataSegment ) {
496 outhead1("DATAFIRSTSEGMENT = %s", _environment->dataSegment->realName );
497 if ( _environment->readDataUsed && _environment->restoreDynamic ) {
498 outhead0("DATASEGMENTNUMERIC:" );
499 DataSegment * actual = _environment->dataSegment;
500 while( actual ) {
501 if ( actual->isNumeric ) {
502 outline2( ".word $%4.4x, %s", actual->lineNumber, actual->realName );
503 }
504 actual = actual->next;
505 }
506 outline0( ".word $ffff, DATAPTRE" );
507 }
508 }
509
510 if ( _environment->offsetting ) {
511 Offsetting * actual = _environment->offsetting;
512 while( actual ) {
513 out1("OFFSETS%4.4x: .word ", actual->size );
514 for( i=0; i<actual->count; ++i ) {
515 out1("$%4.4x", i * actual->size );
516 if ( i < ( actual->count - 1 ) ) {
517 out0(",");
518 } else {
519 outline0("");
520 }
521 }
522 if ( actual->variables ) {
523 OffsettingVariable * actualVariable = actual->variables;
524 while( actualVariable ) {
525 if ( actualVariable->sequence ) {
526 outhead1("%soffsetsequence:", actualVariable->variable->realName );
527 } else {
528 outhead1("%soffsetframe:", actualVariable->variable->realName );
529 }
530 actualVariable = actualVariable->next;
531 }
532 outhead1("fs%4.4xoffsetsequence:", actual->size );
533 outhead1("fs%4.4xsoffsetframe:", actual->size );
534 outline1("LDA #<OFFSETS%4.4x", actual->size );
535 outline0("STA MATHPTR1" );
536 outline1("LDA #>OFFSETS%4.4x", actual->size );
537 outline0("STA MATHPTR1+1" );
538 outline0("CLC" );
539 outline0("LDA MATHPTR0" );
540 outline0("ASL" );
541 outline0("TAY" );
542 outline0("LDA TMPPTR" );
543 outline0("ADC (MATHPTR1), Y" );
544 outline0("STA TMPPTR" );
545 outline0("INY" );
546 outline0("LDA TMPPTR+1" );
547 outline0("ADC (MATHPTR1), Y" );
548 outline0("STA TMPPTR+1" );
549 outline0("RTS" );
550 }
551 actual = actual->next;
552 }
553
554 int values[MAX_TEMPORARY_STORAGE];
555 char * address[MAX_TEMPORARY_STORAGE];
556
557 actual = _environment->offsetting;
558 int count = 0;
559 while( actual ) {
560 values[count] = actual->size;
561 address[count] = malloc( MAX_TEMPORARY_STORAGE );
562 sprintf( address[count], "fs%4.4xsoffsetframe", actual->size );
563 actual = actual->next;
564 ++count;
565 }
566
567 cpu_address_table_build( _environment, "EXECOFFSETS", values, address, count );
568
569 cpu_address_table_lookup( _environment, "EXECOFFSETS", count );
570
571 }
572
573 generate_cgoto_address_table( _environment );
574
575 banks_generate( _environment );
576
577 for(i=0; i<BANK_TYPE_COUNT; ++i) {
578 Bank * actual = _environment->banks[i];
579 while( actual ) {
580 if ( actual->type == BT_VARIABLES ) {
581 // cfgline3("# BANK %s %s AT $%4.4x", BANK_TYPE_AS_STRING[actual->type], actual->name, actual->address);
582 // cfgline2("%s: load = MAIN, type = ro, optional = yes, start = $%4.4x;", actual->name, actual->address);
583 // outhead1(".segment \"%s\"", actual->name);
584 Variable * variable = _environment->variables;
585
586 variable_cleanup_entry( _environment, variable );
587 variable_cleanup_entry_bit( _environment, variable );
588
589 } else if ( actual->type == BT_TEMPORARY ) {
590 // cfgline3("# BANK %s %s AT $%4.4x", BANK_TYPE_AS_STRING[actual->type], actual->name, actual->address);
591 // cfgline2("%s: load = MAIN, type = ro, optional = yes, start = $%4.4x;", actual->name, actual->address);
592 // outhead1(".segment \"%s\"", actual->name);
593 if ( _environment->bitmaskNeeded ) {
594 outhead0("BITMASK: .byte $01,$02,$04,$08,$10,$20,$40,$80");
595 outhead0("BITMASKN: .byte $fe,$fd,$fb,$f7,$ef,$df,$bf,$7f");
596 }
597 if ( _environment->deployed.dstring ) {
598 outhead1("max_free_string = $%4.4x", _environment->dstring.space == 0 ? DSTRING_DEFAULT_SPACE : _environment->dstring.space );
599 }
600
601 for( int j=0; j< (_environment->currentProcedure+1); ++j ) {
602 Variable * variable = _environment->tempVariables[j];
603 variable_cleanup_entry( _environment, variable );
604 variable_cleanup_entry_bit( _environment, variable );
605 }
606
607 Variable * variable = _environment->tempResidentVariables;
608
609 variable_cleanup_entry( _environment, variable );
610 variable_cleanup_entry_bit( _environment, variable );
611
612 // } else if ( actual->type == BT_STRINGS ) {
613 // cfgline3("# BANK %s %s AT $%4.4x", BANK_TYPE_AS_STRING[actual->type], actual->name, actual->address);
614 // cfgline2("%s: load = MAIN, type = ro, optional = yes, start = $%4.4x;", actual->name, actual->address);
615 } else {
616
617 }
618 actual = actual->next;
619 }
620 }
621
622 if ( _environment->descriptors ) {
623 outhead0("UDCCHAR:" );
624 int i=0,j=0;
625 for(i=_environment->descriptors->first;i<(_environment->descriptors->first+_environment->descriptors->count);++i) {
626 out0(".byte " );
627 for(j=0;j<7;++j) {
628 out1("$%2.2x,", ((unsigned char)_environment->descriptors->data[i].data[j]) );
629 }
630 outline1("$%2.2x", ((unsigned char)_environment->descriptors->data[i].data[j]) );
631 }
632 outhead0("TEDUDCCHAR:" );
633 char startAddress[MAX_TEMPORARY_STORAGE]; sprintf( startAddress, "$E800+$%4.4x", ( _environment->descriptors->first * 8) );
634 cpu_mem_move_direct_size( _environment, "UDCCHAR", startAddress, _environment->descriptors->count*8 );
635 // outline0("LDA $FF12" );
636 // outline0("AND #$FB" );
637 // outline0("STA $FF12" );
638 // outline0("LDA $FF13" );
639 // outline0("AND #$03" );
640 // outline0("ORA #$18" );
641 outline0("LDA #$F8" );
642 outline0("STA $FF13" );
643 // outline0("LDA $FF07" );
644 // outline0("ORA #$80" );
645 // outline0("STA $FF07" );
646 outline0("RTS" );
647 } else {
648 outhead0("UDCCHAR = $C000");
649 outhead0("TEDUDCCHAR:" );
650 outline0("RTS" );
651 }
652
653 if ( _environment->memoryAreas ) {
654 MemoryArea * memoryArea = _environment->memoryAreas;
655 while( memoryArea ) {
656 // if ( memoryArea->type == MAT_RAM ) {
657 // cfgline3("MA%3.3x: load = RAM%3.3x, type = overwrite, optional = yes, start = $%4.4x;", memoryArea->id, memoryArea->id, memoryArea->start);
658 // } else {
659 // cfgline2("MA%3.3x: load = MAIN, type = overwrite, optional = yes, start = $%4.4x;", memoryArea->id, memoryArea->start);
660 // }
661 outhead1(".segment \"MA%3.3x\"", memoryArea->id );
662 for( i=memoryArea->start; i<memoryArea->end; ++i ) {
663 Variable * variable = _environment->variables;
664 while( variable ) {
665 if ( !variable->assigned && variable->memoryArea == memoryArea && variable->absoluteAddress == i ) {
666 variable_cleanup_memory_mapped( _environment, variable );
667 variable->staticalInit = ( memoryArea->type == MAT_RAM ? 0 : 1 );
668 break;
669 }
670 variable = variable->next;
671 }
672 for( int j=0; j< (_environment->currentProcedure+1); ++j ) {
673 Variable * variable = _environment->tempVariables[j];
674 while( variable ) {
675 if ( !variable->assigned && variable->memoryArea == memoryArea && variable->absoluteAddress == i ) {
676 variable_cleanup_memory_mapped( _environment, variable );
677 variable->staticalInit = ( memoryArea->type == MAT_RAM ? 0 : 1 );
678 break;
679 }
680 variable = variable->next;
681 }
682 }
683 variable = _environment->tempResidentVariables;
684 while( variable ) {
685 if ( !variable->assigned && variable->memoryArea == memoryArea && variable->absoluteAddress == i ) {
686 variable_cleanup_memory_mapped( _environment, variable );
687 variable->staticalInit = ( memoryArea->type == MAT_RAM ? 0 : 1 );
688 break;
689 }
690 variable = variable->next;
691 }
692 }
693 memoryArea = memoryArea->next;
694 }
695
696 }
697
698 for( i=0; i<MAX_RESIDENT_SHAREDS; ++i ) {
699 if ( _environment->maxExpansionBankSize[i] ) {
700 outhead1("BANKWINDOWID%2.2x: .byte $FF, $FF", i );
701 outhead2("BANKWINDOW%2.2x: .res %d,0", i, _environment->maxExpansionBankSize[i]);
702 }
703 }
704
705 deploy_inplace_preferred( tedstartup, src_hw_ted_startup_asm );
706
707 outhead0(".segment \"CODE\"" );
708
709 variable_on_memory_init( _environment, 0 );
710
711 DataSegment * dataSegment = _environment->dataSegment;
712 while( dataSegment ) {
713 int i=0;
714 if ( dataSegment->data ) {
715 out1("%s: .BYTE ", dataSegment->realName );
716 } else {
717 outhead1("%s: ", dataSegment->realName );
718 }
719 DataDataSegment * dataDataSegment = dataSegment->data;
720 while( dataDataSegment ) {
721 if ( dataSegment->type ) {
722 if ( dataDataSegment->type == VT_STRING || dataDataSegment->type == VT_DSTRING ) {
723 out1("$%2.2x,", (unsigned char)(dataDataSegment->size) );
724 out1("\"%s\"", dataDataSegment->data );
725 } else {
726 for( i=0; i<(dataDataSegment->size-1); ++i ) {
727 out1("$%2.2x,", (unsigned char)(dataDataSegment->data[i]&0xff) );
728 }
729 out1("$%2.2x", (unsigned char)(dataDataSegment->data[i]&0xff) );
730 }
731 } else {
732 if ( dataDataSegment->type == VT_STRING || dataDataSegment->type == VT_DSTRING ) {
733 out1("$%2.2x,", (unsigned char)(dataDataSegment->type) );
734 out1("$%2.2x,", (unsigned char)(dataDataSegment->size) );
735 out1("\"%s\"", dataDataSegment->data );
736 } else {
737 out1("$%2.2x,", (unsigned char)(dataDataSegment->type) );
738 for( i=0; i<(dataDataSegment->size-1); ++i ) {
739 out1("$%2.2x,", (unsigned char)(dataDataSegment->data[i]&0xff) );
740 }
741 out1("$%2.2x", (unsigned char)(dataDataSegment->data[i]&0xff) );
742 }
743 }
744 dataDataSegment = dataDataSegment->next;
745 if ( dataDataSegment ) {
746 out0(",");
747 }
748 }
749 outline0("");
750 dataSegment = dataSegment->next;
751 }
752
753 if ( _environment->dataNeeded || _environment->dataSegment || _environment->deployed.read_data_unsafe ) {
754 outhead0("DATAPTRE:");
755 }
756
757 StaticString * staticStrings = _environment->strings;
758 while( staticStrings ) {
759 outhead3("cstring%d: .byte %d, %s", staticStrings->id, (int)strlen(staticStrings->value), escape_newlines( staticStrings->value ) );
760 staticStrings = staticStrings->next;
761 }
762
763
764}
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_float_fast_from_double_to_int_array(Environment *_environment, double _value, int _result[])
Definition 6309.c:6743
void cpu_float_single_from_double_to_int_array(Environment *_environment, double _value, int _result[])
Definition 6309.c:6747
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
char * escape_newlines(char *_string)
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.
#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
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 read_data_unsafe
Definition ugbc.h:1923
int dstring
Definition ugbc.h:1789
Variable * tempResidentVariables
Definition ugbc.h:2595
Offsetting * offsetting
Definition ugbc.h:2937
Bank * banks[BANK_TYPE_COUNT]
Definition ugbc.h:2514
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
DString dstring
Definition ugbc.h:2405
Variable * variables
Definition ugbc.h:2616
int dataNeeded
Definition ugbc.h:2557
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 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
double valueFloating
Definition ugbc.h:1046
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
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
#define MAX_RESIDENT_SHAREDS
Definition ugbc.h:572
struct _Variable Variable
Structure of a single variable.
#define outline2(s, a, b)
Definition ugbc.h:4254
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 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
@ FT_FAST
Definition ugbc.h:854
@ FT_SINGLE
Definition ugbc.h:855
@ 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]