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