Nugget
Bare-metal libraries and examples for the original PlayStation
Loading...
Searching...
No Matches
cdlstop.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 // Sends a command with no parameters and records its two responses.
31 // Returns 0 if either response does not arrive within its timeout.
32 static int stopCommand(uint8_t command, uint8_t* cause1, uint8_t* stat1, uint32_t* ackTime, uint8_t* cause2,
33 uint8_t* stat2, uint32_t* completeTime) {
34 uint8_t response[16];
35 *cause1 = *stat1 = *cause2 = *stat2 = 0xff;
36 *ackTime = *completeTime = 0;
38 CDROM_REG0 = 0;
40 uint32_t timeout = 1000000;
41 if (!waitCDRomIRQWithTimeout(&timeout)) return 0;
45 *stat1 = response[0];
46 timeout = 10000000;
47 if (!waitCDRomIRQWithTimeout(&timeout)) return 0;
51 *stat2 = response[0];
52 return 1;
53 }
54
55 static uint8_t stopNopStat() {
56 uint8_t response[16];
57 CDROM_REG0 = 0;
62 return response[0];
63 }
64)
65
66CESTER_TEST(cdlStopSpinning, test_instance,
67 int resetDone = resetCDRom();
68 if (!resetDone) {
70 return;
71 }
72
75 int ok = stopCommand(CDL_STOP, &cause1, &stat1, &ackTime, &cause2, &stat2, &completeTime);
76 uint8_t nopStat = stopNopStat();
77 ramsyscall_printf("Stop while spinning: ack %i stat %02x in %ius, complete %i stat %02x in %ius, Nop stat %02x\n",
88)
89
90CESTER_TEST(cdlStopStopped, test_instance,
91 int resetDone = resetCDRom();
92 if (!resetDone) {
94 return;
95 }
96
97 uint8_t cause1, stat1, cause2, stat2;
99 int setupOk = stopCommand(CDL_STOP, &cause1, &stat1, &ackTime, &cause2, &stat2, &completeTime);
100 if (!setupOk) {
102 return;
103 }
104 int ok = stopCommand(CDL_STOP, &cause1, &stat1, &ackTime, &cause2, &stat2, &completeTime);
105 ramsyscall_printf("Stop while stopped: ack %i stat %02x in %ius, complete %i stat %02x in %ius\n", cause1, stat1,
113)
114
115CESTER_TEST(cdlStandbyAfterStop, test_instance,
116 int resetDone = resetCDRom();
117 if (!resetDone) {
119 return;
120 }
121
122 uint8_t cause1, stat1, cause2, stat2;
124 int setupOk = stopCommand(CDL_STOP, &cause1, &stat1, &ackTime, &cause2, &stat2, &completeTime);
125 if (!setupOk) {
127 return;
128 }
129 int ok = stopCommand(CDL_STANDBY, &cause1, &stat1, &ackTime, &cause2, &stat2, &completeTime);
130 uint8_t nopStat = stopNopStat();
131 ramsyscall_printf("Standby after Stop: ack %i stat %02x in %ius, complete %i stat %02x in %ius, Nop stat %02x\n",
141)
142
143CESTER_TEST(cdlStandbySpinning, test_instance,
144 int resetDone = resetCDRom();
145 if (!resetDone) {
147 return;
148 }
149
150 uint8_t response[16];
152 CDROM_REG0 = 0;
154 uint32_t timeout = 1000000;
155 int ok = waitCDRomIRQWithTimeout(&timeout);
156 uint8_t cause = ackCDRomCause();
157 uint8_t size = readResponse(response);
158 ramsyscall_printf("Standby while spinning: ok %i cause %i size %i resp %02x %02x in %ius\n", ok, cause, size,
159 response[0], response[1], timeout);
165)
initializeTime()
uint8_t response[16]
Definition cdlgetlocl.c:84
waitCDRomIRQ()
readResponse(response)
ackCDRomCause()
cester_assert_uint_lt(ackTime, 10000)
int ok
Definition cdlstop.c:75
cester_assert_uint_eq(3, cause1)
uint8_t stat1
Definition cdlstop.c:73
uint32_t ackTime
Definition cdlstop.c:74
cester_assert_uint_ge(completeTime, 300000)
int resetDone
Definition cdlstop.c:116
test_instance
Definition cdlstop.c:115
cester_assert_true(ok)
uint32_t completeTime
Definition cdlstop.c:74
uint8_t cause1
Definition cdlstop.c:73
uint8_t cause2
Definition cdlstop.c:73
CESTER_BODY(static int stopCommand(uint8_t command, uint8_t *cause1, uint8_t *stat1, uint32_t *ackTime, uint8_t *cause2, uint8_t *stat2, uint32_t *completeTime) { uint8_t response[16];*cause1=*stat1=*cause2=*stat2=0xff;*ackTime=*completeTime=0;initializeTime();CDROM_REG0=0;CDROM_REG1=command;uint32_t timeout=1000000;if(!waitCDRomIRQWithTimeout(&timeout)) return 0;*ackTime=timeout;*cause1=ackCDRomCause();readResponse(response);*stat1=response[0];timeout=10000000;if(!waitCDRomIRQWithTimeout(&timeout)) return 0;*completeTime=timeout;*cause2=ackCDRomCause();readResponse(response);*stat2=response[0];return 1;} static uint8_t stopNopStat() { uint8_t response[16];CDROM_REG0=0;CDROM_REG1=CDL_NOP;waitCDRomIRQ();ackCDRomCause();readResponse(response);return response[0];})
Definition cdlstop.c:29
int setupOk
Definition cdlstop.c:124
CESTER_TEST(cdlStopStopped, test_instance, int resetDone=resetCDRom();if(!resetDone) { cester_assert_true(resetDone);return;} uint8_t cause1, stat1, cause2, stat2;uint32_t ackTime, completeTime;int setupOk=stopCommand(CDL_STOP, &cause1, &stat1, &ackTime, &cause2, &stat2, &completeTime);if(!setupOk) { cester_assert_true(setupOk);return;} int ok=stopCommand(CDL_STOP, &cause1, &stat1, &ackTime, &cause2, &stat2, &completeTime);ramsyscall_printf("Stop while stopped: ack %i stat %02x in %ius, complete %i stat %02x in %ius\n", cause1, stat1, ackTime, cause2, stat2, completeTime);cester_assert_true(ok);cester_assert_uint_eq(3, cause1);cester_assert_uint_eq(0x00, stat1);cester_assert_uint_eq(2, cause2);cester_assert_uint_eq(0x00, stat2);cester_assert_uint_lt(completeTime, 10000);) CESTER_TEST(cdlStandbyAfterStop
uint8_t nopStat
Definition cdlstop.c:76
uint8_t stat2
Definition cdlstop.c:73
uint8_t cause
Definition cdltest.c:207
@ CDL_STANDBY
Definition cdrom.h:49
@ CDL_NOP
Definition cdrom.h:43
@ CDL_STOP
Definition cdrom.h:50
#define CDROM_REG0
Definition cdrom.h:31
#define CDROM_REG1
Definition cdrom.h:32
static int size
Definition string.h:142
ramsyscall_printf("=== e01_kseg1_reads_no_fill ===\n")
uint32_t timeout
Definition race.c:103
Definition gte-timing.c:164
void uint32_t(classId, spec)