5 Copyright © 1995-2007, The AROS Development Team. All rights reserved.
8 Desc: AROS version of BPTRs
13 # include <exec/types.h>
17 #ifndef AROS_BPTR_TYPE
18 # ifdef AROS_FAST_BPTR
19 # define AROS_BPTR_TYPE APTR
21 # define AROS_BPTR_TYPE IPTR
24 #ifndef AROS_BSTR_TYPE
25 # ifdef AROS_FAST_BSTR
26 # define AROS_BSTR_TYPE STRPTR
28 # define AROS_BSTR_TYPE IPTR
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
48 # define MKBADDR(a) ((BPTR)(a))
49 # define BADDR(a) ((APTR)a)
52 # define MKBADDR(a) ((BPTR)(((IPTR)a)>>2))
53 # define BADDR(a) ((APTR)(((IPTR)a)<<2))
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
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)
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); \
83 # define AROS_BSTR_MEMSIZE4LEN(l) ((l)+2)
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
91 #define AROS_CONST_BSTR(string) ((BSTR)MKBADDR(string))
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);})
99 #endif /* DOS_BPTR_H */