Previous 199869 Revisions Next

r23573 Sunday 9th June, 2013 at 18:58:02 UTC by smf
Started to separate the bus master dma from the drive emulation (nw)
[src/emu/machine]idectrl.c idectrl.h
[src/mame/drivers]zn.c

trunk/src/mame/drivers/zn.c
r23572r23573
13381338      return;
13391339   }
13401340
1341//   printf( "%08x %08x %08x\n", n_address, n_size * 4, n_address + n_size * 4 );
1342
13431341   /* dma size is in 32-bit words, convert to words */
13441342   n_size <<= 1;
1345   address_space &space = machine().firstcpu->space(AS_PROGRAM);
13461343   while( n_size > 0 )
13471344   {
1348      psxwriteword( p_n_psxram, n_address, m_ide->read_cs0( space, 0, 0xffff ) );
1345      psxwriteword( p_n_psxram, n_address, m_ide->read_dma() );
13491346      n_address += 2;
13501347      n_size--;
13511348   }
1352
1353//   printf( "%08x\n", n_address );
13541349}
13551350
13561351void zn_state::atpsx_dma_write( UINT32 *p_n_psxram, UINT32 n_address, INT32 n_size )
trunk/src/emu/machine/idectrl.c
r23572r23573
301301void ide_controller_device::write_buffer_to_dma()
302302{
303303   int bytesleft = IDE_DISK_SECTOR_SIZE;
304   UINT8 *data = buffer;
304   UINT16 data = 0;
305305
306306//  LOG(("Writing sector to %08X\n", dma_address));
307307
308308   /* loop until we've consumed all bytes */
309309   while (bytesleft--)
310310   {
311      data >>= 8;
312
313      if (bytesleft & 1)
314         data = read_dma();
315
311316      /* if we're out of space, grab the next descriptor */
312317      if (dma_bytes_left == 0)
313318      {
r23572r23573
339344      }
340345
341346      /* write the next byte */
342      dma_space->write_byte(dma_address++, *data++);
347      dma_space->write_byte(dma_address++, data & 0xff);
343348      dma_bytes_left--;
344349   }
345350}
r23572r23573
392397      if (dma_active)
393398         write_buffer_to_dma();
394399
395      /* if we're just verifying or if we DMA'ed the data, we can read the next sector */
396      if (verify_only || dma_active)
400      /* if we're just verifying we can read the next sector */
401      if (verify_only)
397402         continue_read();
398403   }
399404
r23572r23573
507512void ide_controller_device::read_buffer_from_dma()
508513{
509514   int bytesleft = IDE_DISK_SECTOR_SIZE;
510   UINT8 *data = buffer;
515   UINT16 data = 0;
511516
512517//  LOG(("Reading sector from %08X\n", dma_address));
513518
r23572r23573
545550      }
546551
547552      /* read the next byte */
548      *data++ = dma_space->read_byte(dma_address++);
549      dma_bytes_left--;
553      data |= dma_space->read_byte(dma_address++) << 8;
554      dma_bytes_left --;
555
556      if((bytesleft & 1) == 0)
557         write_dma(data);
558
559      data >>= 8;
550560   }
551561}
552562
r23572r23573
595605      if (dma_active && sector_count != 0)
596606      {
597607         read_buffer_from_dma();
598         continue_write();
599608      }
600609      else
601610         dma_active = 0;
r23572r23573
739748         if (bus_master_command & 1)
740749         {
741750            read_buffer_from_dma();
742            continue_write();
743751         }
744752         break;
745753
r23572r23573
961969   }
962970}
963971
972UINT16 ide_controller_device::read_dma()
973{
974   UINT16 result = buffer[buffer_offset++];
975   result |= buffer[buffer_offset++] << 8;
976
977   if (buffer_offset >= IDE_DISK_SECTOR_SIZE)
978   {
979      LOG(("%s:IDE completed DMA read\n", machine().describe_context()));
980      read_buffer_empty();
981   }
982
983   return result;
984}
985
964986READ16_MEMBER( ide_controller_device::read_cs0 )
965987{
966988   UINT16 result = 0;
r23572r23573
10011023            if (buffer_offset >= IDE_DISK_SECTOR_SIZE)
10021024            {
10031025               LOG(("%s:IDE completed PIO read\n", machine().describe_context()));
1004               continue_read();
1005               error = IDE_ERROR_DEFAULT;
1026               read_buffer_empty();
10061027            }
10071028         }
10081029         break;
r23572r23573
10621083}
10631084
10641085
1086void ide_controller_device::write_buffer_full()
1087{
1088   ide_device_interface *dev = slot[cur_drive]->dev();
1089
1090   if (command == IDE_COMMAND_SECURITY_UNLOCK)
1091   {
1092      if (user_password_enable && memcmp(buffer, user_password, 2 + 32) == 0)
1093      {
1094         LOGPRINT(("IDE Unlocked user password\n"));
1095         user_password_enable = 0;
1096      }
1097      if (master_password_enable && memcmp(buffer, master_password, 2 + 32) == 0)
1098      {
1099         LOGPRINT(("IDE Unlocked master password\n"));
1100         master_password_enable = 0;
1101      }
1102      if (PRINTF_IDE_PASSWORD)
1103      {
1104         int i;
1105
1106         for (i = 0; i < 34; i += 2)
1107         {
1108            if (i % 8 == 2)
1109               mame_printf_debug("\n");
1110
1111            mame_printf_debug("0x%02x, 0x%02x, ", buffer[i], buffer[i + 1]);
1112            //mame_printf_debug("0x%02x%02x, ", buffer[i], buffer[i + 1]);
1113         }
1114         mame_printf_debug("\n");
1115      }
1116
1117      /* clear the busy and error flags */
1118      status &= ~IDE_STATUS_ERROR;
1119      status &= ~IDE_STATUS_BUSY;
1120      status &= ~IDE_STATUS_BUFFER_READY;
1121
1122      if (master_password_enable || user_password_enable)
1123         security_error();
1124      else
1125         status |= IDE_STATUS_DRIVE_READY;
1126   }
1127   else if (command == IDE_COMMAND_TAITO_GNET_UNLOCK_2)
1128   {
1129      UINT8 key[5] = { 0 };
1130      int i, bad = 0;
1131      dev->read_key(key);
1132
1133      for (i=0; !bad && i<512; i++)
1134         bad = ((i < 2 || i >= 7) && buffer[i]) || ((i >= 2 && i < 7) && buffer[i] != key[i-2]);
1135
1136      status &= ~IDE_STATUS_BUSY;
1137      status &= ~IDE_STATUS_BUFFER_READY;
1138      if (bad)
1139         status |= IDE_STATUS_ERROR;
1140      else {
1141         status &= ~IDE_STATUS_ERROR;
1142         gnetreadlock= 0;
1143      }
1144   }
1145   else
1146      continue_write();
1147}
1148
1149void ide_controller_device::read_buffer_empty()
1150{
1151   continue_read();
1152   error = IDE_ERROR_DEFAULT;
1153}
1154
10651155READ16_MEMBER( ide_controller_device::read_cs1_pc )
10661156{
10671157   if (mem_mask == 0xff00)
r23572r23573
11701260   }
11711261}
11721262
1263void ide_controller_device::write_dma( UINT16 data )
1264{
1265   buffer[buffer_offset++] = data;
1266   buffer[buffer_offset++] = data >> 8;
1267
1268   /* if we're at the end of the buffer, handle it */
1269   if (buffer_offset >= IDE_DISK_SECTOR_SIZE)
1270   {
1271      LOG(("%s:IDE completed DMA write\n", machine().describe_context()));
1272      write_buffer_full();
1273   }
1274}
1275
11731276WRITE16_MEMBER( ide_controller_device::write_cs0 )
11741277{
11751278//   printf( "write cs0 %04x %04x %04x\n", offset, data, mem_mask );
r23572r23573
12041307            if (buffer_offset >= IDE_DISK_SECTOR_SIZE)
12051308            {
12061309               LOG(("%s:IDE completed PIO write\n", machine().describe_context()));
1207               if (command == IDE_COMMAND_SECURITY_UNLOCK)
1208               {
1209                  if (user_password_enable && memcmp(buffer, user_password, 2 + 32) == 0)
1210                  {
1211                     LOGPRINT(("IDE Unlocked user password\n"));
1212                     user_password_enable = 0;
1213                  }
1214                  if (master_password_enable && memcmp(buffer, master_password, 2 + 32) == 0)
1215                  {
1216                     LOGPRINT(("IDE Unlocked master password\n"));
1217                     master_password_enable = 0;
1218                  }
1219                  if (PRINTF_IDE_PASSWORD)
1220                  {
1221                     int i;
1222
1223                     for (i = 0; i < 34; i += 2)
1224                     {
1225                        if (i % 8 == 2)
1226                           mame_printf_debug("\n");
1227
1228                        mame_printf_debug("0x%02x, 0x%02x, ", buffer[i], buffer[i + 1]);
1229                        //mame_printf_debug("0x%02x%02x, ", buffer[i], buffer[i + 1]);
1230                     }
1231                     mame_printf_debug("\n");
1232                  }
1233
1234                  /* clear the busy and error flags */
1235                  status &= ~IDE_STATUS_ERROR;
1236                  status &= ~IDE_STATUS_BUSY;
1237                  status &= ~IDE_STATUS_BUFFER_READY;
1238
1239                  if (master_password_enable || user_password_enable)
1240                     security_error();
1241                  else
1242                     status |= IDE_STATUS_DRIVE_READY;
1243               }
1244               else if (command == IDE_COMMAND_TAITO_GNET_UNLOCK_2)
1245               {
1246                  UINT8 key[5] = { 0 };
1247                  int i, bad = 0;
1248                  dev->read_key(key);
1249
1250                  for (i=0; !bad && i<512; i++)
1251                     bad = ((i < 2 || i >= 7) && buffer[i]) || ((i >= 2 && i < 7) && buffer[i] != key[i-2]);
1252
1253                  status &= ~IDE_STATUS_BUSY;
1254                  status &= ~IDE_STATUS_BUFFER_READY;
1255                  if (bad)
1256                     status |= IDE_STATUS_ERROR;
1257                  else {
1258                     status &= ~IDE_STATUS_ERROR;
1259                     gnetreadlock= 0;
1260                  }
1261               }
1262               else
1263                  continue_write();
1264
1310               write_buffer_full();
12651311            }
12661312         }
12671313         break;
r23572r23573
14081454               else
14091455               {
14101456                  read_buffer_from_dma();
1411                  continue_write();
14121457               }
14131458            }
14141459         }
trunk/src/emu/machine/idectrl.h
r23572r23573
8989
9090   DECLARE_READ8_MEMBER(read_via_config);
9191   DECLARE_WRITE8_MEMBER(write_via_config);
92   UINT16 read_dma();
9293   DECLARE_READ16_MEMBER(read_cs0);
9394   DECLARE_READ16_MEMBER(read_cs1);
95   void write_dma(UINT16 data);
9496   DECLARE_WRITE16_MEMBER(write_cs0);
9597   DECLARE_WRITE16_MEMBER(write_cs1);
9698
r23572r23573
136138   void write_buffer_to_dma();
137139   void read_first_sector();
138140   void handle_command(UINT8 _command);
141   void read_buffer_empty();
142   void write_buffer_full();
139143
140144   UINT8           adapter_control;
141145   UINT8           error;

Previous 199869 Revisions Next


© 1997-2024 The MAME Team