Previous 199869 Revisions Next

r17773 Monday 10th September, 2012 at 06:34:19 UTC by Miodrag Milanović
(MESS) isa_blaster: improves the adpcm and simplifies the dsp protection, based on the ATI Stereo FX rom. [Carl]
(MESS) pc_joy: made pc joystick a device for the many isa audio adapters with joy ports to share. [Carl]
[src/mess/machine]isa_sblaster.c isa_sblaster.h pc_joy.c pc_joy.h

trunk/src/mess/machine/pc_joy.c
r17772r17773
8989   PORT_BIT(0xff,0x80,IPT_AD_STICK_Y) PORT_SENSITIVITY(100) PORT_KEYDELTA(1) PORT_MINMAX(1,0xff) PORT_CODE_DEC(JOYCODE_Y_UP_SWITCH) PORT_CODE_INC(JOYCODE_Y_DOWN_SWITCH) PORT_PLAYER(2)
9090INPUT_PORTS_END
9191
92const device_type PC_JOY = &device_creator<pc_joy_device>;
93
94pc_joy_device::pc_joy_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
95   : device_t(mconfig, PC_JOY, "PC joystick", tag, owner, clock)
96{
97}
98
99ioport_constructor pc_joy_device::device_input_ports() const
100{
101   return INPUT_PORTS_NAME( pc_joystick );
102}
trunk/src/mess/machine/pc_joy.h
r17772r17773
99#ifndef PC_JOY_H
1010#define PC_JOY_H
1111
12#include "emu.h"
1213
1314READ8_HANDLER ( pc_JOY_r );
1415WRITE8_HANDLER ( pc_JOY_w );
r17772r17773
1617INPUT_PORTS_EXTERN( pc_joystick_none );
1718INPUT_PORTS_EXTERN( pc_joystick );
1819
20#define MCFG_PC_JOY_ADD(_tag) \
21   MCFG_DEVICE_ADD(_tag, PC_JOY, 0)
1922
23class pc_joy_device : public device_t
24{
25public:
26   pc_joy_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
27   virtual ioport_constructor device_input_ports() const;
28
29   DECLARE_READ8_MEMBER(joy_port_r) { return pc_JOY_r(&space, offset); }
30   DECLARE_WRITE8_MEMBER(joy_port_w) { pc_JOY_w(&space, offset, data); }
31protected:
32   virtual void device_start() {}
33};
34
35extern const device_type PC_JOY;
2036#endif /* PC_JOY_H */
trunk/src/mess/machine/isa_sblaster.c
r17772r17773
3838#define ym3812_StdClock XTAL_3_579545MHz
3939#define ymf262_StdClock XTAL_14_31818MHz
4040
41static INPUT_PORTS_START( sblaster )
42   PORT_START("pc_joy")
43   PORT_BIT( 0x0f, IP_ACTIVE_LOW,    IPT_UNUSED ) // x/y ad stick to digital converters
44   PORT_BIT( 0x10, IP_ACTIVE_LOW,   IPT_BUTTON1) PORT_NAME("SB: Joystick Button 1")
45   PORT_BIT( 0x20, IP_ACTIVE_LOW,   IPT_BUTTON2) PORT_NAME("SB: Joystick Button 2")
46   PORT_BIT( 0x40, IP_ACTIVE_LOW,   IPT_BUTTON3) PORT_NAME("SB: Joystick Button 3")
47   PORT_BIT( 0x80, IP_ACTIVE_LOW,   IPT_BUTTON4) PORT_NAME("SB: Joystick Button 4")
48
49   PORT_START("pc_joy_1")
50   PORT_BIT(0xff,0x80,IPT_AD_STICK_X) PORT_SENSITIVITY(100) PORT_KEYDELTA(1) PORT_MINMAX(1,0xff) PORT_CODE_DEC(KEYCODE_LEFT) PORT_CODE_INC(KEYCODE_RIGHT) PORT_CODE_DEC(JOYCODE_X_LEFT_SWITCH) PORT_CODE_INC(JOYCODE_X_RIGHT_SWITCH)
51
52   PORT_START("pc_joy_2")
53   PORT_BIT(0xff,0x80,IPT_AD_STICK_Y) PORT_SENSITIVITY(100) PORT_KEYDELTA(1) PORT_MINMAX(1,0xff) PORT_CODE_DEC(KEYCODE_UP) PORT_CODE_INC(KEYCODE_DOWN) PORT_CODE_DEC(JOYCODE_Y_UP_SWITCH) PORT_CODE_INC(JOYCODE_Y_DOWN_SWITCH)
54INPUT_PORTS_END
55
56ioport_constructor sb_device::device_input_ports() const
57{
58   return INPUT_PORTS_NAME( sblaster );
59}
60
6141static const int m_cmd_fifo_length[256] =
6242{
6343/*   0   1   2   3   4   5   6   7   8   9   A   B   C   D   E   F        */
r17772r17773
7959   -1, -1,  1, -1, -1, -1, -1, -1,  1, -1, -1,   -1,  1, -1, -1, -1  /* Fx */
8060};
8161
82static const int protection_magic[4][9] =
83{
84    {  1, -2, -4,  8, -16,  32,  64, -128, -106 },
85    { -1,  2, -4,  8,  16, -32,  64, -128,  165 },
86    { -1,  2,  4, -8,  16, -32, -64,  128, -151 },
87    {  1, -2,  4, -8, -16,  32, -64,  128,  90 }
88};
62static const int protection_magic[4] = { 0x96, 0xa5, 0x69, 0x5a };
8963
9064static const ym3812_interface pc_ym3812_interface =
9165{
r17772r17773
11488    MCFG_SOUND_ROUTE(ALL_OUTPUTS, "lspeaker", 1.00)
11589   MCFG_SOUND_ADD("sbdacr", DAC, 0)
11690    MCFG_SOUND_ROUTE(ALL_OUTPUTS, "rspeaker", 1.00)
91
92   MCFG_PC_JOY_ADD("joy")
11793MACHINE_CONFIG_END
11894
11995static MACHINE_CONFIG_FRAGMENT( sblaster1_5_config )
r17772r17773
128104    MCFG_SOUND_ROUTE(ALL_OUTPUTS, "lspeaker", 1.00)
129105   MCFG_SOUND_ADD("sbdacr", DAC, 0)
130106    MCFG_SOUND_ROUTE(ALL_OUTPUTS, "rspeaker", 1.00)
107
108   MCFG_PC_JOY_ADD("joy")
131109MACHINE_CONFIG_END
132110
133111static MACHINE_CONFIG_FRAGMENT( sblaster_16_config )
r17772r17773
142120    MCFG_SOUND_ROUTE(ALL_OUTPUTS, "lspeaker", 1.00)
143121   MCFG_SOUND_ADD("sbdacr", DAC, 0)
144122    MCFG_SOUND_ROUTE(ALL_OUTPUTS, "rspeaker", 1.00)
123
124   MCFG_PC_JOY_ADD("joy")
145125MACHINE_CONFIG_END
146126
147127static READ8_DEVICE_HANDLER( ym3812_16_r )
r17772r17773
354334            m_dsp.adpcm_new_ref = true;
355335            m_dsp.adpcm_step = 0;
356336         case 0x16:  // 2-bit ADPCM
337            m_dsp.adpcm_count = 0;
357338            m_dsp.dma_length = (m_dsp.fifo[1] + (m_dsp.fifo[2]<<8)) + 1;
358339            m_dsp.dma_transferred = 0;
359340            m_dsp.dma_autoinit = 0;
r17772r17773
395376            m_dsp.adpcm_new_ref = true;
396377            m_dsp.adpcm_step = 0;
397378         case 0x74:  // 4-bit ADPCM
379            m_dsp.adpcm_count = 0;
398380            m_dsp.dma_length = (m_dsp.fifo[1] + (m_dsp.fifo[2]<<8)) + 1;
399381            m_dsp.dma_transferred = 0;
400382            m_dsp.dma_autoinit = 0;
r17772r17773
408390            m_dsp.adpcm_new_ref = true;
409391            m_dsp.adpcm_step = 0;
410392         case 0x76:  // 2.6-bit ADPCM
393            m_dsp.adpcm_count = 0;
411394            m_dsp.dma_length = (m_dsp.fifo[1] + (m_dsp.fifo[2]<<8)) + 1;
412395            m_dsp.dma_transferred = 0;
413396            m_dsp.dma_autoinit = 0;
r17772r17773
448431            break;
449432
450433            case 0xe2: // DSP protection
451                for (int i = 0; i < 8; i++)
452                {
453                    if ((m_dsp.fifo[1] >> i) & 0x01)
454                    {
455                        m_dsp.prot_value += protection_magic[m_dsp.prot_count % 4][i];
456                    }
457                }
458
459                m_dsp.prot_value += protection_magic[m_dsp.prot_count % 4][8];
460                m_dsp.prot_count++;
461
434                m_dsp.prot_value += protection_magic[m_dsp.prot_count++] ^ m_dsp.fifo[1];
435                m_dsp.prot_count &= 3;
436            m_dsp.adc_transferred = 0;
437            m_dsp.adc_length = 1;
462438                m_dack_out = (UINT8)(m_dsp.prot_value & 0xff);
463439                drq_w(1);
464440                break;
r17772r17773
487463                  case 0x1f:  // 2-bit autoinit ADPCM w/new reference
488464                     m_dsp.adpcm_new_ref = true;
489465                     m_dsp.adpcm_step = 0;
466                     m_dsp.adpcm_count = 0;
490467                     m_dsp.dma_length = (m_dsp.fifo[1] + (m_dsp.fifo[2]<<8)) + 1;
491468                     m_dsp.dma_transferred = 0;
492469                     m_dsp.dma_autoinit = 1;
r17772r17773
498475                  case 0x7d:  // 4-bit autoinit ADPCM w/new reference
499476                     m_dsp.adpcm_new_ref = true;
500477                     m_dsp.adpcm_step = 0;
478                     m_dsp.adpcm_count = 0;
501479                     m_dsp.dma_length = (m_dsp.fifo[1] + (m_dsp.fifo[2]<<8)) + 1;
502480                     m_dsp.dma_transferred = 0;
503481                     m_dsp.dma_autoinit = 1;
r17772r17773
509487                  case 0x7f:  // 2.6-bit autoinit ADPCM w/new reference
510488                     m_dsp.adpcm_new_ref = true;
511489                     m_dsp.adpcm_step = 0;
490                     m_dsp.adpcm_count = 0;
512491                     m_dsp.dma_length = (m_dsp.fifo[1] + (m_dsp.fifo[2]<<8)) + 1;
513492                     m_dsp.dma_transferred = 0;
514493                     m_dsp.dma_autoinit = 1;
r17772r17773
640619
641620void sb_device::adpcm_decode(UINT8 sample, int size)
642621{
643   int sign = (sample & (1 << (size - 1))) ? -1: 1;
644   int shift = (size == 2) ? 2 : 0;
645   INT16 dec_sample = m_dsp.adpcm_ref + sign * (sample << (m_dsp.adpcm_step + shift));
622   const UINT8 adpcm_2_table[] =  {0, 1, 1, 3, 2, 6, 4, 12, 8, 24, 16, 48};
623   const UINT8 step_2_table[] =   {0, 2, 0, 4, 2, 6, 4,  8, 6, 10,  8, 10};
646624
625   const UINT8 adpcm_3_table[] =  {0,  1,  2,  3,  1,  3,  5,  7,
626                           2,  6, 10, 14,  4, 12, 20, 28,
627                           8, 24, 40, 56};
628   const UINT8 step_3_table[] =   {0,  0,  0,  4,  0,  4,  4,  8,
629                           4,  8,  8, 12,  8, 12, 12, 16,
630                           12, 16, 16, 16};
631
632   const UINT8 adpcm_4_table[] =  {0,  1,  2,  3,  4,  5,  6,  7,
633                           1,  3,  5,  7,  9, 11, 13, 15,
634                           2,  6, 10, 14, 18, 22, 26, 30,
635                           4, 12, 20, 28, 36, 44, 52, 60};
636   const UINT8 step_4_table[]  =  {0,  0,  0,  0,  0,  8,  8,  8,
637                           0,  8,  8,  8,  8, 16, 16, 16,
638                           8, 16, 16, 16, 16, 24, 24, 24,
639                           16, 24, 24, 24, 24, 24, 24, 24};
640
641   INT16 dec_sample = m_dsp.adpcm_ref;
642   UINT8 index;
643   switch(size)
644   {
645      case 2:
646         index = (sample & 1) | m_dsp.adpcm_step;
647         dec_sample += ((sample & 2)?-1:1) * adpcm_2_table[index];
648         m_dsp.adpcm_step = step_2_table[index];
649         break;
650      case 3:
651         index = (sample & 3) | m_dsp.adpcm_step;
652         dec_sample += ((sample & 4)?-1:1) * adpcm_3_table[index];
653         m_dsp.adpcm_step = step_3_table[index];
654         break;
655      case 4:
656         index = (sample & 7) | m_dsp.adpcm_step;
657         dec_sample += ((sample & 8)?-1:1) * adpcm_4_table[index];
658         m_dsp.adpcm_step = step_4_table[index];
659         break;
660   }
661
647662   if(dec_sample > 255)
648663      dec_sample = 255;
649664   else if(dec_sample < 0)
r17772r17773
651666   m_dsp.adpcm_ref = dec_sample;
652667   m_dacl->write_unsigned8(m_dsp.adpcm_ref);
653668   m_dacr->write_unsigned8(m_dsp.adpcm_ref);
654   sample &= (1 << (size - 1)) - 1;
655   if(sample >= ((size << 1) - 3))
656   {
657      if(m_dsp.adpcm_step < 3)
658         m_dsp.adpcm_step++;
659   }
660   else if(!sample && m_dsp.adpcm_step)
661      m_dsp.adpcm_step--;
662669}
663670
664READ8_MEMBER ( sb_device::joy_port_r )
665{
666   UINT8 data = 0;
667   int delta;
668   attotime new_time = machine().time();
669
670   {
671      data = ioport("pc_joy")->read() | 0x0f;
672
673      {
674         delta = ((new_time - m_joy_time) * 256 * 1000).seconds;
675
676         if (ioport("pc_joy_1")->read() < delta) data &= ~0x01;
677         if (ioport("pc_joy_2")->read() < delta) data &= ~0x02;
678      }
679   }
680
681   return data;
682}
683
684WRITE8_MEMBER ( sb_device::joy_port_w )
685{
686   m_joy_time = machine().time();
687}
688
689671READ8_MEMBER( sb16_device::mpu401_r )
690672{
691673   UINT8 res;
r17772r17773
804786sb_device::sb_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, UINT32 clock, const char *name) :
805787    device_t(mconfig, type, name, tag, owner, clock),
806788    m_dacl(*this, "sbdacl"),
807    m_dacr(*this, "sbdacr")
789    m_dacr(*this, "sbdacr"),
790   m_joy(*this, "joy")
808791{
809792}
810793
r17772r17773
845828
846829void sb8_device::device_start()
847830{
848   m_isa->install_device(                   0x0200, 0x0207, 0, 0, read8_delegate(FUNC(sb_device::joy_port_r), this), write8_delegate(FUNC(sb_device::joy_port_w), this));
831   m_isa->install_device(                   0x0200, 0x0207, 0, 0, read8_delegate(FUNC(pc_joy_device::joy_port_r), subdevice<pc_joy_device>("joy")), write8_delegate(FUNC(pc_joy_device::joy_port_w), subdevice<pc_joy_device>("joy")));
849832   m_isa->install_device(                   0x0226, 0x0227, 0, 0, read8_delegate(FUNC(sb_device::dsp_reset_r), this), write8_delegate(FUNC(sb_device::dsp_reset_w), this));
850833   m_isa->install_device(                   0x022a, 0x022b, 0, 0, read8_delegate(FUNC(sb_device::dsp_data_r), this), write8_delegate(FUNC(sb_device::dsp_data_w), this) );
851834   m_isa->install_device(                   0x022c, 0x022d, 0, 0, read8_delegate(FUNC(sb_device::dsp_wbuf_status_r), this), write8_delegate(FUNC(sb_device::dsp_cmd_w), this) );
r17772r17773
888871
889872void sb16_device::device_start()
890873{
891   m_isa->install_device(                   0x0200, 0x0207, 0, 0, read8_delegate(FUNC(sb_device::joy_port_r), this), write8_delegate(FUNC(sb_device::joy_port_w), this));
874   m_isa->install_device(                   0x0200, 0x0207, 0, 0, read8_delegate(FUNC(pc_joy_device::joy_port_r), subdevice<pc_joy_device>("joy")), write8_delegate(FUNC(pc_joy_device::joy_port_w), subdevice<pc_joy_device>("joy")));
892875   m_isa->install_device(                   0x0224, 0x0225, 0, 0, read8_delegate(FUNC(sb_device::mixer_r), this), write8_delegate(FUNC(sb_device::mixer_w), this));
893876   m_isa->install_device(                   0x0226, 0x0227, 0, 0, read8_delegate(FUNC(sb_device::dsp_reset_r), this), write8_delegate(FUNC(sb_device::dsp_reset_w), this));
894877   m_isa->install_device(                   0x022a, 0x022b, 0, 0, read8_delegate(FUNC(sb_device::dsp_data_r), this), write8_delegate(FUNC(sb_device::dsp_data_w), this) );
r17772r17773
926909    m_dsp.fifo_r_ptr = 0;
927910    m_dsp.wbuf_status = 0;
928911    m_dsp.rbuf_status = 0;
929   m_dsp.frequency = 22050; //?
912   m_dsp.frequency = 8000; // per stereo-fx
930913   m_dsp.irq_active = 0;
931914   m_mixer_index = 0;
932915}
r17772r17773
11301113            m_dacl->write_unsigned8(m_dsp.adpcm_ref);
11311114            break;
11321115         }
1133         lsample = m_dsp.data[m_dsp.d_rptr++];
1134         adpcm_decode(lsample >> 6, 2);
1135         adpcm_decode((lsample >> 4) & 3, 2);
1136         adpcm_decode((lsample >> 2) & 3, 2);
1137         adpcm_decode(lsample & 3, 2);
1116         lsample = m_dsp.data[m_dsp.d_rptr];
1117         switch(m_dsp.adpcm_count++)
1118         {
1119            case 0:
1120               adpcm_decode(lsample >> 6, 2);
1121               break;
1122            case 1:
1123               adpcm_decode((lsample >> 4) & 3, 2);
1124               break;
1125            case 2:
1126               adpcm_decode((lsample >> 2) & 3, 2);
1127               break;
1128            case 3:
1129               adpcm_decode(lsample & 3, 2);
1130               m_dsp.data[m_dsp.d_rptr++] = 0x80;
1131               m_dsp.adpcm_count = 0;
1132               break;
1133         }
11381134         break;
11391135      case ADPCM3:
11401136         if(m_dsp.adpcm_new_ref)
r17772r17773
11451141            m_dacl->write_unsigned8(m_dsp.adpcm_ref);
11461142            break;
11471143         }   
1148         lsample = m_dsp.data[m_dsp.d_rptr++];
1149         adpcm_decode(lsample >> 5, 3);
1150         adpcm_decode((lsample >> 2) & 7, 3);
1151         adpcm_decode(lsample & 3, 2);
1144         lsample = m_dsp.data[m_dsp.d_rptr];
1145         switch(m_dsp.adpcm_count++)
1146         {
1147            case 0:
1148               adpcm_decode(lsample >> 5, 3);
1149               break;
1150            case 1:
1151               adpcm_decode((lsample >> 2) & 7, 3);
1152               break;
1153            case 2:
1154               adpcm_decode(((lsample & 2) << 1) | (lsample & 1), 3);
1155               m_dsp.data[m_dsp.d_rptr++] = 0x80;
1156               m_dsp.adpcm_count = 0;
1157               break;
1158         }
11521159         break;
11531160      case ADPCM4:
11541161         if(m_dsp.adpcm_new_ref)
r17772r17773
11591166            m_dacl->write_unsigned8(m_dsp.adpcm_ref);
11601167            break;
11611168         }   
1162         lsample = m_dsp.data[m_dsp.d_rptr++];
1163         adpcm_decode(lsample >> 4, 4);
1164         adpcm_decode(lsample & 15, 4);
1169         lsample = m_dsp.data[m_dsp.d_rptr];
1170         switch(m_dsp.adpcm_count++)
1171         {
1172            case 0:
1173               adpcm_decode(lsample >> 4, 4);
1174               break;
1175            case 1:
1176               adpcm_decode(lsample & 15, 4);
1177               m_dsp.data[m_dsp.d_rptr++] = 0x80;
1178               m_dsp.adpcm_count = 0;
1179               break;
1180         }
11651181         break;
11661182      default:
11671183         logerror("SB: unimplemented sample type %x\n", m_dsp.flags);
trunk/src/mess/machine/isa_sblaster.h
r17772r17773
66#include "emu.h"
77#include "machine/isa.h"
88#include "sound/dac.h"
9#include "machine/pc_joy.h"
910
1011#define SIXTEENBIT   0x01
1112#define STEREO      0x02
r17772r17773
4849   bool adpcm_new_ref;
4950   UINT8 adpcm_ref;
5051   UINT8 adpcm_step;
52   UINT8 adpcm_count;
5153};
5254
5355// ======================> sb8_device (parent)
r17772r17773
6163
6264        required_device<dac_device> m_dacl;
6365        required_device<dac_device> m_dacr;
66   required_device<pc_joy_device> m_joy;
6467
6568        void process_fifo(UINT8 cmd);
6669        void queue(UINT8 data);
r17772r17773
7578        DECLARE_READ8_MEMBER(dsp_wbuf_status_r);
7679        DECLARE_WRITE8_MEMBER(dsp_rbuf_status_w);
7780        DECLARE_WRITE8_MEMBER(dsp_cmd_w);
78        DECLARE_READ8_MEMBER(joy_port_r);
79        DECLARE_WRITE8_MEMBER(joy_port_w);
8081      DECLARE_READ8_MEMBER(mixer_r);
8182      DECLARE_WRITE8_MEMBER(mixer_w);
82      virtual ioport_constructor device_input_ports() const;
8383
8484protected:
8585        // device-level overrides
r17772r17773
9494
9595        struct sb8_dsp_state m_dsp;
9696        UINT8 m_dack_out;
97        attotime m_joy_time;
9897      UINT8 m_mixer_index;
9998
10099        emu_timer *m_timer;

Previous 199869 Revisions Next


© 1997-2024 The MAME Team