24 |
/*************************************************************************/ |
/*************************************************************************/ |
25 |
|
|
26 |
|
|
27 |
// Maintained by Detlef Würkner <TetiSoft@apg.lahn.de> |
/* Maintained by Detlef Würkner <TetiSoft@apg.lahn.de> */ |
28 |
|
|
29 |
// TetiSoft: Modified to avoid fopen() fclose() fread() fseek() ftell() |
/* TetiSoft: Modified to avoid fopen() fclose() fread() fseek() ftell() |
30 |
// malloc() realloc() and free() which can't be used in an amiga |
* malloc() realloc() and free(). |
31 |
// shared run-time library linked with libinit.o |
* We need exec V39+ because we use AllocPooled() etc. |
32 |
|
*/ |
|
#include <exec/memory.h> |
|
|
|
|
|
#ifdef __GNUC__ |
|
|
// Avoid warnings "struct X declared inside parameter list" |
|
|
#include <exec/devices.h> |
|
|
#include <exec/io.h> |
|
|
#include <exec/semaphores.h> |
|
|
#include <dos/exall.h> |
|
|
#endif |
|
|
|
|
|
// Necessary with OS3.9 includes |
|
|
#define __USE_SYSBASE |
|
33 |
|
|
34 |
|
#define __NOLIBBASE__ |
35 |
|
#define __NOGLOBALIFACE__ |
36 |
|
#define __USE_INLINE__ |
37 |
#include <proto/exec.h> |
#include <proto/exec.h> |
38 |
|
#include <dos/stdio.h> |
39 |
#include <proto/dos.h> |
#include <proto/dos.h> |
40 |
|
#ifdef __amigaos4__ |
41 |
#ifndef __GNUC__ |
extern struct ExecIFace *IExec; |
42 |
/* TetiSoft: Missing in alib_protos.h, see amiga.lib autodoc |
extern struct DOSIFace *IDOS; |
43 |
* (These amiga.lib functions work under AmigaOS V33 and up) |
#else |
44 |
*/ |
extern struct Library *SysBase; |
45 |
extern APTR __asm |
extern struct Library *DOSBase; |
|
AsmCreatePool( register __d0 ULONG memFlags, |
|
|
register __d1 ULONG puddleSize, |
|
|
register __d2 ULONG threshSize, |
|
|
register __a6 struct ExecBase* SysBase ); |
|
|
|
|
|
extern VOID __asm |
|
|
AsmDeletePool( register __a0 APTR poolHeader, |
|
|
register __a6 struct ExecBase* SysBase ); |
|
|
|
|
|
extern APTR __asm |
|
|
AsmAllocPooled( register __a0 APTR poolHeader, |
|
|
register __d0 ULONG memSize, |
|
|
register __a6 struct ExecBase* SysBase ); |
|
|
|
|
|
extern VOID __asm |
|
|
AsmFreePooled( register __a0 APTR poolHeader, |
|
|
register __a1 APTR memory, |
|
|
register __d0 ULONG memSize, |
|
|
register __a6 struct ExecBase* SysBase); |
|
46 |
#endif |
#endif |
47 |
|
|
48 |
|
#define IOBUF_SIZE 512 |
49 |
|
|
50 |
// TetiSoft: C implementation of AllocVecPooled (see autodoc exec/AllocPooled) |
/* structure that helps us to avoid |
51 |
|
* useless calls of Seek() and Read() |
52 |
|
*/ |
53 |
|
struct SysFile |
54 |
|
{ |
55 |
|
BPTR file; |
56 |
|
ULONG iobuf_start; |
57 |
|
ULONG iobuf_end; |
58 |
|
UBYTE iobuf[IOBUF_SIZE]; |
59 |
|
}; |
60 |
|
|
61 |
|
#ifndef __amigaos4__ |
62 |
|
/* C implementation of AllocVecPooled (see autodoc exec/AllocPooled) */ |
63 |
APTR |
APTR |
64 |
AllocVecPooled( APTR poolHeader, |
Alloc_VecPooled( APTR poolHeader, |
65 |
ULONG memSize ) |
ULONG memSize ) |
66 |
{ |
{ |
67 |
ULONG newSize = memSize + sizeof ( ULONG ); |
ULONG newSize = memSize + sizeof ( ULONG ); |
|
#ifdef __GNUC__ |
|
68 |
ULONG *mem = AllocPooled( poolHeader, newSize ); |
ULONG *mem = AllocPooled( poolHeader, newSize ); |
|
#else |
|
|
ULONG *mem = AsmAllocPooled( poolHeader, newSize, SysBase ); |
|
|
#endif |
|
69 |
|
|
70 |
if ( !mem ) |
if ( !mem ) |
71 |
return NULL; |
return NULL; |
73 |
return mem + 1; |
return mem + 1; |
74 |
} |
} |
75 |
|
|
76 |
|
/* C implementation of FreeVecPooled (see autodoc exec/AllocPooled) */ |
|
// TetiSoft: C implementation of FreeVecPooled (see autodoc exec/AllocPooled) |
|
77 |
void |
void |
78 |
FreeVecPooled( APTR poolHeader, |
Free_VecPooled( APTR poolHeader, |
79 |
APTR memory ) |
APTR memory ) |
80 |
{ |
{ |
81 |
ULONG *realmem = (ULONG *)memory - 1; |
ULONG *realmem = (ULONG *)memory - 1; |
82 |
|
|
|
#ifdef __GNUC__ |
|
83 |
FreePooled( poolHeader, realmem, *realmem ); |
FreePooled( poolHeader, realmem, *realmem ); |
|
#else |
|
|
AsmFreePooled( poolHeader, realmem, *realmem, SysBase ); |
|
|
#endif |
|
84 |
} |
} |
85 |
|
#endif |
86 |
|
|
87 |
#include <ft2build.h> |
#include <ft2build.h> |
88 |
#include FT_CONFIG_CONFIG_H |
#include FT_CONFIG_CONFIG_H |
131 |
ft_alloc( FT_Memory memory, |
ft_alloc( FT_Memory memory, |
132 |
long size ) |
long size ) |
133 |
{ |
{ |
134 |
// FT_UNUSED( memory ); |
#ifdef __amigaos4__ |
|
|
|
|
// return malloc( size ); |
|
135 |
return AllocVecPooled( memory->user, size ); |
return AllocVecPooled( memory->user, size ); |
136 |
|
#else |
137 |
|
return Alloc_VecPooled( memory->user, size ); |
138 |
|
#endif |
139 |
} |
} |
140 |
|
|
141 |
|
|
165 |
long new_size, |
long new_size, |
166 |
void* block ) |
void* block ) |
167 |
{ |
{ |
|
// FT_UNUSED( memory ); |
|
|
// FT_UNUSED( cur_size ); |
|
|
|
|
|
// return realloc( block, new_size ); |
|
|
|
|
168 |
void* new_block; |
void* new_block; |
169 |
|
|
170 |
|
#ifdef __amigaos4__ |
171 |
new_block = AllocVecPooled ( memory->user, new_size ); |
new_block = AllocVecPooled ( memory->user, new_size ); |
172 |
|
#else |
173 |
|
new_block = Alloc_VecPooled ( memory->user, new_size ); |
174 |
|
#endif |
175 |
if ( new_block != NULL ) |
if ( new_block != NULL ) |
176 |
{ |
{ |
177 |
CopyMem ( block, new_block, |
CopyMem ( block, new_block, |
178 |
( new_size > cur_size ) ? cur_size : new_size ); |
( new_size > cur_size ) ? cur_size : new_size ); |
179 |
|
#ifdef __amigaos4__ |
180 |
FreeVecPooled ( memory->user, block ); |
FreeVecPooled ( memory->user, block ); |
181 |
|
#else |
182 |
|
Free_VecPooled ( memory->user, block ); |
183 |
|
#endif |
184 |
} |
} |
185 |
return new_block; |
return new_block; |
186 |
} |
} |
195 |
/* The memory release function. */ |
/* The memory release function. */ |
196 |
/* */ |
/* */ |
197 |
/* <Input> */ |
/* <Input> */ |
198 |
/* memory :: A pointer to the memory object. */ |
/* memory :: A pointer to the memory object. */ |
199 |
/* */ |
/* */ |
200 |
/* block :: The address of block in memory to be freed. */ |
/* block :: The address of block in memory to be freed. */ |
201 |
/* */ |
/* */ |
202 |
FT_CALLBACK_DEF( void ) |
FT_CALLBACK_DEF( void ) |
203 |
ft_free( FT_Memory memory, |
ft_free( FT_Memory memory, |
204 |
void* block ) |
void* block ) |
205 |
{ |
{ |
206 |
// FT_UNUSED( memory ); |
#ifdef __amigaos4__ |
|
|
|
|
// free( block ); |
|
|
|
|
207 |
FreeVecPooled( memory->user, block ); |
FreeVecPooled( memory->user, block ); |
208 |
|
#else |
209 |
|
Free_VecPooled( memory->user, block ); |
210 |
|
#endif |
211 |
} |
} |
212 |
|
|
213 |
|
|
229 |
|
|
230 |
/* We use the macro STREAM_FILE for convenience to extract the */ |
/* We use the macro STREAM_FILE for convenience to extract the */ |
231 |
/* system-specific stream handle from a given FreeType stream object */ |
/* system-specific stream handle from a given FreeType stream object */ |
232 |
// #define STREAM_FILE( stream ) ( (FILE*)stream->descriptor.pointer ) |
#define STREAM_FILE( stream ) ( (struct SysFile *)stream->descriptor.pointer ) |
|
#define STREAM_FILE( stream ) ( (BPTR)stream->descriptor.pointer ) // TetiSoft |
|
233 |
|
|
234 |
|
|
235 |
/*************************************************************************/ |
/*************************************************************************/ |
236 |
/* */ |
/* */ |
237 |
/* <Function> */ |
/* <Function> */ |
238 |
/* ft_close_stream */ |
/* ft_amiga_stream_close */ |
239 |
/* */ |
/* */ |
240 |
/* <Description> */ |
/* <Description> */ |
241 |
/* The function to close a stream. */ |
/* The function to close a stream. */ |
244 |
/* stream :: A pointer to the stream object. */ |
/* stream :: A pointer to the stream object. */ |
245 |
/* */ |
/* */ |
246 |
FT_CALLBACK_DEF( void ) |
FT_CALLBACK_DEF( void ) |
247 |
ft_close_stream( FT_Stream stream ) |
ft_amiga_stream_close( FT_Stream stream ) |
248 |
{ |
{ |
249 |
// fclose( STREAM_FILE( stream ) ); |
struct SysFile* sysfile; |
250 |
Close( STREAM_FILE( stream ) ); // TetiSoft |
|
251 |
|
sysfile = STREAM_FILE( stream ); |
252 |
|
Close ( sysfile->file ); |
253 |
|
FreeMem ( sysfile, sizeof ( struct SysFile )); |
254 |
|
|
255 |
stream->descriptor.pointer = NULL; |
stream->descriptor.pointer = NULL; |
256 |
stream->size = 0; |
stream->size = 0; |
261 |
/*************************************************************************/ |
/*************************************************************************/ |
262 |
/* */ |
/* */ |
263 |
/* <Function> */ |
/* <Function> */ |
264 |
/* ft_io_stream */ |
/* ft_amiga_stream_io */ |
265 |
/* */ |
/* */ |
266 |
/* <Description> */ |
/* <Description> */ |
267 |
/* The function to open a stream. */ |
/* The function to open a stream. */ |
279 |
/* The number of bytes actually read. */ |
/* The number of bytes actually read. */ |
280 |
/* */ |
/* */ |
281 |
FT_CALLBACK_DEF( unsigned long ) |
FT_CALLBACK_DEF( unsigned long ) |
282 |
ft_io_stream( FT_Stream stream, |
ft_amiga_stream_io( FT_Stream stream, |
283 |
unsigned long offset, |
unsigned long offset, |
284 |
unsigned char* buffer, |
unsigned char* buffer, |
285 |
unsigned long count ) |
unsigned long count ) |
286 |
{ |
{ |
287 |
// FILE* file; |
struct SysFile* sysfile; |
288 |
BPTR file; // TetiSoft |
unsigned long read_bytes; |
289 |
|
|
290 |
|
if ( count != 0 ) |
291 |
|
{ |
292 |
|
sysfile = STREAM_FILE( stream ); |
293 |
|
|
294 |
file = STREAM_FILE( stream ); |
/* handle the seek */ |
295 |
|
if ( (offset < sysfile->iobuf_start) || (offset + count > sysfile->iobuf_end) ) |
296 |
|
{ |
297 |
|
/* requested offset implies we need a buffer refill */ |
298 |
|
if ( !sysfile->iobuf_end || offset != (sysfile->iobuf_end + 1) ) |
299 |
|
{ |
300 |
|
/* a physical seek is necessary */ |
301 |
|
Seek( sysfile->file, offset, OFFSET_BEGINNING ); |
302 |
|
} |
303 |
|
sysfile->iobuf_start = offset; |
304 |
|
sysfile->iobuf_end = 0; /* trigger a buffer refill */ |
305 |
|
} |
306 |
|
|
307 |
// fseek( file, offset, SEEK_SET ); |
/* handle the read */ |
308 |
Seek( file, offset, OFFSET_BEGINNING ); // TetiSoft |
if ( offset + count <= sysfile->iobuf_end ) |
309 |
|
{ |
310 |
|
/* we have buffer and requested bytes are all inside our buffer */ |
311 |
|
CopyMem( &sysfile->iobuf[offset - sysfile->iobuf_start], buffer, count ); |
312 |
|
read_bytes = count; |
313 |
|
} |
314 |
|
else |
315 |
|
{ |
316 |
|
/* (re)fill buffer */ |
317 |
|
if ( count <= IOBUF_SIZE ) |
318 |
|
{ |
319 |
|
/* requested bytes is a subset of the buffer */ |
320 |
|
read_bytes = Read( sysfile->file, sysfile->iobuf, IOBUF_SIZE ); |
321 |
|
if ( read_bytes == -1UL ) |
322 |
|
{ |
323 |
|
/* error */ |
324 |
|
read_bytes = 0; |
325 |
|
} |
326 |
|
else |
327 |
|
{ |
328 |
|
sysfile->iobuf_end = offset + read_bytes; |
329 |
|
CopyMem( sysfile->iobuf, buffer, count ); |
330 |
|
if ( read_bytes > count ) |
331 |
|
{ |
332 |
|
read_bytes = count; |
333 |
|
} |
334 |
|
} |
335 |
|
} |
336 |
|
else |
337 |
|
{ |
338 |
|
/* we actually need more than our buffer can hold, so we decide |
339 |
|
** to do a single big read, and then copy the last IOBUF_SIZE |
340 |
|
** bytes of that to our internal buffer for later use */ |
341 |
|
read_bytes = Read( sysfile->file, buffer, count ); |
342 |
|
if ( read_bytes == -1UL ) |
343 |
|
{ |
344 |
|
/* error */ |
345 |
|
read_bytes = 0; |
346 |
|
} |
347 |
|
else |
348 |
|
{ |
349 |
|
ULONG bufsize; |
350 |
|
|
351 |
|
bufsize = ( read_bytes > IOBUF_SIZE ) ? IOBUF_SIZE : read_bytes; |
352 |
|
sysfile->iobuf_end = offset + read_bytes - bufsize; |
353 |
|
sysfile->iobuf_start = sysfile->iobuf_end - bufsize; |
354 |
|
CopyMem( &buffer[read_bytes - bufsize] , sysfile->iobuf, bufsize ); |
355 |
|
} |
356 |
|
} |
357 |
|
} |
358 |
|
} |
359 |
|
else |
360 |
|
{ |
361 |
|
read_bytes = 0; |
362 |
|
} |
363 |
|
|
364 |
// return (unsigned long)fread( buffer, 1, count, file ); |
return read_bytes; |
|
return (unsigned long)FRead( file, buffer, 1, count); |
|
365 |
} |
} |
366 |
|
|
367 |
|
|
371 |
FT_Stream_Open( FT_Stream stream, |
FT_Stream_Open( FT_Stream stream, |
372 |
const char* filepathname ) |
const char* filepathname ) |
373 |
{ |
{ |
374 |
// FILE* file; |
struct FileInfoBlock* fib; |
375 |
BPTR file; // TetiSoft |
struct SysFile* sysfile; |
|
struct FileInfoBlock* fib; // TetiSoft |
|
376 |
|
|
377 |
|
|
378 |
if ( !stream ) |
if ( !stream ) |
379 |
return FT_Err_Invalid_Stream_Handle; |
return FT_Err_Invalid_Stream_Handle; |
380 |
|
|
381 |
// file = fopen( filepathname, "rb" ); |
#ifdef __amigaos4__ |
382 |
file = Open( filepathname, MODE_OLDFILE ); // TetiSoft |
sysfile = AllocMem ( sizeof (struct SysFile ), MEMF_SHARED ); |
383 |
if ( !file ) |
#else |
384 |
|
sysfile = AllocMem ( sizeof (struct SysFile ), MEMF_PUBLIC ); |
385 |
|
#endif |
386 |
|
if ( !sysfile ) |
387 |
{ |
{ |
388 |
FT_ERROR(( "FT_Stream_Open:" )); |
FT_ERROR(( "FT_Stream_Open:" )); |
389 |
FT_ERROR(( " could not open `%s'\n", filepathname )); |
FT_ERROR(( " could not open `%s'\n", filepathname )); |
390 |
|
|
391 |
return FT_Err_Cannot_Open_Resource; |
return FT_Err_Cannot_Open_Resource; |
392 |
} |
} |
393 |
|
sysfile->file = Open( (STRPTR)filepathname, MODE_OLDFILE ); |
394 |
|
if ( !sysfile->file ) |
395 |
|
{ |
396 |
|
FreeMem ( sysfile, sizeof ( struct SysFile )); |
397 |
|
FT_ERROR(( "FT_Stream_Open:" )); |
398 |
|
FT_ERROR(( " could not open `%s'\n", filepathname )); |
399 |
|
|
400 |
|
return FT_Err_Cannot_Open_Resource; |
401 |
|
} |
402 |
|
|
|
// fseek( file, 0, SEEK_END ); |
|
|
// astream->size = ftell( file ); |
|
|
// fseek( file, 0, SEEK_SET ); |
|
403 |
fib = AllocDosObject( DOS_FIB, NULL ); |
fib = AllocDosObject( DOS_FIB, NULL ); |
404 |
if ( !fib ) |
if ( !fib ) |
405 |
{ |
{ |
406 |
Close ( file ); |
Close ( sysfile->file ); |
407 |
|
FreeMem ( sysfile, sizeof ( struct SysFile )); |
408 |
FT_ERROR(( "FT_Stream_Open:" )); |
FT_ERROR(( "FT_Stream_Open:" )); |
409 |
FT_ERROR(( " could not open `%s'\n", filepathname )); |
FT_ERROR(( " could not open `%s'\n", filepathname )); |
410 |
|
|
411 |
return FT_Err_Cannot_Open_Resource; |
return FT_Err_Cannot_Open_Resource; |
412 |
} |
} |
413 |
if ( !( ExamineFH( file, fib ) ) ) |
if ( !( ExamineFH( sysfile->file, fib ) ) ) |
414 |
{ |
{ |
415 |
FreeDosObject( DOS_FIB, fib ); |
FreeDosObject( DOS_FIB, fib ); |
416 |
Close ( file ); |
Close ( sysfile->file ); |
417 |
|
FreeMem ( sysfile, sizeof ( struct SysFile )); |
418 |
FT_ERROR(( "FT_Stream_Open:" )); |
FT_ERROR(( "FT_Stream_Open:" )); |
419 |
FT_ERROR(( " could not open `%s'\n", filepathname )); |
FT_ERROR(( " could not open `%s'\n", filepathname )); |
420 |
|
|
423 |
stream->size = fib->fib_Size; |
stream->size = fib->fib_Size; |
424 |
FreeDosObject( DOS_FIB, fib ); |
FreeDosObject( DOS_FIB, fib ); |
425 |
|
|
426 |
// stream->descriptor.pointer = file; |
stream->descriptor.pointer = (void *)sysfile; |
|
stream->descriptor.pointer = (void *)file; |
|
|
|
|
427 |
stream->pathname.pointer = (char*)filepathname; |
stream->pathname.pointer = (char*)filepathname; |
428 |
|
sysfile->iobuf_start = 0; |
429 |
|
sysfile->iobuf_end = 0; |
430 |
stream->pos = 0; |
stream->pos = 0; |
431 |
|
|
432 |
stream->read = ft_io_stream; |
stream->read = ft_amiga_stream_io; |
433 |
stream->close = ft_close_stream; |
stream->close = ft_amiga_stream_close; |
434 |
|
|
435 |
FT_TRACE1(( "FT_Stream_Open:" )); |
FT_TRACE1(( "FT_Stream_Open:" )); |
436 |
FT_TRACE1(( " opened `%s' (%d bytes) successfully\n", |
FT_TRACE1(( " opened `%s' (%ld bytes) successfully\n", |
437 |
filepathname, stream->size )); |
filepathname, stream->size )); |
438 |
|
|
439 |
return FT_Err_Ok; |
return FT_Err_Ok; |
447 |
|
|
448 |
extern void |
extern void |
449 |
ft_mem_debug_done( FT_Memory memory ); |
ft_mem_debug_done( FT_Memory memory ); |
450 |
|
|
451 |
#endif |
#endif |
452 |
|
|
453 |
|
|
459 |
FT_Memory memory; |
FT_Memory memory; |
460 |
|
|
461 |
|
|
462 |
// memory = (FT_Memory)malloc( sizeof ( *memory ) ); |
#ifdef __amigaos4__ |
463 |
|
memory = (FT_Memory)AllocVec( sizeof ( *memory ), MEMF_SHARED ); |
464 |
|
#else |
465 |
memory = (FT_Memory)AllocVec( sizeof ( *memory ), MEMF_PUBLIC ); |
memory = (FT_Memory)AllocVec( sizeof ( *memory ), MEMF_PUBLIC ); |
466 |
|
#endif |
467 |
if ( memory ) |
if ( memory ) |
468 |
{ |
{ |
469 |
// memory->user = 0; |
#ifdef __amigaos4__ |
470 |
#ifdef __GNUC__ |
memory->user = CreatePool( MEMF_SHARED, 16384, 16384 ); |
|
memory->user = CreatePool( MEMF_PUBLIC, 2048, 2048 ); |
|
471 |
#else |
#else |
472 |
memory->user = AsmCreatePool( MEMF_PUBLIC, 2048, 2048, SysBase ); |
memory->user = CreatePool( MEMF_PUBLIC, 16384, 16384 ); |
473 |
#endif |
#endif |
474 |
if ( memory->user == NULL ) |
if ( memory->user == NULL ) |
475 |
{ |
{ |
483 |
memory->free = ft_free; |
memory->free = ft_free; |
484 |
#ifdef FT_DEBUG_MEMORY |
#ifdef FT_DEBUG_MEMORY |
485 |
ft_mem_debug_init( memory ); |
ft_mem_debug_init( memory ); |
486 |
#endif |
#endif |
487 |
} |
} |
488 |
} |
} |
489 |
|
|
498 |
{ |
{ |
499 |
#ifdef FT_DEBUG_MEMORY |
#ifdef FT_DEBUG_MEMORY |
500 |
ft_mem_debug_done( memory ); |
ft_mem_debug_done( memory ); |
501 |
#endif |
#endif |
502 |
|
|
|
#ifdef __GNUC__ |
|
503 |
DeletePool( memory->user ); |
DeletePool( memory->user ); |
|
#else |
|
|
AsmDeletePool( memory->user, SysBase ); |
|
|
#endif |
|
504 |
FreeVec( memory ); |
FreeVec( memory ); |
505 |
} |
} |
506 |
|
|
|
|
|
507 |
/* END */ |
/* END */ |