Previous 199869 Revisions Next

r22738 Friday 10th May, 2013 at 15:06:32 UTC by smf
modernised YMF271 [smf]
[src/emu/sound]ymf271.c ymf271.h
[src/mame/drivers]ms32.c seibuspi.c zn.c

trunk/src/mame/drivers/ms32.c
r22737r22738
13591359
13601360static ADDRESS_MAP_START( ms32_sound_map, AS_PROGRAM, 8, ms32_state )
13611361   AM_RANGE(0x0000, 0x3eff) AM_ROM
1362   AM_RANGE(0x3f00, 0x3f0f) AM_DEVREADWRITE_LEGACY("ymf", ymf271_r,ymf271_w)
1362   AM_RANGE(0x3f00, 0x3f0f) AM_DEVREADWRITE("ymf", ymf271_device, read, write)
13631363   AM_RANGE(0x3f10, 0x3f10) AM_READWRITE(latch_r,to_main_w)
13641364   AM_RANGE(0x3f20, 0x3f20) AM_READNOP /* 2nd latch ? */
13651365   AM_RANGE(0x3f20, 0x3f20) AM_WRITENOP /* to_main2_w  ? */
trunk/src/mame/drivers/zn.c
r22737r22738
16191619static ADDRESS_MAP_START( psarc_snd_map, AS_PROGRAM, 16, zn_state )
16201620   AM_RANGE(0x000000, 0x07ffff) AM_ROM
16211621   AM_RANGE(0x080000, 0x0fffff) AM_RAM
1622   AM_RANGE(0x100000, 0x10001f) AM_DEVREADWRITE8_LEGACY("ymf", ymf271_r, ymf271_w, 0x00ff )
1622   AM_RANGE(0x100000, 0x10001f) AM_DEVREADWRITE8("ymf", ymf271_device, read, write, 0x00ff )
16231623   AM_RANGE(0x180008, 0x180009) AM_READ8(soundlatch_byte_r, 0x00ff )
16241624   AM_RANGE(0x000000, 0x07ffff) AM_WRITENOP
16251625   AM_RANGE(0x100020, 0xffffff) AM_WRITENOP
trunk/src/mame/drivers/seibuspi.c
r22737r22738
10561056   AM_RANGE(0x400b, 0x400b) AM_WRITENOP            /* Unknown */
10571057   AM_RANGE(0x4013, 0x4013) AM_READ(z80_coin_r)
10581058   AM_RANGE(0x401b, 0x401b) AM_WRITE(z80_bank_w)       /* control register: bits 0-2 = bank @ 8000, bit 3 = watchdog? */
1059   AM_RANGE(0x6000, 0x600f) AM_DEVREADWRITE_LEGACY("ymf", ymf271_r, ymf271_w)
1059   AM_RANGE(0x6000, 0x600f) AM_DEVREADWRITE("ymf", ymf271_device, read, write)
10601060   AM_RANGE(0x8000, 0xffff) AM_ROMBANK("bank4")
10611061ADDRESS_MAP_END
10621062
r22737r22738
11021102   m_eeprom->set_cs_line((data & 0x20) ? CLEAR_LINE : ASSERT_LINE);
11031103}
11041104
1105static const ymf271_interface ymf271_config =
1106{
1107   DEVCB_DRIVER_MEMBER(seibuspi_state,flashrom_read),
1108   DEVCB_DRIVER_MEMBER(seibuspi_state,flashrom_write),
1109   DEVCB_DRIVER_LINE_MEMBER(seibuspi_state,irqhandler)
1110};
1111
11121105/********************************************************************/
11131106
11141107static ADDRESS_MAP_START( seibu386_map, AS_PROGRAM, 32, seibuspi_state )
r22737r22738
18701863   MCFG_SPEAKER_STANDARD_STEREO("lspeaker", "rspeaker")
18711864
18721865   MCFG_SOUND_ADD("ymf", YMF271, XTAL_16_9344MHz)
1873   MCFG_SOUND_CONFIG(ymf271_config)
1866   MCFG_YMF271_IRQ_HANDLER(WRITELINE(seibuspi_state, irqhandler))
1867   MCFG_YMF271_EXT_READ_HANDLER(READ8(seibuspi_state, flashrom_read))
1868   MCFG_YMF271_EXT_WRITE_HANDLER(WRITE8(seibuspi_state,flashrom_write))
1869
18741870   MCFG_SOUND_ROUTE(0, "lspeaker", 1.0)
18751871   MCFG_SOUND_ROUTE(1, "rspeaker", 1.0)
18761872MACHINE_CONFIG_END
r22737r22738
19471943   MCFG_CPU_CLOCK(XTAL_4_9152MHz)
19481944
19491945   MCFG_SOUND_REPLACE("ymf", YMF271, XTAL_16_384MHz)
1950   MCFG_SOUND_CONFIG(ymf271_config)
1946   MCFG_YMF271_IRQ_HANDLER(WRITELINE(seibuspi_state, irqhandler))
1947   MCFG_YMF271_EXT_READ_HANDLER(READ8(seibuspi_state, flashrom_read))
1948   MCFG_YMF271_EXT_WRITE_HANDLER(WRITE8(seibuspi_state,flashrom_write))
19511949
19521950   MCFG_SOUND_ROUTE(0, "lspeaker", 1.0)
19531951   MCFG_SOUND_ROUTE(1, "rspeaker", 1.0)
trunk/src/emu/sound/ymf271.c
r22737r22738
3333
3434//#define log2(n) (log((float) n)/log((float) 2))
3535
36struct YMF271Slot
37{
38   INT8  extout;
39   UINT8 lfoFreq;
40   INT8  lfowave;
41   INT8  pms, ams;
42   INT8  detune;
43   INT8  multiple;
44   INT8  tl;
45   INT8  keyscale;
46   INT8  ar;
47   INT8  decay1rate, decay2rate;
48   INT8  decay1lvl;
49   INT8  relrate;
50   INT32 fns;
51   INT8  block;
52   INT8  feedback;
53   INT8  waveform;
54   INT8  accon;
55   INT8  algorithm;
56   INT8  ch0_level, ch1_level, ch2_level, ch3_level;
57
58   UINT32 startaddr;
59   UINT32 loopaddr;
60   UINT32 endaddr;
61   INT8   fs, srcnote, srcb;
62
63   INT64 step;
64   INT64 stepptr;
65
66   INT8 active;
67   INT8 bits;
68
69   // envelope generator
70   INT32 volume;
71   INT32 env_state;
72   INT32 env_attack_step;      // volume increase step in attack state
73   INT32 env_decay1_step;
74   INT32 env_decay2_step;
75   INT32 env_release_step;
76
77   INT64 feedback_modulation0;
78   INT64 feedback_modulation1;
79
80   INT32 lfo_phase, lfo_step;
81   INT32 lfo_amplitude;
82   double lfo_phasemod;
83};
84
85struct YMF271Group
86{
87   INT8 sync, pfm;
88};
89
90struct YMF271Chip
91{
92   YMF271Slot slots[48];
93   YMF271Group groups[12];
94
95   INT32 timerA, timerB;
96   INT32 timerAVal, timerBVal;
97   INT32 irqstate;
98   INT8  status;
99   INT8  enable;
100
101   emu_timer *timA, *timB;
102
103   INT8  reg0, reg1, reg2, reg3, pcmreg, timerreg;
104   UINT32 ext_address;
105   UINT8 ext_read;
106
107   const UINT8 *rom;
108   devcb_resolved_read8 ext_mem_read;
109   devcb_resolved_write8 ext_mem_write;
110   devcb_resolved_write_line irq_callback;
111
112   UINT32 clock;
113   sound_stream * stream;
114   device_t *device;
115};
116
11736// slot mapping assists
11837static const int fm_tab[] = { 0, 1, 2, -1, 3, 4, 5, -1, 6, 7, 8, -1, 9, 10, 11, -1 };
11938static const int pcm_tab[] = { 0, 4, 8, -1, 12, 16, 20, -1, 24, 28, 32, -1, 36, 40, 44, -1 };
r22737r22738
271190static int total_level[128];
272191static int env_volume_table[256];
273192
274INLINE YMF271Chip *get_safe_token(device_t *device)
275{
276   assert(device != NULL);
277   assert(device->type() == YMF271);
278   return (YMF271Chip *)downcast<ymf271_device *>(device)->token();
279}
280193
281
282194INLINE int GET_KEYSCALED_RATE(int rate, int keycode, int keyscale)
283195{
284196   int newrate = rate + RKS_Table[keycode][keyscale];
r22737r22738
347259
348260static const double fs_frequency[4] = { 1.0/1.0, 1.0/2.0, 1.0/4.0, 1.0/8.0 };
349261
350INLINE void calculate_step(YMF271Slot *slot)
262void ymf271_device::calculate_step(YMF271Slot *slot)
351263{
352264   double st;
353265
r22737r22738
377289   }
378290}
379291
380static void update_envelope(YMF271Slot *slot)
292void ymf271_device::update_envelope(YMF271Slot *slot)
381293{
382294   switch (slot->env_state)
383295   {
r22737r22738
430342   }
431343}
432344
433static void init_envelope(YMF271Slot *slot)
345void ymf271_device::init_envelope(YMF271Slot *slot)
434346{
435347   int keycode, rate;
436348   int attack_length, decay1_length, decay2_length, release_length;
r22737r22738
479391   slot->env_state = ENV_ATTACK;
480392}
481393
482static void init_lfo(YMF271Slot *slot)
394void ymf271_device::init_lfo(YMF271Slot *slot)
483395{
484396   slot->lfo_phase = 0;
485397   slot->lfo_amplitude = 0;
r22737r22738
488400   slot->lfo_step = (int)((((double)LFO_LENGTH * LFO_frequency_table[slot->lfoFreq]) / 44100.0) * 256.0);
489401}
490402
491INLINE void update_lfo(YMF271Slot *slot)
403void ymf271_device::update_lfo(YMF271Slot *slot)
492404{
493405   slot->lfo_phase += slot->lfo_step;
494406
r22737r22738
498410   calculate_step(slot);
499411}
500412
501INLINE int calculate_slot_volume(YMF271Slot *slot)
413int ymf271_device::calculate_slot_volume(YMF271Slot *slot)
502414{
503415   UINT64 volume;
504416   UINT64 env_volume;
r22737r22738
519431   return volume;
520432}
521433
522static void update_pcm(YMF271Chip *chip, int slotnum, INT32 *mixp, int length)
434void ymf271_device::update_pcm(int slotnum, INT32 *mixp, int length)
523435{
524436   int i;
525437   int final_volume;
526438   INT16 sample;
527439   INT64 ch0_vol, ch1_vol; //, ch2_vol, ch3_vol;
528   const UINT8 *rombase;
529440
530   YMF271Slot *slot = &chip->slots[slotnum];
531   rombase = chip->rom;
441   YMF271Slot *slot = &m_slots[slotnum];
532442
533443   if (!slot->active)
534444   {
r22737r22738
545455      if (slot->bits == 8)
546456      {
547457         // 8bit
548         sample = rombase[slot->startaddr + (slot->stepptr>>16)]<<8;
458         sample = m_rom[slot->startaddr + (slot->stepptr>>16)]<<8;
549459      }
550460      else
551461      {
552462         // 12bit
553463         if (slot->stepptr & 0x10000)
554            sample = rombase[slot->startaddr + (slot->stepptr>>17)*3 + 2]<<8 | ((rombase[slot->startaddr + (slot->stepptr>>17)*3 + 1] << 4) & 0xf0);
464            sample = m_rom[slot->startaddr + (slot->stepptr>>17)*3 + 2]<<8 | ((m_rom[slot->startaddr + (slot->stepptr>>17)*3 + 1] << 4) & 0xf0);
555465         else
556            sample = rombase[slot->startaddr + (slot->stepptr>>17)*3]<<8 | (rombase[slot->startaddr + (slot->stepptr>>17)*3 + 1] & 0xf0);
466            sample = m_rom[slot->startaddr + (slot->stepptr>>17)*3]<<8 | (m_rom[slot->startaddr + (slot->stepptr>>17)*3 + 1] & 0xf0);
557467      }
558468
559469      update_envelope(slot);
r22737r22738
585495// calculates 2 operator FM using algorithm 0
586496// <--------|
587497// +--[S1]--+--[S3]-->
588INLINE INT32 calculate_2op_fm_0(YMF271Chip *chip, int slotnum1, int slotnum2)
498INT32 ymf271_device::calculate_2op_fm_0(int slotnum1, int slotnum2)
589499{
590   YMF271Slot *slot1 = &chip->slots[slotnum1];
591   YMF271Slot *slot2 = &chip->slots[slotnum2];
500   YMF271Slot *slot1 = &m_slots[slotnum1];
501   YMF271Slot *slot2 = &m_slots[slotnum2];
592502   INT64 env1, env2;
593503   INT64 slot1_output, slot2_output;
594504   INT64 phase_mod;
r22737r22738
622532// calculates 2 operator FM using algorithm 1
623533// <-----------------|
624534// +--[S1]--+--[S3]--|-->
625INLINE INT32 calculate_2op_fm_1(YMF271Chip *chip, int slotnum1, int slotnum2)
535INT32 ymf271_device::calculate_2op_fm_1(int slotnum1, int slotnum2)
626536{
627   YMF271Slot *slot1 = &chip->slots[slotnum1];
628   YMF271Slot *slot2 = &chip->slots[slotnum2];
537   YMF271Slot *slot1 = &m_slots[slotnum1];
538   YMF271Slot *slot2 = &m_slots[slotnum2];
629539   INT64 env1, env2;
630540   INT64 slot1_output, slot2_output;
631541   INT64 phase_mod;
r22737r22738
657567}
658568
659569// calculates the output of one FM operator
660INLINE INT32 calculate_1op_fm_0(YMF271Chip *chip, int slotnum, int phase_modulation)
570INT32 ymf271_device::calculate_1op_fm_0(int slotnum, int phase_modulation)
661571{
662   YMF271Slot *slot = &chip->slots[slotnum];
572   YMF271Slot *slot = &m_slots[slotnum];
663573   INT64 env;
664574   INT64 slot_output;
665575   INT64 phase_mod = phase_modulation;
r22737r22738
681591// calculates the output of one FM operator with feedback modulation
682592// <--------|
683593// +--[S1]--|
684INLINE INT32 calculate_1op_fm_1(YMF271Chip *chip, int slotnum)
594INT32 ymf271_device::calculate_1op_fm_1(int slotnum)
685595{
686   YMF271Slot *slot = &chip->slots[slotnum];
596   YMF271Slot *slot = &m_slots[slotnum];
687597   INT64 env;
688598   INT64 slot_output;
689599   INT64 feedback;
r22737r22738
704614   return slot_output;
705615}
706616
707static STREAM_UPDATE( ymf271_update )
617//-------------------------------------------------
618//  sound_stream_update - handle a stream update
619//-------------------------------------------------
620
621void ymf271_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples)
708622{
709623   int i, j;
710624   int op;
711625   INT32 *mixp;
712626   INT32 mix[48000*2];
713   YMF271Chip *chip = (YMF271Chip *)param;
714627
715628   memset(mix, 0, sizeof(mix[0])*samples*2);
716629
717630   for (j = 0; j < 12; j++)
718631   {
719      YMF271Group *slot_group = &chip->groups[j];
632      YMF271Group *slot_group = &m_groups[j];
720633      mixp = &mix[0];
721634
722635      if (slot_group->pfm && slot_group->sync != 3)
723636      {
724637         mame_printf_debug("Group %d: PFM, Sync = %d, Waveform Slot1 = %d, Slot2 = %d, Slot3 = %d, Slot4 = %d\n",
725            j, slot_group->sync, chip->slots[j+0].waveform, chip->slots[j+12].waveform, chip->slots[j+24].waveform, chip->slots[j+36].waveform);
638            j, slot_group->sync, m_slots[j+0].waveform, m_slots[j+12].waveform, m_slots[j+24].waveform, m_slots[j+36].waveform);
726639      }
727640
728641      switch (slot_group->sync)
r22737r22738
735648            int slot4 = j + (3*12);
736649            mixp = &mix[0];
737650
738            if (chip->slots[slot1].active)
651            if (m_slots[slot1].active)
739652            {
740653               for (i = 0; i < samples; i++)
741654               {
742655                  INT64 output1 = 0, output2 = 0, output3 = 0, output4 = 0, phase_mod1 = 0, phase_mod2 = 0;
743                  switch (chip->slots[slot1].algorithm)
656                  switch (m_slots[slot1].algorithm)
744657                  {
745658                     // <--------|
746659                     // +--[S1]--+--[S3]--+--[S2]--+--[S4]-->
747660                     case 0:
748                        phase_mod1 = calculate_2op_fm_0(chip, slot1, slot3);
749                        phase_mod2 = calculate_1op_fm_0(chip, slot2, phase_mod1);
750                        output4 = calculate_1op_fm_0(chip, slot4, phase_mod2);
661                        phase_mod1 = calculate_2op_fm_0(slot1, slot3);
662                        phase_mod2 = calculate_1op_fm_0(slot2, phase_mod1);
663                        output4 = calculate_1op_fm_0(slot4, phase_mod2);
751664                        break;
752665
753666                     // <-----------------|
754667                     // +--[S1]--+--[S3]--+--[S2]--+--[S4]-->
755668                     case 1:
756                        phase_mod1 = calculate_2op_fm_1(chip, slot1, slot3);
757                        phase_mod2 = calculate_1op_fm_0(chip, slot2, phase_mod1);
758                        output4 = calculate_1op_fm_0(chip, slot4, phase_mod2);
669                        phase_mod1 = calculate_2op_fm_1(slot1, slot3);
670                        phase_mod2 = calculate_1op_fm_0(slot2, phase_mod1);
671                        output4 = calculate_1op_fm_0(slot4, phase_mod2);
759672                        break;
760673
761674                     // <--------|
762675                     // +--[S1]--|
763676                     // ---[S3]--+--[S2]--+--[S4]-->
764677                     case 2:
765                        phase_mod1 = (calculate_1op_fm_1(chip, slot1) + calculate_1op_fm_0(chip, slot3, 0)) / 2;
766                        phase_mod2 = calculate_1op_fm_0(chip, slot2, phase_mod1);
767                        output4 = calculate_1op_fm_0(chip, slot4, phase_mod2);
678                        phase_mod1 = (calculate_1op_fm_1(slot1) + calculate_1op_fm_0(slot3, 0)) / 2;
679                        phase_mod2 = calculate_1op_fm_0(slot2, phase_mod1);
680                        output4 = calculate_1op_fm_0(slot4, phase_mod2);
768681                        break;
769682
770683                     //          <--------|
771684                     //          +--[S1]--|
772685                     // ---[S3]--+--[S2]--+--[S4]-->
773686                     case 3:
774                        phase_mod1 = calculate_1op_fm_0(chip, slot3, 0);
775                        phase_mod2 = (calculate_1op_fm_0(chip, slot2, phase_mod1) + calculate_1op_fm_1(chip, slot1)) / 2;
776                        output4 = calculate_1op_fm_0(chip, slot4, phase_mod2);
687                        phase_mod1 = calculate_1op_fm_0(slot3, 0);
688                        phase_mod2 = (calculate_1op_fm_0(slot2, phase_mod1) + calculate_1op_fm_1(slot1)) / 2;
689                        output4 = calculate_1op_fm_0(slot4, phase_mod2);
777690                        break;
778691
779692                     // <--------|  --[S2]--|
780693                     // ---[S1]--|-+--[S3]--+--[S4]-->
781694                     case 4:
782                        phase_mod1 = (calculate_2op_fm_0(chip, slot1, slot3) + calculate_1op_fm_0(chip, slot2, 0)) / 2;
783                        output4 = calculate_1op_fm_0(chip, slot4, phase_mod1);
695                        phase_mod1 = (calculate_2op_fm_0(slot1, slot3) + calculate_1op_fm_0(slot2, 0)) / 2;
696                        output4 = calculate_1op_fm_0(slot4, phase_mod1);
784697                        break;
785698
786699                     //           --[S2]-----|
787700                     // <-----------------|  |
788701                     // ---[S1]--+--[S3]--|--+--[S4]-->
789702                     case 5:
790                        phase_mod1 = (calculate_2op_fm_1(chip, slot1, slot3) + calculate_1op_fm_0(chip, slot2, 0)) / 2;
791                        output4 = calculate_1op_fm_0(chip, slot4, phase_mod1);
703                        phase_mod1 = (calculate_2op_fm_1(slot1, slot3) + calculate_1op_fm_0(slot2, 0)) / 2;
704                        output4 = calculate_1op_fm_0(slot4, phase_mod1);
792705                        break;
793706
794707                     // ---[S2]-----+--[S4]--|
r22737r22738
796709                     // <--------|           |
797710                     // +--[S1]--|--+--[S3]--+-->
798711                     case 6:
799                        output3 = calculate_2op_fm_0(chip, slot1, slot3);
800                        phase_mod1 = calculate_1op_fm_0(chip, slot2, 0);
801                        output4 = calculate_1op_fm_0(chip, slot4, phase_mod1);
712                        output3 = calculate_2op_fm_0(slot1, slot3);
713                        phase_mod1 = calculate_1op_fm_0(slot2, 0);
714                        output4 = calculate_1op_fm_0(slot4, phase_mod1);
802715                        break;
803716
804717                     // ---[S2]--+--[S4]-----|
r22737r22738
806719                     // <-----------------|  |
807720                     // +--[S1]--+--[S3]--|--+-->
808721                     case 7:
809                        output3 = calculate_2op_fm_1(chip, slot1, slot3);
810                        phase_mod1 = calculate_1op_fm_0(chip, slot2, 0);
811                        output4 = calculate_1op_fm_0(chip, slot4, phase_mod1);
722                        output3 = calculate_2op_fm_1(slot1, slot3);
723                        phase_mod1 = calculate_1op_fm_0(slot2, 0);
724                        output4 = calculate_1op_fm_0(slot4, phase_mod1);
812725                        break;
813726
814727                     // ---[S3]--+--[S2]--+--[S4]--|
r22737r22738
816729                     // <--------|                 |
817730                     // +--[S1]--|-----------------+-->
818731                     case 8:
819                        output1 = calculate_1op_fm_1(chip, slot1);
820                        phase_mod1 = calculate_1op_fm_0(chip, slot3, 0);
821                        phase_mod2 = calculate_1op_fm_0(chip, slot2, phase_mod1);
822                        output4 = calculate_1op_fm_0(chip, slot4, phase_mod2);
732                        output1 = calculate_1op_fm_1(slot1);
733                        phase_mod1 = calculate_1op_fm_0(slot3, 0);
734                        phase_mod2 = calculate_1op_fm_0(slot2, phase_mod1);
735                        output4 = calculate_1op_fm_0(slot4, phase_mod2);
823736                        break;
824737
825738                     //         <--------|
r22737r22738
828741                     // --[S3]--|        |
829742                     // --[S2]--+--[S4]--+-->
830743                     case 9:
831                        phase_mod1 = (calculate_1op_fm_0(chip, slot2, 0) + calculate_1op_fm_0(chip, slot3, 0)) / 2;
832                        output4 = calculate_1op_fm_0(chip, slot4, phase_mod1);
833                        output1 = calculate_1op_fm_1(chip, slot1);
744                        phase_mod1 = (calculate_1op_fm_0(slot2, 0) + calculate_1op_fm_0(slot3, 0)) / 2;
745                        output4 = calculate_1op_fm_0(slot4, phase_mod1);
746                        output1 = calculate_1op_fm_1(slot1);
834747                        break;
835748
836749                     //           --[S4]--|
r22737r22738
838751                     // <--------|        |
839752                     // +--[S1]--+--[S3]--+-->
840753                     case 10:
841                        output3 = calculate_2op_fm_0(chip, slot1, slot3);
842                        output2 = calculate_1op_fm_0(chip, slot2, 0);
843                        output4 = calculate_1op_fm_0(chip, slot4, 0);
754                        output3 = calculate_2op_fm_0(slot1, slot3);
755                        output2 = calculate_1op_fm_0(slot2, 0);
756                        output4 = calculate_1op_fm_0(slot4, 0);
844757                        break;
845758
846759                     //           --[S4]-----|
r22737r22738
848761                     // <-----------------|  |
849762                     // +--[S1]--+--[S3]--|--+-->
850763                     case 11:
851                        output3 = calculate_2op_fm_1(chip, slot1, slot3);
852                        output2 = calculate_1op_fm_0(chip, slot2, 0);
853                        output4 = calculate_1op_fm_0(chip, slot4, 0);
764                        output3 = calculate_2op_fm_1(slot1, slot3);
765                        output2 = calculate_1op_fm_0(slot2, 0);
766                        output4 = calculate_1op_fm_0(slot4, 0);
854767                        break;
855768
856769                     //            |--+--[S4]--+
857770                     // <--------| |--+--[S3]--+
858771                     // +--[S1]--+-|--+--[S2]--+-->
859772                     case 12:
860                        phase_mod1 = calculate_1op_fm_1(chip, slot1);
861                        output2 = calculate_1op_fm_0(chip, slot2, phase_mod1);
862                        output3 = calculate_1op_fm_0(chip, slot3, phase_mod1);
863                        output4 = calculate_1op_fm_0(chip, slot4, phase_mod1);
773                        phase_mod1 = calculate_1op_fm_1(slot1);
774                        output2 = calculate_1op_fm_0(slot2, phase_mod1);
775                        output3 = calculate_1op_fm_0(slot3, phase_mod1);
776                        output4 = calculate_1op_fm_0(slot4, phase_mod1);
864777                        break;
865778
866779                     // ---[S3]--+--[S2]--+
r22737r22738
869782                     // <--------|        |
870783                     // +--[S1]--|--------+-->
871784                     case 13:
872                        output1 = calculate_1op_fm_1(chip, slot1);
873                        phase_mod1 = calculate_1op_fm_0(chip, slot3, 0);
874                        output2 = calculate_1op_fm_0(chip, slot2, phase_mod1);
875                        output4 = calculate_1op_fm_0(chip, slot4, 0);
785                        output1 = calculate_1op_fm_1(slot1);
786                        phase_mod1 = calculate_1op_fm_0(slot3, 0);
787                        output2 = calculate_1op_fm_0(slot2, phase_mod1);
788                        output4 = calculate_1op_fm_0(slot4, 0);
876789                        break;
877790
878791                     // ---[S2]----+--[S4]--+
r22737r22738
880793                     // <--------| +--[S3]--|
881794                     // +--[S1]--+-|--------+-->
882795                     case 14:
883                        output1 = calculate_1op_fm_1(chip, slot1);
796                        output1 = calculate_1op_fm_1(slot1);
884797                        phase_mod1 = output1;
885                        output3 = calculate_1op_fm_0(chip, slot3, phase_mod1);
886                        phase_mod2 = calculate_1op_fm_0(chip, slot2, 0);
887                        output4 = calculate_1op_fm_0(chip, slot4, phase_mod2);
798                        output3 = calculate_1op_fm_0(slot3, phase_mod1);
799                        phase_mod2 = calculate_1op_fm_0(slot2, 0);
800                        output4 = calculate_1op_fm_0(slot4, phase_mod2);
888801                        break;
889802
890803                     //  --[S4]-----+
r22737r22738
893806                     // <--------|  |
894807                     // +--[S1]--|--+-->
895808                     case 15:
896                        output1 = calculate_1op_fm_1(chip, slot1);
897                        output2 = calculate_1op_fm_0(chip, slot2, 0);
898                        output3 = calculate_1op_fm_0(chip, slot3, 0);
899                        output4 = calculate_1op_fm_0(chip, slot4, 0);
809                        output1 = calculate_1op_fm_1(slot1);
810                        output2 = calculate_1op_fm_0(slot2, 0);
811                        output3 = calculate_1op_fm_0(slot3, 0);
812                        output4 = calculate_1op_fm_0(slot4, 0);
900813                        break;
901814                  }
902815
903                  *mixp++ += ((output1 * channel_attenuation[chip->slots[slot1].ch0_level]) +
904                           (output2 * channel_attenuation[chip->slots[slot2].ch0_level]) +
905                           (output3 * channel_attenuation[chip->slots[slot3].ch0_level]) +
906                           (output4 * channel_attenuation[chip->slots[slot4].ch0_level])) >> 16;
907                  *mixp++ += ((output1 * channel_attenuation[chip->slots[slot1].ch1_level]) +
908                           (output2 * channel_attenuation[chip->slots[slot2].ch1_level]) +
909                           (output3 * channel_attenuation[chip->slots[slot3].ch1_level]) +
910                           (output4 * channel_attenuation[chip->slots[slot4].ch1_level])) >> 16;
816                  *mixp++ += ((output1 * channel_attenuation[m_slots[slot1].ch0_level]) +
817                           (output2 * channel_attenuation[m_slots[slot2].ch0_level]) +
818                           (output3 * channel_attenuation[m_slots[slot3].ch0_level]) +
819                           (output4 * channel_attenuation[m_slots[slot4].ch0_level])) >> 16;
820                  *mixp++ += ((output1 * channel_attenuation[m_slots[slot1].ch1_level]) +
821                           (output2 * channel_attenuation[m_slots[slot2].ch1_level]) +
822                           (output3 * channel_attenuation[m_slots[slot3].ch1_level]) +
823                           (output4 * channel_attenuation[m_slots[slot4].ch1_level])) >> 16;
911824               }
912825            }
913826            break;
r22737r22738
921834               int slot2 = j + ((op + 2) * 12);
922835
923836               mixp = &mix[0];
924               if (chip->slots[slot1].active)
837               if (m_slots[slot1].active)
925838               {
926839                  for (i = 0; i < samples; i++)
927840                  {
928841                     INT64 output1 = 0, output2 = 0, phase_mod = 0;
929                     switch (chip->slots[slot1].algorithm & 3)
842                     switch (m_slots[slot1].algorithm & 3)
930843                     {
931844                        // <--------|
932845                        // +--[S1]--+--[S3]-->
933846                        case 0:
934                           output2 = calculate_2op_fm_0(chip, slot1, slot2);
847                           output2 = calculate_2op_fm_0(slot1, slot2);
935848                           break;
936849
937850                        // <-----------------|
938851                        // +--[S1]--+--[S3]--|-->
939852                        case 1:
940                           output2 = calculate_2op_fm_1(chip, slot1, slot2);
853                           output2 = calculate_2op_fm_1(slot1, slot2);
941854                           break;
942855
943856                        // ---[S3]-----|
944857                        // <--------|  |
945858                        // +--[S1]--|--+-->
946859                        case 2:
947                           output1 = calculate_1op_fm_1(chip, slot1);
948                           output2 = calculate_1op_fm_0(chip, slot2, 0);
860                           output1 = calculate_1op_fm_1(slot1);
861                           output2 = calculate_1op_fm_0(slot2, 0);
949862                           break;
950863                        //
951864                        // <--------| +--[S3]--|
952865                        // +--[S1]--|-|--------+-->
953866                        case 3:
954                           output1 = calculate_1op_fm_1(chip, slot1);
867                           output1 = calculate_1op_fm_1(slot1);
955868                           phase_mod = output1;
956                           output2 = calculate_1op_fm_0(chip, slot2, phase_mod);
869                           output2 = calculate_1op_fm_0(slot2, phase_mod);
957870                           break;
958871                     }
959872
960                     *mixp++ += ((output1 * channel_attenuation[chip->slots[slot1].ch0_level]) +
961                              (output2 * channel_attenuation[chip->slots[slot2].ch0_level])) >> 16;
962                     *mixp++ += ((output1 * channel_attenuation[chip->slots[slot1].ch1_level]) +
963                              (output2 * channel_attenuation[chip->slots[slot2].ch1_level])) >> 16;
873                     *mixp++ += ((output1 * channel_attenuation[m_slots[slot1].ch0_level]) +
874                              (output2 * channel_attenuation[m_slots[slot2].ch0_level])) >> 16;
875                     *mixp++ += ((output1 * channel_attenuation[m_slots[slot1].ch1_level]) +
876                              (output2 * channel_attenuation[m_slots[slot2].ch1_level])) >> 16;
964877                  }
965878               }
966879            }
r22737r22738
974887            int slot3 = j + (2*12);
975888            mixp = &mix[0];
976889
977            if (chip->slots[slot1].active)
890            if (m_slots[slot1].active)
978891            {
979892               for (i = 0; i < samples; i++)
980893               {
981894                  INT64 output1 = 0, output2 = 0, output3 = 0, phase_mod = 0;
982                  switch (chip->slots[slot1].algorithm & 7)
895                  switch (m_slots[slot1].algorithm & 7)
983896                  {
984897                     // <--------|
985898                     // +--[S1]--+--[S3]--+--[S2]-->
986899                     case 0:
987                        phase_mod = calculate_2op_fm_0(chip, slot1, slot3);
988                        output2 = calculate_1op_fm_0(chip, slot2, phase_mod);
900                        phase_mod = calculate_2op_fm_0(slot1, slot3);
901                        output2 = calculate_1op_fm_0(slot2, phase_mod);
989902                        break;
990903
991904                     // <-----------------|
992905                     // +--[S1]--+--[S3]--+--[S2]-->
993906                     case 1:
994                        phase_mod = calculate_2op_fm_1(chip, slot1, slot3);
995                        output2 = calculate_1op_fm_0(chip, slot2, phase_mod);
907                        phase_mod = calculate_2op_fm_1(slot1, slot3);
908                        output2 = calculate_1op_fm_0(slot2, phase_mod);
996909                        break;
997910
998911                     // ---[S3]-----|
999912                     // <--------|  |
1000913                     // +--[S1]--+--+--[S2]-->
1001914                     case 2:
1002                        phase_mod = (calculate_1op_fm_1(chip, slot1) + calculate_1op_fm_0(chip, slot3, 0)) / 2;
1003                        output2 = calculate_1op_fm_0(chip, slot2, phase_mod);
915                        phase_mod = (calculate_1op_fm_1(slot1) + calculate_1op_fm_0(slot3, 0)) / 2;
916                        output2 = calculate_1op_fm_0(slot2, phase_mod);
1004917                        break;
1005918
1006919                     // ---[S3]--+--[S2]--|
1007920                     // <--------|        |
1008921                     // +--[S1]--|--------+-->
1009922                     case 3:
1010                        phase_mod = calculate_1op_fm_0(chip, slot3, 0);
1011                        output2 = calculate_1op_fm_0(chip, slot2, phase_mod);
1012                        output1 = calculate_1op_fm_1(chip, slot1);
923                        phase_mod = calculate_1op_fm_0(slot3, 0);
924                        output2 = calculate_1op_fm_0(slot2, phase_mod);
925                        output1 = calculate_1op_fm_1(slot1);
1013926                        break;
1014927
1015928                     // ------------[S2]--|
1016929                     // <--------|        |
1017930                     // +--[S1]--+--[S3]--+-->
1018931                     case 4:
1019                        output3 = calculate_2op_fm_0(chip, slot1, slot3);
1020                        output2 = calculate_1op_fm_0(chip, slot2, 0);
932                        output3 = calculate_2op_fm_0(slot1, slot3);
933                        output2 = calculate_1op_fm_0(slot2, 0);
1021934                        break;
1022935
1023936                     // ------------[S2]--|
1024937                     // <-----------------|
1025938                     // +--[S1]--+--[S3]--+-->
1026939                     case 5:
1027                        output3 = calculate_2op_fm_1(chip, slot1, slot3);
1028                        output2 = calculate_1op_fm_0(chip, slot2, 0);
940                        output3 = calculate_2op_fm_1(slot1, slot3);
941                        output2 = calculate_1op_fm_0(slot2, 0);
1029942                        break;
1030943
1031944                     // ---[S2]-----|
r22737r22738
1033946                     // <--------|  |
1034947                     // +--[S1]--+--+-->
1035948                     case 6:
1036                        output1 = calculate_1op_fm_1(chip, slot1);
1037                        output3 = calculate_1op_fm_0(chip, slot3, 0);
1038                        output2 = calculate_1op_fm_0(chip, slot2, 0);
949                        output1 = calculate_1op_fm_1(slot1);
950                        output3 = calculate_1op_fm_0(slot3, 0);
951                        output2 = calculate_1op_fm_0(slot2, 0);
1039952                        break;
1040953
1041954                     // --------------[S2]--+
1042955                     // <--------| +--[S3]--|
1043956                     // +--[S1]--+-|--------+-->
1044957                     case 7:
1045                        output1 = calculate_1op_fm_1(chip, slot1);
958                        output1 = calculate_1op_fm_1(slot1);
1046959                        phase_mod = output1;
1047                        output3 = calculate_1op_fm_0(chip, slot3, phase_mod);
1048                        output2 = calculate_1op_fm_0(chip, slot2, 0);
960                        output3 = calculate_1op_fm_0(slot3, phase_mod);
961                        output2 = calculate_1op_fm_0(slot2, 0);
1049962                        break;
1050963                  }
1051964
1052                  *mixp++ += ((output1 * channel_attenuation[chip->slots[slot1].ch0_level]) +
1053                           (output2 * channel_attenuation[chip->slots[slot2].ch0_level]) +
1054                           (output3 * channel_attenuation[chip->slots[slot3].ch0_level])) >> 16;
1055                  *mixp++ += ((output1 * channel_attenuation[chip->slots[slot1].ch1_level]) +
1056                           (output2 * channel_attenuation[chip->slots[slot2].ch1_level]) +
1057                           (output3 * channel_attenuation[chip->slots[slot3].ch1_level])) >> 16;
965                  *mixp++ += ((output1 * channel_attenuation[m_slots[slot1].ch0_level]) +
966                           (output2 * channel_attenuation[m_slots[slot2].ch0_level]) +
967                           (output3 * channel_attenuation[m_slots[slot3].ch0_level])) >> 16;
968                  *mixp++ += ((output1 * channel_attenuation[m_slots[slot1].ch1_level]) +
969                           (output2 * channel_attenuation[m_slots[slot2].ch1_level]) +
970                           (output3 * channel_attenuation[m_slots[slot3].ch1_level])) >> 16;
1058971               }
1059972            }
1060973
1061            update_pcm(chip, j + (3*12), mixp, samples);
974            update_pcm(j + (3*12), mixp, samples);
1062975            break;
1063976         }
1064977
1065978         case 3:     // PCM
1066979         {
1067            update_pcm(chip, j + (0*12), mixp, samples);
1068            update_pcm(chip, j + (1*12), mixp, samples);
1069            update_pcm(chip, j + (2*12), mixp, samples);
1070            update_pcm(chip, j + (3*12), mixp, samples);
980            update_pcm(j + (0*12), mixp, samples);
981            update_pcm(j + (1*12), mixp, samples);
982            update_pcm(j + (2*12), mixp, samples);
983            update_pcm(j + (3*12), mixp, samples);
1071984            break;
1072985         }
1073986
r22737r22738
1083996   }
1084997}
1085998
1086static void write_register(YMF271Chip *chip, int slotnum, int reg, int data)
999void ymf271_device::write_register(int slotnum, int reg, int data)
10871000{
1088   YMF271Slot *slot = &chip->slots[slotnum];
1001   YMF271Slot *slot = &m_slots[slotnum];
10891002
10901003   switch (reg)
10911004   {
r22737r22738
12181131   }
12191132}
12201133
1221static void ymf271_write_fm(YMF271Chip *chip, int grp, int adr, int data)
1134void ymf271_device::ymf271_write_fm(int grp, int adr, int data)
12221135{
12231136   int reg;
12241137   //int slotnum;
r22737r22738
12281141
12291142   //slotnum = 12*grp;
12301143   //slotnum += fm_tab[adr & 0xf];
1231   //slot = &chip->slots[slotnum];
1144   //slot = &m_slots[slotnum];
12321145   slot_group = fm_tab[adr & 0xf];
12331146
12341147   reg = (adr >> 4) & 0xf;
r22737r22738
12521165
12531166   // check if the slot is key on slot for synchronizing
12541167   sync_mode = 0;
1255   switch (chip->groups[slot_group].sync)
1168   switch (m_groups[slot_group].sync)
12561169   {
12571170      case 0:     // 4 slot mode
12581171      {
r22737r22738
12791192
12801193   if (sync_mode && sync_reg)      // key-on slot & synced register
12811194   {
1282      switch (chip->groups[slot_group].sync)
1195      switch (m_groups[slot_group].sync)
12831196      {
12841197         case 0:     // 4 slot mode
12851198         {
1286            write_register(chip, (12 * 0) + slot_group, reg, data);
1287            write_register(chip, (12 * 1) + slot_group, reg, data);
1288            write_register(chip, (12 * 2) + slot_group, reg, data);
1289            write_register(chip, (12 * 3) + slot_group, reg, data);
1199            write_register((12 * 0) + slot_group, reg, data);
1200            write_register((12 * 1) + slot_group, reg, data);
1201            write_register((12 * 2) + slot_group, reg, data);
1202            write_register((12 * 3) + slot_group, reg, data);
12901203            break;
12911204         }
12921205         case 1:     // 2x 2 slot mode
12931206         {
12941207            if (grp == 0)       // Slot 1 - Slot 3
12951208            {
1296               write_register(chip, (12 * 0) + slot_group, reg, data);
1297               write_register(chip, (12 * 2) + slot_group, reg, data);
1209               write_register((12 * 0) + slot_group, reg, data);
1210               write_register((12 * 2) + slot_group, reg, data);
12981211            }
12991212            else                // Slot 2 - Slot 4
13001213            {
1301               write_register(chip, (12 * 1) + slot_group, reg, data);
1302               write_register(chip, (12 * 3) + slot_group, reg, data);
1214               write_register((12 * 1) + slot_group, reg, data);
1215               write_register((12 * 3) + slot_group, reg, data);
13031216            }
13041217            break;
13051218         }
13061219         case 2:     // 3 slot + 1 slot mode
13071220         {
13081221            // 1 slot is handled normally
1309            write_register(chip, (12 * 0) + slot_group, reg, data);
1310            write_register(chip, (12 * 1) + slot_group, reg, data);
1311            write_register(chip, (12 * 2) + slot_group, reg, data);
1222            write_register((12 * 0) + slot_group, reg, data);
1223            write_register((12 * 1) + slot_group, reg, data);
1224            write_register((12 * 2) + slot_group, reg, data);
13121225            break;
13131226         }
13141227         default:
r22737r22738
13171230   }
13181231   else        // write register normally
13191232   {
1320      write_register(chip, (12 * grp) + slot_group, reg, data);
1233      write_register((12 * grp) + slot_group, reg, data);
13211234   }
13221235}
13231236
1324static void ymf271_write_pcm(YMF271Chip *chip, int data)
1237void ymf271_device::ymf271_write_pcm(int data)
13251238{
13261239   int slotnum;
13271240   YMF271Slot *slot;
13281241
1329   slotnum = pcm_tab[chip->pcmreg&0xf];
1330   slot = &chip->slots[slotnum];
1242   slotnum = pcm_tab[m_pcmreg&0xf];
1243   slot = &m_slots[slotnum];
13311244
1332   switch ((chip->pcmreg>>4)&0xf)
1245   switch ((m_pcmreg>>4)&0xf)
13331246   {
13341247      case 0:
13351248         slot->startaddr &= ~0xff;
r22737r22738
13761289   }
13771290}
13781291
1379static TIMER_CALLBACK( ymf271_timer_a_tick )
1292void ymf271_device::device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr)
13801293{
1381   YMF271Chip *chip = (YMF271Chip *)ptr;
1382
1383   chip->status |= 1;
1384
1385   if (chip->enable & 4)
1294   switch(id)
13861295   {
1387      chip->irqstate |= 1;
1388      if (!chip->irq_callback.isnull()) chip->irq_callback(1);
1389   }
1390}
1296   case 0:
1297      m_status |= 1;
13911298
1392static TIMER_CALLBACK( ymf271_timer_b_tick )
1393{
1394   YMF271Chip *chip = (YMF271Chip *)ptr;
1299      if (m_enable & 4)
1300      {
1301         m_irqstate |= 1;
1302         if (!m_irq_handler.isnull()) m_irq_handler(1);
1303      }
1304      break;
13951305
1396   chip->status |= 2;
1306   case 1:
1307      m_status |= 2;
13971308
1398   if (chip->enable & 8)
1399   {
1400      chip->irqstate |= 2;
1401      if (!chip->irq_callback.isnull()) chip->irq_callback(1);
1309      if (m_enable & 8)
1310      {
1311         m_irqstate |= 2;
1312         if (!m_irq_handler.isnull()) m_irq_handler(1);
1313      }
1314      break;
14021315   }
14031316}
14041317
1405static UINT8 ymf271_read_ext_memory(YMF271Chip *chip, UINT32 address)
1318UINT8 ymf271_device::ymf271_read_ext_memory(UINT32 address)
14061319{
1407   if( !chip->ext_mem_read.isnull() )
1320   if( !m_ext_read_handler.isnull() )
14081321   {
1409      return chip->ext_mem_read(address);
1322      return m_ext_read_handler(address);
14101323   }
14111324   else
14121325   {
14131326      if( address < 0x800000)
1414         return chip->rom[address];
1327         return m_rom[address];
14151328   }
14161329   return 0xff;
14171330}
14181331
1419static void ymf271_write_ext_memory(YMF271Chip *chip, UINT32 address, UINT8 data)
1332void ymf271_device::ymf271_write_ext_memory(UINT32 address, UINT8 data)
14201333{
1421   chip->ext_mem_write(address, data);
1334   if( !m_ext_write_handler.isnull() )
1335   {
1336      m_ext_write_handler(address, data);
1337   }
14221338}
14231339
1424static void ymf271_write_timer(YMF271Chip *chip, int data)
1340void ymf271_device::ymf271_write_timer(int data)
14251341{
14261342   int slotnum;
14271343   YMF271Group *group;
14281344   attotime period;
14291345
1430   slotnum = fm_tab[chip->timerreg & 0xf];
1431   group = &chip->groups[slotnum];
1346   slotnum = fm_tab[m_timerreg & 0xf];
1347   group = &m_groups[slotnum];
14321348
1433   if ((chip->timerreg & 0xf0) == 0)
1349   if ((m_timerreg & 0xf0) == 0)
14341350   {
14351351      group->sync = data & 0x3;
14361352      group->pfm = data >> 7;
14371353   }
14381354   else
14391355   {
1440      switch (chip->timerreg)
1356      switch (m_timerreg)
14411357      {
14421358         case 0x10:
1443            chip->timerA &= ~0xff;
1444            chip->timerA |= data;
1359            m_timerA &= ~0xff;
1360            m_timerA |= data;
14451361            break;
14461362
14471363         case 0x11:
14481364            if (!(data & 0xfc))
14491365            {
1450               chip->timerA &= 0x00ff;
1366               m_timerA &= 0x00ff;
14511367               if ((data & 0x3) != 0x3)
14521368               {
1453                  chip->timerA |= (data & 0xff)<<8;
1369                  m_timerA |= (data & 0xff)<<8;
14541370               }
14551371            }
14561372            break;
14571373
14581374         case 0x12:
1459            chip->timerB = data;
1375            m_timerB = data;
14601376            break;
14611377
14621378         case 0x13:
14631379            if (data & 1)
14641380            {   // timer A load
1465               chip->timerAVal = chip->timerA;
1381               m_timerAVal = m_timerA;
14661382            }
14671383            if (data & 2)
14681384            {   // timer B load
1469               chip->timerBVal = chip->timerB;
1385               m_timerBVal = m_timerB;
14701386            }
14711387            if (data & 4)
14721388            {
14731389               // timer A IRQ enable
1474               chip->enable |= 4;
1390               m_enable |= 4;
14751391            }
14761392            if (data & 8)
14771393            {
14781394               // timer B IRQ enable
1479               chip->enable |= 8;
1395               m_enable |= 8;
14801396            }
14811397            if (data & 0x10)
14821398            {   // timer A reset
1483               chip->irqstate &= ~1;
1484               chip->status &= ~1;
1485               chip->timerAVal |= 0x300;
1399               m_irqstate &= ~1;
1400               m_status &= ~1;
1401               m_timerAVal |= 0x300;
14861402
1487               if (!chip->irq_callback.isnull()) chip->irq_callback(0);
1403               if (!m_irq_handler.isnull()) m_irq_handler(0);
14881404
1489               period = attotime::from_hz(chip->clock) * (384 * 4 * (1024 - chip->timerAVal));
1405               period = attotime::from_hz(m_clock) * (384 * 4 * (1024 - m_timerAVal));
14901406
1491               chip->timA->adjust(period, 0, period);
1407               m_timA->adjust(period, 0, period);
14921408            }
14931409            if (data & 0x20)
14941410            {   // timer B reset
1495               chip->irqstate &= ~2;
1496               chip->status &= ~2;
1411               m_irqstate &= ~2;
1412               m_status &= ~2;
14971413
1498               if (!chip->irq_callback.isnull()) chip->irq_callback(0);
1414               if (!m_irq_handler.isnull()) m_irq_handler(0);
14991415
1500               period = attotime::from_hz(chip->clock) * (384 * 16 * (256 - chip->timerBVal));
1416               period = attotime::from_hz(m_clock) * (384 * 16 * (256 - m_timerBVal));
15011417
1502               chip->timB->adjust(period, 0, period);
1418               m_timB->adjust(period, 0, period);
15031419            }
15041420
15051421            break;
15061422
15071423         case 0x14:
1508            chip->ext_address &= ~0xff;
1509            chip->ext_address |= data;
1424            m_ext_address &= ~0xff;
1425            m_ext_address |= data;
15101426            break;
15111427         case 0x15:
1512            chip->ext_address &= ~0xff00;
1513            chip->ext_address |= data << 8;
1428            m_ext_address &= ~0xff00;
1429            m_ext_address |= data << 8;
15141430            break;
15151431         case 0x16:
1516            chip->ext_address &= ~0xff0000;
1517            chip->ext_address |= (data & 0x7f) << 16;
1518            chip->ext_read = (data & 0x80) ? 1 : 0;
1519            if( !chip->ext_read )
1520               chip->ext_address = (chip->ext_address + 1) & 0x7fffff;
1432            m_ext_address &= ~0xff0000;
1433            m_ext_address |= (data & 0x7f) << 16;
1434            m_ext_read = (data & 0x80) ? 1 : 0;
1435            if( !m_ext_read )
1436               m_ext_address = (m_ext_address + 1) & 0x7fffff;
15211437            break;
15221438         case 0x17:
1523            ymf271_write_ext_memory( chip, chip->ext_address, data );
1524            chip->ext_address = (chip->ext_address + 1) & 0x7fffff;
1439            ymf271_write_ext_memory( m_ext_address, data );
1440            m_ext_address = (m_ext_address + 1) & 0x7fffff;
15251441            break;
15261442      }
15271443   }
15281444}
15291445
1530WRITE8_DEVICE_HANDLER( ymf271_w )
1446WRITE8_MEMBER( ymf271_device::write )
15311447{
1532   YMF271Chip *chip = get_safe_token(device);
1533
15341448   switch (offset)
15351449   {
15361450      case 0:
1537         chip->reg0 = data;
1451         m_reg0 = data;
15381452         break;
15391453      case 1:
1540         ymf271_write_fm(chip, 0, chip->reg0, data);
1454         ymf271_write_fm(0, m_reg0, data);
15411455         break;
15421456      case 2:
1543         chip->reg1 = data;
1457         m_reg1 = data;
15441458         break;
15451459      case 3:
1546         ymf271_write_fm(chip, 1, chip->reg1, data);
1460         ymf271_write_fm(1, m_reg1, data);
15471461         break;
15481462      case 4:
1549         chip->reg2 = data;
1463         m_reg2 = data;
15501464         break;
15511465      case 5:
1552         ymf271_write_fm(chip, 2, chip->reg2, data);
1466         ymf271_write_fm(2, m_reg2, data);
15531467         break;
15541468      case 6:
1555         chip->reg3 = data;
1469         m_reg3 = data;
15561470         break;
15571471      case 7:
1558         ymf271_write_fm(chip, 3, chip->reg3, data);
1472         ymf271_write_fm(3, m_reg3, data);
15591473         break;
15601474      case 8:
1561         chip->pcmreg = data;
1475         m_pcmreg = data;
15621476         break;
15631477      case 9:
1564         ymf271_write_pcm(chip, data);
1478         ymf271_write_pcm(data);
15651479         break;
15661480      case 0xc:
1567         chip->timerreg = data;
1481         m_timerreg = data;
15681482         break;
15691483      case 0xd:
1570         ymf271_write_timer(chip, data);
1484         ymf271_write_timer(data);
15711485         break;
15721486   }
15731487}
15741488
1575READ8_DEVICE_HANDLER( ymf271_r )
1489READ8_MEMBER( ymf271_device::read )
15761490{
15771491   UINT8 value;
1578   YMF271Chip *chip = get_safe_token(device);
15791492
15801493   switch(offset)
15811494   {
15821495      case 0:
1583         return chip->status;
1496         return m_status;
15841497
15851498      case 2:
1586         value = ymf271_read_ext_memory( chip, chip->ext_address );
1587         chip->ext_address = (chip->ext_address + 1) & 0x7fffff;
1499         value = ymf271_read_ext_memory( m_ext_address );
1500         m_ext_address = (m_ext_address + 1) & 0x7fffff;
15881501         return value;
15891502   }
15901503
r22737r22738
16771590   }
16781591}
16791592
1680static void init_state(YMF271Chip *chip, device_t *device)
1593void ymf271_device::init_state()
16811594{
16821595   int i;
16831596
1684   for (i = 0; i < ARRAY_LENGTH(chip->slots); i++)
1597   for (i = 0; i < ARRAY_LENGTH(m_slots); i++)
16851598   {
1686      device->save_item(NAME(chip->slots[i].extout), i);
1687      device->save_item(NAME(chip->slots[i].lfoFreq), i);
1688      device->save_item(NAME(chip->slots[i].pms), i);
1689      device->save_item(NAME(chip->slots[i].ams), i);
1690      device->save_item(NAME(chip->slots[i].detune), i);
1691      device->save_item(NAME(chip->slots[i].multiple), i);
1692      device->save_item(NAME(chip->slots[i].tl), i);
1693      device->save_item(NAME(chip->slots[i].keyscale), i);
1694      device->save_item(NAME(chip->slots[i].ar), i);
1695      device->save_item(NAME(chip->slots[i].decay1rate), i);
1696      device->save_item(NAME(chip->slots[i].decay2rate), i);
1697      device->save_item(NAME(chip->slots[i].decay1lvl), i);
1698      device->save_item(NAME(chip->slots[i].relrate), i);
1699      device->save_item(NAME(chip->slots[i].fns), i);
1700      device->save_item(NAME(chip->slots[i].block), i);
1701      device->save_item(NAME(chip->slots[i].feedback), i);
1702      device->save_item(NAME(chip->slots[i].waveform), i);
1703      device->save_item(NAME(chip->slots[i].accon), i);
1704      device->save_item(NAME(chip->slots[i].algorithm), i);
1705      device->save_item(NAME(chip->slots[i].ch0_level), i);
1706      device->save_item(NAME(chip->slots[i].ch1_level), i);
1707      device->save_item(NAME(chip->slots[i].ch2_level), i);
1708      device->save_item(NAME(chip->slots[i].ch3_level), i);
1709      device->save_item(NAME(chip->slots[i].startaddr), i);
1710      device->save_item(NAME(chip->slots[i].loopaddr), i);
1711      device->save_item(NAME(chip->slots[i].endaddr), i);
1712      device->save_item(NAME(chip->slots[i].fs), i);
1713      device->save_item(NAME(chip->slots[i].srcnote), i);
1714      device->save_item(NAME(chip->slots[i].srcb), i);
1715      device->save_item(NAME(chip->slots[i].step), i);
1716      device->save_item(NAME(chip->slots[i].stepptr), i);
1717      device->save_item(NAME(chip->slots[i].active), i);
1718      device->save_item(NAME(chip->slots[i].bits), i);
1719      device->save_item(NAME(chip->slots[i].volume), i);
1720      device->save_item(NAME(chip->slots[i].env_state), i);
1721      device->save_item(NAME(chip->slots[i].env_attack_step), i);
1722      device->save_item(NAME(chip->slots[i].env_decay1_step), i);
1723      device->save_item(NAME(chip->slots[i].env_decay2_step), i);
1724      device->save_item(NAME(chip->slots[i].env_release_step), i);
1725      device->save_item(NAME(chip->slots[i].feedback_modulation0), i);
1726      device->save_item(NAME(chip->slots[i].feedback_modulation1), i);
1727      device->save_item(NAME(chip->slots[i].lfo_phase), i);
1728      device->save_item(NAME(chip->slots[i].lfo_step), i);
1729      device->save_item(NAME(chip->slots[i].lfo_amplitude), i);
1599      save_item(NAME(m_slots[i].extout), i);
1600      save_item(NAME(m_slots[i].lfoFreq), i);
1601      save_item(NAME(m_slots[i].pms), i);
1602      save_item(NAME(m_slots[i].ams), i);
1603      save_item(NAME(m_slots[i].detune), i);
1604      save_item(NAME(m_slots[i].multiple), i);
1605      save_item(NAME(m_slots[i].tl), i);
1606      save_item(NAME(m_slots[i].keyscale), i);
1607      save_item(NAME(m_slots[i].ar), i);
1608      save_item(NAME(m_slots[i].decay1rate), i);
1609      save_item(NAME(m_slots[i].decay2rate), i);
1610      save_item(NAME(m_slots[i].decay1lvl), i);
1611      save_item(NAME(m_slots[i].relrate), i);
1612      save_item(NAME(m_slots[i].fns), i);
1613      save_item(NAME(m_slots[i].block), i);
1614      save_item(NAME(m_slots[i].feedback), i);
1615      save_item(NAME(m_slots[i].waveform), i);
1616      save_item(NAME(m_slots[i].accon), i);
1617      save_item(NAME(m_slots[i].algorithm), i);
1618      save_item(NAME(m_slots[i].ch0_level), i);
1619      save_item(NAME(m_slots[i].ch1_level), i);
1620      save_item(NAME(m_slots[i].ch2_level), i);
1621      save_item(NAME(m_slots[i].ch3_level), i);
1622      save_item(NAME(m_slots[i].startaddr), i);
1623      save_item(NAME(m_slots[i].loopaddr), i);
1624      save_item(NAME(m_slots[i].endaddr), i);
1625      save_item(NAME(m_slots[i].fs), i);
1626      save_item(NAME(m_slots[i].srcnote), i);
1627      save_item(NAME(m_slots[i].srcb), i);
1628      save_item(NAME(m_slots[i].step), i);
1629      save_item(NAME(m_slots[i].stepptr), i);
1630      save_item(NAME(m_slots[i].active), i);
1631      save_item(NAME(m_slots[i].bits), i);
1632      save_item(NAME(m_slots[i].volume), i);
1633      save_item(NAME(m_slots[i].env_state), i);
1634      save_item(NAME(m_slots[i].env_attack_step), i);
1635      save_item(NAME(m_slots[i].env_decay1_step), i);
1636      save_item(NAME(m_slots[i].env_decay2_step), i);
1637      save_item(NAME(m_slots[i].env_release_step), i);
1638      save_item(NAME(m_slots[i].feedback_modulation0), i);
1639      save_item(NAME(m_slots[i].feedback_modulation1), i);
1640      save_item(NAME(m_slots[i].lfo_phase), i);
1641      save_item(NAME(m_slots[i].lfo_step), i);
1642      save_item(NAME(m_slots[i].lfo_amplitude), i);
17301643   }
17311644
1732   for (i = 0; i < sizeof(chip->groups) / sizeof(chip->groups[0]); i++)
1645   for (i = 0; i < sizeof(m_groups) / sizeof(m_groups[0]); i++)
17331646   {
1734      device->save_item(NAME(chip->groups[i].sync), i);
1735      device->save_item(NAME(chip->groups[i].pfm), i);
1647      save_item(NAME(m_groups[i].sync), i);
1648      save_item(NAME(m_groups[i].pfm), i);
17361649   }
17371650
1738   device->save_item(NAME(chip->timerA));
1739   device->save_item(NAME(chip->timerB));
1740   device->save_item(NAME(chip->timerAVal));
1741   device->save_item(NAME(chip->timerBVal));
1742   device->save_item(NAME(chip->irqstate));
1743   device->save_item(NAME(chip->status));
1744   device->save_item(NAME(chip->enable));
1745   device->save_item(NAME(chip->reg0));
1746   device->save_item(NAME(chip->reg1));
1747   device->save_item(NAME(chip->reg2));
1748   device->save_item(NAME(chip->reg3));
1749   device->save_item(NAME(chip->pcmreg));
1750   device->save_item(NAME(chip->timerreg));
1751   device->save_item(NAME(chip->ext_address));
1752   device->save_item(NAME(chip->ext_read));
1651   save_item(NAME(m_timerA));
1652   save_item(NAME(m_timerB));
1653   save_item(NAME(m_timerAVal));
1654   save_item(NAME(m_timerBVal));
1655   save_item(NAME(m_irqstate));
1656   save_item(NAME(m_status));
1657   save_item(NAME(m_enable));
1658   save_item(NAME(m_reg0));
1659   save_item(NAME(m_reg1));
1660   save_item(NAME(m_reg2));
1661   save_item(NAME(m_reg3));
1662   save_item(NAME(m_pcmreg));
1663   save_item(NAME(m_timerreg));
1664   save_item(NAME(m_ext_address));
1665   save_item(NAME(m_ext_read));
17531666}
17541667
1755static void ymf271_init(device_t *device, YMF271Chip *chip, UINT8 *rom, const devcb_write_line *cb, const devcb_read8 *ext_read, const devcb_write8 *ext_write)
1668//-------------------------------------------------
1669//  device_start - device-specific startup
1670//-------------------------------------------------
1671
1672void ymf271_device::device_start()
17561673{
1757   chip->timA = device->machine().scheduler().timer_alloc(FUNC(ymf271_timer_a_tick), chip);
1758   chip->timB = device->machine().scheduler().timer_alloc(FUNC(ymf271_timer_b_tick), chip);
1674   int i;
17591675
1760   chip->rom = rom;
1761   chip->irq_callback.resolve(*cb, *device);
1676   m_clock = clock();
17621677
1763   chip->ext_mem_read.resolve(*ext_read, *device);
1764   chip->ext_mem_write.resolve(*ext_write, *device);
1678   m_timA = timer_alloc(0);
1679   m_timB = timer_alloc(1);
17651680
1766   init_tables(device->machine());
1767   init_state(chip, device);
1768}
1681   m_rom = *region();
1682   m_irq_handler.resolve();
17691683
1770static DEVICE_START( ymf271 )
1771{
1772   static const ymf271_interface defintrf = { DEVCB_NULL };
1773   const ymf271_interface *intf;
1774   int i;
1775   YMF271Chip *chip = get_safe_token(device);
1684   m_ext_read_handler.resolve();
1685   m_ext_write_handler.resolve();
17761686
1777   chip->device = device;
1778   chip->clock = device->clock();
1687   init_tables(machine());
1688   init_state();
17791689
1780   intf = (device->static_config() != NULL) ? (const ymf271_interface *)device->static_config() : &defintrf;
1690   m_stream = machine().sound().stream_alloc(*this, 0, 2, clock()/384);
17811691
1782   ymf271_init(device, chip, *device->region(), &intf->irq_callback, &intf->ext_read, &intf->ext_write);
1783   chip->stream = device->machine().sound().stream_alloc(*device, 0, 2, device->clock()/384, chip, ymf271_update);
1784
17851692   for (i = 0; i < 256; i++)
17861693   {
17871694      env_volume_table[i] = (int)(65536.0 / pow(10.0, ((double)i / (256.0 / 96.0)) / 20.0));
r22737r22738
17981705   }
17991706}
18001707
1801static DEVICE_RESET( ymf271 )
1708//-------------------------------------------------
1709//  device_reset - device-specific reset
1710//-------------------------------------------------
1711
1712void ymf271_device::device_reset()
18021713{
18031714   int i;
1804   YMF271Chip *chip = get_safe_token(device);
18051715
18061716   for (i = 0; i < 48; i++)
18071717   {
1808      chip->slots[i].active = 0;
1809      chip->slots[i].volume = 0;
1718      m_slots[i].active = 0;
1719      m_slots[i].volume = 0;
18101720   }
18111721}
18121722
r22737r22738
18141724
18151725ymf271_device::ymf271_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
18161726   : device_t(mconfig, YMF271, "YMF271", tag, owner, clock),
1817      device_sound_interface(mconfig, *this)
1727      device_sound_interface(mconfig, *this),
1728      m_irq_handler(*this),
1729      m_ext_read_handler(*this),
1730      m_ext_write_handler(*this)
18181731{
1819   m_token = global_alloc_clear(YMF271Chip);
18201732}
18211733
18221734//-------------------------------------------------
r22737r22738
18281740void ymf271_device::device_config_complete()
18291741{
18301742}
1831
1832//-------------------------------------------------
1833//  device_start - device-specific startup
1834//-------------------------------------------------
1835
1836void ymf271_device::device_start()
1837{
1838   DEVICE_START_NAME( ymf271 )(this);
1839}
1840
1841//-------------------------------------------------
1842//  device_reset - device-specific reset
1843//-------------------------------------------------
1844
1845void ymf271_device::device_reset()
1846{
1847   DEVICE_RESET_NAME( ymf271 )(this);
1848}
1849
1850//-------------------------------------------------
1851//  sound_stream_update - handle a stream update
1852//-------------------------------------------------
1853
1854void ymf271_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples)
1855{
1856   // should never get here
1857   fatalerror("sound_stream_update called; not applicable to legacy sound devices\n");
1858}
trunk/src/emu/sound/ymf271.h
r22737r22738
33#ifndef __YMF271_H__
44#define __YMF271_H__
55
6#include "devlegcy.h"
6#include "emu.h"
77
8#define MCFG_YMF271_IRQ_HANDLER(_devcb) \
9   devcb = &ymf271_device::set_irq_handler(*device, DEVCB2_##_devcb);
810
9struct ymf271_interface
10{
11   devcb_read8 ext_read;       /* external memory read */
12   devcb_write8 ext_write; /* external memory write */
13   devcb_write_line irq_callback;  /* irq callback */
14};
11#define MCFG_YMF271_EXT_READ_HANDLER(_devcb) \
12   devcb = &ymf271_device::set_ext_read_handler(*device, DEVCB2_##_devcb);
1513
16DECLARE_READ8_DEVICE_HANDLER( ymf271_r );
17DECLARE_WRITE8_DEVICE_HANDLER( ymf271_w );
14#define MCFG_YMF271_EXT_WRITE_HANDLER(_devcb) \
15   devcb = &ymf271_device::set_ext_write_handler(*device, DEVCB2_##_devcb);
1816
1917class ymf271_device : public device_t,
2018                           public device_sound_interface
2119{
2220public:
2321   ymf271_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
24   ~ymf271_device() { global_free(m_token); }
2522
26   // access to legacy token
27   void *token() const { assert(m_token != NULL); return m_token; }
23   // static configuration helpers
24   template<class _Object> static devcb2_base &set_irq_handler(device_t &device, _Object object) { return downcast<ymf271_device &>(device).m_irq_handler.set_callback(object); }
25   template<class _Object> static devcb2_base &set_ext_read_handler(device_t &device, _Object object) { return downcast<ymf271_device &>(device).m_ext_read_handler.set_callback(object); }
26   template<class _Object> static devcb2_base &set_ext_write_handler(device_t &device, _Object object) { return downcast<ymf271_device &>(device).m_ext_write_handler.set_callback(object); }
27
28   DECLARE_READ8_MEMBER( read );
29   DECLARE_WRITE8_MEMBER( write );
30
2831protected:
2932   // device-level overrides
3033   virtual void device_config_complete();
3134   virtual void device_start();
3235   virtual void device_reset();
36   virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr);
3337
3438   // sound stream update overrides
3539   virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples);
3640private:
41   struct YMF271Slot
42   {
43      INT8  extout;
44      UINT8 lfoFreq;
45      INT8  lfowave;
46      INT8  pms, ams;
47      INT8  detune;
48      INT8  multiple;
49      INT8  tl;
50      INT8  keyscale;
51      INT8  ar;
52      INT8  decay1rate, decay2rate;
53      INT8  decay1lvl;
54      INT8  relrate;
55      INT32 fns;
56      INT8  block;
57      INT8  feedback;
58      INT8  waveform;
59      INT8  accon;
60      INT8  algorithm;
61      INT8  ch0_level, ch1_level, ch2_level, ch3_level;
62
63      UINT32 startaddr;
64      UINT32 loopaddr;
65      UINT32 endaddr;
66      INT8   fs, srcnote, srcb;
67
68      INT64 step;
69      INT64 stepptr;
70
71      INT8 active;
72      INT8 bits;
73
74      // envelope generator
75      INT32 volume;
76      INT32 env_state;
77      INT32 env_attack_step;      // volume increase step in attack state
78      INT32 env_decay1_step;
79      INT32 env_decay2_step;
80      INT32 env_release_step;
81
82      INT64 feedback_modulation0;
83      INT64 feedback_modulation1;
84
85      INT32 lfo_phase, lfo_step;
86      INT32 lfo_amplitude;
87      double lfo_phasemod;
88   };
89
90   struct YMF271Group
91   {
92      INT8 sync, pfm;
93   };
94
95   void init_state();
96   void calculate_step(YMF271Slot *slot);
97   void update_envelope(YMF271Slot *slot);
98   void init_envelope(YMF271Slot *slot);
99   void init_lfo(YMF271Slot *slot);
100   void update_lfo(YMF271Slot *slot);
101   int calculate_slot_volume(YMF271Slot *slot);
102   void update_pcm(int slotnum, INT32 *mixp, int length);
103   INT32 calculate_2op_fm_0(int slotnum1, int slotnum2);
104   INT32 calculate_2op_fm_1(int slotnum1, int slotnum2);
105   INT32 calculate_1op_fm_0(int slotnum, int phase_modulation);
106   INT32 calculate_1op_fm_1(int slotnum);
107   void write_register(int slotnum, int reg, int data);
108   void ymf271_write_fm(int grp, int adr, int data);
109   void ymf271_write_pcm(int data);
110   UINT8 ymf271_read_ext_memory(UINT32 address);
111   void ymf271_write_ext_memory(UINT32 address, UINT8 data);
112   void ymf271_write_timer(int data);
113
37114   // internal state
38   void *m_token;
115   YMF271Slot m_slots[48];
116   YMF271Group m_groups[12];
117
118   INT32 m_timerA, m_timerB;
119   INT32 m_timerAVal, m_timerBVal;
120   INT32 m_irqstate;
121   INT8  m_status;
122   INT8  m_enable;
123
124   emu_timer *m_timA, *m_timB;
125
126   INT8  m_reg0, m_reg1, m_reg2, m_reg3, m_pcmreg, m_timerreg;
127   UINT32 m_ext_address;
128   UINT8 m_ext_read;
129
130   const UINT8 *m_rom;
131   devcb2_write_line m_irq_handler;
132   devcb2_read8 m_ext_read_handler;
133   devcb2_write8 m_ext_write_handler;
134
135   UINT32 m_clock;
136   sound_stream * m_stream;
39137};
40138
41139extern const device_type YMF271;

Previous 199869 Revisions Next


© 1997-2024 The MAME Team