Previous 199869 Revisions Next

r23713 Friday 14th June, 2013 at 19:17:43 UTC by smf
Renamed some #defines to match up closer to the ATA specification. Added validation to register access, switching Primal Rage 2 away from using the DMA interface in it's DMA handler as the game only executes normal read commands (nw)
[src/emu/machine]idectrl.c idectrl.h idehd.c idehd.h
[src/mame/drivers]zn.c

trunk/src/emu/machine/idehd.c
r23712r23713
2121#define TIME_SEEK_MULTISECTOR               (attotime::from_msec(13))
2222#define TIME_NO_SEEK_MULTISECTOR            (attotime::from_nsec(16300))
2323
24#define IDE_BANK0_DATA                      0
25#define IDE_BANK0_ERROR                     1
26#define IDE_BANK0_SECTOR_COUNT              2
27#define IDE_BANK0_SECTOR_NUMBER             3
28#define IDE_BANK0_CYLINDER_LSB              4
29#define IDE_BANK0_CYLINDER_MSB              5
30#define IDE_BANK0_HEAD_NUMBER               6
31#define IDE_BANK0_STATUS_COMMAND            7
24#define IDE_CS0_DATA_RW              0
25#define IDE_CS0_ERROR_R              1
26#define IDE_CS0_FEATURE_W            1
27#define IDE_CS0_SECTOR_COUNT_RW      2
28#define IDE_CS0_SECTOR_NUMBER_RW     3
29#define IDE_CS0_CYLINDER_LOW_RW      4
30#define IDE_CS0_CYLINDER_HIGH_RW     5
31#define IDE_CS0_DEVICE_HEAD_RW       6
32#define IDE_CS0_STATUS_R             7
33#define IDE_CS0_COMMAND_W            7
3234
33#define IDE_BANK1_STATUS_CONTROL            6
35#define IDE_CS1_ALTERNATE_STATUS_R   6
36#define IDE_CS1_DEVICE_CONTROL_W     6
3437
3538#define IDE_COMMAND_READ_SECTORS            0x20
3639#define IDE_COMMAND_READ_SECTORS_NORETRY    0x21
r23712r23713
9093   ide_device_interface(mconfig, *this),
9194   device_slot_card_interface(mconfig, *this),
9295   m_csel(0),
93   m_dasp(0)
96   m_dasp(0),
97   m_dmack(0),
98   m_dmarq(0),
99   m_irq(0)
94100{
95101}
96102
97103void ide_mass_storage_device::set_irq(int state)
98104{
99   if (state == ASSERT_LINE)
100      LOG(("IDE interrupt assert\n"));
101   else
102      LOG(("IDE interrupt clear\n"));
105   if (m_irq != state)
106   {
107      m_irq = state;
103108
104   m_interrupt_pending = state;
109      if (state == ASSERT_LINE)
110         LOG(("IDE interrupt assert\n"));
111      else
112         LOG(("IDE interrupt clear\n"));
105113
106   /* signal an interrupt */
107   m_irq_handler(state);
114      /* signal an interrupt */
115      m_irq_handler(state);
116   }
108117}
109118
110119void ide_mass_storage_device::set_dmarq(int state)
111120{
112   m_dmarq_handler(state);
121   if (m_dmarq != state)
122   {
123      m_dmarq = state;
124
125      m_dmarq_handler(state);
126   }
113127}
114128
115129WRITE_LINE_MEMBER( ide_mass_storage_device::write_csel )
r23712r23713
122136   m_dasp = state;
123137}
124138
139WRITE_LINE_MEMBER( ide_mass_storage_device::write_dmack )
140{
141   m_dmack = state;
142}
143
125144/*************************************
126145 *
127146 *  Compute the LBA address
r23712r23713
340359   save_item(NAME(m_command));
341360   save_item(NAME(m_error));
342361
343   save_item(NAME(m_adapter_control));
344   save_item(NAME(m_precomp_offset));
362   save_item(NAME(m_device_control));
363   save_item(NAME(m_feature));
345364   save_item(NAME(m_sector_count));
346365
347   save_item(NAME(m_interrupt_pending));
366   save_item(NAME(m_irq));
367   save_item(NAME(m_dmarq));
348368   save_item(NAME(m_sectors_until_int));
349369
350370   save_item(NAME(m_master_password_enable));
r23712r23713
368388   m_master_password_enable = (m_master_password != NULL);
369389   m_user_password_enable = (m_user_password != NULL);
370390   m_error = IDE_ERROR_DEFAULT;
371   m_status = IDE_STATUS_DRIVE_READY | IDE_STATUS_SEEK_COMPLETE;
391
392   m_status = IDE_STATUS_DSC;
393   if (is_ready())
394   {
395      m_status |= IDE_STATUS_DRDY;
396   }
397
372398   m_cur_drive = 0;
373399
374400   /* reset the drive state */
r23712r23713
381407   switch(id)
382408   {
383409   case TID_DELAYED_INTERRUPT:
384      m_status &= ~IDE_STATUS_BUSY;
410      m_status &= ~IDE_STATUS_BSY;
385411      set_irq(ASSERT_LINE);
386412      break;
387413
388414   case TID_DELAYED_INTERRUPT_BUFFER_READY:
389      m_status &= ~IDE_STATUS_BUSY;
390      m_status |= IDE_STATUS_BUFFER_READY;
415      m_status &= ~IDE_STATUS_BSY;
416      m_status |= IDE_STATUS_DRQ;
417
391418      set_irq(ASSERT_LINE);
392419      break;
393420
r23712r23713
397424
398425   case TID_SECURITY_ERROR_DONE:
399426      /* clear error state */
400      m_status &= ~IDE_STATUS_ERROR;
401      m_status |= IDE_STATUS_DRIVE_READY;
427      m_status &= ~IDE_STATUS_ERR;
428      m_status |= IDE_STATUS_DRDY;
402429      break;
403430
404431   case TID_READ_SECTOR_DONE_CALLBACK:
r23712r23713
414441void ide_mass_storage_device::signal_delayed_interrupt(attotime time, int buffer_ready)
415442{
416443   /* clear buffer ready and set the busy flag */
417   m_status &= ~IDE_STATUS_BUFFER_READY;
418   m_status |= IDE_STATUS_BUSY;
444   m_status &= ~IDE_STATUS_DRQ;
445   m_status |= IDE_STATUS_BSY;
419446
420447   /* set a timer */
421448   if (buffer_ready)
r23712r23713
476503void ide_mass_storage_device::security_error()
477504{
478505   /* set error state */
479   m_status |= IDE_STATUS_ERROR;
480   m_status &= ~IDE_STATUS_DRIVE_READY;
506   m_status |= IDE_STATUS_ERR;
507   m_status &= ~IDE_STATUS_DRDY;
481508
482509   /* just set a timer and mark ourselves error */
483510   timer_set(TIME_SECURITY_ERROR, TID_SECURITY_ERROR_DONE);
r23712r23713
497524   m_buffer_offset = 0;
498525
499526   /* clear the buffer ready and busy flag */
500   m_status &= ~IDE_STATUS_BUFFER_READY;
501   m_status &= ~IDE_STATUS_BUSY;
527   m_status &= ~IDE_STATUS_DRQ;
528   m_status &= ~IDE_STATUS_BSY;
502529   m_error = IDE_ERROR_DEFAULT;
503530   set_dmarq(CLEAR_LINE);
504531
r23712r23713
525552
526553   /* GNET readlock check */
527554   if (m_gnetreadlock) {
528      m_status &= ~IDE_STATUS_ERROR;
529      m_status &= ~IDE_STATUS_BUSY;
555      m_status &= ~IDE_STATUS_ERR;
556      m_status &= ~IDE_STATUS_BSY;
530557      return;
531558   }
532559
r23712r23713
535562
536563   /* by default, mark the buffer ready and the seek complete */
537564   if (!m_verify_only)
538      m_status |= IDE_STATUS_BUFFER_READY;
539   m_status |= IDE_STATUS_SEEK_COMPLETE;
565      m_status |= IDE_STATUS_DRQ;
540566
567   m_status |= IDE_STATUS_DSC;
568
541569   /* and clear the busy and error flags */
542   m_status &= ~IDE_STATUS_ERROR;
543   m_status &= ~IDE_STATUS_BUSY;
570   m_status &= ~IDE_STATUS_ERR;
571   m_status &= ~IDE_STATUS_BSY;
544572
545573   /* if we succeeded, advance to the next sector and set the nice bits */
546574   if (count == 1)
r23712r23713
575603   else
576604   {
577605      /* set the error flag and the error */
578      m_status |= IDE_STATUS_ERROR;
606      m_status |= IDE_STATUS_ERR;
579607      m_error = IDE_ERROR_BAD_SECTOR;
580608
581609      /* signal an interrupt */
r23712r23713
587615void ide_mass_storage_device::read_first_sector()
588616{
589617   /* mark ourselves busy */
590   m_status |= IDE_STATUS_BUSY;
618   m_status |= IDE_STATUS_BSY;
591619
592620   /* just set a timer */
593621   if (m_command == IDE_COMMAND_READ_MULTIPLE)
r23712r23713
611639void ide_mass_storage_device::read_next_sector()
612640{
613641   /* mark ourselves busy */
614   m_status |= IDE_STATUS_BUSY;
642   m_status |= IDE_STATUS_BSY;
615643
616644   if (m_command == IDE_COMMAND_READ_MULTIPLE)
617645   {
r23712r23713
641669   m_buffer_offset = 0;
642670
643671   /* clear the buffer ready flag */
644   m_status &= ~IDE_STATUS_BUFFER_READY;
645   m_status |= IDE_STATUS_BUSY;
672   m_status &= ~IDE_STATUS_DRQ;
673   m_status |= IDE_STATUS_BSY;
646674
647675   if (m_command == IDE_COMMAND_WRITE_MULTIPLE)
648676   {
r23712r23713
668696void ide_mass_storage_device::write_buffer_full()
669697{
670698   set_dmarq(CLEAR_LINE);
699
671700   if (m_command == IDE_COMMAND_SECURITY_UNLOCK)
672701   {
673702      if (m_user_password_enable && memcmp(m_buffer, m_user_password, 2 + 32) == 0)
r23712r23713
696725      }
697726
698727      /* clear the busy and error flags */
699      m_status &= ~IDE_STATUS_ERROR;
700      m_status &= ~IDE_STATUS_BUSY;
701      m_status &= ~IDE_STATUS_BUFFER_READY;
728      m_status &= ~IDE_STATUS_ERR;
729      m_status &= ~IDE_STATUS_BSY;
730      m_status &= ~IDE_STATUS_DRQ;
702731
703732      if (m_master_password_enable || m_user_password_enable)
704733         security_error();
705734      else
706         m_status |= IDE_STATUS_DRIVE_READY;
735         m_status |= IDE_STATUS_DRDY;
707736   }
708737   else if (m_command == IDE_COMMAND_TAITO_GNET_UNLOCK_2)
709738   {
r23712r23713
714743      for (i=0; !bad && i<512; i++)
715744         bad = ((i < 2 || i >= 7) && m_buffer[i]) || ((i >= 2 && i < 7) && m_buffer[i] != key[i-2]);
716745
717      m_status &= ~IDE_STATUS_BUSY;
718      m_status &= ~IDE_STATUS_BUFFER_READY;
746      m_status &= ~IDE_STATUS_BSY;
747      m_status &= ~IDE_STATUS_DRQ;
719748      if (bad)
720         m_status |= IDE_STATUS_ERROR;
749         m_status |= IDE_STATUS_ERR;
721750      else {
722         m_status &= ~IDE_STATUS_ERROR;
751         m_status &= ~IDE_STATUS_ERR;
723752         m_gnetreadlock= 0;
724753      }
725754   }
r23712r23713
738767   count = write_sector(lba, m_buffer);
739768
740769   /* by default, mark the buffer ready and the seek complete */
741   m_status |= IDE_STATUS_BUFFER_READY;
742   m_status |= IDE_STATUS_SEEK_COMPLETE;
770   m_status |= IDE_STATUS_DRQ;
771   m_status |= IDE_STATUS_DSC;
743772
744773   /* and clear the busy adn error flags */
745   m_status &= ~IDE_STATUS_ERROR;
746   m_status &= ~IDE_STATUS_BUSY;
774   m_status &= ~IDE_STATUS_ERR;
775   m_status &= ~IDE_STATUS_BSY;
747776
748777   /* if we succeeded, advance to the next sector and set the nice bits */
749778   if (count == 1)
r23712r23713
767796      if (m_sector_count > 0)
768797         m_sector_count--;
769798      if (m_sector_count == 0)
770         m_status &= ~IDE_STATUS_BUFFER_READY;
799         m_status &= ~IDE_STATUS_DRQ;
771800
772801      /* keep going for DMA */
773802      if (m_dma_active && m_sector_count != 0)
r23712r23713
780809   else
781810   {
782811      /* set the error flag and the error */
783      m_status |= IDE_STATUS_ERROR;
812      m_status |= IDE_STATUS_ERR;
784813      m_error = IDE_ERROR_BAD_SECTOR;
785814
786815      /* signal an interrupt */
r23712r23713
796825 *
797826 *************************************/
798827
799void ide_mass_storage_device::handle_command(UINT8 _command)
828void ide_mass_storage_device::handle_command()
800829{
801830   UINT8 key[5];
802831
803832   /* implicitly clear interrupts & dmarq here */
804833   set_irq(CLEAR_LINE);
805834   set_dmarq(CLEAR_LINE);
806   m_command = _command;
835
807836   switch (m_command)
808837   {
809838      case IDE_COMMAND_READ_SECTORS:
r23712r23713
875904         m_dma_active = 0;
876905
877906         /* mark the buffer ready */
878         m_status |= IDE_STATUS_BUFFER_READY;
907         m_status |= IDE_STATUS_DRQ;
879908         break;
880909
881910      case IDE_COMMAND_WRITE_MULTIPLE:
r23712r23713
888917         m_dma_active = 0;
889918
890919         /* mark the buffer ready */
891         m_status |= IDE_STATUS_BUFFER_READY;
920         m_status |= IDE_STATUS_DRQ;
892921         break;
893922
894923      case IDE_COMMAND_WRITE_DMA:
r23712r23713
900929         m_sectors_until_int = m_sector_count;
901930         m_dma_active = 1;
902931
932         /* mark the buffer ready */
933         m_status |= IDE_STATUS_DRQ;
934
903935         /* start the read going */
904936         set_dmarq(ASSERT_LINE);
905937         break;
r23712r23713
913945         m_dma_active = 0;
914946
915947         /* mark the buffer ready */
916         m_status |= IDE_STATUS_BUFFER_READY;
948         m_status |= IDE_STATUS_DRQ;
949
917950         set_irq(ASSERT_LINE);
918951         break;
919952
r23712r23713
928961         memcpy(m_buffer, m_features, sizeof(m_buffer));
929962
930963         /* indicate everything is ready */
931         m_status |= IDE_STATUS_BUFFER_READY;
932         m_status |= IDE_STATUS_SEEK_COMPLETE;
933         m_status |= IDE_STATUS_DRIVE_READY;
964         m_status |= IDE_STATUS_DRQ;
965         m_status |= IDE_STATUS_DSC;
966         m_status |= IDE_STATUS_DRDY;
934967
935968         /* and clear the busy adn error flags */
936         m_status &= ~IDE_STATUS_ERROR;
937         m_status &= ~IDE_STATUS_BUSY;
969         m_status &= ~IDE_STATUS_ERR;
970         m_status &= ~IDE_STATUS_BSY;
938971
939972         /* clear the error too */
940973         m_error = IDE_ERROR_NONE;
r23712r23713
9691002
9701003      case IDE_COMMAND_SET_CONFIG:
9711004         LOGPRINT(("IDE Set configuration (%d heads, %d sectors)\n", m_cur_head + 1, m_sector_count));
972         m_status &= ~IDE_STATUS_ERROR;
1005         m_status &= ~IDE_STATUS_ERR;
9731006         m_error = IDE_ERROR_NONE;
9741007         set_geometry(m_sector_count,m_cur_head + 1);
9751008
r23712r23713
9861019         break;
9871020
9881021      case IDE_COMMAND_SET_FEATURES:
989         LOGPRINT(("IDE Set features (%02X %02X %02X %02X %02X)\n", m_precomp_offset, m_sector_count & 0xff, m_cur_sector, m_cur_cylinder & 0xff, m_cur_cylinder >> 8));
1022         LOGPRINT(("IDE Set features (%02X %02X %02X %02X %02X)\n", m_feature, m_sector_count & 0xff, m_cur_sector, m_cur_cylinder & 0xff, m_cur_cylinder >> 8));
9901023
9911024         /* signal an interrupt */
9921025         signal_delayed_interrupt(MINIMUM_COMMAND_TIME, 0);
r23712r23713
9971030
9981031         m_block_count = m_sector_count;
9991032         // judge dredd wants 'drive ready' on this command
1000         m_status |= IDE_STATUS_DRIVE_READY;
1033         m_status |= IDE_STATUS_DRDY;
10011034
10021035         /* signal an interrupt */
10031036         set_irq(ASSERT_LINE);
r23712r23713
10071040         LOGPRINT(("IDE GNET Unlock 1\n"));
10081041
10091042         m_sector_count = 1;
1010         m_status |= IDE_STATUS_DRIVE_READY;
1011         m_status &= ~IDE_STATUS_ERROR;
1043         m_status |= IDE_STATUS_DRDY;
1044         m_status &= ~IDE_STATUS_ERR;
10121045         set_irq(ASSERT_LINE);
10131046         break;
10141047
r23712r23713
10211054         m_dma_active = 0;
10221055
10231056         /* mark the buffer ready */
1024         m_status |= IDE_STATUS_BUFFER_READY;
1057         m_status |= IDE_STATUS_DRQ;
1058
10251059         set_irq(ASSERT_LINE);
10261060         break;
10271061
r23712r23713
10301064
10311065         /* key check */
10321066         read_key(key);
1033         if ((m_precomp_offset == key[0]) && (m_sector_count == key[1]) && (m_cur_sector == key[2]) && (m_cur_cylinder == (((UINT16)key[4]<<8)|key[3])))
1067         if ((m_feature == key[0]) && (m_sector_count == key[1]) && (m_cur_sector == key[2]) && (m_cur_cylinder == (((UINT16)key[4]<<8)|key[3])))
10341068         {
10351069            m_gnetreadlock= 0;
10361070         }
10371071
10381072         /* update flags */
1039         m_status |= IDE_STATUS_DRIVE_READY;
1040         m_status &= ~IDE_STATUS_ERROR;
1073         m_status |= IDE_STATUS_DRDY;
1074         m_status &= ~IDE_STATUS_ERR;
10411075         set_irq(ASSERT_LINE);
10421076         break;
10431077
r23712r23713
10591093
10601094      default:
10611095         LOGPRINT(("IDE unknown command (%02X)\n", m_command));
1062         m_status |= IDE_STATUS_ERROR;
1096         m_status |= IDE_STATUS_ERR;
10631097         m_error = IDE_ERROR_UNKNOWN_COMMAND;
10641098         set_irq(ASSERT_LINE);
10651099         //debugger_break(device->machine());
r23712r23713
10691103
10701104UINT16 ide_mass_storage_device::read_dma()
10711105{
1072   if (m_cur_drive != m_csel)
1106   UINT16 result = 0xffff;
1107
1108   if (device_selected())
10731109   {
1074      if (m_csel == 0 && m_dasp == 0)
1075         return 0;
1110      if (!m_dmack)
1111      {
1112         logerror( "%s: read_dma ignored (!DMACK)\n", machine().describe_context() );
1113      }
1114      else if( !m_dmarq)
1115      {
1116         logerror( "%s: read_dma ignored (!DMARQ)\n", machine().describe_context() );
1117      }
1118      else if (m_status & IDE_STATUS_BSY)
1119      {
1120         logerror( "%s: read_dma ignored (BSY)\n", machine().describe_context() );
1121      }
1122      else if (!(m_status & IDE_STATUS_DRQ))
1123      {
1124         logerror( "%s: read_dma ignored (!DRQ)\n", machine().describe_context() );
1125      }
1126      else
1127      {
1128         result = m_buffer[m_buffer_offset++];
1129         result |= m_buffer[m_buffer_offset++] << 8;
10761130
1077      return 0xffff;
1131         if (m_buffer_offset >= IDE_DISK_SECTOR_SIZE)
1132         {
1133            LOG(("%s:IDE completed DMA read\n", machine().describe_context()));
1134            read_buffer_empty();
1135         }
1136      }
10781137   }
10791138
1080   UINT16 result = m_buffer[m_buffer_offset++];
1081   result |= m_buffer[m_buffer_offset++] << 8;
1082
1083   if (m_buffer_offset >= IDE_DISK_SECTOR_SIZE)
1084   {
1085      LOG(("%s:IDE completed DMA read\n", machine().describe_context()));
1086      read_buffer_empty();
1087   }
1088
10891139   return result;
10901140}
10911141
10921142READ16_MEMBER( ide_mass_storage_device::read_cs0 )
10931143{
1094   UINT16 result = 0;
1095
10961144   /* logit */
1097//  if (offset != IDE_BANK0_DATA && offset != IDE_BANK0_STATUS_COMMAND)
1145//  if (offset != IDE_CS0_DATA_RW && offset != IDE_CS0_STATUS_R)
10981146      LOG(("%s:IDE cs0 read at %X, mem_mask=%d\n", machine().describe_context(), offset, mem_mask));
10991147
1100   if (m_cur_drive != m_csel)
1101   {
1102      if (m_csel == 0 && m_dasp == 0)
1103         return 0;
1148   UINT16 result = 0xffff;
11041149
1105      return 0xffff;
1106   }
1107
1108   if (is_ready()) {
1109      m_status |= IDE_STATUS_DRIVE_READY;
1110   } else {
1111      m_status &= ~IDE_STATUS_DRIVE_READY;
1112   }
1113
1114   switch (offset)
1150   if (device_selected() || single_device())
11151151   {
1116      /* read data if there's data to be read */
1117      case IDE_BANK0_DATA:
1118         if (m_status & IDE_STATUS_BUFFER_READY)
1152      if (m_dmack)
1153      {
1154         logerror( "%s: read_cs0 %04x %04x ignored (DMACK)\n", machine().describe_context(), offset, mem_mask );
1155      }
1156      else if ((m_status & IDE_STATUS_BSY) && offset != IDE_CS0_STATUS_R)
1157      {
1158         if (device_selected())
11191159         {
1120            /* fetch the correct amount of data */
1121            result = m_buffer[m_buffer_offset++];
1122            if (mem_mask == 0xffff)
1123               result |= m_buffer[m_buffer_offset++] << 8;
1160            switch (offset)
1161            {
1162               case IDE_CS0_DATA_RW:
1163                  logerror( "%s: read_cs0 %04x %04x ignored (BSY)\n", machine().describe_context(), offset, mem_mask );
1164                  break;
11241165
1125            /* if we're at the end of the buffer, handle it */
1126            if (m_buffer_offset >= IDE_DISK_SECTOR_SIZE)
1127            {
1128               LOG(("%s:IDE completed PIO read\n", machine().describe_context()));
1129               read_buffer_empty();
1166               default:
1167                  result = m_status;
1168
1169                  if (m_last_status_timer->elapsed() > TIME_PER_ROTATION)
1170                  {
1171                     result |= IDE_STATUS_IDX;
1172                     m_last_status_timer->adjust(attotime::never);
1173                  }
1174                  break;
11301175            }
11311176         }
1132         break;
1177         else
1178         {
1179            result = 0;
1180         }
1181      }
1182      else
1183      {
1184         switch (offset)
1185         {
1186            /* read data if there's data to be read */
1187            case IDE_CS0_DATA_RW:
1188               if (device_selected())
1189               {
1190                  if (m_status & IDE_STATUS_DRQ)
1191                  {
1192                     /* fetch the correct amount of data */
1193                     result = m_buffer[m_buffer_offset++];
1194                     if (mem_mask == 0xffff)
1195                        result |= m_buffer[m_buffer_offset++] << 8;
11331196
1134      /* return the current error */
1135      case IDE_BANK0_ERROR:
1136         result = m_error;
1137         break;
1197                     /* if we're at the end of the buffer, handle it */
1198                     if (m_buffer_offset >= IDE_DISK_SECTOR_SIZE)
1199                     {
1200                        LOG(("%s:IDE completed PIO read\n", machine().describe_context()));
1201                        read_buffer_empty();
1202                     }
1203                  }
1204               }
1205               else
1206               {
1207                  result = 0;
1208               }
1209               break;
11381210
1139      /* return the current sector count */
1140      case IDE_BANK0_SECTOR_COUNT:
1141         result = m_sector_count;
1142         break;
1211            /* return the current error */
1212            case IDE_CS0_ERROR_R:
1213               result = m_error;
1214               break;
11431215
1144      /* return the current sector */
1145      case IDE_BANK0_SECTOR_NUMBER:
1146         result = m_cur_sector;
1147         break;
1216            /* return the current sector count */
1217            case IDE_CS0_SECTOR_COUNT_RW:
1218               result = m_sector_count;
1219               break;
11481220
1149      /* return the current cylinder LSB */
1150      case IDE_BANK0_CYLINDER_LSB:
1151         result = m_cur_cylinder & 0xff;
1152         break;
1221            /* return the current sector */
1222            case IDE_CS0_SECTOR_NUMBER_RW:
1223               result = m_cur_sector;
1224               break;
11531225
1154      /* return the current cylinder MSB */
1155      case IDE_BANK0_CYLINDER_MSB:
1156         result = m_cur_cylinder >> 8;
1157         break;
1226            /* return the current cylinder LSB */
1227            case IDE_CS0_CYLINDER_LOW_RW:
1228               result = m_cur_cylinder & 0xff;
1229               break;
11581230
1159      /* return the current head */
1160      case IDE_BANK0_HEAD_NUMBER:
1161         result = m_cur_head_reg;
1162         break;
1231            /* return the current cylinder MSB */
1232            case IDE_CS0_CYLINDER_HIGH_RW:
1233               result = m_cur_cylinder >> 8;
1234               break;
11631235
1164      /* return the current status and clear any pending interrupts */
1165      case IDE_BANK0_STATUS_COMMAND:
1166         result = m_status;
1167         if (m_last_status_timer->elapsed() > TIME_PER_ROTATION)
1168         {
1169            result |= IDE_STATUS_HIT_INDEX;
1170            m_last_status_timer->adjust(attotime::never);
1236            /* return the current head */
1237            case IDE_CS0_DEVICE_HEAD_RW:
1238               result = m_cur_head_reg;
1239               break;
1240
1241            /* return the current status and clear any pending interrupts */
1242            case IDE_CS0_STATUS_R:
1243               if (device_selected())
1244               {
1245                  result = m_status;
1246
1247                  if (m_last_status_timer->elapsed() > TIME_PER_ROTATION)
1248                  {
1249                     result |= IDE_STATUS_IDX;
1250                     m_last_status_timer->adjust(attotime::never);
1251                  }
1252
1253                  set_irq(CLEAR_LINE);
1254               }
1255               else
1256               {
1257                  result = 0;
1258               }
1259               break;
1260
1261            /* log anything else */
1262            default:
1263               logerror("%s:unknown IDE cs0 read at %03X, mem_mask=%d\n", machine().describe_context(), offset, mem_mask);
1264               break;
11711265         }
1172         if (m_interrupt_pending == ASSERT_LINE)
1173            set_irq(CLEAR_LINE);
1174         break;
1175
1176      /* log anything else */
1177      default:
1178         logerror("%s:unknown IDE cs0 read at %03X, mem_mask=%d\n", machine().describe_context(), offset, mem_mask);
1179         break;
1266      }
11801267   }
11811268
11821269   /* return the result */
r23712r23713
11851272
11861273READ16_MEMBER( ide_mass_storage_device::read_cs1 )
11871274{
1188   if (m_cur_drive != m_csel)
1189   {
1190      if (m_csel == 0 && m_dasp == 0)
1191         return 0;
1192
1193      return 0xffff;
1194   }
1195
1196   if (is_ready()) {
1197      m_status |= IDE_STATUS_DRIVE_READY;
1198   } else {
1199      m_status &= ~IDE_STATUS_DRIVE_READY;
1200   }
1201
12021275   /* logit */
1203//  if (offset != IDE_BANK1_STATUS_CONTROL)
1276//  if (offset != IDE_CS1_ALTERNATE_STATUS_R)
12041277      LOG(("%s:IDE cs1 read at %X, mem_mask=%d\n", machine().describe_context(), offset, mem_mask));
1205      /* return the current status but don't clear interrupts */
12061278
1207   UINT16 result = 0;
1279   UINT16 result = 0xffff;
12081280
1209   switch (offset)
1281   if (device_selected() || single_device())
12101282   {
1211      case IDE_BANK1_STATUS_CONTROL:
1212         result = m_status;
1213         if (m_last_status_timer->elapsed() > TIME_PER_ROTATION)
1283      if (m_dmack)
1284      {
1285         logerror( "%s: read_cs1 %04x %04x ignored (DMACK)\n", machine().describe_context(), offset, mem_mask );
1286      }
1287      else
1288      {
1289         switch (offset)
12141290         {
1215            result |= IDE_STATUS_HIT_INDEX;
1216            m_last_status_timer->adjust(attotime::never);
1291            case IDE_CS1_ALTERNATE_STATUS_R:
1292               if( device_selected() )
1293               {
1294                  /* return the current status but don't clear interrupts */
1295                  result = m_status;
1296                  if (m_last_status_timer->elapsed() > TIME_PER_ROTATION)
1297                  {
1298                     result |= IDE_STATUS_IDX;
1299                     m_last_status_timer->adjust(attotime::never);
1300                  }
1301               }
1302               else
1303               {
1304                  result = 0;
1305               }
1306               break;
1307
1308            /* log anything else */
1309            default:
1310               logerror("%s:unknown IDE cs1 read at %03X, mem_mask=%d\n", machine().describe_context(), offset, mem_mask);
1311               break;
12171312         }
1218         break;
1219
1220      /* log anything else */
1221      default:
1222         logerror("%s:unknown IDE cs1 read at %03X, mem_mask=%d\n", machine().describe_context(), offset, mem_mask);
1223         break;
1313      }
12241314   }
12251315
12261316   /* return the result */
r23712r23713
12291319
12301320void ide_mass_storage_device::write_dma( UINT16 data )
12311321{
1232   if (m_cur_drive != m_csel)
1233      return;
1322   if (device_selected())
1323   {
1324      if (!m_dmack)
1325      {
1326         logerror( "%s: write_dma %04x ignored (!DMACK)\n", machine().describe_context(), data );
1327      }
1328      else if( !m_dmarq)
1329      {
1330         logerror( "%s: write_dma %04x ignored (!DMARQ)\n", machine().describe_context(), data );
1331      }
1332      else if (m_status & IDE_STATUS_BSY)
1333      {
1334         logerror( "%s: write_dma %04x ignored (BSY)\n", machine().describe_context(), data );
1335      }
1336      else if (!(m_status & IDE_STATUS_DRQ))
1337      {
1338         logerror( "%s: write_dma %04x ignored (!DRQ)\n", machine().describe_context(), data );
1339      }
1340      else
1341      {
1342         m_buffer[m_buffer_offset++] = data;
1343         m_buffer[m_buffer_offset++] = data >> 8;
12341344
1235   m_buffer[m_buffer_offset++] = data;
1236   m_buffer[m_buffer_offset++] = data >> 8;
1237
1238   /* if we're at the end of the buffer, handle it */
1239   if (m_buffer_offset >= IDE_DISK_SECTOR_SIZE)
1240   {
1241      LOG(("%s:IDE completed DMA write\n", machine().describe_context()));
1242      write_buffer_full();
1345         /* if we're at the end of the buffer, handle it */
1346         if (m_buffer_offset >= IDE_DISK_SECTOR_SIZE)
1347         {
1348            LOG(("%s:IDE completed DMA write\n", machine().describe_context()));
1349            write_buffer_full();
1350         }
1351      }
12431352   }
12441353}
12451354
12461355WRITE16_MEMBER( ide_mass_storage_device::write_cs0 )
12471356{
1248   switch (offset)
1249   {
1250      case IDE_BANK0_HEAD_NUMBER:
1251         m_cur_drive = (data & 0x10) >> 4;
1252         break;
1253   }
1254
1255   if (m_cur_drive != m_csel)
1256      return;
1257
12581357   /* logit */
1259   if (offset != IDE_BANK0_DATA)
1358   if (offset != IDE_CS0_DATA_RW)
12601359      LOG(("%s:IDE cs0 write to %X = %08X, mem_mask=%d\n", machine().describe_context(), offset, data, mem_mask));
12611360   //  fprintf(stderr, "ide write %03x %02x mem_mask=%d\n", offset, data, size);
1262   switch (offset)
1361
1362   if (m_dmack)
12631363   {
1264      /* write data */
1265      case IDE_BANK0_DATA:
1266         if (m_status & IDE_STATUS_BUFFER_READY)
1267         {
1268            /* store the correct amount of data */
1269            m_buffer[m_buffer_offset++] = data;
1270            if (mem_mask == 0xffff)
1271               m_buffer[m_buffer_offset++] = data >> 8;
1364      logerror( "%s: write_cs0 %04x %04x %04x ignored (DMACK)\n", machine().describe_context(), offset, data, mem_mask );
1365   }
1366   else if ((m_status & IDE_STATUS_BSY) && offset != IDE_CS0_COMMAND_W)
1367   {
1368      logerror( "%s: write_cs0 %04x %04x %04x ignored (BSY)\n", machine().describe_context(), offset, data, mem_mask );
1369   }
1370   else if ((m_status & IDE_STATUS_DRQ) && offset != IDE_CS0_DATA_RW && offset != IDE_CS0_COMMAND_W)
1371   {
1372      logerror( "%s: write_cs0 %04x %04x %04x ignored (DRQ)\n", machine().describe_context(), offset, data, mem_mask );
1373   }
1374   else
1375   {
1376      switch (offset)
1377      {
1378         /* write data */
1379         case IDE_CS0_DATA_RW:
1380            if( device_selected() )
1381            {
1382               if (!(m_status & IDE_STATUS_DRQ))
1383               {
1384                  logerror( "%s: write_cs0 %04x %04x %04x ignored (!DRQ)\n", machine().describe_context(), offset, data, mem_mask );
1385               }
1386               else
1387               {
1388                  /* store the correct amount of data */
1389                  m_buffer[m_buffer_offset++] = data;
1390                  if (mem_mask == 0xffff)
1391                     m_buffer[m_buffer_offset++] = data >> 8;
12721392
1273            /* if we're at the end of the buffer, handle it */
1274            if (m_buffer_offset >= IDE_DISK_SECTOR_SIZE)
1275            {
1276               LOG(("%s:IDE completed PIO write\n", machine().describe_context()));
1277               write_buffer_full();
1393                  /* if we're at the end of the buffer, handle it */
1394                  if (m_buffer_offset >= IDE_DISK_SECTOR_SIZE)
1395                  {
1396                     LOG(("%s:IDE completed PIO write\n", machine().describe_context()));
1397                     write_buffer_full();
1398                  }
1399               }
12781400            }
1279         }
1280         break;
1401            break;
12811402
1282      /* precompensation offset?? */
1283      case IDE_BANK0_ERROR:
1284         m_precomp_offset = data;
1285         break;
1403         case IDE_CS0_FEATURE_W:
1404            m_feature = data;
1405            break;
12861406
1287      /* sector count */
1288      case IDE_BANK0_SECTOR_COUNT:
1289         m_sector_count = data ? data : 256;
1290         break;
1407         /* sector count */
1408         case IDE_CS0_SECTOR_COUNT_RW:
1409            m_sector_count = data ? data : 256;
1410            break;
12911411
1292      /* current sector */
1293      case IDE_BANK0_SECTOR_NUMBER:
1294         m_cur_sector = data;
1295         break;
1412         /* current sector */
1413         case IDE_CS0_SECTOR_NUMBER_RW:
1414            m_cur_sector = data;
1415            break;
12961416
1297      /* current cylinder LSB */
1298      case IDE_BANK0_CYLINDER_LSB:
1299         m_cur_cylinder = (m_cur_cylinder & 0xff00) | (data & 0xff);
1300         break;
1417         /* current cylinder LSB */
1418         case IDE_CS0_CYLINDER_LOW_RW:
1419            m_cur_cylinder = (m_cur_cylinder & 0xff00) | (data & 0xff);
1420            break;
13011421
1302      /* current cylinder MSB */
1303      case IDE_BANK0_CYLINDER_MSB:
1304         m_cur_cylinder = (m_cur_cylinder & 0x00ff) | ((data & 0xff) << 8);
1305         break;
1422         /* current cylinder MSB */
1423         case IDE_CS0_CYLINDER_HIGH_RW:
1424            m_cur_cylinder = ((data << 8) & 0xff00) | (m_cur_cylinder & 0xff);
1425            break;
13061426
1307      /* current head */
1308      case IDE_BANK0_HEAD_NUMBER:
1309         m_cur_head = data & 0x0f;
1310         m_cur_head_reg = data;
1311         // LBA mode = data & 0x40
1312         break;
1427         /* current head */
1428         case IDE_CS0_DEVICE_HEAD_RW:
1429            // LBA mode = data & 0x40
1430            m_cur_drive = (data & 0x10) >> 4;
1431            m_cur_head = data & 0x0f;
1432            m_cur_head_reg = data;
1433            break;
13131434
1314      /* command */
1315      case IDE_BANK0_STATUS_COMMAND:
1316         handle_command(data);
1317         break;
1435         /* command */
1436         case IDE_CS0_COMMAND_W:
1437            m_command = data;
1438
1439            if (device_selected() || m_command == IDE_COMMAND_DIAGNOSTIC)
1440               handle_command();
1441            break;
1442      }
13181443   }
13191444}
13201445
13211446WRITE16_MEMBER( ide_mass_storage_device::write_cs1 )
13221447{
1323   if (m_cur_drive != m_csel)
1324      return;
1325
13261448   /* logit */
13271449   LOG(("%s:IDE cs1 write to %X = %08X, mem_mask=%d\n", machine().describe_context(), offset, data, mem_mask));
13281450
1329   switch (offset)
1451   if (m_dmack)
13301452   {
1331      /* adapter control */
1332      case IDE_BANK1_STATUS_CONTROL:
1333         m_adapter_control = data;
1453      logerror( "%s: write_cs1 %04x %04x %04x ignored (DMACK)\n", machine().describe_context(), offset, data, mem_mask );
1454   }
1455   else
1456   {
1457      switch (offset)
1458      {
1459         /* adapter control */
1460         case IDE_CS1_DEVICE_CONTROL_W:
1461            m_device_control = data;
13341462
1335         /* handle controller reset */
1336         //if (data == 0x04)
1337         if (data & 0x04)
1338         {
1339            m_status |= IDE_STATUS_BUSY;
1340            m_status &= ~IDE_STATUS_DRIVE_READY;
1341            m_reset_timer->adjust(attotime::from_msec(5));
1342         }
1343         break;
1463            if (data & 0x02)
1464            {
1465               // nIEN
1466               logerror( "%s: write_cs1 %04x %04x %04x nIEN not supported\n", machine().describe_context(), offset, data, mem_mask );
1467            }
1468
1469            if (data & 0x04)
1470            {
1471               // SRST
1472               m_status |= IDE_STATUS_BSY;
1473               m_status &= ~IDE_STATUS_DRDY;
1474               m_reset_timer->adjust(attotime::from_msec(5));
1475            }
1476            break;
1477      }
13441478   }
13451479}
13461480
r23712r23713
13711505
13721506void ide_hdd_device::device_reset()
13731507{
1374   ide_mass_storage_device::device_reset();
1375
13761508   m_handle = subdevice<harddisk_image_device>("harddisk")->get_chd_file();
13771509
13781510   if (m_handle)
r23712r23713
13851517      m_disk = hard_disk_open(m_handle);
13861518   }
13871519
1520   ide_mass_storage_device::device_reset();
1521
13881522   if (m_disk != NULL)
13891523   {
13901524      const hard_disk_info *hdinfo = hard_disk_get_info(m_disk);
trunk/src/emu/machine/idehd.h
r23712r23713
33
44#define IDE_DISK_SECTOR_SIZE            512
55
6#define IDE_STATUS_ERROR                    0x01
7#define IDE_STATUS_HIT_INDEX                0x02
8#define IDE_STATUS_BUFFER_READY             0x08
9#define IDE_STATUS_SEEK_COMPLETE            0x10
10#define IDE_STATUS_DRIVE_READY              0x40
11#define IDE_STATUS_BUSY                     0x80
6// Error
7#define IDE_STATUS_ERR  (0x01)
128
9// Index
10#define IDE_STATUS_IDX  (0x02)
11
12// Corrected Data
13#define IDE_STATUS_CORR (0x04)
14
15// Data Request
16#define IDE_STATUS_DRQ  (0x08)
17
18// Drive Seek Complete
19#define IDE_STATUS_DSC  (0x10)
20
21// Drive Write Fault
22#define IDE_STATUS_DWF  (0x20)
23
24// Drive Ready
25#define IDE_STATUS_DRDY (0x40)
26
27// Busy
28#define IDE_STATUS_BSY  (0x80)
29
1330#define IDE_ERROR_NONE                      0x00
1431#define IDE_ERROR_DEFAULT                   0x01
1532#define IDE_ERROR_TRACK0_NOT_FOUND          0x02
r23712r23713
3249   virtual void write_dma(UINT16 data) = 0;
3350   virtual DECLARE_WRITE16_MEMBER(write_cs0) = 0;
3451   virtual DECLARE_WRITE16_MEMBER(write_cs1) = 0;
52   virtual DECLARE_WRITE_LINE_MEMBER(write_dmack) = 0;
3553   virtual DECLARE_WRITE_LINE_MEMBER(write_csel) = 0;
3654   virtual DECLARE_WRITE_LINE_MEMBER(write_dasp) = 0;
3755
r23712r23713
6280   virtual DECLARE_WRITE16_MEMBER(write_cs1);
6381   virtual DECLARE_WRITE_LINE_MEMBER(write_csel);
6482   virtual DECLARE_WRITE_LINE_MEMBER(write_dasp);
83   virtual DECLARE_WRITE_LINE_MEMBER(write_dmack);
6584
6685   virtual UINT8 *get_features() { return m_features; }
6786   
r23712r23713
7594   virtual bool is_ready() = 0;
7695   virtual void read_key(UINT8 key[]) = 0;
7796
97   bool device_selected() { return m_cur_drive == m_csel; }
98   bool single_device() { return m_csel == 0 && m_dasp == 0; }
99
78100   void set_irq(int state);
79101   void set_dmarq(int state);
80102   void ide_build_features();
r23712r23713
98120   void security_error();
99121   void continue_read();
100122   void read_first_sector();
101   void handle_command(UINT8 _command);
123   void handle_command();
102124   void read_buffer_empty();
103125   void write_buffer_full();
104126
105127   int m_csel;
106128   int m_dasp;
129   int m_dmack;
130   int m_dmarq;
131   int m_irq;
107132
108133   int             m_cur_drive;
109134   UINT16          m_cur_cylinder;
r23712r23713
119144   UINT8           m_buffer[IDE_DISK_SECTOR_SIZE];
120145   UINT16          m_buffer_offset;
121146
122   UINT8           m_adapter_control;
123   UINT8           m_precomp_offset;
147   UINT8           m_device_control;
148   UINT8           m_feature;
124149   UINT16          m_sector_count;
125150   UINT16          m_block_count;
126151
127   UINT8           m_interrupt_pending;
128152   UINT16          m_sectors_until_int;
129153
130154   UINT8           m_dma_active;
trunk/src/emu/machine/idectrl.c
r23712r23713
232232         m_slot[i]->dev()->write_cs1(space, offset, data, mem_mask);
233233}
234234
235WRITE_LINE_MEMBER( ide_controller_device::write_dmack )
236{
237//  printf( "write_dmack %04x\n", state );
238
239   for (int i = 0; i < 2; i++)
240      if (m_slot[i]->dev() != NULL)
241         m_slot[i]->dev()->write_dmack(state);
242}
243
235244WRITE8_MEMBER( ide_controller_device::write_via_config )
236245{
237246//  printf( "write via config %04x %04x %04x\n", offset, data, mem_mask );
r23712r23713
416425   dma_last_buffer(0),
417426   bus_master_command(0),
418427   bus_master_status(0),
419   bus_master_descriptor(0)
428   bus_master_descriptor(0),
429   m_irq(0),
430   m_dmarq(0)
420431{
421432}
422433
r23712r23713
568579
569580void bus_master_ide_controller_device::execute_dma()
570581{
582   write_dmack(ASSERT_LINE);
583
571584   while (m_dmarq && (bus_master_status & IDE_BUSMASTER_STATUS_ACTIVE))
572585   {
573586      /* if we're out of space, grab the next descriptor */
r23712r23713
624637         }
625638      }
626639   }
640
641   write_dmack(CLEAR_LINE);
627642}
trunk/src/emu/machine/idectrl.h
r23712r23713
9494   UINT16 read_dma();
9595   DECLARE_READ16_MEMBER(read_cs0);
9696   DECLARE_READ16_MEMBER(read_cs1);
97
9798   void write_dma(UINT16 data);
9899   DECLARE_WRITE16_MEMBER(write_cs0);
99100   DECLARE_WRITE16_MEMBER(write_cs1);
101   DECLARE_WRITE_LINE_MEMBER(write_dmack);
100102
101103   DECLARE_READ8_MEMBER(read_via_config);
102104   DECLARE_WRITE8_MEMBER(write_via_config);
trunk/src/mame/drivers/zn.c
r23712r23713
13381338      return;
13391339   }
13401340
1341   address_space &space = machine().firstcpu->space(AS_PROGRAM);
1342
13411343   /* dma size is in 32-bit words, convert to words */
13421344   n_size <<= 1;
13431345   while( n_size > 0 )
13441346   {
1345      psxwriteword( p_n_psxram, n_address, m_ide->read_dma() );
1347      psxwriteword( p_n_psxram, n_address, m_ide->read_cs0(space, 0, 0xffff) );
13461348      n_address += 2;
13471349      n_size--;
13481350   }

Previous 199869 Revisions Next


© 1997-2024 The MAME Team