Previous 199869 Revisions Next

r23670 Thursday 13th June, 2013 at 12:20:48 UTC by smf
moved the status and command across (nw)
[src/emu/machine]idectrl.c idectrl.h idehd.c idehd.h

trunk/src/emu/machine/idehd.c
r23669r23670
253253   save_item(NAME(buffer));
254254   save_item(NAME(buffer_offset));
255255
256   save_item(NAME(status));
257   save_item(NAME(command));
256258   save_item(NAME(error));
257259
258260   save_item(NAME(adapter_control));
r23669r23670
312314   master_password_enable = (master_password != NULL);
313315   user_password_enable = (user_password != NULL);
314316   error = IDE_ERROR_DEFAULT;
317   status = IDE_STATUS_DRIVE_READY | IDE_STATUS_SEEK_COMPLETE;
315318}
316319
317320//-------------------------------------------------
trunk/src/emu/machine/idehd.h
r23669r23670
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
12
613#define IDE_ERROR_NONE                      0x00
714#define IDE_ERROR_DEFAULT                   0x01
815#define IDE_ERROR_TRACK0_NOT_FOUND          0x02
r23669r23670
3542   UINT8           cur_head_reg;
3643   UINT32          cur_lba;
3744
45   UINT8           status;
3846   UINT8           error;
47   UINT8           command;
3948
4049   UINT8           buffer[IDE_DISK_SECTOR_SIZE];
4150   UINT16          buffer_offset;
trunk/src/emu/machine/idectrl.c
r23669r23670
3535#define TIME_SEEK_MULTISECTOR               (attotime::from_msec(13))
3636#define TIME_NO_SEEK_MULTISECTOR            (attotime::from_nsec(16300))
3737
38#define IDE_STATUS_ERROR                    0x01
39#define IDE_STATUS_HIT_INDEX                0x02
40#define IDE_STATUS_BUFFER_READY             0x08
41#define IDE_STATUS_SEEK_COMPLETE            0x10
42#define IDE_STATUS_DRIVE_READY              0x40
43#define IDE_STATUS_BUSY                     0x80
44
4538#define IDE_BANK0_DATA                      0
4639#define IDE_BANK0_ERROR                     1
4740#define IDE_BANK0_SECTOR_COUNT              2
r23669r23670
120113
121114void ide_controller_device::device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr)
122115{
116   ide_device_interface *dev = slot[cur_drive]->dev();
117
123118   switch(id)
124119   {
125120   case TID_DELAYED_INTERRUPT:
126      status &= ~IDE_STATUS_BUSY;
121      dev->status &= ~IDE_STATUS_BUSY;
127122      set_irq(ASSERT_LINE);
128123      break;
129124
130125   case TID_DELAYED_INTERRUPT_BUFFER_READY:
131      status &= ~IDE_STATUS_BUSY;
132      status |= IDE_STATUS_BUFFER_READY;
126      dev->status &= ~IDE_STATUS_BUSY;
127      dev->status |= IDE_STATUS_BUFFER_READY;
133128      set_irq(ASSERT_LINE);
134129      break;
135130
r23669r23670
139134
140135   case TID_SECURITY_ERROR_DONE:
141136      /* clear error state */
142      status &= ~IDE_STATUS_ERROR;
143      status |= IDE_STATUS_DRIVE_READY;
137      dev->status &= ~IDE_STATUS_ERROR;
138      dev->status |= IDE_STATUS_DRIVE_READY;
144139      break;
145140
146141   case TID_READ_SECTOR_DONE_CALLBACK:
r23669r23670
156151
157152void ide_controller_device::signal_delayed_interrupt(attotime time, int buffer_ready)
158153{
154   ide_device_interface *dev = slot[cur_drive]->dev();
155
159156   /* clear buffer ready and set the busy flag */
160   status &= ~IDE_STATUS_BUFFER_READY;
161   status |= IDE_STATUS_BUSY;
157   dev->status &= ~IDE_STATUS_BUFFER_READY;
158   dev->status |= IDE_STATUS_BUSY;
162159
163160   /* set a timer */
164161   if (buffer_ready)
r23669r23670
250247
251248void ide_controller_device::security_error()
252249{
250   ide_device_interface *dev = slot[cur_drive]->dev();
251
253252   /* set error state */
254   status |= IDE_STATUS_ERROR;
255   status &= ~IDE_STATUS_DRIVE_READY;
253   dev->status |= IDE_STATUS_ERROR;
254   dev->status &= ~IDE_STATUS_DRIVE_READY;
256255
257256   /* just set a timer and mark ourselves error */
258257   timer_set(TIME_SECURITY_ERROR, TID_SECURITY_ERROR_DONE);
r23669r23670
274273   dev->buffer_offset = 0;
275274
276275   /* clear the buffer ready and busy flag */
277   status &= ~IDE_STATUS_BUFFER_READY;
278   status &= ~IDE_STATUS_BUSY;
276   dev->status &= ~IDE_STATUS_BUFFER_READY;
277   dev->status &= ~IDE_STATUS_BUSY;
279278   dev->error = IDE_ERROR_DEFAULT;
280279   set_dmarq(0);
281280
r23669r23670
303302
304303   /* GNET readlock check */
305304   if (dev->gnetreadlock) {
306      status &= ~IDE_STATUS_ERROR;
307      status &= ~IDE_STATUS_BUSY;
305      dev->status &= ~IDE_STATUS_ERROR;
306      dev->status &= ~IDE_STATUS_BUSY;
308307      return;
309308   }
310309
r23669r23670
313312
314313   /* by default, mark the buffer ready and the seek complete */
315314   if (!dev->verify_only)
316      status |= IDE_STATUS_BUFFER_READY;
317   status |= IDE_STATUS_SEEK_COMPLETE;
315      dev->status |= IDE_STATUS_BUFFER_READY;
316   dev->status |= IDE_STATUS_SEEK_COMPLETE;
318317
319318   /* and clear the busy and error flags */
320   status &= ~IDE_STATUS_ERROR;
321   status &= ~IDE_STATUS_BUSY;
319   dev->status &= ~IDE_STATUS_ERROR;
320   dev->status &= ~IDE_STATUS_BUSY;
322321
323322   /* if we succeeded, advance to the next sector and set the nice bits */
324323   if (count == 1)
r23669r23670
336335         dev->sectors_until_int--;
337336      if (dev->sectors_until_int == 0 || dev->sector_count == 1)
338337      {
339         dev->sectors_until_int = ((command == IDE_COMMAND_READ_MULTIPLE) ? dev->block_count : 1);
338         dev->sectors_until_int = ((dev->command == IDE_COMMAND_READ_MULTIPLE) ? dev->block_count : 1);
340339         set_irq(ASSERT_LINE);
341340      }
342341
r23669r23670
353352   else
354353   {
355354      /* set the error flag and the error */
356      status |= IDE_STATUS_ERROR;
355      dev->status |= IDE_STATUS_ERROR;
357356      dev->error = IDE_ERROR_BAD_SECTOR;
358357
359358      /* signal an interrupt */
r23669r23670
366365{
367366   ide_device_interface *dev = slot[cur_drive]->dev();
368367   /* mark ourselves busy */
369   status |= IDE_STATUS_BUSY;
368   dev->status |= IDE_STATUS_BUSY;
370369
371370   /* just set a timer */
372   if (command == IDE_COMMAND_READ_MULTIPLE)
371   if (dev->command == IDE_COMMAND_READ_MULTIPLE)
373372   {
374373      int new_lba = dev->lba_address();
375374      attotime seek_time;
r23669r23670
392391   ide_device_interface *dev = slot[cur_drive]->dev();
393392
394393   /* mark ourselves busy */
395   status |= IDE_STATUS_BUSY;
394   dev->status |= IDE_STATUS_BUSY;
396395
397   if (command == IDE_COMMAND_READ_MULTIPLE)
396   if (dev->command == IDE_COMMAND_READ_MULTIPLE)
398397   {
399398      if (dev->sectors_until_int != 1)
400399         /* make ready now */
r23669r23670
424423   dev->buffer_offset = 0;
425424
426425   /* clear the buffer ready flag */
427   status &= ~IDE_STATUS_BUFFER_READY;
428   status |= IDE_STATUS_BUSY;
426   dev->status &= ~IDE_STATUS_BUFFER_READY;
427   dev->status |= IDE_STATUS_BUSY;
429428
430   if (command == IDE_COMMAND_WRITE_MULTIPLE)
429   if (dev->command == IDE_COMMAND_WRITE_MULTIPLE)
431430   {
432431      if (dev->sectors_until_int != 1)
433432      {
r23669r23670
453452   ide_device_interface *dev = slot[cur_drive]->dev();
454453
455454   set_dmarq(0);
456   if (command == IDE_COMMAND_SECURITY_UNLOCK)
455   if (dev->command == IDE_COMMAND_SECURITY_UNLOCK)
457456   {
458457      if (dev->user_password_enable && memcmp(dev->buffer, dev->user_password, 2 + 32) == 0)
459458      {
r23669r23670
481480      }
482481
483482      /* clear the busy and error flags */
484      status &= ~IDE_STATUS_ERROR;
485      status &= ~IDE_STATUS_BUSY;
486      status &= ~IDE_STATUS_BUFFER_READY;
483      dev->status &= ~IDE_STATUS_ERROR;
484      dev->status &= ~IDE_STATUS_BUSY;
485      dev->status &= ~IDE_STATUS_BUFFER_READY;
487486
488487      if (dev->master_password_enable || dev->user_password_enable)
489488         security_error();
490489      else
491         status |= IDE_STATUS_DRIVE_READY;
490         dev->status |= IDE_STATUS_DRIVE_READY;
492491   }
493   else if (command == IDE_COMMAND_TAITO_GNET_UNLOCK_2)
492   else if (dev->command == IDE_COMMAND_TAITO_GNET_UNLOCK_2)
494493   {
495494      UINT8 key[5] = { 0 };
496495      int i, bad = 0;
r23669r23670
499498      for (i=0; !bad && i<512; i++)
500499         bad = ((i < 2 || i >= 7) && dev->buffer[i]) || ((i >= 2 && i < 7) && dev->buffer[i] != key[i-2]);
501500
502      status &= ~IDE_STATUS_BUSY;
503      status &= ~IDE_STATUS_BUFFER_READY;
501      dev->status &= ~IDE_STATUS_BUSY;
502      dev->status &= ~IDE_STATUS_BUFFER_READY;
504503      if (bad)
505         status |= IDE_STATUS_ERROR;
504         dev->status |= IDE_STATUS_ERROR;
506505      else {
507         status &= ~IDE_STATUS_ERROR;
506         dev->status &= ~IDE_STATUS_ERROR;
508507         dev->gnetreadlock= 0;
509508      }
510509   }
r23669r23670
524523   count = dev->write_sector(lba, dev->buffer);
525524
526525   /* by default, mark the buffer ready and the seek complete */
527   status |= IDE_STATUS_BUFFER_READY;
528   status |= IDE_STATUS_SEEK_COMPLETE;
526   dev->status |= IDE_STATUS_BUFFER_READY;
527   dev->status |= IDE_STATUS_SEEK_COMPLETE;
529528
530529   /* and clear the busy adn error flags */
531   status &= ~IDE_STATUS_ERROR;
532   status &= ~IDE_STATUS_BUSY;
530   dev->status &= ~IDE_STATUS_ERROR;
531   dev->status &= ~IDE_STATUS_BUSY;
533532
534533   /* if we succeeded, advance to the next sector and set the nice bits */
535534   if (count == 1)
r23669r23670
545544      /* signal an interrupt */
546545      if (--dev->sectors_until_int == 0 || dev->sector_count == 1)
547546      {
548         dev->sectors_until_int = ((command == IDE_COMMAND_WRITE_MULTIPLE) ? dev->block_count : 1);
547         dev->sectors_until_int = ((dev->command == IDE_COMMAND_WRITE_MULTIPLE) ? dev->block_count : 1);
549548         set_irq(ASSERT_LINE);
550549      }
551550
r23669r23670
553552      if (dev->sector_count > 0)
554553         dev->sector_count--;
555554      if (dev->sector_count == 0)
556         status &= ~IDE_STATUS_BUFFER_READY;
555         dev->status &= ~IDE_STATUS_BUFFER_READY;
557556
558557      /* keep going for DMA */
559558      if (dev->dma_active && dev->sector_count != 0)
r23669r23670
566565   else
567566   {
568567      /* set the error flag and the error */
569      status |= IDE_STATUS_ERROR;
568      dev->status |= IDE_STATUS_ERROR;
570569      dev->error = IDE_ERROR_BAD_SECTOR;
571570
572571      /* signal an interrupt */
r23669r23670
590589   /* implicitly clear interrupts & dmarq here */
591590   set_irq(CLEAR_LINE);
592591   set_dmarq(0);
593   command = _command;
594   switch (command)
592   dev->command = _command;
593   switch (dev->command)
595594   {
596595      case IDE_COMMAND_READ_SECTORS:
597596      case IDE_COMMAND_READ_SECTORS_NORETRY:
r23669r23670
662661         dev->dma_active = 0;
663662
664663         /* mark the buffer ready */
665         status |= IDE_STATUS_BUFFER_READY;
664         dev->status |= IDE_STATUS_BUFFER_READY;
666665         break;
667666
668667      case IDE_COMMAND_WRITE_MULTIPLE:
r23669r23670
675674         dev->dma_active = 0;
676675
677676         /* mark the buffer ready */
678         status |= IDE_STATUS_BUFFER_READY;
677         dev->status |= IDE_STATUS_BUFFER_READY;
679678         break;
680679
681680      case IDE_COMMAND_WRITE_DMA:
r23669r23670
700699         dev->dma_active = 0;
701700
702701         /* mark the buffer ready */
703         status |= IDE_STATUS_BUFFER_READY;
702         dev->status |= IDE_STATUS_BUFFER_READY;
704703         set_irq(ASSERT_LINE);
705704         break;
706705
r23669r23670
715714         memcpy(dev->buffer, slot[cur_drive]->dev()->get_features(), sizeof(dev->buffer));
716715
717716         /* indicate everything is ready */
718         status |= IDE_STATUS_BUFFER_READY;
719         status |= IDE_STATUS_SEEK_COMPLETE;
720         status |= IDE_STATUS_DRIVE_READY;
717         dev->status |= IDE_STATUS_BUFFER_READY;
718         dev->status |= IDE_STATUS_SEEK_COMPLETE;
719         dev->status |= IDE_STATUS_DRIVE_READY;
721720
722721         /* and clear the busy adn error flags */
723         status &= ~IDE_STATUS_ERROR;
724         status &= ~IDE_STATUS_BUSY;
722         dev->status &= ~IDE_STATUS_ERROR;
723         dev->status &= ~IDE_STATUS_BUSY;
725724
726725         /* clear the error too */
727726         dev->error = IDE_ERROR_NONE;
r23669r23670
756755
757756      case IDE_COMMAND_SET_CONFIG:
758757         LOGPRINT(("IDE Set configuration (%d heads, %d sectors)\n", dev->cur_head + 1, dev->sector_count));
759         status &= ~IDE_STATUS_ERROR;
758         dev->status &= ~IDE_STATUS_ERROR;
760759         dev->error = IDE_ERROR_NONE;
761760         dev->set_geometry(dev->sector_count,dev->cur_head + 1);
762761
r23669r23670
784783
785784         dev->block_count = dev->sector_count;
786785         // judge dredd wants 'drive ready' on this command
787         status |= IDE_STATUS_DRIVE_READY;
786         dev->status |= IDE_STATUS_DRIVE_READY;
788787
789788         /* signal an interrupt */
790789         set_irq(ASSERT_LINE);
r23669r23670
794793         LOGPRINT(("IDE GNET Unlock 1\n"));
795794
796795         dev->sector_count = 1;
797         status |= IDE_STATUS_DRIVE_READY;
798         status &= ~IDE_STATUS_ERROR;
796         dev->status |= IDE_STATUS_DRIVE_READY;
797         dev->status &= ~IDE_STATUS_ERROR;
799798         set_irq(ASSERT_LINE);
800799         break;
801800
r23669r23670
808807         dev->dma_active = 0;
809808
810809         /* mark the buffer ready */
811         status |= IDE_STATUS_BUFFER_READY;
810         dev->status |= IDE_STATUS_BUFFER_READY;
812811         set_irq(ASSERT_LINE);
813812         break;
814813
r23669r23670
823822         }
824823
825824         /* update flags */
826         status |= IDE_STATUS_DRIVE_READY;
827         status &= ~IDE_STATUS_ERROR;
825         dev->status |= IDE_STATUS_DRIVE_READY;
826         dev->status &= ~IDE_STATUS_ERROR;
828827         set_irq(ASSERT_LINE);
829828         break;
830829
r23669r23670
845844
846845
847846      default:
848         LOGPRINT(("IDE unknown command (%02X)\n", command));
849         status |= IDE_STATUS_ERROR;
847         LOGPRINT(("IDE unknown command (%02X)\n", dev->command));
848         dev->status |= IDE_STATUS_ERROR;
850849         dev->error = IDE_ERROR_UNKNOWN_COMMAND;
851850         set_irq(ASSERT_LINE);
852851         //debugger_break(device->machine());
r23669r23670
949948   }
950949
951950   if (dev->is_ready()) {
952      status |= IDE_STATUS_DRIVE_READY;
951      dev->status |= IDE_STATUS_DRIVE_READY;
953952   } else {
954      status &= ~IDE_STATUS_DRIVE_READY;
953      dev->status &= ~IDE_STATUS_DRIVE_READY;
955954   }
956955
957956   switch (offset)
958957   {
959958      /* read data if there's data to be read */
960959      case IDE_BANK0_DATA:
961         if (status & IDE_STATUS_BUFFER_READY)
960         if (dev->status & IDE_STATUS_BUFFER_READY)
962961         {
963962            /* fetch the correct amount of data */
964963            result = dev->buffer[dev->buffer_offset++];
r23669r23670
10061005
10071006      /* return the current status and clear any pending interrupts */
10081007      case IDE_BANK0_STATUS_COMMAND:
1009         result = status;
1008         result = dev->status;
10101009         if (last_status_timer->elapsed() > TIME_PER_ROTATION)
10111010         {
10121011            result |= IDE_STATUS_HIT_INDEX;
r23669r23670
10541053   }
10551054
10561055   if (dev->is_ready()) {
1057      status |= IDE_STATUS_DRIVE_READY;
1056      dev->status |= IDE_STATUS_DRIVE_READY;
10581057   } else {
1059      status &= ~IDE_STATUS_DRIVE_READY;
1058      dev->status &= ~IDE_STATUS_DRIVE_READY;
10601059   }
10611060
10621061   /* logit */
r23669r23670
10671066   switch (offset)
10681067   {
10691068      case IDE_BANK1_STATUS_CONTROL:
1070         result = status;
1069         result = dev->status;
10711070         if (last_status_timer->elapsed() > TIME_PER_ROTATION)
10721071         {
10731072            result |= IDE_STATUS_HIT_INDEX;
r23669r23670
11761175   {
11771176      /* write data */
11781177      case IDE_BANK0_DATA:
1179         if (status & IDE_STATUS_BUFFER_READY)
1178         if (dev->status & IDE_STATUS_BUFFER_READY)
11801179         {
11811180            /* store the correct amount of data */
11821181            dev->buffer[dev->buffer_offset++] = data;
r23669r23670
12651264         //if (data == 0x04)
12661265         if (data & 0x04)
12671266         {
1268            status |= IDE_STATUS_BUSY;
1269            status &= ~IDE_STATUS_DRIVE_READY;
1267            dev->status |= IDE_STATUS_BUSY;
1268            dev->status &= ~IDE_STATUS_DRIVE_READY;
12701269            reset_timer->adjust(attotime::from_msec(5));
12711270         }
12721271         break;
r23669r23670
12801279
12811280ide_controller_device::ide_controller_device(const machine_config &mconfig, device_type type, const char *name, const char *tag, device_t *owner, UINT32 clock) :
12821281   device_t(mconfig, type, name, tag, owner, clock),
1283   status(0),
1284   command(0),
12851282   config_unknown(0),
12861283   config_register_num(0),
12871284   cur_drive(0),
r23669r23670
12941291
12951292ide_controller_device::ide_controller_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock) :
12961293   device_t(mconfig, IDE_CONTROLLER, "IDE Controller", tag, owner, clock),
1297   command(0),
12981294   config_unknown(0),
12991295   config_register_num(0),
13001296   cur_drive(0),
r23669r23670
13191315   reset_timer = timer_alloc(TID_RESET_CALLBACK);
13201316
13211317   /* register ide states */
1322   save_item(NAME(status));
1323   save_item(NAME(command));
1324
13251318   save_item(NAME(config_unknown));
13261319   save_item(NAME(config_register));
13271320   save_item(NAME(config_register_num));
r23669r23670
13361329   LOG(("IDE controller reset performed\n"));
13371330   /* reset the drive state */
13381331   cur_drive = 0;
1339   status = IDE_STATUS_DRIVE_READY | IDE_STATUS_SEEK_COMPLETE;
13401332   set_irq(CLEAR_LINE);
13411333   set_dmarq(0);
13421334}
trunk/src/emu/machine/idectrl.h
r23669r23670
126126   void read_buffer_empty();
127127   void write_buffer_full();
128128
129   UINT8           status;
130   UINT8           command;
131
132129   UINT8           config_unknown;
133130   UINT8           config_register[IDE_CONFIG_REGISTERS];
134131   UINT8           config_register_num;

Previous 199869 Revisions Next


© 1997-2024 The MAME Team