git-svn-id: http://pcsx2.googlecode.com/svn/trunk@429 96395faa-99c1-11dd-bbfe-3dabce05a288

This commit is contained in:
refraction 2009-02-06 20:30:49 +00:00
parent 94cc1fd329
commit 73fff124b2
55 changed files with 8946 additions and 0 deletions

View File

@ -0,0 +1,43 @@
Changes:
-------
CDVDlinuz v0.4 (efp):
* Moved all "threaded" code to CDVDEFP (actual directory) (efp)
* Copied mid-level (not low-level) device drivers from CDVDisoEFP (efp)
* In Windows, when newly selected from the PCSX2 configure screen, CDVDinit()
(as well as InitConf()) are not called. Fixed. (efp)
CDVDEFP v0.3 (efp):
* Protection against "Interrupted system call" errors enhanced (threading)
* Simplified ReadLoop completion detection code (threading)
* Separated buffer.c from device.c for cross-CDVD portability.
CDVDEFP v0.2 (efp):
* Separated out device command calls (for easier maintainability)
* Added a read cache (currently sized at 512kb)
* Added threading code (pthreads, because it's portable)
* With threading comes tray polling (currently at 1/sec)
* With threading comes a read-ahead function (currently set to 64kb)
CDVDEFP v0.1 (efp):
* Updated to 0.6.0 (beta) specs
* Removed Glade influence in Configure/About interfaces
* Added O_NONBLOCK so disc is not required to be in drive when Pcsx2 starts
discs can now be switched out at will.
* Separated CD and DVD access calls for better maintainability
* Removed 2GB byte limitation to DVD sector calls
* Collected all info on disc when disc is first inserted
* Expanded disc type detection to meet 0.6.0 specs.
CD/DVD detection. PS1/PS2/CDDA/other detection.
* Multilevel Debug info added (currently controlled by #defines)
CDVDlinuz v0.3 (linuzappz):
* Updated to 0.4.3 specs
CDVDlinuz v0.2 (linuzappz):
* Updated to 0.2.9 specs
CDVDlinuz v0.1 (linuzappz):
* First Release
* Tested with Pcsx2
Email: <linuzappz@hotmail.com>

View File

@ -0,0 +1,342 @@
GNU GENERAL PUBLIC LICENSE
Version 2, June 1991
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The licenses for most software are designed to take away your
freedom to share and change it. By contrast, the GNU General Public
License is intended to guarantee your freedom to share and change free
software--to make sure the software is free for all its users. This
General Public License applies to most of the Free Software
Foundation's software and to any other program whose authors commit to
using it. (Some other Free Software Foundation software is covered by
the GNU Library General Public License instead.) You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
this service if you wish), that you receive source code or can get it
if you want it, that you can change the software or use pieces of it
in new free programs; and that you know you can do these things.
To protect your rights, we need to make restrictions that forbid
anyone to deny you these rights or to ask you to surrender the rights.
These restrictions translate to certain responsibilities for you if you
distribute copies of the software, or if you modify it.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must give the recipients all the rights that
you have. You must make sure that they, too, receive or can get the
source code. And you must show them these terms so they know their
rights.
We protect your rights with two steps: (1) copyright the software, and
(2) offer you this license which gives you legal permission to copy,
distribute and/or modify the software.
Also, for each author's protection and ours, we want to make certain
that everyone understands that there is no warranty for this free
software. If the software is modified by someone else and passed on, we
want its recipients to know that what they have is not the original, so
that any problems introduced by others will not reflect on the original
authors' reputations.
Finally, any free program is threatened constantly by software
patents. We wish to avoid the danger that redistributors of a free
program will individually obtain patent licenses, in effect making the
program proprietary. To prevent this, we have made it clear that any
patent must be licensed for everyone's free use or not licensed at all.
The precise terms and conditions for copying, distribution and
modification follow.
GNU GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License applies to any program or other work which contains
a notice placed by the copyright holder saying it may be distributed
under the terms of this General Public License. The "Program", below,
refers to any such program or work, and a "work based on the Program"
means either the Program or any derivative work under copyright law:
that is to say, a work containing the Program or a portion of it,
either verbatim or with modifications and/or translated into another
language. (Hereinafter, translation is included without limitation in
the term "modification".) Each licensee is addressed as "you".
Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope. The act of
running the Program is not restricted, and the output from the Program
is covered only if its contents constitute a work based on the
Program (independent of having been made by running the Program).
Whether that is true depends on what the Program does.
1. You may copy and distribute verbatim copies of the Program's
source code as you receive it, in any medium, provided that you
conspicuously and appropriately publish on each copy an appropriate
copyright notice and disclaimer of warranty; keep intact all the
notices that refer to this License and to the absence of any warranty;
and give any other recipients of the Program a copy of this License
along with the Program.
You may charge a fee for the physical act of transferring a copy, and
you may at your option offer warranty protection in exchange for a fee.
2. You may modify your copy or copies of the Program or any portion
of it, thus forming a work based on the Program, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:
a) You must cause the modified files to carry prominent notices
stating that you changed the files and the date of any change.
b) You must cause any work that you distribute or publish, that in
whole or in part contains or is derived from the Program or any
part thereof, to be licensed as a whole at no charge to all third
parties under the terms of this License.
c) If the modified program normally reads commands interactively
when run, you must cause it, when started running for such
interactive use in the most ordinary way, to print or display an
announcement including an appropriate copyright notice and a
notice that there is no warranty (or else, saying that you provide
a warranty) and that users may redistribute the program under
these conditions, and telling the user how to view a copy of this
License. (Exception: if the Program itself is interactive but
does not normally print such an announcement, your work based on
the Program is not required to print an announcement.)
These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Program,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works. But when you
distribute the same sections as part of a whole which is a work based
on the Program, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote it.
Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Program.
In addition, mere aggregation of another work not based on the Program
with the Program (or with a work based on the Program) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.
3. You may copy and distribute the Program (or a work based on it,
under Section 2) in object code or executable form under the terms of
Sections 1 and 2 above provided that you also do one of the following:
a) Accompany it with the complete corresponding machine-readable
source code, which must be distributed under the terms of Sections
1 and 2 above on a medium customarily used for software interchange; or,
b) Accompany it with a written offer, valid for at least three
years, to give any third party, for a charge no more than your
cost of physically performing source distribution, a complete
machine-readable copy of the corresponding source code, to be
distributed under the terms of Sections 1 and 2 above on a medium
customarily used for software interchange; or,
c) Accompany it with the information you received as to the offer
to distribute corresponding source code. (This alternative is
allowed only for noncommercial distribution and only if you
received the program in object code or executable form with such
an offer, in accord with Subsection b above.)
The source code for a work means the preferred form of the work for
making modifications to it. For an executable work, complete source
code means all the source code for all modules it contains, plus any
associated interface definition files, plus the scripts used to
control compilation and installation of the executable. However, as a
special exception, the source code distributed need not include
anything that is normally distributed (in either source or binary
form) with the major components (compiler, kernel, and so on) of the
operating system on which the executable runs, unless that component
itself accompanies the executable.
If distribution of executable or object code is made by offering
access to copy from a designated place, then offering equivalent
access to copy the source code from the same place counts as
distribution of the source code, even though third parties are not
compelled to copy the source along with the object code.
4. You may not copy, modify, sublicense, or distribute the Program
except as expressly provided under this License. Any attempt
otherwise to copy, modify, sublicense or distribute the Program is
void, and will automatically terminate your rights under this License.
However, parties who have received copies, or rights, from you under
this License will not have their licenses terminated so long as such
parties remain in full compliance.
5. You are not required to accept this License, since you have not
signed it. However, nothing else grants you permission to modify or
distribute the Program or its derivative works. These actions are
prohibited by law if you do not accept this License. Therefore, by
modifying or distributing the Program (or any work based on the
Program), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Program or works based on it.
6. Each time you redistribute the Program (or any work based on the
Program), the recipient automatically receives a license from the
original licensor to copy, distribute or modify the Program subject to
these terms and conditions. You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties to
this License.
7. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Program at all. For example, if a patent
license would not permit royalty-free redistribution of the Program by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Program.
If any portion of this section is held invalid or unenforceable under
any particular circumstance, the balance of the section is intended to
apply and the section as a whole is intended to apply in other
circumstances.
It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system, which is
implemented by public license practices. Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.
This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.
8. If the distribution and/or use of the Program is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Program under this License
may add an explicit geographical distribution limitation excluding
those countries, so that distribution is permitted only in or among
countries not thus excluded. In such case, this License incorporates
the limitation as if written in the body of this License.
9. The Free Software Foundation may publish revised and/or new versions
of the General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the Program
specifies a version number of this License which applies to it and "any
later version", you have the option of following the terms and conditions
either of that version or of any later version published by the Free
Software Foundation. If the Program does not specify a version number of
this License, you may choose any version ever published by the Free Software
Foundation.
10. If you wish to incorporate parts of the Program into other free
programs whose distribution conditions are different, write to the author
to ask for permission. For software which is copyrighted by the Free
Software Foundation, write to the Free Software Foundation; we sometimes
make exceptions for this. Our decision will be guided by the two goals
of preserving the free status of all derivatives of our free software and
of promoting the sharing and reuse of software generally.
NO WARRANTY
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
REPAIR OR CORRECTION.
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
convey the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Also add information on how to contact you by electronic and paper mail.
If the program is interactive, make it output a short notice like this
when it starts in an interactive mode:
Gnomovision version 69, Copyright (C) year name of author
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, the commands you use may
be called something other than `show w' and `show c'; they could even be
mouse-clicks or menu items--whatever suits your program.
You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the program, if
necessary. Here is a sample; alter the names:
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
`Gnomovision' (which makes passes at compilers) written by James Hacker.
<signature of Ty Coon>, 1 April 1989
Ty Coon, President of Vice
This General Public License does not permit incorporating your program into
proprietary programs. If your program is a subroutine library, you may
consider it more useful to permit linking proprietary applications with the
library. If this is what you want to do, use the GNU Library General
Public License instead of this License.

View File

@ -0,0 +1,367 @@
/* CD.c
* Copyright (C) 2002-2005 PCSX2 Team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* PCSX2 members can be contacted through their website at www.pcsx2.net.
*/
#include <errno.h> // errno
#include <stddef.h> // NULL
#include <string.h> // strerror()
#include <fcntl.h> // open()
#include <sys/ioctl.h> // ioctl()
#include <sys/stat.h> // open()
#include <sys/types.h> // lseek(), open()
#include <unistd.h> // close(), lseek(), (sleep())
#include <linux/cdrom.h> // CD/DVD based ioctl() and defines.
#include "../convert.h"
#include "logfile.h"
#include "device.h"
#include "CD.h"
// Constants
u8 *playstationcdname = "PLAYSTATION\0";
u8 *ps1name = "CD-XA001\0";
// CD-ROM temp storage structures (see linux/cdrom.h for details)
struct cdrom_tochdr cdheader;
struct cdrom_tocentry cdtrack;
struct cdrom_subchnl subchannel;
u8 cdtempbuffer[2352];
int cdmode; // mode of last CDVDreadTrack call (important for CDs)
// Internal Functions
void InitCDSectorInfo() {
cdmode = -1;
} // END InitSectorInfo();
// Function Calls from CDVD.c
void InitCDInfo() {
InitCDSectorInfo();
} // END InitDiscType()
s32 CDreadTrack(u32 lsn, int mode, u8 *buffer) {
s32 s32result;
#ifdef VERBOSE_FUNCTION
PrintLog("CDVD driver: CDreadTrack(%i)", lsn);
#endif /* VERBOSE_FUNCTION */
s32result = 0;
if(buffer == NULL) return(-1);
// The CD way of figuring out where to read.
LBAtoMSF(lsn, buffer);
switch(mode) {
case CDVD_MODE_2048:
case CDVD_MODE_2328:
case CDVD_MODE_2340:
case CDVD_MODE_2352:
errno = 4; // Interrupted system call... (simulated the first time)
while(errno == 4) {
errno = 0;
s32result = ioctl(devicehandle, CDROMREADRAW, buffer);
} // ENDWHILE- Continually being interrupted by the system...
break;
case CDVD_MODE_2368: // Unimplemented... as yet.
default:
#ifdef VERBOSE_WARNINGS
PrintLog("CDVD driver: Unknown Mode %i", mode);
#endif /* VERBOSE_WARNINGS */
return(-1); // Illegal Read Mode? Abort
break;
} // ENDSWITCH- Which read mode should we choose?
if((s32result == -1) || (errno != 0)) {
#ifdef VERBOSE_WARNINGS
PrintLog("CDVD driver: Error reading CD: %i:%s", errno, strerror(errno));
#endif /* VERBOSE_WARNINGS */
InitCDSectorInfo();
return(-1);
} // ENDIF- Trouble getting a track count?
cdmode = mode; // Save mode for buffer positioning later.
return(0); // Call accomplished
} // END CDreadTrack()
s32 CDgetBufferOffset() {
#ifdef VERBOSE_FUNCTION
PrintLog("CDVD driver: CDgetBufferOffset()");
#endif /* VERBOSE_FUNCTION */
switch(cdmode) {
case CDVD_MODE_2048:
return(0+24);
case CDVD_MODE_2328:
return(0+24);
case CDVD_MODE_2340:
return(0+12);
case CDVD_MODE_2352:
return(0+0);
case CDVD_MODE_2368: // Unimplemented... as yet.
default:
#ifdef VERBOSE_WARNINGS
PrintLog("CDVD driver: Unknown Mode %i", cdmode);
#endif /* VERBOSE_WARNINGS */
return(0); // Not to worry. for now.
} // ENDSWITCH- where should we put the buffer pointer?
} // END CDgetBuffer()
// I, personally, don't see the big deal with SubQ
// However, sooner or later I'll incorporate it into the Cache Buffer system
// (backward compatibility, and all that)
s32 CDreadSubQ(u32 lsn, cdvdSubQ *subq) {
int tempmode;
s32 s32result;
s32result = 0;
#ifdef VERBOSE_FUNCTION
PrintLog("CDVD driver: CDreadSubQ()");
#endif /* VERBOSE_FUNCTION */
tempmode = cdmode;
if(tempmode == -1) tempmode = CDVD_MODE_2352;
CDreadTrack(lsn, tempmode, cdtempbuffer);
if((s32result == -1) || (errno != 0)) {
#ifdef VERBOSE_WARNINGS
PrintLog("CDVD driver: Error prepping CD SubQ: %i:%s", errno, strerror(errno));
#endif /* VERBOSE_WARNINGS */
return(s32result);
} // ENDIF- Trouble?
subchannel.cdsc_format = CDROM_MSF;
s32result = ioctl(devicehandle, CDROMSUBCHNL, &subchannel);
if((s32result == -1) || (errno != 0)) {
#ifdef VERBOSE_WARNINGS
PrintLog("CDVD driver: Error reading CD SubQ: %i:%s", errno, strerror(errno));
#endif /* VERBOSE_WARNINGS */
return(s32result);
} // ENDIF- Trouble?
if(subq != NULL) {
subq->mode = subchannel.cdsc_adr;
subq->ctrl = subchannel.cdsc_ctrl;
subq->trackNum = subchannel.cdsc_trk;
subq->trackIndex = subchannel.cdsc_ind;
subq->trackM = subchannel.cdsc_reladdr.msf.minute;
subq->trackS = subchannel.cdsc_reladdr.msf.second;
subq->trackF = subchannel.cdsc_reladdr.msf.frame;
subq->discM = subchannel.cdsc_absaddr.msf.minute;
subq->discS = subchannel.cdsc_absaddr.msf.second;
subq->discF = subchannel.cdsc_absaddr.msf.frame;
} // ENDIF- Did the caller want all this data?
return(0);
} // END CDVDreadSubQ()
s32 CDgetTN(cdvdTN *cdvdtn) {
#ifdef VERBOSE_FUNCTION
PrintLog("CDVD driver: CDgetTN()");
#endif /* VERBOSE_FUNCTION */
if(cdvdtn != NULL) {
cdvdtn->strack = cdheader.cdth_trk0;
cdvdtn->etrack = cdheader.cdth_trk1;
} // ENDIF- programmer actually WANTS this info?
return(0); // Call accomplished
} // END CDVDgetTN()
s32 CDgetTD(u8 newtrack, cdvdTD *cdvdtd) {
u8 j;
u16 k;
char temptime[3];
#ifdef VERBOSE_FUNCTION
PrintLog("CDVD driver: CDgetTD()");
#endif /* VERBOSE_FUNCTION */
j = newtrack;
if(j == CDROM_LEADOUT) j = 0;
if(j == 0) {
k = 27;
} else {
k = j * 10 + 37;
} // ENDIF- Where to start hunting for this number?
if(cdvdtd != NULL) {
cdvdtd->type = tocbuffer[j*10 + 30];
temptime[0] = BCDTOHEX(tocbuffer[k]);
temptime[1] = BCDTOHEX(tocbuffer[k + 1]);
temptime[2] = BCDTOHEX(tocbuffer[k + 2]);
cdvdtd->lsn = MSFtoLBA(temptime);
} // ENDIF- Does the caller REALLY want this data?
return(0); // Call accomplished
} // END CDVDgetTD()
s32 CALLBACK CDgetDiskType(s32 ioctldisktype) {
s32 offset;
s32 s32result;
int i;
u8 j;
int tempdisctype;
offset = 0;
errno = 0;
i = 0;
j = 0;
tempdisctype = CDVD_TYPE_UNKNOWN;
#ifdef VERBOSE_FUNCTION
PrintLog("CDVD driver: CDgetDiskType()");
#endif /* VERBOSE_FUNCTION */
s32result = CDreadTrack(16, CDVD_MODE_2352, cdtempbuffer);
if((s32result != 0) || (errno != 0)) {
return(-1);
} // ENDIF- Cannot read the CD's ISO9660 volume sector? Abort
disctype = CDVD_TYPE_DETCTCD;
switch(ioctldisktype) {
case CDS_AUDIO:
#ifdef VERBOSE_DISC_TYPE
PrintLog("CDVD driver: Detected CDDA Audio disc.");
#endif /* VERBOSE_DISC_TYPE */
tempdisctype = CDVD_TYPE_CDDA;
tocbuffer[0] = 0x01;
break;
case CDS_DATA_1:
case CDS_MIXED:
#ifdef VERBOSE_DISC_TYPE
PrintLog("CDVD driver: Detected CD disc.");
#endif /* VERBOSE_DISC_TYPE */
tocbuffer[0] = 0x41;
CDreadTrack(16, CDVD_MODE_2048, cdtempbuffer);
offset = CDgetBufferOffset();
i = 0;
while((*(playstationcdname + i) != 0) &&
(*(playstationcdname + i) == cdtempbuffer[offset + 8 + i])) i++;
if(*(playstationcdname + i) == 0) {
i = 0;
while((*(ps1name + i) != 0) &&
(*(ps1name + i) == cdtempbuffer[offset + 1024 + i])) i++;
if(*(ps1name + i) == 0) {
#ifdef VERBOSE_DISC_TYPE
PrintLog("CDVD driver: Detected Playstation CD disc.");
#endif /* VERBOSE_DISC_TYPE */
tempdisctype = CDVD_TYPE_PSCD;
} else {
#ifdef VERBOSE_DISC_TYPE
PrintLog("CDVD driver: Detected Playstation 2 CD disc.");
#endif /* VERBOSE_DISC_TYPE */
tempdisctype = CDVD_TYPE_PS2CD;
} // ENDIF- Did we find the CD ident? (For Playstation 1 CDs)
} else {
tempdisctype = CDVD_TYPE_UNKNOWN;
} // ENDIF- Did we find the Playstation name?
break;
default:
return(-1);
} // ENDSWITCH- What has ioctl disc type come up with?
// Collect TN data
cdheader.cdth_trk0 = 0;
cdheader.cdth_trk1 = 0;
s32result = ioctl(devicehandle, CDROMREADTOCHDR, &cdheader);
if((s32result == -1) || (errno != 0)) {
#ifdef VERBOSE_WARNINGS
PrintLog("CDVD driver: Error reading TN: (%i) %i:%s",
s32result, errno, strerror(errno));
#endif /* VERBOSE_WARNINGS */
cdheader.cdth_trk0 = 1;
cdheader.cdth_trk1 = 1;
} // ENDIF- Failed to read in track count? Assume 1 track.
#ifdef VERBOSE_DISC_INFO
PrintLog("CDVD driver: Track Number Range: %i-%i",
cdheader.cdth_trk0, cdheader.cdth_trk1);
#endif /* VERBOSE_DISC_INFO */
tocbuffer[2] = 0xA0;
tocbuffer[7] = HEXTOBCD(cdheader.cdth_trk0);
tocbuffer[12] = 0xA1;
tocbuffer[17] = HEXTOBCD(cdheader.cdth_trk1);
// Collect disc TD data
cdtrack.cdte_track = CDROM_LEADOUT;
cdtrack.cdte_format = CDROM_LBA;
s32result = ioctl(devicehandle, CDROMREADTOCENTRY, &cdtrack);
if((s32result == -1) || (errno != 0)) {
#ifdef VERBOSE_WARNINGS
PrintLog("CDVD driver: Error reading TD for disc: (%i) %i:%s",
s32result, errno, strerror(errno));
#endif /* VERBOSE_WARNINGS */
return(-1);
} // ENDIF- Trouble getting a track count?
LBAtoMSF(cdtrack.cdte_addr.lba, &tocbuffer[27]);
#ifdef VERBOSE_DISC_INFO
PrintLog("CDVD driver: Total Time: %i:%i",
tocbuffer[27], tocbuffer[28]);
#endif /* VERBOSE_DISC_INFO */
tocbuffer[27] = HEXTOBCD(tocbuffer[27]);
tocbuffer[28] = HEXTOBCD(tocbuffer[28]);
tocbuffer[29] = HEXTOBCD(tocbuffer[29]);
// Collect track TD data
for(j = cdheader.cdth_trk0; j <= cdheader.cdth_trk1; j++) {
cdtrack.cdte_track = j; // j-1?
cdtrack.cdte_format = CDROM_LBA;
s32result = ioctl(devicehandle, CDROMREADTOCENTRY, &cdtrack);
if((s32result == -1) || (errno != 0)) {
#ifdef VERBOSE_WARNINGS
PrintLog("CDVD driver: Error reading TD for track %i: (%i) %i:%s",
j, s32result, errno, strerror(errno));
#endif /* VERBOSE_WARNINGS */
// No more here...
} else {
LBAtoMSF(cdtrack.cdte_addr.lba, &tocbuffer[j*10 + 37]);
#ifdef VERBOSE_DISC_INFO
PrintLog("CDVD driver: Track %i: Data Mode %i Disc Start Time:%i:%i.%i\n",
j,
cdtrack.cdte_datamode,
tocbuffer[j*10+37],
tocbuffer[j*10+38],
tocbuffer[j*10+39]);
#endif /* VERBOSE_DISC_INFO */
tocbuffer[j*10 + 30] = cdtrack.cdte_datamode;
tocbuffer[j*10 + 32] = HEXTOBCD(j);
tocbuffer[j*10 + 37] = HEXTOBCD(tocbuffer[j*10 + 37]);
tocbuffer[j*10 + 38] = HEXTOBCD(tocbuffer[j*10 + 38]);
tocbuffer[j*10 + 39] = HEXTOBCD(tocbuffer[j*10 + 39]);
} // ENDIF- Trouble getting a track count?
} // NEXT j- Reading each track's info in turn
errno = 0;
disctype = tempdisctype; // Trigger the fact we have the info (finally)
return(disctype);
} // END CDVDgetDiskType()

View File

@ -0,0 +1,46 @@
/* CD.h
* Copyright (C) 2002-2005 PCSX2 Team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* PCSX2 members can be contacted through their website at www.pcsx2.net.
*/
#ifndef __CD_H__
#define __CD_H__
#ifndef __LINUX__
#ifdef __linux__
#define __LINUX__
#endif /* __linux__ */
#endif /* No __LINUX__ */
#define CDVDdefs
#include "../PS2Edefs.h"
// Exported Functions
extern void InitCDInfo();
extern s32 CDreadTrack(u32 lsn, int mode, u8 *buffer);
extern s32 CDgetBufferOffset();
extern s32 CDreadSubQ(u32 lsn, cdvdSubQ *subq);
extern s32 CDgetTN(cdvdTN *cdvdtn);
extern s32 CDgetTD(u8 newtrack, cdvdTD *cdvdtd);
extern s32 CDgetDiskType(s32 ioctldisktype);
#endif /* __CD_H__ */

View File

@ -0,0 +1,368 @@
/* CDVDlinuz.c
* Copyright (C) 2002-2005 CDVDlinuz Team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <errno.h> // errno
#include <fcntl.h> // open()
#include <stddef.h> // NULL
#include <stdio.h> // printf()
#include <stdlib.h> // getenv(), system()
#include <string.h> // strerror(), sprintf()
#include <sys/ioctl.h> // ioctl()
#include <sys/stat.h> // stat()
#include <sys/types.h> // stat()
#include <time.h> // time_t, time(), struct timeval
#include <unistd.h> // stat()
#ifndef __LINUX__
#ifdef __linux__
#define __LINUX__
#endif /* __linux__ */
#endif /* No __LINUX__ */
#define CDVDdefs
#include "PS2Edefs.h"
// #include "PS2Etypes.h"
#include "CDVDlinuz.h"
#include "buffer.h"
#include "conf.h"
#include "logfile.h"
#include "CD.h" // InitCDInfo()
#include "DVD.h" // InitDVDInfo()
#include "device.h"
#include "../version.h"
// Globals
time_t lasttime;
// Interface Functions
u32 CALLBACK PS2EgetLibType() {
return(PS2E_LT_CDVD); // Library Type CDVD
} // END PS2EgetLibType()
u32 CALLBACK PS2EgetLibVersion2(u32 type) {
return((version<<16)|(revision<<8)|build);
} // END PS2EgetLibVersion2()
char* CALLBACK PS2EgetLibName() {
return(libname);
} // END PS2EgetLibName()
s32 CALLBACK CDVDinit() {
errno = 0;
InitLog();
if(OpenLog() != 0) return(-1);
#ifdef VERBOSE_FUNCTION
PrintLog("CDVD interface: CDVDinit()");
#endif /* VERBOSE_FUNCTION */
InitConf();
devicehandle = -1;
devicecapability = 0;
lasttime = time(NULL);
// Initialize DVD.c and CD.c as well
InitDisc();
InitDVDInfo();
InitCDInfo();
return(0);
} // END CDVDinit()
void CALLBACK CDVDshutdown() {
#ifdef VERBOSE_FUNCTION
PrintLog("CDVD interface: CDVDshutdown()");
#endif /* VERBOSE_FUNCTION */
DeviceClose();
CloseLog();
} // END CDVDshutdown()
s32 CALLBACK CDVDopen(const char* pTitleFilename) {
s32 s32result;
#ifdef VERBOSE_FUNCTION
PrintLog("CDVD interface: CDVDopen()");
#endif /* VERBOSE_FUNCTION */
InitBuffer();
LoadConf();
errno = 0;
s32result = DeviceOpen();
if(s32result != 0) return(s32result);
if(errno != 0) return(-1);
return(0);
} // END CDVDopen();
void CALLBACK CDVDclose() {
#ifdef VERBOSE_FUNCTION
PrintLog("CDVD interface: CDVDclose()");
#endif /* VERBOSE_FUNCTION */
DeviceClose();
} // END CDVDclose()
s32 CALLBACK CDVDreadTrack(u32 lsn, int mode) {
s32 s32result;
#ifdef VERBOSE_FUNCTION
PrintLog("CDVD interface: CDVDreadTrack(%i)", lsn);
#endif /* VERBOSE_FUNCTION */
s32result = 0;
errno = 0;
if(DiscInserted() == -1) return(-1);
if(userbuffer < BUFFERMAX) {
if((bufferlist[userbuffer].lsn == lsn) &&
(bufferlist[userbuffer].mode == mode)) {
return(0);
} // ENDIF- And it's the right one?
} // ENDIF- Are we already pointing at the buffer?
userbuffer = FindListBuffer(lsn);
if(userbuffer < BUFFERMAX) {
if((bufferlist[userbuffer].lsn == lsn) &&
(bufferlist[userbuffer].mode == mode)) {
return(0);
} // ENDIF- And it was the right one?
} // ENDIF- Was a buffer found in the cache?
replacebuffer++;
if(replacebuffer >= BUFFERMAX) replacebuffer = 0;
userbuffer = replacebuffer;
if(bufferlist[replacebuffer].upsort != 0xffff) {
RemoveListBuffer(replacebuffer);
} // ENDIF- Reference already in place? Remove it.
s32result = DeviceReadTrack(lsn, mode, bufferlist[replacebuffer].buffer);
bufferlist[replacebuffer].lsn = lsn;
bufferlist[replacebuffer].mode = mode;
bufferlist[replacebuffer].offset = DeviceBufferOffset();
if((s32result != 0) || (errno != 0)) {
bufferlist[replacebuffer].mode = -1; // Error! flag buffer as such.
} else {
if((disctype != CDVD_TYPE_PS2DVD) && (disctype != CDVD_TYPE_DVDV)) {
if(mode == CDVD_MODE_2352) {
CDreadSubQ(lsn, &bufferlist[replacebuffer].subq);
errno = 0;
} // ENDIF- Read subq as well?
} // ENDIF- Read a DVD buffer or a CD buffer?
} // ENDIF-Read ok? Fill out rest of buffer info.
AddListBuffer(replacebuffer);
return(s32result);
} // END CDVDreadTrack()
u8* CALLBACK CDVDgetBuffer() {
#ifdef VERBOSE_FUNCTION
PrintLog("CDVD interface: CDVDgetBuffer()");
#endif /* VERBOSE_FUNCTION */
if(DiscInserted() == -1) return(NULL);
if(userbuffer == 0xffff) {
#ifdef VERBOSE_WARNINGS
PrintLog("CDVD interface: Not pointing to a buffer!");
#endif /* VERBOSE_WARNINGS */
return(NULL); // No buffer reference?
} // ENDIF- user buffer not pointing at anything? Abort
if(bufferlist[userbuffer].mode < 0) {
#ifdef VERBOSE_WARNINGS
PrintLog("CDVD interface: Error in buffer!");
#endif /* VERBOSE_WARNINGS */
return(NULL); // Bad Sector?
} // ENDIF- Trouble reading physical sector? Tell them.
return(bufferlist[userbuffer].buffer + bufferlist[userbuffer].offset);
} // END CDVDgetBuffer()
// Note: without the lsn, I could pull the SubQ data directly from
// the stored buffer (in buffer.h). Oh, well.
s32 CALLBACK CDVDreadSubQ(u32 lsn, cdvdSubQ *subq) {
#ifdef VERBOSE_FUNCTION
PrintLog("CDVD interface: CDVDreadSubQ(%i)", lsn);
#endif /* VERBOSE_FUNCTION */
if(DiscInserted() == -1) return(-1);
// DVDs don't have SubQ data
if(disctype == CDVD_TYPE_PS2DVD) return(-1);
if(disctype == CDVD_TYPE_DVDV) return(-1);
return(CDreadSubQ(lsn, subq));
} // END CDVDreadSubQ()
s32 CALLBACK CDVDgetTN(cdvdTN *cdvdtn) {
#ifdef VERBOSE_FUNCTION
PrintLog("CDVD interface: CDVDgetTN()");
#endif /* VERBOSE_FUNCTION */
if(DiscInserted() == -1) return(-1);
if((disctype == CDVD_TYPE_PS2DVD) || (disctype == CDVD_TYPE_DVDV)) {
return(DVDgetTN(cdvdtn));
} else {
return(CDgetTN(cdvdtn));
} // ENDIF- Are we looking at a DVD?
} // END CDVDgetTN()
s32 CALLBACK CDVDgetTD(u8 newtrack, cdvdTD *cdvdtd) {
#ifdef VERBOSE_FUNCTION
PrintLog("CDVD interface: CDVDgetTD()");
#endif /* VERBOSE_FUNCTION */
if(DiscInserted() == -1) return(-1);
if((disctype == CDVD_TYPE_PS2DVD) || (disctype == CDVD_TYPE_DVDV)) {
return(DVDgetTD(newtrack, cdvdtd));
} else {
return(CDgetTD(newtrack, cdvdtd));
} // ENDIF- Are we looking at a DVD?
} // END CDVDgetTD()
s32 CALLBACK CDVDgetTOC(void *toc) {
// A structure to fill in, or at least some documentation on what
// the PS2 expects from this call would be more helpful than a
// "void *".
union {
void *voidptr;
u8 *u8ptr;
} tocptr;
s32 i;
#ifdef VERBOSE_FUNCTION
PrintLog("CDVD interface: CDVDgetTOC()");
#endif /* VERBOSE_FUNCTION */
if(toc == NULL) return(-1);
if(DiscInserted() == -1) return(-1);
tocptr.voidptr = toc;
for(i = 0; i < 1024; i++) *(tocptr.u8ptr + i) = tocbuffer[i];
tocptr.voidptr = NULL;
return(0);
} // END CDVDgetTOC()
s32 CALLBACK CDVDgetDiskType() {
#ifdef VERBOSE_FUNCTION
// Called way too often in boot part of bios to be left in.
// PrintLog("CDVD interface: CDVDgetDiskType()");
#endif /* VERBOSE_FUNCTION */
if(lasttime != time(NULL)) {
lasttime = time(NULL);
DeviceTrayStatus();
} // ENDIF- Has enough time passed between calls?
return(disctype);
} // END CDVDgetDiskType()
s32 CALLBACK CDVDgetTrayStatus() {
#ifdef VERBOSE_FUNCTION
PrintLog("CDVD interface: CDVDgetTrayStatus()");
#endif /* VERBOSE_FUNCTION */
if(lasttime != time(NULL)) {
lasttime = time(NULL);
DeviceTrayStatus();
} // ENDIF- Has enough time passed between calls?
return(traystatus);
} // END CDVDgetTrayStatus()
s32 CALLBACK CDVDctrlTrayOpen() {
#ifdef VERBOSE_FUNCTION
PrintLog("CDVD interface: CDVDctrlTrayOpen()");
#endif /* VERBOSE_FUNCTION */
return(DeviceTrayOpen());
} // END CDVDctrlTrayOpen()
s32 CALLBACK CDVDctrlTrayClose() {
#ifdef VERBOSE_FUNCTION
PrintLog("CDVD interface: CDVDctrlTrayClose()");
#endif /* VERBOSE_FUNCTION */
return(DeviceTrayClose());
} // END CDVDctrlTrayClose()
void CALLBACK CDVDconfigure() {
ExecCfg("configure");
} // END CDVDconfigure()
void CALLBACK CDVDabout() {
ExecCfg("about");
} // END CDVDabout()
s32 CALLBACK CDVDtest() {
s32 s32result;
errno = 0;
if(devicehandle != -1) {
#ifdef VERBOSE_WARNINGS
PrintLog("CDVD interface: Device already open");
#endif /* VERBOSE_WARNINGS */
return(0);
} // ENDIF- Is the CD/DVD already in use? That's fine.
#ifdef VERBOSE_FUNCTION
PrintLog("CDVD driver: CDVDtest()");
#endif /* VERBOSE_FUNCTION */
s32result = DeviceOpen();
DeviceClose();
return(s32result);
} // END CDVDtest()

View File

@ -0,0 +1,31 @@
/* CDVDlinuz.h
* Copyright (C) 2002-2005 CDVDlinuz Team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef __CDVDLINUZ_H__
#define __CDVDLINUZ_H__
// #define VERBOSE_WARNINGS
// #define VERBOSE_FUNCTION
#define VERBOSE_DISC_INFO
#define VERBOSE_DISC_TYPE
#define READ_AHEAD_BUFFERS 32
#endif /* __CDVDLINUZ_H__ */

View File

@ -0,0 +1,584 @@
/* DVD.c
* Copyright (C) 2002-2005 PCSX2 Team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* PCSX2 members can be contacted through their website at www.pcsx2.net.
*/
#include <errno.h> // errno
#include <stddef.h> // NULL
#include <stdio.h> // sprintf()
#include <string.h> // strerror(), memset(), memcpy()
#include <fcntl.h> // open()
#include <sys/ioctl.h> // ioctl()
#include <sys/stat.h> // open()
#include <sys/types.h> // lseek(), open()
#include <unistd.h> // close(), lseek(), (sleep())
#include <linux/cdrom.h> // CD/DVD based ioctl() and defines.
#include "logfile.h"
#include "device.h"
#include "DVD.h"
#include "../PS2Etypes.h" // u8, u32
// Constants
u8 *playstationname = "PLAYSTATION\0";
// DVD storage structures (see linux/cdrom.h for details)
dvd_struct dvdphysical;
dvd_struct dvdcopyright[DVD_LAYERS];
dvd_struct dvdbca;
dvd_struct dvdmanufact[DVD_LAYERS];
u32 dvdlastlsn;
u8 dvdtempbuffer[2064];
// Internal Functions
void InitDVDSectorInfo() {
dvdlastlsn = 0xffffffff;
} // END InitSectorInfo();
void HexDump(u8 *strptr, u8 count) {
int i;
u8 ch[2];
char hexline[81];
int hexlinepos;
ch[1] = 0;
if(count == 0) count = 16;
if((count < 1) || (count > 16)) return;
hexlinepos = 0;
hexlinepos += sprintf(&hexline[hexlinepos], "CDVD driver: ");
for(i = 0; i < count; i++) {
hexlinepos += sprintf(&hexline[hexlinepos], "%.2x ", (*(strptr + i)) * 1);
} // NEXT i- printing each new Hex number
for(i = 0; i < count; i++) {
if((*(strptr + i) < 32) || (*(strptr + i) > 127)) {
hexlinepos += sprintf(&hexline[hexlinepos], ".");
} else {
ch[0] = *(strptr + i);
hexlinepos += sprintf(&hexline[hexlinepos], "%s", ch);
} // ENDIF- Is this an unprintable character?
} // NEXT i- printing each new character
PrintLog(hexline);
} // ENDIF HexDump()
//// DVD Structure Functions
s32 DVDreadPhysical() {
s32 s32result;
u8 i;
errno = 0;
#ifdef VERBOSE_FUNCTION
PrintLog("CDVD driver: DVDreadPhysical()\n");
#endif /* VERBOSE_FUNCTION */
memset(&dvdphysical, 0, sizeof(dvd_struct));
dvdphysical.type = DVD_STRUCT_PHYSICAL;
i = DVD_LAYERS;
while(i > 0) {
i--;
dvdphysical.physical.layer_num = i;
errno = 0;
s32result = ioctl(devicehandle, DVD_READ_STRUCT, &dvdphysical);
} // ENDWHILE- reading in all physical layers...
if((s32result == -1) || (errno != 0)) {
dvdphysical.type = 0xFF;
#ifdef VERBOSE_WARNINGS
PrintLog("CDVD driver: Error getting Physical structure: (%i) %i:%s", s32result, errno, strerror(errno));
#endif /* VERBOSE_WARNINGS */
return(-1);
} // ENDIF- Problem with reading Layer 0 of the physical data? Abort
i = 3;
while((i > 0) && (dvdphysical.physical.layer[i].end_sector == 0)) i--;
dvdphysical.physical.layer_num = i;
#ifdef VERBOSE_DISC_INFO
PrintLog("CDVD driver: Physical Characteristics");
PrintLog("CDVD driver: Number of Layers: %i",
(s32) dvdphysical.physical.layer_num + 1);
for(i = 0; i <= dvdphysical.physical.layer_num; i++) {
PrintLog("CDVD driver: Layer Number %i", i);
switch(dvdphysical.physical.layer[i].book_type) {
case 0:
PrintLog("CDVD driver: Book Type: DVD-ROM");
break;
case 1:
PrintLog("CDVD driver: Book Type: DVD-RAM");
break;
case 2:
PrintLog("CDVD driver: Book Type: DVD-R");
break;
case 3:
PrintLog("CDVD driver: Book Type: DVD-RW");
break;
case 9:
PrintLog("CDVD driver: Book Type: DVD+RW");
break;
default:
PrintLog("CDVD driver: Book Type: Unknown (%i)",
dvdphysical.physical.layer[i].book_type);
break;
} // ENDSWITCH- Displaying the Book Type
PrintLog("CDVD driver: Book Version %i",
dvdphysical.physical.layer[i].book_version);
switch(dvdphysical.physical.layer[i].min_rate) {
case 0:
PrintLog("CDVD driver: Use Minimum Rate for: DVD-ROM");
break;
case 1:
PrintLog("CDVD driver: Use Minimum Rate for: DVD-RAM");
break;
case 2:
PrintLog("CDVD driver: Use Minimum Rate for: DVD-R");
break;
case 3:
PrintLog("CDVD driver: Use Minimum Rate for: DVD-RW");
break;
case 9:
PrintLog("CDVD driver: Use Minimum Rate for: DVD+RW");
break;
default:
PrintLog("CDVD driver: Use Minimum Rate for: Unknown (%i)",
dvdphysical.physical.layer[i].min_rate);
break;
} // ENDSWITCH- Displaying the Minimum (Spin?) Rate
switch(dvdphysical.physical.layer[i].disc_size) {
case 0:
PrintLog("CDVD driver: Physical Disk Size: 120mm");
break;
case 1:
PrintLog("CDVD driver: Physical Disk Size: 80mm");
break;
default:
PrintLog("CDVD driver: Physical Disk Size: Unknown (%i)",
dvdphysical.physical.layer[i].disc_size);
break;
} // ENDSWITCH- What's the Disk Size?
switch(dvdphysical.physical.layer[i].layer_type) {
case 1:
PrintLog("CDVD driver: Layer Type: Read-Only");
break;
case 2:
PrintLog("CDVD driver: Layer Type: Recordable");
break;
case 4:
PrintLog("CDVD driver: Layer Type: Rewritable");
break;
default:
PrintLog("CDVD driver: Layer Type: Unknown (%i)",
dvdphysical.physical.layer[i].layer_type);
break;
} // ENDSWITCH- Displaying the Layer Type
switch(dvdphysical.physical.layer[i].track_path) {
case 0:
PrintLog("CDVD driver: Track Path: PTP");
break;
case 1:
PrintLog("CDVD driver: Track Path: OTP");
break;
default:
PrintLog("CDVD driver: Track Path: Unknown (%i)",
dvdphysical.physical.layer[i].track_path);
break;
} // ENDSWITCH- What's Track Path Layout?
// PrintLog("CDVD driver: Disc Size %i Layer Type %i Track Path %i Nlayers %i",
// dvdphysical.physical.layer[i].nlayers);
switch(dvdphysical.physical.layer[i].track_density) {
case 0:
PrintLog("CDVD driver: Track Density: .74 m/track");
break;
case 1:
PrintLog("CDVD driver: Track Density: .8 m/track");
break;
case 2:
PrintLog("CDVD driver: Track Density: .615 m/track");
break;
default:
PrintLog("CDVD driver: Track Density: Unknown (%i)",
dvdphysical.physical.layer[i].track_density);
break;
} // ENDSWITCH- Displaying the Track Density
switch(dvdphysical.physical.layer[i].linear_density) {
case 0:
PrintLog("CDVD driver: Linear Density: .267 m/bit");
break;
case 1:
PrintLog("CDVD driver: Linear Density: .293 m/bit");
break;
case 2:
PrintLog("CDVD driver: Linear Density: .409 to .435 m/bit");
break;
case 4:
PrintLog("CDVD driver: Linear Density: .280 to .291 m/bit");
break;
case 8:
PrintLog("CDVD driver: Linear Density: .353 m/bit");
break;
default:
PrintLog("CDVD driver: Linear Density: Unknown (%i)",
dvdphysical.physical.layer[i].linear_density);
break;
} // ENDSWITCH- Displaying the Linear Density
if(dvdphysical.physical.layer[i].start_sector == 0x30000) {
PrintLog("CDVD driver: Starting Sector: %lu (DVD-ROM, DVD-R, DVD-RW)",
dvdphysical.physical.layer[i].start_sector);
} else if(dvdphysical.physical.layer[i].start_sector == 0x31000) {
PrintLog("CDVD driver: Starting Sector: %lu (DVD-RAM, DVD+RW)",
dvdphysical.physical.layer[i].start_sector);
} else {
PrintLog("CDVD driver: Starting Sector: %lu",
dvdphysical.physical.layer[i].start_sector);
} // ENDLONGIF- What does the starting sector tell us?
PrintLog("CDVD driver: End of Layer 0: %lu",
dvdphysical.physical.layer[i].end_sector_l0);
PrintLog("CDVD driver: Ending Sector: %lu",
dvdphysical.physical.layer[i].end_sector);
if(dvdphysical.physical.layer[i].bca != 0)
PrintLog("CDVD driver: BCA data present");
} // NEXT i- Work our way through each layer...
#endif /* VERBOSE_DISC_INFO */
return(0); // Success. Physical data stored for perusal.
} // END DVDreadPhysical()
s32 DVDreadCopyright() {
s32 s32result;
u8 i;
int successflag;
#ifdef VERBOSE_FUNCTION
PrintLog("CDVD driver: DVDreadCopyright()");
#endif /* VERBOSE_FUNCTION */
successflag = 0;
for(i = 0; i <= dvdphysical.physical.layer_num; i++) {
memset(&dvdcopyright[i], 0, sizeof(dvd_struct));
dvdcopyright[i].type = DVD_STRUCT_COPYRIGHT;
dvdcopyright[i].copyright.layer_num = i;
errno = 0;
s32result = ioctl(devicehandle, DVD_READ_STRUCT, &dvdcopyright[i]);
if(s32result == 0) {
successflag = 1;
} else {
dvdcopyright[i].type = 0xFF;
} // ENDIF-
} // NEXT i- Getting copyright data for every known layer
if(successflag == 0) {
#ifdef VERBOSE_WARNINGS
PrintLog("CDVD driver: Error getting Copyright info: (%i) %i:%s", s32result, errno, strerror(errno));
#endif /* VERBOSE_WARNINGS */
return(-1);
} // ENDIF- Problem with read of physical data?
#ifdef VERBOSE_DISC_INFO
PrintLog("CDVD driver: Copyright Information\n");
for(i = 0; i <= dvdphysical.physical.layer_num; i++) {
if(dvdcopyright[i].type != 0xFF) {
PrintLog("CDVD driver: Layer Number %i CPST %i RMI %i",
dvdcopyright[i].copyright.layer_num,
dvdcopyright[i].copyright.cpst,
dvdcopyright[i].copyright.rmi);
} // ENDIF- Were we successful reading this one?
} // NEXT i- Printing out all copyright info found...
#endif /* VERBOSE_DISC_INFO */
errno = 0;
return(0); // Success. Copyright data stored for perusal.
} // END DVDreadCopyright()
s32 DVDreadBCA() {
s32 s32result;
int i;
i = 0;
errno = 0;
#ifdef VERBOSE_FUNCTION
PrintLog("CDVD driver: DVDreadBCA()");
#endif /* VERBOSE_FUNCTION */
memset(&dvdbca, 0, sizeof(dvd_struct));
dvdbca.type = DVD_STRUCT_BCA;
s32result = ioctl(devicehandle, DVD_READ_STRUCT, &dvdbca);
if((s32result == -1) || (errno != 0)) {
dvdbca.type = 0xFF;
#ifdef VERBOSE_WARNINGS
PrintLog("CDVD driver: Error getting BCA: (%i) %i:%s", s32result, errno, strerror(errno));
#endif /* VERBOSE_WARNINGS */
return(-1);
} // ENDIF- Problem with read of physical data?
#ifdef VERBOSE_DISC_INFO
PrintLog("CDVD driver: BCA Length %i Value:",
dvdbca.bca.len);
for(i = 0; i < 188-15; i += 16) {
HexDump(dvdbca.bca.value+i, 16);
} // NEXT i- dumping whole key data
#endif /* VERBOSE_DISC_INFO */
return(0); // Success. BCA data stored for perusal.
} // END DVDreadBCA()
s32 DVDreadManufact() {
s32 s32result;
u8 i;
int successflag;
int j;
#ifdef VERBOSE_FUNCTION
PrintLog("CDVD driver: DVDreadManufact()");
#endif /* VERBOSE_FUNCTION */
j = 0;
successflag = 0;
for(i = 0; i <= dvdphysical.physical.layer_num; i++) {
memset(&dvdmanufact[i], 0, sizeof(dvd_struct));
dvdmanufact[i].type = DVD_STRUCT_MANUFACT;
dvdmanufact[i].manufact.layer_num = i;
errno = 0;
s32result = ioctl(devicehandle, DVD_READ_STRUCT, &dvdmanufact[i]);
if((s32result != 0) || (errno != 0)) {
dvdmanufact[i].type = 0xFF;
} else {
successflag = 1;
} // ENDIF- Did we fail to read in some manufacturer data?
} // NEXT i- Collecting manufacturer data from all layers
if(successflag == 0) {
#ifdef VERBOSE_WARNINGS
PrintLog("CDVD driver: Error getting Manufact: (%i) %i:%s", s32result, errno, strerror(errno));
#endif /* VERBOSE_WARNINGS */
return(-1);
} // ENDIF- Problem with read of physical data?
#ifdef VERBOSE_DISC_INFO
PrintLog("CDVD driver: Manufact Data");
for(i = 0; i <= dvdphysical.physical.layer_num; i++) {
if(dvdmanufact[i].type != 0xFF) {
PrintLog("CDVD driver: Layer %i Length %i Value:",
dvdmanufact[i].manufact.layer_num,
dvdmanufact[i].manufact.len);
for(j = 0; j < 128-15; j += 16) {
HexDump(dvdmanufact[i].manufact.value+j, 16);
} // NEXT j- dumping whole key data
} // ENDIF- Do we have data at this layer?
} // NEXT i- Running through all the layers
#endif /* VERBOSE_DISC_INFO */
errno = 0;
return(0); // Success. Manufacturer's data stored for perusal.
} // END DVDreadManufact()
// External Functions
// Function Calls from CDVD.c
void InitDVDInfo() {
int j;
dvdphysical.type = 0xFF; // Using for empty=0xff, full!=0xff test
dvdbca.type = 0xFF;
for(j = 0; j < DVD_LAYERS; j++) {
dvdcopyright[j].type = 0xFF;
dvdmanufact[j].type = 0xFF;
} // NEXT j- Zeroing each layer of data
InitDVDSectorInfo();
} // END InitDiscType()
s32 DVDreadTrack(u32 lsn, int mode, u8 *buffer) {
s32 s32result;
off64_t offsettarget;
off64_t offsetresult;
errno = 0;
s32result = 0;
offsetresult = 0;
#ifdef VERBOSE_FUNCTION
PrintLog("CDVD driver: DVDreadTrack(%i)", lsn);
#endif /* VERBOSE_FUNCTION */
if(lsn != dvdlastlsn + 1) {
offsettarget = lsn;
offsettarget *= 2048;
errno = 4;
while(errno == 4) {
errno = 0;
offsetresult = lseek64(devicehandle, offsettarget, SEEK_SET);
} // ENDWHILE- waiting for the system interruptions to cease.
if((offsetresult < 0) || (errno != 0)) {
#ifdef VERBOSE_WARNINGS
PrintLog("CDVD driver: Error on seek: %i:%s", errno, strerror(errno));
#endif /* VERBOSE_WARNINGS */
InitDVDSectorInfo();
return(-1);
} // ENDIF- trouble with seek? Reset pointer and abort
} // ENDIF- Do we have to seek a new position to read?
errno = 4;
while(errno == 4) {
errno = 0;
s32result = read(devicehandle, buffer, 2048);
} // ENDWHILE- waiting for the system interruptions to cease.
if((s32result != 2048) || (errno != 0)) {
#ifdef VERBOSE_WARNINGS
PrintLog("CDVD driver: DVD Short Block, Size: %i", s32result);
PrintLog("CDVD driver: Error: %i:%s", errno, strerror(errno));
#endif /* VERBOSE_WARNINGS */
InitDVDSectorInfo();
return(-1);
} // ENDIF- Trouble reading the data? Reset pointer and abort
dvdlastlsn = lsn;
return(0); // Call accomplished
} // END DVDreadTrack()
s32 DVDgetTN(cdvdTN *cdvdtn) {
#ifdef VERBOSE_FUNCTION
PrintLog("CDVD driver: CDVDgetTN()");
#endif /* VERBOSE_FUNCTION */
// Going to treat this as one large track for now.
if(cdvdtn != NULL) {
cdvdtn->strack = 1;
cdvdtn->etrack = 1;
} // ENDIF- programmer actually WANTS this info?
return(0); // Call accomplished
} // END DVDgetTN()
s32 DVDgetTD(u8 newtrack, cdvdTD *cdvdtd) {
#ifdef VERBOSE_FUNCTION
PrintLog("CDVD driver: CDVDgetTD()");
#endif /* VERBOSE_FUNCTION */
if((newtrack >= 2) && (newtrack != CDROM_LEADOUT)) return(-1);
if(cdvdtd != NULL) {
cdvdtd->lsn = dvdphysical.physical.layer[0].end_sector
- dvdphysical.physical.layer[0].start_sector
+ 1;
cdvdtd->type = CDVD_MODE_2048;
} // ENDIF- Does the caller REALLY want this data?
return(0); // Call accomplished
} // END DVDgetTD()
s32 DVDgetDiskType(s32 ioctldisktype) {
s32 s32result;
int i;
s32 tempdisctype;
errno = 0;
s32result = 0;
i = 0;
tempdisctype = CDVD_TYPE_UNKNOWN;
#ifdef VERBOSE_FUNCTION
PrintLog("CDVD driver: DVDgetDiskType()");
#endif /* VERBOSE_FUNCTION */
if((ioctldisktype != CDS_DATA_1) && (ioctldisktype != CDS_MIXED)) {
return(-1);
} // ENDIF- Not a data disc we know of? Abort then
s32result = DVDreadPhysical();
if((s32result != 0) || (errno != 0)) {
return(-1);
} // ENDIF- Error reading the DVD physical structure? Not a DVD after all.
if(dvdphysical.physical.layer[0].end_sector >= (2048*1024)) {
#ifdef VERBOSE_DISC_TYPE
PrintLog("CDVD driver: DVD Found (Dual-Sided)");
#endif /* VERBOSE_DISC_TYPE */
disctype = CDVD_TYPE_DETCTDVDD;
} else {
#ifdef VERBOSE_DISC_TYPE
PrintLog("CDVD driver: DVD Found (Single-Sided)");
#endif /* VERBOSE_DISC_TYPE */
disctype = CDVD_TYPE_DETCTDVDS;
} // ENDIF- Definitely a DVD. Size Test?
// Read in the rest of the structures...
DVDreadCopyright();
DVDreadBCA();
DVDreadManufact();
// Test for "Playstation" header
s32result = DVDreadTrack(16, CDVD_MODE_2048, dvdtempbuffer);
if(s32result != 0) {
return(-1);
} else {
i = 0;
while((*(playstationname + i) != 0) &&
(*(playstationname + i) == dvdtempbuffer[8 + i])) {
i++;
} // ENDWHILE- Checking each letter of PLAYSTATION name for a match
if(*(playstationname + i) == 0) {
#ifdef VERBOSE_DISC_TYPE
PrintLog("CDVD driver: Detected Playstation 2 DVD");
#endif /* VERBOSE_DISC_TYPE */
tempdisctype = CDVD_TYPE_PS2DVD;
} else {
#ifdef VERBOSE_DISC_TYPE
PrintLog("CDVD driver: Guessing it's a Video DVD");
#endif /* VERBOSE_DISC_TYPE */
tempdisctype = CDVD_TYPE_DVDV;
} // ENDIF- Did we find the Playstation name?
} // ENDIF- Error reading disc volume information? Invalidate Disc
if(dvdphysical.physical.layer[0].end_sector >= (2048*1024)) {
tocbuffer[0] = 0x24; // Dual-Sided DVD
tocbuffer[4] = 0x41;
tocbuffer[5] = 0x95;
} else {
tocbuffer[0] = 0x04; // Single-Sided DVD
tocbuffer[4] = 0x86;
tocbuffer[5] = 0x72;
} // ENDIF- Are there too many sectors for a single-sided disc?
tocbuffer[1] = 0x02;
tocbuffer[2] = 0xF2;
tocbuffer[3] = 0x00;
tocbuffer[16] = 0x00;
tocbuffer[17] = 0x03;
tocbuffer[18] = 0x00;
tocbuffer[19] = 0x00;
disctype = tempdisctype; // Triggers the fact the other info is available
return(disctype);
} // END DVDgetDiskType()

View File

@ -0,0 +1,45 @@
/* DVD.h
* Copyright (C) 2002-2005 PCSX2 Team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* PCSX2 members can be contacted through their website at www.pcsx2.net.
*/
#ifndef __DVD_H__
#define __DVD_H__
#ifndef __LINUX__
#ifdef __linux__
#define __LINUX__
#endif /* __linux__ */
#endif /* No __LINUX__ */
#define CDVDdefs
#include "PS2Edefs.h"
// Exported Functions
extern void HexDump(u8 *strptr, u8 count);
extern void InitDVDInfo();
extern s32 DVDreadTrack(u32 lsn, int mode, u8 *buffer);
extern s32 DVDgetTN(cdvdTN *cdvdtn);
extern s32 DVDgetTD(u8 newtrack, cdvdTD *cdvdtd);
extern s32 DVDgetDiskType(s32 ioctldisktype);
#endif /* __DVD_H__ */

View File

@ -0,0 +1,71 @@
PLUGIN = libCDVDlinuz.so
PLUGINOBJS = CDVDlinuz.o ../buffer.o
PLUGINHEADERS = CDVDlinuz.h ../buffer.h
PLUGINFLAGS = -fPIC -Wall -O2 -fomit-frame-pointer -D_LARGEFILE64_SOURCE \
-I.. -I. -I./Linux
PLUGINLIBS =
CFG = cfgCDVDlinuz
CFGOBJS = aboutbox.o mainbox.o interface.o
CFGHEADERS = aboutbox.h mainbox.h interface.h
CFGFLAGS = -fPIC -Wall -O2 -fomit-frame-pointer -D_LARGEFILE64_SOURCE \
-I.. -I. -I./Linux
CFGLIBS =
SHAREDOBJS = actualfile.o conf.o logfile.o \
device.o CD.o DVD.o \
../convert.o ../ini.o ../version.o
SHAREDHEADERS = actualfile.h conf.h logfile.h \
device.h CD.h DVD.h \
../convert.h ../ini.h ../version.h
CC = gcc
GTKFLAGS = $(shell pkg-config --cflags gtk+-2.0)
//GTKFLAGS += -DG_DISABLE_DEPRECATED \
// -DGDK_DISABLE_DEPRECATED \
// -DGDK_PIXBUF_DISABLE_DEPRECATED \
// -DGTK_DISABLE_DEPRECATED
GTKLIBS = $(shell pkg-config --libs gtk+-2.0)
# Do we need to remove "-rdynamic" as well? Or is that just the main program?
all: plugin cfg
install: all
release: plugin cfg
cp $(PLUGIN) ../..
cp $(CFG) ../..
plugin: $(PLUGINOBJS) $(SHAREDOBJS)
# rm -f $(PLUGIN)
$(CC) -shared -Wl,-soname,$(PLUGIN) $(PLUGINFLAGS) $(PLUGINLIBS) \
$(PLUGINOBJS) $(SHAREDOBJS) -o $(PLUGIN)
strip --strip-unneeded --strip-debug $(PLUGIN)
cfg: $(CFGOBJS) $(SHAREDOBJS)
# rm -f $(CFG)
$(CC) $(CFGFLAGS) $(GTKFLAGS) $(CFGLIBS) $(GTKLIBS) \
$(CFGOBJS) $(SHAREDOBJS) -o $(CFG)
strip $(CFG)
$(PLUGINOBJS) $(SHAREDOBJS): %.o: %.c
$(CC) $(PLUGINFLAGS) -c $< -o $@
$(CFGOBJS): %.o: %.c
$(CC) $(CFGFLAGS) $(GTKFLAGS) -c $< -o $@
.PHONY : clean allclean
clean:
-rm -f $(PLUGINOBJS) $(PLUGIN) $(CFGOBJS) $(CFG) $(SHAREDOBJS)
-rm -f *~ temp.txt ../*~ ../temp.txt ../../*~
allclean:
-rm -f $(PLUGINOBJS) $(PLUGIN) $(CFGOBJS) $(CFG) $(SHAREDOBJS)
-rm -f *~ temp.txt ../*~ ../temp.txt ../../*~
-rm -f ../../$(PLUGIN) ../../$(CFG)

View File

@ -0,0 +1,106 @@
/* aboutbox.c
* Copyright (C) 2002-2005 PCSX2 Team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* PCSX2 members can be contacted through their website at www.pcsx2.net.
*/
#include <stddef.h> // NULL
#include <stdio.h> // sprintf()
#include <gtk/gtkbutton.h> // gtk_button_new_with_label()
#include <gtk/gtkcontainer.h> // gtk_container_add()
#include <gtk/gtkhbbox.h> // gtk_hbutton_box_new()
#include <gtk/gtklabel.h> // gtk_label_new()
#include <gtk/gtkmain.h> // gtk_init(), gtk_main(), gtk_main_quit()
#include <gtk/gtkvbox.h> // gtk_vbox_new()
#include <gtk/gtkwindow.h> // gtk_window_new()
#include "version.h"
#include "aboutbox.h"
struct AboutBoxData aboutbox;
gint AboutBoxCancelEvent(GtkWidget *widget, GdkEvent event, gpointer data) {
if(aboutbox.window != NULL) {
gtk_widget_destroy(aboutbox.window);
aboutbox.window = NULL;
} // ENDIF- Do we have an About Box still?
gtk_main_quit();
return(TRUE);
} // END AboutBoxCancelEvent()
void AboutBoxDisplay() {
GtkWidget *item;
GtkWidget *container;
GtkWidget *vbox1;
char templine[256];
aboutbox.window = NULL;
aboutbox.window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_container_set_border_width(GTK_CONTAINER(aboutbox.window), 5);
gtk_window_set_title(GTK_WINDOW(aboutbox.window), "About CDVDlinuz");
gtk_window_set_position(GTK_WINDOW(aboutbox.window), GTK_WIN_POS_CENTER);
gtk_window_set_modal(GTK_WINDOW(aboutbox.window), TRUE);
gtk_window_set_resizable(GTK_WINDOW(aboutbox.window), FALSE);
g_signal_connect(G_OBJECT(aboutbox.window), "delete_event",
G_CALLBACK(AboutBoxCancelEvent), NULL);
vbox1 = gtk_vbox_new(FALSE, 5);
gtk_container_add(GTK_CONTAINER(aboutbox.window), vbox1);
gtk_container_set_border_width(GTK_CONTAINER(vbox1), 5);
gtk_widget_show(vbox1);
sprintf(templine, "%s v%i.%i", libname, revision, build);
item = gtk_label_new(templine);
gtk_box_pack_start(GTK_BOX(vbox1), item, FALSE, FALSE, 0);
gtk_widget_show(item);
item = NULL;
item = gtk_label_new("Current Author: efp");
gtk_box_pack_start(GTK_BOX(vbox1), item, FALSE, FALSE, 0);
gtk_widget_show(item);
item = NULL;
item = gtk_label_new("Original code by: linuzappz & shadow");
gtk_box_pack_start(GTK_BOX(vbox1), item, FALSE, FALSE, 0);
gtk_widget_show(item);
item = NULL;
container = gtk_hbutton_box_new();
gtk_box_pack_start(GTK_BOX(vbox1), container, TRUE, TRUE, 0);
gtk_widget_show(container);
item = gtk_button_new_with_label("Ok");
gtk_container_add(GTK_CONTAINER(container), item);
GTK_WIDGET_SET_FLAGS(item, GTK_CAN_DEFAULT);
gtk_widget_show(item);
g_signal_connect(G_OBJECT(item), "clicked",
G_CALLBACK(AboutBoxCancelEvent), NULL);
item = NULL;
container = NULL;
vbox1 = NULL;
gtk_widget_show(aboutbox.window);
gtk_main();
} // END AboutDisplay()

View File

@ -0,0 +1,39 @@
/* aboutbox.h
* Copyright (C) 2002-2005 PCSX2 Team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* PCSX2 members can be contacted through their website at www.pcsx2.net.
*/
#ifndef ABOUTBOX_H
#define ABOUTBOX_H
#include <gtk/gtkwidget.h>
struct AboutBoxData {
GtkWidget *window; // GtkWindow - About Box
};
extern struct AboutBoxData aboutbox;
extern void AboutBoxDisplay();
#endif /* ABOUTBOX_H */

View File

@ -0,0 +1,222 @@
/* actualfile.c
* Copyright (C) 2002-2005 PCSX2 Team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* PCSX2 members can be contacted through their website at www.pcsx2.net.
*/
#include <errno.h> // errno
#include <fcntl.h> // open()
#include <stdio.h> // rename()
#include <string.h> // strerror()
#include <sys/stat.h> // stat64(), open(), fstat()
#include <sys/types.h> // stat64(), open(), fstat(), lseek64()
#include <unistd.h> // stat64(), fstat(), lseek64(), read(), close(), write()
// unlink()
#include "logfile.h"
#include "actualfile.h"
int IsActualFile(const char *filename) {
int retval;
struct stat64 filestat;
#ifdef VERBOSE_FUNCTION_ACTUALFILE
PrintLog("CDVDiso file: IsActualFile(%s)", filename);
#endif /* VERBOSE_FUNCTION_ACTUALFILE */
errno = 0;
retval = stat64(filename, &filestat);
if((retval < 0) || (errno != 0)) {
#ifdef VERBOSE_WARNING_ACTUALFILE
PrintLog("CDVDiso file: Error retrieving stats on %s", filename);
PrintLog("CDVDiso file: %i:%s\n", errno, strerror(errno));
#endif /* VERBOSE_WARNING_ACTUALFILE */
return(-1); // Name doesn't exist.
} // ENDIF- Trouble getting stat on a file?
if(S_ISREG(filestat.st_mode) == 0) return(-2); // Not a regular file.
return(0); // Yep, that's a file.
} // END IsActualFile()
void ActualFileDelete(const char *filename) {
#ifdef VERBOSE_FUNCTION_ACTUALFILE
PrintLog("CDVDiso file: ActualFileDelete(%s)", filename);
#endif /* VERBOSE_FUNCTION_ACTUALFILE */
unlink(filename);
} // END ActualFileDelete()
void ActualFileRename(const char *origname, const char *newname) {
#ifdef VERBOSE_FUNCTION_ACTUALFILE
PrintLog("CDVDiso file: ActualFileRename(%s->%s)", origname, newname);
#endif /* VERBOSE_FUNCTION_ACTUALFILE */
rename(origname, newname);
return;
} // END ActualFileRename()
ACTUALHANDLE ActualFileOpenForRead(const char *filename) {
int newhandle;
if(filename == NULL) return(-1);
#ifdef VERBOSE_FUNCTION_ACTUALFILE
PrintLog("CDVDiso file: ActualFileOpenForRead(%s)", filename);
#endif /* VERBOSE_FUNCTION_ACTUALFILE */
errno = 0;
newhandle = open(filename, O_RDONLY | O_LARGEFILE);
if((newhandle < 0) || (errno != 0)) {
#ifdef VERBOSE_WARNING_ACTUALFILE
PrintLog("CDVDiso file: Error opening file %s\n", filename);
PrintLog("CDVDiso file: (%i) %i:%s\n", newhandle, errno, strerror(errno));
#endif /* VERBOSE_WARNING_ACTUALFILE */
return(-1);
} // ENDIF- Error? Abort
return(newhandle);
} // END ActualFileOpenForRead()
off64_t ActualFileSize(ACTUALHANDLE handle) {
int retval;
struct stat64 filestat;
#ifdef VERBOSE_FUNCTION_ACTUALFILE
PrintLog("CDVDiso file: ActualFileSize()\n");
#endif /* VERBOSE_FUNCTION_ACTUALFILE */
errno = 0;
retval = fstat64(handle, &filestat);
if((retval < 0) || (errno != 0)) return(-1); // Name doesn't exist.
return(filestat.st_size);
} // END ActualFileSize()
int ActualFileSeek(ACTUALHANDLE handle, off64_t position) {
off64_t moved;
if(handle < 0) return(-1);
if(position < 0) return(-1); // Maybe... position = 0?
#ifdef VERBOSE_FUNCTION_ACTUALFILE
PrintLog("CDVDiso file: ActualFileSeek(%lli)", position);
#endif /* VERBOSE_FUNCTION_ACTUALFILE */
errno = 0;
moved = lseek64(handle, position, SEEK_SET);
if(errno != 0) {
#ifdef VERBOSE_WARNING_ACTUALFILE
PrintLog("CDVDiso file: Error on seek (%lli)", position);
PrintLog("CDVDiso file: %i:%s\n", errno, strerror(errno));
#endif /* VERBOSE_WARNING_ACTUALFILE */
return(-1);
} // ENDIF- Error? Abort
return(0);
} // END ActualFileSeek()
int ActualFileRead(ACTUALHANDLE handle, int bytes, char *buffer) {
int retval;
if(handle == ACTUALHANDLENULL) return(-1);
if(bytes < 1) return(-1);
if(buffer == NULL) return(-1);
#ifdef VERBOSE_FUNCTION_ACTUALFILE
PrintLog("CDVDiso file: ActualFileRead(%i)", bytes);
#endif /* VERBOSE_FUNCTION_ACTUALFILE */
errno = 0;
retval = read(handle, buffer, bytes);
if((retval < 0) || (errno != 0)) {
#ifdef VERBOSE_WARNING_ACTUALFILE
PrintLog("CDVDiso file: Error reading from file!");
PrintLog("CDVDiso file: %i:%s", errno, strerror(errno));
#endif /* VERBOSE_WARNING_ACTUALFILE */
// return(-1);
} // ENDIF- Error? Abort
return(retval); // Send back how many bytes read
} // END ActualFileRead()
void ActualFileClose(ACTUALHANDLE handle) {
if(handle < 0) return;
#ifdef VERBOSE_FUNCTION_ACTUALFILE
PrintLog("CDVDiso file: ActualFileClose()");
#endif /* VERBOSE_FUNCTION_ACTUALFILE */
errno = 0;
close(handle);
return;
} // END ActualFileClose()
ACTUALHANDLE ActualFileOpenForWrite(const char *filename) {
int newhandle;
if(filename == NULL) return(-1);
#ifdef VERBOSE_FUNCTION_ACTUALFILE
PrintLog("CDVDiso file: ActualFileOpenForWrite(%s)", filename);
#endif /* VERBOSE_FUNCTION_ACTUALFILE */
errno = 0;
newhandle = open(filename, O_WRONLY | O_CREAT | O_LARGEFILE, 0644);
if((newhandle < 0) || (errno != 0)) {
#ifdef VERBOSE_WARNING_ACTUALFILE
PrintLog("CDVDiso file: Error opening file %s", filename);
PrintLog("CDVDiso file: (%i) %i:%s", newhandle, errno, strerror(errno));
#endif /* VERBOSE_WARNING_ACTUALFILE */
return(-1);
} // ENDIF- Error? Abort
return(newhandle);
} // END ActualFileOpenForWrite()
int ActualFileWrite(ACTUALHANDLE handle, int bytes, char *buffer) {
int retval;
if(handle < 0) return(-1);
if(bytes < 1) return(-1);
if(buffer == NULL) return(-1);
#ifdef VERBOSE_FUNCTION_ACTUALFILE
PrintLog("CDVDiso file: ActualFileWrite(%i)", bytes);
#endif /* VERBOSE_FUNCTION_ACTUALFILE */
errno = 0;
retval = write(handle, buffer, bytes);
if((retval < 0) || (errno != 0)) {
#ifdef VERBOSE_WARNING_ACTUALFILE
PrintLog("CDVDiso file: Error writing to file!");
PrintLog("CDVDiso file: %i:%s", errno, strerror(errno));
#endif /* VERBOSE_WARNING_ACTUALFILE */
// return(-1);
} // ENDIF- Error? Abort
return(retval); // Send back how many bytes written
} // END ActualFileWrite()

View File

@ -0,0 +1,50 @@
/* actualfile.h
* Copyright (C) 2002-2005 PCSX2 Team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* PCSX2 members can be contacted through their website at www.pcsx2.net.
*/
#ifndef ACTUALFILE_H
#define ACTUALFILE_H
#include <sys/types.h> // off64_t
#define ACTUALHANDLE int
#define ACTUALHANDLENULL -1
// #define VERBOSE_FUNCTION_ACTUALFILE
// #define VERBOSE_WARNING_ACTUALFILE
extern int IsActualFile(const char *filename);
extern void ActualFileDelete(const char *filename);
extern void ActualFileRename(const char *origname, const char *newname);
extern ACTUALHANDLE ActualFileOpenForRead(const char *filename);
extern off64_t ActualFileSize(ACTUALHANDLE handle);
extern int ActualFileSeek(ACTUALHANDLE handle, off64_t position);
extern int ActualFileRead(ACTUALHANDLE handle, int bytes, char *buffer);
extern void ActualFileClose(ACTUALHANDLE handle);
extern ACTUALHANDLE ActualFileOpenForWrite(const char *filename);
extern int ActualFileWrite(ACTUALHANDLE handle, int bytes, char *buffer);
#endif /* ACTUALFILE_H */

View File

@ -0,0 +1,184 @@
/* conf.c
* Copyright (C) 2002-2005 PCSX2 Team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* PCSX2 members can be contacted through their website at www.pcsx2.net.
*/
#include <errno.h> // errno
#include <stddef.h> // NULL
#include <stdio.h> // sprintf()
#include <stdlib.h> // getenv()
#include <string.h> // strerror()
#include <sys/stat.h> // mkdir(), stat()
#include <sys/types.h> // mkdir(), stat()
#include <unistd.h> // stat()
// #define CDVDdefs
// #include "../PS2Edefs.h"
#include "logfile.h"
#include "../ini.h"
#include "conf.h"
const char *cfgname[] = { \
"./cfg/cfgCDVDlinuz", \
"../cfg/cfgCDVDlinuz", \
"./plugins/cfgCDVDlinuz", \
"../plugins/cfgCDVDlinuz", \
"./cfgCDVDlinuz", \
"../cfgCDVDlinuz", \
NULL };
const char *confnames[] = { "Device", NULL };
const u8 defaultdevice[] = DEFAULT_DEVICE;
const char defaulthome[] = "../inis";
const char defaultdirectory[] = ".PS2E";
const char defaultfile[] = "CDVDlinuz.ini";
char confdirname[256];
char conffilename[256];
CDVDconf conf;
void ExecCfg(char *arg) {
int nameptr;
struct stat filestat;
char templine[256];
#ifdef VERBOSE_FUNCTION_CONF
PrintLog("CDVDiso interface: ExecCfg(%s)", arg);
#endif /* VERBOSE FUNCTION_CONF */
errno = 0;
nameptr = 0;
while((cfgname[nameptr] != NULL) &&
(stat(cfgname[nameptr], &filestat) == -1)) nameptr++;
errno = 0;
if(cfgname[nameptr] == NULL) {
#ifdef VERBOSE_FUNCTION_CONF
PrintLog("CDVDiso interface: Couldn't find configuration program!");
#endif /* VERBOSE_FUNCTION_CONF */
return;
} // ENDIF- Did not find the executable?
sprintf(templine, "%s %s", cfgname[nameptr], arg);
system(templine);
} // END ExecCfg()
void InitConf() {
int i;
int pos;
char *envptr;
#ifdef VERBOSE_FUNCTION_CONF
PrintLog("CDVD config: InitConf()");
#endif /* VERBOSE_FUNCTION_CONF */
i = 0;
while((i < 255) && defaultdevice[i] != 0) {
conf.devicename[i] = defaultdevice[i];
i++;
} // ENDWHILE- copying the default CD/DVD name in
conf.devicename[i] = 0; // 0-terminate the device name
// Locating directory and file positions
pos = 0;
envptr = getenv("HOME");
if(envptr == NULL) {
// = <Default Home>
i = 0;
while((pos < 253) && (defaulthome[i] != 0)) {
confdirname[pos] = defaulthome[i];
conffilename[pos] = defaulthome[i];
pos++;
i++;
} // NEXT- putting a default place to store configuration data
} else {
// = <Env Home>/<Default Directory>
i = 0;
while((pos < 253) && (*(envptr + i) != 0)) {
confdirname[pos] = *(envptr + i);
conffilename[pos] = *(envptr + i);
pos++;
i++;
} // ENDWHILE- copying home directory info in
if(confdirname[pos-1] != '/') {
confdirname[pos] = '/';
conffilename[pos] = '/';
pos++;
} // ENDIF- No directory separator here? Add one.
i = 0;
while((pos < 253) && (defaultdirectory[i] != 0)) {
confdirname[pos] = defaultdirectory[i];
conffilename[pos] = defaultdirectory[i];
pos++;
i++;
} // NEXT- putting a default place to store configuration data
} // ENDIF- No Home directory?
confdirname[pos] = 0; // Directory reference finished
// += /<Config File Name>
if(conffilename[pos-1] != '/') {
conffilename[pos] = '/';
pos++;
} // ENDIF- No directory separator here? Add one.
i = 0;
while((pos < 253) && (defaultfile[i] != 0)) {
conffilename[pos] = defaultfile[i];
pos++;
i++;
} // NEXT- putting a default place to store configuration data
conffilename[pos] = 0; // File reference finished
#ifdef VERBOSE_FUNCTION_CONF
PrintLog("CDVD config: Directory: %s\n", confdirname);
PrintLog("CDVD config: File: %s\n", conffilename);
#endif /* VERBOSE_FUNCTION_CONF */
} // END InitConf()
void LoadConf() {
int retval;
#ifdef VERBOSE_FUNCTION_CONF
PrintLog("CDVD config: LoadConf()\n");
#endif /* VERBOSE_FUNCTION_CONF */
retval = INILoadString(conffilename, "Settings", "Device", conf.devicename);
if(retval < 0) {
sprintf(conf.devicename, "/dev/dvd");
} // ENDIF- Couldn't find keyword? Fill in a default
} // END LoadConf()
void SaveConf() {
#ifdef VERBOSE_FUNCTION_CONF
PrintLog("CDVD config: SaveConf()\n");
#endif /* VERBOSE_FUNCTION_CONF */
mkdir(confdirname, 0755);
INISaveString(conffilename, "Settings", "Device", conf.devicename);
} // END SaveConf()

View File

@ -0,0 +1,57 @@
/* conf.h
* Copyright (C) 2002-2005 PCSX2 Team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* PCSX2 members can be contacted through their website at www.pcsx2.net.
*/
#ifndef CONF_H
#define CONF_H
#ifndef __LINUX__
#ifdef __linux__
#define __LINUX__
#endif /* __linux__ */
#endif /* No __LINUX__ */
#define CDVDdefs
#include "../PS2Edefs.h"
#define VERBOSE_FUNCTION_CONF
// Configuration Data
typedef struct {
u8 devicename[256];
} CDVDconf;
extern CDVDconf conf;
#define DEFAULT_DEVICE "/dev/cdrom"
// Configuration Functions
extern void InitConf();
extern void LoadConf();
extern void SaveConf();
extern void ExecCfg(char *arg);
#endif /* CONF_H */

View File

@ -0,0 +1,420 @@
/* device.c
* Copyright (C) 2002-2005 PCSX2 Team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* PCSX2 members can be contacted through their website at www.pcsx2.net.
*/
#include <errno.h> // errno
#include <fcntl.h> // open()
#include <stddef.h> // NULL
#include <stdlib.h> // getenv()
#include <string.h> // strerror()
#include <sys/ioctl.h> // ioctl()
#include <sys/stat.h> // open()
#include <sys/types.h> // open()
#include <time.h> // time_t, time(), struct timeval
#include <unistd.h> // close(), select()
#include <linux/cdrom.h> // CD/DVD based ioctl() and defines.
// missing on some files for some reason.........
#ifndef CDC_IOCTLS
#define CDC_IOCTLS 0x400
#endif
#include "logfile.h"
#include "conf.h"
#include "CD.h"
#include "DVD.h"
#include "device.h"
#include "../PS2Etypes.h" // u32, u8, s32
// Globals
int devicehandle; // File Handle for the device/drive
s32 devicecapability; // Capability Flags
time_t lasttime; // Time marker (in case something gets called too often)
s32 traystatus; // Is the CD/DVD tray open?
s32 disctype; // Type of disc in drive (Video DVD, PSX CD, etc.)
u8 tocbuffer[2048];
void DeviceInit() {
devicehandle = -1;
devicecapability = 0;
lasttime = time(NULL);
InitDisc();
} // END DeviceInit()
// Called by DeviceOpen(), DeviceGetDiskType()
void InitDisc() {
int i;
#ifdef VERBOSE_FUNCTION_DEVICE
PrintLog("CDVD device: InitDisc()");
#endif /* VERBOSE_FUNCTION_DEVICE */
if((disctype == CDVD_TYPE_PS2DVD) ||
(disctype == CDVD_TYPE_DVDV)) {
InitDVDInfo();
} // ENDIF- Clean out DVD Disc Info?
if((disctype == CDVD_TYPE_PS2CD) ||
(disctype == CDVD_TYPE_PS2CDDA) ||
(disctype == CDVD_TYPE_PSCD) ||
(disctype == CDVD_TYPE_PSCDDA) ||
(disctype == CDVD_TYPE_CDDA)) {
InitCDInfo();
} // ENDIF- Clean out DVD Disc Info?
disctype = CDVD_TYPE_NODISC;
for(i = 0; i > sizeof(tocbuffer); i++) tocbuffer[i] = 0x00;
} // END InitDisc()
s32 DiscInserted() {
if(devicehandle == -1) return(-1);
if(traystatus == CDVD_TRAY_OPEN) return(-1);
if(disctype == CDVD_TYPE_ILLEGAL) return(-1);
// if(disctype == CDVD_TYPE_UNKNOWN) return(-1); // Hmm. Let this one through?
if(disctype == CDVD_TYPE_DETCTDVDD) return(-1);
if(disctype == CDVD_TYPE_DETCTDVDS) return(-1);
if(disctype == CDVD_TYPE_DETCTCD) return(-1);
if(disctype == CDVD_TYPE_DETCT) return(-1);
if(disctype == CDVD_TYPE_NODISC) return(-1);
#ifdef VERBOSE_FUNCTION_DEVICE
PrintLog("CDVD device: DiscInserted()");
#endif /* VERBOSE_FUNCTION_DEVICE */
return(0);
} // END DiscInserted()
// Called by DeviceTrayStatus() and CDVDopen()
s32 DeviceOpen() {
// s32 s32result;
errno = 0;
if(devicehandle != -1) {
#ifdef VERBOSE_WARNING_DEVICE
PrintLog("CDVD device: Device already open!");
#endif /* VERBOSE_WARNING_DEVICE */
return(0);
} // ENDIF- Is the CD/DVD already in use? That's fine.
#ifdef VERBOSE_FUNCTION_DEVICE
PrintLog("CDVD device: DeviceOpen()");
#endif /* VERBOSE_FUNCTION_DEVICE */
// InitConf();
// LoadConf(); // Should be done once before making this call
devicehandle = open(conf.devicename, O_RDONLY | O_NONBLOCK);
if(devicehandle == -1) {
#ifdef VERBOSE_WARNINGS
PrintLog("CDVD device: Error opening device: %i:%s", errno, strerror(errno));
#endif /* VERBOSE_WARNINGS */
return(-1);
} // ENDIF- Failed to open device? Abort
// Note: Hmm. Need a minimum capability in case this fails?
devicecapability = ioctl(devicehandle, CDROM_GET_CAPABILITY);
if(errno != 0) {
#ifdef VERBOSE_WARNINGS
PrintLog("CDVD device: Error getting device capabilities: %i:%s", errno, strerror(errno));
#endif /* VERBOSE_WARNINGS */
close(devicehandle);
devicehandle = -1;
devicecapability = 0;
return(-1);
} // ENDIF- Can't read drive capabilities? Close and Abort.
#ifdef VERBOSE_DISC_TYPE
PrintLog("CDVD device: Device Type(s)");
if(devicecapability < CDC_CD_R) PrintLog("CDVD device: CD");
if(devicecapability & CDC_CD_R) PrintLog("CDVD device: CD-R");
if(devicecapability & CDC_CD_RW) PrintLog("CDVD device: CD-RW");
if(devicecapability & CDC_DVD) PrintLog("CDVD device: DVD");
if(devicecapability & CDC_DVD_R) PrintLog("CDVD device: DVD-R");
if(devicecapability & CDC_DVD_RAM) PrintLog("CDVD device: DVD-RAM");
#endif /* VERBOSE_DISC_TYPE */
#ifdef VERBOSE_DISC_INFO
PrintLog("CDVD device: Device Capabilities:");
if(devicecapability & CDC_CLOSE_TRAY) PrintLog("CDVD device: Can close a tray");
if(devicecapability & CDC_OPEN_TRAY) PrintLog("CDVD device: Can open a tray");
// if(devicecapability & CDC_LOCK) PrintLog("CDVD device: Can lock the drive door");
if(devicecapability & CDC_SELECT_SPEED) PrintLog("CDVD device: Can change spin speed");
// if(devicecapability & CDC_SELECT_DISC) PrintLog("CDVD device: Can change disks (multi-disk tray)");
// if(devicecapability & CDC_MULTI_SESSION) PrintLog("CDVD device: Can read multi-session disks");
// if(devicecapability & CDC_MCN) PrintLog("CDVD device: Can read Medium Catalog Numbers (maybe)");
if(devicecapability & CDC_MEDIA_CHANGED) PrintLog("CDVD device: Can tell if the disc was changed");
if(devicecapability & CDC_PLAY_AUDIO) PrintLog("CDVD device: Can play audio disks");
// if(devicecapability & CDC_RESET) PrintLog("CDVD device: Can reset the device");
if(devicecapability & CDC_IOCTLS) PrintLog("CDVD device: Odd IOCTLs. Not sure of compatability");
if(devicecapability & CDC_DRIVE_STATUS) PrintLog("CDVD device: Can monitor the drive tray");
#endif /* VERBOSE_DISC_INFO */
////// Should be called after an open (instead of inside of one)
// InitDisc();
// traystatus = CDVD_TRAY_OPEN; // Start with Tray Open
// DeviceTrayStatus(); // Now find out for sure.
return(0); // Device opened and ready for use.
} // END DeviceOpen()
// Called by DeviceTrayStatus(), CDVDclose(), and CDVDshutdown()
void DeviceClose() {
if(devicehandle == -1) {
#ifdef VERBOSE_FUNCTION_DEVICE
PrintLog("CDVD device: Device already closed");
#endif /* VERBOSE_FUNCTION_DEVICE */
return;
} // ENDIF- Device already closed? Ok.
#ifdef VERBOSE_FUNCTION_DEVICE
PrintLog("CDVD device: DeviceClose()");
#endif /* VERBOSE_FUNCTION_DEVICE */
InitDisc();
close(devicehandle);
devicehandle = -1;
devicecapability = 0;
return;
} // END CDVDclose()
s32 DeviceReadTrack(u32 lsn, int mode, u8 *buffer) {
s32 s32result;
#ifdef VERBOSE_FUNCTION_DEVICE
PrintLog("CDVD device: DeviceReadTrack(%i)", lsn);
#endif /* VERBOSE_FUNCTION_DEVICE */
if(DiscInserted() == -1) return(-1);
// Get that data
if((disctype == CDVD_TYPE_PS2DVD) || (disctype == CDVD_TYPE_DVDV)) {
s32result = DVDreadTrack(lsn, mode, buffer);
} else {
s32result = CDreadTrack(lsn, mode, buffer);
} //ENDIF- Read a DVD sector or a CD sector?
return(s32result);
} // END DeviceReadTrack()
s32 DeviceBufferOffset() {
#ifdef VERBOSE_FUNCTION_DEVICE
PrintLog("CDVD device: DeviceBufferOffset()");
#endif /* VERBOSE_FUNCTION_DEVICE */
if(DiscInserted() == -1) return(-1);
if((disctype == CDVD_TYPE_PS2DVD) || (disctype == CDVD_TYPE_DVDV)) {
return(0);
} else {
return(CDgetBufferOffset());
} // ENDIF- Is this a DVD?
} // END DeviceBufferOffset()
s32 DeviceGetTD(u8 track, cdvdTD *cdvdtd) {
if(DiscInserted() == -1) return(-1);
if((disctype == CDVD_TYPE_PS2DVD) || (disctype == CDVD_TYPE_DVDV)) {
return(DVDgetTD(track, cdvdtd));
} else {
return(CDgetTD(track, cdvdtd));
} // ENDIF- Is this a DVD?
} // END DeviceGetTD()
// Called by DeviceTrayStatus()
s32 DeviceGetDiskType() {
s32 s32result;
s32 ioctldisktype;
errno = 0;
if(devicehandle == -1) {
return(-1);
} // ENDIF- Someone forget to open the device?
if(traystatus == CDVD_TRAY_OPEN) {
return(disctype);
} // ENDIF- Is the device tray open? No disc to check yet.
if(disctype != CDVD_TYPE_NODISC) {
return(disctype);
} // ENDIF- Already checked? Drive still closed? Disc hasn't changed.
#ifdef VERBOSE_FUNCTION_DEVICE
PrintLog("CDVD device: DeviceGetDiskType()");
#endif /* VERBOSE_FUNCTION_DEVICE */
disctype = CDVD_TYPE_DETCT;
ioctldisktype = ioctl(devicehandle, CDROM_DISC_STATUS);
if(errno != 0) {
#ifdef VERBOSE_WARNINGS
PrintLog("CDVD device: Trouble reading Disc Type!");
PrintLog("CDVD device: Error: %i:%s", errno, strerror(errno));
#endif /* VERBOSE_WARNINGS */
disctype = CDVD_TYPE_UNKNOWN;
return(disctype);
} // ENDIF- Trouble probing for a disc?
s32result = DVDgetDiskType(ioctldisktype);
if(s32result != -1) {
return(disctype);
} // ENDIF- Did we find a disc type?
s32result = CDgetDiskType(ioctldisktype);
if(s32result != -1) {
return(disctype);
} // ENDIF- Did we find a disc type?
disctype = CDVD_TYPE_UNKNOWN; // Not a CD? Not a DVD? Is is peanut butter?
return(disctype);
} // END CDVDgetDiskType()
// Called by PollLoop() and CDVDgetTrayStatus()
s32 DeviceTrayStatus() {
s32 s32result;
errno = 0;
#ifdef VERBOSE_FUNCTION_DEVICE
PrintLog("CDVD device: DeviceTrayStatus()");
#endif /* VERBOSE_FUNCTION_DEVICE */
if(devicehandle == -1) {
return(-1);
} // ENDIF- Someone forget to open the device?
if((devicecapability & CDC_DRIVE_STATUS) != 0) {
s32result = ioctl(devicehandle, CDROM_DRIVE_STATUS);
if(s32result < 0) {
#ifdef VERBOSE_WARNINGS
PrintLog("CDVD device: Trouble reading Drive Status!");
PrintLog("CDVD device: Error: (%i) %i:%s", s32result, errno, strerror(errno));
#endif /* VERBOSE_WARNINGS */
s32result = CDS_TRAY_OPEN;
} // ENDIF- Failure to get status? Assume it's open.
errno = 0;
} else {
s32result = ioctl(devicehandle, CDROM_DISC_STATUS);
if(errno != 0) {
#ifdef VERBOSE_WARNINGS
PrintLog("CDVD device: Trouble detecting Disc Status presense!");
PrintLog("CDVD device: Error: (%i) %i:%s", s32result, errno, strerror(errno));
#endif /* VERBOSE_WARNINGS */
s32result = CDS_TRAY_OPEN;
errno = 0;
} // ENDIF- Trouble?
if(s32result == CDS_NO_DISC) {
s32result = CDS_TRAY_OPEN;
} // ENDIF- Is there no disc in the device? Guess the tray is open
} // ENDIF- Can we poll the tray directly? (Or look at disc status instead?)
if(s32result == CDS_TRAY_OPEN) {
traystatus = CDVD_TRAY_OPEN;
if(disctype != CDVD_TYPE_NODISC) {
DeviceClose(); // Kind of severe way of flushing all buffers.
DeviceOpen();
InitDisc();
} // ENDIF- Tray just opened... clear disc info
} else {
traystatus = CDVD_TRAY_CLOSE;
if(disctype == CDVD_TYPE_NODISC) {
DeviceGetDiskType();
} // ENDIF- Tray just closed? Get disc information
} // ENDIF- Do we detect an open tray?
return(traystatus);
} // END CDVD_getTrayStatus()
s32 DeviceTrayOpen() {
s32 s32result;
errno = 0;
if(devicehandle == -1) {
return(-1);
} // ENDIF- Someone forget to open the device?
if((devicecapability & CDC_OPEN_TRAY) == 0) {
return(-1);
} // ENDIF- Don't have open capability? Error out.
// Tray already open? Exit.
if(traystatus == CDVD_TRAY_OPEN) return(0);
#ifdef VERBOSE_FUNCTION_DEVICE
PrintLog("CDVD device: DeviceTrayOpen()");
#endif /* VERBOSE_FUNCTION_DEVICE */
s32result = ioctl(devicehandle, CDROMEJECT);
#ifdef VERBOSE_WARNINGS
if((s32result != 0) || (errno != 0)) {
PrintLog("CDVD device: Could not open the tray!");
PrintLog("CDVD device: Error: (%i) %i:%s", s32result, errno, strerror(errno));
} // ENDIF- Trouble?
#endif /* VERBOSE_WARNINGS */
return(s32result);
} // END DeviceTrayOpen()
s32 DeviceTrayClose() {
s32 s32result;
errno = 0;
if(devicehandle == -1) {
return(-1);
} // ENDIF- Someone forget to open the device?
if((devicecapability & CDC_CLOSE_TRAY) == 0) {
return(-1);
} // ENDIF- Don't have close capability? Error out.
// Tray already closed? Exit.
if(traystatus == CDVD_TRAY_CLOSE) return(0);
#ifdef VERBOSE_FUNCTION_DEVICE
PrintLog("CDVD device: DeviceTrayClose()");
#endif /* VERBOSE_FUNCTION_DEVICE */
s32result = ioctl(devicehandle, CDROMCLOSETRAY);
#ifdef VERBOSE_WARNINGS
if((s32result != 0) || (errno != 0)) {
PrintLog("CDVD device: Could not close the tray!");
PrintLog("CDVD device: Error: (%i) %i:%s", s32result, errno, strerror(errno));
} // ENDIF- Trouble?
#endif /* VERBOSE_WARNINGS */
return(s32result);
} // END DeviceTrayClose()

View File

@ -0,0 +1,69 @@
/* device.h
* Copyright (C) 2002-2005 PCSX2 Team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* PCSX2 members can be contacted through their website at www.pcsx2.net.
*/
#ifndef __DEVICE_H__
#define __DEVICE_H__
#include <time.h> // time_t
#ifndef __LINUX__
#ifdef __linux__
#define __LINUX__
#endif /* __linux__ */
#endif /* No __LINUX__ */
#define CDVDdefs
#include "../PS2Edefs.h"
// #define VERBOSE_FUNCTION_DEVICE
// #define VERBOSE_WARNINGS
#define VERBOSE_DISC_TYPE
#define VERBOSE_DISC_INFO
// Device Data
extern int devicehandle;
extern s32 devicecapability; // Need to export?
extern time_t lasttime;
extern s32 traystatus;
extern s32 disctype;
extern u8 tocbuffer[];
// Device Functions
extern void DeviceInit();
extern void InitDisc();
extern s32 DiscInserted();
extern s32 DeviceOpen();
extern void DeviceClose();
extern s32 DeviceReadTrack(u32 lsn, int mode, u8 *buffer);
extern s32 DeviceBufferOffset();
extern s32 DeviceGetTD(u8 track, cdvdTD *cdvdtd);
extern s32 DeviceGetDiskType();
extern s32 DeviceTrayStatus();
extern s32 DeviceTrayOpen();
extern s32 DeviceTrayClose();
#endif /* __DEVICE_H__ */

View File

@ -0,0 +1,57 @@
/* interface.c
* Copyright (C) 2002-2005 PCSX2 Team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* PCSX2 members can be contacted through their website at www.pcsx2.net.
*/
#include <stddef.h> // NULL
#include <stdio.h> // sprintf()
#include <string.h> // strcmp()
#include <gtk/gtkmain.h> // gtk_init(), gtk_main(), gtk_main_quit()
#include <gtk/gtkwidget.h> // gtk_widget_show_all()
#include "logfile.h"
#include "conf.h"
#include "aboutbox.h"
#include "mainbox.h"
int main(int argc, char *argv[]) {
if(argc != 2) return(1);
gtk_init(NULL, NULL);
if(!strcmp(argv[1], "about")) {
AboutBoxDisplay();
return(0);
} else if (!strcmp(argv[1], "configure")) {
OpenLog();
InitConf();
LoadConf();
MainBoxDisplay();
gtk_widget_show_all(mainbox.window);
gtk_main();
CloseLog();
return(0);
} // ENDLONGIF- Which display would you like to see?
return(1); // No Displays chosen? Abort!
} // END main()

View File

@ -0,0 +1,90 @@
/* logfile.c
* Copyright (C) 2002-2005 PCSX2 Team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* PCSX2 members can be contacted through their website at www.pcsx2.net.
*/
#include <fcntl.h> // open
#include <stdio.h> // vsprintf()
#include <stdarg.h> // va_start(), va_end(), vsprintf()
#include <sys/stat.h> // mkdir(), open()
#include <sys/types.h> // mkdir(), open()
#include <unistd.h> // close(), write(), unlink()
#include "logfile.h"
int logfile;
char logfiletemp[2048];
void InitLog() {
// Token comment line
#ifdef VERBOSE_LOGFILE
mkdir("./logs", 0755);
unlink("./logs/CDVDlog.txt");
#endif /* VERBOSE LOGFILE */
} // END InitLog();
int OpenLog() {
// Token comment line
#ifdef VERBOSE_LOGFILE
logfile = -1;
logfile = open("./logs/CDVDlog.txt", O_WRONLY | O_CREAT | O_APPEND, 0755);
if(logfile == -1) return(-1);
#endif /* VERBOSE LOGFILE */
return(0);
} // END OpenLog();
void CloseLog() {
// Token comment line
#ifdef VERBOSE_LOGFILE
if(logfile != -1) {
close(logfile);
logfile = -1;
} // ENDIF- Is the log file actually open? Close it.
#endif /* VERBOSE LOGFILE */
} // END CloseLog()
void PrintLog(const char *fmt, ...) {
// Token comment line
#ifdef VERBOSE_LOGFILE
va_list list;
int len;
if(logfile == -1) return; // Log file not open.
va_start(list, fmt);
vsprintf(logfiletemp, fmt, list);
va_end(list);
len = 0;
while((len < 2048) && (logfiletemp[len] != 0)) len++;
if((len > 0) && (logfiletemp[len-1] == '\n')) len--;
if((len > 0) && (logfiletemp[len-1] == '\r')) len--;
logfiletemp[len] = 0; // Slice off the last "\r\n"...
write(logfile, logfiletemp, len);
write(logfile, "\r\n", 2); // ... and write out your own.
#endif /* VERBOSE LOGFILE */
} // END PrintLog()

View File

@ -0,0 +1,35 @@
/* logfile.h
* Copyright (C) 2002-2005 PCSX2 Team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* PCSX2 members can be contacted through their website at www.pcsx2.net.
*/
#ifndef LOGFILE_H
#define LOGFILE_H
#define VERBOSE_LOGFILE
extern void InitLog();
extern int OpenLog();
extern void CloseLog();
extern void PrintLog(const char *format, ...);
#endif /* LOGFILE_H */

View File

@ -0,0 +1,187 @@
/* mainbox.c
* Copyright (C) 2002-2005 PCSX2 Team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* PCSX2 members can be contacted through their website at www.pcsx2.net.
*/
#include <stddef.h> // NULL
#include <stdio.h> // sprintf()
#include <string.h> // strcpy()
#include <sys/stat.h> // stat()
#include <sys/types.h> // stat()
#include <unistd.h> // stat()
#include <gtk/gtkbutton.h> // gtk_button_new_with_label()
#include <gtk/gtkcontainer.h> // gtk_container_add()
#include <gtk/gtkentry.h> // gtk_entry_new()
#include <gtk/gtkhbbox.h> // gtk_hbutton_box_new()
#include <gtk/gtkhbox.h> // gtk_hbox_new()
#include <gtk/gtklabel.h> // gtk_label_new()
#include <gtk/gtkmain.h> // gtk_init(), gtk_main(), gtk_main_quit()
#include <gtk/gtkvbox.h> // gtk_vbox_new()
#include <gtk/gtkwindow.h> // gtk_window_new()
#include "conf.h"
// #include "logfile.h"
#include "device.h" // DeviceOpen(), DeviceClose()
#include "mainbox.h"
struct MainBoxData mainbox;
void MainBoxDestroy() {
if(mainbox.window != NULL) {
gtk_widget_destroy(mainbox.window);
mainbox.window = NULL;
mainbox.device = NULL;
mainbox.desc = NULL;
} // ENDIF- Do we have a Main Window still?
} // END MainBoxDestroy()
void MainBoxUnfocus() {
gtk_widget_set_sensitive(mainbox.device, FALSE);
gtk_window_iconify(GTK_WINDOW(mainbox.window));
} // END MainBoxUnfocus()
gint MainBoxDeviceEvent(GtkWidget *widget, GdkEvent event, gpointer data) {
struct stat filestat;
int retval;
retval = stat(gtk_entry_get_text(GTK_ENTRY(mainbox.device)), &filestat);
if(retval == -1) {
gtk_label_set_text(GTK_LABEL(mainbox.desc), "Device Type: ---");
return(TRUE);
} // ENDIF- Not a name of any sort?
if(S_ISDIR(filestat.st_mode) != 0) {
gtk_label_set_text(GTK_LABEL(mainbox.desc), "Device Type: Not a device");
return(TRUE);
} // ENDIF- Not a regular file?
gtk_label_set_text(GTK_LABEL(mainbox.desc), "Device Type: Device Likely");
return(TRUE);
} // END MainBoxFileEvent()
void MainBoxRefocus() {
GdkEvent event;
MainBoxDeviceEvent(NULL, event, NULL);
gtk_widget_set_sensitive(mainbox.device, TRUE);
gtk_window_set_focus(GTK_WINDOW(mainbox.window), mainbox.device);
gtk_window_deiconify(GTK_WINDOW(mainbox.window));
} // END MainBoxRefocus()
gint MainBoxCancelEvent(GtkWidget *widget, GdkEvent event, gpointer data) {
MainBoxDestroy();
gtk_main_quit();
return(TRUE);
} // END MainBoxCancelEvent()
gint MainBoxOKEvent(GtkWidget *widget, GdkEvent event, gpointer data) {
const char *tempdevice;
int retval;
MainBoxUnfocus();
tempdevice = gtk_entry_get_text(GTK_ENTRY(mainbox.device));
strcpy(conf.devicename, tempdevice); // Temporarily put in new device name
tempdevice = NULL;
if(*(conf.devicename) != 0) {
retval = DeviceOpen(); // Test by opening the device.
DeviceClose(); // Failed or not, close it.
if(retval != 0) {
MainBoxRefocus();
return(TRUE);
} // ENDIF- Not an ISO file? Message and Stop here.
} // ENDIF- Is there an ISO file to check out?
SaveConf();
MainBoxCancelEvent(widget, event, data);
return(TRUE);
} // END MainBoxOKEvent()
void MainBoxDisplay() {
GtkWidget *item;
GtkWidget *hbox1;
GtkWidget *vbox1;
mainbox.window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_container_set_border_width(GTK_CONTAINER(mainbox.window), 5);
gtk_window_set_title(GTK_WINDOW(mainbox.window), "CDVDlinuz Configuration");
gtk_window_set_position(GTK_WINDOW(mainbox.window), GTK_WIN_POS_CENTER);
g_signal_connect(G_OBJECT(mainbox.window), "delete_event",
G_CALLBACK(MainBoxCancelEvent), NULL);
vbox1 = gtk_vbox_new(FALSE, 5);
gtk_container_add(GTK_CONTAINER(mainbox.window), vbox1);
gtk_container_set_border_width(GTK_CONTAINER(vbox1), 5);
gtk_widget_show(vbox1);
hbox1 = gtk_hbox_new(FALSE, 10);
gtk_box_pack_start(GTK_BOX(vbox1), hbox1, TRUE, TRUE, 0);
gtk_widget_show(hbox1);
item = gtk_label_new("CD/DVD Device:");
gtk_box_pack_start(GTK_BOX(hbox1), item, FALSE, FALSE, 0);
gtk_widget_show(item);
item = NULL;
mainbox.device = gtk_entry_new();
gtk_box_pack_start(GTK_BOX(hbox1), mainbox.device, TRUE, TRUE, 0);
gtk_widget_show(mainbox.device);
g_signal_connect(G_OBJECT(mainbox.device), "changed",
G_CALLBACK(MainBoxDeviceEvent), NULL);
hbox1 = NULL;
mainbox.desc = gtk_label_new("File Type: ---");
gtk_box_pack_start(GTK_BOX(vbox1), mainbox.desc, FALSE, FALSE, 0);
gtk_widget_show(mainbox.desc);
hbox1 = gtk_hbutton_box_new();
gtk_box_pack_start(GTK_BOX(vbox1), hbox1, TRUE, TRUE, 0);
gtk_widget_show(hbox1);
item = gtk_button_new_with_label("Ok");
gtk_box_pack_start(GTK_BOX(hbox1), item, TRUE, TRUE, 0);
gtk_widget_show(item);
g_signal_connect(G_OBJECT(item), "clicked",
G_CALLBACK(MainBoxOKEvent), NULL);
item = gtk_button_new_with_label("Cancel");
gtk_box_pack_start(GTK_BOX(hbox1), item, TRUE, TRUE, 0);
gtk_widget_show(item);
g_signal_connect(G_OBJECT(item), "clicked",
G_CALLBACK(MainBoxCancelEvent), NULL);
item = NULL;
hbox1 = NULL;
vbox1 = NULL;
// We held off setting the name until now... so description would show.
gtk_entry_set_text(GTK_ENTRY(mainbox.device), conf.devicename);
} // END MainBoxDisplay()

View File

@ -0,0 +1,41 @@
/* mainbox.h
* Copyright (C) 2002-2005 PCSX2 Team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* PCSX2 members can be contacted through their website at www.pcsx2.net.
*/
#ifndef MAINBOX_H
#define MAINBOX_H
#include <gtk/gtkwidget.h>
struct MainBoxData {
GtkWidget *window; // GtkWindow
GtkWidget *device; // GtkEntry
GtkWidget *desc; // GtkLabel
};
extern struct MainBoxData mainbox;
// extern void MainBoxRefocus();
extern void MainBoxDisplay();
#endif /* MAINBOX_H */

View File

@ -0,0 +1,812 @@
#ifndef __PS2EDEFS_H__
#define __PS2EDEFS_H__
/*
* PS2E Definitions v0.6.2 (beta)
*
* Author: linuzappz@hotmail.com
* shadowpcsx2@yahoo.gr
* florinsasu@hotmail.com
*/
/*
Notes:
* Since this is still beta things may change.
* OSflags:
__LINUX__ (linux OS)
_WIN32 (win32 OS)
* common return values (for ie. GSinit):
0 - success
-1 - error
* reserved keys:
F1 to F10 are reserved for the emulator
* plugins should NOT change the current
working directory.
(on win32, add flag OFN_NOCHANGEDIR for
GetOpenFileName)
*/
#include "PS2Etypes.h"
#ifdef __LINUX__
#define CALLBACK
#else
#include <windows.h>
#endif
/* common defines */
#ifndef C_ASSERT
#define C_ASSERT(e) typedef char __C_ASSERT__[(e)?1:-1]
#endif
#if defined(GSdefs) || defined(PADdefs) || defined(SIOdefs) || \
defined(SPU2defs) || defined(CDVDdefs) || defined(DEV9defs) || \
defined(USBdefs) || defined(FWdefs)
#define COMMONdefs
#endif
// PS2EgetLibType returns (may be OR'd)
#define PS2E_LT_GS 0x01
#define PS2E_LT_PAD 0x02 // -=[ OBSOLETE ]=-
#define PS2E_LT_SPU2 0x04
#define PS2E_LT_CDVD 0x08
#define PS2E_LT_DEV9 0x10
#define PS2E_LT_USB 0x20
#define PS2E_LT_FW 0x40
#define PS2E_LT_SIO 0x80
// PS2EgetLibVersion2 (high 16 bits)
#define PS2E_GS_VERSION 0x0006
#define PS2E_PAD_VERSION 0x0002 // -=[ OBSOLETE ]=-
#define PS2E_SPU2_VERSION 0x0005
#define PS2E_CDVD_VERSION 0x0005
#define PS2E_DEV9_VERSION 0x0003
#define PS2E_USB_VERSION 0x0003
#define PS2E_FW_VERSION 0x0002
#define PS2E_SIO_VERSION 0x0001
#ifdef COMMONdefs
u32 CALLBACK PS2EgetLibType(void);
u32 CALLBACK PS2EgetLibVersion2(u32 type);
char* CALLBACK PS2EgetLibName(void);
#endif
// key values:
/* key values must be OS dependant:
win32: the VK_XXX will be used (WinUser)
linux: the XK_XXX will be used (XFree86)
*/
// event values:
#define KEYPRESS 1
#define KEYRELEASE 2
typedef struct {
u32 key;
u32 event;
} keyEvent;
// for 64bit compilers
typedef char __keyEvent_Size__[(sizeof(keyEvent) == 8)?1:-1];
// plugin types
#define SIO_TYPE_PAD 0x00000001
#define SIO_TYPE_MTAP 0x00000004
#define SIO_TYPE_RM 0x00000040
#define SIO_TYPE_MC 0x00000100
typedef int (CALLBACK * SIOchangeSlotCB)(int slot);
typedef struct {
u8 ctrl:4; // control and mode bits
u8 mode:4; // control and mode bits
u8 trackNum; // current track number (1 to 99)
u8 trackIndex; // current index within track (0 to 99)
u8 trackM; // current minute location on the disc (BCD encoded)
u8 trackS; // current sector location on the disc (BCD encoded)
u8 trackF; // current frame location on the disc (BCD encoded)
u8 pad; // unused
u8 discM; // current minute offset from first track (BCD encoded)
u8 discS; // current sector offset from first track (BCD encoded)
u8 discF; // current frame offset from first track (BCD encoded)
} cdvdSubQ;
typedef struct { // NOT bcd coded
u32 lsn;
u8 type;
} cdvdTD;
typedef struct {
u8 strack; //number of the first track (usually 1)
u8 etrack; //number of the last track
} cdvdTN;
// CDVDreadTrack mode values:
#define CDVD_MODE_2352 0 // full 2352 bytes
#define CDVD_MODE_2340 1 // skip sync (12) bytes
#define CDVD_MODE_2328 2 // skip sync+head+sub (24) bytes
#define CDVD_MODE_2048 3 // skip sync+head+sub (24) bytes
#define CDVD_MODE_2368 4 // full 2352 bytes + 16 subq
// CDVDgetDiskType returns:
#define CDVD_TYPE_ILLEGAL 0xff // Illegal Disc
#define CDVD_TYPE_DVDV 0xfe // DVD Video
#define CDVD_TYPE_CDDA 0xfd // Audio CD
#define CDVD_TYPE_PS2DVD 0x14 // PS2 DVD
#define CDVD_TYPE_PS2CDDA 0x13 // PS2 CD (with audio)
#define CDVD_TYPE_PS2CD 0x12 // PS2 CD
#define CDVD_TYPE_PSCDDA 0x11 // PS CD (with audio)
#define CDVD_TYPE_PSCD 0x10 // PS CD
#define CDVD_TYPE_UNKNOWN 0x05 // Unknown
#define CDVD_TYPE_DETCTDVDD 0x04 // Detecting Dvd Dual Sided
#define CDVD_TYPE_DETCTDVDS 0x03 // Detecting Dvd Single Sided
#define CDVD_TYPE_DETCTCD 0x02 // Detecting Cd
#define CDVD_TYPE_DETCT 0x01 // Detecting
#define CDVD_TYPE_NODISC 0x00 // No Disc
// CDVDgetTrayStatus returns:
#define CDVD_TRAY_CLOSE 0x00
#define CDVD_TRAY_OPEN 0x01
// cdvdTD.type (track types for cds)
#define CDVD_AUDIO_TRACK 0x01
#define CDVD_MODE1_TRACK 0x41
#define CDVD_MODE2_TRACK 0x61
#define CDVD_AUDIO_MASK 0x00
#define CDVD_DATA_MASK 0x40
// CDROM_DATA_TRACK 0x04 //do not enable this! (from linux kernel)
typedef void (*DEV9callback)(int cycles);
typedef int (*DEV9handler)(void);
typedef void (*USBcallback)(int cycles);
typedef int (*USBhandler)(void);
// freeze modes:
#define FREEZE_LOAD 0
#define FREEZE_SAVE 1
#define FREEZE_SIZE 2
typedef struct {
char name[8];
void *common;
} GSdriverInfo;
#ifdef _WIN32
typedef struct { // unsupported values must be set to zero
HWND hWnd;
HMENU hMenu;
HWND hStatusWnd;
} winInfo;
#endif
/* GS plugin API */
// if this file is included with this define
// the next api will not be skipped by the compiler
#ifdef GSdefs
// basic funcs
s32 CALLBACK GSinit();
s32 CALLBACK GSopen(void *pDsp, char *Title, int multithread);
void CALLBACK GSclose();
void CALLBACK GSshutdown();
void CALLBACK GSvsync(int field);
void CALLBACK GSgifTransfer1(u32 *pMem, u32 addr);
void CALLBACK GSgifTransfer2(u32 *pMem, u32 size);
void CALLBACK GSgifTransfer3(u32 *pMem, u32 size);
void CALLBACK GSgifSoftReset(u32 mask);
void CALLBACK GSreadFIFO(u64 *mem);
void CALLBACK GSreadFIFO2(u64 *mem, int qwc);
// extended funcs
// GSkeyEvent gets called when there is a keyEvent from the PAD plugin
void CALLBACK GSkeyEvent(keyEvent *ev);
void CALLBACK GSchangeSaveState(int, const char* filename);
void CALLBACK GSmakeSnapshot(char *path);
void CALLBACK GSmakeSnapshot2(char *pathname, int* snapdone, int savejpg);
void CALLBACK GSirqCallback(void (*callback)());
void CALLBACK GSprintf(int timeout, char *fmt, ...);
void CALLBACK GSsetBaseMem(void*);
void CALLBACK GSsetGameCRC(int);
// controls frame skipping in the GS, if this routine isn't present, frame skipping won't be done
void CALLBACK GSsetFrameSkip(int frameskip);
void CALLBACK GSreset();
void CALLBACK GSwriteCSR(u32 value);
void CALLBACK GSgetDriverInfo(GSdriverInfo *info);
#ifdef _WIN32
s32 CALLBACK GSsetWindowInfo(winInfo *info);
#endif
s32 CALLBACK GSfreeze(int mode, freezeData *data);
void CALLBACK GSconfigure();
void CALLBACK GSabout();
s32 CALLBACK GStest();
#endif
/* PAD plugin API -=[ OBSOLETE ]=- */
// if this file is included with this define
// the next api will not be skipped by the compiler
#ifdef PADdefs
// basic funcs
s32 CALLBACK PADinit(u32 flags);
s32 CALLBACK PADopen(void *pDsp);
void CALLBACK PADclose();
void CALLBACK PADshutdown();
// PADkeyEvent is called every vsync (return NULL if no event)
keyEvent* CALLBACK PADkeyEvent();
u8 CALLBACK PADstartPoll(int pad);
u8 CALLBACK PADpoll(u8 value);
// returns: 1 if supported pad1
// 2 if supported pad2
// 3 if both are supported
u32 CALLBACK PADquery();
// extended funcs
void CALLBACK PADgsDriverInfo(GSdriverInfo *info);
void CALLBACK PADconfigure();
void CALLBACK PADabout();
s32 CALLBACK PADtest();
#endif
/* SIO plugin API */
// if this file is included with this define
// the next api will not be skipped by the compiler
#ifdef SIOdefs
// basic funcs
s32 CALLBACK SIOinit(u32 port, u32 slot, SIOchangeSlotCB f);
s32 CALLBACK SIOopen(void *pDsp);
void CALLBACK SIOclose();
void CALLBACK SIOshutdown();
u8 CALLBACK SIOstartPoll(u8 value);
u8 CALLBACK SIOpoll(u8 value);
// returns: SIO_TYPE_{PAD,MTAP,RM,MC}
u32 CALLBACK SIOquery();
// extended funcs
void CALLBACK SIOconfigure();
void CALLBACK SIOabout();
s32 CALLBACK SIOtest();
#endif
/* SPU2 plugin API */
// if this file is included with this define
// the next api will not be skipped by the compiler
#ifdef SPU2defs
// basic funcs
s32 CALLBACK SPU2init();
s32 CALLBACK SPU2open(void *pDsp);
void CALLBACK SPU2close();
void CALLBACK SPU2shutdown();
void CALLBACK SPU2write(u32 mem, u16 value);
u16 CALLBACK SPU2read(u32 mem);
void CALLBACK SPU2readDMA4Mem(u16 *pMem, int size);
void CALLBACK SPU2writeDMA4Mem(u16 *pMem, int size);
void CALLBACK SPU2interruptDMA4();
void CALLBACK SPU2readDMA7Mem(u16* pMem, int size);
void CALLBACK SPU2writeDMA7Mem(u16 *pMem, int size);
void CALLBACK SPU2interruptDMA7();
u32 CALLBACK SPU2ReadMemAddr(int core);
void CALLBACK SPU2WriteMemAddr(int core,u32 value);
void CALLBACK SPU2irqCallback(void (*SPU2callback)(),void (*DMA4callback)(),void (*DMA7callback)());
// extended funcs
void CALLBACK SPU2async(u32 cycles);
s32 CALLBACK SPU2freeze(int mode, freezeData *data);
void CALLBACK SPU2configure();
void CALLBACK SPU2about();
s32 CALLBACK SPU2test();
#endif
/* CDVD plugin API */
// if this file is included with this define
// the next api will not be skipped by the compiler
#ifdef CDVDdefs
// basic funcs
s32 CALLBACK CDVDinit();
s32 CALLBACK CDVDopen(const char* pTitleFilename);
void CALLBACK CDVDclose();
void CALLBACK CDVDshutdown();
s32 CALLBACK CDVDreadTrack(u32 lsn, int mode);
// return can be NULL (for async modes)
u8* CALLBACK CDVDgetBuffer();
s32 CALLBACK CDVDreadSubQ(u32 lsn, cdvdSubQ* subq);//read subq from disc (only cds have subq data)
s32 CALLBACK CDVDgetTN(cdvdTN *Buffer); //disk information
s32 CALLBACK CDVDgetTD(u8 Track, cdvdTD *Buffer); //track info: min,sec,frame,type
s32 CALLBACK CDVDgetTOC(void* toc); //gets ps2 style toc from disc
s32 CALLBACK CDVDgetDiskType(); //CDVD_TYPE_xxxx
s32 CALLBACK CDVDgetTrayStatus(); //CDVD_TRAY_xxxx
s32 CALLBACK CDVDctrlTrayOpen(); //open disc tray
s32 CALLBACK CDVDctrlTrayClose(); //close disc tray
// extended funcs
void CALLBACK CDVDconfigure();
void CALLBACK CDVDabout();
s32 CALLBACK CDVDtest();
void CALLBACK CDVDnewDiskCB(void (*callback)());
#endif
/* DEV9 plugin API */
// if this file is included with this define
// the next api will not be skipped by the compiler
#ifdef DEV9defs
// basic funcs
// NOTE: The read/write functions CANNOT use XMM/MMX regs
// If you want to use them, need to save and restore current ones
s32 CALLBACK DEV9init();
s32 CALLBACK DEV9open(void *pDsp);
void CALLBACK DEV9close();
void CALLBACK DEV9shutdown();
u8 CALLBACK DEV9read8(u32 addr);
u16 CALLBACK DEV9read16(u32 addr);
u32 CALLBACK DEV9read32(u32 addr);
void CALLBACK DEV9write8(u32 addr, u8 value);
void CALLBACK DEV9write16(u32 addr, u16 value);
void CALLBACK DEV9write32(u32 addr, u32 value);
void CALLBACK DEV9readDMA8Mem(u32 *pMem, int size);
void CALLBACK DEV9writeDMA8Mem(u32 *pMem, int size);
// cycles = IOP cycles before calling callback,
// if callback returns 1 the irq is triggered, else not
void CALLBACK DEV9irqCallback(DEV9callback callback);
DEV9handler CALLBACK DEV9irqHandler(void);
// extended funcs
s32 CALLBACK DEV9freeze(int mode, freezeData *data);
void CALLBACK DEV9configure();
void CALLBACK DEV9about();
s32 CALLBACK DEV9test();
#endif
/* USB plugin API */
// if this file is included with this define
// the next api will not be skipped by the compiler
#ifdef USBdefs
// basic funcs
s32 CALLBACK USBinit();
s32 CALLBACK USBopen(void *pDsp);
void CALLBACK USBclose();
void CALLBACK USBshutdown();
u8 CALLBACK USBread8(u32 addr);
u16 CALLBACK USBread16(u32 addr);
u32 CALLBACK USBread32(u32 addr);
void CALLBACK USBwrite8(u32 addr, u8 value);
void CALLBACK USBwrite16(u32 addr, u16 value);
void CALLBACK USBwrite32(u32 addr, u32 value);
// cycles = IOP cycles before calling callback,
// if callback returns 1 the irq is triggered, else not
void CALLBACK USBirqCallback(USBcallback callback);
USBhandler CALLBACK USBirqHandler(void);
void CALLBACK USBsetRAM(void *mem);
// extended funcs
s32 CALLBACK USBfreeze(int mode, freezeData *data);
void CALLBACK USBconfigure();
void CALLBACK USBabout();
s32 CALLBACK USBtest();
#endif
/* FW plugin API */
// if this file is included with this define
// the next api will not be skipped by the compiler
#ifdef FWdefs
// basic funcs
// NOTE: The read/write functions CANNOT use XMM/MMX regs
// If you want to use them, need to save and restore current ones
s32 CALLBACK FWinit();
s32 CALLBACK FWopen(void *pDsp);
void CALLBACK FWclose();
void CALLBACK FWshutdown();
u32 CALLBACK FWread32(u32 addr);
void CALLBACK FWwrite32(u32 addr, u32 value);
void CALLBACK FWirqCallback(void (*callback)());
// extended funcs
s32 CALLBACK FWfreeze(int mode, freezeData *data);
void CALLBACK FWconfigure();
void CALLBACK FWabout();
s32 CALLBACK FWtest();
#endif
// might be useful for emulators
#ifdef PLUGINtypedefs
typedef u32 (CALLBACK* _PS2EgetLibType)(void);
typedef u32 (CALLBACK* _PS2EgetLibVersion2)(u32 type);
typedef char*(CALLBACK* _PS2EgetLibName)(void);
// GS
// NOTE: GSreadFIFOX/GSwriteCSR functions CANNOT use XMM/MMX regs
// If you want to use them, need to save and restore current ones
typedef s32 (CALLBACK* _GSinit)();
typedef s32 (CALLBACK* _GSopen)(void *pDsp, char *Title, int multithread);
typedef void (CALLBACK* _GSclose)();
typedef void (CALLBACK* _GSshutdown)();
typedef void (CALLBACK* _GSvsync)(int field);
typedef void (CALLBACK* _GSgifTransfer1)(u32 *pMem, u32 addr);
typedef void (CALLBACK* _GSgifTransfer2)(u32 *pMem, u32 size);
typedef void (CALLBACK* _GSgifTransfer3)(u32 *pMem, u32 size);
typedef void (CALLBACK* _GSgifSoftReset)(u32 mask);
typedef void (CALLBACK* _GSreadFIFO)(u64 *pMem);
typedef void (CALLBACK* _GSreadFIFO2)(u64 *pMem, int qwc);
typedef void (CALLBACK* _GSkeyEvent)(keyEvent* ev);
typedef void (CALLBACK* _GSchangeSaveState)(int, const char* filename);
typedef void (CALLBACK* _GSirqCallback)(void (*callback)());
typedef void (CALLBACK* _GSprintf)(int timeout, char *fmt, ...);
typedef void (CALLBACK* _GSsetBaseMem)(void*);
typedef void (CALLBACK* _GSsetGameCRC)(int);
typedef void (CALLBACK* _GSsetFrameSkip)(int frameskip);
typedef void (CALLBACK* _GSreset)();
typedef void (CALLBACK* _GSwriteCSR)(u32 value);
typedef void (CALLBACK* _GSgetDriverInfo)(GSdriverInfo *info);
#ifdef _WIN32
typedef s32 (CALLBACK* _GSsetWindowInfo)(winInfo *info);
#endif
typedef void (CALLBACK* _GSmakeSnapshot)(char *path);
typedef void (CALLBACK* _GSmakeSnapshot2)(char *path, int*, int);
typedef s32 (CALLBACK* _GSfreeze)(int mode, freezeData *data);
typedef void (CALLBACK* _GSconfigure)();
typedef s32 (CALLBACK* _GStest)();
typedef void (CALLBACK* _GSabout)();
// PAD
typedef s32 (CALLBACK* _PADinit)(u32 flags);
typedef s32 (CALLBACK* _PADopen)(void *pDsp);
typedef void (CALLBACK* _PADclose)();
typedef void (CALLBACK* _PADshutdown)();
typedef keyEvent* (CALLBACK* _PADkeyEvent)();
typedef u8 (CALLBACK* _PADstartPoll)(int pad);
typedef u8 (CALLBACK* _PADpoll)(u8 value);
typedef u32 (CALLBACK* _PADquery)();
typedef void (CALLBACK* _PADgsDriverInfo)(GSdriverInfo *info);
typedef void (CALLBACK* _PADconfigure)();
typedef s32 (CALLBACK* _PADtest)();
typedef void (CALLBACK* _PADabout)();
// SIO
typedef s32 (CALLBACK* _SIOinit)(u32 port, u32 slot, SIOchangeSlotCB f);
typedef s32 (CALLBACK* _SIOopen)(void *pDsp);
typedef void (CALLBACK* _SIOclose)();
typedef void (CALLBACK* _SIOshutdown)();
typedef u8 (CALLBACK* _SIOstartPoll)(u8 value);
typedef u8 (CALLBACK* _SIOpoll)(u8 value);
typedef u32 (CALLBACK* _SIOquery)();
typedef void (CALLBACK* _SIOconfigure)();
typedef s32 (CALLBACK* _SIOtest)();
typedef void (CALLBACK* _SIOabout)();
// SPU2
// NOTE: The read/write functions CANNOT use XMM/MMX regs
// If you want to use them, need to save and restore current ones
typedef s32 (CALLBACK* _SPU2init)();
typedef s32 (CALLBACK* _SPU2open)(void *pDsp);
typedef void (CALLBACK* _SPU2close)();
typedef void (CALLBACK* _SPU2shutdown)();
typedef void (CALLBACK* _SPU2write)(u32 mem, u16 value);
typedef u16 (CALLBACK* _SPU2read)(u32 mem);
typedef void (CALLBACK* _SPU2readDMA4Mem)(u16 *pMem, int size);
typedef void (CALLBACK* _SPU2writeDMA4Mem)(u16 *pMem, int size);
typedef void (CALLBACK* _SPU2interruptDMA4)();
typedef void (CALLBACK* _SPU2readDMA7Mem)(u16 *pMem, int size);
typedef void (CALLBACK* _SPU2writeDMA7Mem)(u16 *pMem, int size);
typedef void (CALLBACK* _SPU2interruptDMA7)();
typedef void (CALLBACK* _SPU2irqCallback)(void (*SPU2callback)(),void (*DMA4callback)(),void (*DMA7callback)());
typedef u32 (CALLBACK* _SPU2ReadMemAddr)(int core);
typedef void (CALLBACK* _SPU2WriteMemAddr)(int core,u32 value);
typedef void (CALLBACK* _SPU2async)(u32 cycles);
typedef s32 (CALLBACK* _SPU2freeze)(int mode, freezeData *data);
typedef void (CALLBACK* _SPU2configure)();
typedef s32 (CALLBACK* _SPU2test)();
typedef void (CALLBACK* _SPU2about)();
// CDVD
// NOTE: The read/write functions CANNOT use XMM/MMX regs
// If you want to use them, need to save and restore current ones
typedef s32 (CALLBACK* _CDVDinit)();
typedef s32 (CALLBACK* _CDVDopen)(const char* pTitleFilename);
typedef void (CALLBACK* _CDVDclose)();
typedef void (CALLBACK* _CDVDshutdown)();
typedef s32 (CALLBACK* _CDVDreadTrack)(u32 lsn, int mode);
typedef u8* (CALLBACK* _CDVDgetBuffer)();
typedef s32 (CALLBACK* _CDVDreadSubQ)(u32 lsn, cdvdSubQ* subq);
typedef s32 (CALLBACK* _CDVDgetTN)(cdvdTN *Buffer);
typedef s32 (CALLBACK* _CDVDgetTD)(u8 Track, cdvdTD *Buffer);
typedef s32 (CALLBACK* _CDVDgetTOC)(void* toc);
typedef s32 (CALLBACK* _CDVDgetDiskType)();
typedef s32 (CALLBACK* _CDVDgetTrayStatus)();
typedef s32 (CALLBACK* _CDVDctrlTrayOpen)();
typedef s32 (CALLBACK* _CDVDctrlTrayClose)();
typedef void (CALLBACK* _CDVDconfigure)();
typedef s32 (CALLBACK* _CDVDtest)();
typedef void (CALLBACK* _CDVDabout)();
typedef void (CALLBACK* _CDVDnewDiskCB)(void (*callback)());
// DEV9
// NOTE: The read/write functions CANNOT use XMM/MMX regs
// If you want to use them, need to save and restore current ones
typedef s32 (CALLBACK* _DEV9init)();
typedef s32 (CALLBACK* _DEV9open)(void *pDsp);
typedef void (CALLBACK* _DEV9close)();
typedef void (CALLBACK* _DEV9shutdown)();
typedef u8 (CALLBACK* _DEV9read8)(u32 mem);
typedef u16 (CALLBACK* _DEV9read16)(u32 mem);
typedef u32 (CALLBACK* _DEV9read32)(u32 mem);
typedef void (CALLBACK* _DEV9write8)(u32 mem, u8 value);
typedef void (CALLBACK* _DEV9write16)(u32 mem, u16 value);
typedef void (CALLBACK* _DEV9write32)(u32 mem, u32 value);
typedef void (CALLBACK* _DEV9readDMA8Mem)(u32 *pMem, int size);
typedef void (CALLBACK* _DEV9writeDMA8Mem)(u32 *pMem, int size);
typedef void (CALLBACK* _DEV9irqCallback)(DEV9callback callback);
typedef DEV9handler (CALLBACK* _DEV9irqHandler)(void);
typedef s32 (CALLBACK* _DEV9freeze)(int mode, freezeData *data);
typedef void (CALLBACK* _DEV9configure)();
typedef s32 (CALLBACK* _DEV9test)();
typedef void (CALLBACK* _DEV9about)();
// USB
// NOTE: The read/write functions CANNOT use XMM/MMX regs
// If you want to use them, need to save and restore current ones
typedef s32 (CALLBACK* _USBinit)();
typedef s32 (CALLBACK* _USBopen)(void *pDsp);
typedef void (CALLBACK* _USBclose)();
typedef void (CALLBACK* _USBshutdown)();
typedef u8 (CALLBACK* _USBread8)(u32 mem);
typedef u16 (CALLBACK* _USBread16)(u32 mem);
typedef u32 (CALLBACK* _USBread32)(u32 mem);
typedef void (CALLBACK* _USBwrite8)(u32 mem, u8 value);
typedef void (CALLBACK* _USBwrite16)(u32 mem, u16 value);
typedef void (CALLBACK* _USBwrite32)(u32 mem, u32 value);
typedef void (CALLBACK* _USBirqCallback)(USBcallback callback);
typedef USBhandler (CALLBACK* _USBirqHandler)(void);
typedef void (CALLBACK* _USBsetRAM)(void *mem);
typedef s32 (CALLBACK* _USBfreeze)(int mode, freezeData *data);
typedef void (CALLBACK* _USBconfigure)();
typedef s32 (CALLBACK* _USBtest)();
typedef void (CALLBACK* _USBabout)();
//FW
typedef s32 (CALLBACK* _FWinit)();
typedef s32 (CALLBACK* _FWopen)(void *pDsp);
typedef void (CALLBACK* _FWclose)();
typedef void (CALLBACK* _FWshutdown)();
typedef u32 (CALLBACK* _FWread32)(u32 mem);
typedef void (CALLBACK* _FWwrite32)(u32 mem, u32 value);
typedef void (CALLBACK* _FWirqCallback)(void (*callback)());
typedef s32 (CALLBACK* _FWfreeze)(int mode, freezeData *data);
typedef void (CALLBACK* _FWconfigure)();
typedef s32 (CALLBACK* _FWtest)();
typedef void (CALLBACK* _FWabout)();
#endif
#ifdef PLUGINfuncs
// GS
_GSinit GSinit;
_GSopen GSopen;
_GSclose GSclose;
_GSshutdown GSshutdown;
_GSvsync GSvsync;
_GSgifTransfer1 GSgifTransfer1;
_GSgifTransfer2 GSgifTransfer2;
_GSgifTransfer3 GSgifTransfer3;
_GSgifSoftReset GSgifSoftReset;
_GSreadFIFO GSreadFIFO;
_GSreadFIFO2 GSreadFIFO2;
_GSkeyEvent GSkeyEvent;
_GSchangeSaveState GSchangeSaveState;
_GSmakeSnapshot GSmakeSnapshot;
_GSmakeSnapshot2 GSmakeSnapshot2;
_GSirqCallback GSirqCallback;
_GSprintf GSprintf;
_GSsetBaseMem GSsetBaseMem;
_GSsetGameCRC GSsetGameCRC;
_GSsetFrameSkip GSsetFrameSkip;
_GSreset GSreset;
_GSwriteCSR GSwriteCSR;
_GSgetDriverInfo GSgetDriverInfo;
#ifdef _WIN32
_GSsetWindowInfo GSsetWindowInfo;
#endif
_GSfreeze GSfreeze;
_GSconfigure GSconfigure;
_GStest GStest;
_GSabout GSabout;
// PAD1
_PADinit PAD1init;
_PADopen PAD1open;
_PADclose PAD1close;
_PADshutdown PAD1shutdown;
_PADkeyEvent PAD1keyEvent;
_PADstartPoll PAD1startPoll;
_PADpoll PAD1poll;
_PADquery PAD1query;
_PADgsDriverInfo PAD1gsDriverInfo;
_PADconfigure PAD1configure;
_PADtest PAD1test;
_PADabout PAD1about;
// PAD2
_PADinit PAD2init;
_PADopen PAD2open;
_PADclose PAD2close;
_PADshutdown PAD2shutdown;
_PADkeyEvent PAD2keyEvent;
_PADstartPoll PAD2startPoll;
_PADpoll PAD2poll;
_PADquery PAD2query;
_PADgsDriverInfo PAD2gsDriverInfo;
_PADconfigure PAD2configure;
_PADtest PAD2test;
_PADabout PAD2about;
// SIO[2]
_SIOinit SIOinit[2][9];
_SIOopen SIOopen[2][9];
_SIOclose SIOclose[2][9];
_SIOshutdown SIOshutdown[2][9];
_SIOstartPoll SIOstartPoll[2][9];
_SIOpoll SIOpoll[2][9];
_SIOquery SIOquery[2][9];
_SIOconfigure SIOconfigure[2][9];
_SIOtest SIOtest[2][9];
_SIOabout SIOabout[2][9];
// SPU2
_SPU2init SPU2init;
_SPU2open SPU2open;
_SPU2close SPU2close;
_SPU2shutdown SPU2shutdown;
_SPU2write SPU2write;
_SPU2read SPU2read;
_SPU2readDMA4Mem SPU2readDMA4Mem;
_SPU2writeDMA4Mem SPU2writeDMA4Mem;
_SPU2interruptDMA4 SPU2interruptDMA4;
_SPU2readDMA7Mem SPU2readDMA7Mem;
_SPU2writeDMA7Mem SPU2writeDMA7Mem;
_SPU2interruptDMA7 SPU2interruptDMA7;
_SPU2ReadMemAddr SPU2ReadMemAddr;
_SPU2WriteMemAddr SPU2WriteMemAddr;
_SPU2irqCallback SPU2irqCallback;
_SPU2async SPU2async;
_SPU2freeze SPU2freeze;
_SPU2configure SPU2configure;
_SPU2test SPU2test;
_SPU2about SPU2about;
// CDVD
_CDVDinit CDVDinit;
_CDVDopen CDVDopen;
_CDVDclose CDVDclose;
_CDVDshutdown CDVDshutdown;
_CDVDreadTrack CDVDreadTrack;
_CDVDgetBuffer CDVDgetBuffer;
_CDVDreadSubQ CDVDreadSubQ;
_CDVDgetTN CDVDgetTN;
_CDVDgetTD CDVDgetTD;
_CDVDgetTOC CDVDgetTOC;
_CDVDgetDiskType CDVDgetDiskType;
_CDVDgetTrayStatus CDVDgetTrayStatus;
_CDVDctrlTrayOpen CDVDctrlTrayOpen;
_CDVDctrlTrayClose CDVDctrlTrayClose;
_CDVDconfigure CDVDconfigure;
_CDVDtest CDVDtest;
_CDVDabout CDVDabout;
_CDVDnewDiskCB CDVDnewDiskCB;
// DEV9
_DEV9init DEV9init;
_DEV9open DEV9open;
_DEV9close DEV9close;
_DEV9shutdown DEV9shutdown;
_DEV9read8 DEV9read8;
_DEV9read16 DEV9read16;
_DEV9read32 DEV9read32;
_DEV9write8 DEV9write8;
_DEV9write16 DEV9write16;
_DEV9write32 DEV9write32;
_DEV9readDMA8Mem DEV9readDMA8Mem;
_DEV9writeDMA8Mem DEV9writeDMA8Mem;
_DEV9irqCallback DEV9irqCallback;
_DEV9irqHandler DEV9irqHandler;
_DEV9configure DEV9configure;
_DEV9freeze DEV9freeze;
_DEV9test DEV9test;
_DEV9about DEV9about;
// USB
_USBinit USBinit;
_USBopen USBopen;
_USBclose USBclose;
_USBshutdown USBshutdown;
_USBread8 USBread8;
_USBread16 USBread16;
_USBread32 USBread32;
_USBwrite8 USBwrite8;
_USBwrite16 USBwrite16;
_USBwrite32 USBwrite32;
_USBirqCallback USBirqCallback;
_USBirqHandler USBirqHandler;
_USBsetRAM USBsetRAM;
_USBconfigure USBconfigure;
_USBfreeze USBfreeze;
_USBtest USBtest;
_USBabout USBabout;
// FW
_FWinit FWinit;
_FWopen FWopen;
_FWclose FWclose;
_FWshutdown FWshutdown;
_FWread32 FWread32;
_FWwrite32 FWwrite32;
_FWirqCallback FWirqCallback;
_FWconfigure FWconfigure;
_FWfreeze FWfreeze;
_FWtest FWtest;
_FWabout FWabout;
#endif
#endif /* __PS2EDEFS_H__ */

View File

@ -0,0 +1,43 @@
#ifndef __PS2ETYPES_H__
#define __PS2ETYPES_H__
// Basic types
#if defined(__MSCW32__)
typedef __int8 s8;
typedef __int16 s16;
typedef __int32 s32;
typedef __int64 s64;
typedef unsigned __int8 u8;
typedef unsigned __int16 u16;
typedef unsigned __int32 u32;
typedef unsigned __int64 u64;
#if defined(__x86_64__)
typedef u64 uptr;
#else
typedef u32 uptr;
#endif
#elif defined(__LINUX__) || defined(__MINGW32__)
typedef char s8;
typedef short s16;
typedef int s32;
typedef long long s64;
typedef unsigned char u8;
typedef unsigned short u16;
typedef unsigned int u32;
typedef unsigned long long u64;
#if defined(__x86_64__)
typedef u64 uptr;
#else
typedef u32 uptr;
#endif
#endif
#endif /* __PS2ETYPES_H__ */

View File

@ -0,0 +1,387 @@
/* CD.c
* Copyright (C) 2002-2005 PCSX2 Team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* PCSX2 members can be contacted through their website at www.pcsx2.net.
*/
#include <windows.h>
#include <ddk/ntddcdrm.h> // IOCTL_CDROM...
#include <sys/types.h> // off64_t
#define CDVDdefs
#include "PS2Edefs.h"
#include "logfile.h"
#include "../convert.h" // MSFtoLBA(), HEXTOBCD()
#include "actualfile.h"
#include "device.h" // tocbuffer[], FinishCommand()
#include "CD.h"
int actualcdmode; // -1=ReadFile, 0=YellowMode2, 1=XAForm2, 2=CDDA
DWORD cdblocksize; // 2048 to 2352
int cdoffset; // 0, 8, 16, or 24
int cdmode;
void InitCDInfo() {
actualcdmode = -1;
cdblocksize = 2048;
cdmode = -1;
} // END InitCDInfo()
s32 CDreadTrackPass(u32 lsn, int mode, u8 *buffer) {
RAW_READ_INFO rawinfo;
BOOL boolresult;
DWORD byteswritten;
DWORD errcode;
LARGE_INTEGER targetpos;
int i;
if((actualcdmode < -1) || (actualcdmode > 2)) return(-1);
#ifdef VERBOSE_FUNCTION_DEVICE
PrintLog("CDVDlinuz CD: CDreadTrack(%llu, %i)", lsn, actualcdmode);
#endif /* VERBOSE_FUNCTION_DEVICE */
if(actualcdmode >= 0) {
rawinfo.DiskOffset.QuadPart = lsn * 2048; // Yes, 2048.
rawinfo.SectorCount = 1;
rawinfo.TrackMode = actualcdmode;
boolresult = DeviceIoControl(devicehandle,
IOCTL_CDROM_RAW_READ,
&rawinfo,
sizeof(RAW_READ_INFO),
buffer,
2352,
&byteswritten,
&waitevent);
errcode = FinishCommand(boolresult);
if(errcode != 0) {
#ifdef VERBOSE_WARNING_DEVICE
PrintLog("CDVDlinuz CD: Couldn't read a sector raw!");
PrintError("CDVDlinuz CD", errcode);
#endif /* VERBOSE_WARNING_DEVICE */
return(-1);
} // ENDIF- Couldn't read a raw sector? Maybe not a CD.
} else {
targetpos.QuadPart = lsn * 2048;
waitevent.Offset = targetpos.LowPart;
waitevent.OffsetHigh = targetpos.HighPart;
boolresult = ReadFile(devicehandle,
buffer + 24,
2048,
&byteswritten,
&waitevent);
errcode = FinishCommand(boolresult);
if(errcode != 0) {
#ifdef VERBOSE_WARNING_DEVICE
PrintLog("CDVDlinuz CD: Couldn't read a cooked sector!");
PrintError("CDVDlinuz CD", errcode);
#endif /* VERBOSE_WARNING_DEVICE */
return(-1);
} // ENDIF- Trouble with seek? Report it.
for(i = 0; i < 24; i++) *(buffer + i) = 0;
for(i = 24 + 2048; i < 2352; i++) *(buffer + i) = 0;
} // ENDIF- Could we read a raw sector? Read another one!
if(boolresult == FALSE) {
boolresult = GetOverlappedResult(devicehandle,
&waitevent,
&byteswritten,
FALSE);
} // ENDIF- Did the initial call not complete? Get byteswritten for
// the completed call.
if(byteswritten < 2048) {
#ifdef VERBOSE_WARNING_DEVICE
errcode = GetLastError();
PrintLog("CDVDlinuz CD: Short block! only got %u out of %u bytes",
byteswritten, cdblocksize);
PrintError("CDVDlinuz CD", errcode);
#endif /* VERBOSE_WARNING_DEVICE */
return(-1);
} // ENDIF- Couldn't read a raw sector? Maybe not a CD.
cdmode = mode;
cdblocksize = byteswritten;
return(0);
} // END CDreadTrackPass()
s32 CDreadTrack(u32 lsn, int mode, u8 *buffer) {
int retval;
int lastmode;
int i;
retval = CDreadTrackPass(lsn, mode, buffer);
if(retval >= 0) return(retval);
#ifdef VERBOSE_WARNING_DEVICE
PrintLog("CDVDlinuz CD: Same mode doesn't work. Scanning...");
#endif /* VERBOSE_WARNING_DEVICE */
lastmode = actualcdmode;
actualcdmode = 2;
while(actualcdmode >= -1) {
retval = CDreadTrackPass(lsn, mode, buffer);
if(retval >= 0) return(retval);
actualcdmode--;
} // ENDWHILE- Searching each mode for a way to read the sector
actualcdmode = lastmode; // None worked? Go back to first mode.
#ifdef VERBOSE_WARNING_DEVICE
PrintLog("CDVDlinuz CD: No modes work. Failing sector!");
#endif /* VERBOSE_WARNING_DEVICE */
for(i = 0; i < 2352; i++) *(buffer + i) = 0;
return(-1);
} // END CDreadTrack()
s32 CDgetBufferOffset() {
#ifdef VERBOSE_FUNCTION_DEVICE
PrintLog("CDVD CD: CDgetBufferOffset()");
#endif /* VERBOSE_FUNCTION_DEVICE */
// Send a whole CDDA record in?
if((actualcdmode == CDDA) && (cdmode == CDVD_MODE_2352)) return(0);
// Otherwise, send the start of the data block in...
return(cdoffset);
} // END CDgetBufferOffset()
s32 CDreadSubQ() {
return(-1);
} // END CDreadSubQ()
s32 CDgetTN(cdvdTN *cdvdtn) {
cdvdtn->strack = BCDTOHEX(tocbuffer[7]);
cdvdtn->etrack = BCDTOHEX(tocbuffer[17]);
return(0);
} // END CDgetTN()
s32 CDgetTD(u8 newtrack, cdvdTD *cdvdtd) {
u8 actualtrack;
int pos;
char temptime[3];
#ifdef VERBOSE_FUNCTION_DEVICE
PrintLog("CDVDlinuz CD: CDgetTD()");
#endif /* VERBOSE_FUNCTION_DEVICE */
actualtrack = newtrack;
if(actualtrack == 0xaa) actualtrack = 0;
if(actualtrack == 0) {
cdvdtd->type = 0;
temptime[0] = BCDTOHEX(tocbuffer[27]);
temptime[1] = BCDTOHEX(tocbuffer[28]);
temptime[2] = BCDTOHEX(tocbuffer[29]);
cdvdtd->lsn = MSFtoLBA(temptime);
} else {
pos = actualtrack * 10;
pos += 30;
cdvdtd->type = tocbuffer[pos];
temptime[0] = BCDTOHEX(tocbuffer[pos + 7]);
temptime[1] = BCDTOHEX(tocbuffer[pos + 8]);
temptime[2] = BCDTOHEX(tocbuffer[pos + 9]);
cdvdtd->lsn = MSFtoLBA(temptime);
} // ENDIF- Whole disc? (or single track?)
return(0);
} // END CDgetTD()
s32 CDgetDiskType() {
CDROM_TOC cdinfo;
BOOL boolresult;
int retval;
DWORD byteswritten;
DWORD errcode;
u8 iso9660name[] = "CD001\0";
u8 playstationname[] = "PLAYSTATION\0";
u8 ps1name[] = "CD-XA001\0";
u8 tempbuffer[2448];
int tempdisctype;
int i;
int pos;
unsigned long volumesize;
#ifdef VERBOSE_FUNCTION_DEVICE
PrintLog("CDVDlinuz CD: CDgetDiskType()");
#endif /* VERBOSE_FUNCTION_DEVICE */
tempdisctype = CDVD_TYPE_UNKNOWN;
actualcdmode = 2;
retval = CDreadTrack(16, CDVD_MODE_2048, tempbuffer);
if(retval < 0) {
disctype = tempdisctype;
return(-1);
} // ENDIF- Couldn't read the directory sector? Abort.
disctype = CDVD_TYPE_DETCTCD;
tempdisctype = CDVD_TYPE_CDDA;
cdoffset = 0;
i = 0;
while((cdoffset <= 24) && (iso9660name[i] != 0)) {
i = 0;
while((iso9660name[i] != 0) &&
(iso9660name[i] == tempbuffer[cdoffset + 1 + i])) i++;
if(iso9660name[i] != 0) cdoffset += 8;
} // ENDWHILE- Trying to find a working offset for a ISO9660 record.
if(iso9660name[i] != 0) {
#ifdef VERBOSE_DISC_TYPE
PrintLog("Detected a CDDA (Music CD).");
#endif /* VERBOSE_DISC_TYPE */
tempdisctype = CDVD_TYPE_CDDA;
tocbuffer[0] = 0x01;
} else {
tocbuffer[0] = 0x41;
i = 0;
while((playstationname[i] != 0) &&
(playstationname[i] == tempbuffer[cdoffset + 8 + i])) i++;
if(playstationname[i] != 0) {
#ifdef VERBOSE_DISC_TYPE
PrintLog("Detected a non-Playstation CD.");
#endif /* VERBOSE_DISC_TYPE */
tempdisctype = CDVD_TYPE_UNKNOWN;
} else {
i = 0;
while((ps1name[i] != 0) &&
(ps1name[i] == tempbuffer[cdoffset + 1024 + i])) i++;
if(ps1name[i] != 0) {
#ifdef VERBOSE_DISC_TYPE
PrintLog("Detected a Playstation 2 CD.");
#endif /* VERBOSE_DISC_TYPE */
tempdisctype = CDVD_TYPE_PS2CD;
} else {
#ifdef VERBOSE_DISC_TYPE
PrintLog("Detected a Playstation CD.");
#endif /* VERBOSE_DISC_TYPE */
tempdisctype = CDVD_TYPE_PSCD;
} // ENDIF- Is this not a PlayStation Disc?
} // ENDIF- Is this not a PlayStation Disc?
} // ENDIF- Is this not an ISO9660 CD? (a CDDA, in other words?)
// Build the Fake TOC
tocbuffer[2] = 0xA0;
tocbuffer[7] = HEXTOBCD(1); // Starting Track
tocbuffer[12] = 0xA1;
tocbuffer[17] = HEXTOBCD(1); // Ending Track
volumesize = tempbuffer[84]; // Volume size (big endian)
volumesize *= 256;
volumesize += tempbuffer[85];
volumesize *= 256;
volumesize += tempbuffer[86];
volumesize *= 256;
volumesize += tempbuffer[87];
#ifdef VERBOSE_DISC_INFO
if(tempdisctype != CDVD_TYPE_CDDA) {
PrintLog("CDVDlinuz CD: ISO9660 size %llu", volumesize);
} // ENDIF- Data CD? Print size in blocks.
#endif /* VERBOSE_DISC_INFO */
LBAtoMSF(volumesize, &tocbuffer[27]);
tocbuffer[27] = HEXTOBCD(tocbuffer[27]);
tocbuffer[28] = HEXTOBCD(tocbuffer[28]);
tocbuffer[29] = HEXTOBCD(tocbuffer[29]);
tocbuffer[40] = 0x02; // Data Mode
tocbuffer[42] = 0x01; // Track #
LBAtoMSF(0, &tocbuffer[47]);
tocbuffer[47] = HEXTOBCD(tocbuffer[47]);
tocbuffer[48] = HEXTOBCD(tocbuffer[48]);
tocbuffer[49] = HEXTOBCD(tocbuffer[49]);
// Can we get the REAL TOC?
boolresult = DeviceIoControl(devicehandle,
IOCTL_CDROM_READ_TOC,
NULL,
0,
&cdinfo,
sizeof(CDROM_TOC),
&byteswritten,
NULL);
if(boolresult == FALSE) {
#ifdef VERBOSE_WARNING_DEVICE
errcode = GetLastError();
PrintLog("CDVDlinuz CD: Can't get TOC!");
PrintError("CDVDlinuz CD", errcode);
#endif /* VERBOSE_WARNING_DEVICE */
disctype = tempdisctype;
return(disctype);
} // ENDIF- Can't read the TOC? Accept the fake TOC then.
// Fill in the pieces of the REAL TOC.
#ifdef VERBOSE_DISC_INFO
PrintLog("CDVDlinuz CD: TOC First Track: %u Last Track: %u",
cdinfo.FirstTrack, cdinfo.LastTrack);
#endif /* VERBOSE_DISC_INFO */
tocbuffer[7] = HEXTOBCD(cdinfo.FirstTrack);
tocbuffer[17] = HEXTOBCD(cdinfo.LastTrack);
// for(i = cdinfo.FirstTrack; i <= cdinfo.LastTrack; i++) {
for(i = 0; i <= cdinfo.LastTrack - cdinfo.FirstTrack; i++) {
#ifdef VERBOSE_DISC_INFO
PrintLog("CDVDlinuz CD: TOC Track %u Disc Size: %u:%u.%u Data Mode %u",
cdinfo.TrackData[i].TrackNumber,
cdinfo.TrackData[i].Address[1] * 1,
cdinfo.TrackData[i].Address[2] * 1,
cdinfo.TrackData[i].Address[3] * 1,
cdinfo.TrackData[i].Control * 1);
#endif /* VERBOSE_DISC_INFO */
pos = i * 10 + 40;
tocbuffer[pos] = cdinfo.TrackData[i].Control;
tocbuffer[pos + 2] = HEXTOBCD(i + 1);
tocbuffer[pos + 7] = HEXTOBCD(cdinfo.TrackData[i].Address[1]);
tocbuffer[pos + 8] = HEXTOBCD(cdinfo.TrackData[i].Address[2]);
tocbuffer[pos + 9] = HEXTOBCD(cdinfo.TrackData[i].Address[3]);
} // NEXT i- Transferring Track data to the PS2 TOC
#ifdef VERBOSE_DISC_INFO
PrintLog("CDVDlinuz CD: TOC Disc Size: %u:%u.%u",
cdinfo.TrackData[i].Address[1] * 1,
cdinfo.TrackData[i].Address[2] * 1,
cdinfo.TrackData[i].Address[3] * 1);
#endif /* VERBOSE_DISC_INFO */
tocbuffer[27] = HEXTOBCD(cdinfo.TrackData[i].Address[1]);
tocbuffer[28] = HEXTOBCD(cdinfo.TrackData[i].Address[2]);
tocbuffer[29] = HEXTOBCD(cdinfo.TrackData[i].Address[3]);
disctype = tempdisctype;
return(disctype);
} // END CDgetDiskType()

View File

@ -0,0 +1,44 @@
/* CD.h
* Copyright (C) 2002-2005 PCSX2 Team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* PCSX2 members can be contacted through their website at www.pcsx2.net.
*/
#ifndef CD_H
#define CD_H
#include <windows.h> // DWORD
#define CDVDdefs
#include "PS2Edefs.h"
extern DWORD cdblocksize;
extern void InitCDInfo();
extern s32 CDreadTrack(u32 lsn, int mode, u8 *buffer);
extern s32 CDgetBufferOffset();
extern s32 CDreadSubQ();
extern s32 CDgetTN(cdvdTN *cdvdtn);
extern s32 CDgetTD(u8 newtrack, cdvdTD *cdvdtd);
extern s32 CDgetDiskType();
#endif /* CD_H */

View File

@ -0,0 +1,434 @@
/* CDVDlinuz.c
* Copyright (C) 2002-2005 PCSX2 Team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* PCSX2 members can be contacted through their website at www.pcsx2.net.
*/
#include <windows.h> // BOOL, CALLBACK, APIENTRY
#include <windef.h> // NULL
#include <time.h> // time(), time_t
#define CDVDdefs
#include "../PS2Edefs.h"
#include "device.h"
#include "CD.h"
#include "DVD.h"
#include "../buffer.h"
#include "../convert.h"
#include "conf.h"
#include "logfile.h"
#include "../version.h"
#include "screens.h"
#include "mainbox.h" // Initialize mainboxwindow
#include "CDVDlinuz.h"
HINSTANCE progmodule;
BOOL APIENTRY DllMain(HANDLE hModule,
DWORD param,
LPVOID reserved) {
switch(param) {
case DLL_PROCESS_ATTACH:
progmodule = hModule;
// mainboxwindow = NULL;
return(TRUE);
break;
case DLL_PROCESS_DETACH:
// CDVDshutdown();
return(TRUE);
break;
case DLL_THREAD_ATTACH:
return(TRUE);
break;
case DLL_THREAD_DETACH:
return(TRUE);
break;
} // ENDSWITCH param- What does the OS want with us?
return(FALSE); // Wasn't on list? Wasn't handled.
} // END DllMain()
char* CALLBACK PS2EgetLibName() {
return(libname);
} // END PS2EgetLibName()
u32 CALLBACK PS2EgetLibType() {
return(PS2E_LT_CDVD);
} // END PS2getLibType()
u32 CALLBACK PS2EgetLibVersion2(u32 type) {
return((version << 16) | (revision << 8) | build);
} // END PS2EgetLibVersion2()
s32 CALLBACK CDVDinit() {
InitLog();
if(OpenLog() != 0) return(-1); // Couldn't open Log File? Abort.
#ifdef VERBOSE_FUNCTION_INTERFACE
PrintLog("CDVDlinuz interface: CDVDinit()");
#endif /* VERBOSE_FUNCTION_INTERFACE */
InitConf();
DeviceInit();
InitCDInfo();
InitDVDInfo();
mainboxwindow = NULL;
return(0);
} // END CDVDinit()
void CALLBACK CDVDshutdown() {
#ifdef VERBOSE_FUNCTION_INTERFACE
PrintLog("CDVDlinuz interface: CDVDshutdown()");
#endif /* VERBOSE_FUNCTION_INTERFACE */
DeviceClose();
// Close Windows as well? (Just in case)
CloseLog();
} // END CDVDshutdown()
s32 CALLBACK CDVDopen() {
int retval;
#ifdef VERBOSE_FUNCTION_INTERFACE
PrintLog("CDVDlinuz interface: CDVDopen()");
#endif /* VERBOSE_FUNCTION_INTERFACE */
InitBuffer();
LoadConf();
retval = DeviceOpen();
if(retval == 0) {
DeviceTrayStatus();
} // ENDIF- Did we open the device? Poll for media.
return(retval);
} // END CDVDopen()
void CALLBACK CDVDclose() {
#ifdef VERBOSE_FUNCTION_INTERFACE
PrintLog("CDVDlinuz interface: CDVDclose()");
#endif /* VERBOSE_FUNCTION_INTERFACE */
DeviceClose();
} // END CDVDclose()
s32 CALLBACK CDVDreadSubQ(u32 lsn, cdvdSubQ* subq) {
char temptime[3];
int i;
int pos;
u32 tracklsn;
#ifdef VERBOSE_FUNCTION_INTERFACE
PrintLog("CDVDlinuz interface: CDVDreadSubQ()");
#endif /* VERBOSE_FUNCTION_INTERFACE */
if(DiscInserted() != 0) return(-1);
if((disctype == CDVD_TYPE_PS2DVD) || (disctype == CDVD_TYPE_DVDV)) {
return(-1); // DVDs don't have SubQ data
} // ENDIF- Trying to get a SubQ from a DVD?
// fake it
i = BCDTOHEX(tocbuffer[7]);
pos = i * 10;
pos += 30;
temptime[0] = BCDTOHEX(tocbuffer[pos + 7]);
temptime[1] = BCDTOHEX(tocbuffer[pos + 8]);
temptime[2] = BCDTOHEX(tocbuffer[pos + 9]);
tracklsn = MSFtoLBA(temptime);
while((i < BCDTOHEX(tocbuffer[17])) && (tracklsn < lsn)) {
i++;
pos = i * 10;
pos += 30;
temptime[0] = BCDTOHEX(tocbuffer[pos + 7]);
temptime[1] = BCDTOHEX(tocbuffer[pos + 8]);
temptime[2] = BCDTOHEX(tocbuffer[pos + 9]);
tracklsn = MSFtoLBA(temptime);
} // ENDIF- Loop through tracks searching for lsn track
i--;
subq->ctrl = 4;
subq->mode = 1;
subq->trackNum = HEXTOBCD(i);
subq->trackIndex = HEXTOBCD(i);
LBAtoMSF(lsn - tracklsn, temptime);
subq->trackM = HEXTOBCD(temptime[0]);
subq->trackS = HEXTOBCD(temptime[1]);
subq->trackF = HEXTOBCD(temptime[2]);
subq->pad = 0;
// lba_to_msf(lsn + (2*75), &min, &sec, &frm);
LBAtoMSF(lsn, temptime);
subq->discM = HEXTOBCD(temptime[0]);
subq->discS = HEXTOBCD(temptime[1]);
subq->discF = HEXTOBCD(temptime[2]);
return(0);
} // END CDVDreadSubQ()
s32 CALLBACK CDVDgetTN(cdvdTN *Buffer) {
#ifdef VERBOSE_FUNCTION_INTERFACE
PrintLog("CDVDlinuz interface: CDVDgetTN()");
#endif /* VERBOSE_FUNCTION_INTERFACE */
if(DiscInserted() != 0) return(-1);
if((disctype == CDVD_TYPE_PS2DVD) || (disctype == CDVD_TYPE_DVDV)) {
Buffer->strack = 1;
Buffer->etrack = 1;
} else {
Buffer->strack = BCDTOHEX(tocbuffer[7]);
Buffer->etrack = BCDTOHEX(tocbuffer[17]);
} // ENDIF- Retrieve track info from a DVD? (or a CD?)
return(0);
} // END CDVDgetTN()
s32 CALLBACK CDVDgetTD(u8 track, cdvdTD *buffer) {
#ifdef VERBOSE_FUNCTION_INTERFACE
PrintLog("CDVDlinuz interface: CDVDgetTD()");
#endif /* VERBOSE_FUNCTION_INTERFACE */
return(DeviceGetTD(track, buffer));
} // END CDVDgetTD()
s32 CALLBACK CDVDgetTOC(void* toc) {
int i;
#ifdef VERBOSE_FUNCTION_INTERFACE
PrintLog("CDVDlinuz interface: CDVDgetTOC()");
#endif /* VERBOSE_FUNCTION_INTERFACE */
if(DiscInserted() != 0) return(-1);
for(i = 0; i < 2048; i++) *(((char *) toc) + i) = tocbuffer[i];
return(0);
} // END CDVDgetTOC()
s32 CALLBACK CDVDreadTrack(u32 lsn, int mode) {
int retval;
#ifdef VERBOSE_FUNCTION_INTERFACE
PrintLog("CDVDlinuz interface: CDVDreadTrack(%u)", lsn);
#endif /* VERBOSE_FUNCTION_INTERFACE */
if(DiscInserted() == -1) return(-1);
if(userbuffer < BUFFERMAX) {
if((bufferlist[userbuffer].lsn == lsn) &&
(bufferlist[userbuffer].mode == mode)) {
return(0);
} // ENDIF- And it's the right one?
} // ENDIF- Are we already pointing at the buffer?
userbuffer = FindListBuffer(lsn);
if(userbuffer < BUFFERMAX) {
if((bufferlist[userbuffer].lsn == lsn) &&
(bufferlist[userbuffer].mode == mode)) {
return(0);
} // ENDIF- And it was the right one?
} // ENDIF- Was a buffer found in the cache?
replacebuffer++;
if(replacebuffer >= BUFFERMAX) replacebuffer = 0;
userbuffer = replacebuffer;
if(bufferlist[replacebuffer].upsort != 0xffff) {
RemoveListBuffer(replacebuffer);
} // ENDIF- Reference already in place? Remove it.
retval = DeviceReadTrack(lsn, mode, bufferlist[replacebuffer].buffer);
bufferlist[replacebuffer].lsn = lsn;
bufferlist[replacebuffer].mode = mode;
bufferlist[replacebuffer].offset = DeviceBufferOffset();
if(retval != 0) {
bufferlist[replacebuffer].mode = -1; // Error! flag buffer as such.
} else {
if((disctype != CDVD_TYPE_PS2DVD) && (disctype != CDVD_TYPE_DVDV)) {
if(mode == CDVD_MODE_2352) {
CDreadSubQ(lsn, &bufferlist[replacebuffer].subq);
} // ENDIF- Read subq as well?
} // ENDIF- Read a DVD buffer or a CD buffer?
} // ENDIF-Read ok? Fill out rest of buffer info.
AddListBuffer(replacebuffer);
return(retval);
} // END CDVDreadTrack()
u8* CALLBACK CDVDgetBuffer() {
#ifdef VERBOSE_FUNCTION_INTERFACE
PrintLog("CDVDlinuz interface: CDVDgetBuffer()");
#endif /* VERBOSE_FUNCTION_INTERFACE */
if(DiscInserted() == -1) return(NULL);
if(userbuffer == 0xffff) {
#ifdef VERBOSE_WARNINGS
PrintLog("CDVDlinuz interface: Not pointing to a buffer!");
#endif /* VERBOSE_WARNINGS */
return(NULL); // No buffer reference?
} // ENDIF- user buffer not pointing at anything? Abort
if(bufferlist[userbuffer].mode < 0) {
#ifdef VERBOSE_WARNINGS
PrintLog("CDVDlinuz interface: Error retrieving sector (ReadTrack call)");
#endif /* VERBOSE_WARNINGS */
return(NULL); // Bad Sector?
} // ENDIF- Trouble reading physical sector? Tell them.
return(bufferlist[userbuffer].buffer + bufferlist[userbuffer].offset);
} // END CDVDgetBuffer()
s32 CALLBACK CDVDgetDiskType() {
#ifdef VERBOSE_FUNCTION_INTERFACE
PrintLog("CDVDlinuz interface: CDVDgetDiskType()");
#endif /* VERBOSE_FUNCTION_INTERFACE */
if(lasttime != time(NULL)) {
lasttime = time(NULL);
DeviceTrayStatus();
} // ENDIF- Has enough time passed between calls?
return(disctype);
} // END CDVDgetDiskType()
s32 CALLBACK CDVDgetTrayStatus() {
#ifdef VERBOSE_FUNCTION_INTERFACE
PrintLog("CDVDlinuz interface: CDVDgetTrayStatus()");
#endif /* VERBOSE_FUNCTION_INTERFACE */
if(lasttime != time(NULL)) {
lasttime = time(NULL);
DeviceTrayStatus();
} // ENDIF- Has enough time passed between calls?
return(traystatus);
} // END CDVDgetTrayStatus()
s32 CALLBACK CDVDctrlTrayOpen() {
#ifdef VERBOSE_FUNCTION_INTERFACE
PrintLog("CDVDlinuz interface: CDVDctrlTrayOpen()");
#endif /* VERBOSE_FUNCTION_INTERFACE */
return(DeviceTrayOpen());
} // END CDVDctrlTrayOpen()
s32 CALLBACK CDVDctrlTrayClose() {
#ifdef VERBOSE_FUNCTION_INTERFACE
PrintLog("CDVDlinuz interface: CDVDctrlTrayClose()");
#endif /* VERBOSE_FUNCTION_INTERFACE */
return(DeviceTrayClose());
} // END CDVDctrlTrayClose()
s32 CALLBACK CDVDtest() {
int retval;
errno = 0;
if(devicehandle != NULL) {
#ifdef VERBOSE_WARNINGS
PrintLog("CDVDlinuz interface: Device already open");
#endif /* VERBOSE_WARNINGS */
return(0);
} // ENDIF- Is the CD/DVD already in use? That's fine.
#ifdef VERBOSE_FUNCTION_INTERFACE
PrintLog("CDVDlinuz interface: CDVDtest()");
#endif /* VERBOSE_FUNCTION_INTERFACE */
retval = DeviceOpen();
DeviceClose();
return(retval);
} // END CDVDtest()
void CALLBACK CDVDconfigure() {
HWND lastwindow;
lastwindow = GetActiveWindow();
DialogBox(progmodule,
MAKEINTRESOURCE(DLG_0200),
lastwindow,
(DLGPROC)MainBoxCallback);
SetActiveWindow(lastwindow);
lastwindow = NULL;
return;
} // END CDVDconfigure()
BOOL CALLBACK AboutCallback(HWND window, UINT msg, WPARAM param, LPARAM param2) {
switch(msg) {
case WM_COMMAND:
switch(LOWORD(param)) {
case IDC_0104: // "Ok" Button
EndDialog(window, FALSE);
return(TRUE);
break;
} // ENDSWITCH param- Which Windows Message Command?
case WM_CLOSE:
EndDialog(window, FALSE);
return(TRUE);
break;
} // ENDSWITCH msg- what message has been sent to this window?
return(FALSE); // Not a recognisable message. Pass it back to the OS.
} // END AboutCallback()
void CALLBACK CDVDabout() {
HWND lastwindow;
lastwindow = GetActiveWindow();
DialogBox(progmodule,
MAKEINTRESOURCE(DLG_0100),
lastwindow,
(DLGPROC)AboutCallback);
SetActiveWindow(lastwindow);
return;
} // END CDVDabout()

View File

@ -0,0 +1,40 @@
/* CDVDlinuz.h
* Copyright (C) 2002-2005 PCSX2 Team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* PCSX2 members can be contacted through their website at www.pcsx2.net.
*/
#ifndef CDVDLINUZ_H
#define CDVDLINUZ_H
#include <windows.h> // HINSTANCE
// #define VERBOSE_WARNINGS
// #define VERBOSE_FUNCTION_INTERFACE
#define VERBOSE_DISC_INFO
#define VERBOSE_DISC_TYPE
#define READ_AHEAD_BUFFERS 32
extern HINSTANCE progmodule;
#endif /* CDVDLINUZ_H */

View File

@ -0,0 +1,398 @@
/* DVD.c
* Copyright (C) 2002-2005 PCSX2 Team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* PCSX2 members can be contacted through their website at www.pcsx2.net.
*/
#include <windows.h>
#include <ddk/ntddcdvd.h> // IOCTL_DVD...
#include <sys/types.h> // off64_t
#define CDVDdefs
#include "PS2Edefs.h"
#include "logfile.h"
#include "device.h" // FinishCommand()
struct {
DVD_DESCRIPTOR_HEADER h;
DVD_LAYER_DESCRIPTOR d;
} layer;
// DVD_LAYER_DESCRIPTOR layer;
// DVD_COPYRIGHT_DESCRIPTOR copyright;
// DVD_DISK_KEY_DESCRIPTOR disckey;
// DVD_BCA_DESCRIPTOR bca;
// DVD_MANUFACTURER_DESCRIPTOR manufact;
void InitDVDInfo() {
layer.d.EndDataSector = 0;
} // END InitDVDInfo()
s32 DVDGetStructures() {
DVD_SESSION_ID sessionid;
DVD_READ_STRUCTURE request;
DWORD byteswritten;
BOOL boolresult;
DWORD errcode;
s32 retval;
#ifdef VERBOSE_FUNCTION_DEVICE
PrintLog("CDVDlinuz DVD: DVDgetStructures()");
#endif /* VERBOSE_FUNCTION_DEVICE */
boolresult = DeviceIoControl(devicehandle,
IOCTL_DVD_START_SESSION,
NULL,
0,
&sessionid,
sizeof(DVD_SESSION_ID),
&byteswritten,
&waitevent);
errcode = FinishCommand(boolresult);
if(errcode != 0) {
#ifdef VERBOSE_WARNING_DEVICE
PrintLog("CDVDlinuz DVD: Couldn't start session!");
PrintError("CDVDlinuz DVD", errcode);
#endif /* VERBOSE_WARNING_DEVICE */
return(-1);
} // ENDIF- Couldn't start a user session on the DVD drive? Fail.
request.BlockByteOffset.QuadPart = 0;
request.Format = DvdPhysicalDescriptor;
request.SessionId = sessionid;
request.LayerNumber = 0;
retval = 0;
boolresult = DeviceIoControl(devicehandle,
IOCTL_DVD_READ_STRUCTURE,
&request,
sizeof(DVD_READ_STRUCTURE),
&layer,
sizeof(layer),
&byteswritten,
&waitevent);
errcode = FinishCommand(boolresult);
if(errcode != 0) {
#ifdef VERBOSE_WARNING_DEVICE
PrintLog("CDVDlinuz DVD: Couldn't get layer data!");
PrintError("CDVDlinuz DVD", errcode);
#endif /* VERBOSE_WARNING_DEVICE */
retval = -1;
} // ENDIF- Couldn't get layer data? (Including DVD size) Abort.
#ifdef VERBOSE_DISC_INFO
switch(layer.d.BookType) {
case 0:
PrintLog("CDVDlinuz DVD: Book Type: DVD-ROM");
break;
case 1:
PrintLog("CDVDlinuz DVD: Book Type: DVD-RAM");
break;
case 2:
PrintLog("CDVDlinuz DVD: Book Type: DVD-R");
break;
case 3:
PrintLog("CDVDlinuz DVD: Book Type: DVD-RW");
break;
case 9:
PrintLog("CDVDlinuz DVD: Book Type: DVD+RW");
break;
default:
PrintLog("CDVDlinuz DVD: Book Type: Unknown (%i)", layer.d.BookType);
break;
} // ENDSWITCH- Displaying the Book Type
PrintLog("CDVDlinuz DVD: Book Version %i", layer.d.BookVersion);
switch(layer.d.MinimumRate) {
case 0:
PrintLog("CDVDlinuz DVD: Use Minimum Rate for: DVD-ROM");
break;
case 1:
PrintLog("CDVDlinuz DVD: Use Minimum Rate for: DVD-RAM");
break;
case 2:
PrintLog("CDVDlinuz DVD: Use Minimum Rate for: DVD-R");
break;
case 3:
PrintLog("CDVDlinuz DVD: Use Minimum Rate for: DVD-RW");
break;
case 9:
PrintLog("CDVDlinuz DVD: Use Minimum Rate for: DVD+RW");
break;
default:
PrintLog("CDVDlinuz DVD: Use Minimum Rate for: Unknown (%i)", layer.d.MinimumRate);
break;
} // ENDSWITCH- Displaying the Minimum (Spin?) Rate
switch(layer.d.DiskSize) {
case 0:
PrintLog("CDVDlinuz DVD: Physical Disk Size: 120mm");
break;
case 1:
PrintLog("CDVDlinuz DVD: Physical Disk Size: 80mm");
break;
default:
PrintLog("CDVDlinuz DVD: Physical Disk Size: Unknown (%i)", layer.d.DiskSize);
break;
} // ENDSWITCH- What's the Disk Size?
switch(layer.d.LayerType) {
case 1:
PrintLog("CDVDlinuz DVD: Layer Type: Read-Only");
break;
case 2:
PrintLog("CDVDlinuz DVD: Layer Type: Recordable");
break;
case 4:
PrintLog("CDVDlinuz DVD: Layer Type: Rewritable");
break;
default:
PrintLog("CDVDlinuz DVD: Layer Type: Unknown (%i)", layer.d.LayerType);
break;
} // ENDSWITCH- Displaying the Layer Type
switch(layer.d.TrackPath) {
case 0:
PrintLog("CDVDlinuz DVD: Track Path: PTP");
break;
case 1:
PrintLog("CDVDlinuz DVD: Track Path: OTP");
break;
default:
PrintLog("CDVDlinuz DVD: Track Path: Unknown (%i)", layer.d.TrackPath);
break;
} // ENDSWITCH- What's Track Path Layout?
PrintLog("CDVDlinuz DVD: Number of Layers: %i", layer.d.NumberOfLayers + 1);
switch(layer.d.TrackDensity) {
case 0:
PrintLog("CDVDlinuz DVD: Track Density: .74 m/track");
break;
case 1:
PrintLog("CDVDlinuz DVD: Track Density: .8 m/track");
break;
case 2:
PrintLog("CDVDlinuz DVD: Track Density: .615 m/track");
break;
default:
PrintLog("CDVDlinuz DVD: Track Density: Unknown (%i)", layer.d.TrackDensity);
break;
} // ENDSWITCH- Displaying the Layer Type
switch(layer.d.LinearDensity) {
case 0:
PrintLog("CDVDlinuz DVD: Linear Density: .267 m/bit");
break;
case 1:
PrintLog("CDVDlinuz DVD: Linear Density: .293 m/bit");
break;
case 2:
PrintLog("CDVDlinuz DVD: Linear Density: .409 to .435 m/bit");
break;
case 4:
PrintLog("CDVDlinuz DVD: Linear Density: .280 to .291 m/bit");
break;
case 8:
PrintLog("CDVDlinuz DVD: Linear Density: .353 m/bit");
break;
default:
PrintLog("CDVDlinuz DVD: Linear Density: Unknown (%i)", layer.d.LinearDensity);
break;
} // ENDSWITCH- Displaying the Book Type
if(layer.d.StartingDataSector == 0x30000) {
PrintLog("CDVDlinuz DVD: Starting Sector: %lu (DVD-ROM, DVD-R, DVD-RW)",
layer.d.StartingDataSector);
} else if(layer.d.StartingDataSector == 0x31000) {
PrintLog("CDVDlinuz DVD: Starting Sector: %lu (DVD-RAM, DVD+RW)",
layer.d.StartingDataSector);
} else {
PrintLog("CDVDlinuz DVD: Starting Sector: %lu", layer.d.StartingDataSector);
} // ENDLONGIF- What does the starting sector tell us?
PrintLog("CDVDlinuz DVD: End of Layer 0: %lu", layer.d.EndLayerZeroSector);
PrintLog("CDVDlinuz DVD: Ending Sector: %lu", layer.d.EndDataSector);
if(layer.d.BCAFlag != 0) PrintLog("CDVDlinuz DVD: BCA data present");
#endif /* VERBOSE_DISC_INFO */
boolresult = DeviceIoControl(devicehandle,
IOCTL_DVD_END_SESSION,
&sessionid,
sizeof(DVD_SESSION_ID),
NULL,
0,
&byteswritten,
&waitevent);
errcode = FinishCommand(boolresult);
if(errcode != 0) {
#ifdef VERBOSE_WARNING_DEVICE
PrintLog("CDVDlinuz DVD: Couldn't end the session!");
PrintError("CDVDlinuz DVD", errcode);
#endif /* VERBOSE_WARNING_DEVICE */
} // ENDIF- Couldn't end the user session? Report it.
return(retval);
} // END DVDGetStructures()
s32 DVDreadTrack(u32 lsn, int mode, u8 *buffer) {
LARGE_INTEGER targetpos;
DWORD byteswritten;
BOOL boolresult;
DWORD errcode;
#ifdef VERBOSE_FUNCTION_DEVICE
PrintLog("CDVDlinuz DVD: DVDreadTrack(%lu)", lsn);
#endif /* VERBOSE_FUNCTION_DEVICE */
targetpos.QuadPart = lsn * 2048;
waitevent.Offset = targetpos.LowPart;
waitevent.OffsetHigh = targetpos.HighPart;
boolresult = ReadFile(devicehandle,
buffer,
2048,
&byteswritten,
&waitevent);
errcode = FinishCommand(boolresult);
if(errcode != 0) {
#ifdef VERBOSE_WARNING_DEVICE
PrintLog("CDVDlinuz DVD: Couldn't read sector!");
PrintError("CDVDlinuz DVD", errcode);
#endif /* VERBOSE_WARNING_DEVICE */
return(-1);
} // ENDIF- Trouble with the command? Report it.
if(boolresult == FALSE) {
boolresult = GetOverlappedResult(devicehandle,
&waitevent,
&byteswritten,
FALSE);
} // ENDIF- Did the initial call not complete? Get byteswritten for
// the completed call.
if(byteswritten < 2048) {
#ifdef VERBOSE_WARNING_DEVICE
errcode = GetLastError();
PrintLog("CDVDlinuz CD: Short block! only got %u out of %u bytes",
byteswritten, 2048);
PrintError("CDVDlinuz CD", errcode);
#endif /* VERBOSE_WARNING_DEVICE */
return(-1);
} // ENDIF- Didn't get enough bytes? Report and Abort!
return(0);
} // END DVDreadTrack()
s32 DVDgetTN(cdvdTN *cdvdtn) {
#ifdef VERBOSE_FUNCTION_DEVICE
PrintLog("CDVDlinuz DVD: DVDgetTN()");
#endif /* VERBOSE_FUNCTION_DEVICE */
if(cdvdtn != NULL) {
cdvdtn->strack = 1;
cdvdtn->etrack = 1;
} // ENDIF- Does the user really want this data?
return(0);
} // END DVDgetTN()
s32 DVDgetTD(u8 newtrack, cdvdTD *cdvdtd) {
#ifdef VERBOSE_FUNCTION_DEVICE
PrintLog("CDVDlinuz DVD: DVDgetTD()");
#endif /* VERBOSE_FUNCTION_DEVICE */
if((newtrack >= 2) && (newtrack != 0xAA)) return(-1); // Wrong track
if(cdvdtd != NULL) {
cdvdtd->type = 0;
cdvdtd->lsn = layer.d.EndDataSector - layer.d.StartingDataSector + 1;
} // ENDIF- Does the user really want this data?
return(0);
} // END DVDgetTD()
s32 DVDgetDiskType() {
char playstationname[] = "PLAYSTATION\0";
int retval;
s32 tempdisctype;
char tempbuffer[2048];
int i;
#ifdef VERBOSE_FUNCTION_DEVICE
PrintLog("CDVDlinuz DVD: DVDgetDiskType()");
#endif /* VERBOSE_FUNCTION_DEVICE */
retval = DVDGetStructures();
if(retval < 0) return(-1); // Can't get DVD structures? Not a DVD then.
if(layer.d.EndDataSector == 0) return(-1); // Missing info? Abort.
retval = DVDreadTrack(16, CDVD_MODE_2048, tempbuffer);
if(retval < 0) {
return(-1);
} // ENDIF- Couldn't read the ISO9660 volume track? Fail.
tempdisctype = CDVD_TYPE_UNKNOWN;
if(layer.d.NumberOfLayers == 0) {
#ifdef VERBOSE_DISC_INFO
PrintLog("CDVDlinuz DVD: Found Single-Sided DVD.");
#endif /* VERBOSE_DISC_INFO */
disctype = CDVD_TYPE_DETCTDVDS;
} else {
#ifdef VERBOSE_DISC_INFO
PrintLog("CDVDlinuz DVD: Found Dual-Sided DVD.");
#endif /* VERBOSE_DISC_INFO */
disctype = CDVD_TYPE_DETCTDVDD;
} // ENDIF- Are we looking at a single layer DVD? (NumberOfLayers + 1)
i = 0;
while((playstationname[i] != 0) &&
(playstationname[i] == tempbuffer[8 + i])) i++;
if(playstationname[i] == 0) {
#ifdef VERBOSE_DISC_TYPE
PrintLog("CDVDlinuz DVD: Found Playstation 2 DVD.");
#endif /* VERBOSE_DISC_TYPE */
tempdisctype = CDVD_TYPE_PS2DVD;
} else {
#ifdef VERBOSE_DISC_TYPE
PrintLog("CDVDlinuz DVD: Guessing it's a Video DVD.");
#endif /* VERBOSE_DISC_TYPE */
tempdisctype = CDVD_TYPE_DVDV;
} // ENDIF- Is this a playstation disc?
for(i = 0; i < 2048; i++) tocbuffer[i] = 0;
if(layer.d.NumberOfLayers == 0) {
tocbuffer[0] = 0x04;
tocbuffer[4] = 0x86;
tocbuffer[5] = 0x72;
} else {
tocbuffer[0] = 0x24;
tocbuffer[4] = 0x41;
tocbuffer[5] = 0x95;
} // ENDIF- Are we looking at a single layer DVD? (NumberOfLayers + 1)
tocbuffer[1] = 0x02;
tocbuffer[2] = 0xF2;
tocbuffer[3] = 0x00;
tocbuffer[16] = 0x00;
tocbuffer[17] = 0x03;
tocbuffer[18] = 0x00;
tocbuffer[19] = 0x00;
disctype = tempdisctype;
return(disctype);
} // END DVDgetDiskType()

View File

@ -0,0 +1,37 @@
/* DVD.h
* Copyright (C) 2002-2005 PCSX2 Team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* PCSX2 members can be contacted through their website at www.pcsx2.net.
*/
#ifndef DVD_H
#define DVD_H
#define CDVDdefs
#include "PS2Edefs.h"
extern void InitDVDInfo();
extern s32 DVDreadTrack(u32 lsn, int mode, u8 *buffer);
extern s32 DVDgetTN(cdvdTN *cdvdtn);
extern s32 DVDgetTD(u8 newtrack, cdvdTD *cdvdtd);
extern s32 DVDgetDiskType();
#endif /* DVD_H */

View File

@ -0,0 +1,43 @@
PLUGIN = CDVDlinuz.dll
PLUGINOBJS = CDVDlinuz.o mainbox.o
PLUGINHEADERS = CDVDlinuz.h mainbox.h
PLUGINFLAGS = -Wall -O2 -D_LARGEFILE64_SOURCE -I.. -I. -I.\\Win32
PLUGINLIBS =
# In this case, SHARED marks files that don't need Windows Display components
SHAREDOBJS = device.o CD.o DVD.o logfile.o actualfile.o conf.o \
..\\ini.o ..\\buffer.o ..\\version.o ..\\convert.o
SHAREDHEADERS = device.h CD.h DVD.h logfile.h actualfile.h conf.h \
..\\ini.h ..\\buffer.h ..\\version.h ..\\convert.h
CC = mingw32-gcc.exe
WINDRES = windres.exe
all: plugin
release: plugin
copy $(PLUGIN) ..\\..
plugin: $(PLUGINOBJS) $(SHAREDOBJS) screens.res
-del $(PLUGIN)
dllwrap --def plugin.def -o $(PLUGIN) $(PLUGINOBJS) screens.res $(SHAREDOBJS) $(PLUGINLIBS)
strip --strip-unneeded --strip-debug $(PLUGIN)
$(PLUGINOBJS) $(SHAREDOBJS): %.o: %.c
$(CC) $(PLUGINFLAGS) -c $< -o $@
screens.res: screens.rc
$(WINDRES) -i screens.rc -J rc -o screens.res -O coff
.PHONY : clean allclean
clean:
-del $(PLUGINOBJS) $(PLUGIN) $(SHAREDOBJS) screens.res
allclean:
-del $(PLUGINOBJS) $(PLUGIN) $(SHAREDOBJS) screens.res
-del temp.txt err.txt ..\\temp.txt ..\\err.txt
-del ..\\..\\$(PLUGIN)

View File

@ -0,0 +1,253 @@
/* actualfile.c
* Copyright (C) 2002-2005 PCSX2 Team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* PCSX2 members can be contacted through their website at www.pcsx2.net.
*/
#include <windows.h>
#include <stddef.h> // NULL
#include "logfile.h"
#include "actualfile.h"
int IsActualFile(const char *filename) {
DWORD retval;
if(filename == NULL) return(-1);
#ifdef VERBOSE_FUNCTION_ACTUALFILE
PrintLog("CDVDiso file: IsActualFile(%s)", filename);
#endif /* VERBOSE_FUNCTION_ACTUALFILE */
retval = GetFileAttributes(filename);
if(retval == INVALID_FILE_ATTRIBUTES) return(-1); // Name doesn't exist.
if((retval & FILE_ATTRIBUTE_DIRECTORY) != 0) return(-2);
return(0); // Yep, that's a file.
} // END IsActualFile()
void ActualFileDelete(const char *filename) {
#ifdef VERBOSE_FUNCTION_ACTUALFILE
PrintLog("CDVDiso file: ActualFileDelete(%s)", filename);
#endif /* VERBOSE_FUNCTION_ACTUALFILE */
DeleteFile(filename);
} // END ActualFileDelete()
void ActualFileRename(const char *origname, const char *newname) {
#ifdef VERBOSE_FUNCTION_ACTUALFILE
PrintLog("CDVDiso file: ActualFileDelete(%s->%s)", origname, newname);
#endif /* VERBOSE_FUNCTION_ACTUALFILE */
MoveFile(origname, newname);
return;
} // END ActualFileRename()
ACTUALHANDLE ActualFileOpenForRead(const char *filename) {
HANDLE newhandle;
if(filename == NULL) return(NULL);
#ifdef VERBOSE_FUNCTION_ACTUALFILE
PrintLog("CDVDiso file: ActualFileOpenForRead(%s)", filename);
#endif /* VERBOSE_FUNCTION_ACTUALFILE */
newhandle = CreateFile(filename,
GENERIC_READ,
FILE_SHARE_READ,
NULL,
OPEN_EXISTING,
FILE_FLAG_RANDOM_ACCESS,
NULL);
if(newhandle == INVALID_HANDLE_VALUE) {
#ifdef VERBOSE_WARNING_ACTUALFILE
PrintLog("CDVDiso file: Error opening file %s", filename);
#endif /* VERBOSE_WARNING_ACTUALFILE */
return(NULL);
} // ENDIF- Error? Abort
return(newhandle);
} // END ActualFileOpenForRead()
off64_t ActualFileSize(ACTUALHANDLE handle) {
int retval;
BY_HANDLE_FILE_INFORMATION info;
off64_t retsize;
if(handle == NULL) return(-1);
if(handle == INVALID_HANDLE_VALUE) return(-1);
#ifdef VERBOSE_FUNCTION_ACTUALFILE
PrintLog("CDVDiso file: ActualFileSize()");
#endif /* VERBOSE_FUNCTION_ACTUALFILE */
retval = GetFileInformationByHandle(handle, &info);
if(retval == 0) return(-1); // Handle doesn't exist...
retsize = info.nFileSizeHigh;
retsize *= 0x10000;
retsize *= 0x10000;
retsize += info.nFileSizeLow;
return(retsize);
} // END ActualFileSize()
int ActualFileSeek(ACTUALHANDLE handle, off64_t position) {
// int retval;
LARGE_INTEGER realpos;
DWORD errcode;
if(handle == NULL) return(-1);
if(handle == INVALID_HANDLE_VALUE) return(-1);
if(position < 0) return(-1);
#ifdef VERBOSE_FUNCTION_ACTUALFILE
PrintLog("CDVDiso file: ActualFileSeek(%llu)", position);
#endif /* VERBOSE_FUNCTION_ACTUALFILE */
realpos.QuadPart = position;
////// WinXP code for seek
// retval = SetFilePointerEx(handle,
// realpos,
// NULL,
// FILE_BEGIN);
// if(retval == 0) {
////// Win98 code for seek
realpos.LowPart = SetFilePointer(handle,
realpos.LowPart,
&realpos.HighPart,
FILE_BEGIN);
errcode = GetLastError();
if((realpos.LowPart == 0xFFFFFFFF) && (errcode != NO_ERROR)) {
#ifdef VERBOSE_WARNING_ACTUALFILE
PrintLog("CDVDiso file: Error on seek (%llu)", position);
PrintError("CDVDiso file", errcode);
#endif /* VERBOSE_WARNING_ACTUALFILE */
return(-1);
} // ENDIF- Error? Abort
return(0);
} // END ActualFileSeek()
int ActualFileRead(ACTUALHANDLE handle, int bytes, char *buffer) {
int retval;
DWORD bytesread;
#ifdef VERBOSE_WARNING_ACTUALFILE
DWORD errcode;
#endif /* VERBOSE_WARNING_ACTUALFILE */
if(handle == NULL) return(-1);
if(handle == INVALID_HANDLE_VALUE) return(-1);
if(bytes < 1) return(-1);
if(buffer == NULL) return(-1);
#ifdef VERBOSE_FUNCTION_ACTUALFILE
PrintLog("CDVDiso file: ActualFileRead(%i)", bytes);
#endif /* VERBOSE_FUNCTION_ACTUALFILE */
retval = ReadFile(handle, buffer, bytes, &bytesread, NULL);
if(retval == 0) {
#ifdef VERBOSE_WARNING_ACTUALFILE
errcode = GetLastError();
PrintLog("CDVDiso file: Error reading from file");
PrintError("CDVDiso file", errcode);
#endif /* VERBOSE_WARNING_ACTUALFILE */
return(-1);
} // ENDIF- Error? Abort
if(bytesread < bytes) {
#ifdef VERBOSE_WARNING_ACTUALFILE
PrintLog("CDVDiso file: Short Block! Only read %i out of %i bytes", bytesread, bytes);
#endif /* VERBOSE_WARNING_ACTUALFILE */
} // ENDIF- Error? Abort
return(bytesread); // Send back how many bytes read
} // END ActualFileRead()
void ActualFileClose(ACTUALHANDLE handle) {
if(handle == NULL) return;
if(handle == INVALID_HANDLE_VALUE) return;
#ifdef VERBOSE_FUNCTION_ACTUALFILE
PrintLog("CDVDiso file: ActualFileClose()");
#endif /* VERBOSE_FUNCTION_ACTUALFILE */
CloseHandle(handle);
return;
} // END ActualFileClose()
ACTUALHANDLE ActualFileOpenForWrite(const char *filename) {
HANDLE newhandle;
if(filename == NULL) return(NULL);
#ifdef VERBOSE_FUNCTION_ACTUALFILE
PrintLog("CDVDiso file: ActualFileOpenForWrite(%s)", filename);
#endif /* VERBOSE_FUNCTION_ACTUALFILE */
newhandle = CreateFile(filename,
GENERIC_WRITE,
0,
NULL,
CREATE_ALWAYS,
FILE_FLAG_SEQUENTIAL_SCAN,
NULL);
if(newhandle == INVALID_HANDLE_VALUE) {
#ifdef VERBOSE_WARNING_ACTUALFILE
PrintLog("CDVDiso file: Error opening file %s", filename);
#endif /* VERBOSE_WARNING_ACTUALFILE */
return(NULL);
} // ENDIF- Error? Abort
return(newhandle);
} // END ActualFileOpenForWrite()
int ActualFileWrite(ACTUALHANDLE handle, int bytes, char *buffer) {
int retval;
DWORD byteswritten;
if(handle == NULL) return(-1);
if(handle == INVALID_HANDLE_VALUE) return(-1);
if(bytes < 1) return(-1);
if(buffer == NULL) return(-1);
#ifdef VERBOSE_FUNCTION_ACTUALFILE
PrintLog("CDVDiso file: ActualFileWrite(%i)", bytes);
#endif /* VERBOSE_FUNCTION_ACTUALFILE */
retval = WriteFile(handle, buffer, bytes, &byteswritten, NULL);
if(retval == 0) {
#ifdef VERBOSE_WARNING_ACTUALFILE
PrintLog("CDVDiso file: Error writing to file!");
#endif /* VERBOSE_WARNING_ACTUALFILE */
// return(-1);
} // ENDIF- Error? Abort
return(byteswritten); // Send back how many bytes written
} // END ActualFileWrite()

View File

@ -0,0 +1,52 @@
/* actualfile.h
* Copyright (C) 2002-2005 PCSX2 Team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* PCSX2 members can be contacted through their website at www.pcsx2.net.
*/
#ifndef ACTUALFILE_H
#define ACTUALFILE_H
#include <windows.h>
#include <sys/types.h> // off64_t
#define ACTUALHANDLE HANDLE
#define ACTUALHANDLENULL NULL
// #define VERBOSE_FUNCTION_ACTUALFILE
// #define VERBOSE_WARNING_ACTUALFILE
extern int IsActualFile(const char *filename);
extern void ActualFileDelete(const char *filename);
extern void ActualFileRename(const char *origname, const char *newname);
extern ACTUALHANDLE ActualFileOpenForRead(const char *filename);
extern off64_t ActualFileSize(ACTUALHANDLE handle);
extern int ActualFileSeek(ACTUALHANDLE handle, off64_t position);
extern int ActualFileRead(ACTUALHANDLE handle, int bytes, char *buffer);
extern void ActualFileClose(ACTUALHANDLE handle);
extern ACTUALHANDLE ActualFileOpenForWrite(const char *filename);
extern int ActualFileWrite(ACTUALHANDLE handle, int bytes, char *buffer);
#endif /* ACTUALFILE_H */

View File

@ -0,0 +1,175 @@
/* conf.c
* Copyright (C) 2002-2005 PCSX2 Team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* PCSX2 members can be contacted through their website at www.pcsx2.net.
*/
#include <errno.h> // errno
#include <stddef.h> // NULL
#include <stdio.h> // sprintf()
#include <stdlib.h> // getenv()
#include <string.h> // strerror()
#include <sys/stat.h> // mkdir(), stat()
#include <sys/types.h> // mkdir(), stat(), fork()
#include <unistd.h> // stat(), fork(), execlp()
#include <windows.h> // CreateProcess()
// #define CDVDdefs
// #include "../PS2Edefs.h"
#include "../PS2Etypes.h" // u8
#include "logfile.h"
#include "../ini.h"
#include "conf.h"
const char *confnames[] = { "Device", NULL };
const u8 defaultdevice[] = DEFAULT_DEVICE;
const char defaulthome[] = "inis";
const char defaultdirectory[] = "HideMe.PS2E";
const char defaultfile[] = "CDVDlinuz.ini";
char confdirname[256];
char conffilename[256];
CDVDconf conf;
void InitConf() {
DWORD retval;
int i;
int pos;
char *envptr;
#ifdef VERBOSE_FUNCTION_CONF
PrintLog("CDVD config: InitConf()");
#endif /* VERBOSE_FUNCTION_CONF */
i = 0;
while((i < 255) && defaultdevice[i] != 0) {
conf.devicename[i] = defaultdevice[i];
i++;
} // ENDWHILE- copying the default CD/DVD name in
conf.devicename[i] = 0; // 0-terminate the device name
// Locating directory and file positions
pos = 0;
envptr = NULL;
// envptr = getenv("HOME");
if(envptr == NULL) {
// = <Default Home>
retval = GetCurrentDirectory(253, confdirname);
if(retval > 0) {
pos = retval;
} else {
pos = 2;
confdirname[0] = '.';
confdirname[1] = '\\';
} // ENDIF- Did we retrieve a directory reference?
i = 0;
while(i < pos) {
conffilename[i] = confdirname[i];
i++;
} // ENDWHILE- Copying dir info (so far) into file info
if(confdirname[pos-1] != '\\') {
confdirname[pos] = '\\';
conffilename[pos] = '\\';
pos++;
} // ENDIF- No directory separator here? Add one.
i = 0;
while((pos < 253) && (defaulthome[i] != 0)) {
confdirname[pos] = defaulthome[i];
conffilename[pos] = defaulthome[i];
pos++;
i++;
} // ENDWHILE- putting an offset where to store ini data
} else {
// = <Env Home>/<Default Directory>
i = 0;
while((pos < 253) && (*(envptr + i) != 0)) {
confdirname[pos] = *(envptr + i);
conffilename[pos] = *(envptr + i);
pos++;
i++;
} // ENDWHILE- copying home directory info in
if(confdirname[pos-1] != '\\') {
confdirname[pos] = '\\';
conffilename[pos] = '\\';
pos++;
} // ENDIF- No directory separator here? Add one.
i = 0;
while((pos < 253) && (defaultdirectory[i] != 0)) {
confdirname[pos] = defaultdirectory[i];
conffilename[pos] = defaultdirectory[i];
pos++;
i++;
} // NEXT- putting a default place to store configuration data
} // ENDIF- No Home directory?
confdirname[pos] = 0; // Directory reference finished
// += /<Config File Name>
if(conffilename[pos-1] != '\\') {
conffilename[pos] = '\\';
pos++;
} // ENDIF- No directory separator here? Add one.
i = 0;
while((pos < 253) && (defaultfile[i] != 0)) {
conffilename[pos] = defaultfile[i];
pos++;
i++;
} // NEXT- putting a default place to store configuration data
conffilename[pos] = 0; // File reference finished
#ifdef VERBOSE_FUNCTION_CONF
PrintLog("CDVD config: Directory: %s", confdirname);
PrintLog("CDVD config: File: %s", conffilename);
#endif /* VERBOSE_FUNCTION_CONF */
} // END InitConf()
void LoadConf() {
int retval;
#ifdef VERBOSE_FUNCTION_CONF
PrintLog("CDVD config: LoadConf()");
#endif /* VERBOSE_FUNCTION_CONF */
retval = INILoadString(conffilename, "Settings", "Device", conf.devicename);
if(retval < 0) {
sprintf(conf.devicename, "D:");
} // ENDIF- Couldn't find keyword? Fill in a default
} // END LoadConf()
void SaveConf() {
#ifdef VERBOSE_FUNCTION_CONF
PrintLog("CDVD config: SaveConf()");
#endif /* VERBOSE_FUNCTION_CONF */
mkdir(confdirname);
INISaveString(conffilename, "Settings", "Device", conf.devicename);
} // END SaveConf()

View File

@ -0,0 +1,49 @@
/* conf.h
* Copyright (C) 2002-2005 PCSX2 Team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* PCSX2 members can be contacted through their website at www.pcsx2.net.
*/
#ifndef CONF_H
#define CONF_H
#define CDVDdefs
#include "../PS2Edefs.h"
#define VERBOSE_FUNCTION_CONF
// Configuration Data
typedef struct {
u8 devicename[256];
} CDVDconf;
extern CDVDconf conf;
#define DEFAULT_DEVICE "K:\\"
// Configuration Functions
extern void InitConf();
extern void LoadConf();
extern void SaveConf();
#endif /* CONF_H */

View File

@ -0,0 +1,583 @@
/* device.c
* Copyright (C) 2002-2005 PCSX2 Team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* PCSX2 members can be contacted through their website at www.pcsx2.net.
*/
#include <windows.h>
#include <ddk/ntddcdrm.h> // IOCTL_CDROM..., IOCTL_STORAGE...
#include <ddk/ntdddisk.h> // IOCTL_DISK...
#include <stdio.h> // sprintf()
#include <time.h> // time_t
#define CDVDdefs
#include "PS2Edefs.h"
#include "logfile.h"
#include "conf.h"
#include "CD.h"
#include "DVD.h"
#include "device.h"
HANDLE devicehandle;
OVERLAPPED waitevent;
time_t lasttime;
s32 traystatus;
int traystatusmethod;
s32 disctype;
char tocbuffer[2048];
void DeviceInit() {
devicehandle = NULL;
waitevent.hEvent = NULL;
waitevent.Internal = 0;
waitevent.InternalHigh = 0;
waitevent.Offset = 0;
waitevent.OffsetHigh = 0;
lasttime = 0;
InitDisc();
} // END DeviceInit()
void InitDisc() {
int i;
InitCDInfo();
InitDVDInfo();
traystatus = CDVD_TRAY_OPEN;
traystatusmethod = 0; // Poll all until one works
disctype = CDVD_TYPE_NODISC;
for(i = 0; i < 2048; i++) tocbuffer[i] = 0;
} // END InitDisc()
s32 DiscInserted() {
if(traystatus != CDVD_TRAY_CLOSE) return(-1);
if(disctype == CDVD_TYPE_ILLEGAL) return(-1);
// if(disctype == CDVD_TYPE_UNKNOWN) return(-1); // Hmm. Let this one through?
if(disctype == CDVD_TYPE_DETCTDVDD) return(-1);
if(disctype == CDVD_TYPE_DETCTDVDS) return(-1);
if(disctype == CDVD_TYPE_DETCTCD) return(-1);
if(disctype == CDVD_TYPE_DETCT) return(-1);
if(disctype == CDVD_TYPE_NODISC) return(-1);
#ifdef VERBOSE_FUNCTION_DEVICE
PrintLog("CDVDlinuz device: DiscInserted()");
#endif /* VERBOSE_FUNCTION_DEVICE */
return(0);
} // END DiscInserted()
// Returns errcode (or 0 if successful)
DWORD FinishCommand(BOOL boolresult) {
DWORD errcode;
DWORD waitcode;
#ifdef VERBOSE_FUNCTION_DEVICE
PrintLog("CDVDlinuz device: FinishCommand()");
#endif /* VERBOSE_FUNCTION_DEVICE */
if(boolresult == TRUE) {
ResetEvent(waitevent.hEvent);
return(0);
} // ENDIF- Device is ready? Say so.
errcode = GetLastError();
if(errcode == ERROR_IO_PENDING) {
#ifdef VERBOSE_FUNCTION_DEVICE
PrintLog("CDVDlinuz device: Waiting for completion.");
#endif /* VERBOSE_FUNCTION_DEVICE */
waitcode = WaitForSingleObject(waitevent.hEvent, 10 * 1000); // 10 sec wait
if((waitcode == WAIT_FAILED) || (waitcode == WAIT_ABANDONED)) {
errcode = GetLastError();
} else if(waitcode == WAIT_TIMEOUT) {
errcode = 21;
CancelIo(devicehandle); // Speculative Line
} else {
ResetEvent(waitevent.hEvent);
return(0); // Success!
} // ENDIF- Trouble waiting? (Or doesn't finish in 5 seconds?)
} // ENDIF- Should we wait for the call to finish?
ResetEvent(waitevent.hEvent);
return(errcode);
} // END DeviceCommand()
s32 DeviceOpen() {
char tempname[256];
UINT drivetype;
DWORD errcode;
if(conf.devicename[0] == 0) return(-1);
if(devicehandle != NULL) return(0);
#ifdef VERBOSE_FUNCTION_DEVICE
PrintLog("CDVDlinuz device: DeviceOpen()");
#endif /* VERBOSE_FUNCTION_DEVICE */
// InitConf();
// LoadConf(); // Should be done at least once before this call
// Root Directory reference
if(conf.devicename[1] == 0) {
sprintf(tempname, "%s:\\", conf.devicename);
} else if((conf.devicename[1] == ':') && (conf.devicename[2] == 0)) {
sprintf(tempname, "%s\\", conf.devicename);
} else {
sprintf(tempname, "%s", conf.devicename);
} // ENDIF- Not a single drive letter? (or a letter/colon?) Copy the name in.
drivetype = GetDriveType(tempname);
if(drivetype != DRIVE_CDROM) {
#ifdef VERBOSE_WARNING_DEVICE
PrintLog("CDVDlinuz device: Not a CD-ROM!");
PrintLog("CDVDlinuz device: (Came back: %u)", drivetype);
errcode = GetLastError();
if(errcode > 0) PrintError("CDVDlinuz device", errcode);
#endif /* VERBOSE_WARNING_DEVICE */
return(-1);
} // ENDIF- Not a CD-ROM? Say so!
// Hmm. Do we want to include DRIVE_REMOVABLE... just in case?
// Device Reference
if(conf.devicename[1] == 0) {
sprintf(tempname, "\\\\.\\%s:", conf.devicename);
} else if((conf.devicename[1] == ':') && (conf.devicename[2] == 0)) {
sprintf(tempname, "\\\\.\\%s", conf.devicename);
} else {
sprintf(tempname, "%s", conf.devicename);
} // ENDIF- Not a single drive letter? (or a letter/colon?) Copy the name in.
devicehandle = CreateFile(tempname,
GENERIC_READ,
FILE_SHARE_READ,
NULL,
OPEN_EXISTING,
FILE_FLAG_OVERLAPPED | FILE_FLAG_SEQUENTIAL_SCAN,
NULL);
if(devicehandle == INVALID_HANDLE_VALUE) {
#ifdef VERBOSE_WARNING_DEVICE
PrintLog("CDVDlinuz device: Couldn't open device read-only! Read-Write perhaps?");
errcode = GetLastError();
PrintError("CDVDlinuz device", errcode);
#endif /* VERBOSE_WARNING_DEVICE */
devicehandle = CreateFile(tempname,
GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL,
OPEN_EXISTING,
FILE_FLAG_OVERLAPPED | FILE_FLAG_SEQUENTIAL_SCAN,
NULL);
} // ENDIF- Couldn't open for read? Try read/write (for those drives that insist)
if(devicehandle == INVALID_HANDLE_VALUE) {
#ifdef VERBOSE_WARNING_DEVICE
PrintLog("CDVDlinuz device: Couldn't open device!");
errcode = GetLastError();
PrintError("CDVDlinuz device", errcode);
#endif /* VERBOSE_WARNING_DEVICE */
devicehandle = NULL;
return(-1);
} // ENDIF- Couldn't open that way either? Abort.
waitevent.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
if(waitevent.hEvent == INVALID_HANDLE_VALUE) {
#ifdef VERBOSE_WARNING_DEVICE
PrintLog("CDVDlinuz device: Couldn't open event handler!");
errcode = GetLastError();
PrintError("CDVDlinuz device", errcode);
#endif /* VERBOSE_WARNING_DEVICE */
waitevent.hEvent = NULL;
CloseHandle(devicehandle);
devicehandle = NULL;
} // ENDIF- Couldn't create an "Wait for I/O" handle? Abort.
// More here... DeviceIoControl? for Drive Capabilities
// DEVICE_CAPABILITIES?
////// Should be done just after the first DeviceOpen();
// InitDisc(); // ?
// DeviceTrayStatus();
return(0);
} // END DeviceOpen()
void DeviceClose() {
if(devicehandle == NULL) return;
if(devicehandle == INVALID_HANDLE_VALUE) {
devicehandle = NULL;
return;
} // ENDIF- Bad value? Just clear the value.
#ifdef VERBOSE_FUNCTION_DEVICE
PrintLog("CDVDlinuz device: DeviceClose()");
#endif /* VERBOSE_FUNCTION_DEVICE */
if(waitevent.hEvent != NULL) {
if(waitevent.hEvent != INVALID_HANDLE_VALUE) {
CancelIo(devicehandle);
CloseHandle(waitevent.hEvent);
} // ENDIF- Is this handle actually open?
waitevent.hEvent = NULL;
waitevent.Offset = 0;
waitevent.OffsetHigh = 0;
} // ENDIF- Reset the event handle?
CloseHandle(devicehandle);
devicehandle = NULL;
return;
} // END DeviceClose()
s32 DeviceReadTrack(u32 lsn, int mode, u8 *buffer) {
if(DiscInserted() == -1) return(-1);
if((disctype == CDVD_TYPE_PS2DVD) || (disctype == CDVD_TYPE_DVDV)) {
return(DVDreadTrack(lsn, mode, buffer));
} else {
return(CDreadTrack(lsn, mode, buffer));
} // ENDIF- Is this a DVD?
} // END DeviceReadTrack()
s32 DeviceBufferOffset() {
if(DiscInserted() == -1) return(-1);
if((disctype == CDVD_TYPE_PS2DVD) || (disctype == CDVD_TYPE_DVDV)) {
return(0);
} else {
return(CDgetBufferOffset());
} // ENDIF- Is this a DVD?
return(-1);
} // END DeviceBufferOffset()
s32 DeviceGetTD(u8 track, cdvdTD *cdvdtd) {
if(DiscInserted() == -1) return(-1);
if((disctype == CDVD_TYPE_PS2DVD) || (disctype == CDVD_TYPE_DVDV)) {
return(DVDgetTD(track, cdvdtd));
} else {
return(CDgetTD(track, cdvdtd));
} // ENDIF- Is this a DVD?
return(-1);
} // END DeviceGetTD()
s32 DeviceGetDiskType() {
s32 s32result;
if(devicehandle == NULL) return(-1);
if(devicehandle == INVALID_HANDLE_VALUE) return(-1);
if(traystatus == CDVD_TRAY_OPEN) return(disctype);
if(disctype != CDVD_TYPE_NODISC) return(disctype);
#ifdef VERBOSE_FUNCTION_DEVICE
PrintLog("CDVDlinuz device: DeviceGetDiskType()");
#endif /* VERBOSE_FUNCTION_DEVICE */
disctype = CDVD_TYPE_DETCT;
s32result = DVDgetDiskType();
if(s32result != -1) return(disctype);
s32result = CDgetDiskType();
if(s32result != -1) return(disctype);
disctype = CDVD_TYPE_UNKNOWN;
return(disctype);
} // END DeviceGetDiskType()
BOOL DeviceTrayStatusStorage() {
BOOL boolresult;
DWORD byteswritten;
DWORD errcode;
boolresult = DeviceIoControl(devicehandle,
IOCTL_STORAGE_CHECK_VERIFY,
NULL,
0,
NULL,
0,
&byteswritten,
NULL);
errcode = FinishCommand(boolresult);
if(errcode == 0) return(TRUE);
if(errcode == 21) return(FALSE); // Device not ready? (Valid error)
#ifdef VERBOSE_WARNING_DEVICE
PrintLog("CDVDlinuz device: Trouble detecting drive status (STORAGE)!");
PrintError("CDVDlinuz device", errcode);
#endif /* VERBOSE_WARNING_DEVICE */
return(FALSE);
} // END DeviceTrayStatusStorage()
BOOL DeviceTrayStatusCDRom() {
BOOL boolresult;
DWORD byteswritten;
DWORD errcode;
boolresult = DeviceIoControl(devicehandle,
IOCTL_CDROM_CHECK_VERIFY,
NULL,
0,
NULL,
0,
&byteswritten,
NULL);
errcode = FinishCommand(boolresult);
if(errcode == 0) return(TRUE);
if(errcode == 21) return(FALSE); // Device not ready? (Valid error)
#ifdef VERBOSE_WARNING_DEVICE
PrintLog("CDVDlinuz device: Trouble detecting drive status (CDROM)!");
PrintError("CDVDlinuz device", errcode);
#endif /* VERBOSE_WARNING_DEVICE */
return(FALSE);
} // END DeviceTrayStatusCDRom()
BOOL DeviceTrayStatusDisk() {
BOOL boolresult;
DWORD byteswritten;
DWORD errcode;
boolresult = DeviceIoControl(devicehandle,
IOCTL_DISK_CHECK_VERIFY,
NULL,
0,
NULL,
0,
&byteswritten,
NULL);
errcode = FinishCommand(boolresult);
if(errcode == 0) return(TRUE);
if(errcode == 21) return(FALSE); // Device not ready? (Valid error)
#ifdef VERBOSE_WARNING_DEVICE
PrintLog("CDVDlinuz device: Trouble detecting drive status (DISK)!");
PrintError("CDVDlinuz device", errcode);
#endif /* VERBOSE_WARNING_DEVICE */
return(FALSE);
} // END DeviceTrayStatusDisk()
s32 DeviceTrayStatus() {
BOOL boolresult;
if(devicehandle == NULL) return(-1);
if(devicehandle == INVALID_HANDLE_VALUE) return(-1);
#ifdef VERBOSE_FUNCTION_DEVICE
PrintLog("CDVDlinuz device: DeviceTrayStatus()");
#endif /* VERBOSE_FUNCTION_DEVICE */
switch(traystatusmethod) {
case 1:
boolresult = DeviceTrayStatusStorage();
break;
case 2:
boolresult = DeviceTrayStatusCDRom();
break;
case 3:
boolresult = DeviceTrayStatusDisk();
break;
default:
boolresult = FALSE;
break;
} // ENDSWITCH traystatusmethod- One method already working? Try it again.
if(boolresult == FALSE) {
traystatusmethod = 0;
boolresult = DeviceTrayStatusStorage();
if(boolresult == TRUE) {
traystatusmethod = 1;
} else {
boolresult = DeviceTrayStatusCDRom();
if(boolresult == TRUE) {
traystatusmethod = 2;
} else {
boolresult = DeviceTrayStatusDisk();
if(boolresult == TRUE) traystatusmethod = 3;
} // ENDIF- Did we succeed with CDRom?
} // ENDIF- Did we succeed with Storage?
} // Single call to already working test just failed? Test them all.
if(boolresult == FALSE) {
if(traystatus == CDVD_TRAY_CLOSE) {
#ifdef VERBOSE_FUNCTION_DEVICE
PrintLog("CDVDlinuz device: Tray just opened!");
#endif /* VERBOSE_FUNCTION_DEVICE */
traystatus = CDVD_TRAY_OPEN;
DeviceClose();
DeviceOpen();
InitDisc();
} // ENDIF- Just opened? clear disc info
return(traystatus);
} // ENDIF- Still failed? Assume no disc in drive then.
if(traystatus == CDVD_TRAY_OPEN) {
traystatus = CDVD_TRAY_CLOSE;
#ifdef VERBOSE_FUNCTION_DEVICE
PrintLog("CDVDlinuz device: Tray just closed!");
#endif /* VERBOSE_FUNCTION_DEVICE */
DeviceGetDiskType();
return(traystatus);
} // ENDIF- Just closed? Get disc information
return(traystatus);
} // END DeviceTrayStatus()
s32 DeviceTrayOpen() {
BOOL boolresult;
DWORD byteswritten;
DWORD errcode;
if(devicehandle == NULL) return(-1);
if(devicehandle == INVALID_HANDLE_VALUE) return(-1);
if(traystatus == CDVD_TRAY_OPEN) return(0);
#ifdef VERBOSE_FUNCTION_DEVICE
PrintLog("CDVDlinuz device: DeviceOpenTray()");
#endif /* VERBOSE_FUNCTION_DEVICE */
boolresult = DeviceIoControl(devicehandle,
IOCTL_STORAGE_EJECT_MEDIA,
NULL,
0,
NULL,
0,
&byteswritten,
&waitevent);
errcode = FinishCommand(boolresult);
if(errcode != 0) {
#ifdef VERBOSE_WARNING_DEVICE
PrintLog("CDVDlinuz device: Couldn't signal media to eject! (STORAGE)");
PrintError("CDVDlinuz device", errcode);
#endif /* VERBOSE_WARNING_DEVICE */
// boolresult = DeviceIoControl(devicehandle,
// IOCTL_DISK_EJECT_MEDIA,
// NULL,
// 0,
// NULL,
// 0,
// &byteswritten,
// NULL);
// } // ENDIF- Storage Call failed? Try Disk call.
// if(boolresult == FALSE) {
// #ifdef VERBOSE_WARNING_DEVICE
// PrintLog("CDVDlinuz device: Couldn't signal media to eject! (DISK)");
// PrintError("CDVDlinuz device", errcode);
// #endif /* VERBOSE_WARNING_DEVICE */
return(-1);
} // ENDIF- Disk Call failed as well? Give it up.
return(0);
} // END DeviceTrayOpen()
s32 DeviceTrayClose() {
BOOL boolresult;
DWORD byteswritten;
DWORD errcode;
if(devicehandle == NULL) return(-1);
if(devicehandle == INVALID_HANDLE_VALUE) return(-1);
if(traystatus == CDVD_TRAY_CLOSE) return(0);
#ifdef VERBOSE_FUNCTION_DEVICE
PrintLog("CDVDlinuz device: DeviceCloseTray()");
#endif /* VERBOSE_FUNCTION_DEVICE */
boolresult = DeviceIoControl(devicehandle,
IOCTL_STORAGE_LOAD_MEDIA,
NULL,
0,
NULL,
0,
&byteswritten,
NULL);
errcode = FinishCommand(boolresult);
if(errcode != 0) {
#ifdef VERBOSE_WARNING_DEVICE
PrintLog("CDVDlinuz device: Couldn't signal media to load! (STORAGE)");
PrintError("CDVDlinuz device", errcode);
#endif /* VERBOSE_WARNING_DEVICE */
// boolresult = DeviceIoControl(devicehandle,
// IOCTL_CDROM_LOAD_MEDIA,
// NULL,
// 0,
// NULL,
// 0,
// &byteswritten,
// NULL);
// } // ENDIF- Storage call failed. CDRom call?
// if(boolresult == FALSE) {
// errcode = GetLastError();
// #ifdef VERBOSE_WARNING_DEVICE
// PrintLog("CDVDlinuz device: Couldn't signal media to load! (CDROM)");
// PrintError("CDVDlinuz device", errcode);
// #endif /* VERBOSE_WARNING_DEVICE */
// boolresult = DeviceIoControl(devicehandle,
// IOCTL_DISK_LOAD_MEDIA,
// NULL,
// 0,
// NULL,
// 0,
// &byteswritten,
// NULL);
// } // ENDIF- CDRom call failed. Disk call?
// if(boolresult == FALSE) {
// #ifdef VERBOSE_WARNING_DEVICE
// PrintLog("CDVDlinuz device: Couldn't signal media to load! (DISK)");
// PrintError("CDVDlinuz device", errcode);
// #endif /* VERBOSE_WARNING_DEVICE */
return(-1);
} // ENDIF- Media not available?
return(0);
} // END DeviceTrayClose()

View File

@ -0,0 +1,64 @@
/* device.h
* Copyright (C) 2002-2005 PCSX2 Team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* PCSX2 members can be contacted through their website at www.pcsx2.net.
*/
#ifndef __DEVICE_H__
#define __DEVICE_H__
#include <windows.h> // BOOL, DWORD
#include <time.h> // time_t
#define CDVDdefs
#include "../PS2Edefs.h"
// #define VERBOSE_FUNCTION_DEVICE
// #define VERBOSE_WARNING_DEVICE
#define VERBOSE_DISC_TYPE
#define VERBOSE_DISC_INFO
extern HANDLE devicehandle;
extern OVERLAPPED waitevent;
extern time_t lasttime;
extern s32 traystatus;
extern s32 disctype;
extern char tocbuffer[];
extern void DeviceInit();
extern void InitDisc();
extern s32 DiscInserted();
extern DWORD FinishCommand(BOOL boolresult);
extern s32 DeviceOpen();
extern void DeviceClose();
extern s32 DeviceReadTrack(u32 lsn, int mode, u8 *buffer);
extern s32 DeviceBufferOffset();
extern s32 DeviceGetTD(u8 track, cdvdTD *cdvdtd);
extern s32 DeviceGetDiskType();
extern s32 DeviceTrayStatus();
extern s32 DeviceTrayOpen();
extern s32 DeviceTrayClose();
#endif /* __DEVICE_H__ */

View File

@ -0,0 +1,119 @@
/* logfile.c
* Copyright (C) 2002-2005 PCSX2 Team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* PCSX2 members can be contacted through their website at www.pcsx2.net.
*/
#include <windows.h>
// #include <fcntl.h> // open()
// #include <io.h> // mkdir()
#include <stddef.h> // NULL
#include <stdio.h> // vsprintf()
#include <stdarg.h> // va_start(), va_end(), vsprintf()
// #include <sys/stat.h> // open()
// #include <sys/types.h> // open()
#include "logfile.h"
HANDLE logfile;
char logfiletemp[2048];
void InitLog() {
// Token comment line
#ifdef VERBOSE_LOGFILE
CreateDirectory("logs", NULL);
DeleteFile("logs\\CDVDlog.txt");
logfile = NULL;
#endif /* VERBOSE LOGFILE */
} // END InitLog();
int OpenLog() {
// Token comment line
#ifdef VERBOSE_LOGFILE
logfile = CreateFile("logs\\CDVDlog.txt",
GENERIC_WRITE,
0,
NULL,
CREATE_ALWAYS,
FILE_FLAG_SEQUENTIAL_SCAN,
NULL);
if(logfile == INVALID_HANDLE_VALUE) {
logfile = NULL;
return(-1);
} // ENDIF- Failed to open? Say so.
#endif /* VERBOSE LOGFILE */
return(0);
} // END OpenLog();
void CloseLog() {
// Token comment line
#ifdef VERBOSE_LOGFILE
if(logfile != NULL) {
CloseHandle(logfile);
logfile = NULL;
} // ENDIF- Is the log file actually open? Close it.
#endif /* VERBOSE LOGFILE */
} // END CloseLog()
void PrintLog(const char *fmt, ...) {
DWORD byteswritten;
// Token comment line
#ifdef VERBOSE_LOGFILE
va_list list;
int len;
if(logfile == NULL) return; // Log file not open... yet.
va_start(list, fmt);
vsprintf(logfiletemp, fmt, list);
va_end(list);
len = 0;
while((len < 2048) && (logfiletemp[len] != 0)) len++;
if((len > 0) && (logfiletemp[len-1] == '\n')) len--;
if((len > 0) && (logfiletemp[len-1] == '\r')) len--;
logfiletemp[len] = 0; // Slice off the last "\r\n"...
WriteFile(logfile, logfiletemp, len, &byteswritten, NULL);
WriteFile(logfile, "\r\n", 2, &byteswritten, NULL);
#endif /* VERBOSE LOGFILE */
} // END PrintLog()
void PrintError(const char *header, DWORD errcode) {
#ifdef VERBOSE_LOGFILE
TCHAR errmsg[256];
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | 80,
NULL,
errcode,
0,
errmsg,
256,
NULL);
PrintLog("%s: (%u) %s", header, errcode, errmsg);
#endif /* VERBOSE_WARNING_DEVICE */
} // END PrintError()

View File

@ -0,0 +1,39 @@
/* logfile.h
* Copyright (C) 2002-2005 PCSX2 Team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* PCSX2 members can be contacted through their website at www.pcsx2.net.
*/
#ifndef LOGFILE_H
#define LOGFILE_H
#include <windows.h> // Just for DWORD
#define VERBOSE_LOGFILE
extern void InitLog();
extern int OpenLog();
extern void CloseLog();
extern void PrintLog(const char *format, ...);
extern void PrintError(const char *header, DWORD errcode);
#endif /* LOGFILE_H */

View File

@ -0,0 +1,173 @@
/* mainbox.c
* Copyright (C) 2002-2005 PCSX2 Team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* PCSX2 members can be contacted through their website at www.pcsx2.net.
*/
#include <windows.h>
// #include <windowsx.h> // Button_
#include <windef.h> // NULL
#include <stdio.h> // sprintf()
#include <string.h> // strcpy()
#include <sys/stat.h> // stat()
#include <sys/types.h> // stat()
#include <unistd.h> // stat()
#include "conf.h"
#include "device.h"
// #include "imagetype.h" // imagedata[].name
#include "screens.h" // DLG_, IDC_
#include "CDVDlinuz.h" // progmodule
#include "mainbox.h"
HWND mainboxwindow;
void MainBoxDestroy() {
if(mainboxwindow != NULL) {
EndDialog(mainboxwindow, FALSE);
mainboxwindow = NULL;
} // ENDIF- Do we have a Main Window still?
} // END MainBoxDestroy()
void MainBoxUnfocus() {
// EnableWindow(?)
// gtk_widget_set_sensitive(mainbox.device, FALSE);
ShowWindow(mainboxwindow, SW_HIDE);
} // END MainBoxUnfocus()
void MainBoxDeviceEvent() {
char tempdevice[256];
struct stat filestat;
int returnval;
GetDlgItemText(mainboxwindow, IDC_0202, tempdevice, 256);
returnval = stat(tempdevice, &filestat);
if(returnval == -1) {
SetDlgItemText(mainboxwindow, IDC_0203, "Device Type: ---");
return;
} // ENDIF- Not a name of any sort?
if(S_ISDIR(filestat.st_mode) != 0) {
SetDlgItemText(mainboxwindow, IDC_0203, "Device Type: Not a device");
return;
} // ENDIF- Not a regular file?
SetDlgItemText(mainboxwindow, IDC_0203, "Device Type: Device Likely");
return;
} // END MainBoxFileEvent()
void MainBoxRefocus() {
MainBoxDeviceEvent();
// gtk_widget_set_sensitive(mainbox.device, TRUE);
// gtk_window_set_focus(GTK_WINDOW(mainbox.window), mainbox.device);
// ShowWindow(mainboxwindow, SW_RESTORE); // and/or, SW_SHOW? SW_SHOWNORMAL?
ShowWindow(mainboxwindow, SW_SHOW);
SetActiveWindow(mainboxwindow);
} // END MainBoxRefocus()
void MainBoxCancelEvent() {
MainBoxDestroy();
return;
} // END MainBoxCancelEvent()
void MainBoxOKEvent() {
int retval;
MainBoxUnfocus();
GetDlgItemText(mainboxwindow, IDC_0202, conf.devicename, 256);
retval = DeviceOpen();
DeviceClose();
if(retval != 0) {
MainBoxRefocus();
MessageBox(mainboxwindow,
"Could not open the device",
"CDVDlinuz Message",
MB_OK | MB_ICONWARNING | MB_SETFOREGROUND);
return;
} // ENDIF- Trouble opening device? Abort here.
SaveConf();
MainBoxCancelEvent();
return;
} // END MainBoxOKEvent()
void MainBoxDisplay() {
InitConf(); // Man, am I boiling mad! CDVDinit() should have been called first!
LoadConf();
// Adjust window position?
// We held off setting the name until now... so description would show.
SetDlgItemText(mainboxwindow, IDC_0202, conf.devicename);
// First Time - Show the window
ShowWindow(mainboxwindow, SW_SHOWNORMAL);
} // END MainBoxDisplay()
BOOL CALLBACK MainBoxCallback(HWND window,
UINT msg,
WPARAM param,
LPARAM param2) {
switch(msg) {
case WM_INITDIALOG:
mainboxwindow = window;
MainBoxDisplay(); // In this case, final touches to this window.
return(FALSE); // And let Windows display this window.
break;
case WM_CLOSE: // The "X" in the upper right corner was hit.
MainBoxCancelEvent();
return(TRUE);
break;
case WM_COMMAND:
// Do we wish to capture 'ENTER/RETURN' and/or 'ESC' here?
switch(LOWORD(param)) {
case IDC_0202: // Devicename Edit Box
MainBoxDeviceEvent(); // Describe the File's type...
return(FALSE); // Let Windows handle the actual 'edit' processing...
break;
case IDC_0204: // "Ok" Button
MainBoxOKEvent();
return(TRUE);
break;
case IDC_0205: // "Cancel" Button
MainBoxCancelEvent();
return(TRUE);
break;
} // ENDSWITCH param- Which object got the message?
} // ENDSWITCH msg- what message has been sent to this window?
return(FALSE); // Not a recognized message? Tell Windows to handle it.
} // END MainBoxEventLoop()

View File

@ -0,0 +1,42 @@
/* mainbox.h
* Copyright (C) 2002-2005 PCSX2 Team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* PCSX2 members can be contacted through their website at www.pcsx2.net.
*/
#ifndef MAINBOX_H
#define MAINBOX_H
#include <windows.h> // HWND
extern const char fileselection[];
extern HWND mainboxwindow;
extern void MainBoxRefocus();
extern void MainBoxDisplay();
extern BOOL CALLBACK MainBoxCallback(HWND window,
UINT msg,
WPARAM param,
LPARAM param2);
#endif /* MAINBOX_H */

View File

@ -0,0 +1 @@
mingw32-make -f Makefile.MinGW32 %1

View File

@ -0,0 +1,21 @@
EXPORTS
PS2EgetLibType = PS2EgetLibType@0 @2
PS2EgetLibName = PS2EgetLibName@0 @3
PS2EgetLibVersion2 = PS2EgetLibVersion2@4 @4
CDVDinit = CDVDinit@0 @5
CDVDshutdown = CDVDshutdown@0 @6
CDVDopen = CDVDopen@0 @7
CDVDclose = CDVDclose@0 @8
CDVDreadTrack = CDVDreadTrack@8 @9
CDVDgetBuffer = CDVDgetBuffer@0 @10
CDVDreadSubQ = CDVDreadSubQ@8 @11
CDVDgetTN = CDVDgetTN@4 @12
CDVDgetTD = CDVDgetTD@8 @13
CDVDgetTOC = CDVDgetTOC@4 @14
CDVDgetDiskType = CDVDgetDiskType@0 @15
CDVDgetTrayStatus = CDVDgetTrayStatus@0 @16
CDVDctrlTrayOpen = CDVDctrlTrayOpen@0 @17
CDVDctrlTrayClose = CDVDctrlTrayClose@0 @18
CDVDconfigure = CDVDconfigure@0 @19
CDVDtest = CDVDtest@0 @20
CDVDabout = CDVDabout@0 @21

View File

@ -0,0 +1,9 @@
/* Weditres generated include file. Do NOT edit */
#include <windows.h>
#define DLG_0100 100
#define IDC_0104 104
#define DLG_0200 200
#define IDC_0202 202
#define IDC_0203 203
#define IDC_0204 204
#define IDC_0205 205

View File

@ -0,0 +1,29 @@
/* Wedit generated resource file */
#ifdef __LCC__
#include <windows.h>
#endif
#include "screens.h"
DLG_0100 DIALOG 2, 2, 140, 59
STYLE DS_CENTER | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
CAPTION "About CDVDlinuz"
FONT 8, "MS Sans Serif"
BEGIN
CTEXT "EFP polling CDVD Driver v0.4", 101, 11, 6, 118, 12
CTEXT "Current Author: efp", 102, 12, 16, 118, 12
CTEXT "Original code by: linuzappz && shadow", 103, 12, 26, 118, 12
PUSHBUTTON "Ok", IDC_0104, 50, 37, 40, 14
END
DLG_0200 DIALOG 4, 2, 241, 50
STYLE WS_MINIMIZEBOX | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
CAPTION "CDVDlinuz Configuration"
FONT 8, "MS Sans Serif"
BEGIN
LTEXT "CD/DVD device:", 201, 14, 8, 59, 12
EDITTEXT IDC_0202, 71, 7, 164, 12, ES_AUTOHSCROLL
CTEXT "Device Type: ---", IDC_0203, 10, 21, 220, 12
PUSHBUTTON "Ok", IDC_0204, 15, 31, 48, 14
PUSHBUTTON "Cancel", IDC_0205, 177, 31, 48, 14
END

View File

@ -0,0 +1,525 @@
/* buffer.c
* Copyright (C) 2002-2005 CDVDlinuz Team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <errno.h> // errno
#include <stddef.h> // NULL
#include <stdio.h> // printf()
#include <string.h> // strerror()
#ifndef __LINUX__
#ifdef __linux__
#define __LINUX__
#endif /* __linux__ */
#endif /* No __LINUX__ */
#define CDVDdefs
#include "PS2Edefs.h"
#include "logfile.h"
#include "buffer.h"
// Globals
struct BufferSortEmpty {
u16 sortptr;
};
struct BufferSort {
u16 upptr;
u16 uppos;
u32 mask;
u32 divisor;
struct {
u8 isdata;
u16 ptr;
} lower[256];
u16 ptrcount;
u16 firstptr;
};
struct BufferSortEmpty buffersortempty[BUFFERMAX];
u16 buffersortemptystart;
u16 buffersortemptyend;
struct BufferSort buffersort[BUFFERMAX];
u8 buffersortstartisdata;
u16 buffersortstart;
struct BufferList bufferlist[BUFFERMAX];
u16 userbuffer;
u16 replacebuffer;
void InitBuffer() {
u16 i;
u16 j;
#ifdef VERBOSE_FUNCTION_BUFFER
PrintLog("CDVD buffer: InitBuffer()");
#endif /* VERBOSE_FUNCTION_BUFFER */
buffersortemptystart = 0;
buffersortemptyend = 0;
for(i = 0; i < BUFFERMAX; i++) {
buffersortempty[i].sortptr = i;
} // NEXT i- Saying all buffersort[] entries are open.
buffersortstart = 0xffff;
buffersortstartisdata = 2;
for(i = 0; i < BUFFERMAX; i++) {
for(j = 0; j < 256; j++) buffersort[i].lower[j].isdata = 2;
// buffersort[i].ptrcount = 0;
} // NEXT i- Saying all buffersort[] entries are open.
for(i = 0; i < BUFFERMAX; i++) {
bufferlist[i].upsort = 0xffff;
} // NEXT i- Clearing out the buffer pointers
userbuffer = 0xffff;
replacebuffer = BUFFERMAX - 1;
} // END InitBuffer();
u16 AllocSortBuffer() {
u16 newbuffer;
#ifdef VERBOSE_FUNCTION_BUFFER
PrintLog("CDVD buffer: AllocSortBuffer()");
#endif /* VERBOSE_FUNCTION_BUFFER */
newbuffer = buffersortempty[buffersortemptyend].sortptr;
buffersortempty[buffersortemptyend].sortptr = BUFFERMAX;
buffersortemptyend++;
if(buffersortemptyend > BUFFERMAX - 1) buffersortemptyend = 0;
#ifdef VERBOSE_FUNCTION_BUFFER
PrintLog("CDVD buffer: Sort Buffer %u", newbuffer);
#endif /* VERBOSE_FUNCTION_BUFFER */
#ifdef VERBOSE_WARNINGS_BUFFER
if(buffersortemptyend == buffersortemptystart) {
PrintLog("Completely out of Sort Buffers to allocate now!");
} // ENDIF- Out of Sort Buffers? Say so!
#endif /* VERBOSE_WARNINGS_BUFFER */
return(newbuffer);
} // END AllocSortBuffer()
void ReleaseSortBuffer(u16 oldbuffer) {
#ifdef VERBOSE_FUNCTION_BUFFER
PrintLog("CDVD buffer: ReleaseSortBuffer(%u)", oldbuffer);
#endif /* VERBOSE_FUNCTION_BUFFER */
buffersortempty[buffersortemptystart].sortptr = oldbuffer;
buffersortemptystart++;
if(buffersortemptystart > BUFFERMAX - 1) buffersortemptystart = 0;
} // END ReleaseSortBuffer()
// Returns either index in buffersort... or closest insertion point.
// Make lsn == buffersort[int].lsn test for exact match
u16 FindListBuffer(u32 lsn) {
u16 current;
u8 isdata;
u32 index;
#ifdef VERBOSE_FUNCTION_BUFFER
PrintLog("CDVD buffer: FindListBuffer(%u)", lsn);
#endif /* VERBOSE_FUNCTION_BUFFER */
if(buffersortstart == 0xffff) return(0xffff); // Buffer empty? Exit
if(buffersortstartisdata == 1) {
if(bufferlist[buffersortstart].lsn != lsn) return(0xffff);
return(buffersortstart);
} // ENDIF- Only one Record in Buffer?
#ifdef VERBOSE_FUNCTION_BUFFER
PrintLog("CDVD buffer: Searching...");
#endif /* VERBOSE_FUNCTION_BUFFER */
current = buffersortstart;
isdata = 0;
while(isdata == 0) {
index = lsn;
index &= buffersort[current].mask;
index /= buffersort[current].divisor;
isdata = buffersort[current].lower[index].isdata;
current = buffersort[current].lower[index].ptr;
} // ENDWHILE- still haven't found data
if(isdata == 2) return(0xffff); // Pointing at empty entry?
if(bufferlist[current].lsn != lsn) return(0xffff); // LSNs don't match?
#ifdef VERBOSE_FUNCTION_BUFFER
PrintLog("CDVD buffer: Found.");
#endif /* VERBOSE_FUNCTION_BUFFER */
return(current);
} // END FindListBuffer()
// Removes buffer from the buffersort list
// bufnum = The bufferlist pointer
void RemoveListBuffer(u16 bufnum) {
u16 current;
u16 currentpos;
u16 upperlink;
u16 upperindex;
u16 lowerlink;
u8 lowerisdata;
u32 index;
#ifdef VERBOSE_FUNCTION_BUFFER
PrintLog("CDVD buffer: RemoveListBuffer(%u)", bufnum);
#endif /* VERBOSE_FUNCTION_BUFFER */
if(bufferlist[bufnum].upsort == 0xffff) return; // No link to break.
current = bufferlist[bufnum].upsort;
currentpos = bufferlist[bufnum].uppos;
bufferlist[bufnum].upsort = 0xffff;
if(current == 0xfffe) {
buffersortstart = 0xffff;
buffersortstartisdata = 2;
#ifdef VERBOSE_FUNCTION_BUFFER
PrintLog("CDVD buffer: Buffer emptied");
#endif /* VERBOSE_FUNCTION_BUFFER */
return;
} // ENDIF- Last link broken... empty buffer now.
lowerlink = 0xffff;
lowerisdata = 2;
// Remove Lower Pointer
buffersort[current].lower[currentpos].isdata = 2;
if(currentpos == buffersort[current].firstptr) {
index = currentpos + 1;
while((index < 256) && (buffersort[current].lower[index].isdata == 2)) index++;
buffersort[current].firstptr = index;
} // ENDIF- Do we need to move firstptr to an active entry?
buffersort[current].ptrcount--;
#ifdef VERBOSE_FUNCTION_BUFFER
PrintLog("CDVD buffer: Pointer count for sort buffer %u: %u",
current, buffersort[current].ptrcount);
#endif /* VERBOSE_FUNCTION_BUFFER */
if(buffersort[current].ptrcount > 1) return; // Still 2+ branches left
// Find Lower Link
index = buffersort[current].firstptr;
lowerlink = buffersort[current].lower[index].ptr;
lowerisdata = buffersort[current].lower[index].isdata;
buffersort[current].lower[index].isdata = 2;
// Find and Break Upper Link
upperlink = buffersort[current].upptr;
upperindex = buffersort[current].uppos;
if(upperlink == 0xffff) {
buffersortstart = lowerlink;
buffersortstartisdata = lowerisdata;
} else {
buffersort[upperlink].lower[upperindex].ptr = lowerlink;
buffersort[upperlink].lower[upperindex].isdata = lowerisdata;
} // ENDIF- Did we hit the top of the web?
// Break Lower Link
if(lowerisdata == 1) {
if(upperlink == 0xffff) {
bufferlist[lowerlink].upsort = 0xfffe;
#ifdef VERBOSE_FUNCTION_BUFFER
PrintLog("CDVD buffer: Buffer down to 1 record now");
#endif /* VERBOSE_FUNCTION_BUFFER */
} else {
bufferlist[lowerlink].upsort = upperlink;
bufferlist[lowerlink].uppos = upperindex;
} // ENDIF- Is this the last active buffersort?
} else {
buffersort[lowerlink].upptr = upperlink;
buffersort[lowerlink].uppos = upperindex;
} // ENDIF- Was this a BufferList link?
// Cleanup in aisle 5....
ReleaseSortBuffer(current);
return;
} // END RemoveListBuffer()
// Adds buffer to the buffersort list
// bufnum = The bufferlist pointer
void AddListBuffer(u16 bufnum) {
u32 newmask;
u32 newdivisor;
u16 newbuffer;
u32 newvalue;
u16 current;
u32 currentvalue;
u8 currentisdata;
u16 prevbuffer;
u32 prevvalue;
u16 comparebuffer;
u8 compareisdata;
u32 comparevalue;
#ifdef VERBOSE_FUNCTION_BUFFER
PrintLog("CDVD buffer: AddListBuffer(%u)", bufnum);
#endif /* VERBOSE_FUNCTION_BUFFER */
// Already in list? Oh, re-sorting? Got it covered.
if(bufferlist[bufnum].upsort != 0xffff) RemoveListBuffer(bufnum);
if(buffersortstartisdata == 2) {
buffersortstart = bufnum;
buffersortstartisdata = 1;
bufferlist[bufnum].upsort = 0xfffe;
#ifdef VERBOSE_FUNCTION_BUFFER
PrintLog("CDVD buffer: Buffer up to 1 record now");
#endif /* VERBOSE_FUNCTION_BUFFER */
return;
} // ENDIF- Empty list? Set for just 1 entry.
if(buffersortstartisdata == 1) {
newmask = 0xff000000;
newdivisor = 0x01000000;
newvalue = (bufferlist[bufnum].lsn & newmask) / newdivisor;
currentvalue = (bufferlist[buffersortstart].lsn & newmask) / newdivisor;
while((newdivisor != 0x00000001) && (newvalue == currentvalue)) {
newmask /= 0x0100;
newdivisor /= 0x0100;
newvalue = (bufferlist[bufnum].lsn & newmask) / newdivisor;
currentvalue = (bufferlist[buffersortstart].lsn & newmask) / newdivisor;
} // ENDWHILE- trying to find a difference between the LSNs
if(newvalue == currentvalue) {
bufferlist[buffersortstart].upsort = 0xffff;
bufferlist[bufnum].upsort = 0xfffe;
buffersortstart = bufnum;
return;
} else {
newbuffer = AllocSortBuffer();
buffersort[newbuffer].upptr = 0xffff;
buffersort[newbuffer].mask = newmask;
buffersort[newbuffer].divisor = newdivisor;
buffersort[newbuffer].lower[currentvalue].isdata = 1;
buffersort[newbuffer].lower[currentvalue].ptr = buffersortstart;
buffersort[newbuffer].lower[newvalue].isdata = 1;
buffersort[newbuffer].lower[newvalue].ptr = bufnum;
buffersort[newbuffer].ptrcount = 2;
buffersort[newbuffer].firstptr = currentvalue;
if(newvalue < buffersort[newbuffer].firstptr)
buffersort[newbuffer].firstptr = newvalue;
bufferlist[buffersortstart].upsort = newbuffer;
bufferlist[buffersortstart].uppos = currentvalue;
buffersortstart = newbuffer;
buffersortstartisdata = 0;
bufferlist[bufnum].upsort = newbuffer;
bufferlist[bufnum].uppos = newvalue;
#ifdef VERBOSE_FUNCTION_BUFFER
PrintLog("CDVD buffer: Buffer up to 2 records now");
#endif /* VERBOSE_FUNCTION_BUFFER */
return;
} // ENDIF- Same LSN? Shift pointer in response. Else, add a Sort Record.
} // ENDIF- Only 1 record? Check if we need a Sort Record.
newmask = 0xff000000;
newdivisor = 0x01000000;
prevbuffer = 0xffff;
prevvalue = 0;
current = buffersortstart;
currentisdata = 0;
while(currentisdata == 0) {
newvalue = (bufferlist[bufnum].lsn & newmask) / newdivisor;
if(buffersort[current].mask != newmask) {
comparebuffer = current;
compareisdata = 0;
while(compareisdata == 0) {
comparevalue = buffersort[comparebuffer].firstptr;
compareisdata = buffersort[comparebuffer].lower[comparevalue].isdata;
comparebuffer = buffersort[comparebuffer].lower[comparevalue].ptr;
} // ENDWHILE- looking for an another buffer to compare to...
comparevalue = (bufferlist[comparebuffer].lsn & newmask) / newdivisor;
if(newvalue != comparevalue) {
// Add buffersort here (comparevalue/newvalue)
newbuffer = AllocSortBuffer();
buffersort[newbuffer].upptr = buffersort[current].upptr;
buffersort[newbuffer].uppos = buffersort[current].uppos;
buffersort[newbuffer].mask = newmask;
buffersort[newbuffer].divisor = newdivisor;
buffersort[newbuffer].lower[comparevalue].isdata = 0;
buffersort[newbuffer].lower[comparevalue].ptr = current;
buffersort[newbuffer].lower[newvalue].isdata = 1;
buffersort[newbuffer].lower[newvalue].ptr = bufnum;
buffersort[newbuffer].ptrcount = 2;
buffersort[newbuffer].firstptr = comparevalue;
if(newvalue < buffersort[newbuffer].firstptr)
buffersort[newbuffer].firstptr = newvalue;
if(buffersort[newbuffer].upptr == 0xffff) {
buffersortstart = newbuffer;
} else {
buffersort[prevbuffer].lower[prevvalue].isdata = 0;
buffersort[prevbuffer].lower[prevvalue].ptr = newbuffer;
if(prevvalue < buffersort[prevbuffer].firstptr)
buffersort[prevbuffer].firstptr = prevvalue;
} // ENDIF- Do we need to adjust to buffersortstart connection?
buffersort[current].upptr = newbuffer;
buffersort[current].uppos = comparevalue;
bufferlist[bufnum].upsort = newbuffer;
bufferlist[bufnum].uppos = newvalue;
return;
} // ENDIF- Don't match? Add a buffersort here to say that!
compareisdata = 0;
newmask /= 0x0100;
newdivisor /= 0x0100;
} else {
currentisdata = buffersort[current].lower[newvalue].isdata;
prevbuffer = current;
prevvalue = newvalue;
if(currentisdata == 0) {
current = buffersort[current].lower[newvalue].ptr;
newmask /= 0x0100;
newdivisor /= 0x0100;
if(newdivisor == 0) {
#ifdef VERBOSE_WARNINGS_BUFFER
PrintLog("CDVD buffer: Mask/Divisor at 0! Index corruption! (detected in search)");
#endif /* VERBOSE_WARNINGS_BUFFER */
return;
} // ENDIF- The Mask went too far! Abort! (Sanity Check)
} // ENDIF- Do we have to go through another level of sort data?
} // ENDIF- We don't have a comparison on this byte?
} // ENDWHILE- looking for his level...
if(buffersort[current].lower[newvalue].isdata == 2) {
buffersort[current].lower[newvalue].isdata = 1;
buffersort[current].lower[newvalue].ptr = bufnum;
buffersort[current].ptrcount++;
if(newvalue < buffersort[current].firstptr)
buffersort[current].firstptr = newvalue;
bufferlist[bufnum].upsort = current;
bufferlist[bufnum].uppos = newvalue;
return;
} // ENDIF- an empty slot? Fill it in.
comparebuffer = buffersort[current].lower[newvalue].ptr;
if(bufferlist[bufnum].lsn == bufferlist[comparebuffer].lsn) {
buffersort[current].lower[newvalue].ptr = bufnum;
bufferlist[bufnum].upsort = current;
bufferlist[bufnum].uppos = newvalue;
bufferlist[comparebuffer].upsort = 0xffff;
return;
} // ENDIF- Same LSN? Replace!
// Calc new position based on new separation markers...
newmask /= 0x0100;
newdivisor /= 0x0100;
if(newdivisor == 0) {
#ifdef VERBOSE_WARNINGS_BUFFER
PrintLog("CDVD buffer: Mask/Divisor at 0! Index corruption! (bottom add initial)");
#endif /* VERBOSE_WARNINGS_BUFFER */
return;
} // ENDIF- The Mask went too far! Abort! (Sanity Check)
newvalue = (bufferlist[bufnum].lsn & newmask) / newdivisor;
comparevalue = (bufferlist[comparebuffer].lsn & newmask) / newdivisor;
while((newmask != 0x000000ff) && (comparevalue == newvalue)) {
newmask /= 0x0100;
newdivisor /= 0x0100;
if(newdivisor == 0) {
#ifdef VERBOSE_WARNINGS_BUFFER
PrintLog("CDVD buffer: Mask/Divisor at 0! Index corruption! (bottom add loop)");
#endif /* VERBOSE_WARNINGS_BUFFER */
return;
} // ENDIF- The Mask went too far! Abort! (Sanity Check)
newvalue = (bufferlist[bufnum].lsn & newmask) / newdivisor;
comparevalue = (bufferlist[comparebuffer].lsn & newmask) / newdivisor;
} // ENDWHILE- continuing to scan for difference between the two numbers
newbuffer = AllocSortBuffer();
buffersort[newbuffer].upptr = prevbuffer;
buffersort[newbuffer].uppos = prevvalue;
buffersort[newbuffer].mask = newmask;
buffersort[newbuffer].divisor = newdivisor;
buffersort[newbuffer].lower[comparevalue].isdata = 1;
buffersort[newbuffer].lower[comparevalue].ptr = comparebuffer;
buffersort[newbuffer].lower[newvalue].isdata = 1;
buffersort[newbuffer].lower[newvalue].ptr = bufnum;
buffersort[newbuffer].ptrcount = 2;
buffersort[newbuffer].firstptr = comparevalue;
if(newvalue < buffersort[newbuffer].firstptr)
buffersort[newbuffer].firstptr = newvalue;
buffersort[prevbuffer].lower[prevvalue].isdata = 0;
buffersort[prevbuffer].lower[prevvalue].ptr = newbuffer;
bufferlist[comparebuffer].upsort = newbuffer;
bufferlist[comparebuffer].uppos = comparevalue;
bufferlist[bufnum].upsort = newbuffer;
bufferlist[bufnum].uppos = newvalue;
} // END AddListBuffer()
#ifdef VERBOSE_WARNINGS_BUFFER
void PrintSortBuffers() {
u16 h;
u16 i;
u16 j;
printf("CDVD buffer: Sort Buffer Dump\n");
printf("CDVD buffer: Top Pointer: isdata %u ptr %u\n",
buffersortstartisdata, buffersortstart);
for(i = 0; i < BUFFERMAX; i++) {
h = 0;
while((h < BUFFERMAX) && (buffersortempty[h].sortptr != i)) h++;
if(h == BUFFERMAX) {
printf("CDVD buffer: Sort Buffer:%u Mask:%x Divisor:%x\n",
i, buffersort[i].mask, buffersort[i].divisor);
printf("CDVD buffer: Up Ptr:%u Up Pos:%u First Down Ptr:%u Ptr Count: %u\n",
buffersort[i].upptr,
buffersort[i].uppos,
buffersort[i].firstptr,
buffersort[i].ptrcount);
printf("CDVD buffer: ");
for(j = 0; j < 256; j++) {
if(buffersort[i].lower[j].isdata == 1) printf(" D");
if(buffersort[i].lower[j].isdata == 0) printf(" L");
if(buffersort[i].lower[j].isdata < 2) {
printf("%u:%u", j, buffersort[i].lower[j].ptr);
} // ENDIF- We have active data? Print it.
} // NEXT j- Scanning lower 256 pointers for active ones...
printf("\n");
} // ENDIF- Not found in inactive list? Must be active! Print it.
} // NEXT i- looking at all the Allocated Buffers...
} // END PrintSortBuffers()
#endif /* VERBOSE_WARNINGS_BUFFER */

View File

@ -0,0 +1,67 @@
/* buffer.h
* Copyright (C) 2002-2005 CDVDlinuz Team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef __BUFFER_H__
#define __BUFFER_H__
#define CDVDdefs
#include "PS2Edefs.h"
// #define VERBOSE_FUNCTION_BUFFER
// #define VERBOSE_WARNINGS_BUFFER
// Remember, each buffer set is about 5k (packed. might be 4x that in-memory)
// Minimum: 16 Maximum: 32760
#define BUFFERMAX 256
// Buffer Structures
struct BufferList {
u16 upsort; // Don't alter this variable
u16 uppos; // Don't alter this variable
u32 lsn;
int mode; // -1 means error
u8 buffer[2368];
u8 offset;
cdvdSubQ subq;
};
// Exported Variables
extern struct BufferList bufferlist[];
extern u16 userbuffer;
extern u16 replacebuffer;
// Exported Functions
extern void InitBuffer();
extern u16 FindListBuffer(u32 lsn);
extern void RemoveListBuffer(u16 oldbuffer);
extern void AddListBuffer(u16 newbuffer);
#ifdef VERBOSE_WARNINGS_BUFFER
extern void PrintSortBuffers();
#endif /* VERBOSE_WARNINGS_BUFFER */
#endif /* __BUFFER_H__ */

View File

@ -0,0 +1,118 @@
/* convert.c
* Copyright (C) 2002-2005 PCSX2 Team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* PCSX2 members can be contacted through their website at www.pcsx2.net.
*/
#include <stddef.h>
#include <sys/types.h>
#include "convert.h"
off64_t ConvertEndianOffset(off64_t number) {
#ifndef CONVERTLITTLEENDIAN
union {
off64_t n;
char c[sizeof(off64_t)];
} oldnumber, newnumber;
int i;
oldnumber.n = number;
for(i = 0; i < sizeof(off64_t); i++)
newnumber.c[i] = oldnumber.c[sizeof(off64_t) - 1 - i];
return(newnumber.n);
#else
return(number);
#endif /* CONVERTLITTLEENDIAN */
} // END ConvertEndianOffset()
unsigned int ConvertEndianUInt(unsigned int number) {
#ifndef CONVERTLITTLEENDIAN
union {
unsigned int n;
char c[sizeof(unsigned int)];
} oldnumber, newnumber;
int i;
oldnumber.n = number;
for(i = 0; i < sizeof(unsigned int); i++)
newnumber.c[i] = oldnumber.c[sizeof(unsigned int) - 1 - i];
return(newnumber.n);
#else
return(number);
#endif /* CONVERTLITTLEENDIAN */
} // END ConvertEndianUInt()
unsigned short ConvertEndianUShort(unsigned short number) {
#ifndef CONVERTLITTLEENDIAN
union {
unsigned short n;
char c[sizeof(unsigned short)];
} oldnumber, newnumber;
int i;
oldnumber.n = number;
for(i = 0; i < sizeof(unsigned short); i++)
newnumber.c[i] = oldnumber.c[sizeof(unsigned short) - 1 - i];
return(newnumber.n);
#else
return(number);
#endif /* CONVERTLITTLEENDIAN */
} // END ConvertEndianUShort()
// Note: deposits M/S/F data in buffer[0]/[1]/[2] respectively.
void LBAtoMSF(unsigned long lsn, char *buffer) {
unsigned long templsn;
if(lsn >= 0xFFFFFFFF - 150) {
*(buffer + 2) = 75-1;
*(buffer + 1) = 60-1;
*(buffer) = 100-1;
} // ENDIF- Out of range?
templsn = lsn;
templsn += 150; // 2 second offset (75 Frames * 2 Seconds)
*(buffer + 2) = templsn % 75; // Remainder in frames
templsn -= *(buffer + 2);
templsn /= 75;
*(buffer + 1) = templsn % 60; // Remainder in seconds
templsn -= *(buffer + 1);
templsn /= 60;
*(buffer) = templsn; // Leftover quotient in minutes
} // END LBAtoMSF()
unsigned long MSFtoLBA(char *buffer) {
unsigned long templsn;
if(buffer == NULL) return(0xFFFFFFFF);
templsn = *(buffer); // Minutes
templsn *= 60;
templsn += *(buffer + 1); // Seconds
templsn *= 75;
templsn += *(buffer + 2); // Frames
if(templsn < 150) return(0xFFFFFFFF);
templsn -= 150; // Offset
return(templsn);
} // END MSFtoLBA()

View File

@ -0,0 +1,50 @@
/* convert.h
* Copyright (C) 2002-2005 PCSX2 Team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* PCSX2 members can be contacted through their website at www.pcsx2.net.
*/
#ifndef CONVERT_H
#define CONVERT_H
#include <sys/types.h> // off64_t
#ifdef __linux__
#include "endian.h"
#if __BYTE_ORDER == __LITTLE_ENDIAN
#define CONVERTLITTLEENDIAN
#endif /* __BYTE_ORDER */
#endif /* __linux__ */
#ifdef __WIN32__
#define CONVERTLITTLEENDIAN
#endif /* __WIN32__ */
#define HEXTOBCD(i) (((i)/10*16) + ((i)%10))
#define BCDTOHEX(i) (((i)/16*10) + ((i)%16))
extern off64_t ConvertEndianOffset(off64_t number);
extern unsigned int ConvertEndianUInt(unsigned int number);
extern unsigned short ConvertEndianUShort(unsigned short number);
extern void LBAtoMSF(unsigned long lsn, char *buffer);
extern unsigned long MSFtoLBA(char *buffer);
#endif /* CONVERT_H */

689
plugins/CDVDlinuz/Src/ini.c Normal file
View File

@ -0,0 +1,689 @@
/* ini.c
* Copyright (C) 2002-2005 PCSX2 Team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* PCSX2 members can be contacted through their website at www.pcsx2.net.
*/
#include <stddef.h> // NULL
#include <stdio.h> // sprintf()
#include "logfile.h"
#include "actualfile.h"
#include "ini.h"
const char INIext[] = ".ini";
const char INInewext[] = ".new";
// Returns: position where new extensions should be added.
int INIRemoveExt(char *argname, char *tempname) {
int i;
int j;
int k;
#ifdef VERBOSE_FUNCTION_INI
PrintLog("CDVDiso ini: RemoveExt(%s)", argname);
#endif /* VERBOSE_FUNCTION_INI */
i = 0;
while((i <= INIMAXLEN) && (*(argname + i) != 0)) {
*(tempname + i) = *(argname + i);
i++;
} // ENDWHILE- Copying the argument name into a temporary area;
*(tempname + i) = 0; // And 0-terminate
k = i;
k--;
j = 0;
while((j <= INIMAXLEN) && (INIext[j] != 0)) j++;
j--;
while((j >= 0) && (*(tempname + k) == INIext[j])) {
k--;
j--;
} // ENDWHILE- Comparing the ending characters to the INI ext.
if(j < 0) {
k++;
i = k;
*(tempname + i) = 0; // 0-terminate, cutting off ".ini"
} // ENDIF- Do we have a match? Then remove the end chars.
return(i);
} // END INIRemoveExt()
void INIAddInExt(char *tempname, int temppos) {
int i;
#ifdef VERBOSE_FUNCTION_INI
PrintLog("CDVDiso ini: AddInExt(%s, %i)", tempname, temppos);
#endif /* VERBOSE_FUNCTION_INI */
i = 0;
while((i + temppos < INIMAXLEN) && (INIext[i] != 0)) {
*(tempname + temppos + i) = INIext[i];
i++;
} // ENDWHILE- Attaching extenstion to filename
*(tempname + temppos + i) = 0; // And 0-terminate
} // END INIAddInExt()
void INIAddOutExt(char *tempname, int temppos) {
int i;
#ifdef VERBOSE_FUNCTION_INI
PrintLog("CDVDiso ini: AddOutExt(%s, %i)", tempname, temppos);
#endif /* VERBOSE_FUNCTION_INI */
i = 0;
while((i + temppos < INIMAXLEN) && (INInewext[i] != 0)) {
*(tempname + temppos + i) = INInewext[i];
i++;
} // ENDWHILE- Attaching extenstion to filename
*(tempname + temppos + i) = 0; // And 0-terminate
} // END INIAddInExt()
// Returns number of bytes read to get line (0 means end-of-file)
int INIReadLine(ACTUALHANDLE infile, char *buffer) {
int charcount;
int i;
char tempin[2];
int retflag;
int retval;
#ifdef VERBOSE_FUNCTION_INI
PrintLog("CDVDiso ini: ReadLine()");
#endif /* VERBOSE_FUNCTION_INI */
charcount = 0;
i = 0;
tempin[1] = 0;
retflag = 0;
while((i < INIMAXLEN) && (retflag < 2)) {
retval = ActualFileRead(infile, 1, tempin);
charcount++;
if(retval != 1) {
retflag = 2;
charcount--;
} else if(tempin[0] == '\n') {
retflag = 2;
} else if(tempin[0] >= ' ') {
*(buffer + i) = tempin[0];
i++;
} // ENDLONGIF- How do we react to the next character?
} // ENDWHILE- Loading up on characters until an End-of-Line appears
*(buffer + i) = 0; // And 0-terminate
#ifdef VERBOSE_FUNCTION_INI
PrintLog("CDVDiso ini: Line: %s", buffer);
#endif /* VERBOSE_FUNCTION_INI */
return(charcount);
} // END INIReadLine()
// Note: Do we need to back-skip a char if something other \n follows \r?
// Returns: number of bytes to get to start of section (or -1)
int INIFindSection(ACTUALHANDLE infile, char *section) {
int charcount;
int i;
int retflag;
int retval;
char scanbuffer[INIMAXLEN+1];
#ifdef VERBOSE_FUNCTION_INI
PrintLog("CDVDiso ini: FindSection(%s)", section);
#endif /* VERBOSE_FUNCTION_INI */
charcount = 0;
retflag = 0;
while(retflag == 0) {
retval = INIReadLine(infile, scanbuffer);
if(retval == 0) return(-1); // EOF? Stop here.
if(scanbuffer[0] == '[') {
i = 0;
while((i < INIMAXLEN) &&
(*(section + i) != 0) &&
(*(section + i) == scanbuffer[i + 1])) i++;
if((i < INIMAXLEN - 2) && (*(section + i) == 0)) {
if((scanbuffer[i + 1] == ']') && (scanbuffer[i + 2] == 0)) {
retflag = 1;
} // ENDIF- End marks look good? Return successful.
} // ENDIF- Do we have a section match?
} // ENDIF- Does this look like a section header?
if(retflag == 0) charcount += retval;
} // ENDWHILE- Scanning lines for the correct [Section] header.
return(charcount);
} // END INIFindSection()
// Returns: number of bytes to get to start of keyword (or -1)
int INIFindKeyword(ACTUALHANDLE infile, char *keyword, char *buffer) {
int charcount;
int i;
int j;
int retflag;
int retval;
char scanbuffer[INIMAXLEN+1];
#ifdef VERBOSE_FUNCTION_INI
PrintLog("CDVDiso ini: FindKeyword(%s)", keyword);
#endif /* VERBOSE_FUNCTION_INI */
charcount = 0;
retflag = 0;
while(retflag == 0) {
retval = INIReadLine(infile, scanbuffer);
if(retval == 0) return(-1); // EOF? Stop here.
if(scanbuffer[0] == '[') return(-1); // New section? Stop here.
i = 0;
while((i < INIMAXLEN) &&
(*(keyword + i) != 0) &&
(*(keyword + i) == scanbuffer[i])) i++;
if((i < INIMAXLEN - 2) && (*(keyword + i) == 0)) {
if(scanbuffer[i] == '=') {
retflag = 1;
if(buffer != NULL) {
i++;
j = 0;
while((i < INIMAXLEN) && (scanbuffer[i] != 0)) {
*(buffer + j) = scanbuffer[i];
i++;
j++;
} // ENDWHILE- Copying the value out to the outbound buffer.
*(buffer + j) = 0; // And 0-terminate.
} // ENDIF- Return the value as well?
} // ENDIF- End marks look good? Return successful.
} // ENDIF- Do we have a section match?
if(retflag == 0) charcount += retval;
} // ENDWHILE- Scanning lines for the correct [Section] header.
#ifdef VERBOSE_FUNCTION_INI
PrintLog("CDVDiso ini: Value: %s", buffer);
#endif /* VERBOSE_FUNCTION_INI */
return(charcount);
} // END INIFindKeyWord()
// Returns: number of bytes left to write... (from charcount back)
int INICopy(ACTUALHANDLE infile, ACTUALHANDLE outfile, int charcount) {
char buffer[4096];
int i;
int chunk;
int retval;
#ifdef VERBOSE_FUNCTION_INI
PrintLog("CDVDiso ini: Copy(%i)", charcount);
#endif /* VERBOSE_FUNCTION_INI */
i = charcount;
chunk = 4096;
if(i < chunk) chunk = i;
while(chunk > 0) {
retval = ActualFileRead(infile, chunk, buffer);
if(retval <= 0) return(i); // Trouble? Stop here.
if(retval < chunk) chunk = retval; // Short block? Note it.
retval = ActualFileWrite(outfile, chunk, buffer);
if(retval <= 0) return(i); // Trouble? Stop here.
i -= retval;
if(retval < chunk) return(i); // Short block written? Stop here.
chunk = 4096;
if(i < chunk) chunk = i;
} // ENDWHILE- Copying a section of file across, one chunk at a time.
return(0);
} // END INICopyToPos()
int INISaveString(char *file, char *section, char *keyword, char *value) {
char inname[INIMAXLEN+1];
char outname[INIMAXLEN+1];
int filepos;
ACTUALHANDLE infile;
ACTUALHANDLE outfile;
int i;
int retval;
char templine[INIMAXLEN+1];
if(file == NULL) return(-1);
if(section == NULL) return(-1);
if(keyword == NULL) return(-1);
if(value == NULL) return(-1);
#ifdef VERBOSE_FUNCTION_INI
PrintLog("CDVDiso ini: SaveString(%s, %s, %s, %s)",
file, section, keyword, value);
#endif /* VERBOSE_FUNCTION_INI */
filepos = INIRemoveExt(file, inname);
for(i = 0; i <= filepos; i++) outname[i] = inname[i];
INIAddInExt(inname, filepos);
INIAddOutExt(outname, filepos);
filepos = 0;
infile = ActualFileOpenForRead(inname);
if(infile == ACTUALHANDLENULL) {
#ifdef VERBOSE_FUNCTION_INI
PrintLog("CDVDiso ini: creating new file");
#endif /* VERBOSE_FUNCTION_INI */
outfile = ActualFileOpenForWrite(inname);
if(outfile == ACTUALHANDLENULL) return(-1); // Just a bad name? Abort.
sprintf(templine, "[%s]\r\n", section);
i = 0;
while((i < INIMAXLEN) && (templine[i] != 0)) i++;
retval = ActualFileWrite(outfile, i, templine);
if(retval < i) {
ActualFileClose(outfile);
outfile = ACTUALHANDLENULL;
ActualFileDelete(inname);
return(-1);
} // ENDIF- Trouble writing it out? Abort.
sprintf(templine, "%s=%s\r\n", keyword, value);
i = 0;
while((i < INIMAXLEN) && (templine[i] != 0)) i++;
retval = ActualFileWrite(outfile, i, templine);
ActualFileClose(outfile);
outfile = ACTUALHANDLENULL;
if(retval < i) {
ActualFileDelete(inname);
return(-1);
} // ENDIF- Trouble writing it out? Abort.
return(0);
} // ENDIF- No input file? Create a brand new .ini file then.
retval = INIFindSection(infile, section);
if(retval < 0) {
#ifdef VERBOSE_FUNCTION_INI
PrintLog("CDVDiso ini: creating new section");
#endif /* VERBOSE_FUNCTION_INI */
outfile = ActualFileOpenForWrite(outname);
if(outfile == ACTUALHANDLENULL) {
ActualFileClose(infile);
infile = ACTUALHANDLENULL;
return(-1);
} // ENDIF- Couldn't open a temp file? Abort
ActualFileSeek(infile, 0); // Move ini to beginning of file...
INICopy(infile, outfile, 0x0FFFFFFF); // Copy the whole file out...
sprintf(templine, "\r\n[%s]\r\n", section);
i = 0;
while((i < INIMAXLEN) && (templine[i] != 0)) i++;
retval = ActualFileWrite(outfile, i, templine);
if(retval < i) {
ActualFileClose(infile);
infile = ACTUALHANDLENULL;
ActualFileClose(outfile);
outfile = ACTUALHANDLENULL;
ActualFileDelete(outname);
return(-1);
} // ENDIF- Trouble writing it out? Abort.
sprintf(templine, "%s=%s\r\n", keyword, value);
i = 0;
while((i < INIMAXLEN) && (templine[i] != 0)) i++;
retval = ActualFileWrite(outfile, i, templine);
ActualFileClose(infile);
infile = ACTUALHANDLENULL;
ActualFileClose(outfile);
outfile = ACTUALHANDLENULL;
if(retval < i) {
ActualFileDelete(outname);
return(-1);
} // ENDIF- Trouble writing it out? Abort.
ActualFileDelete(inname);
ActualFileRename(outname, inname);
return(0);
} // ENDIF- Couldn't find the section? Make a new one!
filepos = retval;
ActualFileSeek(infile, filepos);
filepos += INIReadLine(infile, templine); // Get section line's byte count
retval = INIFindKeyword(infile, keyword, NULL);
if(retval < 0) {
#ifdef VERBOSE_FUNCTION_INI
PrintLog("CDVDiso ini: creating new keyword");
#endif /* VERBOSE_FUNCTION_INI */
ActualFileSeek(infile, filepos);
retval = INIReadLine(infile, templine);
i = 0;
while((i < INIMAXLEN) && (templine[i] != 0) && (templine[i] != '=')) i++;
while((retval > 0) && (templine[i] == '=')) {
filepos += retval;
retval = INIReadLine(infile, templine);
i = 0;
while((i < INIMAXLEN) && (templine[i] != 0) && (templine[i] != '=')) i++;
} // ENDWHILE- skimming to the bottom of the section
outfile = ActualFileOpenForWrite(outname);
if(outfile == ACTUALHANDLENULL) {
ActualFileClose(infile);
infile = ACTUALHANDLENULL;
return(-1);
} // ENDIF- Couldn't open a temp file? Abort
ActualFileSeek(infile, 0);
retval = INICopy(infile, outfile, filepos);
if(retval > 0) {
ActualFileClose(infile);
infile = ACTUALHANDLENULL;
ActualFileClose(outfile);
outfile = ACTUALHANDLENULL;
ActualFileDelete(outname);
return(-1);
} // ENDIF- Trouble writing everything up to keyword? Abort.
sprintf(templine, "%s=%s\r\n", keyword, value);
i = 0;
while((i < INIMAXLEN) && (templine[i] != 0)) i++;
retval = ActualFileWrite(outfile, i, templine);
if(retval < i) {
ActualFileClose(infile);
infile = ACTUALHANDLENULL;
ActualFileClose(outfile);
outfile = ACTUALHANDLENULL;
ActualFileDelete(outname);
return(-1);
} // ENDIF- Trouble writing it out? Abort.
} else {
#ifdef VERBOSE_FUNCTION_INI
PrintLog("CDVDiso ini: replacing keyword");
#endif /* VERBOSE_FUNCTION_INI */
filepos += retval; // Position just before old version of keyword
outfile = ActualFileOpenForWrite(outname);
if(outfile == ACTUALHANDLENULL) {
ActualFileClose(infile);
infile = ACTUALHANDLENULL;
return(-1);
} // ENDIF- Couldn't open a temp file? Abort
ActualFileSeek(infile, 0);
retval = INICopy(infile, outfile, filepos);
if(retval > 0) {
ActualFileClose(infile);
infile = ACTUALHANDLENULL;
ActualFileClose(outfile);
outfile = ACTUALHANDLENULL;
ActualFileDelete(outname);
return(-1);
} // ENDIF- Trouble writing everything up to keyword? Abort.
INIReadLine(infile, templine); // Read past old keyword/value...
// Replace with new value
sprintf(templine, "%s=%s\r\n", keyword, value);
i = 0;
while((i < INIMAXLEN) && (templine[i] != 0)) i++;
retval = ActualFileWrite(outfile, i, templine);
if(retval < i) {
ActualFileClose(infile);
infile = ACTUALHANDLENULL;
ActualFileClose(outfile);
outfile = ACTUALHANDLENULL;
ActualFileDelete(outname);
return(-1);
} // ENDIF- Trouble writing it out? Abort.
} // ENDIF- Need to add a new keyword?
INICopy(infile, outfile, 0xFFFFFFF); // Write out rest of file
ActualFileClose(infile);
infile = ACTUALHANDLENULL;
ActualFileClose(outfile);
outfile = ACTUALHANDLENULL;
ActualFileDelete(inname);
ActualFileRename(outname, inname);
return(0);
} // END INISaveString()
int INILoadString(char *file, char *section, char *keyword, char *buffer) {
char inname[INIMAXLEN+1];
int filepos;
ACTUALHANDLE infile;
int retval;
if(file == NULL) return(-1);
if(section == NULL) return(-1);
if(keyword == NULL) return(-1);
if(buffer == NULL) return(-1);
#ifdef VERBOSE_FUNCTION_INI
PrintLog("CDVDiso ini: LoadString(%s, %s, %s)",
file, section, keyword);
#endif /* VERBOSE_FUNCTION_INI */
filepos = INIRemoveExt(file, inname);
INIAddInExt(inname, filepos);
filepos = 0;
infile = ActualFileOpenForRead(inname);
if(infile == ACTUALHANDLENULL) return(-1);
retval = INIFindSection(infile, section);
if(retval < 0) {
ActualFileClose(infile);
infile = ACTUALHANDLENULL;
return(-1);
} // ENDIF- Didn't find it? Abort.
retval = INIFindKeyword(infile, keyword, buffer);
if(retval < 0) {
ActualFileClose(infile);
infile = ACTUALHANDLENULL;
return(-1);
} // ENDIF- Didn't find it? Abort.
ActualFileClose(infile);
infile = ACTUALHANDLENULL;
return(0);
} // END INILoadString()
int INIRemove(char *file, char *section, char *keyword) {
char inname[INIMAXLEN+1];
char outname[INIMAXLEN+1];
int filepos;
ACTUALHANDLE infile;
ACTUALHANDLE outfile;
char templine[INIMAXLEN+1];
int i;
int retval;
if(file == NULL) return(-1);
if(section == NULL) return(-1);
#ifdef VERBOSE_FUNCTION_INI
PrintLog("CDVDiso ini: Remove(%s, %s, %s)",
file, section, keyword);
#endif /* VERBOSE_FUNCTION_INI */
filepos = INIRemoveExt(file, inname);
for(i = 0; i <= filepos; i++) outname[i] = inname[i];
INIAddInExt(inname, filepos);
INIAddOutExt(outname, filepos);
infile = ActualFileOpenForRead(inname);
if(infile == ACTUALHANDLENULL) return(-1);
retval = INIFindSection(infile, section);
if(retval == -1) {
ActualFileClose(infile);
infile = ACTUALHANDLENULL;
return(-1);
} // ENDIF- Couldn't even find the section? Abort
filepos = retval;
if(keyword == NULL) {
#ifdef VERBOSE_FUNCTION_INI
PrintLog("CDVDiso ini: removing section");
#endif /* VERBOSE_FUNCTION_INI */
outfile = ActualFileOpenForWrite(outname);
if(outfile == ACTUALHANDLENULL) {
ActualFileClose(infile);
infile = ACTUALHANDLENULL;
return(-1);
} // ENDIF- Couldn't open a temp file? Abort
ActualFileSeek(infile, 0);
retval = INICopy(infile, outfile, filepos);
if(retval > 0) {
ActualFileClose(infile);
infile = ACTUALHANDLENULL;
ActualFileClose(outfile);
outfile = ACTUALHANDLENULL;
ActualFileDelete(outname);
return(-1);
} // ENDIF- Trouble writing everything up to the section? Abort.
templine[0] = 0;
retval = 1;
while((retval > 0) && (templine[0] != '[')) {
retval = INIReadLine(infile, templine);
} // ENDWHILE- Read to the start of the next section... or EOF.
if(templine[0] == '[') {
i = 0;
while((i < INIMAXLEN) && (templine[i] != 0)) i++;
retval = ActualFileWrite(outfile, i, templine);
if(retval < i) {
ActualFileClose(infile);
infile = ACTUALHANDLENULL;
ActualFileClose(outfile);
outfile = ACTUALHANDLENULL;
ActualFileDelete(outname);
return(-1);
} // ENDIF- Trouble writing it out? Abort.
} // ENDIF- Are there other sections after this one? Save them then.
} else {
filepos = retval;
ActualFileSeek(infile, filepos);
filepos += INIReadLine(infile, templine); // Get section line's byte count
retval = INIFindKeyword(infile, keyword, NULL);
if(retval == -1) {
ActualFileClose(infile);
infile = ACTUALHANDLENULL;
return(-1);
} // ENDIF- Couldn't find the keyword? Abort
filepos += retval;
#ifdef VERBOSE_FUNCTION_INI
PrintLog("CDVDiso ini: removing keyword");
#endif /* VERBOSE_FUNCTION_INI */
outfile = ActualFileOpenForWrite(outname);
if(outfile == ACTUALHANDLENULL) {
ActualFileClose(infile);
infile = ACTUALHANDLENULL;
return(-1);
} // ENDIF- Couldn't open a temp file? Abort
ActualFileSeek(infile, 0);
retval = INICopy(infile, outfile, filepos);
if(retval > 0) {
ActualFileClose(infile);
infile = ACTUALHANDLENULL;
ActualFileClose(outfile);
outfile = ACTUALHANDLENULL;
ActualFileDelete(outname);
return(-1);
} // ENDIF- Trouble writing everything up to keyword? Abort.
INIReadLine(infile, templine); // Read (and discard) the keyword line
} // ENDIF- Wipe out the whole section? Or just a keyword?
INICopy(infile, outfile, 0xFFFFFFF); // Write out rest of file
ActualFileClose(infile);
infile = ACTUALHANDLENULL;
ActualFileClose(outfile);
outfile = ACTUALHANDLENULL;
ActualFileDelete(inname);
ActualFileRename(outname, inname);
return(0);
} // END INIRemove()
int INISaveUInt(char *file, char *section, char *keyword, unsigned int value) {
char numvalue[INIMAXLEN+1];
sprintf(numvalue, "%u", value);
return(INISaveString(file, section, keyword, numvalue));
} // END INISaveUInt()
int INILoadUInt(char *file, char *section, char *keyword, unsigned int *buffer) {
char numvalue[INIMAXLEN+1];
int retval;
unsigned int value;
// unsigned int sign; // Not needed in unsigned numbers
int pos;
if(buffer == NULL) return(-1);
*(buffer) = 0;
retval = INILoadString(file, section, keyword, numvalue);
if(retval < 0) return(retval);
value = 0;
// sign = 1; // Start positive
pos = 0;
// Note: skip leading spaces? (Shouldn't have to, I hope)
// if(numvalue[pos] == '-') {
// pos++;
// sign = -1;
// } // ENDIF- Negative sign check
while((pos < INIMAXLEN) && (numvalue[pos] != 0)) {
if(value > (0xFFFFFFFF / 10)) return(-1); // Overflow?
if((numvalue[pos] >= '0') && (numvalue[pos] <= '9')) {
value *= 10;
value += numvalue[pos] - '0';
pos++;
} else {
numvalue[pos] = 0;
} // ENDIF- Add a digit in? Or stop searching for digits?
} // ENDWHILE- Adding digits of info to our ever-increasing value
// value *= sign
*(buffer) = value;
return(0);
} // END INILoadUInt()

View File

@ -0,0 +1,64 @@
/* ini.h
* Copyright (C) 2002-2005 PCSX2 Team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* PCSX2 members can be contacted through their website at www.pcsx2.net.
*/
#ifndef INI_H
#define INI_H
// #ifndef __LINUX__
// #ifdef __linux__
// #define __LINUX__
// #endif /* __linux__ */
// #endif /* No __LINUX__ */
// #define CDVDdefs
// #include "PS2Edefs.h"
// File format:
// [section]
// keyword=value
// file - Name of the INI file
// section - Section within the file
// keyword - Identifier for a value
// value - value to store with a keyword in a section in the file
// buffer - place to retrieve the value of a keyword
// return values: 0 = success, -1 = failure
// #define VERBOSE_FUNCTION_INI
#define INIMAXLEN 255
extern int INISaveString(char *file, char *section, char *keyword, char *value);
extern int INILoadString(char *file, char *section, char *keyword, char *buffer);
extern int INISaveUInt(char *file, char *section, char *keyword, unsigned int value);
extern int INILoadUInt(char *file, char *section, char *keyword, unsigned int *buffer);
// NULL in the keyword below removes the whole section.
extern int INIRemove(char *file, char *section, char *keyword);
#endif /* INI_H */

View File

@ -0,0 +1,36 @@
/* version.c
* Copyright (C) 2002-2005 PCSX2 Team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* PCSX2 members can be contacted through their website at www.pcsx2.net.
*/
#ifndef __LINUX__
#ifdef __linux__
#define __LINUX__
#endif /* __linux__ */
#endif /* No __LINUX__ */
#define CDVDdefs
#include "PS2Edefs.h"
char *libname = "EFP polling CDVD Driver";
const unsigned char version = PS2E_CDVD_VERSION;
const unsigned char revision = 0;
const unsigned char build = 4;

View File

@ -0,0 +1,43 @@
/* version.h
* Copyright (C) 2002-2005 PCSX2 Team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* PCSX2 members can be contacted through their website at www.pcsx2.net.
*/
#ifndef VERSION_H
#define VERSION_H
#ifndef __LINUX__
#ifdef __linux__
#define __LINUX__
#endif /* __linux__ */
#endif /* No __LINUX__ */
#define CDVDdefs
#include "PS2Edefs.h"
extern char *libname;
extern const unsigned char version;
extern const unsigned char revision;
extern const unsigned char build;
#endif /* VERSION_H */

View File

@ -0,0 +1,16 @@
#!/bin/sh
curdir=`pwd`
echo ------------------
echo Building CDVDlinuz
echo ------------------
cd ${curdir}/Src/Linux
make $@
if [ -s cfgCDVDlinuz ] && [ -s libCDVDlinuz.so ]
then
# copy the files
cp cfgCDVDlinuz libCDVDlinuz.so ${PCSX2PLUGINS}
fi

View File

@ -0,0 +1,37 @@
CDVDlinuz v0.4
--------------
This is an extension to use with play station2 emulators
as PCSX2 (only one right now).
The plugin is free open source code.
Modified by efp to work with DVDs as well
To install in Windows:
-----
Place the file "CDVDlinuz.dll" in the "plugins" directory.
To install in Linux:
-----
Place the file "libCDVDlinuz.so" in the "plugins/" directory.
Place the file "cfgCDVDlinuz" in the "cfg/" directory.
To activate in PCSX2:
-----
Start up PCSX2.
Select "Configuration", then "Plugins and Bios".
In the "Cdvdrom" pull-down menu, you should see:
"EFP polling CDVD Driver v.04"
Select it.
Then press the "Configure" button under it.
In the "CDVDlinuz Configuration" screen, type in where your CD or DVD
device can be found.
(In Linux, devices look like "/dev/<device>")
(In Windows, devices look like "D:". There are other types of references to
devices, but they haven't been tested.)
Press to "OK" button to save your selection.
Finally, put a CD or DVD in the selected drive, and run PCSX2.
Keep in mind the above instructions only cover the "CD/DVD" portion of
PCSX2. All configuration options must be attended to before PCSX2 could run
correctly.