ugBASIC 1.18
An isomorphic BASIC language compiler for retrocomputers
Loading...
Searching...
No Matches
_build.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
41#include<stdlib.h>
42#include<stdio.h>
43#include<math.h>
44
45extern char OUTPUT_FILE_TYPE_AS_STRING[][16];
46
47void target_linkage( Environment * _environment ) {
48
49 char commandLine[8*MAX_TEMPORARY_STORAGE];
50 char executableName[MAX_TEMPORARY_STORAGE];
51 char listingFileName[MAX_TEMPORARY_STORAGE];
52
53 if ( (_environment->outputFileType != OUTPUT_FILE_TYPE_K7_ORIGINAL) && (_environment->outputFileType != OUTPUT_FILE_TYPE_K7_NEW) && (_environment->outputFileType != OUTPUT_FILE_TYPE_SDDRIVE) ) {
55 }
56
57 BUILD_SAFE_REMOVE( _environment, _environment->exeFileName );
58
59 BUILD_TOOLCHAIN_ASM6809_GET_EXECUTABLE( _environment, executableName );
60
61 BUILD_TOOLCHAIN_ASM6809_GET_LISTING_FILE( _environment, listingFileName );
62
63 BUILD_TOOLCHAIN_ASM6809EXEC( _environment, "-B", 10240, executableName, listingFileName );
64
65 if ( _environment->listingFileName ) {
66
67 if ( _environment->profileFileName && _environment->profileCycles ) {
68 if ( _environment->executerFileName ) {
69 sprintf(executableName, "%s", _environment->executerFileName );
70 } else if( access( "run6809.exe", F_OK ) == 0 ) {
71 sprintf(executableName, "%s", "run6809.exe" );
72 } else {
73 sprintf(executableName, "%s", "run6809" );
74 }
75
76 sprintf( commandLine, "\"%s\" -i \"%s\" -R 3000 -b -l 3000 \"%s\" -p \"%s\" %d",
77 executableName,
78 _environment->listingFileName,
79 _environment->exeFileName,
80 _environment->profileFileName,
81 _environment->profileCycles ? _environment->profileCycles : 1000000
82 );
83
84 if ( system_call( _environment, commandLine ) ) {
85 printf("The profiling of assembly program failed.\n\n");
86 return;
87 };
88
89 }
90
91 }
92
93 switch( _environment->outputFileType ) {
95 convertbintok7( _environment );
96 break;
98 convertbintok7_original( _environment );
99 break;
101 convertbintosddrive( _environment );
102 break;
103 default:
104 }
105
106}
107
108static unsigned int sum=0;
109static unsigned char chk=0;
110static unsigned short l;
111static int nblock;
112static int rest;
113static int cnt=0;
114static int frmt( Environment * _environment, char * ptr, char size,char* out)
115{
116 memset(out,0x20,11);
117 char * point=".";
118 int k=0,i=0;
119 int p=strcspn(ptr,point);
120 if(p==size-1||p>8||size>12||p==0)
121 {
123 }
124 for(i=0;i<size;i++)
125 {
126 if(i==p)
127 k+=(8-p);
128 else
129 {
130 out[k]=ptr[i];
131 k++;
132 }
133
134 }
135 return 0;
136}
137
138// FIX #173
139#if ( defined(__BYTE_ORDER) && __BYTE_ORDER == __BIG_ENDIAN ) || \
140 defined(__BIG_ENDIAN__) || \
141 defined(__ARMEB__) || \
142 defined(__THUMBEB__) || \
143 defined(__AARCH64EB__) || \
144 defined(_MIBSEB) || defined(__MIBSEB) || defined(__MIBSEB__)
145
146 static void swapen(unsigned short *num)
147 {
148 return *num;
149 }
150
151#else
152
153 static void swapen(unsigned short *num)
154 {
155 unsigned short swapped;
156 swapped = (*num>>8) | (*num<<8);
157 *num=swapped;
158 }
159
160#endif
161
162static void crc ( unsigned char * data, int l,unsigned int * old)
163{
164
165 cnt+=l;
166 for (int i= 0;i<l;i++)
167 {
168 (*old)+=data[i];
169
170 }
171}
172
173static unsigned char cmpl(unsigned int n)
174{
175 return 0x100- ((unsigned char)n);
176}
177
179{
180 // if(argc==1)
181 // {
182 // printf("Missing arguments !!!!!!\n"
183 // "bin2k7 source pc128_filename K7_filename\n"
184 // "load and exec address is set to &H0000.\n"
185 // "Use offset to load to any address. EX: LOADM\"CASS:\",&H6000 will load starting to &H6000\n"
186 // );
187 // return -1;
188 // }
189 unsigned short start=0x3000;
190 unsigned short size;
191 unsigned short runaddr=0x3000;
192 FILE *fr,*fw;
193 char nome[12];
194 char nomecod[12];
195 char source[20];
196 char destin[100];
197
198 // Rename the output file into a temporary filename
199 char temporaryFileName[MAX_TEMPORARY_STORAGE];
200 sprintf(temporaryFileName, "%s.bin", get_temporary_filename( _environment ) );
201
202 remove( temporaryFileName );
203
204 BUILD_SAFE_MOVE( _environment, _environment->exeFileName, temporaryFileName );
205
206 fr=fopen(temporaryFileName,"rb");
207 if(!fr)
208 {
209 CRITICAL_CANNOT_OPEN_EXECUTABLE_FILE( temporaryFileName );
210 // printf("source file not found!!!!");
211 // return -1;
212 }
213
214 if(frmt(_environment, "main.exe",strlen("main.exe"),nome))
215 {
217 }
218
219 unsigned char byt;
220 unsigned short l;
221 unsigned char h[]={1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0x3c,0x5a};
222 unsigned char h1[]={1,0,0};
223 unsigned char h2[]={1,0};
224 unsigned char n[]={0x00,0x10};
225 unsigned char n1[]={0x02,0x00,0x00};
226 unsigned char end[]={0xff,0x02,0x00};
227 unsigned char z=0;
228 unsigned char u=1;
229 unsigned char preend[]={0xff,0x00,0x00};
230 fr=fopen(temporaryFileName,"rb");
231 // if(argv[3]==NULL)
232 // {
233 strcopy(destin,_environment->exeFileName);
234 // strcat(destin,".K7");
235 // }
236 // else
237 // strcopy(destin,argv[3]);
238 fw=fopen(destin,"wb");
239 fseek(fr, 0L, SEEK_END);
240 size = ftell(fr);
241 l=size;
242 nblock=floor((size+12)/254);
243 // printf("n blocks: %d\n",nblock);
244 // printf("size: %d\n",size);
245 rest=size+12-nblock*254;
246
247 // Fix #187
248 unsigned char restByte = (unsigned char)rest;
249
250 rewind(fr);
251 swapen(&size);
252 swapen(&start);
253 swapen(&runaddr);
254 fwrite(&h,sizeof(h),1,fw);
255 fwrite(&n,sizeof(n),1,fw);
256 fwrite(&nome,sizeof(nome)-1,1,fw);
257 fwrite(&n1,3,1,fw);
258 crc(nome,11,&sum);
259 crc(n1,1,&sum);
260
261 chk=cmpl(sum);
262 sum=0;
263 cnt=0;
264 fwrite(&chk,1,1,fw);
265 fwrite(&h,sizeof(h),1,fw);
266 if(nblock>0)
267 {
268 fwrite(&h1,sizeof(h1),1,fw);
269 }
270 else
271 {
272 fwrite(&u,sizeof(u),1,fw);
273 // Fix #187
274 fwrite(&restByte,1,1,fw);
275 fwrite(&z,sizeof(z),1,fw);
276 }
277 cnt++;
278 fwrite(&size,sizeof(size),1,fw);
279 fwrite(&start,sizeof(start),1,fw);
280 crc((unsigned char *)&size,sizeof(size),&sum);
281 crc((unsigned char *)&start,sizeof(start),&sum);
282 for (int i=0;i<l;i++)
283 {
284 if(cnt>253)
285 {
286 nblock--;
287 chk=cmpl(sum);
288 sum=0;
289 //printf("%d\n",chk);
290 fwrite(&chk,1,1,fw);
291 fwrite(&h,sizeof(h),1,fw);
292 if(nblock>0)
293 fwrite(&h2,sizeof(h2),1,fw);
294 else
295 {
296 fwrite(&u,sizeof(u),1,fw);
297 // Fix #187
298 fwrite(&restByte,1,1,fw);
299 // printf("*****\n");
300 }
301 cnt=0;
302
303 }
304 (void)!fread(&byt,1,1,fr);
305 crc(&byt,1,&sum);
306 (void)!fwrite(&byt,1,1,fw);
307 }
308 crc((unsigned char *)&preend,3,&sum);
309 fwrite(&preend,3,1,fw);
310 crc((unsigned char *)&runaddr,2,&sum);
311 fwrite(&runaddr,2,1,fw);
312 chk=cmpl(sum);
313 sum=0;
314 fwrite(&chk,1,1,fw);
315 fwrite(&h,sizeof(h),1,fw);
316 fwrite(&end,sizeof(end),1,fw);
317 // printf("chk %x rest %x block %d\n",chk,rest,nblock);
318
319 fclose(fr);
320 fclose(fw);
321
322 return 0;
323}
324
325void target_cleanup( Environment * _environment ) {
326
327 remove( _environment->asmFileName );
328
329 if ( _environment->analysis && _environment->listingFileName ) {
330 target_analysis( _environment );
331 }
332
333}
334
335unsigned char sddrive_boot_loader[] = {
336 0xE0,0x82,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
337 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
338 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
339 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
340 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
341 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
342 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
343 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xF3,
344 0xCE,0x20,0x48,0x8E,0x5E,0x00,0xAF,0x47,0x8E,0x00,0x00,0xAF,0x42,0x86,0x02,0xA7,
345 0x44,0xC6,0x02,0xE7,0xC4,0x3F,0x26,0x7E,0x5E,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
346 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
347 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
348 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
349 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
350 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
351 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
352 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
353 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
354 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
355 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
356 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
357 0xFF,0xFF,0xFF,0xFF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D,0xA0,0x28,0x8D,0x50,0x8D,
370 0x4E,0x96,0xC0,0x84,0xFE,0x97,0xC0,0x10,0x8E,0x00,0x00,0xC6,0x10,0x8D,0x5E,0xFC,
371 0x1F,0x40,0xFD,0xA7,0xDC,0x8E,0x1F,0x42,0x7F,0xA7,0xDB,0x10,0x8E,0x00,0x10,0xEC,
372 0x81,0xB7,0xA7,0xDA,0xF7,0xA7,0xDA,0x31,0x3F,0x26,0xF4,0x0C,0xC0,0x10,0x8E,0x00,
373 0x00,0xC6,0x2F,0x8D,0x38,0xC6,0x02,0x34,0x04,0x8D,0x29,0x35,0x04,0x5C,0xC1,0x08,
374 0x26,0xF5,0xC6,0x7F,0xD1,0xBF,0x25,0xFC,0x10,0xCE,0x1F,0xFF,0x7E,0x1F,0x40,0xC6,
375 0x7F,0xD1,0xBF,0x25,0xFC,0x8E,0x02,0x02,0x86,0x01,0xD1,0xBF,0x49,0x24,0xFB,0x30,
376 0x1F,0x26,0xF5,0x39,0xF7,0xA7,0xE5,0x10,0x8E,0x60,0x00,0xC6,0x20,0x34,0x04,0xC6,
377 0x7F,0xD1,0xBF,0x25,0xFC,0x8E,0x02,0x00,0x86,0x01,0xD1,0xBF,0x49,0x24,0xFB,0xA7,
378 0xA0,0x30,0x1F,0x26,0xF3,0x86,0x10,0x91,0xBF,0x4A,0x26,0xFB,0x6A,0xE4,0x26,0xE1,
379 0x35,0x84,0x52,0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
380 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
381 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
382 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
383 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,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xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
397 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
398 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
399 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF
400};
401
402unsigned char sddrive_restore[] = {
403 0xB6, 0x1F, 0xD0, 0x97, 0xC0, 0xFC, 0x1F, 0xD1,
404 0xDD, 0xE4, 0xFC, 0x1F, 0xD3, 0xDD, 0xE6, 0x5F,
405 0xB6, 0xA7, 0xC1, 0x88, 0x01, 0xB7, 0xA7, 0xC1,
406 0x8E, 0x00, 0x50, 0x30, 0x1F, 0x26, 0xFC, 0x5A,
407 0x26, 0xEE, 0xFC, 0x1F, 0xC4, 0x83, 0x1F, 0xFF,
408 0xED, 0x8C, 0x18, 0xFC, 0x1F, 0xC8, 0x34, 0x04,
409 0x1F, 0x8B, 0xFC, 0x1F, 0xCA, 0xBE, 0x1F, 0xC0,
410 0x10, 0xBE, 0x1F, 0xC2, 0xFE, 0x1F, 0xC6, 0x35,
411 0x01, 0x32, 0xE9, 0xFF, 0xFF, 0x6E, 0x9F, 0x1F,
412 0xCC, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
413};
414
415static char * findbank( Environment * _environment, int _bank ) {
416
417 char * buffer = malloc( 0x4000 );
418 memset( buffer, 0, 0x4000 );
419 Storage * storage = _environment->storage;
420
421 if ( storage ) {
422
423 FileStorage * fileStorage = storage->files;
424
425 Bank * bank = _environment->expansionBanks;
426
427 while( bank && fileStorage ) {
428
429 if ( bank->address && bank->id == _bank ) {
430
431 if ( fileStorage->content && fileStorage->size ) {
432 memcpy( buffer, fileStorage->content, fileStorage->size );
433 } else {
434 FILE * file = fopen( fileStorage->sourceName, "rb" );
435 if ( !file ) {
437 }
438 fseek( file, 0, SEEK_END );
439 int size = ftell( file );
440 fseek( file, 0, SEEK_SET );
441 (void)!fread( buffer, size, 1, file );
442 fclose( file );
443 }
444 return buffer;
445 }
446
447 bank = bank->next;
448 fileStorage = fileStorage->next;
449
450 }
451
452 }
453
454 return buffer;
455
456}
457
458int convertbintosddrive(Environment * _environment) {
459
460 int start, end;
461
462 char temporaryFileName[MAX_TEMPORARY_STORAGE];
463 sprintf(temporaryFileName, "%s.bin", get_temporary_filename( _environment ) );
464 remove( temporaryFileName );
465 BUILD_SAFE_MOVE( _environment, _environment->exeFileName, temporaryFileName );
466
467 FILE * sddrive = fopen( _environment->exeFileName, "wb");
468
469 // A 0x0000 0x03ff Boot loader (ASM)
470 // start = ftell( sddrive );
471 fwrite( sddrive_boot_loader, sizeof(sddrive_boot_loader), 1, sddrive );
472 // end = ftell( sddrive )-1;
473
474 // printf( "A -- 0x%4.4x 0x%4.4x | Boot loader (ASM)\n", start, end );
475
476 // B 0x0400 0x233f RAM (video 0) 0x0000 0x1f3f
477 // start = ftell( sddrive );
478 for( int i=0x0400; i<=0x233f; ++i ) {
479 char zero = 0;
480 fwrite( &zero, 1, 1, sddrive );;
481 }
482 // end = ftell( sddrive )-1;
483
484 // printf( "B -- 0x%4.4x 0x%4.4x | RAM (video 0)\n", start, end );
485
486 // C 0x2340 0x23ff Registri HW + palette
487 // start = ftell( sddrive );
488 // 0x2340 contenuto del registro $a7dc
489 char ra7dc = 0x00;
490 fwrite( &ra7dc, 1, 1, sddrive );;
491 // 0x2341 contenuto del registro $a7dd
492 char ra7dd = 0x36;
493 fwrite( &ra7dd, 1, 1, sddrive );;
494 // 0x2342 16 words della palette
495 for( int i=0x2342; i<=0x23ff; ++i ) {
496 char zero = 0;
497 fwrite( &zero, 1, 1, sddrive );;
498 }
499 // end = ftell( sddrive )-1;
500
501 // printf( "C -- 0x%4.4x 0x%4.4x | Registri HW + palette\n", start, end );
502
503 // D 0x2400 0x433f RAM (video 1) 0x0000 0x1f3f
504 // start = ftell( sddrive );
505 for( int i=0x2400; i<=0x433f; ++i ) {
506 char zero = 0;
507 fwrite( &zero, 1, 1, sddrive );;
508 }
509 // end = ftell( sddrive )-1;
510
511 // printf( "D -- 0x%4.4x 0x%4.4x | RAM (video 1)\n", start, end );
512
513 // E 0x4340 0x43bf Loader snapshot
514 // start = ftell( sddrive );
515 fwrite( sddrive_restore, sizeof(sddrive_restore), 1, sddrive );
516 for( int i=0x438f; i<0x43bf; ++i ) {
517 char zero = 0;
518 fwrite( &zero, 1, 1, sddrive );;
519 }
520 // end = ftell( sddrive )-1;
521 // printf( "E -- 0x%4.4x 0x%4.4x | Loader snapshot\n", start, end );
522
523 // F 0x43c0 0x43d0 Registri CPU + HW
524 // 0x1fc0 contenuto del registro D
525 // start = ftell( sddrive );
526 int regD = 0;
527 fwrite( &regD, 2, 1, sddrive );
528 // 0x1fc2 contenuto del registro X
529 int regX = 0;
530 fwrite( &regX, 2, 1, sddrive );
531 // 0x1fc4 contenuto del registro Y
532 int regY = 0;
533 fwrite( &regY, 2, 1, sddrive );
534 // 0x1fc6 contenuto del registro S
535 int regS = 0x5fe0;
536 fwrite( &regS, 2, 1, sddrive );
537 // 0x1fc8 contenuto del registro U
538 int regU = 0xa7c0;
539 fwrite( &regU, 2, 1, sddrive );
540 // 0x1fca contenuto del registro DP
541 char regDP = 0x20;
542 fwrite( &regDP, 1, 1, sddrive );
543 // 0x1fcb contenuto del registro CC
544 char regCC = 0x80;
545 fwrite( &regCC, 1, 1, sddrive );
546 // 0x1fcc contenuto del registro PC (endianess)
547 int regPC = 0x0030;
548 fwrite( &regPC, 2, 1, sddrive );
549 // 0x1fcd byte di scostamento
550 char ignored = 0x00;
551 fwrite( &ignored, 1, 1, sddrive );
552 char ignored2 = 0x00;
553 fwrite( &ignored2, 1, 1, sddrive );
554 // 0x1fce contenuto del registro 0xa7c0
555 char ra7c0 = 0x91;
556 fwrite( &ra7c0, 1, 1, sddrive );
557 // 0x1fd1 contenuto del registro 0xa7e4
558 char ra7e4 = 0x30;
559 fwrite( &ra7e4, 1, 1, sddrive );
560 // 0x1fd2 contenuto del registro 0xa7e5
561 char ra7e5 = 0x02;
562 fwrite( &ra7e5, 1, 1, sddrive );
563 // 0x1fd3 contenuto del registro 0xa7e6
564 char ra7e6 = 0x00;
565 fwrite( &ra7e6, 1, 1, sddrive );
566 // 0x1fd4 contenuto del registro 0xa7e7
567 // end = ftell( sddrive )-1;
568
569 // printf( "F -- 0x%4.4x 0x%4.4x | Registri CPU + HW\n", start, end );
570
571 // G 0x43d0 0x43ff (spazio libero)
572 // start = ftell( sddrive );
573 for( int i=0x43d4; i<=0x43ff; ++i ) {
574 char zero = 0;
575 fwrite( &zero, 1, 1, sddrive );;
576 }
577 // end = ftell( sddrive )-1;
578
579 // printf( "G -- 0x%4.4x 0x%4.4x | (spazio libero)\n", start, end );
580
581 FILE * bin;
582 char * bank;
583 int bankSize;
584
585 // H 0x4400 0x81ff RAM (banco 1) 0x2000 0x5fff
586 // start = ftell( sddrive );
587 for( int i=0x4400; i<=0x53ff; ++i ) {
588 char zero = 0;
589 fwrite( &zero, 1, 1, sddrive );;
590 }
591 bankSize = 0x6000 - 0x3000;
592 bin = fopen(temporaryFileName, "rb");
593 bank = malloc( bankSize );
594 (void)!fread( bank, bankSize, 1, bin );
595 fwrite( bank, bankSize, 1, sddrive );
596 free(bank);
597 // end = ftell( sddrive )-1;
598
599 // printf( "H -- 0x%4.4x 0x%4.4x | RAM (banco 1)\n", start, end );
600
601 bankSize = 0x4000;
602 // I 0x8300 0xc2ff RAM (banco 2) 0x6000 0x9e00
603 // start = ftell( sddrive );
604 bank = findbank( _environment, 2 );
605 fwrite( bank, bankSize, 1, sddrive );
606 // end = ftell( sddrive )-1;
607
608 // printf( "I -- 0x%4.4x 0x%4.4x | RAM (banco 2)\n", start, end );
609
610 // J 0xc300 0x102ff RAM (banco 3) 0x6000 0x9e00
611 // start = ftell( sddrive );
612 bank = findbank( _environment, 3 );
613 fwrite( bank, bankSize, 1, sddrive );
614 // end = ftell( sddrive )-1;
615
616 // printf( "J -- 0x%4.4x 0x%4.4x | RAM (banco 3)\n", start, end );
617
618 // K 0x10300 0x142ff RAM (banco 4) 0x6000 0x9e00
619 // start = ftell( sddrive );
620 bank = findbank( _environment, 4 );
621 fwrite( bank, bankSize, 1, sddrive );
622 // end = ftell( sddrive )-1;
623
624 // printf( "K -- 0x%4.4x 0x%4.4x | RAM (banco 4)\n", start, end );
625
626 // L 0x14300 0x182ff RAM (banco 5) 0x6000 0x9e00
627 // start = ftell( sddrive );
628 bank = findbank( _environment, 5 );
629 fwrite( bank, bankSize, 1, sddrive );
630 // end = ftell( sddrive )-1;
631
632 // printf( "L -- 0x%4.4x 0x%4.4x | RAM (banco 5)\n", start, end );
633
634 // M 0x18300 0x1c2ff RAM (banco 6) 0x6000 0x9e00
635 // start = ftell( sddrive );
636 bank = findbank( _environment, 6 );
637 fwrite( bank, bankSize, 1, sddrive );
638 // end = ftell( sddrive )-1;
639
640 // printf( "M -- 0x%4.4x 0x%4.4x | RAM (banco 6)\n", start, end );
641
642 // N 0x1c300 0x202ff RAM (banco 7) 0x6000 0x9e00
643 // start = ftell( sddrive );
644 bank = findbank( _environment, 7 );
645 fwrite( bank, bankSize, 1, sddrive );
646 // end = ftell( sddrive )-1;
647
648 // printf( "N -- 0x%4.4x 0x%4.4x | RAM (banco 7)\n", start, end );
649
650 // O 0x20300 0x203ff RAM (banco 1) 0x9e00 0x9fff
651 // start = ftell( sddrive );
652 for( int i=0x20300; i<=0x203ff; ++i ) {
653 char zero = 0;
654 fwrite( &zero, 1, 1, sddrive );;
655 }
656 // end = ftell( sddrive )-1;
657
658 // printf( "O -- 0x%4.4x 0x%4.4x | RAM (banco 1)\n", start, end );
659
660 fclose( sddrive );
661 remove( temporaryFileName );
662
663}
int system_call(Environment *_environment, char *_commandline)
Call an external executable.
char * get_temporary_filename(Environment *_environment)
void target_linkage(Environment *_environment)
Convert C64's assembly to executable.
Definition _build.c:327
void target_cleanup(Environment *_environment)
Definition _build.c:343
void target_analysis(Environment *_environment)
Definition _cleanup.c:68
int size
Definition _optimizer.c:678
Variable * point(Environment *_environment, char *_x, char *_y)
Definition point.c:46
int frmt(Environment *_environment, char *ptr, char size, char *out)
Definition _cleanup.c:59
void end(Environment *_environment)
Emit ASM code for END.
Definition end.c:91
int convertbintok7_original(Environment *_environment)
int convertbintok7(Environment *_environment)
Definition _cleanup.c:120
unsigned char sddrive_restore[]
Definition _build.c:402
unsigned char sddrive_boot_loader[]
Definition _build.c:335
int convertbintosddrive(Environment *_environment)
Definition _build.c:458
int pc128op_convertbintok7_original(Environment *_environment)
Definition _build.c:178
int address
Definition ugbc.h:159
int id
Definition ugbc.h:153
struct _Bank * next
Definition ugbc.h:185
Storage * storage
Definition ugbc.h:2526
char * listingFileName
Definition ugbc.h:2305
int analysis
Definition ugbc.h:2365
char * executerFileName
Definition ugbc.h:2315
OutputFileType outputFileType
Definition ugbc.h:2452
Bank * expansionBanks
Definition ugbc.h:3005
char * profileFileName
Definition ugbc.h:2310
char * asmFileName
Definition ugbc.h:2285
int profileCycles
Definition ugbc.h:2375
char * exeFileName
Definition ugbc.h:2290
int size
Definition ugbc.h:204
char * sourceName
Definition ugbc.h:198
char * content
Definition ugbc.h:210
struct _FileStorage * next
Definition ugbc.h:213
FileStorage * files
Definition ugbc.h:232
void * malloc(YYSIZE_T)
void free(void *)
#define BUILD_TOOLCHAIN_ASM6809_GET_LISTING_FILE(_environment, listingFileName)
Definition ugbc.h:4872
@ OUTPUT_FILE_TYPE_K7_NEW
Definition ugbc.h:262
@ OUTPUT_FILE_TYPE_K7_ORIGINAL
Definition ugbc.h:261
@ OUTPUT_FILE_TYPE_SDDRIVE
Definition ugbc.h:274
#define BUILD_SAFE_REMOVE(_environment, filename)
Definition ugbc.h:4748
#define MAX_TEMPORARY_STORAGE
Definition ugbc.h:563
#define CRITICAL_DLOAD_MISSING_FILE(f)
Definition ugbc.h:3578
#define BUILD_TOOLCHAIN_ASM6809EXEC(_environment, flag, startingAddress, executableName, listingFileName)
Definition ugbc.h:4880
struct _Environment Environment
Structure of compilation environment.
#define CRITICAL_CANNOT_OPEN_EXECUTABLE_FILE(c)
Definition ugbc.h:3520
struct _Storage Storage
Structure of a single storage.
#define CRITICAL_BUILD_INVALID_FILENAME_K7(f)
Definition ugbc.h:3869
struct _FileStorage FileStorage
Structure of a single file inside a storage.
#define BUILD_TOOLCHAIN_ASM6809_GET_EXECUTABLE(_environment, executableName)
Definition ugbc.h:4855
#define BUILD_SAFE_MOVE(_environment, source, destination)
Definition ugbc.h:4751
struct _Bank Bank
Structure of a single bank.
#define CRITICAL_UNSUPPORTED_OUTPUT_FILE_TYPE(t)
Definition ugbc.h:3537
char OUTPUT_FILE_TYPE_AS_STRING[][16]
@ L
Definition ugbc.tab.h:508
char * strcopy(char *_dest, char *_source)