ugBASIC 1.18
An isomorphic BASIC language compiler for retrocomputers
Loading...
Searching...
No Matches
_cleanup.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
42
43 if ( _environment->deployed.tiles ) {
44
45 } else {
46 variable_delete( _environment, "TILEX" );
47 variable_delete( _environment, "TILEY" );
48 variable_delete( _environment, "TILEX2" );
49 variable_delete( _environment, "TILET" );
50 variable_delete( _environment, "TILEW" );
51 variable_delete( _environment, "TILEH" );
52 variable_delete( _environment, "TILEW2" );
53 variable_delete( _environment, "TILEH2" );
54 variable_delete( _environment, "TILEA" );
55 variable_delete( _environment, "TILEO" );
56 }
57
58 if ( _environment->deployed.blitimage ) {
59
60 } else {
61 variable_delete( _environment, "BLITIMAGEBLITTINGADDR" );
62 variable_delete( _environment, "BLITTMPPTR" );
63 variable_delete( _environment, "BLITTMPPTR2" );
64 }
65
66 if ( _environment->deployed.sliceimageextract ) {
67
68 } else {
69 variable_delete( _environment, "SLICEX" );
70 variable_delete( _environment, "SLICEY" );
71 variable_delete( _environment, "SLICEDTARGET" );
72 }
73
74}
75
76void target_finalization( Environment * _environment ) {
77
78 ef9345_finalization( _environment );
79
80 if ( ! _environment->anyProtothread ) {
81 outhead0("PROTOTHREADINIT:" );
82 outline0("RET");
83 }
84
85}
86
87// -------------------------------------------------------------------------
88// CONVERT BINARY TO K7 TAPE FILE
89// -------------------------------------------------------------------------
90
91#include<stdlib.h>
92#include<stdio.h>
93#include<math.h>
94
95int convertbintok7(Environment * _environment)
96{
97 unsigned short start=0x3000;
98 unsigned short size;
99 unsigned short runaddr=0x3000;
100 FILE *fr,*fw;
101 char nome[12];
102 char source[20];
103 char destin[100];
104
105 // Rename the output file into a temporary filename
106 char temporaryFileName[MAX_TEMPORARY_STORAGE];
107 sprintf(temporaryFileName, "%s.bin", get_temporary_filename( _environment ) );
108 remove( temporaryFileName );
109 BUILD_SAFE_MOVE( _environment, _environment->exeFileName, temporaryFileName );
110
111 fr=fopen(temporaryFileName,"rb");
112 if(!fr)
113 {
114 CRITICAL_CANNOT_OPEN_EXECUTABLE_FILE( temporaryFileName );
115 }
116
117 fr=fopen(temporaryFileName,"rb");
118
119 strcopy(destin,_environment->exeFileName);
120 fw=fopen(destin,"wb");
121
122 fseek(fr, 0L, SEEK_END);
123 size = ftell(fr);
124 rewind(fr);
125
126 unsigned char header[] = {
127 0xd3, 0xd3, 0xd3, 0xd3, 0xd3, 0xd3, 0xd3, 0xd3,
128 0xd3, 0xd3, 0x4d, 'm', 'a', 'i', 'n', 0x00,
129 0x00, 0x00, 0x31, 0x30, 0x00, 0x00, 0x00, 0x00,
130 0x00, 0x00, 0xfb, 0x49, 0x00, 0x00, 0x00, 0x00,
131 0x00, 0xd6, 0xd6, 0xd6, 0xd6, 0xd6, 0xd6, 0xd6,
132 0xd6, 0xd6, 0xd6
133 };
134
135 unsigned char basic[] = {
136 0x00, 0x08, 0x4a, 0x0a, 0x00,
137 0x9f, 0x31, 0x38, 0x39, 0x35,
138 0x34, 0x3a, 0x00, 0x00, 0x00
139 };
140
141 int length = size + sizeof( basic );
142 int checksum = 0;
143
144 for( int i=0; i<sizeof(basic); ++i ) {
145 checksum += basic[i];
146 }
147
148 for( int i=0; i<size; ++i ) {
149 unsigned char c = (unsigned char) fgetc(fr);
150 checksum += c;
151 }
152
153 header[28] = ( length & 0xff );
154 header[29] = ( ( length>>8) & 0xff );
155 header[30] = ( checksum & 0xff );
156 header[31] = ( ( checksum >> 8 ) & 0xff );
157
158 fwrite( header, sizeof( header ), 1, fw );
159 fwrite( basic, sizeof( basic ), 1, fw );
160
161 fseek( fr, 0, SEEK_SET );
162 for( int i=0; i<size; ++i ) {
163 unsigned char c = (unsigned char) fgetc(fr);
164 fputc(c, fw);
165 }
166 fputc(0, fw);
167 fputc(0, fw);
168 fputc(0, fw);
169 fputc(0, fw);
170 fputc(0, fw);
171 fputc(0, fw);
172 fputc(0, fw);
173 fputc(0, fw);
174 fputc(0, fw);
175 fputc(0, fw);
176 fputc(0, fw);
177 fputc(0, fw);
178 fputc(0, fw);
179 fputc(0, fw);
180 fputc(0, fw);
181
182 fclose(fr);
183 fclose(fw);
184
185 return 0;
186}
187
188void target_analysis( Environment * _environment ) {
189
190}
int variable_delete(Environment *_environment, char *_name)
char * get_temporary_filename(Environment *_environment)
void target_finalization(Environment *_environment)
Definition _cleanup.c:45
void target_prepare_finalization(Environment *_environment)
Definition _cleanup.c:41
void target_analysis(Environment *_environment)
Definition _cleanup.c:68
int size
Definition _optimizer.c:678
int convertbintok7(Environment *_environment)
Definition _cleanup.c:120
void ef9345_finalization(Environment *_environment)
Definition ef9345.c:883
int tiles
Definition ugbc.h:1824
int sliceimageextract
Definition ugbc.h:1822
int blitimage
Definition ugbc.h:1820
int anyProtothread
Definition ugbc.h:2835
char * exeFileName
Definition ugbc.h:2290
Deployed deployed
Definition ugbc.h:2921
#define MAX_TEMPORARY_STORAGE
Definition ugbc.h:563
struct _Environment Environment
Structure of compilation environment.
#define CRITICAL_CANNOT_OPEN_EXECUTABLE_FILE(c)
Definition ugbc.h:3520
#define outhead0(s)
Definition ugbc.h:4246
#define outline0(s)
Definition ugbc.h:4252
#define BUILD_SAFE_MOVE(_environment, source, destination)
Definition ugbc.h:4751
@ L
Definition ugbc.tab.h:508
char * strcopy(char *_dest, char *_source)