demOS
Main Page
Modules
Data Structures
Files
File List
All
Data Structures
Files
Modules
Pages
DEMOSDK
BASTYPES.H
Go to the documentation of this file.
1
/*------------------------------------------------------------------------------ --------------
2
Copyright J.Hubert 2015
3
4
This file is part of demOS
5
6
demOS is free software: you can redistribute it and/or modify it under the terms of
7
the GNU Lesser General Public License as published by the Free Software Foundation,
8
either version 3 of the License, or (at your option) any later version.
9
10
demOS is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY ;
11
without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
See the GNU Lesser General Public License for more details.
13
14
You should have received a copy of the GNU Lesser General Public License along with demOS.
15
If not, see <http://www.gnu.org/licenses/>.
16
-----------------------------------------------------------------------------------------------*/
17
27
#ifndef BASTYPES_H
28
#define BASTYPES_H
29
30
/* #define DEMOS_OPTIMIZED */
/* enforce optimization */
31
32
/* Configuration */
33
#ifndef __TOS__
34
# define DEMOS_LOAD_FROMHD
35
#endif
36
37
#ifdef DEMOS_OPTIMIZED
38
39
# define IGNORE_PARAM(NAME)
40
# define STATIC_ASSERT(COND)
41
42
#else
43
44
# define DEMOS_DEBUG
45
# define DEMOS_ASSERT
46
/*# define DEMOS_ALLOW_DEBUGGER */
47
/*# define DEMOS_LOAD_FROMHD */
48
49
# if defined(DEMOS_ASSERT) && defined(DEMOS_DEBUG)
50
# define DEMOS_UNITTEST
51
# endif
52
53
# define IGNORE_PARAM(NAME) NAME = NAME;
54
# define STATIC_ASSERT(COND) typedef char static_assertion##__LINE__[(COND)?1:-1]
55
56
#endif
57
58
#ifndef DEMOS_INVERT_DRIVE
59
# define DEMOS_INVERT_DRIVE 0
60
#endif
61
62
/* OS standards */
63
#if !defined(DEMOS_OPTIMIZED) || !defined(__TOS__)
64
# ifndef __TOS__
65
# define _CRT_SECURE_NO_WARNINGS
66
# include <assert.h>
67
# endif
68
# include <stdio.h>
69
# include <stdlib.h>
70
# include <string.h>
71
#endif
72
73
/* constructs */
74
#define ENUM(NAME) typedef enum NAME##_ NAME; enum NAME##_
75
#define PREDECLARE_STRUCT(NAME) typedef struct NAME##_ NAME
76
#define STRUCT(NAME) PREDECLARE_STRUCT(NAME); struct NAME##_
77
#define UNION(NAME) typedef union NAME##_ NAME; union NAME##_
78
79
#define DEFAULT_CONSTRUCT(INSTANCE_PTR) STDmset(INSTANCE_PTR,0,sizeof(*INSTANCE_PTR));
80
81
/* basic types */
82
typedef
signed
char
s8;
83
typedef
unsigned
char
u8;
84
typedef
short
s16;
85
typedef
unsigned
short
u16;
86
typedef
long
s32;
87
typedef
unsigned
long
u32;
88
89
#ifndef __cplusplus
90
typedef
u8 bool;
91
# define false 0
92
# define true 1
93
#endif
94
95
#ifndef ARRAYSIZE
96
# define ARRAYSIZE(TAB) (sizeof(TAB) / sizeof(*TAB))
97
#endif
98
99
#ifndef NULL
100
# define NULL ((void*)0)
101
#endif
102
103
#define U16_SIZEOF_SHIFT 1
104
#define U32_SIZEOF_SHIFT 2
105
106
/* endian swap */
107
#ifdef __TOS__
108
# define PCENDIANSWAP16(V) V
109
# define PCENDIANSWAP32(V) V
110
# define PCSTUB
111
# define PCSTUBRET
112
# define ASMIMPORT extern
113
#else
114
# define PCENDIANSWAP16(V) STDswap16(V)
115
# define PCENDIANSWAP32(V) STDswap32(V)
116
# define PCSTUB {}
117
# define PCSTUBRET { return 0; }
118
# define ASMIMPORT
119
#endif
120
121
/* memory allocator interface */
122
typedef
void
* (*MEMallocFunc)(
void
* _allocator, u32 _size);
123
typedef
void (*MEMfreeFunc)(
void
* _allocator,
void
* _adr);
124
125
STRUCT(
MEMallocator
)
126
{
127
void
* allocator;
128
MEMallocFunc alloc;
129
MEMfreeFunc free;
130
};
131
132
#define MEM_ALLOC(ALLOCATOR,SIZE) (ALLOCATOR)->alloc((ALLOCATOR)->allocator,(SIZE))
133
#define MEM_FREE(ALLOCATOR,ADR) (ALLOCATOR)->free((ALLOCATOR)->allocator,(ADR))
134
135
#define MEM_ALLOC_STRUCT(ALLOCATOR,NAME) (NAME*) (ALLOCATOR)->alloc((ALLOCATOR)->allocator, sizeof(NAME))
136
137
/* assertion */
138
#ifdef __TOS__
139
# ifdef DEMOS_ASSERT
140
void
SYSassert(
char
* _message,
char
* _file,
int
_line);
141
# define ASSERT(A) if (!(A)) { SYSassert(#A, __FILE__, __LINE__); }
142
# else
143
# define ASSERT(A)
144
# endif
145
#else
146
# define ASSERT(A) assert(A)
147
#endif
148
149
#endif
MEMallocator
Definition:
BASTYPES.H:125
Generated on Fri Jun 26 2015 22:07:59 for demOS by
1.8.8