trunk/src/emu/machine/idectrl.c
| r23572 | r23573 | |
| 301 | 301 | void ide_controller_device::write_buffer_to_dma() |
| 302 | 302 | { |
| 303 | 303 | int bytesleft = IDE_DISK_SECTOR_SIZE; |
| 304 | | UINT8 *data = buffer; |
| 304 | UINT16 data = 0; |
| 305 | 305 | |
| 306 | 306 | // LOG(("Writing sector to %08X\n", dma_address)); |
| 307 | 307 | |
| 308 | 308 | /* loop until we've consumed all bytes */ |
| 309 | 309 | while (bytesleft--) |
| 310 | 310 | { |
| 311 | data >>= 8; |
| 312 | |
| 313 | if (bytesleft & 1) |
| 314 | data = read_dma(); |
| 315 | |
| 311 | 316 | /* if we're out of space, grab the next descriptor */ |
| 312 | 317 | if (dma_bytes_left == 0) |
| 313 | 318 | { |
| r23572 | r23573 | |
| 339 | 344 | } |
| 340 | 345 | |
| 341 | 346 | /* write the next byte */ |
| 342 | | dma_space->write_byte(dma_address++, *data++); |
| 347 | dma_space->write_byte(dma_address++, data & 0xff); |
| 343 | 348 | dma_bytes_left--; |
| 344 | 349 | } |
| 345 | 350 | } |
| r23572 | r23573 | |
| 392 | 397 | if (dma_active) |
| 393 | 398 | write_buffer_to_dma(); |
| 394 | 399 | |
| 395 | | /* if we're just verifying or if we DMA'ed the data, we can read the next sector */ |
| 396 | | if (verify_only || dma_active) |
| 400 | /* if we're just verifying we can read the next sector */ |
| 401 | if (verify_only) |
| 397 | 402 | continue_read(); |
| 398 | 403 | } |
| 399 | 404 | |
| r23572 | r23573 | |
| 507 | 512 | void ide_controller_device::read_buffer_from_dma() |
| 508 | 513 | { |
| 509 | 514 | int bytesleft = IDE_DISK_SECTOR_SIZE; |
| 510 | | UINT8 *data = buffer; |
| 515 | UINT16 data = 0; |
| 511 | 516 | |
| 512 | 517 | // LOG(("Reading sector from %08X\n", dma_address)); |
| 513 | 518 | |
| r23572 | r23573 | |
| 545 | 550 | } |
| 546 | 551 | |
| 547 | 552 | /* read the next byte */ |
| 548 | | *data++ = dma_space->read_byte(dma_address++); |
| 549 | | dma_bytes_left--; |
| 553 | data |= dma_space->read_byte(dma_address++) << 8; |
| 554 | dma_bytes_left --; |
| 555 | |
| 556 | if((bytesleft & 1) == 0) |
| 557 | write_dma(data); |
| 558 | |
| 559 | data >>= 8; |
| 550 | 560 | } |
| 551 | 561 | } |
| 552 | 562 | |
| r23572 | r23573 | |
| 595 | 605 | if (dma_active && sector_count != 0) |
| 596 | 606 | { |
| 597 | 607 | read_buffer_from_dma(); |
| 598 | | continue_write(); |
| 599 | 608 | } |
| 600 | 609 | else |
| 601 | 610 | dma_active = 0; |
| r23572 | r23573 | |
| 739 | 748 | if (bus_master_command & 1) |
| 740 | 749 | { |
| 741 | 750 | read_buffer_from_dma(); |
| 742 | | continue_write(); |
| 743 | 751 | } |
| 744 | 752 | break; |
| 745 | 753 | |
| r23572 | r23573 | |
| 961 | 969 | } |
| 962 | 970 | } |
| 963 | 971 | |
| 972 | UINT16 ide_controller_device::read_dma() |
| 973 | { |
| 974 | UINT16 result = buffer[buffer_offset++]; |
| 975 | result |= buffer[buffer_offset++] << 8; |
| 976 | |
| 977 | if (buffer_offset >= IDE_DISK_SECTOR_SIZE) |
| 978 | { |
| 979 | LOG(("%s:IDE completed DMA read\n", machine().describe_context())); |
| 980 | read_buffer_empty(); |
| 981 | } |
| 982 | |
| 983 | return result; |
| 984 | } |
| 985 | |
| 964 | 986 | READ16_MEMBER( ide_controller_device::read_cs0 ) |
| 965 | 987 | { |
| 966 | 988 | UINT16 result = 0; |
| r23572 | r23573 | |
| 1001 | 1023 | if (buffer_offset >= IDE_DISK_SECTOR_SIZE) |
| 1002 | 1024 | { |
| 1003 | 1025 | LOG(("%s:IDE completed PIO read\n", machine().describe_context())); |
| 1004 | | continue_read(); |
| 1005 | | error = IDE_ERROR_DEFAULT; |
| 1026 | read_buffer_empty(); |
| 1006 | 1027 | } |
| 1007 | 1028 | } |
| 1008 | 1029 | break; |
| r23572 | r23573 | |
| 1062 | 1083 | } |
| 1063 | 1084 | |
| 1064 | 1085 | |
| 1086 | void ide_controller_device::write_buffer_full() |
| 1087 | { |
| 1088 | ide_device_interface *dev = slot[cur_drive]->dev(); |
| 1089 | |
| 1090 | if (command == IDE_COMMAND_SECURITY_UNLOCK) |
| 1091 | { |
| 1092 | if (user_password_enable && memcmp(buffer, user_password, 2 + 32) == 0) |
| 1093 | { |
| 1094 | LOGPRINT(("IDE Unlocked user password\n")); |
| 1095 | user_password_enable = 0; |
| 1096 | } |
| 1097 | if (master_password_enable && memcmp(buffer, master_password, 2 + 32) == 0) |
| 1098 | { |
| 1099 | LOGPRINT(("IDE Unlocked master password\n")); |
| 1100 | master_password_enable = 0; |
| 1101 | } |
| 1102 | if (PRINTF_IDE_PASSWORD) |
| 1103 | { |
| 1104 | int i; |
| 1105 | |
| 1106 | for (i = 0; i < 34; i += 2) |
| 1107 | { |
| 1108 | if (i % 8 == 2) |
| 1109 | mame_printf_debug("\n"); |
| 1110 | |
| 1111 | mame_printf_debug("0x%02x, 0x%02x, ", buffer[i], buffer[i + 1]); |
| 1112 | //mame_printf_debug("0x%02x%02x, ", buffer[i], buffer[i + 1]); |
| 1113 | } |
| 1114 | mame_printf_debug("\n"); |
| 1115 | } |
| 1116 | |
| 1117 | /* clear the busy and error flags */ |
| 1118 | status &= ~IDE_STATUS_ERROR; |
| 1119 | status &= ~IDE_STATUS_BUSY; |
| 1120 | status &= ~IDE_STATUS_BUFFER_READY; |
| 1121 | |
| 1122 | if (master_password_enable || user_password_enable) |
| 1123 | security_error(); |
| 1124 | else |
| 1125 | status |= IDE_STATUS_DRIVE_READY; |
| 1126 | } |
| 1127 | else if (command == IDE_COMMAND_TAITO_GNET_UNLOCK_2) |
| 1128 | { |
| 1129 | UINT8 key[5] = { 0 }; |
| 1130 | int i, bad = 0; |
| 1131 | dev->read_key(key); |
| 1132 | |
| 1133 | for (i=0; !bad && i<512; i++) |
| 1134 | bad = ((i < 2 || i >= 7) && buffer[i]) || ((i >= 2 && i < 7) && buffer[i] != key[i-2]); |
| 1135 | |
| 1136 | status &= ~IDE_STATUS_BUSY; |
| 1137 | status &= ~IDE_STATUS_BUFFER_READY; |
| 1138 | if (bad) |
| 1139 | status |= IDE_STATUS_ERROR; |
| 1140 | else { |
| 1141 | status &= ~IDE_STATUS_ERROR; |
| 1142 | gnetreadlock= 0; |
| 1143 | } |
| 1144 | } |
| 1145 | else |
| 1146 | continue_write(); |
| 1147 | } |
| 1148 | |
| 1149 | void ide_controller_device::read_buffer_empty() |
| 1150 | { |
| 1151 | continue_read(); |
| 1152 | error = IDE_ERROR_DEFAULT; |
| 1153 | } |
| 1154 | |
| 1065 | 1155 | READ16_MEMBER( ide_controller_device::read_cs1_pc ) |
| 1066 | 1156 | { |
| 1067 | 1157 | if (mem_mask == 0xff00) |
| r23572 | r23573 | |
| 1170 | 1260 | } |
| 1171 | 1261 | } |
| 1172 | 1262 | |
| 1263 | void ide_controller_device::write_dma( UINT16 data ) |
| 1264 | { |
| 1265 | buffer[buffer_offset++] = data; |
| 1266 | buffer[buffer_offset++] = data >> 8; |
| 1267 | |
| 1268 | /* if we're at the end of the buffer, handle it */ |
| 1269 | if (buffer_offset >= IDE_DISK_SECTOR_SIZE) |
| 1270 | { |
| 1271 | LOG(("%s:IDE completed DMA write\n", machine().describe_context())); |
| 1272 | write_buffer_full(); |
| 1273 | } |
| 1274 | } |
| 1275 | |
| 1173 | 1276 | WRITE16_MEMBER( ide_controller_device::write_cs0 ) |
| 1174 | 1277 | { |
| 1175 | 1278 | // printf( "write cs0 %04x %04x %04x\n", offset, data, mem_mask ); |
| r23572 | r23573 | |
| 1204 | 1307 | if (buffer_offset >= IDE_DISK_SECTOR_SIZE) |
| 1205 | 1308 | { |
| 1206 | 1309 | LOG(("%s:IDE completed PIO write\n", machine().describe_context())); |
| 1207 | | if (command == IDE_COMMAND_SECURITY_UNLOCK) |
| 1208 | | { |
| 1209 | | if (user_password_enable && memcmp(buffer, user_password, 2 + 32) == 0) |
| 1210 | | { |
| 1211 | | LOGPRINT(("IDE Unlocked user password\n")); |
| 1212 | | user_password_enable = 0; |
| 1213 | | } |
| 1214 | | if (master_password_enable && memcmp(buffer, master_password, 2 + 32) == 0) |
| 1215 | | { |
| 1216 | | LOGPRINT(("IDE Unlocked master password\n")); |
| 1217 | | master_password_enable = 0; |
| 1218 | | } |
| 1219 | | if (PRINTF_IDE_PASSWORD) |
| 1220 | | { |
| 1221 | | int i; |
| 1222 | | |
| 1223 | | for (i = 0; i < 34; i += 2) |
| 1224 | | { |
| 1225 | | if (i % 8 == 2) |
| 1226 | | mame_printf_debug("\n"); |
| 1227 | | |
| 1228 | | mame_printf_debug("0x%02x, 0x%02x, ", buffer[i], buffer[i + 1]); |
| 1229 | | //mame_printf_debug("0x%02x%02x, ", buffer[i], buffer[i + 1]); |
| 1230 | | } |
| 1231 | | mame_printf_debug("\n"); |
| 1232 | | } |
| 1233 | | |
| 1234 | | /* clear the busy and error flags */ |
| 1235 | | status &= ~IDE_STATUS_ERROR; |
| 1236 | | status &= ~IDE_STATUS_BUSY; |
| 1237 | | status &= ~IDE_STATUS_BUFFER_READY; |
| 1238 | | |
| 1239 | | if (master_password_enable || user_password_enable) |
| 1240 | | security_error(); |
| 1241 | | else |
| 1242 | | status |= IDE_STATUS_DRIVE_READY; |
| 1243 | | } |
| 1244 | | else if (command == IDE_COMMAND_TAITO_GNET_UNLOCK_2) |
| 1245 | | { |
| 1246 | | UINT8 key[5] = { 0 }; |
| 1247 | | int i, bad = 0; |
| 1248 | | dev->read_key(key); |
| 1249 | | |
| 1250 | | for (i=0; !bad && i<512; i++) |
| 1251 | | bad = ((i < 2 || i >= 7) && buffer[i]) || ((i >= 2 && i < 7) && buffer[i] != key[i-2]); |
| 1252 | | |
| 1253 | | status &= ~IDE_STATUS_BUSY; |
| 1254 | | status &= ~IDE_STATUS_BUFFER_READY; |
| 1255 | | if (bad) |
| 1256 | | status |= IDE_STATUS_ERROR; |
| 1257 | | else { |
| 1258 | | status &= ~IDE_STATUS_ERROR; |
| 1259 | | gnetreadlock= 0; |
| 1260 | | } |
| 1261 | | } |
| 1262 | | else |
| 1263 | | continue_write(); |
| 1264 | | |
| 1310 | write_buffer_full(); |
| 1265 | 1311 | } |
| 1266 | 1312 | } |
| 1267 | 1313 | break; |
| r23572 | r23573 | |
| 1408 | 1454 | else |
| 1409 | 1455 | { |
| 1410 | 1456 | read_buffer_from_dma(); |
| 1411 | | continue_write(); |
| 1412 | 1457 | } |
| 1413 | 1458 | } |
| 1414 | 1459 | } |