From 8b10fec0628ae6436bf6be6c5acd536549f00242 Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Mon, 30 Mar 2020 01:25:47 +1000 Subject: [PATCH] cdrom: add disc-swap test (#3) Simple program to observe the behavior of the CD-ROM controller when the cover is opened/closed. --- Makefile | 1 + README.md | 6 ++++ cdrom/disc-swap/Makefile | 4 +++ cdrom/disc-swap/main.cpp | 62 ++++++++++++++++++++++++++++++++++++++++ cdrom/disc-swap/psx.log | 11 +++++++ 5 files changed, 84 insertions(+) create mode 100644 cdrom/disc-swap/Makefile create mode 100644 cdrom/disc-swap/main.cpp create mode 100644 cdrom/disc-swap/psx.log diff --git a/Makefile b/Makefile index 7116bd6..b82f5bc 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,7 @@ TOPTARGETS = build clean IMAGES = common \ + cdrom/disc-swap \ cpu/access-time \ cpu/code-in-scratchpad \ dma/otc-test \ diff --git a/README.md b/README.md index 393e510..7dbda91 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,12 @@ Collection of PlayStation 1 tests for emulator development and hardware verifica ## Tests +### CD-ROM + +Name | Description +-------------------------|------------ +disc-swap | Program to observe behavior of CD-ROM controller when opening/closing the drive cover. + ### CPU Name | Description diff --git a/cdrom/disc-swap/Makefile b/cdrom/disc-swap/Makefile new file mode 100644 index 0000000..804a669 --- /dev/null +++ b/cdrom/disc-swap/Makefile @@ -0,0 +1,4 @@ +TARGET = disc-swap.elf +LIBS += -lpsxspu -lpsxcd + +include ../../common-test.mk diff --git a/cdrom/disc-swap/main.cpp b/cdrom/disc-swap/main.cpp new file mode 100644 index 0000000..d3e90c4 --- /dev/null +++ b/cdrom/disc-swap/main.cpp @@ -0,0 +1,62 @@ +#include +#include +#include +#include +#include +#include +#include + +// 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; +} diff --git a/cdrom/disc-swap/psx.log b/cdrom/disc-swap/psx.log new file mode 100644 index 0000000..f0bc056 --- /dev/null +++ b/cdrom/disc-swap/psx.log @@ -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?