Previous 199869 Revisions Next

r19355 Thursday 6th December, 2012 at 08:44:58 UTC by David Haywood
further mcd/ncd code reduction (nw)
[src/mame/machine]megacdcd.c megacdcd.h
[src/mess/drivers]ng_aes.c

trunk/src/mess/drivers/ng_aes.c
r19354r19355
10331033}
10341034
10351035
1036
1037/*
1038 *  CD-ROM / DMA control
1039 *
1040 *  DMA
1041
1042    FF0061  Write 0x40 means start DMA transfer
1043    FF0064  Source address (in copy mode), Target address (in filll mode)
1044    FF0068  Target address (in copy mode)
1045    FF006C  Fill word
1046    FF0070  Words count
1047    FF007E  \
1048    ......   | DMA programming words?   NeoGeoCD uses Sanyo Puppet LC8359 chip to
1049    FF008E  /                           interface with CD, and do DMA transfers
1050
1051    Memory access control
1052
1053    FF011C  DIP SWITCH (Region code)
1054    FF0105  Area Selector (5 = FIX, 0 = SPR, 4 = Z80, 1 = PCM)
1055    FF01A1  Sprite bank selector
1056    FF01A3  PCM bank selector
1057    FF0120  Prepare sprite area for transfer
1058    FF0122  Prepare PCM area for transfer
1059    FF0126  Prepare Z80 area for transfer
1060    FF0128  Prepare Fix area for transfer
1061    FF0140  Terminate work on Spr Area  (Sprites must be decoded here)
1062    FF0142  Terminate work on Pcm Area
1063    FF0146  Terminate work on Z80 Area  (Z80 needs to be reset)
1064    FF0148  Terminate work on Fix Area
1065
1066    CD-ROM:
1067    0xff0102 == 0xF0 start cd transfer
1068    int m=bcd(fast_r8(0x10f6c8));
1069    int s=bcd(fast_r8(0x10f6c9));
1070    int f=bcd(fast_r8(0x10f6ca));
1071    int seccount=fast_r16(0x10f688);
1072
1073    inisec=((m*60)+s)*75+f;
1074    inisec-=150;
1075    dstaddr=0x111204; // this must come from somewhere
1076
1077    the value @ 0x10f688 is decremented each time a sector is read until it's 0.
1078
1079 *
1080 */
1081
1082
10361083void ng_aes_state::NeoCDDoDMA()
10371084{
10381085
trunk/src/mame/machine/megacdcd.c
r19354r19355
2525   NeoCDCommsWordCount = 0;
2626   NeoCDAssyStatus = 0;
2727   SCD_CURLBA = 0;
28   for (int i=0;i<2352;i++)
29      NeoCDSectorData[i] = 0;
28
3029   bNeoCDLoadSector = false;
3130   CDC_REG0 = 0;
3231   nNeoCDIRQVectorAck = 0;
r19354r19355
10101009         NeoCDIRQUpdate(0);
10111010
10121011         if (nff0002 & 0x0500) {
1013            Read_LBA_To_Buffer_NeoCD();
1012            Read_LBA_To_Buffer(machine());
10141013         }
10151014      }
10161015   }
r19354r19355
10401039
10411040
10421041
1043INT32 lc89510_temp_device::CDEmuLoadSector(INT32 LBA, char* pBuffer)
1044{
1045//   printf("CDEmuLoadSector %d\n", LBA);
1046   //LBA += 150;
10471042
1048   cdrom_read_data(segacd.cd, LBA, pBuffer, CD_TRACK_MODE1);
10491043
1050   return LBA+1;// - 150;
1051}
10521044
1053
1054
1055
1056
10571045void lc89510_temp_device::NeoCDCommsReset()
10581046{
10591047   bNeoCDCommsSend  = false;
r19354r19355
10661054
10671055   NeoCDAssyStatus = 9;
10681056
1069   memset(NeoCDSectorData, 0, sizeof(NeoCDSectorData));
1070
10711057   bNeoCDLoadSector = false;
10721058
10731059   nff0016 = 0;
r19354r19355
11931179      //bprintf(PRINT_ERROR, _T("    LC8951 DOUTEN status invalid\n"));
11941180      return NULL;
11951181   }
1196   if (((LC8951RegistersW[REG_W_DACH] << 8) | LC8951RegistersW[REG_W_DACL]) + (NeoCDDMACount << 1) > 2352) {
1182   if (((LC8951RegistersW[REG_W_DACH] << 8) | LC8951RegistersW[REG_W_DACL]) + (NeoCDDMACount << 1) > LC89510_EXTERNAL_BUFFER_SIZE) {
11971183      //bprintf(PRINT_ERROR, _T("    DMA transfer exceeds current sector in LC8951 external buffer\n"));
1184
11981185      return NULL;
11991186   }
12001187
1201   return NeoCDSectorData + ((LC8951RegistersW[REG_W_DACH] << 8) | LC8951RegistersW[REG_W_DACL]);
1188   char* addr = (char*)CDC_BUFFER + ((LC8951RegistersW[REG_W_DACH] << 8) | LC8951RegistersW[REG_W_DACL]);
1189   return  addr;
12021190}
12031191
12041192void lc89510_temp_device::LC8915EndTransfer()
r19354r19355
12361224
12371225
12381226
1239/*
1240 *  CD-ROM / DMA control
1241 *
1242 *  DMA
12431227
1244    FF0061  Write 0x40 means start DMA transfer
1245    FF0064  Source address (in copy mode), Target address (in filll mode)
1246    FF0068  Target address (in copy mode)
1247    FF006C  Fill word
1248    FF0070  Words count
1249    FF007E  \
1250    ......   | DMA programming words?   NeoGeoCD uses Sanyo Puppet LC8359 chip to
1251    FF008E  /                           interface with CD, and do DMA transfers
1252
1253    Memory access control
1254
1255    FF011C  DIP SWITCH (Region code)
1256    FF0105  Area Selector (5 = FIX, 0 = SPR, 4 = Z80, 1 = PCM)
1257    FF01A1  Sprite bank selector
1258    FF01A3  PCM bank selector
1259    FF0120  Prepare sprite area for transfer
1260    FF0122  Prepare PCM area for transfer
1261    FF0126  Prepare Z80 area for transfer
1262    FF0128  Prepare Fix area for transfer
1263    FF0140  Terminate work on Spr Area  (Sprites must be decoded here)
1264    FF0142  Terminate work on Pcm Area
1265    FF0146  Terminate work on Z80 Area  (Z80 needs to be reset)
1266    FF0148  Terminate work on Fix Area
1267
1268    CD-ROM:
1269    0xff0102 == 0xF0 start cd transfer
1270    int m=bcd(fast_r8(0x10f6c8));
1271    int s=bcd(fast_r8(0x10f6c9));
1272    int f=bcd(fast_r8(0x10f6ca));
1273    int seccount=fast_r16(0x10f688);
1274
1275    inisec=((m*60)+s)*75+f;
1276    inisec-=150;
1277    dstaddr=0x111204; // this must come from somewhere
1278
1279    the value @ 0x10f688 is decremented each time a sector is read until it's 0.
1280
1281 *
1282 */
1283
1284void lc89510_temp_device::Read_LBA_To_Buffer_NeoCD()
1285{
1286   if ((nff0002 & 0x0500)) {
1287      if (NeoCDAssyStatus == 1 && bNeoCDLoadSector) {
1288
1289//          if (LC8951RegistersW[REG_W_CTRL0] & 0x80) {
1290            SCD_CURLBA++;
1291            SCD_CURLBA = CDEmuLoadSector(SCD_CURLBA, NeoCDSectorData + 4) -1;
1292//          }
1293
1294         if (LC8951RegistersW[REG_W_CTRL0] & 0x80) {
1295            LC8951UpdateHeader();
1296
1297            LC8951RegistersR[REG_R_STAT0] = 0x80;                              // STAT0
1298            LC8951RegistersR[REG_R_STAT1] = 0;                                 // STAT1
1299            LC8951RegistersR[REG_R_STAT2] = 0x10;                              // STAT2
1300            LC8951RegistersR[REG_R_STAT3] = 0;                                 // STAT3
1301
1302//              bprintf(PRINT_IMPORTANT, _T("    Sector %08i (%02i:%02i:%02i) read\n"), SCD_CURLBA, NeoCDSectorMin, NeoCDSectorSec, NeoCDSectorFrm);
1303
1304// CDZ protection hack? (error correction on the CDC should correct this?)
1305#if 1
1306            if (NeoCDSectorData[4 + 64] == 'g' && !strncmp(NeoCDSectorData + 4, "Copyright by SNK", 16)) {
1307//                  printf(PRINT_ERROR, _T("    simulated CDZ protection error\n"));
1308//                  bprintf(PRINT_ERROR, _T("    %.70hs\n"), NeoCDSectorData + 4);
1309
1310               NeoCDSectorData[4 + 64] = 'f';
1311
1312               // LC8951RegistersR[REG_R_STATB0] = 0x00;                                 // STAT0
1313            }
1314#endif
1315
1316            nIRQAcknowledge &= ~0x20;
1317            NeoCDIRQUpdate(0);
1318
1319            LC8951RegistersR[REG_R_IFSTAT] &= ~0x20;
1320
1321//              bprintf(PRINT_IMPORTANT, _T("    DECI interrupt triggered\n"));
1322         }
1323      }
1324
1325      bNeoCDLoadSector = true;
1326//      bNeoCDLoadSector = false;
1327   }
1328}
1329
1330
1331
13321228void lc89510_temp_device::scd_ctrl_checks(running_machine& machine)
13331229{
13341230   LC8951RegistersR[REG_R_STAT0] = 0x80;
r19354r19355
13381234
13391235   if (LC8951RegistersW[REG_W_IFCTRL] & 0x20)
13401236   {
1341      CHECK_SCD_LV5_INTERRUPT
1237   
1238      // todo: handle as interrupt callback
1239      if (is_neoCD)
1240      {
1241         nIRQAcknowledge &= ~0x20;
1242         NeoCDIRQUpdate(0);
1243      }
1244      else
1245      {
1246         CHECK_SCD_LV5_INTERRUPT     
1247      }
1248
1249
1250
13421251      LC8951RegistersR[REG_R_IFSTAT] &= ~0x20;
13431252      CDC_DECODE = 0;
13441253   }
r19354r19355
13921301            CDC_BUFFER[pt+1] = LC8951RegistersR[REG_R_HEAD1];
13931302            CDC_BUFFER[pt+2] = LC8951RegistersR[REG_R_HEAD2];
13941303            CDC_BUFFER[pt+3] = LC8951RegistersR[REG_R_HEAD3];
1304
1305
1306            if (is_neoCD)
1307            {
1308               // This simulates the protection used by the NeoCDZ, a number of games (samsrpg for example)
1309               // will not be recognized unless this happens.  Is this part of the CDC error correction
1310               // mechanism?
1311               char *buffer_hack = (char*)&CDC_BUFFER[pt];
1312               if (buffer_hack[4 + 64] == 'g' && !strncmp(buffer_hack + 4, "Copyright by SNK", 16))
1313               {
1314                  buffer_hack[4 + 64] = 'f';
1315               }
1316            }
1317
13951318         }
13961319         else
13971320         {
r19354r19355
14021325      }
14031326
14041327      scd_ctrl_checks(machine);
1328
1329
14051330   }
14061331
14071332
trunk/src/mame/machine/megacdcd.h
r19354r19355
143143#define SEK_IRQSTATUS_AUTO (0x2000)
144144#define SEK_IRQSTATUS_ACK  (0x1000)
145145
146#define LC89510_EXTERNAL_BUFFER_SIZE ((32 * 1024 * 2) + SECTOR_SIZE)
147
146148class lc89510_temp_device : public device_t
147149{
148150public:
r19354r19355
171173   segacd_t segacd;
172174
173175   UINT8    SCD_BUFFER[2560];
174   char NeoCDSectorData[2352];
175176
176177   UINT32   SCD_STATUS;
177178   UINT32   SCD_STATUS_CDC;
r19354r19355
183184   UINT16 CDC_REG0;
184185   UINT16 CDC_REG1;
185186
186   UINT8 CDC_BUFFER[(32 * 1024 * 2) + SECTOR_SIZE];
187   UINT8 CDC_BUFFER[LC89510_EXTERNAL_BUFFER_SIZE];
187188
188189
189190   UINT8 CDD_RX[10];
r19354r19355
290291   int get_nNeoCDIRQVector(void) { return nNeoCDIRQVector; }
291292
292293   void NeoCDIRQUpdate(UINT8 byteValue);
293   void Read_LBA_To_Buffer_NeoCD();
294294   void NeoCDCommsControl(UINT8 clock, UINT8 send);
295295   void NeoCDProcessCommand();
296296   void LC8951UpdateHeader();
r19354r19355
301301   UINT8 neocd_cdd_rx_r();
302302   void NeoCDCommsReset();
303303
304   INT32 CDEmuLoadSector(INT32 LBA, char* pBuffer);
305304
306305   UINT16 nff0016_r(void);
307306   void nff0016_set(UINT16 wordValue);

Previous 199869 Revisions Next


© 1997-2024 The MAME Team