Nugget
Bare-metal libraries and examples for the original PlayStation
Loading...
Searching...
No Matches
cdlseekp.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 seekP to 00:02:00: ack in %ius, complete in %ius\n", ackTime, completeTime);
86)
87
88CESTER_TEST(cdlSeekPwithArgs, 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 seekP, 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 100ms, and more likely 150ms.
196 ramsyscall_printf("Basic seekP from 00:02:00 to 00:04:00: ack in %ius, complete in %ius\n", ackTime, completeTime);
197)
198
199CESTER_TEST(cdlSeekP2to71, 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
258 // This is a pretty long distance seek, which will take at least a full second.
260 ramsyscall_printf("Basic seekP from 00:02:00 to 71:00:00: ack in %ius, complete in %ius\n", ackTime, completeTime);
261)
262
264 int resetDone = resetCDRom();
265 if (!resetDone) {
267 return;
268 }
269
270 int seekDone = seekPTo(0, 2, 0);
271 if (!seekDone) {
273 return;
274 }
275
276 int setLocDone = setLoc(0x85, 0, 0);
277 if (!setLocDone) {
279 return;
280 }
281
283 // wait 50ms for things to settle
284 while (updateTime() < 50000);
286
287 CDROM_REG0 = 0;
289
291 uint8_t cause1 = ackCDRomCause();
292 uint8_t ctrl1 = CDROM_REG0 & ~3;
293 uint8_t response1[16];
295 uint8_t ctrl2 = CDROM_REG0 & ~3;
296 CDROM_REG0 = 1;
297 uint8_t cause1b = CDROM_REG3_UC;
298
300 uint8_t cause2 = ackCDRomCause();
301 uint8_t ctrl3 = CDROM_REG0 & ~3;
302 uint8_t response2[16];
304 uint8_t ctrl4 = CDROM_REG0 & ~3;
305 CDROM_REG0 = 1;
306 uint8_t cause2b = CDROM_REG3_UC;
307
323 // The seekP won't be successful when targeting a sector past the end of the
324 // disc. The failure can be faster than the previous test, because it won't
325 // retry reading where there's clearly no information whatsoever. Will sometimes
326 // fail in roughly 650ms, which is the seek time plus some minor retry.
328 ramsyscall_printf("Basic seekP from 00:02:00 to 85:00:00: ack in %ius, errored in %ius\n", ackTime, errorTime);
329)
330
331CESTER_TEST(cdlSeekP2to85AndNop, test_instance,
332 int resetDone = resetCDRom();
333 if (!resetDone) {
335 return;
336 }
337
338 int seekDone = seekPTo(0, 2, 0);
339 if (!seekDone) {
341 return;
342 }
343
344 int setLocDone = setLoc(0x85, 0, 0);
345 if (!setLocDone) {
347 return;
348 }
349
351 // wait 50ms for things to settle
352 while (updateTime() < 50000);
354
355 CDROM_REG0 = 0;
357
358 while (CDROM_REG0 & 0x80);
360
362 uint8_t cause1 = ackCDRomCause();
363 uint8_t ctrl1 = CDROM_REG0 & ~3;
364 uint8_t response1[16];
366 uint8_t ctrl2 = CDROM_REG0 & ~3;
367
369 uint8_t cause1b = ackCDRomCause();
370 uint8_t ctrl1b = CDROM_REG0 & ~3;
371 uint8_t response1b[16];
373 uint8_t ctrl2b = CDROM_REG0 & ~3;
374
377 uint8_t cause2 = ackCDRomCause();
378 uint8_t ctrl3 = CDROM_REG0 & ~3;
379 uint8_t response2[16];
381 uint8_t ctrl4 = CDROM_REG0 & ~3;
382 CDROM_REG0 = 1;
383 uint8_t cause2b = CDROM_REG3_UC;
384
406 ramsyscall_printf("Basic seekP with Nop from 00:02:00 to 85:00:00: ack in %ius, errored in %ius\n", ackTime, errorTime);
407)
408
409CESTER_TEST(cdlSeekP2to85AndDelayedNop, test_instance,
410 int resetDone = resetCDRom();
411 if (!resetDone) {
413 return;
414 }
415
416 int seekDone = seekPTo(0, 2, 0);
417 if (!seekDone) {
419 return;
420 }
421
422 int setLocDone = setLoc(0x85, 0, 0);
423 if (!setLocDone) {
425 return;
426 }
427
429 // wait 50ms for things to settle
430 while (updateTime() < 50000);
432
433 CDROM_REG0 = 0;
435
436 while (updateTime() < 50000);
438
440 uint8_t cause1 = ackCDRomCause();
441 uint8_t ctrl1 = CDROM_REG0 & ~3;
442 uint8_t response1[16];
444 uint8_t ctrl2 = CDROM_REG0 & ~3;
445
447 uint8_t cause1b = ackCDRomCause();
448 uint8_t ctrl1b = CDROM_REG0 & ~3;
449 uint8_t response1b[16];
451 uint8_t ctrl2b = CDROM_REG0 & ~3;
452
455 uint8_t cause2 = ackCDRomCause();
456 uint8_t ctrl3 = CDROM_REG0 & ~3;
457 uint8_t response2[16];
459 uint8_t ctrl4 = CDROM_REG0 & ~3;
460 CDROM_REG0 = 1;
461 uint8_t cause2b = CDROM_REG3_UC;
462
480 ramsyscall_printf("Basic seekP with delayed Nop from 00:02:00 to 85:00:00: ack in %ius, errored in %ius\n", ackTime, errorTime);
481)
waitCDRomIRQ()
uint8_t ctrl1b
Definition cdlseekp.c:370
CDROM_REG0
Definition cdlseekp.c:106
uint32_t ackTime
Definition cdlseekp.c:226
uint8_t response2[16]
Definition cdlseekp.c:238
uint8_t responseSize2
Definition cdlseekp.c:239
uint8_t responseSize1
Definition cdlseekp.c:117
int setLocDone
Definition cdlseekp.c:95
int resetDone
Definition cdlseekp.c:89
uint8_t ctrl4
Definition cdlseekp.c:240
uint8_t ctrl2b
Definition cdlseekp.c:373
uint8_t response1[16]
Definition cdlseekp.c:116
test_instance
Definition cdlseekp.c:88
CESTER_TEST(cdlSeekP, 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_SEEKP;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 seekP to 00:02:00: ack in %ius, complete in %ius\n", ackTime, completeTime);) CESTER_TEST(cdlSeekPwithArgs
uint8_t cause2b
Definition cdlseekp.c:242
uint32_t completeTime
Definition cdlseekp.c:235
cester_assert_uint_ge(errorTime, 500)
uint8_t ctrl2
Definition cdlseekp.c:118
uint8_t cause1
Definition cdlseekp.c:114
uint8_t cause2
Definition cdlseekp.c:236
uint32_t ackTime2
Definition cdlseekp.c:368
uint32_t errorTime
Definition cdlseekp.c:113
cester_assert_uint_eq(5, cause1)
uint8_t responseSize1b
Definition cdlseekp.c:372
uint8_t cause1b
Definition cdlseekp.c:120
uint8_t ctrl1
Definition cdlseekp.c:115
CDROM_REG2
Definition cdlseekp.c:107
initializeTime()
CDROM_REG1
Definition cdlseekp.c:111
cester_assert_uint_lt(errorTime, 7000)
int seekDone
Definition cdlseekp.c:206
uint8_t response1b[16]
Definition cdlseekp.c:371
uint8_t ctrl3
Definition cdlseekp.c:237
@ CDL_NOP
Definition cdrom.h:43
@ CDL_SEEKP
Definition cdrom.h:64
#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)