added concrete implementations of putc(), getc(), getchar() and gets()
[tangerine.git] / compiler / include / dos / bptr.h
blob8e9e2b6e76d9a169b77b1b12cf105b0696a0e7b3
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 #else
51 # define MKBADDR(a) ((BPTR)(((IPTR)a)>>2))
52 # define BADDR(a) ((APTR)(((IPTR)a)<<2))
53 #endif
55 /* BCPL strings used the first byte as the length of the string followed by the string.
56 * Strings then also had a maximum length of 255. The normal C convention is to have
57 * strings of any length but ended with a byte value of 0
59 * AROS can be configured to have BSTRs implemented as C strings by setting the
60 * AROS_FAST_BSTR preprocessor symbol in the cpu.h file.
61 * For source code compatibility AROS_FAST_BSTR should only be used for non-standard
62 * AROS implementations.
64 * The AROS_BSTR_ADDR, AROS_BSTR_strlen, AROS_BSTR_setstrlen and AROS_BSTR_MEMSIZE4LEN
65 * preprocessor macros are provided to work with BSTRs in an implementation independent
66 * way.
68 #ifdef AROS_FAST_BSTR
69 # define AROS_BSTR_ADDR(s) ((STRPTR)BADDR(s))
70 # define AROS_BSTR_strlen(s) (strlen(AROS_BSTR_ADDR(s)))
71 # define AROS_BSTR_setstrlen(s,l) (AROS_BSTR_ADDR(s)[l] = 0)
72 # define AROS_BSTR_MEMSIZE4LEN(l) ((l)+1)
73 #else
74 # define AROS_BSTR_ADDR(s) (((STRPTR)BADDR(s))+1)
75 # define AROS_BSTR_strlen(s) (AROS_BSTR_ADDR(s)[-1])
76 # define AROS_BSTR_setstrlen(s,l) do { \
77 STRPTR _s = AROS_BSTR_ADDR(s); \
78 _s[-1] = l; \
79 _s[l]=0; \
80 } while(0)
81 # define AROS_BSTR_MEMSIZE4LEN(l) ((l)+2)
82 #endif
83 #define AROS_BSTR_getchar(s,l) (AROS_BSTR_ADDR(s)[l])
84 #define AROS_BSTR_putchar(s,l,c) (AROS_BSTR_ADDR(s)[l] = c)
86 #endif /* DOS_BPTR_H */