forked from andrew-jacobs/emu816
-
Notifications
You must be signed in to change notification settings - Fork 0
/
wdc816.h
86 lines (74 loc) · 2.34 KB
/
wdc816.h
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
//==============================================================================
// .ooooo. .o .ooo
// d88' `8. o888 .88'
// .ooooo. ooo. .oo. .oo. oooo oooo Y88.. .8' 888 d88'
// d88' `88b `888P"Y88bP"Y88b `888 `888 `88888b. 888 d888P"Ybo.
// 888ooo888 888 888 888 888 888 .8' ``88b 888 Y88[ ]88
// 888 .o 888 888 888 888 888 `8. .88P 888 `Y88 88P
// `Y8bod8P' o888o o888o o888o `V88V"V8P' `boood8' o888o `88bod8'
//
// A Portable C++ WDC 65C816 Emulator
//------------------------------------------------------------------------------
// Copyright (C),2016 Andrew John Jacobs
// All rights reserved.
//
// This work is made available under the terms of the Creative Commons
// Attribution-NonCommercial-ShareAlike 4.0 International license. Open the
// following URL to see the details.
//
// http://creativecommons.org/licenses/by-nc-sa/4.0/
//------------------------------------------------------------------------------
#ifndef WDC816_H
#define WDC816_H
#ifdef CHIPKIT
# define INLINE inline
#else
# define INLINE inline
#endif
// The wdc816 class defines common types for 8-, 16- and 24-bit data values and
// a set of common functions for manipulating them.
class wdc816
{
public:
// Common types for memory and register sizes
typedef unsigned char Bit;
typedef unsigned char Byte;
typedef unsigned short Word;
typedef unsigned long Addr;
// Convert a value to a hex string.
static char *toHex(unsigned long value, unsigned int digits);
// Return the low byte of a word
INLINE static Byte lo(Word value)
{
return ((Byte) value);
}
// Return the high byte of a word
INLINE static Byte hi(Word value)
{
return (lo(value >> 8));
}
// Convert the bank number into a address
INLINE static Addr bank(Byte b)
{
return (b << 16);
}
// Combine two bytes into a word
INLINE static Word join(Byte l, Byte h)
{
return (l | (h << 8));
}
// Combine a bank and an word into an address
INLINE static Addr join(Byte b, Word a)
{
return (bank(b) | a);
}
// Swap the high and low bytes of a word
INLINE static Word swap(Word value)
{
return ((value >> 8) | (value << 8));
}
protected:
wdc816();
~wdc816();
};
#endif