src/mess/drivers/fmtowns.c
| r6470 | r6471 | |
| 122 | 122 | #include "machine/upd71071.h" |
| 123 | 123 | #include "devices/messram.h" |
| 124 | 124 | |
| 125 | // CD controller IRQ types |
| 126 | #define TOWNS_CD_IRQ_MPU 1 |
| 127 | #define TOWNS_CD_IRQ_DMA 2 |
| 128 | |
| 125 | 129 | static UINT8 ftimer; |
| 126 | 130 | static UINT8 nmi_mask; |
| 127 | 131 | static UINT8 compat_mode; |
| r6470 | r6471 | |
| 1201 | 1205 | * bit 4 - DMA transfer mode |
| 1202 | 1206 | * |
| 1203 | 1207 | */ |
| 1208 | static void towns_cdrom_set_irq(running_machine* machine,int line,int state) |
| 1209 | { |
| 1210 | switch(line) |
| 1211 | { |
| 1212 | case TOWNS_CD_IRQ_MPU: |
| 1213 | if(state != 0) |
| 1214 | { |
| 1215 | if(towns_cd.command & 0x40) |
| 1216 | { |
| 1217 | towns_cd.status |= 0x80; |
| 1218 | if(towns_cd.mpu_irq_enable) |
| 1219 | pic8259_set_irq_line(devtag_get_device(machine,"pic8259_slave"),1,1); |
| 1220 | } |
| 1221 | } |
| 1222 | else |
| 1223 | { |
| 1224 | towns_cd.status &= ~0x80; |
| 1225 | pic8259_set_irq_line(devtag_get_device(machine,"pic8259_slave"),1,0); |
| 1226 | } |
| 1227 | break; |
| 1228 | case TOWNS_CD_IRQ_DMA: |
| 1229 | if(state != 0) |
| 1230 | { |
| 1231 | if(towns_cd.command & 0x40) |
| 1232 | { |
| 1233 | towns_cd.status |= 0x40; |
| 1234 | if(towns_cd.dma_irq_enable) |
| 1235 | pic8259_set_irq_line(devtag_get_device(machine,"pic8259_slave"),1,1); |
| 1236 | } |
| 1237 | } |
| 1238 | else |
| 1239 | { |
| 1240 | towns_cd.status &= ~0x40; |
| 1241 | pic8259_set_irq_line(devtag_get_device(machine,"pic8259_slave"),1,0); |
| 1242 | } |
| 1243 | break; |
| 1244 | } |
| 1245 | } |
| 1246 | |
| 1204 | 1247 | static TIMER_CALLBACK( towns_cdrom_read_byte ) |
| 1205 | 1248 | { |
| 1206 | 1249 | const device_config* device = ptr; |
| r6470 | r6471 | |
| 1239 | 1282 | towns_cd.cmd_status[1] = 0x00; |
| 1240 | 1283 | towns_cd.cmd_status[2] = 0x00; |
| 1241 | 1284 | towns_cd.cmd_status[3] = 0x00; |
| 1242 | | if(towns_cd.dma_irq_enable != 0) |
| 1243 | | { |
| 1244 | | towns_cd.status |= 0x40; // IRQ from end of DMA |
| 1245 | | pic8259_set_irq_line(devtag_get_device(device->machine,"pic8259_slave"),1,0); |
| 1246 | | } |
| 1285 | towns_cdrom_set_irq(device->machine,TOWNS_CD_IRQ_DMA,1); |
| 1247 | 1286 | towns_cd.status |= 0x01; // ready |
| 1248 | 1287 | } |
| 1249 | 1288 | else |
| r6470 | r6471 | |
| 1255 | 1294 | towns_cd.cmd_status[1] = 0x00; |
| 1256 | 1295 | towns_cd.cmd_status[2] = 0x00; |
| 1257 | 1296 | towns_cd.cmd_status[3] = 0x00; |
| 1258 | | if(towns_cd.dma_irq_enable != 0) |
| 1259 | | { |
| 1260 | | towns_cd.status |= 0x40; // IRQ from end of DMA |
| 1261 | | pic8259_set_irq_line(devtag_get_device(device->machine,"pic8259_slave"),1,0); |
| 1262 | | } |
| 1297 | towns_cdrom_set_irq(device->machine,TOWNS_CD_IRQ_DMA,1); |
| 1263 | 1298 | cdrom_read_data(mess_cd_get_cdrom_file(devtag_get_device(device->machine,"cdrom")),++towns_cd.lba_current,towns_cd.buffer,CD_TRACK_MODE1); |
| 1264 | 1299 | timer_adjust_oneshot(towns_cd.read_timer,ATTOTIME_IN_HZ(300000),1); |
| 1265 | 1300 | towns_cd.buffer_ptr = -1; |
| r6470 | r6471 | |
| 1294 | 1329 | towns_cd.cmd_status[1] = 0x00; |
| 1295 | 1330 | towns_cd.cmd_status[2] = 0x00; |
| 1296 | 1331 | towns_cd.cmd_status[3] = 0x00; |
| 1297 | | if(towns_cd.mpu_irq_enable != 0) |
| 1298 | | { |
| 1299 | | towns_cd.status |= 0x80; // IRQ from MPU |
| 1300 | | pic8259_set_irq_line(devtag_get_device(device->machine,"pic8259_slave"),1,1); |
| 1301 | | } |
| 1332 | towns_cdrom_set_irq(device->machine,TOWNS_CD_IRQ_MPU,1); |
| 1302 | 1333 | } |
| 1303 | 1334 | else |
| 1304 | 1335 | { |
| r6470 | r6471 | |
| 1313 | 1344 | towns_cd.cmd_status[1] = 0x00; |
| 1314 | 1345 | towns_cd.cmd_status[2] = 0x00; |
| 1315 | 1346 | towns_cd.cmd_status[3] = 0x00; |
| 1316 | | if(towns_cd.mpu_irq_enable != 0) |
| 1317 | | { |
| 1318 | | towns_cd.status |= 0x80; // IRQ from MPU |
| 1319 | | pic8259_set_irq_line(devtag_get_device(device->machine,"pic8259_slave"),1,1); |
| 1320 | | } |
| 1347 | towns_cdrom_set_irq(device->machine,TOWNS_CD_IRQ_MPU,1); |
| 1321 | 1348 | } |
| 1322 | 1349 | |
| 1323 | 1350 | // start read timer - assume single-speed currently |
| r6470 | r6471 | |
| 1340 | 1367 | towns_cd.cmd_status[1] = 0x00; |
| 1341 | 1368 | towns_cd.cmd_status[2] = 0x00; |
| 1342 | 1369 | towns_cd.cmd_status[3] = 0x00; |
| 1370 | towns_cdrom_set_irq(device->machine,TOWNS_CD_IRQ_MPU,1); |
| 1343 | 1371 | } |
| 1344 | 1372 | } |
| 1345 | 1373 | else |
| r6470 | r6471 | |
| 1356 | 1384 | towns_cd.cmd_status[1] = 0x00; |
| 1357 | 1385 | towns_cd.cmd_status[2] = 0x00; |
| 1358 | 1386 | towns_cd.cmd_status[3] = 0x00; |
| 1359 | | if(towns_cd.command & 0x40) |
| 1360 | | towns_cd.status |= 0x80; // IRQ from MPU |
| 1387 | towns_cdrom_set_irq(device->machine,TOWNS_CD_IRQ_MPU,1); |
| 1361 | 1388 | } |
| 1362 | 1389 | logerror("CD: Command 0x00: SEEK\n"); |
| 1363 | 1390 | break; |
| r6470 | r6471 | |
| 1374 | 1401 | towns_cd.cmd_status[1] = 0x00; |
| 1375 | 1402 | towns_cd.cmd_status[2] = 0x00; |
| 1376 | 1403 | towns_cd.cmd_status[3] = 0x00; |
| 1377 | | if(towns_cd.command & 0x40) |
| 1378 | | towns_cd.status |= 0x80; // IRQ from MPU |
| 1404 | towns_cdrom_set_irq(device->machine,TOWNS_CD_IRQ_MPU,1); |
| 1379 | 1405 | break; |
| 1380 | 1406 | case 0x80: // set state |
| 1381 | 1407 | if(towns_cd.command & 0x20) |
| r6470 | r6471 | |
| 1387 | 1413 | towns_cd.cmd_status[1] = 0x00; |
| 1388 | 1414 | towns_cd.cmd_status[2] = 0x00; |
| 1389 | 1415 | towns_cd.cmd_status[3] = 0x00; |
| 1390 | | if(towns_cd.command & 0x40) |
| 1391 | | towns_cd.status |= 0x80; // IRQ from MPU |
| 1416 | towns_cdrom_set_irq(device->machine,TOWNS_CD_IRQ_MPU,1); |
| 1392 | 1417 | } |
| 1393 | 1418 | logerror("CD: Command 0x80: set state\n"); |
| 1394 | 1419 | break; |
| r6470 | r6471 | |
| 1402 | 1427 | towns_cd.cmd_status[1] = 0x00; |
| 1403 | 1428 | towns_cd.cmd_status[2] = 0x00; |
| 1404 | 1429 | towns_cd.cmd_status[3] = 0x00; |
| 1405 | | if(towns_cd.command & 0x40) |
| 1406 | | towns_cd.status |= 0x80; // IRQ from MPU |
| 1430 | towns_cdrom_set_irq(device->machine,TOWNS_CD_IRQ_MPU,1); |
| 1407 | 1431 | } |
| 1408 | 1432 | logerror("CD: Command 0x81: set state (CDDASET)\n"); |
| 1409 | 1433 | break; |
| r6470 | r6471 | |
| 1415 | 1439 | towns_cd.cmd_status[1] = 0x00; |
| 1416 | 1440 | towns_cd.cmd_status[2] = 0x00; |
| 1417 | 1441 | towns_cd.cmd_status[3] = 0x00; |
| 1442 | towns_cdrom_set_irq(device->machine,TOWNS_CD_IRQ_MPU,1); |
| 1418 | 1443 | logerror("CD: Unknown or unimplemented command %02x\n",towns_cd.command); |
| 1419 | 1444 | } |
| 1420 | 1445 | } |
| r6470 | r6471 | |
| 1552 | 1577 | { |
| 1553 | 1578 | case 0x00: // status |
| 1554 | 1579 | if(data & 0x80) |
| 1555 | | towns_cd.status &= ~0x80; |
| 1580 | towns_cdrom_set_irq(space->machine,TOWNS_CD_IRQ_MPU,0); |
| 1556 | 1581 | if(data & 0x40) |
| 1557 | | towns_cd.status &= ~0x40; |
| 1582 | towns_cdrom_set_irq(space->machine,TOWNS_CD_IRQ_DMA,0); |
| 1558 | 1583 | if(data & 0x04) |
| 1559 | 1584 | logerror("CD: sub MPU reset\n"); |
| 1560 | 1585 | towns_cd.mpu_irq_enable = data & 0x02; |