Previous 15994 Revisions Next

r6453 Wednesday 25th November, 2009 at 10:33:03 UTC by Barry Rodewald
[FMTOWNS] Added CD-ROM and CDDA devices, added basic support for reading sectors from CD-ROMs. [uPD71071] Implemented Auto-initialise and Disable DMA Operation.
[src/mess/drivers]fmtowns.c
[src/mess/machine]upd71071.c upd71071.h

src/mess/machine/upd71071.c
r6452r6453
125125         if(dmac->intf->dma_read[channel])
126126            data = dmac->intf->dma_read[channel](device->machine);
127127         memory_write_byte(space,dmac->reg.address_current[channel],data & 0xff);
128         dmac->reg.count_current[channel]--;
129128         if(dmac->reg.mode_control[channel] & 0x20)  // Address direction
130129            dmac->reg.address_current[channel]--;
131130         else
132131            dmac->reg.address_current[channel]++;
132         if(dmac->reg.count_current[channel] == 0)
133         {
134            if(dmac->reg.mode_control[channel] & 0x10)
135            {
136               dmac->reg.address_current[channel] = dmac->reg.address_base[channel];
137               dmac->reg.count_current[channel] = dmac->reg.count_base[channel];
138            }
139            // TODO: send terminal count
140         }
141         else
142            dmac->reg.count_current[channel]--;
133143         break;
134144      case 0x08:  // memory -> I/O
135145         data = memory_read_byte(space,dmac->reg.address_current[channel]);
136146         if(dmac->intf->dma_read[channel])
137147            dmac->intf->dma_write[channel](device->machine,data);
138         dmac->reg.count_current[channel]--;
139148         if(dmac->reg.mode_control[channel] & 0x20)  // Address direction
140149            dmac->reg.address_current[channel]--;
141150         else
142151            dmac->reg.address_current[channel]++;
152         if(dmac->reg.count_current[channel] == 0)
153         {
154            if(dmac->reg.mode_control[channel] & 0x10)
155            {
156               dmac->reg.address_current[channel] = dmac->reg.address_base[channel];
157               dmac->reg.count_current[channel] = dmac->reg.count_base[channel];
158            }
159            // TODO: send terminal count
160         }
161         else
162            dmac->reg.count_current[channel]--;
143163         break;
144164      case 0x0c:  // Invalid
145165         break;
146166   }
147167}
148168
149void upd71071_dmarq(const device_config* device, int state,int channel)
169int upd71071_dmarq(const device_config* device, int state,int channel)
150170{
151171   upd71071_t* dmac = device->token;
152172
153173   if(state != 0)
154174   {
175      if(dmac->reg.device_control & 0x0004)
176         return 2;
177     
178      if(dmac->reg.mask & (1 << channel))  // is channel masked?
179         return 1;
180
155181      dmac->dmarq[channel] = 1;  // DMARQ line is set
156182      dmac->reg.status |= (0x10 << channel);
157183
158184      // start transfer
159      if(dmac->reg.mask & (1 << channel))  // is channel masked?
160         return;
161     
162185      switch(dmac->reg.mode_control[channel] & 0xc0)
163186      {
164187         case 0x00:  // Demand
r6452r6453
182205      dmac->reg.status &= ~(0x10 << channel);
183206      dmac->reg.status |= (0x01 << channel);  // END or TC
184207   }
208   return 0;
185209}
186210
187211static DEVICE_START(upd71071)
src/mess/machine/upd71071.h
r6452r6453
1212   void (*dma_write[4])(running_machine* machine, UINT16 data);
1313};
1414
15void upd71071_dmarq(const device_config* device,int state,int channel);
15int upd71071_dmarq(const device_config* device,int state,int channel);
1616
1717DEVICE_GET_INFO(upd71071);
1818
src/mess/drivers/fmtowns.c
r6452r6453
112112#include "cpu/i386/i386.h"
113113#include "sound/2612intf.h"
114114#include "sound/rf5c68.h"
115#include "sound/cdda.h"
116#include "devices/chd_cd.h"
115117#include "machine/pit8253.h"
116118#include "machine/pic8259.h"
117119#include "formats/basicdsk.h"
r6452r6453
170172   UINT8 status;
171173   UINT8 cmd_status[4];
172174   UINT8 cmd_status_ptr;
175   UINT8 extra_status;
173176   UINT8 parameter[8];
177   UINT8 mpu_irq_enable;
178   UINT8 dma_irq_enable;
179   UINT8 buffer[2048];
180   INT32 buffer_ptr;
181   UINT32 lba_current;
182   UINT32 lba_last;
183   emu_timer* read_timer;
174184} towns_cd;
175185
176186static void towns_update_video_banks(const address_space* space);
177187static PIC8259_SET_INT_LINE( towns_pic_irq );
178188
189INLINE UINT32 bcd_to_dec(UINT32 val)
190{
191   return (val & 0x00000f) +
192      (((val & 0x0000f0) >> 4) * 10) +
193      (((val & 0x000f00) >> 8) * 100) +
194      (((val & 0x00f000) >> 12) * 1000) +
195      (((val & 0x0f0000) >> 16) * 10000) +
196      (((val & 0xf00000) >> 24) * 100000);
197}
198
179199static void towns_init_serial_rom(running_machine* machine)
180200{
181201   // TODO: init serial ROM contents
r6452r6453
11661186 *    bit 4 - DMA transfer mode
11671187 *
11681188 */
1169static void towns_cdrom_execute_command(void)
1189static TIMER_CALLBACK( towns_cdrom_read_byte )
11701190{
1171   // For now, we'll return status codes that hopefully tell the system
1172   // that there is no CD-ROM in the drive.
1191   const device_config* device = ptr;
1192   int masked;
1193   // TODO: support software transfers, for now DMA is assumed.
11731194   
1174   towns_cd.status |= 0x02;  // status read request
1195   if(towns_cd.buffer_ptr < 0) // transfer has ended
1196      return;
1197   
1198   masked = upd71071_dmarq(device,param,3);  // CD-ROM controller uses DMA1 channel 3
1199   //logerror("DMARQ: param=%i ret=%i bufferptr=%i\n",param,masked,towns_cd.buffer_ptr);
1200   if(param != 0)
1201   {
1202      timer_adjust_oneshot(towns_cd.read_timer,ATTOTIME_IN_HZ(300000),0);
1203   }
1204   else
1205   {
1206      if(masked != 0)  // check if the DMA channel is masked
1207      {
1208         timer_adjust_oneshot(towns_cd.read_timer,ATTOTIME_IN_HZ(300000),1);
1209         return;
1210      }
1211      if(towns_cd.buffer_ptr < 2048)
1212         timer_adjust_oneshot(towns_cd.read_timer,ATTOTIME_IN_HZ(300000),1);
1213      else
1214      {  // end of transfer
1215         towns_cd.status &= ~0x10;  // no longer transferring by DMA
1216         towns_cd.status &= ~0x20;  // no longer transferring by software
1217         logerror("DMA1: end of transfer (LBA=%08x)\n",towns_cd.lba_current);
1218         if(towns_cd.lba_current >= towns_cd.lba_last)
1219         { 
1220            towns_cd.status |= 0x02;  // status read request
1221            towns_cd.cmd_status_ptr = 0;
1222            towns_cd.extra_status = 0;
1223            towns_cd.cmd_status[0] = 0x06;
1224            towns_cd.cmd_status[1] = 0x00;
1225            towns_cd.cmd_status[2] = 0x00;
1226            towns_cd.cmd_status[3] = 0x00;
1227            if(towns_cd.dma_irq_enable != 0)
1228            {
1229               towns_cd.status |= 0x40;  // IRQ from end of DMA
1230               pic8259_set_irq_line(devtag_get_device(device->machine,"pic8259_slave"),1,0);
1231            }
1232            towns_cd.status |= 0x01;  // ready
1233         }
1234         else
1235         {
1236            towns_cd.status |= 0x02;  // status read request
1237            towns_cd.cmd_status_ptr = 0;
1238            towns_cd.extra_status = 0;
1239            towns_cd.cmd_status[0] = 0x22;
1240            towns_cd.cmd_status[1] = 0x00;
1241            towns_cd.cmd_status[2] = 0x00;
1242            towns_cd.cmd_status[3] = 0x00;
1243            if(towns_cd.dma_irq_enable != 0)
1244            {
1245               towns_cd.status |= 0x40;  // IRQ from end of DMA
1246               pic8259_set_irq_line(devtag_get_device(device->machine,"pic8259_slave"),1,0);
1247            }
1248            cdrom_read_data(mess_cd_get_cdrom_file(devtag_get_device(device->machine,"cdrom")),++towns_cd.lba_current,towns_cd.buffer,CD_TRACK_MODE1);
1249            timer_adjust_oneshot(towns_cd.read_timer,ATTOTIME_IN_HZ(300000),1);
1250            towns_cd.buffer_ptr = -1;
1251            towns_cd.status |= 0x01;  // ready
1252         }
1253      }
1254   }
1255}
1256
1257static void towns_cdrom_read(const device_config* device)
1258{
1259   // MODE 1 read
1260   // load data into buffer to be sent via DMA1 channel 3
1261   UINT32 lba1,lba2;
1262   
1263   lba1 = towns_cd.parameter[7] << 16;
1264   lba1 += towns_cd.parameter[6] << 8;
1265   lba1 += towns_cd.parameter[5];
1266   lba2 = towns_cd.parameter[4] << 16;
1267   lba2 += towns_cd.parameter[3] << 8;
1268   lba2 += towns_cd.parameter[2];
1269   towns_cd.lba_current = bcd_to_dec(lba1) - 200;
1270   towns_cd.lba_last = bcd_to_dec(lba2) - 200;
1271   
1272   logerror("CD: Mode 1 read from LBA next:%i last:%i\n",towns_cd.lba_current,towns_cd.lba_last);
1273   
1274   cdrom_read_data(mess_cd_get_cdrom_file(device),towns_cd.lba_current,towns_cd.buffer,CD_TRACK_MODE1);
1275   towns_cd.buffer_ptr = 0;
1276   towns_cd.status |= 0x03; // immediate status return?
1277   towns_cd.status |= 0x10;  // DMA transfer begin
1278   towns_cd.status &= ~0x20;  // not a software transfer
11751279   towns_cd.cmd_status_ptr = 0;
1176   towns_cd.cmd_status[0] = 0x10;
1280   towns_cd.extra_status = 2;
1281   towns_cd.cmd_status[0] = 0x00;
11771282   towns_cd.cmd_status[1] = 0x00;
11781283   towns_cd.cmd_status[2] = 0x00;
11791284   towns_cd.cmd_status[3] = 0x00;
1285   if(towns_cd.dma_irq_enable != 0)
1286   {
1287      towns_cd.status |= 0x40;  // IRQ from end of DMA
1288      pic8259_set_irq_line(devtag_get_device(device->machine,"pic8259_slave"),1,0);
1289   }
1290   
1291   // start read timer - assume single-speed currently
1292   //timer_adjust_oneshot(towns_cd.read_timer,ATTOTIME_IN_HZ(300000),1);
11801293}
11811294
1295static void towns_cdrom_execute_command(const device_config* device)
1296{
1297   // For now, we'll return status codes that hopefully tell the system
1298   // that there is no CD-ROM in the drive.
1299
1300   if(mess_cd_get_cdrom_file(device) == NULL)
1301   {  // No CD in drive
1302      if(towns_cd.command & 0x20)
1303      {
1304         towns_cd.status |= 0x02;  // status read request
1305         towns_cd.cmd_status_ptr = 0;
1306         towns_cd.extra_status = 0;
1307         towns_cd.cmd_status[0] = 0x10;
1308         towns_cd.cmd_status[1] = 0x00;
1309         towns_cd.cmd_status[2] = 0x00;
1310         towns_cd.cmd_status[3] = 0x00;
1311      }
1312   }
1313   else
1314   {
1315      switch(towns_cd.command & 0x9f)
1316      {
1317         case 0x00:  // Seek
1318            if(towns_cd.command & 0x20)
1319            {
1320               towns_cd.status |= 0x02;  // status read request
1321               towns_cd.cmd_status_ptr = 0;
1322               towns_cd.extra_status = 1;
1323               towns_cd.cmd_status[0] = 0x00;
1324               towns_cd.cmd_status[1] = 0x00;
1325               towns_cd.cmd_status[2] = 0x00;
1326               towns_cd.cmd_status[3] = 0x00;
1327               if(towns_cd.command & 0x40)
1328                  towns_cd.status |= 0x80;  // IRQ from MPU
1329            }
1330            logerror("CD: Command 0x00: SEEK\n");
1331            break;
1332         case 0x02:  // Read (MODE1)
1333            logerror("CD: Command 0x02: READ MODE1\n");
1334            towns_cdrom_read(device);
1335            break;
1336         case 0x05:  // Read TOC
1337            logerror("CD: Command 0x05: READ TOC\n");
1338            break;
1339         case 0x80:  // set state
1340            if(towns_cd.command & 0x20)
1341            {
1342               towns_cd.status |= 0x02;  // status read request
1343               towns_cd.cmd_status_ptr = 0;
1344               towns_cd.extra_status = 0;
1345               towns_cd.cmd_status[0] = 0x00;
1346               towns_cd.cmd_status[1] = 0x00;
1347               towns_cd.cmd_status[2] = 0x00;
1348               towns_cd.cmd_status[3] = 0x00;
1349               if(towns_cd.command & 0x40)
1350                  towns_cd.status |= 0x80;  // IRQ from MPU
1351            }
1352            logerror("CD: Command 0x80: set state\n");
1353            break;
1354         case 0x81:  // set state (CDDASET)
1355            if(towns_cd.command & 0x20)
1356            {
1357               towns_cd.status |= 0x02;  // status read request
1358               towns_cd.cmd_status_ptr = 0;
1359               towns_cd.extra_status = 0;
1360               towns_cd.cmd_status[0] = 0x00;
1361               towns_cd.cmd_status[1] = 0x00;
1362               towns_cd.cmd_status[2] = 0x00;
1363               towns_cd.cmd_status[3] = 0x00;
1364               if(towns_cd.command & 0x40)
1365                  towns_cd.status |= 0x80;  // IRQ from MPU
1366            }
1367            logerror("CD: Command 0x81: set state (CDDASET)\n");
1368            break;
1369         default:
1370            towns_cd.status |= 0x02;  // status read request
1371            towns_cd.cmd_status_ptr = 0;
1372            towns_cd.extra_status = 0;
1373            towns_cd.cmd_status[0] = 0x10;
1374            towns_cd.cmd_status[1] = 0x00;
1375            towns_cd.cmd_status[2] = 0x00;
1376            towns_cd.cmd_status[3] = 0x00;
1377            logerror("CD: Unknown or unimplemented command %02x\n",towns_cd.command);
1378      }
1379   }
1380}
1381
1382static UINT16 towns_cdrom_dma_r(running_machine* machine)
1383{
1384   if(towns_cd.buffer_ptr >= 2048)
1385      return 0x00;
1386   return towns_cd.buffer[towns_cd.buffer_ptr++];
1387}
1388
11821389static READ8_HANDLER(towns_cdrom_r)
11831390{
1184   logerror("CD: read port %02x\n",offset*2);
11851391   switch(offset)
11861392   {
11871393      case 0x00:  // status
1394         //logerror("CD: status read, returning %02x\n",towns_cd.status);
11881395         return towns_cd.status;
11891396      case 0x01:  // command status
11901397         if(towns_cd.cmd_status_ptr > 3)
11911398         {
11921399            towns_cd.cmd_status_ptr = 0;
11931400            towns_cd.status &= ~0x02;
1401            // check for more status bytes
1402            if(towns_cd.extra_status != 0)
1403            {
1404               towns_cd.status |= 0x02;
1405               switch(towns_cd.command & 0x9f)
1406               {
1407                  case 0x00:  // seek
1408                     towns_cd.cmd_status[0] = 0x04;
1409                     towns_cd.cmd_status[1] = 0x00;
1410                     towns_cd.cmd_status[2] = 0x00;
1411                     towns_cd.cmd_status[3] = 0x00;
1412                     towns_cd.extra_status = 0;
1413                     break;
1414                  case 0x02:  // read
1415                     if(towns_cd.extra_status == 2)
1416                     {
1417                        towns_cd.cmd_status[0] = 0x22;
1418                     }
1419                     else
1420                        towns_cd.cmd_status[0] = 0x06;
1421                     towns_cd.cmd_status[1] = 0x00;
1422                     towns_cd.cmd_status[2] = 0x00;
1423                     towns_cd.cmd_status[3] = 0x00;
1424                     towns_cd.extra_status = 0;
1425                     break;
1426                  case 0x05:  // read toc
1427                     break;
1428               }
1429            }
11941430         }
1431         logerror("CD: reading command status port, returning %02x\n",towns_cd.cmd_status[towns_cd.cmd_status_ptr]);
11951432         return towns_cd.cmd_status[towns_cd.cmd_status_ptr++];
11961433      default:
11971434         return 0x00;
r6452r6453
12041441   switch(offset)
12051442   {
12061443      case 0x00: // status
1444         if(data & 0x80)
1445            towns_cd.status &= ~0x80;
1446         if(data & 0x40)
1447            towns_cd.status &= ~0x40;
1448         if(data & 0x04)
1449            logerror("CD: sub MPU reset\n");
1450         towns_cd.mpu_irq_enable = data & 0x02;
1451         towns_cd.dma_irq_enable = data & 0x01;
12071452         logerror("CD: status write %02x\n",data);
12081453         break;
12091454      case 0x01: // command
12101455         towns_cd.command = data;
1211         towns_cdrom_execute_command();
1456         towns_cdrom_execute_command(devtag_get_device(space->machine,"cdrom"));
12121457         logerror("CD: command %02x sent\n",data);
12131458         logerror("CD: parameters: %02x %02x %02x %02x %02x %02x %02x %02x\n",
1214            towns_cd.parameter[0],towns_cd.parameter[1],towns_cd.parameter[2],
1215            towns_cd.parameter[3],towns_cd.parameter[4],towns_cd.parameter[5],
1216            towns_cd.parameter[6],towns_cd.parameter[7]);
1459            towns_cd.parameter[7],towns_cd.parameter[6],towns_cd.parameter[5],
1460            towns_cd.parameter[4],towns_cd.parameter[3],towns_cd.parameter[2],
1461            towns_cd.parameter[1],towns_cd.parameter[0]);
12171462         break;
12181463      case 0x02: // parameter
1219         for(x=0;x<7;x++)
1220            towns_cd.parameter[x+1] = towns_cd.parameter[x];
1464         for(x=7;x>0;x--)
1465            towns_cd.parameter[x] = towns_cd.parameter[x-1];
12211466         towns_cd.parameter[0] = data;
12221467         logerror("CD: parameter %02x added\n",data);
12231468         break;
1469      case 0x03:
1470         // TODO: software transfer mode (bit 3)
1471         if(data & 0x10)
1472         {
1473            towns_cd.status |= 0x10;  // DMA transfer begin
1474            towns_cd.status &= ~0x20;  // not a software transfer
1475            towns_cd.buffer_ptr = 0;
1476            timer_adjust_oneshot(towns_cd.read_timer,ATTOTIME_IN_HZ(300000),1);
1477         }
1478         break;
12241479      default:
1225         logerror("CD: write port %02x\n",offset*2);
1480         logerror("CD: write %02x to port %02x\n",data,offset*2);
12261481   }
12271482}
12281483
r6452r6453
17031958   towns_rtc_timer = timer_alloc(machine,rtc_second,NULL);
17041959   towns_kb_timer = timer_alloc(machine,poll_keyboard,NULL);
17051960   
1961   // CD-ROM init
1962   towns_cd.read_timer = timer_alloc(machine,towns_cdrom_read_byte,(void*)devtag_get_device(machine,"dma_1"));
1963   
17061964   cpu_set_irq_callback(cputag_get_cpu(machine,"maincpu"), towns_irq_callback);
17071965}
17081966
r6452r6453
18992157{
19002158   "maincpu",
19012159   1000000,
1902   { towns_fdc_dma_r, 0, 0, 0 },
2160   { towns_fdc_dma_r, 0, 0, towns_cdrom_dma_r },
19032161   { towns_fdc_dma_w, 0, 0, 0 }
19042162};
19052163
r6452r6453
19572215   MDRV_SOUND_ADD("pcm", RF5C68, 2150000)  // actual clock speed unknown
19582216//  MDRV_SOUND_CONFIG(rf5c68_interface)
19592217   MDRV_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.50)
2218   MDRV_SOUND_ADD("cdda",CDDA,0)
2219   MDRV_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.50)
19602220
19612221    MDRV_PIT8253_ADD("pit",towns_pit8253_config)
19622222
r6452r6453
19662226
19672227   MDRV_MB8877_ADD("fdc",towns_mb8877a_interface)
19682228   MDRV_FLOPPY_4_DRIVES_ADD(towns_floppy_config)
2229   
2230   MDRV_CDROM_ADD("cdrom")
19692231
19702232   MDRV_UPD71071_ADD("dma_1",towns_dma_config)
19712233   MDRV_UPD71071_ADD("dma_2",towns_dma_config)

Previous 15994 Revisions Next


© 1998-2018 The MESS Team