PCem

changeset 128:42d0b879eb9e

Implemented ATAPI Read CD-ROM Capacity command, fixes CD usage in OS/2.
author TomW
date Sat Jul 12 14:22:54 2014 +0100
parents aa5d4fdaceb6
children 614f796ff7ed
files src/cdrom-ioctl.c src/ide.c src/ide.h
diffstat 3 files changed, 40 insertions(+), 0 deletions(-) [+]
line diff
     1.1 --- a/src/cdrom-ioctl.c	Fri Jul 11 21:00:43 2014 +0100
     1.2 +++ b/src/cdrom-ioctl.c	Sat Jul 12 14:22:54 2014 +0100
     1.3 @@ -18,6 +18,7 @@
     1.4  } CDROM_TOC_SESSION_DATA, *PCDROM_TOC_SESSION_DATA;
     1.5  static ATAPI ioctl_atapi;
     1.6  
     1.7 +static uint32_t last_block = 0;
     1.8  static int ioctl_inited = 0;
     1.9  static char ioctl_path[8];
    1.10  static void ioctl_close(void);
    1.11 @@ -383,14 +384,20 @@
    1.12                  }
    1.13          }
    1.14          b[2]=toc.TrackData[c].TrackNumber;
    1.15 +        last_block = 0;
    1.16          for (c=d;c<=toc.LastTrack;c++)
    1.17          {
    1.18 +                uint32_t address;
    1.19                  if ((len+8)>maxlen) break;
    1.20  //                pclog("Len %i max %i Track %02X - %02X %02X %i %i %i %i %08X\n",len,maxlen,toc.TrackData[c].TrackNumber,toc.TrackData[c].Adr,toc.TrackData[c].Control,toc.TrackData[c].Address[0],toc.TrackData[c].Address[1],toc.TrackData[c].Address[2],toc.TrackData[c].Address[3],MSFtoLBA(toc.TrackData[c].Address[1],toc.TrackData[c].Address[2],toc.TrackData[c].Address[3]));
    1.21                  b[len++]=0; /*Reserved*/
    1.22                  b[len++]=(toc.TrackData[c].Adr<<4)|toc.TrackData[c].Control;
    1.23                  b[len++]=toc.TrackData[c].TrackNumber;
    1.24                  b[len++]=0; /*Reserved*/
    1.25 +                address = MSFtoLBA(toc.TrackData[c].Address[1],toc.TrackData[c].Address[2],toc.TrackData[c].Address[3]);
    1.26 +                if (address > last_block)
    1.27 +                        last_block = address;
    1.28 +
    1.29                  if (msf)
    1.30                  {
    1.31                          b[len++]=toc.TrackData[c].Address[0];
    1.32 @@ -461,6 +468,15 @@
    1.33                  }
    1.34  }
    1.35  
    1.36 +static uint32_t ioctl_size()
    1.37 +{
    1.38 +        unsigned char b[4096];
    1.39 +
    1.40 +        atapi->readtoc(b, 0, 0, 4096, 0);
    1.41 +        
    1.42 +        return last_block;
    1.43 +}
    1.44 +
    1.45  int ioctl_open(char d)
    1.46  {
    1.47  //        char s[8];
    1.48 @@ -510,6 +526,7 @@
    1.49          ioctl_eject,
    1.50          ioctl_pause,
    1.51          ioctl_resume,
    1.52 +        ioctl_size,
    1.53          ioctl_stop,
    1.54          ioctl_exit
    1.55  };
     2.1 --- a/src/ide.c	Fri Jul 11 21:00:43 2014 +0100
     2.2 +++ b/src/ide.c	Sat Jul 12 14:22:54 2014 +0100
     2.3 @@ -71,6 +71,7 @@
     2.4  #define GPCMD_PREVENT_REMOVAL           0x1e
     2.5  #define GPCMD_READ_10                   0x28
     2.6  #define GPCMD_READ_CD			0xbe
     2.7 +#define GPCMD_READ_CDROM_CAPACITY	0x25
     2.8  #define GPCMD_READ_HEADER		0x44
     2.9  #define GPCMD_READ_SUBCHANNEL		0x42
    2.10  #define GPCMD_READ_TOC_PMA_ATIP		0x43
    2.11 @@ -1553,6 +1554,7 @@
    2.12          int msf;
    2.13          int pos=0;
    2.14          unsigned char temp;
    2.15 +        uint32_t size;
    2.16  #ifndef RPCEMU_IDE
    2.17          pclog("New ATAPI command %02X %i\n",idebufferb[0],ins);
    2.18  #endif
    2.19 @@ -1957,6 +1959,26 @@
    2.20                  idecallback[ide_board]=50*IDE_TIME;
    2.21                  break;
    2.22  
    2.23 +        case GPCMD_READ_CDROM_CAPACITY:
    2.24 +                if (!atapi->ready()) { atapi_notready(ide); return; }
    2.25 +                size = atapi->size();
    2.26 +                idebufferb[0] = (size >> 24) & 0xff;
    2.27 +                idebufferb[1] = (size >> 16) & 0xff;
    2.28 +                idebufferb[2] = (size >> 8) & 0xff;
    2.29 +                idebufferb[3] = size & 0xff;
    2.30 +                idebufferb[4] = (2048 >> 24) & 0xff;
    2.31 +                idebufferb[5] = (2048 >> 16) & 0xff;
    2.32 +                idebufferb[6] = (2048 >> 8) & 0xff;
    2.33 +                idebufferb[7] = 2048 & 0xff;
    2.34 +                len=8;
    2.35 +                ide->packetstatus=3;
    2.36 +                ide->cylinder=len;
    2.37 +                ide->secount=2;
    2.38 +                ide->pos=0;
    2.39 +                idecallback[ide_board]=60*IDE_TIME;
    2.40 +                ide->packlen=len;
    2.41 +                break;
    2.42 +                
    2.43          case GPCMD_SEND_DVD_STRUCTURE:
    2.44          default:
    2.45                  ide->atastat = READY_STAT | ERR_STAT;    /*CHECK CONDITION*/
     3.1 --- a/src/ide.h	Fri Jul 11 21:00:43 2014 +0100
     3.2 +++ b/src/ide.h	Sat Jul 12 14:22:54 2014 +0100
     3.3 @@ -30,6 +30,7 @@
     3.4          void (*eject)(void);
     3.5          void (*pause)(void);
     3.6          void (*resume)(void);
     3.7 +        uint32_t (*size)(void);
     3.8          void (*stop)(void);
     3.9          void (*exit)(void);
    3.10  } ATAPI;