Nugget
Bare-metal libraries and examples for the original PlayStation
Loading...
Searching...
No Matches
cdlseekl.c
Go to the documentation of this file.
1/*
2
3MIT License
4
5Copyright (c) 2022 PCSX-Redux authors
6
7Permission is hereby granted, free of charge, to any person obtaining a copy
8of this software and associated documentation files (the "Software"), to deal
9in the Software without restriction, including without limitation the rights
10to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11copies of the Software, and to permit persons to whom the Software is
12furnished to do so, subject to the following conditions:
13
14The above copyright notice and this permission notice shall be included in all
15copies or substantial portions of the Software.
16
17THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23SOFTWARE.
24
25*/
26
27// clang-format off
28
30 int resetDone = resetCDRom();
31 if (!resetDone) {
33 return;
34 }
35
36 int setLocDone = setLoc(0, 2, 0);
37 if (!setLocDone) {
39 return;
40 }
41
43 // wait 50ms for things to settle
44 while (updateTime() < 50000);
46
47 CDROM_REG0 = 0;
49
51 uint8_t cause1 = ackCDRomCause();
52 uint8_t ctrl1 = CDROM_REG0 & ~3;
53 uint8_t response1[16];
55 uint8_t ctrl2 = CDROM_REG0 & ~3;
56 CDROM_REG0 = 1;
57 uint8_t cause1b = CDROM_REG3_UC;
58
60 uint8_t cause2 = ackCDRomCause();
61 uint8_t ctrl3 = CDROM_REG0 & ~3;
62 uint8_t response2[16];
64 uint8_t ctrl4 = CDROM_REG0 & ~3;
65 CDROM_REG0 = 1;
66 uint8_t cause2b = CDROM_REG3_UC;
67
82 // Timings here won't really be relevant, as the CDRom's head will be hovering
83 // already around the right place, so it's mostly a no-op to seek there, but
84 // can vary a lot between 2ms and 500ms as the head is moving and re-aligning.
85 ramsyscall_printf("Basic seekL to 00:02:00: ack in %ius, complete in %ius\n", ackTime, completeTime);
86)
87
88CESTER_TEST(cdlSeekLwithArgs, test_instance,
89 int resetDone = resetCDRom();
90 if (!resetDone) {
92 return;
93 }
94
95 int setLocDone = setLoc(0, 2, 0);
96 if (!setLocDone) {
98 return;
99 }
100
102 // wait 50ms for things to settle
103 while (updateTime() < 50000);
105
108 CDROM_REG2 = 0;
109 CDROM_REG2 = 0;
110 CDROM_REG2 = 0;
112
115 uint8_t ctrl1 = CDROM_REG0 & ~3;
116 uint8_t response1[16];
118 uint8_t ctrl2 = CDROM_REG0 & ~3;
119 CDROM_REG0 = 1;
121
131 ramsyscall_printf("Too many args seekL, errored in %ius\n", errorTime);
132)
133
135 int resetDone = resetCDRom();
136 if (!resetDone) {
138 return;
139 }
140
141 int seekDone = seekPTo(0, 2, 0);
142 if (!seekDone) {
144 return;
145 }
146
147 int setLocDone = setLoc(0, 4, 0);
148 if (!setLocDone) {
150 return;
151 }
152
154 // wait 50ms for things to settle
155 while (updateTime() < 50000);
157
158 CDROM_REG0 = 0;
160
162 uint8_t cause1 = ackCDRomCause();
163 uint8_t ctrl1 = CDROM_REG0 & ~3;
164 uint8_t response1[16];
166 uint8_t ctrl2 = CDROM_REG0 & ~3;
167 CDROM_REG0 = 1;
168 uint8_t cause1b = CDROM_REG3_UC;
169
171 uint8_t cause2 = ackCDRomCause();
172 uint8_t ctrl3 = CDROM_REG0 & ~3;
173 uint8_t response2[16];
175 uint8_t ctrl4 = CDROM_REG0 & ~3;
176 CDROM_REG0 = 1;
177 uint8_t cause2b = CDROM_REG3_UC;
178
193 // It'd be difficult to put an interval check here, as the seek time will vary
194 // a lot depending on the status of the drive, but it should probably be
195 // at least 120ms, and more likely 170ms.
196 ramsyscall_printf("Basic seekL from 00:02:00 to 00:04:00: ack in %ius, complete in %ius\n", ackTime, completeTime);
197)
198
199CESTER_TEST(cdlSeekL2to71, test_instance,
200 int resetDone = resetCDRom();
201 if (!resetDone) {
203 return;
204 }
205
206 int seekDone = seekPTo(0, 2, 0);
207 if (!seekDone) {
209 return;
210 }
211
212 int setLocDone = setLoc(0x71, 0, 0);
213 if (!setLocDone) {
215 return;
216 }
217
219 // wait 50ms for things to settle
220 while (updateTime() < 50000);
222
223 CDROM_REG0 = 0;
225
227 uint8_t cause1 = ackCDRomCause();
228 uint8_t ctrl1 = CDROM_REG0 & ~3;
229 uint8_t response1[16];
231 uint8_t ctrl2 = CDROM_REG0 & ~3;
232 CDROM_REG0 = 1;
233 uint8_t cause1b = CDROM_REG3_UC;
234
237 uint8_t ctrl3 = CDROM_REG0 & ~3;
238 uint8_t response2[16];
240 uint8_t ctrl4 = CDROM_REG0 & ~3;
241 CDROM_REG0 = 1;
243
259 // The seekL won't be successful when targeting a sector past the end of the
260 // data track, but it should still take a while to complete, because it'll
261 // keep retrying reading data where there's none. Roughly 4s.
263 ramsyscall_printf("Basic seekL from 00:02:00 to 71:00:00: ack in %ius, errored in %ius\n", ackTime, errorTime);
264)
265
266CESTER_TEST(cdlSeekL2to85, test_instance,
267 int resetDone = resetCDRom();
268 if (!resetDone) {
270 return;
271 }
272
273 int seekDone = seekPTo(0, 2, 0);
274 if (!seekDone) {
276 return;
277 }
278
279 int setLocDone = setLoc(0x85, 0, 0);
280 if (!setLocDone) {
282 return;
283 }
284
286 // wait 50ms for things to settle
287 while (updateTime() < 50000);
289
290 CDROM_REG0 = 0;
292
294 uint8_t cause1 = ackCDRomCause();
295 uint8_t ctrl1 = CDROM_REG0 & ~3;
296 uint8_t response1[16];
298 uint8_t ctrl2 = CDROM_REG0 & ~3;
299 CDROM_REG0 = 1;
300 uint8_t cause1b = CDROM_REG3_UC;
301
303 uint8_t cause2 = ackCDRomCause();
304 uint8_t ctrl3 = CDROM_REG0 & ~3;
305 uint8_t response2[16];
307 uint8_t ctrl4 = CDROM_REG0 & ~3;
308 CDROM_REG0 = 1;
309 uint8_t cause2b = CDROM_REG3_UC;
310
326 // The seekL won't be successful when targeting a sector past the end of the
327 // disc. The failure can be faster than the previous test, because it won't
328 // retry reading where there's clearly no information whatsoever. Will sometimes
329 // fail in roughly 650ms, which is the seek time plus some minor retry.
331 ramsyscall_printf("Basic seekL from 00:02:00 to 85:00:00: ack in %ius, errored in %ius\n", ackTime, errorTime);
332)
waitCDRomIRQ()
uint32_t completeTime
Definition cdlid.c:201
CDROM_REG0
Definition cdlseekl.c:106
uint32_t ackTime
Definition cdlseekl.c:226
uint8_t response2[16]
Definition cdlseekl.c:238
uint8_t responseSize2
Definition cdlseekl.c:239
uint8_t responseSize1
Definition cdlseekl.c:117
int setLocDone
Definition cdlseekl.c:95
int resetDone
Definition cdlseekl.c:89
uint8_t ctrl4
Definition cdlseekl.c:240
uint8_t response1[16]
Definition cdlseekl.c:116
test_instance
Definition cdlseekl.c:88
uint8_t cause2b
Definition cdlseekl.c:242
cester_assert_uint_ge(errorTime, 500)
uint8_t ctrl2
Definition cdlseekl.c:118
uint8_t cause1
Definition cdlseekl.c:114
uint8_t cause2
Definition cdlseekl.c:236
uint32_t errorTime
Definition cdlseekl.c:113
cester_assert_uint_eq(5, cause1)
CESTER_TEST(cdlSeekL, test_instance, int resetDone=resetCDRom();if(!resetDone) { cester_assert_true(resetDone);return;} int setLocDone=setLoc(0, 2, 0);if(!setLocDone) { cester_assert_true(setLocDone);return;} initializeTime();while(updateTime()< 50000);initializeTime();CDROM_REG0=0;CDROM_REG1=CDL_SEEKL;uint32_t ackTime=waitCDRomIRQ();uint8_t cause1=ackCDRomCause();uint8_t ctrl1=CDROM_REG0 &~3;uint8_t response1[16];uint8_t responseSize1=readResponse(response1);uint8_t ctrl2=CDROM_REG0 &~3;CDROM_REG0=1;uint8_t cause1b=CDROM_REG3_UC;uint32_t completeTime=waitCDRomIRQ() - ackTime;uint8_t cause2=ackCDRomCause();uint8_t ctrl3=CDROM_REG0 &~3;uint8_t response2[16];uint8_t responseSize2=readResponse(response2);uint8_t ctrl4=CDROM_REG0 &~3;CDROM_REG0=1;uint8_t cause2b=CDROM_REG3_UC;cester_assert_uint_eq(3, cause1);cester_assert_uint_eq(2, cause2);cester_assert_uint_eq(0xe0, cause1b);cester_assert_uint_eq(0xe0, cause2b);cester_assert_uint_eq(2, response1[0]);cester_assert_uint_eq(1, responseSize1);cester_assert_uint_eq(2, response2[0]);cester_assert_uint_eq(1, responseSize2);cester_assert_uint_eq(0x38, ctrl1);cester_assert_uint_eq(0x18, ctrl2);cester_assert_uint_eq(0x38, ctrl3);cester_assert_uint_eq(0x18, ctrl4);cester_assert_uint_ge(ackTime, 500);cester_assert_uint_lt(ackTime, 7000);ramsyscall_printf("Basic seekL to 00:02:00: ack in %ius, complete in %ius\n", ackTime, completeTime);) CESTER_TEST(cdlSeekLwithArgs
uint8_t cause1b
Definition cdlseekl.c:120
uint8_t ctrl1
Definition cdlseekl.c:115
CDROM_REG2
Definition cdlseekl.c:107
initializeTime()
CDROM_REG1
Definition cdlseekl.c:111
cester_assert_uint_lt(errorTime, 7000)
int seekDone
Definition cdlseekl.c:206
uint8_t ctrl3
Definition cdlseekl.c:237
@ CDL_SEEKL
Definition cdrom.h:63
#define CDROM_REG3_UC
Definition cdrom.h:39
ramsyscall_printf("=== e01_kseg1_reads_no_fill ===\n")
ackCDRomCause()
cester_assert_true(seekDone)
readResponse(response)
void uint32_t(classId, spec)