mirror of
https://gitlab.com/rnger/amath
synced 2025-10-05 18:39:41 +00:00
Compare commits
5 Commits
e788fec496
...
master
Author | SHA1 | Date | |
---|---|---|---|
811644f4c7 | |||
d7fe11d56a | |||
d7add409cd | |||
d910b98571 | |||
ea2bf72d7b |
118
src/amath.h
118
src/amath.h
@ -29,104 +29,81 @@
|
||||
|
||||
#ifndef AMATH_H
|
||||
#define AMATH_H
|
||||
/******************************************************************************/
|
||||
#ifdef __AMIGA__
|
||||
# define SYS_NAME "AmigaOS 3"
|
||||
# ifndef AOS3
|
||||
# define AOS3
|
||||
# endif
|
||||
#endif
|
||||
/******************************************************************************/
|
||||
#ifdef __AROS__
|
||||
# define SYS_NAME "Aros"
|
||||
# ifndef AROS
|
||||
# define AROS
|
||||
# endif
|
||||
#endif
|
||||
/******************************************************************************/
|
||||
#ifdef __MORPHOS__
|
||||
|
||||
/* Operating System */
|
||||
#if defined(__MORPHOS__)
|
||||
# define SYS_NAME "MorphOS"
|
||||
# ifndef MORPHOS
|
||||
# define MORPHOS
|
||||
# endif
|
||||
#endif
|
||||
/******************************************************************************/
|
||||
#ifdef __amigaos4__
|
||||
#elif defined(__amigaos4__)
|
||||
# define SYS_NAME "AmigaOS 4"
|
||||
# ifndef AOS4
|
||||
# define AOS4
|
||||
# endif
|
||||
#elif defined(__AMIGA__) || defined(__amigaos3__)
|
||||
# define SYS_NAME "AmigaOS 3"
|
||||
# ifndef AOS3
|
||||
# define AOS3
|
||||
# endif
|
||||
/******************************************************************************/
|
||||
#ifdef __HAIKU__
|
||||
#elif defined(__AROS__)
|
||||
# define SYS_NAME "AROS"
|
||||
# ifndef AROS
|
||||
# define AROS
|
||||
# endif
|
||||
#elif defined(__HAIKU__)
|
||||
# define SYS_NAME "Haiku"
|
||||
# ifndef HAIKU
|
||||
# define HAIKU
|
||||
# endif
|
||||
#endif
|
||||
/******************************************************************************/
|
||||
#ifdef __APPLE__
|
||||
#elif defined(__APPLE__) && defined(__MACH__)
|
||||
# define SYS_NAME "Apple"
|
||||
# ifndef APPLE
|
||||
# define APPLE
|
||||
# endif
|
||||
#endif
|
||||
/******************************************************************************/
|
||||
#ifdef __FreeBSD__
|
||||
#elif defined(__FreeBSD__)
|
||||
# define SYS_NAME "FreeBSD"
|
||||
# ifndef FREEBSD
|
||||
# define FREEBSD
|
||||
# endif
|
||||
#endif
|
||||
/******************************************************************************/
|
||||
#ifdef __NetBSD__
|
||||
#elif defined(__NetBSD__)
|
||||
# define SYS_NAME "NetBSD"
|
||||
# ifndef NETBSD
|
||||
# define NETBSD
|
||||
# endif
|
||||
#endif
|
||||
/******************************************************************************/
|
||||
#ifdef __OpenBSD__
|
||||
#elif defined(__OpenBSD__)
|
||||
# define SYS_NAME "OpenBSD"
|
||||
# ifndef OPENBSD
|
||||
# define OPENBSD
|
||||
# endif
|
||||
#endif
|
||||
/******************************************************************************/
|
||||
#ifdef __DragonFly__
|
||||
#elif defined(__DragonFly__)
|
||||
# define SYS_NAME "DragonFly BSD"
|
||||
# ifndef DRAGONFLY
|
||||
# define DRAGONFLY
|
||||
# endif
|
||||
#endif
|
||||
/******************************************************************************/
|
||||
#ifdef __linux__
|
||||
#elif defined(__linux__)
|
||||
# define SYS_NAME "Linux"
|
||||
# ifndef LINUX
|
||||
# define LINUX
|
||||
# endif
|
||||
#endif
|
||||
/******************************************************************************/
|
||||
#ifdef _WIN32
|
||||
#elif defined(_WIN32)
|
||||
# define SYS_NAME "Windows"
|
||||
# ifndef WINDOWS
|
||||
# define WINDOWS
|
||||
# endif
|
||||
#endif
|
||||
/******************************************************************************/
|
||||
#ifdef _WIN64
|
||||
#elif defined(_WIN64)
|
||||
# define SYS_NAME "Windows 64 bit"
|
||||
# ifndef WINDOWS
|
||||
# define WINDOWS
|
||||
# endif
|
||||
#endif
|
||||
/******************************************************************************/
|
||||
|
||||
#if defined(AOS3) || defined(AOS4) || defined(AROS) || defined (MORPHOS)
|
||||
# ifndef AMIGA
|
||||
# define AMIGA
|
||||
# endif
|
||||
#endif
|
||||
/******************************************************************************/
|
||||
|
||||
#if defined(unix) || defined(__unix__) || defined(__unix)
|
||||
# ifndef UNIX
|
||||
# define UNIX
|
||||
@ -135,7 +112,7 @@
|
||||
# define SYS_NAME "Unix variant"
|
||||
# endif
|
||||
#endif
|
||||
/******************************************************************************/
|
||||
|
||||
#if defined(HAIKU) || defined(UNIX) || defined(APPLE)
|
||||
# ifndef TERMIOS
|
||||
# define TERMIOS
|
||||
@ -143,26 +120,25 @@
|
||||
# include <stdint.h>
|
||||
# include <unistd.h>
|
||||
#endif
|
||||
/******************************************************************************/
|
||||
|
||||
#if defined(WINDOWS)
|
||||
# include <stdint.h>
|
||||
#endif
|
||||
/******************************************************************************/
|
||||
|
||||
#if defined(AROS) || defined(MORPHOS) || defined(AOS4)
|
||||
# include <stdint.h>
|
||||
# include <sys/types.h>
|
||||
#endif
|
||||
/******************************************************************************/
|
||||
|
||||
#if defined(AOS3)
|
||||
# include <sys/types.h>
|
||||
# define IPTR LONG*
|
||||
# define uintptr_t uint32_t
|
||||
typedef u_int8_t uint8_t;
|
||||
typedef u_int16_t uint16_t;
|
||||
typedef u_int32_t uint32_t;
|
||||
typedef u_int64_t uint64_t;
|
||||
#endif
|
||||
/******************************************************************************/
|
||||
|
||||
#if (__cplusplus <= 199711L && !defined(WINDOWS)) || !defined(__cplusplus)
|
||||
# ifndef nullptr
|
||||
# define nullptr 0
|
||||
@ -172,9 +148,9 @@ typedef u_int64_t uint64_t;
|
||||
# define nullptr 0
|
||||
# endif
|
||||
#endif
|
||||
/******************************************************************************/
|
||||
|
||||
#define assert(x)
|
||||
/******************************************************************************/
|
||||
|
||||
/* Compilers */
|
||||
#if defined(__clang__)
|
||||
/* Clang */
|
||||
@ -228,7 +204,9 @@ typedef u_int64_t uint64_t;
|
||||
# elif (_MSC_VER == 1900)
|
||||
# define COMP_VERS "14.0"
|
||||
# elif (_MSC_VER > 1900)
|
||||
# define COMP_VERS "15.0+"
|
||||
# define COMP_VERS "15.x"
|
||||
# elif (_MSC_VER > 1920)
|
||||
# define COMP_VERS "16.0+"
|
||||
# else
|
||||
# define str(x) #x
|
||||
# define MSC_VER_STR(x) str(x)
|
||||
@ -261,11 +239,11 @@ typedef u_int64_t uint64_t;
|
||||
# define COMP_VERS GCC_VER_STR(__GNUC__) DOT GCC_VER_STR(__GNUC_MINOR__)
|
||||
# endif
|
||||
#endif
|
||||
/******************************************************************************/
|
||||
|
||||
#define EMPTYSTRING ""
|
||||
#define SPACE " "
|
||||
#define DOT "."
|
||||
/******************************************************************************/
|
||||
|
||||
#if defined(WINDOWS)
|
||||
#define NEWLINE "\r\n"
|
||||
#elif defined(APPLE)
|
||||
@ -273,17 +251,17 @@ typedef u_int64_t uint64_t;
|
||||
#else
|
||||
#define NEWLINE "\n"
|
||||
#endif
|
||||
/******************************************************************************/
|
||||
|
||||
#ifndef __cplusplus
|
||||
typedef int bool;
|
||||
#define true 1
|
||||
#define false 0
|
||||
#endif
|
||||
/******************************************************************************/
|
||||
|
||||
#define LONG_BIT 32
|
||||
#define wsize sizeof(unsigned int)
|
||||
#define wmask (wsize - 1)
|
||||
/******************************************************************************/
|
||||
|
||||
#if defined(INTELCPU) || defined(i386) || defined(i486) || \
|
||||
defined(intel) || defined(x86) || defined(i86pc) || \
|
||||
defined(__i386__) || defined(_M_IX86)
|
||||
@ -295,18 +273,18 @@ typedef int bool;
|
||||
#if defined(__x86_64__) || defined(_M_AMD64)
|
||||
# define TXTCPU "amd64"
|
||||
#endif
|
||||
/******************************************************************************/
|
||||
|
||||
#if defined(__powerpc__) || defined(__powerpc64__)
|
||||
# define TXTCPU "PowerPC"
|
||||
#endif
|
||||
/******************************************************************************/
|
||||
|
||||
#if defined(__arm__) || defined(_M_ARM) || defined(__ARM_ARCH_6__)
|
||||
# define TXTCPU "arm"
|
||||
#endif
|
||||
#if defined(__aarch64__) || defined(_M_ARM64)
|
||||
# define TXTCPU "arm64"
|
||||
#endif
|
||||
/******************************************************************************/
|
||||
|
||||
#if defined(m68060) || defined(mc68060)
|
||||
# define TXTCPU "68060"
|
||||
#elif defined(m68040) || defined(mc68040)
|
||||
@ -320,33 +298,33 @@ typedef int bool;
|
||||
#elif defined(m68000) || defined(mc68000)
|
||||
# define TXTCPU "68000+"
|
||||
#endif
|
||||
/******************************************************************************/
|
||||
|
||||
#ifndef TXTCPU
|
||||
//#error what cpu is this ?!
|
||||
# define TXTCPU EMPTYSTRING
|
||||
#endif
|
||||
/******************************************************************************/
|
||||
|
||||
#if defined(TXTCPU) && defined(__HAVE_68881__)
|
||||
# define TXTFPU SPACE "FPU"
|
||||
#else
|
||||
# define TXTFPU EMPTYSTRING
|
||||
#endif
|
||||
/******************************************************************************/
|
||||
|
||||
#define TXTARCH TXTCPU TXTFPU
|
||||
#define RELDATESTAMP "(11-01-2021)"
|
||||
#define TXTDOSVERSION "\0$VER: amath 1.90" SPACE RELDATESTAMP SPACE TXTARCH
|
||||
#define TXTTITLE "amath version 1.9.0"
|
||||
#define TXTCOPYRIGHT "(c) 2021 Carsten Sonne Larsen"
|
||||
#define TXTSTARTMSG TXTTITLE SPACE TXTCOPYRIGHT
|
||||
/******************************************************************************/
|
||||
|
||||
#define TXTVERSMSG TXTTITLE SPACE RELDATESTAMP SPACE TXTARCH
|
||||
#define TXTCOMPMSG "Compiled with " COMP_NAME SPACE COMP_VERS
|
||||
/******************************************************************************/
|
||||
|
||||
#ifdef SYS_NAME
|
||||
# define TXTSYSMSG TXTCOMPMSG " for " SYS_NAME
|
||||
# define SYSKNOWN 1
|
||||
#else
|
||||
# define TXTSYSMSG TXTCOMPMSG
|
||||
#endif
|
||||
/******************************************************************************/
|
||||
|
||||
#endif
|
||||
|
@ -35,13 +35,17 @@
|
||||
#include <exec/memory.h>
|
||||
#include <exec/semaphores.h>
|
||||
#include <clib/exec_protos.h>
|
||||
#define ALLOC_MEM(x) AllocVec(x, MEMF_ANY | MEMF_CLEAR)
|
||||
#define FREE_MEM(x) FreeVec(x)
|
||||
#define ALLOC_LIST(x) AllocVec(x, MEMF_ANY | MEMF_CLEAR)
|
||||
#define FREE_LIST(x) FreeVec(x)
|
||||
#define ALLOC_MEM(x, y) AllocPooledZero(x, y)
|
||||
#define FREE_MEM(x, y, z) FreePooled(x, y, z)
|
||||
#define Debug(x, y, z)
|
||||
#else
|
||||
#include <stdlib.h>
|
||||
#define ALLOC_MEM(x) calloc(1L,x)
|
||||
#define FREE_MEM(x) free(x)
|
||||
#define ALLOC_LIST(x) calloc(1L, x)
|
||||
#define FREE_LIST(x) free(x)
|
||||
#define ALLOC_MEM(x, y) calloc(1L, y)
|
||||
#define FREE_MEM(x, y, z) free(y)
|
||||
#define Debug(x, y, z)
|
||||
#endif
|
||||
|
||||
@ -67,6 +71,7 @@ struct MemoryBlock
|
||||
struct MemoryList
|
||||
{
|
||||
struct MemoryBlock *first;
|
||||
void *pool;
|
||||
size_t peak;
|
||||
size_t size;
|
||||
long count;
|
||||
@ -80,6 +85,31 @@ struct MemoryList* list = nullptr;
|
||||
void alloc_error(char *, size_t);
|
||||
void dealloc_error(char *, void *);
|
||||
|
||||
#if defined(AMIGA)
|
||||
|
||||
static void MemZero(void *address, ULONG size)
|
||||
{
|
||||
char *c = (char *)address;
|
||||
int n = size;
|
||||
do
|
||||
{
|
||||
*c++ = '\0';
|
||||
} while (--n);
|
||||
}
|
||||
|
||||
static void *AllocPooledZero(void *pool, size_t size)
|
||||
{
|
||||
ULONG memSize = (ULONG)size;
|
||||
void *memory = AllocPooled(pool, memSize);
|
||||
if (memory != NULL)
|
||||
{
|
||||
MemZero(memory, memSize);
|
||||
}
|
||||
return memory;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Allocate memory and add it to the global memory list.
|
||||
*/
|
||||
@ -90,13 +120,16 @@ void* AllocMemSafe(size_t size)
|
||||
|
||||
if (list == nullptr)
|
||||
{
|
||||
list = (struct MemoryList*)ALLOC_MEM(sizeof(struct MemoryList));
|
||||
list = (struct MemoryList *)ALLOC_LIST(sizeof(struct MemoryList));
|
||||
if (!list)
|
||||
{
|
||||
alloc_error("list", sizeof(struct MemoryList));
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if defined(AMIGA)
|
||||
list->pool = CreatePool(MEMF_ANY, 4096, 512);
|
||||
#endif
|
||||
list->first = nullptr;
|
||||
list->peak = 0;
|
||||
list->size = 0;
|
||||
@ -104,24 +137,24 @@ void* AllocMemSafe(size_t size)
|
||||
}
|
||||
|
||||
#ifdef P64BIT
|
||||
// Align to bytes of 8
|
||||
allocsize = (size + 7) & ~0x07;
|
||||
// Align to bytes of 8, remove 0 bytes allocations
|
||||
allocsize = (size + 8) & ~0x07;
|
||||
#else
|
||||
// Align to bytes of 4
|
||||
allocsize = (size + 3) & ~0x03;
|
||||
// Align to bytes of 4, remove 0 bytes allocations
|
||||
allocsize = (size + 4) & ~0x03;
|
||||
#endif
|
||||
|
||||
newblock = (struct MemoryBlock*)ALLOC_MEM(sizeof(struct MemoryBlock));
|
||||
if (!newblock)
|
||||
newblock = (struct MemoryBlock *)ALLOC_MEM(list->pool, sizeof(struct MemoryBlock));
|
||||
if (newblock == NULL)
|
||||
{
|
||||
alloc_error("block", sizeof(struct MemoryBlock));
|
||||
return 0;
|
||||
}
|
||||
|
||||
newblock->address = (struct MemoryBlock*)ALLOC_MEM(allocsize);
|
||||
if (!newblock->address)
|
||||
newblock->address = (struct MemoryBlock *)ALLOC_MEM(list->pool, allocsize);
|
||||
if (newblock->address == NULL)
|
||||
{
|
||||
FREE_MEM(newblock);
|
||||
FREE_MEM(list->pool, newblock, sizeof(struct MemoryBlock));
|
||||
alloc_error("memory", allocsize);
|
||||
return 0;
|
||||
}
|
||||
@ -185,13 +218,13 @@ void RemoveMemSafe(void* block, bool deallocate)
|
||||
|
||||
if (deallocate)
|
||||
{
|
||||
FREE_MEM(current->address);
|
||||
FREE_MEM(list->pool, current->address, current->size);
|
||||
}
|
||||
|
||||
current->address = nullptr;
|
||||
current->next = nullptr;
|
||||
current->size = 0;
|
||||
FREE_MEM(current);
|
||||
FREE_MEM(list->pool, current, sizeof(struct MemoryBlock));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -227,12 +260,16 @@ void FreeAllSafe()
|
||||
while (current != nullptr)
|
||||
{
|
||||
next = current->next;
|
||||
FREE_MEM(current->address);
|
||||
FREE_MEM(current);
|
||||
FREE_MEM(list->pool, current->address, current->size);
|
||||
FREE_MEM(list->pool, current, sizeof(struct MemoryBlock));
|
||||
current = next;
|
||||
}
|
||||
|
||||
FREE_MEM(list);
|
||||
#if defined(AMIGA)
|
||||
DeletePool(list->pool);
|
||||
#endif
|
||||
|
||||
FREE_LIST(list);
|
||||
list = nullptr;
|
||||
}
|
||||
|
||||
@ -243,7 +280,8 @@ void MemUsage(long* blocks, long* size, long* peak)
|
||||
{
|
||||
*blocks = list->count;
|
||||
*size = (long)list->size;
|
||||
*peak = (long)list->peak;;
|
||||
*peak = (long)list->peak;
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -73,10 +73,10 @@ static struct IntuitionBase *IntuitionBase = nullptr;
|
||||
|
||||
#define ARGS_FORMAT "SHELL/S,NOANSI/S,AREXX/S,INPUT/F"
|
||||
|
||||
#if defined(AOS3)
|
||||
#define RDPTR LONG *
|
||||
#else
|
||||
#if defined(AROS)
|
||||
#define RDPTR IPTR *
|
||||
#else
|
||||
#define RDPTR LONG *
|
||||
#endif
|
||||
|
||||
AmigaProgram::AmigaProgram()
|
||||
|
Reference in New Issue
Block a user