Nugget
Bare-metal libraries and examples for the original PlayStation
Loading...
Searching...
No Matches
cdlsetloc.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
37 CDROM_REG0 = 0;
38 CDROM_REG2 = 0;
39 CDROM_REG2 = 2;
40 CDROM_REG2 = 0;
43 uint8_t cause1 = ackCDRomCause();
44 uint8_t ctrl1 = CDROM_REG0 & ~3;
45 uint8_t response[16];
47 uint8_t ctrl2 = CDROM_REG0 & ~3;
48 CDROM_REG0 = 1;
49 uint8_t cause1b = CDROM_REG3_UC;
50
57 // Typical value seems to be around 1ms, but has
58 // been seen to spike high from time to time.
61 ramsyscall_printf("Basic setloc to 00:02:00, ack in %ius\n", ackTime);
62)
63
64CESTER_TEST(cdlSetLocNoArgs, test_instances,
65 int resetDone = resetCDRom();
66 if (!resetDone) {
68 return;
69 }
70
75 uint8_t cause1 = ackCDRomCause();
76 uint8_t ctrl1 = CDROM_REG0 & ~3;
77 uint8_t response[16];
79 uint8_t ctrl2 = CDROM_REG0 & ~3;
80 CDROM_REG0 = 1;
82
92 ramsyscall_printf("Invalid setloc with no args, errored in %ius\n", errorTime);
93)
94
95CESTER_TEST(cdlSetLocMultiple, test_instances,
96 int resetDone = resetCDRom();
97 uint8_t cause;
98 if (!resetDone) {
100 return;
101 }
102
104 CDROM_REG0 = 0;
105 CDROM_REG2 = 0;
106 CDROM_REG2 = 2;
107 CDROM_REG2 = 0;
112 if (cause != 3) {
114 return;
115 }
116
118 CDROM_REG0 = 0;
119 CDROM_REG2 = 0x99;
120 CDROM_REG2 = 0x59;
121 CDROM_REG2 = 0x74;
126 if (cause != 3) {
128 return;
129 }
130
132 CDROM_REG0 = 0;
133 CDROM_REG2 = 0x50;
134 CDROM_REG2 = 0;
135 CDROM_REG2 = 0;
140 if (cause != 3) {
142 return;
143 }
144
145 // Setloc is only changing an internal state.
146 // Its response time is very fast, and won't
147 // vary regardless of the location, but can
148 // still spike to 6ms from time to time.
155 ramsyscall_printf("Multiple setloc to 00:02:00, complete in %ius, %ius, %ius\n", time1, time2, time3);
156)
157
158CESTER_TEST(cdlSetLocInvalid1, test_instances,
159 int resetDone = resetCDRom();
160 if (!resetDone) {
162 return;
163 }
164
166 CDROM_REG0 = 0;
168 CDROM_REG2 = 2;
169 CDROM_REG2 = 0x2a;
172 uint8_t cause1 = ackCDRomCause();
173 uint8_t ctrl1 = CDROM_REG0 & ~3;
174 uint8_t response[16];
176 uint8_t ctrl2 = CDROM_REG0 & ~3;
177 CDROM_REG0 = 1;
178 uint8_t cause1b = CDROM_REG3_UC;
179
189 ramsyscall_printf("Invalid setloc to 00:02:2a, errored in %ius\n", errorTime);
190)
191
192CESTER_TEST(cdlSetLocInvalid2, test_instances,
193 int resetDone = resetCDRom();
194 if (!resetDone) {
196 return;
197 }
198
200 CDROM_REG0 = 0;
201 CDROM_REG2 = 0;
202 CDROM_REG2 = 2;
203 CDROM_REG2 = 0x79;
206 uint8_t cause1 = ackCDRomCause();
207 uint8_t ctrl1 = CDROM_REG0 & ~3;
208 uint8_t response[16];
210 uint8_t ctrl2 = CDROM_REG0 & ~3;
211 CDROM_REG0 = 1;
212 uint8_t cause1b = CDROM_REG3_UC;
213
223 ramsyscall_printf("Invalid setloc to 00:02:79, errored in %ius\n", errorTime);
224)
225
226CESTER_TEST(cdlSetLocTooManyArgs, test_instances,
227 int resetDone = resetCDRom();
228 if (!resetDone) {
230 return;
231 }
232
234 CDROM_REG0 = 0;
235 CDROM_REG2 = 0;
236 CDROM_REG2 = 2;
237 CDROM_REG2 = 0;
238 CDROM_REG2 = 0;
241 uint8_t cause1 = ackCDRomCause();
242 uint8_t ctrl1 = CDROM_REG0 & ~3;
243 uint8_t response[16];
245 uint8_t ctrl2 = CDROM_REG0 & ~3;
246 CDROM_REG0 = 1;
247 uint8_t cause1b = CDROM_REG3_UC;
248
258 ramsyscall_printf("Invalid setloc with too many args, errored in %ius\n", errorTime);
259)
260
261CESTER_TEST(cdlSetLocTooManyArgsAndInvalid, test_instances,
262 int resetDone = resetCDRom();
263 if (!resetDone) {
265 return;
266 }
267
269 CDROM_REG0 = 0;
270 CDROM_REG2 = 0;
271 CDROM_REG2 = 2;
272 CDROM_REG2 = 0x79;
273 CDROM_REG2 = 0;
276 uint8_t cause1 = ackCDRomCause();
277 uint8_t ctrl1 = CDROM_REG0 & ~3;
278 uint8_t response[16];
280 uint8_t ctrl2 = CDROM_REG0 & ~3;
281 CDROM_REG0 = 1;
282 uint8_t cause1b = CDROM_REG3_UC;
283
293 ramsyscall_printf("Invalid setloc with too many invalid args, errored in %ius\n", errorTime);
294)
295
uint32_t ackTime
Definition cdlgetlocp.c:107
waitCDRomIRQ()
CDROM_REG0
Definition cdlsetloc.c:72
uint8_t responseSize
Definition cdlsetloc.c:78
uint8_t response[16]
Definition cdlsetloc.c:77
int resetDone
Definition cdlsetloc.c:65
test_instances
Definition cdlsetloc.c:64
cester_assert_uint_ge(errorTime, 500)
uint8_t ctrl2
Definition cdlsetloc.c:79
uint8_t cause1
Definition cdlsetloc.c:75
uint32_t errorTime
Definition cdlsetloc.c:74
cester_assert_uint_eq(5, cause1)
CESTER_TEST(cdlSetLoc, test_instances, int resetDone=resetCDRom();if(!resetDone) { cester_assert_true(resetDone);return;} initializeTime();CDROM_REG0=0;CDROM_REG2=0;CDROM_REG2=2;CDROM_REG2=0;CDROM_REG1=CDL_SETLOC;uint32_t ackTime=waitCDRomIRQ();uint8_t cause1=ackCDRomCause();uint8_t ctrl1=CDROM_REG0 &~3;uint8_t response[16];uint8_t responseSize=readResponse(response);uint8_t ctrl2=CDROM_REG0 &~3;CDROM_REG0=1;uint8_t cause1b=CDROM_REG3_UC;cester_assert_uint_eq(3, cause1);cester_assert_uint_eq(0xe0, cause1b);cester_assert_uint_eq(0x38, ctrl1);cester_assert_uint_eq(0x18, ctrl2);cester_assert_uint_eq(2, response[0]);cester_assert_uint_eq(1, responseSize);cester_assert_uint_ge(ackTime, 500);cester_assert_uint_lt(ackTime, 7000);ramsyscall_printf("Basic setloc to 00:02:00, ack in %ius\n", ackTime);) CESTER_TEST(cdlSetLocNoArgs
uint8_t cause1b
Definition cdlsetloc.c:81
uint8_t ctrl1
Definition cdlsetloc.c:76
CDROM_REG2
Definition cdlsetloc.c:167
initializeTime()
CDROM_REG1
Definition cdlsetloc.c:73
cester_assert_uint_lt(errorTime, 7000)
@ CDL_SETLOC
Definition cdrom.h:44
#define CDROM_REG3_UC
Definition cdrom.h:39
ramsyscall_printf("=== e01_kseg1_reads_no_fill ===\n")
uint32_t time1
Definition playing.c:109
ackCDRomCause()
uint32_t time2
Definition reading.c:338
cester_assert_true(seekDone)
uint32_t time3
Definition reading.c:351
uint8_t cause
Definition reading.c:707
readResponse(response)
void uint32_t(classId, spec)