File: pasmotypes.h

package info (click to toggle)
pasmo 0.5.3-4
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 892 kB
  • ctags: 1,805
  • sloc: cpp: 8,508; asm: 3,020; sh: 790; makefile: 627
file content (114 lines) | stat: -rw-r--r-- 1,974 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#ifndef INCLUDE_PASMOTYPES_H
#define INCLUDE_PASMOTYPES_H

// pasmotypes.h
// Revision 8-dec-2004

#include <string>
#include <iostream>

#include <limits.h>
#include <stdlib.h>


#if USHRT_MAX == 65535

typedef unsigned short address;

#else

// Using the C99 types, hoping they will be available.

#include <stdint.h>

typedef uint16_t address:

#endif

#if UCHAR_MAX == 255

typedef unsigned char byte;
typedef signed char sbyte;

#else

#include <stdint.h>

typedef uint8_t byte;
typedef int8_t sbyte;

#endif

inline byte lobyte (address n)
{
	return static_cast <byte> (n & 0xFF);
}

inline byte hibyte (address n)
{
	return static_cast <byte> (n >> 8);
}

inline void putword (std::ostream & os, address word)
{
	os.put (lobyte (word) );
	os.put (hibyte (word) );
}

std::string hex2str (byte b);
std::string hex4str (address n);
std::string hex8str (size_t nn);

inline std::string hex2str (sbyte b)
{ return hex2str (static_cast <byte> (b) ); }
inline std::string hex2str (char b)
{ return hex2str (static_cast <byte> (b) ); }


class Hex2 {
public:
	Hex2 (byte b) : b (b)
	{ }
	byte getb () const
	{ return b; }
	std::string str () const;
private:
	byte b;
};

class Hex4 {
public:
	Hex4 (address n) : n (n)
	{ }
	address getn () const
	{ return n; }
	std::string str () const;
private:
	address n;
};

class Hex8 {
public:
	Hex8 (size_t nn) : nn (nn)
	{ }
	size_t getnn () const
	{ return nn; }
	std::string str () const;
private:
	size_t nn;
};

inline Hex2 hex2 (byte b) { return Hex2 (b); }
inline Hex2 hex2 (sbyte b) { return Hex2 (static_cast <byte> (b) ); }
inline Hex2 hex2 (char b) { return Hex2 (static_cast <byte> (b) ); }
inline Hex4 hex4 (address n) { return Hex4 (n); }
inline Hex8 hex8 (size_t nn) { return Hex8 (nn); }

std::ostream & operator << (std::ostream & os, const Hex2 & h2);
std::ostream & operator << (std::ostream & os, const Hex4 & h4);
std::ostream & operator << (std::ostream & os, const Hex8 & h8);


#endif

// End of pasmotypes.h