~ubuntu-branches/debian/sid/mame/sid

« back to all changes in this revision

Viewing changes to src/emu/machine/nscsi_cd.c

  • Committer: Package Import Robot
  • Author(s): Jordi Mallach, Emmanuel Kasper, Jordi Mallach
  • Date: 2012-06-05 20:02:23 UTC
  • mfrom: (0.3.1) (0.1.4)
  • Revision ID: package-import@ubuntu.com-20120605200223-gnlpogjrg6oqe9md
Tags: 0.146-1
[ Emmanuel Kasper ]
* New upstream release
* Drop patch to fix man pages section and patches to link with flac 
  and jpeg system lib: all this has been pushed upstream by Cesare Falco
* Add DM-Upload-Allowed: yes field.

[ Jordi Mallach ]
* Create a "gnu" TARGETOS stanza that defines NO_AFFINITY_NP.
* Stop setting TARGETOS to "unix" in d/rules. It should be autodetected,
  and set to the appropriate value.
* mame_manpage_section.patch: Change mame's manpage section to 6 (games),
  in the TH declaration.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include "machine/nscsi_cd.h"
 
2
#include "imagedev/chd_cd.h"
 
3
 
 
4
const device_type NSCSI_CDROM = &device_creator<nscsi_cdrom_device>;
 
5
 
 
6
nscsi_cdrom_device::nscsi_cdrom_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) :
 
7
        nscsi_full_device(mconfig, NSCSI_CDROM, "SCSI CDROM", tag, owner, clock)
 
8
{
 
9
}
 
10
 
 
11
void nscsi_cdrom_device::device_start()
 
12
{
 
13
        nscsi_full_device::device_start();
 
14
        bytes_per_sector = 2048;
 
15
}
 
16
 
 
17
void nscsi_cdrom_device::device_reset()
 
18
{
 
19
        nscsi_full_device::device_reset();
 
20
        cdrom = subdevice<cdrom_image_device>("image")->get_cdrom_file();
 
21
        lba = 0;
 
22
        blocks = 0;
 
23
        cur_lba = -1;
 
24
}
 
25
 
 
26
cdrom_interface nscsi_cdrom_device::cd_intf = { 0, 0 };
 
27
 
 
28
static MACHINE_CONFIG_FRAGMENT(scsi_cdrom)
 
29
        MCFG_CDROM_ADD("image", nscsi_cdrom_device::cd_intf)
 
30
MACHINE_CONFIG_END
 
31
 
 
32
machine_config_constructor nscsi_cdrom_device::device_mconfig_additions() const
 
33
{
 
34
        return MACHINE_CONFIG_NAME(scsi_cdrom);
 
35
}
 
36
 
 
37
UINT8 nscsi_cdrom_device::scsi_get_data(int id, int pos)
 
38
{
 
39
        if(id != 2)
 
40
                return nscsi_full_device::scsi_get_data(id, pos);
 
41
        int clba = lba + pos / bytes_per_sector;
 
42
        if(clba != cur_lba) {
 
43
                cur_lba = clba;
 
44
                if(!cdrom_read_data(cdrom, cur_lba, block, CD_TRACK_MODE1)) {
 
45
                        logerror("%s: CD READ ERROR !\n", tag());
 
46
                        memset(block, 0, sizeof(block));
 
47
                }
 
48
        }
 
49
        return block[pos & (bytes_per_sector - 1)];
 
50
}
 
51
 
 
52
void nscsi_cdrom_device::scsi_command()
 
53
{
 
54
        switch(scsi_cmdbuf[0]) {
 
55
        case SC_TEST_UNIT_READY:
 
56
                logerror("%s: command TEST UNIT READY\n", tag());
 
57
                scsi_status_complete(SS_GOOD);
 
58
                break;
 
59
 
 
60
        case SC_READ:
 
61
                lba = ((scsi_cmdbuf[1] & 0x1f)<<16) | (scsi_cmdbuf[2]<<8) | scsi_cmdbuf[3];
 
62
                blocks = scsi_cmdbuf[4];
 
63
                if(!blocks)
 
64
                        blocks = 256;
 
65
 
 
66
                logerror("%s: command READ start=%08x blocks=%04x\n",
 
67
                                 tag(), lba, blocks);
 
68
 
 
69
                scsi_data_in(2, blocks*bytes_per_sector);
 
70
                scsi_status_complete(SS_GOOD);
 
71
                break;
 
72
 
 
73
        case SC_INQUIRY: {
 
74
                int lun = get_lun(scsi_cmdbuf[1] >> 5);
 
75
                logerror("%s: command INQUIRY lun=%d EVPD=%d page=%d alloc=%02x link=%02x\n",
 
76
                                 tag(),
 
77
                                 lun, scsi_cmdbuf[1] & 1, scsi_cmdbuf[2], scsi_cmdbuf[4], scsi_cmdbuf[5]);
 
78
                if(lun) {
 
79
                        bad_lun();
 
80
                        return;
 
81
                }
 
82
 
 
83
                int page = scsi_cmdbuf[2];
 
84
                int size = scsi_cmdbuf[4];
 
85
                switch(page) {
 
86
                case 0:
 
87
                        memset(scsi_cmdbuf, 0, 148);
 
88
                        scsi_cmdbuf[0] = 0x05; // device is present, device is CD/DVD (MMC-3)
 
89
                        scsi_cmdbuf[1] = 0x80; // media is removable
 
90
                        scsi_cmdbuf[2] = 0x05; // device complies with SPC-3 standard
 
91
                        scsi_cmdbuf[3] = 0x02; // response data format = SPC-3 standard
 
92
                        // some Konami games freak out if this isn't "Sony", so we'll lie
 
93
                        // this is the actual drive on my Nagano '98 board
 
94
                        strcpy((char *)&scsi_cmdbuf[8], "Sony");
 
95
                        strcpy((char *)&scsi_cmdbuf[16], "CDU-76S");
 
96
                        strcpy((char *)&scsi_cmdbuf[32], "1.0");
 
97
                        if(size > 148)
 
98
                                size = 148;
 
99
                        scsi_data_in(SBUF_MAIN, size);
 
100
                        break;
 
101
                }
 
102
                scsi_status_complete(SS_GOOD);
 
103
                break;
 
104
        }
 
105
 
 
106
        case SC_START_STOP_UNIT:
 
107
                logerror("%s: command START STOP UNIT\n", tag());
 
108
                scsi_status_complete(SS_GOOD);
 
109
                break;
 
110
 
 
111
        case SC_READ_CAPACITY: {
 
112
                logerror("%s: command READ CAPACITY\n", tag());
 
113
 
 
114
                UINT32 temp = cdrom_get_track_start(cdrom, 0xaa);
 
115
                temp--; // return the last used block on the disc
 
116
 
 
117
                scsi_cmdbuf[0] = (temp>>24) & 0xff;
 
118
                scsi_cmdbuf[1] = (temp>>16) & 0xff;
 
119
                scsi_cmdbuf[2] = (temp>>8) & 0xff;
 
120
                scsi_cmdbuf[3] = (temp & 0xff);
 
121
                scsi_cmdbuf[4] = 0;
 
122
                scsi_cmdbuf[5] = 0;
 
123
                scsi_cmdbuf[6] = (bytes_per_sector>>8)&0xff;
 
124
                scsi_cmdbuf[7] = (bytes_per_sector & 0xff);
 
125
 
 
126
                scsi_data_in(SBUF_MAIN, 8);
 
127
                scsi_status_complete(SS_GOOD);
 
128
                break;
 
129
        }
 
130
 
 
131
        case SC_READ_EXTENDED:
 
132
                lba = (scsi_cmdbuf[2]<<24) | (scsi_cmdbuf[3]<<16) | (scsi_cmdbuf[4]<<8) | scsi_cmdbuf[5];
 
133
                blocks = (scsi_cmdbuf[7] << 8) | scsi_cmdbuf[8];
 
134
 
 
135
                logerror("%s: command READ EXTENDED start=%08x blocks=%04x\n",
 
136
                                 tag(), lba, blocks);
 
137
 
 
138
                scsi_data_in(2, blocks*bytes_per_sector);
 
139
                scsi_status_complete(SS_GOOD);
 
140
                break;
 
141
 
 
142
        default:
 
143
                nscsi_full_device::scsi_command();
 
144
                break;
 
145
        }
 
146
}