Previous 199869 Revisions Next

r19046 Monday 19th November, 2012 at 16:19:03 UTC by hap
improve memory handling part 2
[src/emu/sound]ymz280b.c
[src/mame/drivers]firebeat.c

trunk/src/mame/drivers/firebeat.c
r19045r19046
18661866
18671867READ8_MEMBER(firebeat_state::soundram_r)
18681868{
1869   // firebeat expects first read after setting the address to be dummy.  fixes "YMZ test".
1869   // HACK: firebeat expects first read after setting the address to be dummy.  fixes "YMZ test".
18701870   if (offset > 0)
18711871   {
18721872      offset--;
r19045r19046
20412041
20422042MACHINE_RESET_MEMBER(firebeat_state,firebeat)
20432043{
2044   int i;
2045   UINT8 *sound = memregion("ymz")->base();
2046
2047   for (i=0; i < 0x200000; i++)
2048   {
2049      sound[i] = m_flash[1]->read(i);
2050      sound[i+0x200000] = m_flash[2]->read(i);
2051   }
2052
20532044   m_layer = 0;
20542045}
20552046
trunk/src/emu/sound/ymz280b.c
r19045r19046
143143}
144144
145145
146INLINE UINT8 ymz280b_read_memory(UINT8 *base, UINT32 size, UINT32 offset)
146INLINE UINT8 ymz280b_read_memory(ymz280b_state *chip, UINT32 offset)
147147{
148   if (offset < size)
149      return base[offset];
148   if (chip->ext_ram_read.isnull())
149   {
150      if (offset < chip->region_size)
151         return chip->region_base[offset];
150152
151   /* 16MB chip limit (shouldn't happen) */
152   else if (offset > 0xffffff)
153      return base[offset & 0xffffff];
153      /* 16MB chip limit (shouldn't happen) */
154      else if (offset > 0xffffff)
155         return chip->region_base[offset & 0xffffff];
154156
157      else
158         return 0;
159   }
155160   else
156      return 0;
161      return chip->ext_ram_read(offset);
157162}
158163
159164
r19045r19046
277282
278283***********************************************************************************************/
279284
280static int generate_adpcm(struct YMZ280BVoice *voice, UINT8 *base, UINT32 size, INT16 *buffer, int samples)
285static int generate_adpcm(ymz280b_state *chip, struct YMZ280BVoice *voice, INT16 *buffer, int samples)
281286{
282287   int position = voice->position;
283288   int signal = voice->signal;
r19045r19046
291296      while (samples)
292297      {
293298         /* compute the new amplitude and update the current step */
294         val = ymz280b_read_memory(base, size, position / 2) >> ((~position & 1) << 2);
299         val = ymz280b_read_memory(chip, position / 2) >> ((~position & 1) << 2);
295300         signal += (step * diff_lookup[val & 15]) / 8;
296301
297302         /* clamp to the maximum */
r19045r19046
330335      while (samples)
331336      {
332337         /* compute the new amplitude and update the current step */
333         val = ymz280b_read_memory(base, size, position / 2) >> ((~position & 1) << 2);
338         val = ymz280b_read_memory(chip, position / 2) >> ((~position & 1) << 2);
334339         signal += (step * diff_lookup[val & 15]) / 8;
335340
336341         /* clamp to the maximum */
r19045r19046
393398
394399***********************************************************************************************/
395400
396static int generate_pcm8(struct YMZ280BVoice *voice, UINT8 *base, UINT32 size, INT16 *buffer, int samples)
401static int generate_pcm8(ymz280b_state *chip, struct YMZ280BVoice *voice, INT16 *buffer, int samples)
397402{
398403   int position = voice->position;
399404   int val;
r19045r19046
405410      while (samples)
406411      {
407412         /* fetch the current value */
408         val = ymz280b_read_memory(base, size, position / 2);
413         val = ymz280b_read_memory(chip, position / 2);
409414
410415         /* output to the buffer, scaling by the volume */
411416         *buffer++ = (INT8)val * 256;
r19045r19046
430435      while (samples)
431436      {
432437         /* fetch the current value */
433         val = ymz280b_read_memory(base, size, position / 2);
438         val = ymz280b_read_memory(chip, position / 2);
434439
435440         /* output to the buffer, scaling by the volume */
436441         *buffer++ = (INT8)val * 256;
r19045r19046
467472
468473***********************************************************************************************/
469474
470static int generate_pcm16(struct YMZ280BVoice *voice, UINT8 *base, UINT32 size, INT16 *buffer, int samples)
475static int generate_pcm16(ymz280b_state *chip, struct YMZ280BVoice *voice, INT16 *buffer, int samples)
471476{
472477   int position = voice->position;
473478   int val;
r19045r19046
479484      while (samples)
480485      {
481486         /* fetch the current value */
482         val = (INT16)((ymz280b_read_memory(base, size, position / 2 + 1) << 8) + ymz280b_read_memory(base, size, position / 2 + 0));
487         val = (INT16)((ymz280b_read_memory(chip, position / 2 + 0) << 8) + ymz280b_read_memory(chip, position / 2 + 1));
483488
484489         /* output to the buffer, scaling by the volume */
485490         *buffer++ = val;
r19045r19046
504509      while (samples)
505510      {
506511         /* fetch the current value */
507         val = (INT16)((ymz280b_read_memory(base, size, position / 2 + 1) << 8) + ymz280b_read_memory(base, size, position / 2 + 0));
512         val = (INT16)((ymz280b_read_memory(chip, position / 2 + 0) << 8) + ymz280b_read_memory(chip, position / 2 + 1));
508513
509514         /* output to the buffer, scaling by the volume */
510515         *buffer++ = val;
r19045r19046
603608      /* generate them into our buffer */
604609      switch (voice->playing << 7 | voice->mode)
605610      {
606         case 0x81:   samples_left = generate_adpcm(voice, chip->region_base, chip->region_size, chip->scratch, new_samples);      break;
607         case 0x82:   samples_left = generate_pcm8(voice, chip->region_base, chip->region_size, chip->scratch, new_samples);      break;
608         case 0x83:   samples_left = generate_pcm16(voice, chip->region_base, chip->region_size, chip->scratch, new_samples);      break;
609         default:   samples_left = 0; memset(chip->scratch, 0, new_samples * sizeof(chip->scratch[0]));                     break;
611         case 0x81:   samples_left = generate_adpcm(chip, voice, chip->scratch, new_samples); break;
612         case 0x82:   samples_left = generate_pcm8(chip, voice, chip->scratch, new_samples); break;
613         case 0x83:   samples_left = generate_pcm16(chip, voice, chip->scratch, new_samples); break;
614         default:   samples_left = 0; memset(chip->scratch, 0, new_samples * sizeof(chip->scratch[0])); break;
610615      }
611616
612617      /* if there are leftovers, ramp back to 0 */
r19045r19046
10121017         return 0xff;
10131018
10141019      /* read from external memory */
1015      UINT8 result;
1016      if (!chip->ext_ram_read.isnull())
1017         result = chip->ext_ram_read(chip->rom_readback_addr);
1018      else
1019         result = ymz280b_read_memory(chip->region_base, chip->region_size, chip->rom_readback_addr);
1020
1020      UINT8 result = ymz280b_read_memory(chip, chip->rom_readback_addr);
10211021      chip->rom_readback_addr = (chip->rom_readback_addr + 1) & 0xffffff;
10221022      return result;
10231023   }

Previous 199869 Revisions Next


© 1997-2024 The MAME Team