1/*****************************************************************************\
2 Snes9x - Portable Super Nintendo Entertainment System (TM) emulator.
3 This file is licensed under the Snes9x License.
4 For further information, consult the LICENSE file in the root directory.
5\*****************************************************************************/
6
7#include "snes9x.h"
8#include "memmap.h"
9
10
11uint8 S9xGetOBC1 (uint16 Address)
12{
13 switch (Address)
14 {
15 case 0x7ff0:
16 return (Memory.OBC1RAM[OBC1.basePtr + (OBC1.address << 2)]);
17
18 case 0x7ff1:
19 return (Memory.OBC1RAM[OBC1.basePtr + (OBC1.address << 2) + 1]);
20
21 case 0x7ff2:
22 return (Memory.OBC1RAM[OBC1.basePtr + (OBC1.address << 2) + 2]);
23
24 case 0x7ff3:
25 return (Memory.OBC1RAM[OBC1.basePtr + (OBC1.address << 2) + 3]);
26
27 case 0x7ff4:
28 return (Memory.OBC1RAM[OBC1.basePtr + (OBC1.address >> 2) + 0x200]);
29 }
30
31 return (Memory.OBC1RAM[Address - 0x6000]);
32}
33
34void S9xSetOBC1 (uint8 Byte, uint16 Address)
35{
36 switch (Address)
37 {
38 case 0x7ff0:
39 Memory.OBC1RAM[OBC1.basePtr + (OBC1.address << 2)] = Byte;
40 break;
41
42 case 0x7ff1:
43 Memory.OBC1RAM[OBC1.basePtr + (OBC1.address << 2) + 1] = Byte;
44 break;
45
46 case 0x7ff2:
47 Memory.OBC1RAM[OBC1.basePtr + (OBC1.address << 2) + 2] = Byte;
48 break;
49
50 case 0x7ff3:
51 Memory.OBC1RAM[OBC1.basePtr + (OBC1.address << 2) + 3] = Byte;
52 break;
53
54 case 0x7ff4:
55 {
56 uint8 Temp;
57 Temp = Memory.OBC1RAM[OBC1.basePtr + (OBC1.address >> 2) + 0x200];
58 Temp = (Temp & ~(3 << OBC1.shift)) | ((Byte & 3) << OBC1.shift);
59 Memory.OBC1RAM[OBC1.basePtr + (OBC1.address >> 2) + 0x200] = Temp;
60 break;
61 }
62
63 case 0x7ff5:
64 if (Byte & 1)
65 OBC1.basePtr = 0x1800;
66 else
67 OBC1.basePtr = 0x1c00;
68 break;
69
70 case 0x7ff6:
71 OBC1.address = Byte & 0x7f;
72 OBC1.shift = (Byte & 3) << 1;
73 break;
74 }
75
76 Memory.OBC1RAM[Address - 0x6000] = Byte;
77}
78
79void S9xResetOBC1 (void)
80{
81 for (int i = 0; i <= 0x1fff; i++)
82 Memory.OBC1RAM[i] = 0xff;
83
84 if (Memory.OBC1RAM[0x1ff5] & 1)
85 OBC1.basePtr = 0x1800;
86 else
87 OBC1.basePtr = 0x1c00;
88
89 OBC1.address = Memory.OBC1RAM[0x1ff6] & 0x7f;
90 OBC1.shift = (Memory.OBC1RAM[0x1ff6] & 3) << 1;
91}
92
93uint8 * S9xGetBasePointerOBC1 (uint16 Address)
94{
95 if (Address >= 0x7ff0 && Address <= 0x7ff6)
96 return (NULL);
97 return (Memory.OBC1RAM - 0x6000);
98}
99
100uint8 * S9xGetMemPointerOBC1 (uint16 Address)
101{
102 if (Address >= 0x7ff0 && Address <= 0x7ff6)
103 return (NULL);
104 return (Memory.OBC1RAM + Address - 0x6000);
105}
106