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_multibyte( Environment * _environment, Variable * _first, int _bank_read_write ) {
45
46 Variable * variable = _first;
47
48 outline0("ALIGN 2");
49
50 while( variable ) {
51
52 if (
53 variable->bankReadOrWrite == _bank_read_write &&
54 ( !variable->assigned || ( variable->assigned && !variable->temporary ) ) && !variable->imported ) {
55
56 if ( variable->memoryArea && _environment->debuggerLabelsFile ) {
57 fprintf( _environment->debuggerLabelsFile, "%4.4x %s\r\n", variable->absoluteAddress, variable->realName );
58 }
59
60 switch( variable->type ) {
61 case VT_WORD:
62 case VT_SWORD:
63 case VT_POSITION:
64 case VT_ADDRESS:
65 if ( variable->memoryArea ) {
66 outhead2("%s equ $%4.4x", variable->realName, variable->absoluteAddress);
67 } else {
68 vars_emit_word( _environment, variable->realName, variable->initialValue );
69 }
70 break;
71 case VT_DWORD:
72 case VT_SDWORD:
73 if ( variable->memoryArea ) {
74 outhead2("%s equ $%4.4x", variable->realName, variable->absoluteAddress);
75 } else {
76 vars_emit_dword( _environment, variable->realName, variable->initialValue );
77 }
78 break;
79 case VT_NUMBER:
80 if ( variable->memoryArea ) {
81 outhead2("%s equ $%4.4x", variable->realName, variable->absoluteAddress);
82 } else {
83 vars_emit_number( _environment, variable->realName, variable->initialValue );
84 }
85 break;
86 case VT_FLOAT:
87 if ( variable->memoryArea ) {
88 outhead2("%s equ $%4.4x", variable->realName, variable->absoluteAddress);
89 } else {
90 // force 6 bytes to help even alignment (5->6 bytes)
91 outhead1("%s rzb 6", variable->realName);
92 }
93 break;
94 case VT_TILES:
95 if ( variable->memoryArea ) {
96 outhead2("%s equ $%4.4x", variable->realName, variable->absoluteAddress);
97 } else {
98 outhead1("%s rzb 4", variable->realName);
99 }
100 break;
101 case VT_BLIT:
102 break;
103 case VT_MUSIC:
104 case VT_BUFFER:
105 case VT_TYPE:
106 if ( variable->bankAssigned != -1 ) {
107 outhead4("; relocated on bank %d (at %4.4x) for %d bytes (uncompressed: %d)", variable->bankAssigned, variable->absoluteAddress, variable->size, variable->uncompressedSize );
108 // force 2 bytes to help even alignment (1->2 bytes)
109 outhead1("%s fcb 0,0", variable->realName );
110 } else {
111 if ( ! variable->absoluteAddress ) {
112 if ( variable->valueBuffer ) {
113 if ( variable->printable ) {
114 char * string = malloc( variable->size + 1 );
115 memset( string, 0, variable->size + 1 );
116 memcpy( string, variable->valueBuffer, variable->size );
117 // force +1 byte if size is odd
118 if ( variable->size & 0x01 ) {
119 outhead2("%s fcc %s,0", variable->realName, escape_newlines( string ) );
120 } else {
121 outhead2("%s fcc %s", variable->realName, escape_newlines( string ) );
122 }
123 } else {
124 out1("%s fcb ", variable->realName);
125 int i=0;
126 for (i=0; i<(variable->size-1); ++i ) {
127 if ( ( ( i + 1 ) % 16 ) == 0 ) {
128 outline1("$%2.2x", (unsigned char)variable->valueBuffer[i]);
129 out0(" fcb ");
130 } else {
131 out1("$%2.2x,", (unsigned char)variable->valueBuffer[i]);
132 }
133 }
134 // force +1 byte if size is odd
135 if ( variable->size & 0x01 ) {
136 outhead1("$%2.2x, $0", variable->valueBuffer[(variable->size-1)]);
137 } else {
138 outhead1("$%2.2x", variable->valueBuffer[(variable->size-1)]);
139 }
140 }
141 } else {
142 // force +1 byte if size is odd
143 if ( variable->size & 0x01 ) {
144 outhead2("%s rzb %d", variable->realName, variable->size+1);
145 } else {
146 outhead2("%s rzb %d", variable->realName, variable->size);
147 }
148 }
149 } else {
150 outhead2("%s equ $%4.4x", variable->realName, variable->absoluteAddress);
151 if ( variable->valueBuffer ) {
152 if ( variable->printable ) {
153 char * string = malloc( variable->size + 1 );
154 memset( string, 0, variable->size + 1 );
155 memcpy( string, variable->valueBuffer, variable->size );
156 // force +1 byte if size is odd
157 if ( variable->size & 0x01 ) {
158 outhead2("%s fcc %s,0", variable->realName, escape_newlines( string ) );
159 } else {
160 outhead2("%s fcc %s", variable->realName, escape_newlines( string ) );
161 }
162 } else {
163 out1("%scopy fcb ", variable->realName);
164 int i=0;
165 for (i=0; i<(variable->size-1); ++i ) {
166 out1("$%2.2x,", variable->valueBuffer[i]);
167 }
168 // force +1 byte if size is odd
169 if ( variable->size & 0x01 ) {
170 outhead1("$%2.2x,$0", variable->valueBuffer[(variable->size-1)]);
171 } else {
172 outhead1("$%2.2x", variable->valueBuffer[(variable->size-1)]);
173 }
174 }
175 }
176 }
177 }
178 break;
179 case VT_IMAGEREF:
180 if ( variable->memoryArea ) {
181 outhead2("%s equ $%4.4x", variable->realName, variable->absoluteAddress);
182 } else {
183 outhead1("%s rzb 14", variable->realName);
184 }
185 break;
186 case VT_PATH:
187 if ( variable->memoryArea ) {
188 outhead2("%s equ $%4.4x", variable->realName, variable->absoluteAddress);
189 } else {
190 outhead1("%s rzb 16", variable->realName);
191 }
192 break;
193 case VT_VECTOR2:
194 if ( variable->memoryArea ) {
195 outhead2("%s equ $%4.4x", variable->realName, variable->absoluteAddress);
196 } else {
197 outhead1("%s rzb 4", variable->realName);
198 }
199 break;
200 case VT_TILEMAP:
201 case VT_TARRAY: {
202 if ( variable->bankAssigned == -1 ) {
203
204 if ( variable->valueBuffer ) {
205 out1("%s fcb ", variable->realName);
206 int i=0;
207 for (i=0; i<(variable->size-1); ++i ) {
208 out1("$%2.2x,", variable->valueBuffer[i]);
209 }
210 // force +1 byte if size is odd
211 if ( variable->size & 0x01 ) {
212 outhead1("$%2.2x,$0", variable->valueBuffer[(variable->size-1)]);
213 } else {
214 outhead1("$%2.2x", variable->valueBuffer[(variable->size-1)]);
215 }
216 } else if ( variable->value ) {
217
218 switch( VT_BITWIDTH( variable->arrayType ) ) {
219 case 32: {
220 out1("%s fcb ", variable->realName );
221 for( int i=0; i<(variable->size/4)-1; ++i ) {
222 out4("$%2.2x, $%2.2x, $%2.2x, $%2.2x, ", (unsigned int)( ( variable->value >> 24 ) & 0xff ), (unsigned int)( ( variable->value >> 16 ) & 0xff ), (unsigned int)( ( variable->value >> 8 ) & 0xff ), (unsigned int)( variable->value & 0xff ) );
223 }
224 out4("$%2.2x, $%2.2x, $%2.2x, $%2.2x", (unsigned int)( ( variable->value >> 24 ) & 0xff ), (unsigned int)( ( variable->value >> 16 ) & 0xff ), (unsigned int)( ( variable->value >> 8 ) & 0xff ), (unsigned int)( variable->value & 0xff ) );
225 outline0("");
226 break;
227 }
228 case 16: {
229 out1("%s fcb ", variable->realName );
230 for( int i=0; i<(variable->size/2)-1; ++i ) {
231 out2("$%2.2x, $%2.2x,", (unsigned int)( ( variable->value >> 8 ) & 0xff ), (unsigned int)( variable->value & 0xff ) );
232 }
233 out2("$%2.2x, $%2.2x", (unsigned int)( ( variable->value >> 8 ) & 0xff ), (unsigned int)( variable->value & 0xff ) );
234 outline0("");
235 break;
236 }
237 case 8:
238 outhead3("%s rzb %d, $%2.2x", variable->realName, variable->size, (unsigned char)(variable->value&0xff) );
239 break;
240 case 1:
241 outhead3("%s rzb %d, $%2.2x", variable->realName, variable->size, (unsigned char)(variable->value?0xff:0x00));
242 break;
243 }
244
245 } else {
246 outhead4("; relocated on bank %d (at %4.4x) for %d bytes (uncompressed: %d)", variable->bankAssigned, variable->absoluteAddress, variable->size, variable->uncompressedSize );
247 // force +1 byte if size is odd
248 if ( variable->size & 0x01 ) {
249 outhead2("%s rzb %d", variable->realName, variable->size+1);
250 } else {
251 outhead2("%s rzb %d", variable->realName, variable->size);
252 }
253 }
254
255 } else {
256 outhead4("; relocated on bank %d (at %4.4x) for %d bytes (uncompressed: %d)", variable->bankAssigned, variable->absoluteAddress, variable->size, variable->uncompressedSize );
257 if ( variable->type == VT_TARRAY ) {
258 // if (VT_BITWIDTH( variable->arrayType ) == 0 && variable->arrayType != VT_TYPE ) {
259 // CRITICAL_DATATYPE_UNSUPPORTED( "BANKED", DATATYPE_AS_STRING[ variable->arrayType ] );
260 // }
261 // force +1 byte if size is odd
262 if ( variable->arrayType == VT_TYPE ) {
263 int size = 1;
264 Field * field = variable->typeType->first;
265 while( field ) {
266 if ( size < ( VT_BITWIDTH( field->type ) >> 3 ) ) {
267 size = VT_BITWIDTH( field->type ) >> 3;
268 }
269 field = field->next;
270 }
271 if ( size & 0x01 ) {
272 outhead2("%s rzb %d, $00", variable->realName, size+1 );
273 } else {
274 outhead2("%s rzb %d, $00", variable->realName, size );
275 }
276 } else if ( variable->arrayType == VT_PATH ) {
277 outhead1("%s rzb 16, $00", variable->realName );
278 } else {
279 if ( variable->size & 0x01 ) {
280 outhead2("%s rzb %d, $00", variable->realName, (VT_BITWIDTH( variable->arrayType )>>3)+1 );
281 } else {
282 outhead2("%s rzb %d, $00", variable->realName, (VT_BITWIDTH( variable->arrayType )>>3) );
283 }
284 }
285 } else {
286 if (VT_BITWIDTH( variable->type ) == 0 ) {
287 CRITICAL_DATATYPE_UNSUPPORTED( "BANKED", DATATYPE_AS_STRING[ variable->type ] );
288 }
289 // force +1 byte if size is odd
290 if ( variable->size & 0x01 ) {
291 outhead2("%s rzb %d, $00", variable->realName, (VT_BITWIDTH( variable->type )>>3)+1 );
292 } else {
293 outhead2("%s rzb %d, $00", variable->realName, (VT_BITWIDTH( variable->type )>>3) );
294 }
295 }
296 }
297
298 break;
299 }
300 }
301 }
302
303 variable = variable->next;
304
305 }
306
307
308}
309
310static void variable_cleanup_entry_byte( Environment * _environment, Variable * _first, int _bank_read_write ) {
311
312 Variable * variable = _first;
313
314 while( variable ) {
315
316 if ( variable->bankReadOrWrite == _bank_read_write &&
317 ( !variable->assigned || ( variable->assigned && !variable->temporary ) ) && !variable->imported ) {
318
319 if ( variable->memoryArea && _environment->debuggerLabelsFile ) {
320 fprintf( _environment->debuggerLabelsFile, "%4.4x %s\r\n", variable->absoluteAddress, variable->realName );
321 }
322
323 switch( variable->type ) {
324 case VT_CHAR:
325 case VT_BYTE:
326 case VT_SBYTE:
327 case VT_COLOR:
328 case VT_THREAD:
329 if ( variable->memoryArea ) {
330 outhead2("%s equ $%4.4x", variable->realName, variable->absoluteAddress);
331 } else {
332 vars_emit_byte( _environment, variable->realName, variable->initialValue );
333 }
334 break;
335 case VT_DOJOKA:
336 if ( variable->memoryArea ) {
337 outhead2("%s equ $%4.4x", variable->realName, variable->absoluteAddress);
338 } else {
339 outhead1("%s rzb 4", variable->realName);
340 }
341 break;
342 case VT_STRING:
343 if ( ! variable->valueString ) {
344 printf("%s", variable->realName);
345 exit(EXIT_FAILURE);
346 }
347 if ( variable->memoryArea ) {
348 outhead2("%s equ $%4.4x", variable->realName, variable->absoluteAddress);
349 } else {
350 outhead2("%s equ cstring%d", variable->realName, variable->valueString->id );
351 }
352 break;
353 case VT_DSTRING:
354 if ( variable->memoryArea ) {
355 outhead2("%s equ $%4.4x", variable->realName, variable->absoluteAddress);
356 } else {
357 outhead1("%s rzb 1", variable->realName);
358 }
359 break;
360 case VT_SPRITE:
361 if ( variable->memoryArea ) {
362 outhead2("%s equ $%4.4x", variable->realName, variable->absoluteAddress);
363 } else {
364 outhead1("%s rzb 1", variable->realName);
365 }
366 break;
367 case VT_MSPRITE:
368 if ( variable->memoryArea ) {
369 outhead2("%s equ $%4.4x", variable->realName, variable->absoluteAddress);
370 } else {
371 outhead1("%s rzb 2", variable->realName);
372 }
373 break;
374 case VT_TILE:
375 if ( variable->memoryArea ) {
376 outhead2("%s equ $%4.4x", variable->realName, variable->absoluteAddress);
377 } else {
378 outhead1("%s rzb 1", variable->realName);
379 }
380 break;
381 case VT_TILESET:
382 if ( variable->memoryArea ) {
383 outhead2("%s equ $%4.4x", variable->realName, variable->absoluteAddress);
384 } else {
385 outhead1("%s rzb 1", variable->realName);
386 }
387 break;
388 }
389
390 }
391
392 variable = variable->next;
393
394 }
395
396}
397
398static void variable_cleanup_entry( Environment * _environment, Variable * _first, int _bank_read_write ) {
399
400 variable_cleanup_entry_multibyte( _environment, _first, _bank_read_write );
401 variable_cleanup_entry_byte( _environment, _first, _bank_read_write );
402
403}
404
405static void variable_cleanup_entry_image( Environment * _environment, Variable * _first ) {
406
407 Variable * variable = _first;
408
409 outline0("ALIGN 2");
410 while( variable ) {
411
412 if ( ( !variable->assigned || ( variable->assigned && !variable->temporary ) ) && !variable->imported ) {
413
414 if ( variable->memoryArea && _environment->debuggerLabelsFile ) {
415 fprintf( _environment->debuggerLabelsFile, "%4.4x %s\r\n", variable->absoluteAddress, variable->realName );
416 }
417
418 switch( variable->type ) {
419 case VT_IMAGE:
420 case VT_IMAGES:
421 case VT_SEQUENCE:
422 if ( variable->bankAssigned != -1 ) {
423 outhead4("; relocated on bank %d (at %4.4x) for %d bytes (uncompressed: %d)", variable->bankAssigned, variable->absoluteAddress, variable->size, variable->uncompressedSize );
424 // forced 2 bytes to even alignment
425 outhead1("%s fcb 2", variable->realName );
426 } else {
427 if ( ! variable->absoluteAddress ) {
428 if ( variable->valueBuffer ) {
429 if ( variable->printable ) {
430 char * string = malloc( variable->size + 1 );
431 memset( string, 0, variable->size + 1 );
432 memcpy( string, variable->valueBuffer, variable->size );
433 // forced +1 byte to even alignment
434 if ( variable->size & 0x01 ) {
435 outhead2("%s fcc %s,0", variable->realName, escape_newlines( string ) );
436 } else {
437 outhead2("%s fcc %s", variable->realName, escape_newlines( string ) );
438 }
439 } else {
440 out1("%s fcb ", variable->realName);
441 int i=0;
442 for (i=0; i<(variable->size-1); ++i ) {
443 if ( ( ( i + 1 ) % 16 ) == 0 ) {
444 outline1("$%2.2x", (unsigned char)variable->valueBuffer[i]);
445 out0(" fcb ");
446 } else {
447 out1("$%2.2x,", (unsigned char)variable->valueBuffer[i]);
448 }
449 }
450 // forced +1 byte to even alignment
451 if ( variable->size & 0x01 ) {
452 outhead1("$%2.2x, $0", variable->valueBuffer[(variable->size-1)]);
453 } else {
454 outhead1("$%2.2x", variable->valueBuffer[(variable->size-1)]);
455 }
456 }
457 } else {
458 // forced +1 byte to even alignment
459 if ( variable->size & 0x01 ) {
460 outhead2("%s rzb %d", variable->realName, variable->size+1);
461 } else {
462 outhead2("%s rzb %d", variable->realName, variable->size);
463 }
464 }
465 } else {
466 outhead2("%s equ $%4.4x", variable->realName, variable->absoluteAddress);
467 if ( variable->valueBuffer ) {
468 if ( variable->printable ) {
469 char * string = malloc( variable->size + 1 );
470 memset( string, 0, variable->size + 1 );
471 memcpy( string, variable->valueBuffer, variable->size );
472 // forced +1 byte to even alignment
473 if ( variable->size & 0x01 ) {
474 outhead2("%s fcc %s, 0", variable->realName, escape_newlines( string ) );
475 } else {
476 outhead2("%s fcc %s", variable->realName, escape_newlines( string ) );
477 }
478 } else {
479 out1("%scopy fcb ", variable->realName);
480 int i=0;
481 for (i=0; i<(variable->size-1); ++i ) {
482 out1("$%2.2x,", variable->valueBuffer[i]);
483 }
484 // forced +1 byte to even alignment
485 if ( variable->size & 0x01 ) {
486 outhead1("$%2.2x, $0", variable->valueBuffer[(variable->size-1)]);
487 } else {
488 outhead1("$%2.2x", variable->valueBuffer[(variable->size-1)]);
489 }
490 }
491 }
492 }
493 }
494 break;
495 }
496
497 if( variable->type == VT_IMAGES ) {
498 if ( variable->strips ) {
499 vars_emit_strips( _environment, variable->realName, variable->strips );
500 }
501 }
502
503 }
504
505 variable = variable->next;
506
507 }
508
509}
510
511static void variable_cleanup_entry_bit( Environment * _environment, Variable * _first, int _bank_read_write ) {
512
513 Variable * variable = _first;
514
515 int bitCount = 0;
516
517 while( variable ) {
518
519 if ( variable->bankReadOrWrite == _bank_read_write &&
520 ( !variable->assigned || ( variable->assigned && !variable->temporary ) ) && !variable->imported && !variable->memoryArea ) {
521
522 if ( variable->memoryArea && _environment->debuggerLabelsFile ) {
523 fprintf( _environment->debuggerLabelsFile, "%4.4x %s\r\n", variable->absoluteAddress, variable->realName );
524 }
525
526 switch( variable->type ) {
527 case VT_BIT:
528 if ( variable->memoryArea ) {
529 // outline2("%s = $%4.4x", variable->realName, variable->absoluteAddress);
530 } else {
531 outhead1("%s", variable->realName);
532 }
533 ++bitCount;
534 if ( bitCount == 8 ) {
535 outline0(" fcb 0");
536 }
537 break;
538 }
539
540 }
541
542 variable = variable->next;
543
544 }
545
546 if ( bitCount > 0 ) {
547 outline0(" fcb 0");
548 }
549
550}
551
561void variable_cleanup( Environment * _environment ) {
562 int i=0;
563
564 vars_emit_constants( _environment );
565
566 if ( _environment->dataSegment ) {
567 outhead1("DATAFIRSTSEGMENT EQU %s", _environment->dataSegment->realName );
568 if ( _environment->readDataUsed && _environment->restoreDynamic ) {
569 outhead0("DATASEGMENTNUMERIC" );
570 DataSegment * actual = _environment->dataSegment;
571 while( actual ) {
572 if ( actual->isNumeric ) {
573 outline2( "fdb $%4.4x, %s", actual->lineNumber, actual->realName );
574 }
575 actual = actual->next;
576 }
577 outline0( "fdb $ffff, DATAPTRE" );
578 }
579 }
580
581 if ( _environment->offsetting ) {
582 Offsetting * actual = _environment->offsetting;
583 while( actual ) {
584 outline0("ALIGN 2");
585 outhead1("OFFSETS%4.4x", actual->size );
586 out0(" fdb " );
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 if ( actual->count == 1 ) {
597 OffsettingVariable * actualVariable = actual->variables;
598 while( actualVariable ) {
599 if ( actualVariable->sequence ) {
600 outhead1("%soffsetsequence", actualVariable->variable->realName );
601 } else {
602 outhead1("%soffsetframe", actualVariable->variable->realName );
603 }
604 actualVariable = actualVariable->next;
605 }
606 outhead1("fs%4.4xoffsetsequence", actual->size );
607 outhead1("fs%4.4xoffsetframe", actual->size );
608 outline0("RTS");
609 } else {
610 OffsettingVariable * actualVariable = actual->variables;
611 while( actualVariable ) {
612 if ( actualVariable->sequence ) {
613 outhead1("%soffsetsequence", actualVariable->variable->realName );
614 } else {
615 outhead1("%soffsetframe", actualVariable->variable->realName );
616 }
617 actualVariable = actualVariable->next;
618 }
619 outhead1("fs%4.4xoffsetsequence", actual->size );
620 outhead1("fs%4.4xoffsetframe", actual->size );
621 outline1("LDX #OFFSETS%4.4x", actual->size );
622 outline0("LDA #0" );
623 outline0("ABX" );
624 outline0("ABX" );
625 outline0("LDD ,X" );
626 outline0("LEAY D, Y" );
627 outline0("RTS");
628 }
629 }
630 actual = actual->next;
631 }
632
633 int values[MAX_TEMPORARY_STORAGE];
634 char * address[MAX_TEMPORARY_STORAGE];
635
636 actual = _environment->offsetting;
637 int count = 0;
638 while( actual ) {
639 values[count] = actual->size;
640 address[count] = malloc( MAX_TEMPORARY_STORAGE );
641 sprintf( address[count], "fs%4.4xoffsetframe", actual->size );
642 actual = actual->next;
643 ++count;
644 }
645
646 cpu_address_table_build( _environment, "EXECOFFSETS", values, address, count );
647
648 cpu_address_table_lookup( _environment, "EXECOFFSETS", count );
649
650 }
651
652 for(i=0; i<BANK_TYPE_COUNT; ++i) {
653 Bank * actual = _environment->banks[i];
654 while( actual ) {
655 if ( actual->type == BT_VARIABLES ) {
656 // cfgline3("# BANK %s %s AT $%4.4x", BANK_TYPE_AS_STRING[actual->type], actual->name, actual->address);
657 // cfgline2("%s: load = MAIN, type = ro, optional = yes, start = $%4.4x;", actual->name, actual->address);
658 // outhead1(".segment \"%s\"", actual->name);
659 Variable * variable = _environment->variables;
660
661 variable_cleanup_entry( _environment, variable, 0 );
662 variable_cleanup_entry_bit( _environment, variable, 0 );
663
664 } else if ( actual->type == BT_TEMPORARY ) {
665 // cfgline3("# BANK %s %s AT $%4.4x", BANK_TYPE_AS_STRING[actual->type], actual->name, actual->address);
666 // cfgline2("%s: load = MAIN, type = ro, optional = yes, start = $%4.4x;", actual->name, actual->address);
667 // outhead1(".segment \"%s\"", actual->name);
668
669 for( int j=0; j< (_environment->currentProcedure+1); ++j ) {
670 Variable * variable = _environment->tempVariables[j];
671 variable_cleanup_entry( _environment, variable, 0 );
672 variable_cleanup_entry_bit( _environment, variable, 0 );
673 }
674
675 Variable * variable = _environment->tempResidentVariables;
676
677 variable_cleanup_entry( _environment, variable, 0 );
678 variable_cleanup_entry_bit( _environment, variable, 0 );
679
680 } else if ( actual->type == BT_STRINGS ) {
681 // cfgline3("# BANK %s %s AT $%4.4x", BANK_TYPE_AS_STRING[actual->type], actual->name, actual->address);
682 // cfgline2("%s: load = MAIN, type = ro, optional = yes, start = $%4.4x;", actual->name, actual->address);
683 } else {
684
685 }
686 actual = actual->next;
687 }
688
689 }
690
691 if ( _environment->descriptors ) {
692 outline0("ALIGN 2");
693 outhead0("UDCCHAR" );
694 int i=0,j=0;
695 for(i=0;i<_environment->descriptors->count;++i) {
696 outline1("; $%2.2x ", i);
697 out0(" fcb " );
698 for(j=0;j<7;++j) {
699 out1("$%2.2x,", ((unsigned char)_environment->descriptors->data[_environment->descriptors->first+i].data[j]) );
700 }
701 outline1("$%2.2x", ((unsigned char)_environment->descriptors->data[_environment->descriptors->first+i].data[j]) );
702 }
703 } else {
704 outhead0("UDCCHAR EQU $E000");
705 }
706
707 generate_cgoto_address_table( _environment );
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 fcb ", 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 outhead2("cstring%d fcb %d", staticStrings->id, (int)strlen(staticStrings->value) );
760 if ( strlen( staticStrings->value ) > 0 ) {
761 outhead1(" fcc %s", escape_newlines( staticStrings->value ) );
762 }
763 staticStrings = staticStrings->next;
764 }
765
766 if ( _environment->bitmaskNeeded ) {
767 outhead0("BITMASK fcb $01,$02,$04,$08,$10,$20,$40,$80");
768 outhead0("BITMASKN fcb $fe,$fd,$fb,$f7,$ef,$df,$bf,$7f");
769 }
770 if ( _environment->deployed.dstring ) {
771 outhead1("max_free_string equ $%4.4x", _environment->dstring.space == 0 ? DSTRING_DEFAULT_SPACE : _environment->dstring.space );
772 }
773
774 buffered_push_output( _environment );
775
776 outline1("ORG $%4.4x", _environment->program.startingAddress );
777 outhead0("CODESTART");
778 outline0("LDS #$2FFF");
779 outline0("JMP CODESTART2");
780 outhead0("STACK");
781 outline1("rzb %d", _environment->stackSize );
782 outhead0("STACKEND");
783
784 Bank * bank = _environment->expansionBanks;
785 while( bank ) {
786 if ( bank->address ) {
787
788 deploy_preferred( duff, src_hw_6809_duff_asm );
789 deploy_preferred( msc1, src_hw_6809_msc1_asm );
790 deploy_preferred( bank, src_hw_pc128op_bank_asm );
791
792 outhead1("BANKREADBANK%2.2xXSDR", bank->id );
793 outline1("LDX #BANKWINDOW%2.2x", bank->defaultResident );
794 outhead1("BANKREADBANK%2.2xXS", bank->id );
795 outline1("LDB #$%2.2x", bank->id );
796 outline0("JMP BANKREAD" );
797 _environment->bankAccessOptimization.readn = 1;
798
799 outhead1("BANKUNCOMPRESS%2.2xXSDR", bank->id );
800 outline1("LDY #BANKWINDOW%2.2x", bank->defaultResident );
801 outhead1("BANKUNCOMPRESS%2.2xXS", bank->id );
802 outline1("LDB #$%2.2x", bank->id );
803 // outline0("LEAX $6000,X" );
804 outline0("JMP BANKUNCOMPRESS" );
805 }
806 bank = bank->next;
807 }
808
809 deploy_inplace_preferred( duff, src_hw_6809_duff_asm );
810 deploy_inplace_preferred( msc1, src_hw_6809_msc1_asm );
811 deploy_inplace_preferred( bank, src_hw_pc128op_bank_asm );
812
813 int page0LastAddressUsed = 0;
814 for( i=0; i<MAX_RESIDENT_SHAREDS; ++i ) {
815 if ( _environment->maxExpansionBankSize[i] ) {
816 if ( _environment->residentDetectionEnabled ) {
817 if ( _environment->currentMode == BITMAP_MODE_BITMAP_16 && _environment->doubleBufferEnabled ) {
818 outhead2("BANKWINDOWID%2.2x equ $%4.4x", i, page0LastAddressUsed );
819 page0LastAddressUsed += 2;
820 } else {
821 outline0("ALIGN 2");
822 outhead1("BANKWINDOWID%2.2x fcb $FF, $FF", i );
823 }
824 }
825 if ( _environment->currentMode == BITMAP_MODE_BITMAP_16 && _environment->doubleBufferEnabled ) {
826 outhead2("BANKWINDOW%2.2x equ $%4.4x", i, page0LastAddressUsed);
827 page0LastAddressUsed += _environment->maxExpansionBankSize[i];
828 } else {
829 outline0("ALIGN 2");
830 outhead2("BANKWINDOW%2.2x rzb %d", i, _environment->maxExpansionBankSize[i]);
831 }
832 }
833 }
834
835 outline0("ALIGN 2");
836
837 for(i=0; i<BANK_TYPE_COUNT; ++i) {
838 Bank * actual = _environment->banks[i];
839 while( actual ) {
840 if ( actual->type == BT_VARIABLES ) {
841 // cfgline3("# BANK %s %s AT $%4.4x", BANK_TYPE_AS_STRING[actual->type], actual->name, actual->address);
842 // cfgline2("%s: load = MAIN, type = ro, optional = yes, start = $%4.4x;", actual->name, actual->address);
843 // outhead1(".segment \"%s\"", actual->name);
844 Variable * variable = _environment->variables;
845
846 variable_cleanup_entry_image( _environment, variable );
847 variable_cleanup_entry( _environment, variable, 1 );
848
849 } else if ( actual->type == BT_TEMPORARY ) {
850 for( int j=0; j< (_environment->currentProcedure+1); ++j ) {
851 Variable * variable = _environment->tempVariables[j];
852 variable_cleanup_entry_image( _environment, variable );
853 variable_cleanup_entry( _environment, variable, 1 );
854 variable_cleanup_entry_bit( _environment, variable, 1 );
855 }
856
857 Variable * variable = _environment->tempResidentVariables;
858 variable_cleanup_entry_image( _environment, variable );
859 variable_cleanup_entry( _environment, variable, 1 );
860
861 } else if ( actual->type == BT_STRINGS ) {
862 // cfgline3("# BANK %s %s AT $%4.4x", BANK_TYPE_AS_STRING[actual->type], actual->name, actual->address);
863 // cfgline2("%s: load = MAIN, type = ro, optional = yes, start = $%4.4x;", actual->name, actual->address);
864 } else {
865
866 }
867 actual = actual->next;
868 }
869 }
870
871 outhead0("BANKLOAD");
872
873 bank = _environment->expansionBanks;
874
875 while( bank ) {
876
877 if ( bank->address ) {
878 outline1("fcb $%2.2x", bank->id);
879 } else {
880 break;
881 }
882
883 bank = bank->next;
884
885 }
886
887 outline0("fcb $ff");
888
889 deploy_inplace_preferred( ef936xvars, src_hw_ef936x_vars_asm);
890 deploy_inplace_preferred( vars, src_hw_pc128op_vars_asm);
891 deploy_inplace_preferred( startup, src_hw_pc128op_startup_asm);
892 deploy_inplace_preferred( ef936xstartup, src_hw_ef936x_startup_asm);
893 deploy_inplace_preferred( putimage, src_hw_ef936x_put_image_asm );
894 deploy_inplace_preferred( getimage, src_hw_ef936x_get_image_asm );
895 deploy_inplace_preferred( clsBox, src_hw_ef936x_cls_box_asm )
896 deploy_inplace_preferred( clsGraphic, src_hw_ef936x_cls_asm );
897 if ( _environment->keyboardFullSupport || ! _environment->keyboardConfig.sync ) {
898 deploy_inplace_preferred( keyboard, src_hw_pc128op_keyboard_asm );
899 } else {
900 deploy_inplace_preferred( keyboard, src_hw_pc128op_scancode_asm );
901 }
902 deploy_inplace_preferred( scancode, src_hw_pc128op_scancode_asm );
903 deploy_inplace_preferred( textEncodedAtGraphic, src_hw_ef936x_text_at_asm );
904 deploy_inplace_preferred( textEncodedAtGraphicRaw, src_hw_ef936x_text_at_raw_asm );
905
906 outhead0("CODESTART2");
907 outline0("LDS #STACKEND");
908
909 for( i=0; i<MAX_RESIDENT_SHAREDS; ++i ) {
910 if ( _environment->maxExpansionBankSize[i] ) {
911 if ( _environment->residentDetectionEnabled ) {
912 if ( _environment->currentMode == BITMAP_MODE_BITMAP_16 ) {
913 char bankWindowId[MAX_TEMPORARY_STORAGE];
914 sprintf( bankWindowId, "BANKWINDOWID%2.2x", i );
915 cpu_store_16bit( _environment, bankWindowId, 0xffff );
916 }
917 }
918 }
919 }
920
921 buffered_prepend_output( _environment );
922
923}
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_store_16bit(Environment *_environment, char *_destination, int _value)
CPU 6309: emit code to store 16 bit
Definition 6309.c:1503
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
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)
int size
Definition _optimizer.c:678
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.
Variable * scancode(Environment *_environment)
Definition scancode.c:43
#define DSTRING_DEFAULT_SPACE
Definition atari.h:152
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
#define BITMAP_MODE_BITMAP_16
Definition ef936x.h:122
int address
Definition ugbc.h:159
int id
Definition ugbc.h:153
struct _Bank * next
Definition ugbc.h:185
int defaultResident
Definition ugbc.h:182
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
BankAccessOptimization bankAccessOptimization
Definition ugbc.h:3269
Offsetting * offsetting
Definition ugbc.h:2937
int currentMode
Definition ugbc.h:2696
Bank * banks[BANK_TYPE_COUNT]
Definition ugbc.h:2514
int maxExpansionBankSize[MAX_RESIDENT_SHAREDS]
Definition ugbc.h:3010
Program program
Definition ugbc.h:3179
Variable * tempVariables[MAX_PROCEDURES]
Definition ugbc.h:2606
DataSegment * dataSegment
Definition ugbc.h:2568
FILE * debuggerLabelsFile
Definition ugbc.h:3319
Bank * expansionBanks
Definition ugbc.h:3005
StaticString * strings
Definition ugbc.h:2641
int restoreDynamic
Definition ugbc.h:2573
int bitmaskNeeded
Definition ugbc.h:2659
int currentProcedure
Definition ugbc.h:2601
DString dstring
Definition ugbc.h:2405
int doubleBufferEnabled
Definition ugbc.h:2995
Variable * variables
Definition ugbc.h:2616
int dataNeeded
Definition ugbc.h:2557
int stackSize
Definition ugbc.h:3294
int keyboardFullSupport
Definition ugbc.h:3187
KeyboardConfig keyboardConfig
Definition ugbc.h:2435
int residentDetectionEnabled
Definition ugbc.h:3192
TileDescriptors * descriptors
Definition ugbc.h:2939
int readDataUsed
Definition ugbc.h:2578
Deployed deployed
Definition ugbc.h:2921
VariableType type
Definition ugbc.h:1233
struct _Field * next
Definition ugbc.h:1237
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
int startingAddress
Definition ugbc.h:2217
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
struct _Field * first
Definition ugbc.h:1247
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
StaticString * valueString
Definition ugbc.h:1041
int bankReadOrWrite
Definition ugbc.h:1181
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
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
struct _Type * typeType
Definition ugbc.h:1222
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
struct _Field Field
#define MAX_TEMPORARY_STORAGE
Definition ugbc.h:563
struct _Offsetting Offsetting
#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.
@ 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_STRINGS
Definition ugbc.h:135
@ 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]