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 ) {
45
46 Variable * variable = _first;
47
48 while( variable ) {
49
50 if ( ( !variable->assigned || ( variable->assigned && !variable->temporary ) ) && !variable->imported ) {
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_WORD:
58 case VT_SWORD:
59 case VT_POSITION:
60 case VT_ADDRESS:
61 if ( variable->memoryArea ) {
62 outhead2("%s equ $%4.4x", variable->realName, variable->absoluteAddress);
63 } else {
64 vars_emit_word( _environment, variable->realName, variable->initialValue );
65 }
66 break;
67 case VT_DWORD:
68 case VT_SDWORD:
69 if ( variable->memoryArea ) {
70 outhead2("%s equ $%4.4x", variable->realName, variable->absoluteAddress);
71 } else {
72 vars_emit_dword( _environment, variable->realName, variable->initialValue );
73 }
74 break;
75 case VT_NUMBER:
76 if ( variable->memoryArea ) {
77 outhead2("%s equ $%4.4x", variable->realName, variable->absoluteAddress);
78 } else {
79 vars_emit_number( _environment, variable->realName, variable->initialValue );
80 }
81 break;
82 case VT_FLOAT:
83 if ( variable->memoryArea ) {
84 outhead2("%s equ $%4.4x", variable->realName, variable->absoluteAddress);
85 } else {
86 outhead1("%s rzb 6", variable->realName);
87 }
88 break;
89 case VT_MUSIC:
90 case VT_BUFFER:
91 case VT_TYPE:
92 if ( variable->bankAssigned != -1 ) {
93 outhead2("; relocated on bank %d (at %4.4x)", variable->bankAssigned, variable->absoluteAddress );
94 outhead1("%s fcb $0,$0", variable->realName );
95 } else {
96 if ( ! variable->absoluteAddress ) {
97 if ( variable->valueBuffer ) {
98 if ( variable->printable ) {
99 char * string = malloc( variable->size + 1 );
100 memset( string, 0, variable->size + 1 );
101 memcpy( string, variable->valueBuffer, variable->size );
102 outhead2("%s fcc %s", variable->realName, escape_newlines( string ) );
103 if ( variable->size & 0x01 ) {
104 outline0("fcb 0" );
105 }
106 } else {
107 out1("%s fcb ", variable->realName);
108 int i=0;
109 for (i=0; i<(variable->size-1); ++i ) {
110 if ( ( ( i + 1 ) % 16 ) == 0 ) {
111 outline1("$%2.2x", variable->valueBuffer[i]);
112 out0(" fcb ");
113 } else {
114 out1("$%2.2x,", variable->valueBuffer[i]);
115 }
116 }
117 outhead1("$%2.2x", variable->valueBuffer[(variable->size-1)]);
118 if ( variable->size & 0x01 ) {
119 outline0("fcb $0" );
120 }
121 }
122 } else {
123 outhead2("%s rzb %d", variable->realName, variable->size);
124 if ( variable->size & 0x01 ) {
125 outline0("fcb $0" );
126 }
127 }
128 } else {
129 outhead2("%s equ $%4.4x", variable->realName, variable->absoluteAddress);
130 if ( variable->valueBuffer ) {
131 if ( variable->printable ) {
132 char * string = malloc( variable->size + 1 );
133 memset( string, 0, variable->size + 1 );
134 memcpy( string, variable->valueBuffer, variable->size );
135 outhead2("%s fcc %s", variable->realName, escape_newlines( string ) );
136 } else {
137 out1("%scopy fcb ", variable->realName);
138 int i=0;
139 for (i=0; i<(variable->size-1); ++i ) {
140 out1("%d,", variable->valueBuffer[i]);
141 }
142 outhead1("%d", variable->valueBuffer[(variable->size-1)]);
143 if ( variable->size & 0x01 ) {
144 outline0("fcb 0" );
145 }
146 }
147 }
148 }
149 }
150 break;
151 case VT_TILEMAP:
152 case VT_TARRAY: {
153 if ( variable->bankAssigned != -1 ) {
154 outhead4("; relocated on bank %d (at %4.4x) for %d bytes (uncompressed: %d)", variable->bankAssigned, variable->absoluteAddress, variable->size, variable->uncompressedSize );
155 if ( variable->type == VT_TARRAY ) {
156 if (VT_BITWIDTH( variable->arrayType ) == 0 ) {
158 }
159 outhead2("%s rzb %d, $00", variable->realName, (VT_BITWIDTH( variable->arrayType )>>3) );
160 } else {
161 if (VT_BITWIDTH( variable->type ) == 0 ) {
162 CRITICAL_DATATYPE_UNSUPPORTED( "BANKED", DATATYPE_AS_STRING[ variable->type ] );
163 }
164 outhead2("%s rzb %d, $00", variable->realName, (VT_BITWIDTH( variable->type )>>3) );
165 }
166 } else {
167
168 if ( variable->valueBuffer ) {
169 out1("%s fcb ", variable->realName);
170 int i=0;
171 for (i=0; i<(variable->size-1); ++i ) {
172 out1("%d,", variable->valueBuffer[i]);
173 }
174 outhead1("%d", variable->valueBuffer[(variable->size-1)]);
175 } else if ( variable->value ) {
176 switch( VT_BITWIDTH( variable->arrayType ) ) {
177 case 32: {
178 out1("%s fcb ", variable->realName );
179 for( int i=0; i<(variable->size/4)-1; ++i ) {
180 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 ) );
181 }
182 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 ) );
183 outline0("");
184 break;
185 }
186 case 16: {
187 out1("%s fcb ", variable->realName );
188 for( int i=0; i<(variable->size/2)-1; ++i ) {
189 out2("$%2.2x, $%2.2x,", (unsigned int)( ( variable->value >> 8 ) & 0xff ), (unsigned int)( variable->value & 0xff ) );
190 }
191 out2("$%2.2x, $%2.2x", (unsigned int)( ( variable->value >> 8 ) & 0xff ), (unsigned int)( variable->value & 0xff ) );
192 outline0("");
193 break;
194 }
195 case 8:
196 outhead3("%s rzb %d, $%2.2x", variable->realName, variable->size, (unsigned char)(variable->value&0xff) );
197 break;
198 case 1:
199 outhead3("%s rzb %d, $%2.2x", variable->realName, variable->size, (unsigned char)(variable->value?0xff:0x00));
200 break;
201 }
202 } else {
203 outhead2("%s rzb %d", variable->realName, variable->size);
204 }
205
206 }
207 break;
208 }
209 }
210
211 if( variable->type == VT_IMAGES ) {
212 if ( variable->strips ) {
213 vars_emit_strips( _environment, variable->realName, variable->strips );
214 }
215 }
216
217 }
218
219 variable = variable->next;
220
221 }
222
223}
224
225static void variable_cleanup_entry_byte( Environment * _environment, Variable * _first ) {
226
227 Variable * variable = _first;
228
229 while( variable ) {
230
231 if ( ( !variable->assigned || ( variable->assigned && !variable->temporary ) ) && !variable->imported ) {
232
233 if ( variable->memoryArea && _environment->debuggerLabelsFile ) {
234 fprintf( _environment->debuggerLabelsFile, "%4.4x %s\r\n", variable->absoluteAddress, variable->realName );
235 }
236
237 switch( variable->type ) {
238 case VT_CHAR:
239 case VT_BYTE:
240 case VT_SBYTE:
241 case VT_COLOR:
242 case VT_THREAD:
243 if ( variable->memoryArea ) {
244 outhead2("%s equ $%4.4x", variable->realName, variable->absoluteAddress);
245 } else {
246 vars_emit_byte( _environment, variable->realName, variable->initialValue );
247 }
248 break;
249 case VT_DOJOKA:
250 if ( variable->memoryArea ) {
251 outhead2("%s equ $%4.4x", variable->realName, variable->absoluteAddress);
252 } else {
253 outhead1("%s rzb 4", variable->realName);
254 }
255 break;
256 case VT_IMAGEREF:
257 if ( variable->memoryArea ) {
258 outhead2("%s equ $%4.4x", variable->realName, variable->absoluteAddress);
259 } else {
260 outhead1("%s rzb 14", variable->realName);
261 }
262 break;
263 case VT_PATH:
264 if ( variable->memoryArea ) {
265 outhead2("%s equ $%4.4x", variable->realName, variable->absoluteAddress);
266 } else {
267 outhead1("%s rzb 16", variable->realName);
268 }
269 break;
270 case VT_VECTOR2:
271 if ( variable->memoryArea ) {
272 outhead2("%s equ $%4.4x", variable->realName, variable->absoluteAddress);
273 } else {
274 outhead1("%s rzb 4", variable->realName);
275 }
276 break;
277 case VT_STRING:
278 if ( ! variable->valueString ) {
279 printf("%s", variable->realName);
280 exit(EXIT_FAILURE);
281 }
282 if ( variable->memoryArea ) {
283 outhead2("%s equ $%4.4x", variable->realName, variable->absoluteAddress);
284 } else {
285 outhead2("%s equ cstring%d", variable->realName, variable->valueString->id );
286 }
287 break;
288 case VT_DSTRING:
289 if ( variable->memoryArea ) {
290 outhead2("%s equ $%4.4x", variable->realName, variable->absoluteAddress);
291 } else {
292 outhead1("%s rzb 1", variable->realName);
293 }
294 break;
295 case VT_SPRITE:
296 if ( variable->memoryArea ) {
297 outhead2("%s equ $%4.4x", variable->realName, variable->absoluteAddress);
298 } else {
299 outhead1("%s rzb 1", variable->realName);
300 }
301 break;
302 case VT_MSPRITE:
303 if ( variable->memoryArea ) {
304 outhead2("%s equ $%4.4x", variable->realName, variable->absoluteAddress);
305 } else {
306 outhead1("%s rzb 2", variable->realName);
307 }
308 break;
309 case VT_TILE:
310 if ( variable->memoryArea ) {
311 outhead2("%s equ $%4.4x", variable->realName, variable->absoluteAddress);
312 } else {
313 outhead1("%s rzb 1", variable->realName);
314 }
315 break;
316 case VT_TILESET:
317 if ( variable->memoryArea ) {
318 outhead2("%s equ $%4.4x", variable->realName, variable->absoluteAddress);
319 } else {
320 outhead1("%s rzb 1", variable->realName);
321 }
322 break;
323 case VT_TILES:
324 if ( variable->memoryArea ) {
325 outhead2("%s equ $%4.4x", variable->realName, variable->absoluteAddress);
326 } else {
327 outhead1("%s rzb 4", variable->realName);
328 }
329 break;
330
331 }
332 }
333
334 variable = variable->next;
335
336 }
337
338}
339
340static void variable_cleanup_entry( Environment * _environment, Variable * _first ) {
341 variable_cleanup_entry_multibyte( _environment, _first );
342 variable_cleanup_entry_byte( _environment, _first );
343}
344
345static void variable_cleanup_entry_bit( Environment * _environment, Variable * _first ) {
346
347 Variable * variable = _first;
348
349 int bitCount = 0;
350
351 while( variable ) {
352
353 if ( ( !variable->assigned || ( variable->assigned && !variable->temporary ) ) && !variable->imported && !variable->memoryArea ) {
354
355 if ( variable->memoryArea && _environment->debuggerLabelsFile ) {
356 fprintf( _environment->debuggerLabelsFile, "%4.4x %s\r\n", variable->absoluteAddress, variable->realName );
357 }
358
359 switch( variable->type ) {
360 case VT_BIT:
361 if ( variable->memoryArea ) {
362 // outline2("%s = $%4.4x", variable->realName, variable->absoluteAddress);
363 } else {
364 outhead1("%s", variable->realName);
365 }
366 ++bitCount;
367 if ( bitCount == 8 ) {
368 outline0(" fcb 0");
369 }
370 break;
371 }
372
373 }
374
375 variable = variable->next;
376
377 }
378
379 if ( bitCount > 0 ) {
380 outline0(" fcb 0");
381 }
382
383}
384
385static void variable_cleanup_entry_image( Environment * _environment, Variable * _first ) {
386
387 Variable * variable = _first;
388
389 while( variable ) {
390
391 if ( ( !variable->assigned || ( variable->assigned && !variable->temporary ) ) && !variable->imported ) {
392
393 if ( variable->memoryArea && _environment->debuggerLabelsFile ) {
394 fprintf( _environment->debuggerLabelsFile, "%4.4x %s\r\n", variable->absoluteAddress, variable->realName );
395 }
396
397 switch( variable->type ) {
398 case VT_IMAGE:
399 case VT_IMAGES:
400 case VT_SEQUENCE:
401 if ( variable->bankAssigned != -1 ) {
402 outhead2("; relocated on bank %d (at %4.4x)", variable->bankAssigned, variable->absoluteAddress );
403 outhead1("%s fcb $0,$0", variable->realName );
404 } else {
405 if ( ! variable->absoluteAddress ) {
406 if ( variable->valueBuffer ) {
407 if ( variable->printable ) {
408 char * string = malloc( variable->size + 1 );
409 memset( string, 0, variable->size + 1 );
410 memcpy( string, variable->valueBuffer, variable->size );
411 outhead2("%s fcc %s", variable->realName, escape_newlines( string ) );
412 } else {
413 out1("%s fcb ", variable->realName);
414 int i=0;
415 for (i=0; i<(variable->size-1); ++i ) {
416 if ( ( ( i + 1 ) % 16 ) == 0 ) {
417 outline1("%d", variable->valueBuffer[i]);
418 out0(" fcb ");
419 } else {
420 out1("%d,", variable->valueBuffer[i]);
421 }
422 }
423 outhead1("%d", variable->valueBuffer[(variable->size-1)]);
424 }
425 } else {
426 outhead2("%s rzb %d", variable->realName, variable->size);
427 }
428 } else {
429 outhead2("%s equ $%4.4x", variable->realName, variable->absoluteAddress);
430 if ( variable->valueBuffer ) {
431 if ( variable->printable ) {
432 char * string = malloc( variable->size + 1 );
433 memset( string, 0, variable->size + 1 );
434 memcpy( string, variable->valueBuffer, variable->size );
435 outhead2("%s fcc %s", variable->realName, escape_newlines( string ) );
436 } else {
437 out1("%scopy fcb ", variable->realName);
438 int i=0;
439 for (i=0; i<(variable->size-1); ++i ) {
440 out1("%d,", variable->valueBuffer[i]);
441 }
442 outhead1("%d", variable->valueBuffer[(variable->size-1)]);
443 }
444 }
445 }
446 }
447
448 break;
449 }
450 }
451
452 variable = variable->next;
453
454 }
455
456}
457
467void variable_cleanup( Environment * _environment ) {
468 int i=0;
469
470 if (_environment->dojoOnVirtualizedFujiNet || _environment->dojoOnFujiNet ) {
471 dojo_fujinet_init( _environment );
472 }
473
474 vars_emit_constants( _environment );
475
476 if ( _environment->dataSegment ) {
477 outhead1("DATAFIRSTSEGMENT EQU %s", _environment->dataSegment->realName );
478 if ( _environment->readDataUsed && _environment->restoreDynamic ) {
479 outhead0("DATASEGMENTNUMERIC" );
480 DataSegment * actual = _environment->dataSegment;
481 while( actual ) {
482 if ( actual->isNumeric ) {
483 outline2( "fdb $%4.4x, %s", actual->lineNumber, actual->realName );
484 }
485 actual = actual->next;
486 }
487 outline0( "fdb $ffff, DATAPTRE" );
488 }
489 }
490
491 if ( _environment->offsetting ) {
492 Offsetting * actual = _environment->offsetting;
493 while( actual ) {
494 outhead1("OFFSETS%4.4x", actual->size );
495 out0(" fdb " );
496 for( i=0; i<actual->count; ++i ) {
497 out1("$%4.4x", i * actual->size );
498 if ( i < ( actual->count - 1 ) ) {
499 out0(",");
500 } else {
501 outline0("");
502 }
503 }
504 if ( actual->variables ) {
505 OffsettingVariable * actualVariable = actual->variables;
506 while( actualVariable ) {
507 if ( actualVariable->sequence ) {
508 outhead1("%soffsetsequence", actualVariable->variable->realName );
509 } else {
510 outhead1("%soffsetframe", actualVariable->variable->realName );
511 }
512 actualVariable = actualVariable->next;
513 }
514 outhead1("fs%4.4xoffsetsequence", actual->size );
515 outhead1("fs%4.4xoffsetframe", actual->size );
516 outline1("LDX #OFFSETS%4.4x", actual->size );
517 outline0("LDA #0" );
518 outline0("ABX" );
519 outline0("ABX" );
520 outline0("LDD ,X" );
521 outline0("LEAY D, Y" );
522 outline0("RTS");
523 }
524 actual = actual->next;
525 }
526
527 int values[MAX_TEMPORARY_STORAGE];
528 char * address[MAX_TEMPORARY_STORAGE];
529
530 actual = _environment->offsetting;
531 int count = 0;
532 while( actual ) {
533 values[count] = actual->size;
534 address[count] = malloc( MAX_TEMPORARY_STORAGE );
535 sprintf( address[count], "fs%4.4xoffsetframe", actual->size );
536 actual = actual->next;
537 ++count;
538 }
539
540 cpu_address_table_build( _environment, "EXECOFFSETS", values, address, count );
541
542 cpu_address_table_lookup( _environment, "EXECOFFSETS", count );
543
544 }
545
546 outline0("ALIGN $0002, $00");
547
548 generate_cgoto_address_table( _environment );
549
550 for( i=0; i<MAX_RESIDENT_SHAREDS; ++i ) {
551 if ( _environment->maxExpansionBankSize[i] ) {
552 outhead2("BANKWINDOW%2.2x rzb %d", i, _environment->maxExpansionBankSize[i]);
553 outhead1("BANKWINDOWID%2.2x fcb $FF, $FF", i );
554 }
555 }
556
557 for(i=0; i<BANK_TYPE_COUNT; ++i) {
558 Bank * actual = _environment->banks[i];
559 while( actual ) {
560 if ( actual->type == BT_VARIABLES ) {
561 // cfgline3("# BANK %s %s AT $%4.4x", BANK_TYPE_AS_STRING[actual->type], actual->name, actual->address);
562 // cfgline2("%s: load = MAIN, type = ro, optional = yes, start = $%4.4x;", actual->name, actual->address);
563 // outhead1(".segment \"%s\"", actual->name);
564 Variable * variable = _environment->variables;
565
566 variable_cleanup_entry( _environment, variable );
567 variable_cleanup_entry_bit( _environment, variable );
568
569 } else if ( actual->type == BT_TEMPORARY ) {
570 // cfgline3("# BANK %s %s AT $%4.4x", BANK_TYPE_AS_STRING[actual->type], actual->name, actual->address);
571 // cfgline2("%s: load = MAIN, type = ro, optional = yes, start = $%4.4x;", actual->name, actual->address);
572 // outhead1(".segment \"%s\"", actual->name);
573
574 for( int j=0; j< (_environment->currentProcedure+1); ++j ) {
575 Variable * variable = _environment->tempVariables[j];
576 variable_cleanup_entry( _environment, variable );
577 variable_cleanup_entry_bit( _environment, variable );
578 }
579
580 Variable * variable = _environment->tempResidentVariables;
581
582 variable_cleanup_entry( _environment, variable );
583 variable_cleanup_entry_bit( _environment, variable );
584
585 } else if ( actual->type == BT_STRINGS ) {
586 // cfgline3("# BANK %s %s AT $%4.4x", BANK_TYPE_AS_STRING[actual->type], actual->name, actual->address);
587 // cfgline2("%s: load = MAIN, type = ro, optional = yes, start = $%4.4x;", actual->name, actual->address);
588 } else {
589
590 }
591 actual = actual->next;
592 }
593 }
594
595 if ( _environment->deployed.dojo || _environment->deployed.dojo_fujinet ) {
596 outhead0("DOJOERROR fcb $00" );
597 outhead0("DOJOPACKET" );
598 outhead0("DOJOPACKET_CMD" );
599 outhead0("DOJOPACKET_STATUS" );
600 outline0("fcb $0" );
601 outhead0("DOJOPACKET_PAR1" );
602 outhead0("DOJOPACKET_RSIZE" );
603 outline0("fcb $0" );
604 outhead0("DOJOPACKET_PAR2" );
605 outline0("fcb $0" );
606 outhead0("DOJOPACKET_SIZE" );
607 outline0("fcb $0" );
608 }
609
610 variable_on_memory_init( _environment, 0 );
611
612 DataSegment * dataSegment = _environment->dataSegment;
613 while( dataSegment ) {
614 int i=0;
615 if ( dataSegment->data ) {
616 out1("%s fcb ", dataSegment->realName );
617 } else {
618 outhead1("%s ", dataSegment->realName );
619 }
620 DataDataSegment * dataDataSegment = dataSegment->data;
621 while( dataDataSegment ) {
622 int binary = 0;
623 for(int j=0; j<dataDataSegment->size; ++j ) {
624 if (dataDataSegment->data[j] == 34 || dataDataSegment->data[j] < 32 || dataDataSegment->data[j] > 128 ) {
625 binary = 1;
626 break;
627 }
628 }
629 if ( dataSegment->type ) {
630 if ( ( dataDataSegment->type == VT_STRING || dataDataSegment->type == VT_DSTRING ) ) {
631 if ( binary ) {
632 out1("$%2.2x,", (unsigned char)(dataDataSegment->size) );
633 for( i=0; i<(dataDataSegment->size-1); ++i ) {
634 out1("$%2.2x,", (unsigned char)(dataDataSegment->data[i]&0xff) );
635 }
636 out1("$%2.2x", (unsigned char)(dataDataSegment->data[i]&0xff) );
637 } else {
638 out1("$%2.2x,", (unsigned char)(dataDataSegment->size) );
639 out1("\"%s\"", dataDataSegment->data );
640 }
641 } else {
642 for( i=0; i<(dataDataSegment->size-1); ++i ) {
643 out1("$%2.2x,", (unsigned char)(dataDataSegment->data[i]&0xff) );
644 }
645 out1("$%2.2x", (unsigned char)(dataDataSegment->data[i]&0xff) );
646 }
647 } else {
648 if ( ( dataDataSegment->type == VT_STRING || dataDataSegment->type == VT_DSTRING ) && !binary ) {
649 if ( binary ) {
650 out1("$%2.2x,", (unsigned char)(dataDataSegment->type) );
651 for( i=0; i<(dataDataSegment->size-1); ++i ) {
652 out1("$%2.2x,", (unsigned char)(dataDataSegment->data[i]&0xff) );
653 }
654 out1("$%2.2x", (unsigned char)(dataDataSegment->data[i]&0xff) );
655 } else {
656 out1("$%2.2x,", (unsigned char)(dataDataSegment->type) );
657 out1("$%2.2x,", (unsigned char)(dataDataSegment->size) );
658 out1("\"%s\"", dataDataSegment->data );
659 }
660 } else {
661 out1("$%2.2x,", (unsigned char)(dataDataSegment->type) );
662 for( i=0; i<(dataDataSegment->size-1); ++i ) {
663 out1("$%2.2x,", (unsigned char)(dataDataSegment->data[i]&0xff) );
664 }
665 out1("$%2.2x", (unsigned char)(dataDataSegment->data[i]&0xff) );
666 }
667 }
668 if ( dataDataSegment->next && dataDataSegment->size ) {
669 out0(",");
670 }
671 dataDataSegment = dataDataSegment->next;
672 }
673 outline0("");
674 dataSegment = dataSegment->next;
675 }
676
677 if ( _environment->dataNeeded || _environment->dataSegment || _environment->deployed.read_data_unsafe ) {
678 outhead0("DATAPTRE");
679 }
680
681 StaticString * staticStrings = _environment->strings;
682 while( staticStrings ) {
683 outhead2("cstring%d fcb %d", staticStrings->id, (int)strlen(staticStrings->value) );
684 if ( strlen( staticStrings->value ) > 0 ) {
685 outhead1(" fcc %s", escape_newlines( staticStrings->value ) );
686 }
687 staticStrings = staticStrings->next;
688 }
689
691
692 buffered_push_output( _environment );
693
694 outline0("ORG $2A00");
695 outline0("STA $FFDF");
696 outline0("JMP CODESTART")
697 if ( ( _environment->program.startingAddress - 0x2a00 ) > 0 ) {
698 outhead1(" rzb %d", ( _environment->program.startingAddress - 0x2a00 ) - _environment->stackSize );
699 }
700 outhead1("IRQSTACK0 rzb %d", _environment->stackSize );
701 outhead0("IRQSTACK");
702 outhead0("COCO3STARTUP2")
703 if (_environment->dojoOnVirtualizedFujiNet ) {
704 fujinet_define( _environment, FN_BECKER );
705 } else if ( _environment->dojoOnFujiNet ) {
706 fujinet_define( _environment, FN_HDBDOS );
707 }
708 outline0("RTS");
709
710 deploy_inplace( irq, src_hw_coco3_irq_asm);
711 deploy_inplace_preferred( duff, src_hw_6809_duff_asm );
712 deploy_inplace_preferred( msc1, src_hw_6809_msc1_asm );
713 deploy_inplace_preferred( bank, src_hw_coco3_bank_asm);
714 deploy_inplace_preferred( gimevars, src_hw_gime_vars_asm );
715 deploy_inplace_preferred( gimestartup, src_hw_gime_startup_asm );
716 deploy_inplace_preferred( putimage, src_hw_gime_put_image_asm );
717 deploy_inplace_preferred( getimage, src_hw_gime_get_image_asm );
718 deploy_inplace_preferred( clsGraphic, src_hw_gime_cls_graphic_asm );
719 deploy_inplace_preferred( clsText, src_hw_gime_cls_text_asm );
720 deploy_inplace_preferred( blitimage, src_hw_gime_blit_image_asm );
721 deploy_inplace_preferred( vScrollText, src_hw_gime_vscroll_text_asm );
722 deploy_inplace_preferred( textEncodedAt, src_hw_gime_text_at_asm );
723 deploy_inplace_preferred( textEncodedAtText, src_hw_gime_text_at_text_asm );
724 deploy_inplace_preferred( textEncodedAtTextRaw, src_hw_gime_text_at_text_raw_asm );
725 deploy_inplace_preferred( textEncodedAtGraphic, src_hw_gime_text_at_graphic_asm );
726 deploy_inplace_preferred( textEncodedAtGraphicRaw, src_hw_gime_text_at_graphic_raw_asm );
727 deploy_inplace_preferred( plot, src_hw_gime_plot_asm );
728 deploy_inplace_preferred( dcommon, src_hw_coco3_dcommon_asm);
729 deploy_inplace_preferred( dload, src_hw_coco3_dload_asm);
730 deploy_inplace_preferred( dsave, src_hw_coco3_dsave_asm);
731 deploy_inplace_preferred( textHScroll, src_hw_gime_hscroll_text_asm );
732
733 // Moved here for banking reasons.
734
735 for(i=0; i<BANK_TYPE_COUNT; ++i) {
736 Bank * actual = _environment->banks[i];
737 while( actual ) {
738 if ( actual->type == BT_VARIABLES ) {
739 // cfgline3("# BANK %s %s AT $%4.4x", BANK_TYPE_AS_STRING[actual->type], actual->name, actual->address);
740 // cfgline2("%s: load = MAIN, type = ro, optional = yes, start = $%4.4x;", actual->name, actual->address);
741 // outhead1(".segment \"%s\"", actual->name);
742 Variable * variable = _environment->variables;
743
744 variable_cleanup_entry_image( _environment, variable );
745
746 } else if ( actual->type == BT_TEMPORARY ) {
747 for( int j=0; j< (_environment->currentProcedure+1); ++j ) {
748 Variable * variable = _environment->tempVariables[j];
749 variable_cleanup_entry_image( _environment, variable );
750 }
751
752 Variable * variable = _environment->tempResidentVariables;
753 variable_cleanup_entry_image( _environment, variable );
754
755 } else if ( actual->type == BT_STRINGS ) {
756 // cfgline3("# BANK %s %s AT $%4.4x", BANK_TYPE_AS_STRING[actual->type], actual->name, actual->address);
757 // cfgline2("%s: load = MAIN, type = ro, optional = yes, start = $%4.4x;", actual->name, actual->address);
758 } else {
759
760 }
761 actual = actual->next;
762 }
763 }
764
765 if ( _environment->descriptors ) {
766 outhead0("UDCCHAR" );
767 int i=0,j=0;
768 for(i=_environment->descriptors->first;i<(_environment->descriptors->first+_environment->descriptors->count);++i) {
769 outline1("; $%2.2x ", i);
770 out0(" fcb " );
771 for(j=0;j<7;++j) {
772 out1("$%2.2x,", ((unsigned char)_environment->descriptors->data[i].data[j]) );
773 }
774 outline1("$%2.2x", ((unsigned char)_environment->descriptors->data[i].data[j]) );
775 }
776 } else {
777 outhead0("UDCCHAR EQU $E000");
778 }
779
780 if ( _environment->bitmaskNeeded ) {
781 outhead0("BITMASK fcb $01,$02,$04,$08,$10,$20,$40,$80");
782 outhead0("BITMASKN fcb $fe,$fd,$fb,$f7,$ef,$df,$bf,$7f");
783 }
784 if ( _environment->deployed.dstring ) {
785 outhead1("max_free_string equ $%4.4x", _environment->dstring.space == 0 ? DSTRING_DEFAULT_SPACE : _environment->dstring.space );
786 }
787
788 buffered_prepend_output( _environment );
789
790}
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_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)
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 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)
void dsave(Environment *_environment, char *_filename, char *_offset, char *_address, char *_size)
Emit code for DLOAD(...).
Definition dsave.c:58
void plot(Environment *_environment, char *_x, char *_y, char *_c, int _preserve_color)
Definition plot.c:46
#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
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 dojo_fujinet
Definition ugbc.h:1952
int read_data_unsafe
Definition ugbc.h:1923
int dojo
Definition ugbc.h:1951
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 dojoOnVirtualizedFujiNet
Definition ugbc.h:3245
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
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
Variable * variables
Definition ugbc.h:2616
int dataNeeded
Definition ugbc.h:2557
int stackSize
Definition ugbc.h:3294
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 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
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 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
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
@ FN_BECKER
Definition ugbc.h:375
@ FN_HDBDOS
Definition ugbc.h:374
#define MAX_RESIDENT_SHAREDS
Definition ugbc.h:572
struct _Variable Variable
Structure of a single variable.
#define deploy_inplace(s, e)
Definition ugbc.h:4308
#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_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
@ 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]