49 deploy( vars2, src_hw_to8_vars2_asm);
52 cpu_label( _environment,
"PC128OPAUDIOSTARTUP" );
91 int p=strcspn(ptr,
point);
111static unsigned char blk[257];
112static void new_blk(
int type)
118static void out_blk(FILE *f)
120 static unsigned char hdr[]={1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0x3c,0x5a};
121 int pos = 2 + blk[1];
123 blk[pos] = 256 - blk[256];
124 fwrite(hdr,
sizeof(hdr), 1, f);
125 fwrite(blk, pos+1, 1, f);
129static void write_byte(FILE *f,
int byte)
131 blk[256] += (
unsigned char)
byte;
132 blk[2 + blk[1]++] =
byte;
133 if(254 == blk[1]) out_blk(f);
135static void write_word(FILE *f,
int word)
137 write_byte(f,
word >> 8);
138 write_byte(f,
word & 255);
140static void write_bytes(FILE *f,
void *array,
int len)
142 unsigned char *ptr = array;
144 while(cnt--) write_byte(f, *ptr++);
149static void addFileEntry( FILE * _handle,
char * _filename,
int _file_type ) {
152 char synchroTO[] = { 0xdc, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x01, 0x3c };
153 fwrite(&synchroTO[0],
sizeof(synchroTO), 1, _handle);
157 fwrite(&blockType, 1, 1, _handle);
160 char blockLen = 0x14;
161 fwrite(&blockLen, 1, 1, _handle);
163 unsigned char checksum = 0x14;
170 for(
int i=0; i<11; ++i ) {
172 fwrite(&_filename[i], 1, 1, _handle);
173 checksum += _filename[i];
177 char fileType = _file_type;
178 fwrite(&fileType, 1, 1, _handle);
179 checksum += fileType;
183 fwrite(&zero, 1, 1, _handle);
187 fwrite(&ff, 1, 1, _handle);
190 for (
int i=0; i<6; ++i ) {
192 fwrite(&zero, 1, 1, _handle);
196 fwrite(&checksum, 1, 1, _handle);
200static int addFileData( FILE * _handle,
unsigned char _bytes[],
int _size,
int _offset ) {
203 int length = _size - _offset;
210 char synchroTO[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x01, 0x3c };
211 fwrite(&synchroTO[0],
sizeof(synchroTO), 1, _handle);
215 fwrite(&blockType, 1, 1, _handle);
218 unsigned char checksum = 0x01;
221 char blockLen = length;
222 fwrite(&blockLen, 1, 1, _handle);
226 for (
int i=_offset; i<_offset+length; i++) {
228 fwrite(&_bytes[i], 1, 1, _handle);
229 checksum += _bytes[i];
233 fwrite(&checksum, 1, 1, _handle);
246static void addBinaryFile( FILE * _handle,
char * _filename,
int _address,
char * _bytes,
int _size ) {
248 addFileEntry( _handle, _filename,
ASM_PRG );
250 unsigned char * fileData =
malloc( _size + 10 );
253 fileData[1] = (_size >> 8);
254 fileData[2] = (_size & 0xff);
255 fileData[3] = (_address >> 8);
256 fileData[4] = (_address & 0xff);
257 for (
int i=0; i<_size; i++) {
258 fileData[i+5] = _bytes[i];
260 fileData[_size+5] = 0xff;
261 fileData[_size+6] = 0x00;
262 fileData[_size+7] = 0x00;
263 fileData[_size+8] = (_address >> 8);
264 fileData[_size+9] = (_address & 0xff);
265 for (
int i=0; i<_size+10;) {
266 i += addFileData( _handle, fileData, (_size+10), i);
270 char synchroTO[] = { 0xdc, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x01, 0x3c };
271 fwrite(&synchroTO[0],
sizeof(synchroTO), 1, _handle);
274 char blockType = 0xff;
275 fwrite(&blockType, 1, 1, _handle);
279 fwrite(&blockLen, 1, 1, _handle);
282 char checksum = 0xff;
283 fwrite(&checksum, 1, 1, _handle);
290 unsigned short start=0x8100;
292 unsigned short runaddr=0x8100;
301 remove( temporaryFileName );
304 fr=fopen(temporaryFileName,
"rb");
310 if(
frmt( _environment,
"main.exe",strlen(
"main.exe"),nome))
315 unsigned char file_type[]={0x02,0x00,0x00};
318 fw=fopen(destin,
"wb");
320 addBinaryFile( fw,
"loader bin", 0xdeff, data_to8_loader_bin, data_to8_loader_bin_len );
322 fr=fopen(temporaryFileName,
"rb");
323 fseek(fr, 0
L, SEEK_END);
327 (void)!fread( fileContent, 1,
size, fr );
330 addBinaryFile( fw, nome, 0x6400, fileContent,
size );
362 sprintf( bankNumber,
"bank%2.2x dat", ( bank->
id ) );
364 addBinaryFile( fw, bankNumber, 0xa000, bank->
data, bank->
address );
378 while( fileStorage ) {
381 sprintf( bankNumber,
"%8sdat", fileStorage->
targetName );
389 memset( buffer, 0,
size );
390 memcpy( buffer, fileStorage->
content, fileStorage->
size );
392 FILE * file = fopen( fileStorage->
sourceName,
"rb" );
396 fseek( file, 0, SEEK_END );
397 size = ftell( file );
398 fseek( file, 0, SEEK_SET );
400 memset( buffer, 0,
size + 2 );
401 (void)!fread( buffer,
size, 1, file );
405 addBinaryFile( fw, bankNumber, 0xa000, buffer,
size );
407 fileStorage = fileStorage->
next;
411 storage = storage->
next;
417 remove(temporaryFileName);
void cpu_label(Environment *_environment, char *_label)
char * get_temporary_filename(Environment *_environment)
void target_finalization(Environment *_environment)
void target_prepare_finalization(Environment *_environment)
void target_analysis(Environment *_environment)
Variable * point(Environment *_environment, char *_x, char *_y)
int frmt(Environment *_environment, char *ptr, char size, char *out)
int convertbintok7(Environment *_environment)
void ef936x_finalization(Environment *_environment)
DataSegment * dataSegment
struct _FileStorage * next
#define MAX_TEMPORARY_STORAGE
#define CRITICAL_DLOAD_MISSING_FILE(f)
struct _Environment Environment
Structure of compilation environment.
#define CRITICAL_CANNOT_OPEN_EXECUTABLE_FILE(c)
struct _Storage Storage
Structure of a single storage.
#define CRITICAL_BUILD_INVALID_FILENAME_K7(f)
struct _FileStorage FileStorage
Structure of a single file inside a storage.
#define BUILD_SAFE_MOVE(_environment, source, destination)
struct _Bank Bank
Structure of a single bank.
char * strcopy(char *_dest, char *_source)