summaryrefslogtreecommitdiffstatshomepage
path: root/src/emu/cpu/i86/i86mem.c
blob: 3a06419dc360038f8b71a13a2138756e343fce0f (plain) (blame)
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
/*****************************************************************************
    8-bit memory accessors
 *****************************************************************************/

#ifdef I8086
#if (HAS_I8088||HAS_I80188)
static UINT16 read_word_8(offs_t addr)
{
	UINT16 result = program_read_byte_8(addr);
	return result | (program_read_byte_8(addr + 1) << 8);
}

static void write_word_8(offs_t addr, UINT16 data)
{
	program_write_byte_8(addr, data);
	program_write_byte_8(addr + 1, data >> 8);
}

static UINT16 read_port_word_8(offs_t addr)
{
	UINT16 result = io_read_byte_8(addr);
	return result | (io_read_byte_8(addr + 1) << 8);
}

static void write_port_word_8(offs_t addr, UINT16 data)
{
	io_write_byte_8(addr, data);
	io_write_byte_8(addr + 1, data >> 8);
}

static void configure_memory_8bit(void)
{
	I.mem.fetch_xor = 0;

	I.mem.rbyte = program_read_byte_8;
	I.mem.rword = read_word_8;
	I.mem.wbyte = program_write_byte_8;
	I.mem.wword = write_word_8;

	I.mem.rbyte_port = io_read_byte_8;
	I.mem.rword_port = read_port_word_8;
	I.mem.wbyte_port = io_write_byte_8;
	I.mem.wword_port = write_port_word_8;
}
#endif
#endif


/*****************************************************************************
    16-bit memory accessors
 *****************************************************************************/

static UINT16 read_word_16le(offs_t addr)
{
	if (!(addr & 1))
		return program_read_word_16le(addr);
	else
	{
		UINT16 result = program_read_byte_16le(addr);
		return result | (program_read_byte_16le(addr + 1) << 8);
	}
}

static void write_word_16le(offs_t addr, UINT16 data)
{
	if (!(addr & 1))
		program_write_word_16le(addr, data);
	else
	{
		program_write_byte_16le(addr, data);
		program_write_byte_16le(addr + 1, data >> 8);
	}
}

static UINT16 read_port_word_16le(offs_t addr)
{
	if (!(addr & 1))
		return io_read_word_16le(addr);
	else
	{
		UINT16 result = io_read_byte_16le(addr);
		return result | (io_read_byte_16le(addr + 1) << 8);
	}
}

static void write_port_word_16le(offs_t addr, UINT16 data)
{
	if (!(addr & 1))
		io_write_word_16le(addr, data);
	else
	{
		io_write_byte_16le(addr, data);
		io_write_byte_16le(addr + 1, data >> 8);
	}
}

static void configure_memory_16bit(void)
{
	I.mem.fetch_xor = BYTE_XOR_LE(0);

	I.mem.rbyte = program_read_byte_16le;
	I.mem.rword = read_word_16le;
	I.mem.wbyte = program_write_byte_16le;
	I.mem.wword = write_word_16le;

	I.mem.rbyte_port = io_read_byte_16le;
	I.mem.rword_port = read_port_word_16le;
	I.mem.wbyte_port = io_write_byte_16le;
	I.mem.wword_port = write_port_word_16le;
}