Previous 199869 Revisions Next

r23724 Saturday 15th June, 2013 at 17:34:48 UTC by smf
Fixed ct486 booting with two chd's loaded. Moved the GNET protection command processing to ataflash.c (nw)
[src/emu/machine]ataflash.c ataflash.h idectrl.c idehd.c idehd.h
[src/mame/drivers]chihiro.c

trunk/src/emu/machine/idectrl.c
r23723r23724
351351         }
352352
353353         dev->write_csel(i);
354         dev->write_dasp(m_slot[1]->dev() != NULL && m_slot[1]->dev()->device_present());
354         dev->write_dasp(m_slot[1]->dev() != NULL);
355355      }
356356   }
357357
trunk/src/emu/machine/ataflash.c
r23723r23724
11#include "ataflash.h"
22
3#define IDE_COMMAND_TAITO_GNET_UNLOCK_1     0xfe
4#define IDE_COMMAND_TAITO_GNET_UNLOCK_2     0xfc
5#define IDE_COMMAND_TAITO_GNET_UNLOCK_3     0x0f
6
37const device_type ATA_FLASH_PCCARD = &device_creator<ata_flash_pccard_device>;
48
59ata_flash_pccard_device::ata_flash_pccard_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) :
r23723r23724
711{
812}
913
14void ata_flash_pccard_device::device_start()
15{
16   ide_hdd_device::device_start();
17
18   save_item(NAME(m_locked));
19   save_item(NAME(m_gnetreadlock));
20}
21
1022void ata_flash_pccard_device::device_reset()
1123{
24   ide_hdd_device::device_reset();
25
1226   m_locked = 0x1ff;
1327   m_gnetreadlock = 1;
1428
15   ide_hdd_device::device_reset();
16
1729   UINT32 metalength;
1830   memset(m_cis, 0xff, 512);
1931
r23723r23724
6678      return 0x002e;
6779
6880   case 0x201:
69      return m_locked ? 0x0001 : 0;
81      return m_gnetreadlock;
7082
7183   default:
7284      return 0;
r23723r23724
99111      }
100112   }
101113}
114
115bool ata_flash_pccard_device::is_ready()
116{
117   return !m_gnetreadlock;
118}
119
120bool ata_flash_pccard_device::process_command()
121{
122   UINT8 key[5];
123
124   switch (m_command)
125   {
126   case IDE_COMMAND_TAITO_GNET_UNLOCK_1:
127      //LOGPRINT(("IDE GNET Unlock 1\n"));
128
129      m_sector_count = 1;
130      m_status |= IDE_STATUS_DRDY;
131
132      set_irq(ASSERT_LINE);
133      return true;
134
135   case IDE_COMMAND_TAITO_GNET_UNLOCK_2:
136      //LOGPRINT(("IDE GNET Unlock 2\n"));
137
138      /* mark the buffer ready */
139      m_status |= IDE_STATUS_DRQ;
140
141      set_irq(ASSERT_LINE);
142      return true;
143
144   case IDE_COMMAND_TAITO_GNET_UNLOCK_3:
145      //LOGPRINT(("IDE GNET Unlock 3\n"));
146
147      /* key check */
148      read_key(key);
149      if (m_feature == key[0] && m_sector_count == key[1] && m_sector_number == key[2] && m_cylinder_low == key[3] && m_cylinder_high == key[4])
150      {
151         m_gnetreadlock = 0;
152      }
153      else
154      {
155         m_status &= ~IDE_STATUS_DRDY;
156      }
157
158      set_irq(ASSERT_LINE);
159      return true;
160
161   default:
162      if (m_gnetreadlock)
163      {
164         m_status |= IDE_STATUS_ERR;
165         m_error = IDE_ERROR_NONE;
166         m_status &= ~IDE_STATUS_DRDY;
167         return true;
168      }
169
170      return ide_hdd_device::process_command();
171   }
172}
173
174void ata_flash_pccard_device::process_buffer()
175{
176   if (m_command == IDE_COMMAND_TAITO_GNET_UNLOCK_2)
177   {
178      UINT8 key[5] = { 0 };
179      int i, bad = 0;
180      read_key(key);
181
182      for (i=0; !bad && i<512; i++)
183         bad = ((i < 2 || i >= 7) && m_buffer[i]) || ((i >= 2 && i < 7) && m_buffer[i] != key[i-2]);
184
185      if (bad)
186      {
187         m_status |= IDE_STATUS_ERR;
188         m_error = IDE_ERROR_NONE;
189      }
190      else
191      {
192         m_gnetreadlock= 0;
193      }
194   }
195   else
196   {
197      ide_hdd_device::process_buffer();
198   }
199}
trunk/src/emu/machine/ataflash.h
r23723r23724
2121
2222protected:
2323   // device-level overrides
24   virtual void device_start();
2425   virtual void device_reset();
2526
27   virtual bool process_command();
28   virtual void process_buffer();
29   virtual bool is_ready();
30
2631private:
2732   unsigned char m_cis[512];
33   UINT8 m_gnetreadlock;
2834   int m_locked;
2935};
3036
trunk/src/emu/machine/idehd.c
r23723r23724
5656#define IDE_COMMAND_SEEK                    0x70
5757#define IDE_COMMAND_IDLE_IMMEDIATE          0xe1
5858#define IDE_COMMAND_IDLE                    0xe3
59#define IDE_COMMAND_TAITO_GNET_UNLOCK_1     0xfe
60#define IDE_COMMAND_TAITO_GNET_UNLOCK_2     0xfc
61#define IDE_COMMAND_TAITO_GNET_UNLOCK_3     0x0f
6259
6360enum
6461{
r23723r23724
9895{
9996}
10097
98void ide_mass_storage_device::update_irq()
99{
100   if (device_selected() && (m_device_control & 2) == 0)
101      m_irq_handler(m_irq);
102   else
103      m_irq_handler(CLEAR_LINE);
104}
105
101106void ide_mass_storage_device::set_irq(int state)
102107{
103108   if (m_irq != state)
r23723r23724
109114      else
110115         LOG(("IDE interrupt clear\n"));
111116
112      /* signal an interrupt */
113      m_irq_handler(state);
117      update_irq();
114118   }
115119}
116120
r23723r23724
148152UINT32 ide_mass_storage_device::lba_address()
149153{
150154   /* LBA direct? */
151   if (m_cur_head_reg & 0x40)
152      return m_cur_sector + m_cur_cylinder * 256 + m_cur_head * 16777216;
155   if (m_device_head & 0x40)
156      return ((m_device_head & 0xf) << 24) | (m_cylinder_high << 16) | (m_cylinder_low << 8) | m_sector_number;
153157
154158   /* standard CHS */
155159   else
156      return (m_cur_cylinder * m_num_heads + m_cur_head) * m_num_sectors + m_cur_sector - 1;
160      return (((((m_cylinder_high << 8 ) | m_cylinder_low) * m_num_heads) + (m_device_head & 0xf)) * m_num_sectors) + m_sector_number - 1;
157161}
158162
159163
r23723r23724
341345   m_irq_handler.resolve_safe();
342346   m_dmarq_handler.resolve_safe();
343347
344   save_item(NAME(m_features));
345
346   save_item(NAME(m_cur_cylinder));
347   save_item(NAME(m_cur_sector));
348   save_item(NAME(m_cur_head));
349   save_item(NAME(m_cur_head_reg));
350
351   save_item(NAME(m_cur_lba));
352
353348   save_item(NAME(m_buffer));
354349   save_item(NAME(m_buffer_offset));
355
356   save_item(NAME(m_status));
357   save_item(NAME(m_command));
358350   save_item(NAME(m_error));
359
360   save_item(NAME(m_device_control));
361351   save_item(NAME(m_feature));
362352   save_item(NAME(m_sector_count));
353   save_item(NAME(m_sector_number));
354   save_item(NAME(m_cylinder_low));
355   save_item(NAME(m_cylinder_high));
356   save_item(NAME(m_device_head));
357   save_item(NAME(m_status));
358   save_item(NAME(m_command));
359   save_item(NAME(m_device_control));
363360
361   save_item(NAME(m_has_features));
362   save_item(NAME(m_features));
363   save_item(NAME(m_cur_lba));
364364   save_item(NAME(m_irq));
365365   save_item(NAME(m_dmarq));
366366   save_item(NAME(m_sectors_until_int));
367
368367   save_item(NAME(m_master_password_enable));
369368   save_item(NAME(m_user_password_enable));
370
371   save_item(NAME(m_gnetreadlock));
372369   save_item(NAME(m_block_count));
373370
374   save_item(NAME(m_dma_active));
375   save_item(NAME(m_verify_only));
376
377371   /* create a timer for timing status */
378372   m_last_status_timer = timer_alloc(TID_NULL);
379373   m_reset_timer = timer_alloc(TID_RESET_CALLBACK);
r23723r23724
382376void ide_mass_storage_device::device_reset()
383377{
384378   m_buffer_offset = 0;
385   m_gnetreadlock = 0;
386379   m_master_password_enable = (m_master_password != NULL);
387380   m_user_password_enable = (m_user_password != NULL);
388   m_error = IDE_ERROR_DIAGNOSTIC_PASSED;
389381
390382   m_status = IDE_STATUS_DSC;
391383
392   if (!m_gnetreadlock)
384   if (is_ready())
385   {
393386      m_status |= IDE_STATUS_DRDY;
387   }
394388
395   m_cur_drive = 0;
396
397389   /* reset the drive state */
398390   set_irq(CLEAR_LINE);
399391   set_dmarq(CLEAR_LINE);
r23723r23724
405397   {
406398   case TID_DELAYED_INTERRUPT:
407399      m_status &= ~IDE_STATUS_BSY;
400
408401      set_irq(ASSERT_LINE);
409402      break;
410403
r23723r23724
451444void ide_mass_storage_device::next_sector()
452445{
453446   /* LBA direct? */
454   if (m_cur_head_reg & 0x40)
447   if (m_device_head & 0x40)
455448   {
456      m_cur_sector++;
457      if (m_cur_sector == 0)
449      m_sector_number++;
450      if (m_sector_number == 0)
458451      {
459         m_cur_cylinder++;
460         if (m_cur_cylinder == 0)
461            m_cur_head++;
452         m_cylinder_low++;
453         if (m_cylinder_low == 0)
454         {
455            m_cylinder_high++;
456            if( m_cylinder_high == 0)
457               m_device_head = (m_device_head & ~0xf) | ((m_device_head + 1) & 0xf);
458         }
462459      }
463460   }
464461
r23723r23724
466463   else
467464   {
468465      /* sectors are 1-based */
469      m_cur_sector++;
470      if (m_cur_sector > m_num_sectors)
466      m_sector_number++;
467      if (m_sector_number > m_num_sectors)
471468      {
472469         /* heads are 0 based */
473         m_cur_sector = 1;
474         m_cur_head++;
475         if (m_cur_head >= m_num_heads)
470         m_sector_number = 1;
471         m_device_head = (m_device_head & ~0xf) | ((m_device_head + 1) & 0xf);
472         if ((m_device_head & 0xf) >= m_num_heads)
476473         {
477            m_cur_head = 0;
478            m_cur_cylinder++;
474            m_device_head &= ~0xf;
475            m_cylinder_low++;
476            if (m_cylinder_low == 0)
477               m_cylinder_high++;
479478         }
480479      }
481480   }
r23723r23724
537536
538537   m_status &= ~IDE_STATUS_BSY;
539538
540   /* GNET readlock check */
541   if (m_gnetreadlock)
542   {
543      return;
544   }
545
546539   /* now do the read */
547540   count = read_sector(lba, m_buffer);
548541
r23723r23724
555548         next_sector();
556549
557550      /* signal an interrupt */
558      if (!m_verify_only)
559         m_sectors_until_int--;
560      if (m_sectors_until_int == 0 || m_sector_count == 1)
551      if (--m_sectors_until_int == 0 || m_sector_count == 1)
561552      {
562553         m_sectors_until_int = ((m_command == IDE_COMMAND_READ_MULTIPLE) ? m_block_count : 1);
563554         set_irq(ASSERT_LINE);
564555      }
565556
566557      /* if we're just verifying we can read the next sector */
567      if (m_verify_only)
558      if (m_command == IDE_COMMAND_VERIFY_SECTORS ||
559         m_command == IDE_COMMAND_VERIFY_SECTORS_NORETRY )
568560      {
569561         read_buffer_empty();
570562      }
r23723r23724
572564      {
573565         m_status |= IDE_STATUS_DRQ;
574566
575         if (m_dma_active)
567         if (m_command == IDE_COMMAND_READ_DMA)
576568            set_dmarq(ASSERT_LINE);
577569      }
578570   }
r23723r23724
675667   m_status &= ~IDE_STATUS_DRQ;
676668   set_dmarq(CLEAR_LINE);
677669
670   process_buffer();
671}
672
673void ide_mass_storage_device::process_buffer()
674{
678675   if (m_command == IDE_COMMAND_SECURITY_UNLOCK)
679676   {
680677      if (m_user_password_enable && memcmp(m_buffer, m_user_password, 2 + 32) == 0)
r23723r23724
705702      if (m_master_password_enable || m_user_password_enable)
706703         security_error();
707704   }
708   else if (m_command == IDE_COMMAND_TAITO_GNET_UNLOCK_2)
709   {
710      UINT8 key[5] = { 0 };
711      int i, bad = 0;
712      read_key(key);
713
714      for (i=0; !bad && i<512; i++)
715         bad = ((i < 2 || i >= 7) && m_buffer[i]) || ((i >= 2 && i < 7) && m_buffer[i] != key[i-2]);
716
717      if (bad)
718      {
719         m_status |= IDE_STATUS_ERR;
720         m_error = IDE_ERROR_NONE;
721      }
722      else
723      {
724         m_gnetreadlock= 0;
725      }
726   }
727705   else
728706   {
729707      continue_write();
r23723r23724
763741      {
764742         m_status |= IDE_STATUS_DRQ;
765743
766         if (m_dma_active)
767         {
744         if (m_command == IDE_COMMAND_WRITE_DMA)
768745            set_dmarq(ASSERT_LINE);
769         }
770746      }
771747   }
772748
r23723r23724
783759}
784760
785761
786
787762/*************************************
788763 *
789764 *  Handle IDE commands
790765 *
791766 *************************************/
792767
793void ide_mass_storage_device::handle_command()
768bool ide_mass_storage_device::process_command()
794769{
795   UINT8 key[5];
796
797   /* implicitly clear interrupts & dmarq here */
798   set_irq(CLEAR_LINE);
799   set_dmarq(CLEAR_LINE);
800
801   m_status &= ~IDE_STATUS_ERR;
802
803770   switch (m_command)
804771   {
805      case IDE_COMMAND_READ_SECTORS:
806      case IDE_COMMAND_READ_SECTORS_NORETRY:
807         LOGPRINT(("IDE Read multiple: C=%d H=%d S=%d LBA=%d count=%d\n",
808            m_cur_cylinder, m_cur_head, m_cur_sector, lba_address(), m_sector_count));
772   case IDE_COMMAND_READ_SECTORS:
773   case IDE_COMMAND_READ_SECTORS_NORETRY:
774      LOGPRINT(("IDE Read multiple: C=%d H=%d S=%d LBA=%d count=%d\n",
775         (m_cylinder_high << 8) | m_cylinder_low, m_device_head & 0xf, m_sector_number, lba_address(), m_sector_count));
809776
810         /* reset the buffer */
811         m_buffer_offset = 0;
812         m_sectors_until_int = 1;
813         m_dma_active = 0;
814         m_verify_only = 0;
777      m_sectors_until_int = 1;
815778
816         /* start the read going */
817         read_first_sector();
818         break;
779      /* start the read going */
780      read_first_sector();
781      return true;
819782
820      case IDE_COMMAND_READ_MULTIPLE:
821         LOGPRINT(("IDE Read multiple block: C=%d H=%d S=%d LBA=%d count=%d\n",
822            m_cur_cylinder, m_cur_head, m_cur_sector, lba_address(), m_sector_count));
783   case IDE_COMMAND_READ_MULTIPLE:
784      LOGPRINT(("IDE Read multiple block: C=%d H=%d S=%d LBA=%d count=%d\n",
785         (m_cylinder_high << 8) | m_cylinder_low, m_device_head & 0xf, m_sector_number, lba_address(), m_sector_count));
823786
824         /* reset the buffer */
825         m_buffer_offset = 0;
826         m_sectors_until_int = 1;
827         m_dma_active = 0;
828         m_verify_only = 0;
787      m_sectors_until_int = 1;
829788
830         /* start the read going */
831         read_first_sector();
832         break;
789      /* start the read going */
790      read_first_sector();
791      return true;
833792
834      case IDE_COMMAND_VERIFY_SECTORS:
835      case IDE_COMMAND_VERIFY_SECTORS_NORETRY:
836         LOGPRINT(("IDE Read verify multiple with/without retries: C=%d H=%d S=%d LBA=%d count=%d\n",
837            m_cur_cylinder, m_cur_head, m_cur_sector, lba_address(), m_sector_count));
793   case IDE_COMMAND_VERIFY_SECTORS:
794   case IDE_COMMAND_VERIFY_SECTORS_NORETRY:
795      LOGPRINT(("IDE Read verify multiple with/without retries: C=%d H=%d S=%d LBA=%d count=%d\n",
796         (m_cylinder_high << 8) | m_cylinder_low, m_device_head & 0xf, m_sector_number, lba_address(), m_sector_count));
838797
839         /* reset the buffer */
840         m_buffer_offset = 0;
841         m_sectors_until_int = 1;
842         m_dma_active = 0;
843         m_verify_only = 1;
798      /* reset the buffer */
799      m_sectors_until_int = m_sector_count;
844800
845         /* start the read going */
846         read_first_sector();
847         break;
801      /* start the read going */
802      read_first_sector();
803      return true;
848804
849      case IDE_COMMAND_READ_DMA:
850         LOGPRINT(("IDE Read multiple DMA: C=%d H=%d S=%d LBA=%d count=%d\n",
851            m_cur_cylinder, m_cur_head, m_cur_sector, lba_address(), m_sector_count));
805   case IDE_COMMAND_READ_DMA:
806      LOGPRINT(("IDE Read multiple DMA: C=%d H=%d S=%d LBA=%d count=%d\n",
807         (m_cylinder_high << 8) | m_cylinder_low, m_device_head & 0xf, m_sector_number, lba_address(), m_sector_count));
852808
853         /* reset the buffer */
854         m_buffer_offset = 0;
855         m_sectors_until_int = m_sector_count;
856         m_dma_active = 1;
857         m_verify_only = 0;
809      /* reset the buffer */
810      m_sectors_until_int = m_sector_count;
858811
859         /* start the read going */
860         read_first_sector();
861         break;
812      /* start the read going */
813      read_first_sector();
814      return true;
862815
863      case IDE_COMMAND_WRITE_SECTORS:
864      case IDE_COMMAND_WRITE_SECTORS_NORETRY:
865         LOGPRINT(("IDE Write multiple: C=%d H=%d S=%d LBA=%d count=%d\n",
866            m_cur_cylinder, m_cur_head, m_cur_sector, lba_address(), m_sector_count));
816   case IDE_COMMAND_WRITE_SECTORS:
817   case IDE_COMMAND_WRITE_SECTORS_NORETRY:
818      LOGPRINT(("IDE Write multiple: C=%d H=%d S=%d LBA=%d count=%d\n",
819         (m_cylinder_high << 8) | m_cylinder_low, m_device_head & 0xf, m_sector_number, lba_address(), m_sector_count));
867820
868         /* reset the buffer */
869         m_buffer_offset = 0;
870         m_sectors_until_int = 1;
871         m_dma_active = 0;
821      /* reset the buffer */
822      m_sectors_until_int = 1;
872823
873         /* mark the buffer ready */
874         m_status |= IDE_STATUS_DRQ;
875         break;
824      /* mark the buffer ready */
825      m_status |= IDE_STATUS_DRQ;
826      return true;
876827
877      case IDE_COMMAND_WRITE_MULTIPLE:
878         LOGPRINT(("IDE Write multiple block: C=%d H=%d S=%d LBA=%d count=%d\n",
879            m_cur_cylinder, m_cur_head, m_cur_sector, lba_address(), m_sector_count));
828   case IDE_COMMAND_WRITE_MULTIPLE:
829      LOGPRINT(("IDE Write multiple block: C=%d H=%d S=%d LBA=%d count=%d\n",
830         (m_cylinder_high << 8) | m_cylinder_low, m_device_head & 0xf, m_sector_number, lba_address(), m_sector_count));
880831
881         /* reset the buffer */
882         m_buffer_offset = 0;
883         m_sectors_until_int = 1;
884         m_dma_active = 0;
832      /* reset the buffer */
833      m_sectors_until_int = 1;
885834
886         /* mark the buffer ready */
887         m_status |= IDE_STATUS_DRQ;
888         break;
835      /* mark the buffer ready */
836      m_status |= IDE_STATUS_DRQ;
837      return true;
889838
890      case IDE_COMMAND_WRITE_DMA:
891         LOGPRINT(("IDE Write multiple DMA: C=%d H=%d S=%d LBA=%d count=%d\n",
892            m_cur_cylinder, m_cur_head, m_cur_sector, lba_address(), m_sector_count));
839   case IDE_COMMAND_WRITE_DMA:
840      LOGPRINT(("IDE Write multiple DMA: C=%d H=%d S=%d LBA=%d count=%d\n",
841         (m_cylinder_high << 8) | m_cylinder_low, m_device_head & 0xf, m_sector_number, lba_address(), m_sector_count));
893842
894         /* reset the buffer */
895         m_buffer_offset = 0;
896         m_sectors_until_int = m_sector_count;
897         m_dma_active = 1;
843      /* reset the buffer */
844      m_sectors_until_int = m_sector_count;
898845
899         /* mark the buffer ready */
900         m_status |= IDE_STATUS_DRQ;
846      /* mark the buffer ready */
847      m_status |= IDE_STATUS_DRQ;
901848
902         /* start the read going */
903         set_dmarq(ASSERT_LINE);
904         break;
849      /* start the read going */
850      set_dmarq(ASSERT_LINE);
851      return true;
905852
906      case IDE_COMMAND_SECURITY_UNLOCK:
907         LOGPRINT(("IDE Security Unlock\n"));
853   case IDE_COMMAND_SECURITY_UNLOCK:
854      LOGPRINT(("IDE Security Unlock\n"));
908855
909         /* reset the buffer */
910         m_buffer_offset = 0;
911         m_sectors_until_int = 0;
912         m_dma_active = 0;
856      /* mark the buffer ready */
857      m_status |= IDE_STATUS_DRQ;
913858
914         /* mark the buffer ready */
915         m_status |= IDE_STATUS_DRQ;
859      set_irq(ASSERT_LINE);
860      return true;
916861
917         set_irq(ASSERT_LINE);
918         break;
862   case IDE_COMMAND_GET_INFO:
863      LOGPRINT(("IDE Read features\n"));
919864
920      case IDE_COMMAND_GET_INFO:
921         LOGPRINT(("IDE Read features\n"));
922
923         /* reset the buffer */
924         m_buffer_offset = 0;
865      if (m_has_features)
866      {
925867         m_sector_count = 1;
926868
927869         /* build the features page */
r23723r23724
929871
930872         /* indicate everything is ready */
931873         m_status |= IDE_STATUS_DRQ;
932         m_status &= ~IDE_STATUS_BSY;
933874
934875         /* signal an interrupt */
935876         signal_delayed_interrupt(MINIMUM_COMMAND_TIME, 1);
936         break;
937
938      case IDE_COMMAND_DIAGNOSTIC:
939         m_error = IDE_ERROR_DIAGNOSTIC_PASSED;
940
941         /* signal an interrupt */
942         signal_delayed_interrupt(MINIMUM_COMMAND_TIME, 0);
943         break;
944
945      case IDE_COMMAND_RECALIBRATE:
946         /* signal an interrupt */
947         signal_delayed_interrupt(MINIMUM_COMMAND_TIME, 0);
948         break;
949
950      case IDE_COMMAND_IDLE:
951         /* for timeout disabled value is 0 */
952         m_sector_count = 0;
953         /* signal an interrupt */
877      }
878      else
879      {
880         m_status |= IDE_STATUS_ERR;
881         m_error = IDE_ERROR_NONE;
882         m_status &= ~IDE_STATUS_DRDY;
954883         set_irq(ASSERT_LINE);
955         break;
884      }
885      return true;
956886
957      case IDE_COMMAND_SET_CONFIG:
958         LOGPRINT(("IDE Set configuration (%d heads, %d sectors)\n", m_cur_head + 1, m_sector_count));
959         set_geometry(m_sector_count,m_cur_head + 1);
887   case IDE_COMMAND_DIAGNOSTIC:
888      m_error = IDE_ERROR_DIAGNOSTIC_PASSED;
960889
961         /* signal an interrupt */
962         signal_delayed_interrupt(MINIMUM_COMMAND_TIME, 0);
963         break;
890      /* signal an interrupt */
891      signal_delayed_interrupt(MINIMUM_COMMAND_TIME, 0);
892      return true;
964893
965      case IDE_COMMAND_UNKNOWN_F9:
966         /* only used by Killer Instinct AFAICT */
967         LOGPRINT(("IDE unknown command (F9)\n"));
894   case IDE_COMMAND_RECALIBRATE:
895      /* signal an interrupt */
896      signal_delayed_interrupt(MINIMUM_COMMAND_TIME, 0);
897      return true;
968898
969         /* signal an interrupt */
970         set_irq(ASSERT_LINE);
971         break;
899   case IDE_COMMAND_IDLE:
900      /* for timeout disabled value is 0 */
901      m_sector_count = 0;
902      /* signal an interrupt */
903      set_irq(ASSERT_LINE);
904      return true;
972905
973      case IDE_COMMAND_SET_FEATURES:
974         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));
906   case IDE_COMMAND_SET_CONFIG:
907      LOGPRINT(("IDE Set configuration (%d heads, %d sectors)\n", (m_device_head & 0xf) + 1, m_sector_count));
908      set_geometry(m_sector_count,(m_device_head & 0xf) + 1);
975909
976         /* signal an interrupt */
977         signal_delayed_interrupt(MINIMUM_COMMAND_TIME, 0);
978         break;
910      /* signal an interrupt */
911      signal_delayed_interrupt(MINIMUM_COMMAND_TIME, 0);
912      return true;
979913
980      case IDE_COMMAND_SET_BLOCK_COUNT:
981         LOGPRINT(("IDE Set block count (%02X)\n", m_sector_count));
914   case IDE_COMMAND_UNKNOWN_F9:
915      /* only used by Killer Instinct AFAICT */
916      LOGPRINT(("IDE unknown command (F9)\n"));
982917
983         m_block_count = m_sector_count;
918      /* signal an interrupt */
919      set_irq(ASSERT_LINE);
920      return true;
984921
985         /* signal an interrupt */
986         set_irq(ASSERT_LINE);
987         break;
922   case IDE_COMMAND_SET_FEATURES:
923      LOGPRINT(("IDE Set features (%02X %02X %02X %02X %02X)\n", m_feature, m_sector_count & 0xff, m_sector_number, m_cylinder_low, m_cylinder_high));
988924
989      case IDE_COMMAND_TAITO_GNET_UNLOCK_1:
990         LOGPRINT(("IDE GNET Unlock 1\n"));
925      /* signal an interrupt */
926      signal_delayed_interrupt(MINIMUM_COMMAND_TIME, 0);
927      return true;
991928
992         m_sector_count = 1;
993         m_status |= IDE_STATUS_DRDY;
929   case IDE_COMMAND_SET_BLOCK_COUNT:
930      LOGPRINT(("IDE Set block count (%02X)\n", m_sector_count));
994931
995         set_irq(ASSERT_LINE);
996         break;
932      m_block_count = m_sector_count;
997933
998      case IDE_COMMAND_TAITO_GNET_UNLOCK_2:
999         LOGPRINT(("IDE GNET Unlock 2\n"));
934      /* signal an interrupt */
935      set_irq(ASSERT_LINE);
936      return true;
1000937
1001         /* reset the buffer */
1002         m_buffer_offset = 0;
1003         m_sectors_until_int = 0;
1004         m_dma_active = 0;
938   case IDE_COMMAND_SEEK:
939      /*
940         cur_cylinder, cur_sector and cur_head
941         are all already set in this case so no need
942         so that implements actual seek
943      */
1005944
1006         /* mark the buffer ready */
1007         m_status |= IDE_STATUS_DRQ;
945      /* for timeout disabled value is 0 */
946      m_sector_count = 0;
1008947
1009         set_irq(ASSERT_LINE);
1010         break;
948      /* signal an interrupt */
949      set_irq(ASSERT_LINE);
950      return true;
1011951
1012      case IDE_COMMAND_TAITO_GNET_UNLOCK_3:
1013         LOGPRINT(("IDE GNET Unlock 3\n"));
1014
1015         /* key check */
1016         read_key(key);
1017         if ((m_feature == key[0]) && (m_sector_count == key[1]) && (m_cur_sector == key[2]) && (m_cur_cylinder == (((UINT16)key[4]<<8)|key[3])))
1018         {
1019            m_gnetreadlock= 0;
1020         }
1021         else
1022         {
1023            m_status &= ~IDE_STATUS_DRDY;
1024         }
1025
1026         set_irq(ASSERT_LINE);
1027         break;
1028
1029      case IDE_COMMAND_SEEK:
1030         /*
1031             cur_cylinder, cur_sector and cur_head
1032             are all already set in this case so no need
1033             so that implements actual seek
1034         */
1035
1036         /* for timeout disabled value is 0 */
1037         m_sector_count = 0;
1038         /* signal an interrupt */
1039         set_irq(ASSERT_LINE);
1040         break;
1041
1042
1043      default:
1044         LOGPRINT(("IDE unknown command (%02X)\n", m_command));
1045         m_status |= IDE_STATUS_ERR;
1046         m_error = IDE_ERROR_UNKNOWN_COMMAND;
1047         set_irq(ASSERT_LINE);
1048         //debugger_break(device->machine());
1049         break;
952   default:
953      return false;
1050954   }
1051955}
1052956
r23723r23724
11691073
11701074            /* return the current sector */
11711075            case IDE_CS0_SECTOR_NUMBER_RW:
1172               result = m_cur_sector;
1076               result = m_sector_number;
11731077               break;
11741078
11751079            /* return the current cylinder LSB */
11761080            case IDE_CS0_CYLINDER_LOW_RW:
1177               result = m_cur_cylinder & 0xff;
1081               result = m_cylinder_low;
11781082               break;
11791083
11801084            /* return the current cylinder MSB */
11811085            case IDE_CS0_CYLINDER_HIGH_RW:
1182               result = m_cur_cylinder >> 8;
1086               result = m_cylinder_high;
11831087               break;
11841088
11851089            /* return the current head */
11861090            case IDE_CS0_DEVICE_HEAD_RW:
1187               result = m_cur_head_reg;
1091               result = m_device_head;
11881092               break;
11891093
11901094            /* return the current status and clear any pending interrupts */
r23723r23724
11991103                     m_last_status_timer->adjust(attotime::never);
12001104                  }
12011105
1202                  if (!(m_status & IDE_STATUS_DRDY) && !m_gnetreadlock)
1106                  if (!(m_status & IDE_STATUS_DRDY) && is_ready())
12031107                  {
12041108                     m_status |= IDE_STATUS_DRDY;
12051109                  }
r23723r23724
12101114               {
12111115                  result = 0;
12121116               }
1213
12141117               break;
12151118
12161119            /* log anything else */
r23723r23724
13091212
13101213WRITE16_MEMBER( ide_mass_storage_device::write_cs0 )
13111214{
1312   if (!device_present())
1313      return;
1314
13151215   /* logit */
13161216   if (offset != IDE_CS0_DATA_RW)
13171217      LOG(("%s:IDE cs0 write to %X = %08X, mem_mask=%d\n", machine().describe_context(), offset, data, mem_mask));
r23723r23724
13691269
13701270         /* current sector */
13711271         case IDE_CS0_SECTOR_NUMBER_RW:
1372            m_cur_sector = data;
1272            m_sector_number = data;
13731273            break;
13741274
13751275         /* current cylinder LSB */
13761276         case IDE_CS0_CYLINDER_LOW_RW:
1377            m_cur_cylinder = (m_cur_cylinder & 0xff00) | (data & 0xff);
1277            m_cylinder_low = data;
13781278            break;
13791279
13801280         /* current cylinder MSB */
13811281         case IDE_CS0_CYLINDER_HIGH_RW:
1382            m_cur_cylinder = ((data << 8) & 0xff00) | (m_cur_cylinder & 0xff);
1282            m_cylinder_high = data;
13831283            break;
13841284
13851285         /* current head */
13861286         case IDE_CS0_DEVICE_HEAD_RW:
1387            // LBA mode = data & 0x40
1388            m_cur_drive = (data & 0x10) >> 4;
1389            m_cur_head = data & 0x0f;
1390            m_cur_head_reg = data;
1287            m_device_head = data;
1288
1289            update_irq();
13911290            break;
13921291
13931292         /* command */
r23723r23724
13951294            m_command = data;
13961295
13971296            if (device_selected() || m_command == IDE_COMMAND_DIAGNOSTIC)
1398               handle_command();
1297            {
1298               /* implicitly clear interrupts & dmarq here */
1299               set_irq(CLEAR_LINE);
1300               set_dmarq(CLEAR_LINE);
1301
1302               m_buffer_offset = 0;
1303               m_sectors_until_int = 0;
1304
1305               m_status &= ~IDE_STATUS_ERR;
1306
1307               if (!process_command())
1308               {
1309                  LOGPRINT(("IDE unknown command (%02X)\n", m_command));
1310                  m_status |= IDE_STATUS_ERR;
1311                  m_error = IDE_ERROR_UNKNOWN_COMMAND;
1312                  set_irq(ASSERT_LINE);
1313                  //debugger_break(device->machine());
1314               }
1315            }
13991316            break;
14001317      }
14011318   }
r23723r23724
14031320
14041321WRITE16_MEMBER( ide_mass_storage_device::write_cs1 )
14051322{
1406   if (!device_present())
1407      return;
1408
14091323   /* logit */
14101324   LOG(("%s:IDE cs1 write to %X = %08X, mem_mask=%d\n", machine().describe_context(), offset, data, mem_mask));
14111325
r23723r23724
14211335         case IDE_CS1_DEVICE_CONTROL_W:
14221336            m_device_control = data;
14231337
1424            if (data & 0x02)
1425            {
1426               // nIEN
1427               logerror( "%s: write_cs1 %04x %04x %04x nIEN not supported\n", machine().describe_context(), offset, data, mem_mask );
1428            }
1338            update_irq();
14291339
14301340            if (data & 0x04)
14311341            {
r23723r23724
14951405      UINT32 metalength;
14961406      if (m_handle->read_metadata (HARD_DISK_IDENT_METADATA_TAG, 0, m_features, IDE_DISK_SECTOR_SIZE, metalength) != CHDERR_NONE)
14971407         ide_build_features();
1408
1409      m_has_features = 1;
14981410   }
14991411}
15001412
trunk/src/emu/machine/idehd.h
r23723r23724
5757   virtual DECLARE_WRITE_LINE_MEMBER(write_csel) = 0;
5858   virtual DECLARE_WRITE_LINE_MEMBER(write_dasp) = 0;
5959
60   virtual bool device_present() = 0;
60   virtual bool is_ready() { return true; }
6161   virtual UINT8 *get_features() = 0;
6262
6363   UINT8           m_master_password_enable;
r23723r23724
9898   virtual int write_sector(UINT32 lba, const void *buffer) = 0;
9999   virtual void read_key(UINT8 key[]) = 0;
100100
101   bool device_selected() { return m_csel == m_cur_drive && device_present(); }
102   bool single_device() { return m_csel == 0 && m_dasp == 0 && device_present(); }
101   bool device_selected() { return m_csel == (m_device_head & 0x10) >> 4; }
102   bool single_device() { return m_csel == 0 && m_dasp == 0; }
103103
104104   void set_irq(int state);
105105   void set_dmarq(int state);
106106   void ide_build_features();
107107
108   UINT8           m_gnetreadlock;
108   virtual bool process_command();
109   virtual void process_buffer();
109110
111   UINT8           m_buffer[IDE_DISK_SECTOR_SIZE];
112   UINT16          m_buffer_offset;
113   UINT8           m_error;
114   UINT8           m_feature;
115   UINT16          m_sector_count;
116   UINT8           m_sector_number;
117   UINT8           m_cylinder_low;
118   UINT8           m_cylinder_high;
119   UINT8           m_device_head;
120   UINT8           m_status;
121   UINT8           m_command;
122   UINT8           m_device_control;
123
124   int m_has_features;
110125   UINT8           m_features[IDE_DISK_SECTOR_SIZE];
111126   UINT16          m_num_cylinders;
112127   UINT8           m_num_sectors;
r23723r23724
124139   void security_error();
125140   void continue_read();
126141   void read_first_sector();
127   void handle_command();
128142   void read_buffer_empty();
129143   void write_buffer_full();
144   void update_irq();
130145
131146   int m_csel;
132147   int m_dasp;
r23723r23724
134149   int m_dmarq;
135150   int m_irq;
136151
137   int             m_cur_drive;
138   UINT16          m_cur_cylinder;
139   UINT8           m_cur_sector;
140   UINT8           m_cur_head;
141   UINT8           m_cur_head_reg;
142152   UINT32          m_cur_lba;
143
144   UINT8           m_status;
145   UINT8           m_error;
146   UINT8           m_command;
147
148   UINT8           m_buffer[IDE_DISK_SECTOR_SIZE];
149   UINT16          m_buffer_offset;
150
151   UINT8           m_device_control;
152   UINT8           m_feature;
153   UINT16          m_sector_count;
154153   UINT16          m_block_count;
155
156154   UINT16          m_sectors_until_int;
157155
158   UINT8           m_dma_active;
159   UINT8           m_verify_only;
160
161156   emu_timer *     m_last_status_timer;
162157   emu_timer *     m_reset_timer;
163158};
r23723r23724
181176   // optional information overrides
182177   virtual machine_config_constructor device_mconfig_additions() const;
183178
184   virtual bool device_present() { return (m_disk != NULL); }
185179   virtual void read_key(UINT8 key[]);
186180
187181   chd_file       *m_handle;
trunk/src/mame/drivers/chihiro.c
r23723r23724
26642664
26652665   virtual int  read_sector(UINT32 lba, void *buffer);
26662666   virtual int  write_sector(UINT32 lba, const void *buffer);
2667   virtual bool device_present() { return true; }
26682667   virtual void read_key(UINT8 key[]) { }
26692668protected:
26702669   // device-level overrides

Previous 199869 Revisions Next


© 1997-2024 The MAME Team