muimaster.library: introduce a hack to make sure up/down arrows always work
[AROS.git] / compiler / include / dos / bptr.h
blob8fc3baf2c9bea0caa8ac892cd83c3586e40ae36a
1 #ifndef DOS_BPTR_H
2 #define DOS_BPTR_H
4 /*
5 Copyright © 1995-2007, The AROS Development Team. All rights reserved.
6 $Id$
8 Desc: AROS version of BPTRs
9 Lang: english
12 #ifndef EXEC_TYPES_H
13 # include <exec/types.h>
14 #endif
17 #ifndef AROS_BPTR_TYPE
18 # ifdef AROS_FAST_BPTR
19 # define AROS_BPTR_TYPE APTR
20 # else
21 # define AROS_BPTR_TYPE IPTR
22 # endif
23 #endif
24 #ifndef AROS_BSTR_TYPE
25 # ifdef AROS_FAST_BSTR
26 # define AROS_BSTR_TYPE STRPTR
27 # else
28 # define AROS_BSTR_TYPE IPTR
29 # endif
30 #endif
32 typedef AROS_BPTR_TYPE BPTR;
33 typedef AROS_BSTR_TYPE BSTR;
35 /* In the BCPL language memory is addressed in chunks of long (e.g. 32 bit) and also
36 * the BPTRs on used by DOS on amigaos used this addressing. This is contrary to byte
37 * (e.g. 8 bit) addressing as is common now for most architectures.
39 * AROS can be configured to have BPTRs also use byte addressing by setting the
40 * AROS_FAST_BPTR preprocessor symbol in the cpu.h file.
41 * For source code compatibility AROS__FAST_BPTR should only be used for non-standard
42 * AROS implementations.
44 * MKBADDR and BADDR macros are defined to access BPTRs in an implementation
45 * independent way.
47 #ifdef AROS_FAST_BPTR
48 # define MKBADDR(a) ((BPTR)(a))
49 # define BADDR(a) ((APTR)a)
50 # define BNULL (NULL)
51 #else
52 # define MKBADDR(a) ((BPTR)(((IPTR)a)>>2))
53 # define BADDR(a) ((APTR)(((IPTR)a)<<2))
54 # define BNULL (0)
55 #endif
57 /* BCPL strings used the first byte as the length of the string followed by the string.
58 * Strings then also had a maximum length of 255. The normal C convention is to have
59 * strings of any length but ended with a byte value of 0
61 * AROS can be configured to have BSTRs implemented as C strings by setting the
62 * AROS_FAST_BSTR preprocessor symbol in the cpu.h file.
63 * For source code compatibility AROS_FAST_BSTR should only be used for non-standard
64 * AROS implementations.
66 * The AROS_BSTR_ADDR, AROS_BSTR_strlen, AROS_BSTR_setstrlen and AROS_BSTR_MEMSIZE4LEN
67 * preprocessor macros are provided to work with BSTRs in an implementation independent
68 * way.
70 #ifdef AROS_FAST_BSTR
71 # define AROS_BSTR_ADDR(s) ((STRPTR)BADDR(s))
72 # define AROS_BSTR_strlen(s) (strlen(AROS_BSTR_ADDR(s)))
73 # define AROS_BSTR_setstrlen(s,l) (AROS_BSTR_ADDR(s)[l] = 0)
74 # define AROS_BSTR_MEMSIZE4LEN(l) ((l)+1)
75 #else
76 # define AROS_BSTR_ADDR(s) (((STRPTR)BADDR(s))+1)
77 # define AROS_BSTR_strlen(s) (AROS_BSTR_ADDR(s)[-1])
78 # define AROS_BSTR_setstrlen(s,l) do { \
79 STRPTR _s = AROS_BSTR_ADDR(s); \
80 _s[-1] = l; \
81 _s[l]=0; \
82 } while(0)
83 # define AROS_BSTR_MEMSIZE4LEN(l) ((l)+2)
84 #endif
85 #define AROS_BSTR_getchar(s,l) (AROS_BSTR_ADDR(s)[l])
86 #define AROS_BSTR_putchar(s,l,c) (AROS_BSTR_ADDR(s)[l] = c)
88 /* Convenience macro for declaring const BSTRs
90 #ifdef AROS_FAST_BSTR
91 #define AROS_CONST_BSTR(string) ((BSTR)MKBADDR(string))
92 #else
93 #define AROS_CONST_BSTR(string) ({ \
94 static const struct { UBYTE len; UBYTE str[sizeof(string)]; } \
95 const __tmp_bstr __attribute__((__aligned__(4)))= { .len = sizeof(string)-1, .str = string }; \
96 (BSTR)MKBADDR(&__tmp_bstr);})
97 #endif
99 #endif /* DOS_BPTR_H */