1 |
/* PCSX2 - PS2 Emulator for PCs |
2 |
* Copyright (C) 2002-2010 PCSX2 Dev Team |
3 |
* |
4 |
* PCSX2 is free software: you can redistribute it and/or modify it under the terms |
5 |
* of the GNU Lesser General Public License as published by the Free Software Found- |
6 |
* ation, either version 3 of the License, or (at your option) any later version. |
7 |
* |
8 |
* PCSX2 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
9 |
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
10 |
* PURPOSE. See the GNU General Public License for more details. |
11 |
* |
12 |
* You should have received a copy of the GNU General Public License along with PCSX2. |
13 |
* If not, see <http://www.gnu.org/licenses/>. |
14 |
*/ |
15 |
|
16 |
#ifndef __CDVD_INTERNAL_H__ |
17 |
#define __CDVD_INTERNAL_H__ |
18 |
|
19 |
/* |
20 |
Interrupts - values are flag bits. |
21 |
|
22 |
0x00 No interrupt |
23 |
0x01 Data Ready |
24 |
0x02 Command Complete |
25 |
0x03 Acknowledge (reserved) |
26 |
0x04 End of Data Detected |
27 |
0x05 Error Detected |
28 |
0x06 Drive Not Ready |
29 |
|
30 |
In limited experimentation I found that PS2 apps respond actively to use of the |
31 |
'Data Ready' flag -- in that they'll almost immediately initiate a DMA transfer |
32 |
after receiving an Irq with that as the cause. But the question is, of course, |
33 |
*when* to use it. Adding it into some locations of CDVD reading only slowed |
34 |
games down and broke things. |
35 |
|
36 |
Using Drive Not Ready also invokes basic error handling from the Iop Bios, but |
37 |
without proper emulation of the cdvd status flag it also tends to break things. |
38 |
|
39 |
*/ |
40 |
|
41 |
enum CdvdIrqId |
42 |
{ |
43 |
Irq_None = 0 |
44 |
, Irq_DataReady = 0 |
45 |
, Irq_CommandComplete |
46 |
, Irq_Acknowledge |
47 |
, Irq_EndOfData |
48 |
, Irq_Error |
49 |
, Irq_NotReady |
50 |
|
51 |
}; |
52 |
|
53 |
/* is cdvd.Status only for NCMDS? (linuzappz) */ |
54 |
enum cdvdStatus |
55 |
{ |
56 |
CDVD_STATUS_NONE = 0x00, // not sure ;) |
57 |
CDVD_STATUS_SEEK_COMPLETE = 0x0A, |
58 |
}; |
59 |
|
60 |
enum cdvdready |
61 |
{ |
62 |
CDVD_NOTREADY = 0x00, |
63 |
CDVD_READY1 = 0x40, |
64 |
CDVD_READY2 = 0x4e // This is used in a few places for some reason. |
65 |
//It would be worth checking if this was just a typo made at some point. |
66 |
}; |
67 |
|
68 |
// Cdvd actions tell the emulator how and when to respond to certain requests. |
69 |
// Actions are handled by the cdvdInterrupt() |
70 |
enum cdvdActions |
71 |
{ |
72 |
cdvdAction_None = 0 |
73 |
, cdvdAction_Seek |
74 |
, cdvdAction_Standby |
75 |
, cdvdAction_Stop |
76 |
, cdvdAction_Break |
77 |
, cdvdAction_Read // note: not used yet. |
78 |
}; |
79 |
|
80 |
////////////////////////////////////////////////////////////////////////////////////////// |
81 |
// Cdvd Block Read Cycle Timings |
82 |
// |
83 |
// The PS2 CDVD effectively has two seek modes -- the normal/slow one (est. avg seeks being |
84 |
// around 120-160ms), and a faster seek which has an estimated seek time of about 35-40ms. |
85 |
// Fast seeks happen when the destination sector is within a certain range of the starting |
86 |
// point, such that abs(start-dest) is less than the value in the tbl_FastSeekDelta. |
87 |
// |
88 |
// CDVDs also have a secondary seeking method used when the destination is close enough |
89 |
// that a contiguous sector read can reach the sector faster than initiating a full seek. |
90 |
// Typically this value is very low. |
91 |
|
92 |
enum CDVD_MODE_TYPE |
93 |
{ |
94 |
MODE_CDROM = 0, |
95 |
MODE_DVDROM, |
96 |
}; |
97 |
|
98 |
static const uint tbl_FastSeekDelta[3] = |
99 |
{ |
100 |
4371, // CD-ROM |
101 |
14764, // Single-layer DVD-ROM |
102 |
13360 // dual-layer DVD-ROM [currently unused] |
103 |
}; |
104 |
|
105 |
// if a seek is within this many blocks, read instead of seek. |
106 |
// These values are arbitrary assumptions. Not sure what the real PS2 uses. |
107 |
static const uint tbl_ContigiousSeekDelta[3] = |
108 |
{ |
109 |
8, // CD-ROM |
110 |
16, // single-layer DVD-ROM |
111 |
16, // dual-layer DVD-ROM [currently unused] |
112 |
}; |
113 |
|
114 |
// Note: DVD read times are modified to be faster, because games seem to be a lot more |
115 |
// concerned with accurate(ish) seek delays and less concerned with actual block read speeds. |
116 |
// Translation: it's a minor speedhack :D |
117 |
|
118 |
//Fixme ( voodoocycles ): |
119 |
//The current CD mode gives a too low transfer rate. HDloader reports 900kb/s, while the theoretical max is 3600kb/s |
120 |
//Silent Hill 2 videos starve of data and stall. |
121 |
//So let's double that until the cause of the slow data rate is known. |
122 |
|
123 |
static const uint PSX_CD_READSPEED = 153600 * 2; // 1 Byte Time @ x1 (150KB = cd x 1) |
124 |
static const uint PSX_DVD_READSPEED = 1382400 + 256000; // normal is 1 Byte Time @ x1 (1350KB = dvd x 1). |
125 |
|
126 |
// Legacy Note: FullSeek timing causes many games to load very slow, but it likely not the real problem. |
127 |
// Games breaking with it set to PSXCLK*40 : "wrath unleashed" and "Shijou Saikyou no Deshi Kenichi". |
128 |
|
129 |
static const uint Cdvd_FullSeek_Cycles = (PSXCLK*100) / 1000; // average number of cycles per fullseek (100ms) |
130 |
static const uint Cdvd_FastSeek_Cycles = (PSXCLK*30) / 1000; // average number of cycles per fastseek (37ms) |
131 |
|
132 |
static const char *mg_zones[8] = {"Japan", "USA", "Europe", "Oceania", "Asia", "Russia", "China", "Mexico"}; |
133 |
|
134 |
static const char *nCmdName[0x100]= { |
135 |
"CdSync", |
136 |
"CdNop", |
137 |
"CdStandby", |
138 |
"CdStop", |
139 |
"CdPause", |
140 |
"CdSeek", |
141 |
"CdRead", |
142 |
"CdReadCDDA", |
143 |
"CdReadDVDV", |
144 |
"CdGetToc", |
145 |
"", |
146 |
"NCMD_B", |
147 |
"CdReadKey", |
148 |
"", |
149 |
"sceCdReadXCDDA", |
150 |
"sceCdChgSpdlCtrl", |
151 |
}; |
152 |
|
153 |
enum nCmds |
154 |
{ |
155 |
N_CD_SYNC = 0x00, // CdSync |
156 |
N_CD_NOP = 0x01, // CdNop |
157 |
N_CD_STANDBY = 0x02, // CdStandby |
158 |
N_CD_STOP = 0x03, // CdStop |
159 |
N_CD_PAUSE = 0x04, // CdPause |
160 |
N_CD_SEEK = 0x05, // CdSeek |
161 |
N_CD_READ = 0x06, // CdRead |
162 |
N_CD_READ_CDDA = 0x07, // CdReadCDDA |
163 |
N_DVD_READ = 0x08, // DvdRead |
164 |
N_CD_GET_TOC = 0x09, // CdGetToc & cdvdman_call19 |
165 |
N_CMD_B = 0x0B, // CdReadKey |
166 |
N_CD_READ_KEY = 0x0C, // CdReadKey |
167 |
N_CD_READ_XCDDA = 0x0E, // CdReadXCDDA |
168 |
N_CD_CHG_SPDL_CTRL = 0x0F, // CdChgSpdlCtrl |
169 |
}; |
170 |
|
171 |
static const char *sCmdName[0x100]= { |
172 |
"", "sceCdGetDiscType", "sceCdReadSubQ", "subcommands",//sceCdGetMecaconVersion, read/write console id, read renewal date |
173 |
"", "sceCdTrayState", "sceCdTrayCtrl", "", |
174 |
"sceCdReadClock", "sceCdWriteClock", "sceCdReadNVM", "sceCdWriteNVM", |
175 |
"sceCdSetHDMode", "", "", "sceCdPowerOff", |
176 |
"", "", "sceCdReadILinkID", "sceCdWriteILinkID", /*10*/ |
177 |
"sceAudioDigitalOut", "sceForbidDVDP", "sceAutoAdjustCtrl", "sceCdReadModelNumber", |
178 |
"sceWriteModelNumber", "sceCdForbidCD", "sceCdBootCertify", "sceCdCancelPOffRdy", |
179 |
"sceCdBlueLEDCtl", "", "sceRm2Read", "sceRemote2_7",//Rm2PortGetConnection? |
180 |
"sceRemote2_6", "sceCdWriteWakeUpTime", "sceCdReadWakeUpTime", "", /*20*/ |
181 |
"sceCdRcBypassCtl", "", "", "", |
182 |
"", "sceCdNoticeGameStart", "", "", |
183 |
"sceCdXBSPowerCtl", "sceCdXLEDCtl", "sceCdBuzzerCtl", "", |
184 |
"", "sceCdSetMediumRemoval", "sceCdGetMediumRemoval", "sceCdXDVRPReset", /*30*/ |
185 |
"", "", "__sceCdReadRegionParams", "__sceCdReadMAC", |
186 |
"__sceCdWriteMAC", "", "", "", |
187 |
"", "", "__sceCdWriteRegionParams", "", |
188 |
"sceCdOpenConfig", "sceCdReadConfig", "sceCdWriteConfig", "sceCdCloseConfig", /*40*/ |
189 |
"", "", "", "", |
190 |
"", "", "", "", |
191 |
"", "", "", "", |
192 |
"", "", "", "", /*50*/ |
193 |
"", "", "", "", |
194 |
"", "", "", "", |
195 |
"", "", "", "", |
196 |
"", "", "", "", /*60*/ |
197 |
"", "", "", "", |
198 |
"", "", "", "", |
199 |
"", "", "", "", |
200 |
"", "", "", "", /*70*/ |
201 |
"", "", "", "", |
202 |
"", "", "", "", |
203 |
"", "", "", "", |
204 |
"mechacon_auth_0x80", "mechacon_auth_0x81", "mechacon_auth_0x82", "mechacon_auth_0x83", /*80*/ |
205 |
"mechacon_auth_0x84", "mechacon_auth_0x85", "mechacon_auth_0x86", "mechacon_auth_0x87", |
206 |
"mechacon_auth_0x88", "", "", "", |
207 |
"", "sceMgWriteData", "sceMgReadData", "mechacon_auth_0x8F", |
208 |
"sceMgWriteHeaderStart", "sceMgReadBITLength", "sceMgWriteDatainLength", "sceMgWriteDataoutLength", /*90*/ |
209 |
"sceMgReadKbit", "sceMgReadKbit2", "sceMgReadKcon", "sceMgReadKcon2", |
210 |
"sceMgReadIcvPs2", "", "", "", |
211 |
"", "", "", "", |
212 |
/*A0, no sCmds above?*/ |
213 |
}; |
214 |
|
215 |
// NVM (eeprom) layout info |
216 |
struct NVMLayout { |
217 |
u32 biosVer; // bios version that this eeprom layout is for |
218 |
s32 config0; // offset of 1st config block |
219 |
s32 config1; // offset of 2nd config block |
220 |
s32 config2; // offset of 3rd config block |
221 |
s32 consoleId; // offset of console id (?) |
222 |
s32 ilinkId; // offset of ilink id (ilink mac address) |
223 |
s32 modelNum; // offset of ps2 model number (eg "SCPH-70002") |
224 |
s32 regparams; // offset of RegionParams for PStwo |
225 |
s32 mac; // offset of the value written to 0xFFFE0188 and 0xFFFE018C on PStwo |
226 |
}; |
227 |
|
228 |
#define NVM_FORMAT_MAX 2 |
229 |
static NVMLayout nvmlayouts[NVM_FORMAT_MAX] = |
230 |
{ |
231 |
{0x000, 0x280, 0x300, 0x200, 0x1C8, 0x1C0, 0x1A0, 0x180, 0x198}, // eeproms from bios v0.00 and up |
232 |
{0x146, 0x270, 0x2B0, 0x200, 0x1C8, 0x1E0, 0x1B0, 0x180, 0x198}, // eeproms from bios v1.70 and up |
233 |
}; |
234 |
|
235 |
#endif |