source: trunk/Cosy/incl/defs.h@ 17124

Last change on this file since 17124 was 731, checked in by tbretz, 24 years ago
*** empty log message ***
File size: 2.6 KB
Line 
1/*-----------------------------------------------------------------------------
2defs.h -- Various definitions
3
4Copyright (c) 1994 JANZ Computer AG
5All Rights Reserved
6
7Created 94/10/11 by Soenke Hansen
8Version 1.10 of 97/02/03
9
10Basic type definitions: bytes and words.
11Conversion functions for words (16 bit unsigned).
12
13-----------------------------------------------------------------------------*/
14
15#ifndef defs_DEFINED
16#define defs_DEFINED
17
18#ifdef __cplusplus
19extern "C" {
20#endif
21
22#ifdef OS_9
23#ifdef _UCC
24#define _PARAMS(args) args
25#else
26#ifdef __STDC__
27#define _PARAMS(args) args
28#else
29#define _PARAMS(args) ()
30#endif
31#endif
32#endif
33
34/* Function prototypes by default */
35#ifndef _PARAMS
36#define _PARAMS(args) args
37#endif
38
39/* Use of typedef's or #define's. Some compilers (e.g., Ultra C for OS-9)
40 don't like typedef's in prototype declarations. */
41#ifndef TYPEDEFS
42#define TYPEDEFS 1 /* default is with typedef's */
43#endif
44
45/* Generic object type */
46#if TYPEDEFS == 1
47typedef char * OBJECT;
48#else
49#define OBJECT char * /* known to be dangerous! */
50#endif
51#define NIL_OBJECT (OBJECT)0
52
53/* Return values (BYTE_t) */
54#define SUCCESS 0
55#define FAILURE 0xff
56
57/* Basic data types */
58#if TYPEDEFS == 1
59typedef unsigned char BYTE_t; /* 8 bit unsigned integer */
60typedef unsigned short WORD_t; /* 16 bit unsigned integer */
61typedef unsigned long LWORD_t; /* 32 bit unsigned integer */
62#else
63#define BYTE_t unsigned char
64#define WORD_t unsigned short
65#define LWORD_t unsigned long
66#endif
67
68/* Elaborate data types */
69#ifndef OS_9
70#if TYPEDEFS == 1
71typedef void (*Funcptr)(void); /* Having this makes life easier */
72#endif
73#endif
74
75/* Convert between words and pairs of bytes */
76#define word_read(p, w) ((w) = ((WORD_t)(p)[0] << 8)|((WORD_t)(p)[1]))
77#define word_write(p, w) (((p)[0] = (BYTE_t)((w)>>8)), \
78 ((p)[1] = (BYTE_t)((w)&0x00ff)))
79
80/* Extract bytes from word */
81#define word_to_lsb(w) ((BYTE_t)((w)&0x00ff))
82#define word_to_msb(w) ((BYTE_t)((w)>>8))
83
84/* Assemble bytes into word */
85#define word_from_bytes(lsb, msb) (((WORD_t)(msb) << 8)|((WORD_t)(lsb)))
86
87/* Convert between long word and an array of 4 bytes */
88#define lword_from_bytes(b) ((LWORD_t)(b)[0] + ((LWORD_t)(b)[1] << 8) + \
89 ((LWORD_t)(b)[2] << 16) + ((LWORD_t)(b)[3] << 24))
90#define lword_to_bytes(b, lw) do { (b)[0] = (BYTE_t)(lw); \
91 (b)[1] = (BYTE_t)(lw >> 8); (b)[2] = (BYTE_t)(lw >> 16); \
92 (b)[3] = (BYTE_t)(lw >> 24); } while (0)
93
94
95/* Compare 16 bit words which are assumed to have circular distance < 2^15 */
96#define word_cmp(w1, w2) ((w1) - (w2) <= 0x7fff ? ((w1) == (w2) ? 0 : 1) : (-1))
97
98
99#ifdef __cplusplus
100}
101#endif
102
103#endif /* !defs_DEFINED */
Note: See TracBrowser for help on using the repository browser.