summaryrefslogtreecommitdiffstatshomepage
path: root/src/mame/machine/snesobc1.c
blob: ec78ed08bb923f1eaef861f023ea5ea4deb92c71 (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
/***************************************************************************

  snesobc1.c

  File to handle emulation of the SNES "OBC-1" add-on chip.

  Original C++ code by byuu.
  Byuu's code is released under GNU General Public License
  version 2 as published by the Free Software Foundation.
  The implementation below is released under the MAME license 
  for use in MAME, MESS and derivatives by permission of the author.

***************************************************************************/

#include "includes/snes.h"

static int obc1_address;
static int obc1_offset;
static int obc1_shift;

static READ8_HANDLER( obc1_read )
{
	UINT16 address = offset & 0x1fff;
	UINT8 value;

	switch (address)
	{
		case 0x1ff0:
			value = snes_ram[obc1_offset + (obc1_address << 2) + 0];
			break;

		case 0x1ff1:
			value = snes_ram[obc1_offset + (obc1_address << 2) + 1];
			break;

		case 0x1ff2:
			value = snes_ram[obc1_offset + (obc1_address << 2) + 2];
			break;

		case 0x1ff3:
			value = snes_ram[obc1_offset + (obc1_address << 2) + 3];
			break;

		case 0x1ff4:
			value = snes_ram[obc1_offset + (obc1_address >> 2) + 0x200];
			break;

		default:
			value = snes_ram[address];
			break;
	}

	return value;
}


static WRITE8_HANDLER( obc1_write )
{
	UINT16 address = offset & 0x1fff;
	UINT8 temp;

	switch(address)
	{
		case 0x1ff0:
			snes_ram[obc1_offset + (obc1_address << 2) + 0] = data;
			break;

		case 0x1ff1:
			snes_ram[obc1_offset + (obc1_address << 2) + 1] = data;
			break;

		case 0x1ff2:
			snes_ram[obc1_offset + (obc1_address << 2) + 2] = data;
			break;

		case 0x1ff3:
			snes_ram[obc1_offset + (obc1_address << 2) + 3] = data;
			break;

		case 0x1ff4:
			temp = snes_ram[obc1_offset + (obc1_address >> 2) + 0x200];
			temp = (temp & ~(3 << obc1_shift)) | ((data & 0x03) << obc1_shift);
			snes_ram[obc1_offset + (obc1_address >> 2) + 0x200] = temp;
			break;

		case 0x1ff5:
			obc1_offset = (data & 0x01) ? 0x1800 : 0x1c00;
			snes_ram[address & 0x1fff] = data;
			break;

		case 0x1ff6:
			obc1_address = data & 0x7f;
			obc1_shift = (data & 0x03) << 1;
			snes_ram[address & 0x1fff] = data;
			break;

		default:
			snes_ram[address & 0x1fff] = data;
			break;
	}
}

static void obc1_init( void )
{
	obc1_offset  = (snes_ram[0x1ff5] & 0x01) ? 0x1800 : 0x1c00;
	obc1_address = (snes_ram[0x1ff6] & 0x7f);
	obc1_shift   = (snes_ram[0x1ff6] & 0x03) << 1;
}