From 393656a09800fb5c24416e0ada49e2023ef0b22a Mon Sep 17 00:00:00 2001 From: Neils Wagenaar Date: Wed, 6 Oct 2004 14:19:32 +0000 Subject: [PATCH] Added experimental/non-working(?) JaguarCD interface for Linux --- src/cdintf_linux.cpp | 108 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 102 insertions(+), 6 deletions(-) diff --git a/src/cdintf_linux.cpp b/src/cdintf_linux.cpp index bda8346..1d35eea 100644 --- a/src/cdintf_linux.cpp +++ b/src/cdintf_linux.cpp @@ -1,10 +1,42 @@ // // OS specific CDROM interface (linux) // -// by James L. Hammons +// by James L. Hammons and Niels Wagenaar // +// NOTE : This CD-ROM code *could* work with other UN*X related OS. However, +// we/I are not sure on this matter. +// +// This is very experimental and I have the feeling that this won't even compile. +// Hell, I don't even have a Linux dev system (broken) or Jaguar CD releases to +// test this code :( +// +// Big thanks to the DOSBOX team which provided us with great knowlegde about +// CD-ROM access and Linux/UN*X. + +// *** OS dependent CDROM stuffola *** +#include +#include +#include +#include +#include +#include + +// *** End OS dependent *** #include "log.h" +#include "string.h" + +// *** Virtual Jaguar dependent *** +//#include "SDL.h" // Yes, we use SDL for initializing the CD-ROM and +// // give us access to certain CD-ROM states. But not just yet. + +// *** SDL CD-ROM dependent *** // Not yet needed! +// SDL_CD *cdrom; // Our variable for SDL CD-ROM access. +// CDstatus status; // Let us get our status. +// char *status_str; + +// *** Local variables *** +char device_name[512] ; // Devicename, for example /dev/cdrom // // Linux support functions @@ -13,23 +45,87 @@ bool CDIntfInit(void) { - WriteLog("CDINTF: Init unimplemented!\n"); - return false; + // Setting device_name to /deb/cdrom. /dev/cdrom is the default CD-ROM + // drive on most UN*X systems. Well, I think it is. + // + // In the future we can probably use SDL for getting CDROM states and + // CD-ROM specific information. + strcpy(device_name, "/dev/cdrom"); + + // Let us open the device_name and check if we can open the CD-ROM. + int cdrom_fd = open(device_name, O_RDONLY | O_NONBLOCK); + + if (cdrom_fd <= 0) + { + // CD-ROM isn't accessable. + // Write the error in the log file and return false. + WriteLog("CDINTF: CDIntfInit - Unable to open CDROM!\n"); + return false; + } + else + { + // CD-ROM is accessable. + // Write the success in the log file and return true. + WriteLog("CDINTF: CDIntfInit - Succesfully opened CDROM!\n"); + close(device_name); + return true; + } + } void CDIntfDone(void) { + // Just in case : closing device_name. + WriteLog("CDINTF: CDIntfDone - Closing CDROM!\n"); + close(device_name); } bool CDIntfReadBlock(uint32 sector, uint8 * buffer) { - WriteLog("CDINTF: ReadBlock unimplemented!\n"); - return false; + unsigned int buflen = CD_FRAMESIZE_RAW; // Raw read, 2352 bytes per sector + //unsigned char *buf = new unsigned int[buflen]; // DOSBOX, do we need this? + int ret; + struct cdrom_read cdrom_read; + + // Let us open the device_name and check if we can open the CD-ROM. + int cdrom_fd = open(device_name, O_RDONLY | O_NONBLOCK); + if (cdrom_fd <= 0) + { + // CD-ROM isn't accessable. + // Write the error in the log file and return false. + WriteLog("CDINTF: CDIntfReadBlock - Unable to open CDROM!\n"); + return false; + } + + // Setting up the cdrom_read struct : + cdrom_read.cdread_lba = sector; // Which sector to read. + cdrom_read.cdread_bufaddr = (char*)buffer; // Where to put the data (?) + cdrom_read.cdread_buflen = buflen; // 2352 bytes/sector -> RAW read + + // Let us read the content we want. -1 (false) when it didn't work. + ret = ioctl(cdrom_fd, CDROMREADRAW, &cdrom_read); + + // Close the CD-ROM. + close(cdrom_fd); + + // The following was taken from DOSBOX. After reading the content, they write + // back the information from buf (based upon the size of buflen) to buffer. + // I think that this is not needed. *fingers crossed* + // + // MEM_BlockWrite(buffer, buf, buflen); + // delete[] buf; + + // Uncomment the following for debug reasons. + // + // WriteLog("CDINTF: CDIntfReadBlock - Reading sector %d!\n", sector); + + return (ret > 0); + } uint32 CDIntfGetNumSessions(void) { - // Still need relevant code here... !!! FIX !!! + // Still need relevant code here... return 2; } -- 2.37.2