-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Simple program to observe the behavior of the CD-ROM controller when the cover is opened/closed.
- Loading branch information
Showing
5 changed files
with
84 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
TARGET = disc-swap.elf | ||
LIBS += -lpsxspu -lpsxcd | ||
|
||
include ../../common-test.mk |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
#include <common.h> | ||
#include <dma.hpp> | ||
#include <io.h> | ||
#include <psxcd.h> | ||
#include <psxpad.h> | ||
#include <psxapi.h> | ||
#include <psxetc.h> | ||
|
||
// Basic test to determine behavior of CD-ROM controller when the lid is opened. | ||
|
||
void wait_for_disc() { | ||
unsigned char last_result = 0xFF; | ||
bool first = true; | ||
for (;;) | ||
{ | ||
unsigned char result[4] = {}; | ||
if (!CdControl(CdlNop, nullptr, result)) | ||
continue; | ||
|
||
if (result[0] != last_result || first) { | ||
printf("> Getstat: 0x%02X\n", result[0]); | ||
last_result = result[0]; | ||
first = false; | ||
} | ||
|
||
if (!(last_result & 0x10)) | ||
break; | ||
} | ||
} | ||
|
||
int main() { | ||
initVideo(320, 240); | ||
printf("\ncdrom/disc-swap\n"); | ||
clearScreen(); | ||
|
||
for (;;) { | ||
printf("> Init CD\n"); | ||
CdInit(); | ||
|
||
unsigned char status; | ||
int irq = CdSync(1, &status); | ||
printf("> CD IRQ=%d, status=0x%02X\n", irq, status); | ||
|
||
if (status & 0x10) { | ||
printf("> Waiting for disc to be inserted...\n"); | ||
wait_for_disc(); | ||
} | ||
|
||
printf("*** Open the shell now ***\n"); | ||
|
||
int last_irq = irq; | ||
while (last_irq == irq) | ||
irq = CdSync(1, &status); | ||
printf("> Got IRQ %d (expected 5), status 0x%02X\n", irq, status); | ||
|
||
printf("*** Close the shell now ***\n"); | ||
wait_for_disc(); | ||
printf("> Disc detected\n"); | ||
} | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
cdrom/disc-swap | ||
> Init CD | ||
psxcd: Init Ok! | ||
> CD IRQ=2, status=0x02 | ||
*** Open the shell now *** | ||
> Got IRQ 5 (expected 5), status 0x01 | ||
*** Close the shell now *** | ||
> Getstat: 0x12 | ||
> Getstat: 0x10 | ||
> Getstat: 0x00 | ||
> Disc inserted? |