Previous 199869 Revisions Next

r21520 Friday 1st March, 2013 at 15:56:10 UTC by Andrew Gardner
Modernized gomoku, astrocade, saa1099, st0016, and c140 sound devices. [Andrew Gardner]
[src/emu/sound]astrocde.c astrocde.h c140.c c140.h saa1099.c saa1099.h st0016.c st0016.h
[src/mame/audio]gomoku.c
[src/mame/drivers]astrocde.c bingor.c blitz68k.c g627.c gal3.c gomoku.c jclub2.c jpmsys5.c macs.c manohman.c mastboy.c mpu4vid.c namcona1.c namcos2.c namcos21.c speglsht.c srmp5.c st0016.c xorworld.c
[src/mame/includes]gomoku.h jpmsys5.h
[src/mame/video]astrocde.c
[src/mess/drivers]samcoupe.c
[src/mess/machine]isa_gblaster.c isa_sblaster.c

trunk/src/mame/includes/gomoku.h
r21519r21520
1#include "devlegcy.h"
21
32class gomoku_state : public driver_device
43{
r21519r21520
3130
3231/*----------- defined in audio/gomoku.c -----------*/
3332
34DECLARE_WRITE8_DEVICE_HANDLER( gomoku_sound1_w );
35DECLARE_WRITE8_DEVICE_HANDLER( gomoku_sound2_w );
33/* 4 voices max */
34#define GOMOKU_MAX_VOICES 4
3635
36//**************************************************************************
37//  TYPE DEFINITIONS
38//**************************************************************************
39
40struct gomoku_sound_channel
41{
42    gomoku_sound_channel():
43     channel(0),
44     frequency(0),
45     counter(0),
46     volume(0),
47     oneshotplaying(0) {}
48
49   int channel;
50   int frequency;
51   int counter;
52   int volume;
53   int oneshotplaying;
54};
55
56
57// ======================> gomoku_sound_device
58
3759class gomoku_sound_device : public device_t,
38                           public device_sound_interface
60                     public device_sound_interface
3961{
4062public:
4163   gomoku_sound_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
42   ~gomoku_sound_device() { global_free(m_token); }
64   ~gomoku_sound_device() { }
4365
44   // access to legacy token
45   void *token() const { assert(m_token != NULL); return m_token; }
4666protected:
4767   // device-level overrides
48   virtual void device_config_complete();
4968   virtual void device_start();
5069
5170   // sound stream update overrides
5271   virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples);
72
73public:
74    DECLARE_WRITE8_MEMBER( sound1_w );
75    DECLARE_WRITE8_MEMBER( sound2_w );
76
5377private:
54   // internal state
55   void *m_token;
78    void make_mixer_table(int voices, int gain);
79
80private:
81   /* data about the sound system */
82   gomoku_sound_channel m_channel_list[GOMOKU_MAX_VOICES];
83   gomoku_sound_channel *m_last_channel;
84
85   /* global sound parameters */
86   const UINT8 *m_sound_rom;
87   int m_num_voices;
88   int m_sound_enable;
89   sound_stream *m_stream;
90
91   /* mixer tables and internal buffers */
92   INT16 *m_mixer_table;
93   INT16 *m_mixer_lookup;
94   short *m_mixer_buffer;
95   short *m_mixer_buffer_2;
96
97   UINT8 m_soundregs1[0x20];
98   UINT8 m_soundregs2[0x20];
5699};
57100
58101extern const device_type GOMOKU;
trunk/src/mame/includes/jpmsys5.h
r21519r21520
33#include "machine/6840ptm.h"
44#include "machine/6850acia.h"
55#include "sound/2413intf.h"
6#include "sound/saa1099.h"
76#include "sound/upd7759.h"
87#include "video/tms34061.h"
98#include "machine/nvram.h"
trunk/src/mame/video/astrocde.c
r21519r21520
576576      case 0x17:  /* noise volume register */
577577      case 0x18:  /* sound block transfer */
578578         if (m_video_config & AC_SOUND_PRESENT)
579            astrocade_sound_w(machine().device("astrocade1"), space, offset, data);
579            machine().device<astrocade_device>("astrocade1")->astrocade_sound_w(space, offset, data);
580580         break;
581581
582582      case 0x19:  /* expand register */
trunk/src/mame/drivers/srmp5.c
r21519r21520
369369static ADDRESS_MAP_START( st0016_mem, AS_PROGRAM, 8, srmp5_state )
370370   AM_RANGE(0x0000, 0x7fff) AM_ROM
371371   AM_RANGE(0x8000, 0xbfff) AM_ROMBANK("bank1")
372   AM_RANGE(0xe900, 0xe9ff) AM_DEVREADWRITE_LEGACY("stsnd", st0016_snd_r, st0016_snd_w)
372   AM_RANGE(0xe900, 0xe9ff) AM_DEVREADWRITE("stsnd", st0016_device, st0016_snd_r, st0016_snd_w)
373373   AM_RANGE(0xec00, 0xec1f) AM_READ(st0016_character_ram_r) AM_WRITE(st0016_character_ram_w)
374374   AM_RANGE(0xf000, 0xffff) AM_RAM
375375ADDRESS_MAP_END
r21519r21520
560560
561561   MCFG_SPEAKER_STANDARD_STEREO("lspeaker", "rspeaker")
562562
563   MCFG_SOUND_ADD("stsnd", ST0016, 0)
563   MCFG_ST0016_ADD("stsnd", 0)
564564   MCFG_SOUND_CONFIG(st0016_config)
565565   MCFG_SOUND_ROUTE(0, "lspeaker", 1.0)
566566   MCFG_SOUND_ROUTE(1, "rspeaker", 1.0)
trunk/src/mame/drivers/jclub2.c
r21519r21520
758758static ADDRESS_MAP_START( st0016_mem, AS_PROGRAM, 8, darkhors_state )
759759   AM_RANGE(0x0000, 0x7fff) AM_ROM
760760   AM_RANGE(0x8000, 0xbfff) AM_ROMBANK("bank1")
761   AM_RANGE(0xe900, 0xe9ff) AM_DEVREADWRITE_LEGACY("stsnd", st0016_snd_r, st0016_snd_w)
761   AM_RANGE(0xe900, 0xe9ff) AM_DEVREADWRITE("stsnd", st0016_device, st0016_snd_r, st0016_snd_w)
762762   AM_RANGE(0xec00, 0xec1f) AM_READ(st0016_character_ram_r) AM_WRITE(st0016_character_ram_w)
763763   AM_RANGE(0xf000, 0xffff) AM_RAM
764764ADDRESS_MAP_END
r21519r21520
817817
818818   MCFG_SPEAKER_STANDARD_STEREO("lspeaker", "rspeaker")
819819
820   MCFG_SOUND_ADD("stsnd", ST0016, 0)
820   MCFG_ST0016_ADD("stsnd", 0)
821821   MCFG_SOUND_CONFIG(st0016_config)
822822   MCFG_SOUND_ROUTE(0, "lspeaker", 1.0)
823823   MCFG_SOUND_ROUTE(1, "rspeaker", 1.0)
trunk/src/mame/drivers/namcos21.c
r21519r21520
13691369   AM_RANGE(0x0000, 0x3fff) AM_ROMBANK("bank6") /* banked */
13701370   AM_RANGE(0x3000, 0x3003) AM_WRITENOP /* ? */
13711371   AM_RANGE(0x4000, 0x4001) AM_DEVREADWRITE("ymsnd", ym2151_device,read,write)
1372   AM_RANGE(0x5000, 0x6fff) AM_DEVREADWRITE_LEGACY("c140", c140_r,c140_w)
1372   AM_RANGE(0x5000, 0x6fff) AM_DEVREADWRITE("c140", c140_device, c140_r,c140_w)
13731373   AM_RANGE(0x7000, 0x77ff) AM_READWRITE(namcos2_dualportram_byte_r,namcos2_dualportram_byte_w) AM_SHARE("mpdualportram")
13741374   AM_RANGE(0x7800, 0x7fff) AM_READWRITE(namcos2_dualportram_byte_r,namcos2_dualportram_byte_w) /* mirror */
13751375   AM_RANGE(0x8000, 0x9fff) AM_RAM
r21519r21520
15331533
15341534   MCFG_SPEAKER_STANDARD_STEREO("lspeaker", "rspeaker")
15351535
1536   MCFG_SOUND_ADD("c140", C140, 8000000/374)
1536   MCFG_C140_ADD("c140", 8000000/374)
15371537   MCFG_SOUND_CONFIG(C140_interface)
15381538   MCFG_SOUND_ROUTE(0, "lspeaker", 0.50)
15391539   MCFG_SOUND_ROUTE(1, "rspeaker", 0.50)
r21519r21520
15881588
15891589   MCFG_SPEAKER_STANDARD_STEREO("lspeaker", "rspeaker")
15901590
1591   MCFG_SOUND_ADD("c140", C140, 8000000/374)
1591   MCFG_C140_ADD("c140", 8000000/374)
15921592   MCFG_SOUND_CONFIG(C140_interface)
15931593   MCFG_SOUND_ROUTE(0, "lspeaker", 0.50)
15941594   MCFG_SOUND_ROUTE(1, "rspeaker", 0.50)
r21519r21520
16461646
16471647   MCFG_SPEAKER_STANDARD_STEREO("lspeaker", "rspeaker")
16481648
1649   MCFG_SOUND_ADD("c140", C140, 8000000/374)
1649   MCFG_C140_ADD("c140", 8000000/374)
16501650   MCFG_SOUND_CONFIG(C140_interface)
16511651   MCFG_SOUND_ROUTE(0, "lspeaker", 0.50)
16521652   MCFG_SOUND_ROUTE(1, "rspeaker", 0.50)
trunk/src/mame/drivers/speglsht.c
r21519r21520
144144   AM_RANGE(0xd000, 0xdfff) AM_READ(st0016_sprite2_ram_r) AM_WRITE(st0016_sprite2_ram_w)
145145   AM_RANGE(0xe000, 0xe7ff) AM_RAM
146146   AM_RANGE(0xe800, 0xe87f) AM_RAM
147   AM_RANGE(0xe900, 0xe9ff) AM_DEVREADWRITE_LEGACY("stsnd", st0016_snd_r, st0016_snd_w)
147   AM_RANGE(0xe900, 0xe9ff) AM_DEVREADWRITE("stsnd", st0016_device, st0016_snd_r, st0016_snd_w)
148148   AM_RANGE(0xea00, 0xebff) AM_READ(st0016_palette_ram_r) AM_WRITE(st0016_palette_ram_w)
149149   AM_RANGE(0xec00, 0xec1f) AM_READ(st0016_character_ram_r) AM_WRITE(st0016_character_ram_w)
150150   AM_RANGE(0xf000, 0xffff) AM_RAM AM_SHARE("shared")
r21519r21520
409409
410410   MCFG_SPEAKER_STANDARD_STEREO("lspeaker", "rspeaker")
411411
412   MCFG_SOUND_ADD("stsnd", ST0016, 0)
412   MCFG_ST0016_ADD("stsnd", 0)
413413   MCFG_SOUND_CONFIG(st0016_config)
414414   MCFG_SOUND_ROUTE(0, "lspeaker", 1.0)
415415   MCFG_SOUND_ROUTE(1, "rspeaker", 1.0)
trunk/src/mame/drivers/mastboy.c
r21519r21520
722722   AM_RANGE(0xff818, 0xff81f) AM_READ_PORT("DSW2")
723723
724724   AM_RANGE(0xff820, 0xff827) AM_WRITE(mastboy_bank_w)
725   AM_RANGE(0xff828, 0xff828) AM_DEVWRITE_LEGACY("saa", saa1099_data_w)
726   AM_RANGE(0xff829, 0xff829) AM_DEVWRITE_LEGACY("saa", saa1099_control_w)
725   AM_RANGE(0xff828, 0xff828) AM_DEVWRITE("saa", saa1099_device, saa1099_data_w)
726   AM_RANGE(0xff829, 0xff829) AM_DEVWRITE("saa", saa1099_device, saa1099_control_w)
727727   AM_RANGE(0xff830, 0xff830) AM_WRITE(mastboy_msm5205_data_w)
728728   AM_RANGE(0xff838, 0xff838) AM_WRITE(mastboy_irq0_ack_w)
729729   AM_RANGE(0xff839, 0xff839) AM_WRITE(msm5205_mastboy_m5205_sambit0_w)
r21519r21520
907907
908908   // sound hardware
909909   MCFG_SPEAKER_STANDARD_MONO("mono")
910   MCFG_SOUND_ADD("saa", SAA1099, 6000000 )
910   MCFG_SAA1099_ADD("saa", 6000000 )
911911   MCFG_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.50)
912912
913913   MCFG_SOUND_ADD("msm", MSM5205, 384000)
trunk/src/mame/drivers/bingor.c
r21519r21520
522522
523523static ADDRESS_MAP_START( bingor_io, AS_IO, 16, bingor_state )
524524//  AM_RANGE(0x0000, 0x00ff) AM_READ(test_r )
525   AM_RANGE(0x0100, 0x0101) AM_DEVWRITE8_LEGACY("saa", saa1099_data_w, 0x00ff)
526   AM_RANGE(0x0102, 0x0103) AM_DEVWRITE8_LEGACY("saa", saa1099_control_w, 0x00ff)
525   AM_RANGE(0x0100, 0x0101) AM_DEVWRITE8("saa", saa1099_device, saa1099_data_w, 0x00ff)
526   AM_RANGE(0x0102, 0x0103) AM_DEVWRITE8("saa", saa1099_device, saa1099_control_w, 0x00ff)
527527//  AM_RANGE(0x0200, 0x0201) AM_READ(test_r )
528528ADDRESS_MAP_END
529529
r21519r21520
644644
645645
646646   MCFG_SPEAKER_STANDARD_MONO("mono")
647   MCFG_SOUND_ADD("saa", SAA1099, 6000000 )
647   MCFG_SAA1099_ADD("saa", 6000000 )
648648   MCFG_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.50)
649649MACHINE_CONFIG_END
650650
trunk/src/mame/drivers/mpu4vid.c
r21519r21520
14101410   AM_RANGE(0x000000, 0x7fffff) AM_ROM
14111411   AM_RANGE(0x800000, 0x80ffff) AM_RAM AM_SHARE("vid_mainram")
14121412//  AM_RANGE(0x810000, 0x81ffff) AM_RAM /* ? */
1413   AM_RANGE(0x900000, 0x900001) AM_DEVWRITE8_LEGACY("saa", saa1099_data_w, 0x00ff)
1414   AM_RANGE(0x900002, 0x900003) AM_DEVWRITE8_LEGACY("saa", saa1099_control_w, 0x00ff)
1413   AM_RANGE(0x900000, 0x900001) AM_DEVWRITE8("saa", saa1099_device, saa1099_data_w, 0x00ff)
1414   AM_RANGE(0x900002, 0x900003) AM_DEVWRITE8("saa", saa1099_device, saa1099_control_w, 0x00ff)
14151415   AM_RANGE(0xa00000, 0xa00003) AM_READWRITE_LEGACY(ef9369_r, ef9369_w)
14161416/*  AM_RANGE(0xa00004, 0xa0000f) AM_READWRITE_LEGACY(mpu4_vid_unmap_r, mpu4_vid_unmap_w) */
14171417
r21519r21520
14301430   AM_RANGE(0x600000, 0x63ffff) AM_RAM /* The Mating Game has an extra 256kB RAM on the program card */
14311431//  AM_RANGE(0x640000, 0x7fffff) AM_NOP /* Possible bug, reads and writes here */
14321432   AM_RANGE(0x800000, 0x80ffff) AM_RAM AM_SHARE("vid_mainram")
1433   AM_RANGE(0x900000, 0x900001) AM_DEVWRITE8_LEGACY("saa", saa1099_data_w, 0x00ff)
1434   AM_RANGE(0x900002, 0x900003) AM_DEVWRITE8_LEGACY("saa", saa1099_control_w, 0x00ff)
1433   AM_RANGE(0x900000, 0x900001) AM_DEVWRITE8("saa", saa1099_device, saa1099_data_w, 0x00ff)
1434   AM_RANGE(0x900002, 0x900003) AM_DEVWRITE8("saa", saa1099_device, saa1099_control_w, 0x00ff)
14351435   AM_RANGE(0xa00000, 0xa00003) AM_READWRITE_LEGACY(ef9369_r, ef9369_w)
14361436
14371437   AM_RANGE(0xb00000, 0xb0000f) AM_DEVREADWRITE("scn2674_vid", scn2674_device, mpu4_vid_scn2674_r, mpu4_vid_scn2674_w)
r21519r21520
14521452   AM_RANGE(0x000000, 0x7fffff) AM_ROM
14531453   AM_RANGE(0x800000, 0x80ffff) AM_RAM AM_SHARE("vid_mainram")
14541454   AM_RANGE(0x810000, 0x81ffff) AM_RAM /* ? */
1455   AM_RANGE(0x900000, 0x900001) AM_DEVWRITE8_LEGACY("saa", saa1099_data_w, 0x00ff)
1456   AM_RANGE(0x900002, 0x900003) AM_DEVWRITE8_LEGACY("saa", saa1099_control_w, 0x00ff)
1455   AM_RANGE(0x900000, 0x900001) AM_DEVWRITE8("saa", saa1099_device, saa1099_data_w, 0x00ff)
1456   AM_RANGE(0x900002, 0x900003) AM_DEVWRITE8("saa", saa1099_device, saa1099_control_w, 0x00ff)
14571457   AM_RANGE(0xa00000, 0xa00003) AM_READWRITE_LEGACY(ef9369_r, ef9369_w)
14581458//  AM_RANGE(0xa00000, 0xa0000f) AM_READWRITE_LEGACY(bt471_r,bt471_w) //Some games use this
14591459/*  AM_RANGE(0xa00004, 0xa0000f) AM_READWRITE_LEGACY(mpu4_vid_unmap_r, mpu4_vid_unmap_w) */
r21519r21520
14701470   AM_RANGE(0x000000, 0x7fffff) AM_ROM
14711471   AM_RANGE(0x800000, 0x80ffff) AM_RAM AM_SHARE("vid_mainram")
14721472   AM_RANGE(0x810000, 0x81ffff) AM_RAM /* ? */
1473   AM_RANGE(0x900000, 0x900001) AM_DEVWRITE8_LEGACY("saa", saa1099_data_w, 0x00ff)
1474   AM_RANGE(0x900002, 0x900003) AM_DEVWRITE8_LEGACY("saa", saa1099_control_w, 0x00ff)
1473   AM_RANGE(0x900000, 0x900001) AM_DEVWRITE8("saa", saa1099_device, saa1099_data_w, 0x00ff)
1474   AM_RANGE(0x900002, 0x900003) AM_DEVWRITE8("saa", saa1099_device, saa1099_control_w, 0x00ff)
14751475   AM_RANGE(0xa00000, 0xa00003) AM_READWRITE_LEGACY(ef9369_r, ef9369_w)
14761476   //AM_RANGE(0xa00000, 0xa00003) AM_READWRITE_LEGACY(bt471_r,bt471_w) Some games use this
14771477/*  AM_RANGE(0xa00004, 0xa0000f) AM_READWRITE_LEGACY(mpu4_vid_unmap_r, mpu4_vid_unmap_w) */
r21519r21520
15491549   MCFG_PTM6840_ADD("6840ptm_68k", ptm_vid_intf)
15501550   /* Present on all video cards */
15511551   MCFG_SPEAKER_STANDARD_STEREO("lspeaker", "rspeaker")
1552   MCFG_SOUND_ADD("saa", SAA1099, 8000000)
1552   MCFG_SAA1099_ADD("saa", 8000000)
15531553   MCFG_SOUND_ROUTE(0, "lspeaker", 0.5)
15541554   MCFG_SOUND_ROUTE(1, "rspeaker", 0.5)
15551555
trunk/src/mame/drivers/macs.c
r21519r21520
9494   AM_RANGE(0xd000, 0xdfff) AM_READ(st0016_sprite2_ram_r) AM_WRITE(st0016_sprite2_ram_w)
9595   AM_RANGE(0xe000, 0xe7ff) AM_RAM /* work ram ? */
9696   AM_RANGE(0xe800, 0xe87f) AM_RAM AM_SHARE("ram2")
97   AM_RANGE(0xe900, 0xe9ff) AM_DEVREADWRITE_LEGACY("stsnd", st0016_snd_r, st0016_snd_w)
97   AM_RANGE(0xe900, 0xe9ff) AM_DEVREADWRITE("stsnd", st0016_device, st0016_snd_r, st0016_snd_w)
9898   AM_RANGE(0xea00, 0xebff) AM_READ(st0016_palette_ram_r) AM_WRITE(st0016_palette_ram_w)
9999   AM_RANGE(0xec00, 0xec1f) AM_READ(st0016_character_ram_r) AM_WRITE(st0016_character_ram_w)
100100   AM_RANGE(0xf000, 0xf7ff) AM_RAMBANK("bank3") /* common /backup ram ?*/
r21519r21520
500500
501501   MCFG_SPEAKER_STANDARD_STEREO("lspeaker", "rspeaker")
502502
503   MCFG_SOUND_ADD("stsnd", ST0016, 0)
503   MCFG_ST0016_ADD("stsnd", 0)
504504   MCFG_SOUND_CONFIG(st0016_config)
505505   MCFG_SOUND_ROUTE(0, "lspeaker", 1.0)
506506   MCFG_SOUND_ROUTE(1, "rspeaker", 1.0)
trunk/src/mame/drivers/g627.c
r21519r21520
8080   ADDRESS_MAP_GLOBAL_MASK(0xff)
8181   AM_RANGE(0x00, 0x02) AM_WRITE(disp_w)
8282   AM_RANGE(0x03, 0x07) AM_WRITE(lamp_w)
83   AM_RANGE(0x10, 0x17) AM_DEVWRITE_LEGACY("astrocade", astrocade_sound_w)
83   AM_RANGE(0x10, 0x17) AM_DEVWRITE("astrocade", astrocade_device, astrocade_sound_w)
8484   AM_RANGE(0x20, 0x27) AM_DEVREADWRITE("i8156", i8155_device, io_r, io_w)
8585ADDRESS_MAP_END
8686
trunk/src/mame/drivers/namcona1.c
r21519r21520
804804
805805READ16_MEMBER(namcona1_state::snd_r)
806806{
807   device_t *device = machine().device("c140");
807   c140_device *device = machine().device<c140_device>("c140");
808808   /* can't use DEVREADWRITE8 for this because it is opposite endianness to the CPU for some reason */
809   return c140_r(device,space,offset*2+1) | c140_r(device,space,offset*2)<<8;
809   return device->c140_r(space,offset*2+1) | device->c140_r(space,offset*2)<<8;
810810}
811811
812812WRITE16_MEMBER(namcona1_state::snd_w)
813813{
814   device_t *device = machine().device("c140");
814   c140_device *device = machine().device<c140_device>("c140");
815815   /* can't use DEVREADWRITE8 for this because it is opposite endianness to the CPU for some reason */
816816   if (ACCESSING_BITS_0_7)
817817   {
818      c140_w(device,space,(offset*2)+1, data);
818      device->c140_w(space,(offset*2)+1, data);
819819   }
820820
821821   if (ACCESSING_BITS_8_15)
822822   {
823      c140_w(device,space,(offset*2), data>>8);
823      device->c140_w(space,(offset*2), data>>8);
824824   }
825825}
826826
r21519r21520
916916
917917void namcona1_state::machine_start()
918918{
919   c140_set_base(machine().device("c140"), m_workram);
919   machine().device<c140_device>("c140")->set_base(m_workram);
920920}
921921
922922// for games with the MCU emulated, the MCU boots the 68000.  don't allow it before that.
r21519r21520
10321032   /* sound hardware */
10331033   MCFG_SPEAKER_STANDARD_STEREO("lspeaker", "rspeaker")
10341034
1035   MCFG_SOUND_ADD("c140", C140, 44100)
1035   MCFG_C140_ADD("c140", 44100)
10361036   MCFG_SOUND_CONFIG(C140_interface_typeA)
10371037   MCFG_SOUND_ROUTE(0, "rspeaker", 1.00)
10381038   MCFG_SOUND_ROUTE(1, "lspeaker", 1.00)
trunk/src/mame/drivers/blitz68k.c
r21519r21520
19941994   MCFG_RAMDAC_ADD("ramdac", ramdac_intf, ramdac_map)
19951995
19961996   MCFG_SPEAKER_STANDARD_MONO("mono")
1997   MCFG_SOUND_ADD("saa", SAA1099, XTAL_8MHz/2)
1997   MCFG_SAA1099_ADD("saa", XTAL_8MHz/2)
19981998   MCFG_SOUND_ROUTE(ALL_OUTPUTS, "mono", 1.0)
19991999MACHINE_CONFIG_END
20002000
trunk/src/mame/drivers/gomoku.c
r21519r21520
4444   AM_RANGE(0x5000, 0x53ff) AM_RAM_WRITE(gomoku_videoram_w) AM_SHARE("videoram")
4545   AM_RANGE(0x5400, 0x57ff) AM_RAM_WRITE(gomoku_colorram_w) AM_SHARE("colorram")
4646   AM_RANGE(0x5800, 0x58ff) AM_RAM_WRITE(gomoku_bgram_w) AM_SHARE("bgram")
47   AM_RANGE(0x6000, 0x601f) AM_DEVWRITE_LEGACY("gomoku", gomoku_sound1_w)
48   AM_RANGE(0x6800, 0x681f) AM_DEVWRITE_LEGACY("gomoku", gomoku_sound2_w)
47   AM_RANGE(0x6000, 0x601f) AM_DEVWRITE("gomoku", gomoku_sound_device, sound1_w)
48   AM_RANGE(0x6800, 0x681f) AM_DEVWRITE("gomoku", gomoku_sound_device, sound2_w)
4949   AM_RANGE(0x7000, 0x7000) AM_WRITENOP
5050   AM_RANGE(0x7001, 0x7001) AM_WRITE(gomoku_flipscreen_w)
5151   AM_RANGE(0x7002, 0x7002) AM_WRITE(gomoku_bg_dispsw_w)
trunk/src/mame/drivers/namcos2.c
r21519r21520
737737static ADDRESS_MAP_START( sound_default_am, AS_PROGRAM, 8, namcos2_state )
738738   AM_RANGE(0x0000, 0x3fff) AM_ROMBANK("bank6") /* banked */
739739   AM_RANGE(0x4000, 0x4001) AM_DEVREADWRITE("ymsnd", ym2151_device,read,write)
740   AM_RANGE(0x5000, 0x6fff) AM_DEVREADWRITE_LEGACY("c140", c140_r,c140_w)
740   AM_RANGE(0x5000, 0x6fff) AM_DEVREADWRITE("c140", c140_device, c140_r,c140_w)
741741   AM_RANGE(0x7000, 0x77ff) AM_READWRITE(dpram_byte_r,dpram_byte_w) AM_SHARE("dpram")
742742   AM_RANGE(0x7800, 0x7fff) AM_READWRITE(dpram_byte_r,dpram_byte_w) /* mirror */
743743   AM_RANGE(0x8000, 0x9fff) AM_RAM
r21519r21520
16401640
16411641   MCFG_SPEAKER_STANDARD_STEREO("lspeaker", "rspeaker")
16421642
1643   MCFG_SOUND_ADD("c140", C140, C140_SOUND_CLOCK) /* 21.333kHz */
1643   MCFG_C140_ADD("c140", C140_SOUND_CLOCK) /* 21.333kHz */
16441644   MCFG_SOUND_CONFIG(c140_config)
16451645   MCFG_SOUND_ROUTE(0, "lspeaker", 0.75)
16461646   MCFG_SOUND_ROUTE(1, "rspeaker", 0.75)
r21519r21520
16531653/* adjusted machine driver start */
16541654static MACHINE_CONFIG_DERIVED( default2, default )
16551655
1656   MCFG_SOUND_REPLACE("c140", C140, C140_SOUND_CLOCK) /* 21.333kHz */
1656   MCFG_C140_REPLACE("c140", C140_SOUND_CLOCK) /* 21.333kHz */
16571657   MCFG_SOUND_CONFIG(c140_config)
16581658   MCFG_SOUND_ROUTE(0, "lspeaker", 1.0)
16591659   MCFG_SOUND_ROUTE(1, "rspeaker", 1.0)
r21519r21520
16671667
16681668static MACHINE_CONFIG_DERIVED( default3, default )
16691669
1670   MCFG_SOUND_REPLACE("c140", C140, C140_SOUND_CLOCK) /* 21.333kHz */
1670   MCFG_C140_REPLACE("c140", C140_SOUND_CLOCK) /* 21.333kHz */
16711671   MCFG_SOUND_CONFIG(c140_config)
16721672   MCFG_SOUND_ROUTE(0, "lspeaker", 0.45)
16731673   MCFG_SOUND_ROUTE(1, "rspeaker", 0.45)
r21519r21520
17141714
17151715   MCFG_SPEAKER_STANDARD_STEREO("lspeaker", "rspeaker")
17161716
1717   MCFG_SOUND_ADD("c140", C140, C140_SOUND_CLOCK) /* 21.333kHz */
1717   MCFG_C140_ADD("c140", C140_SOUND_CLOCK) /* 21.333kHz */
17181718   MCFG_SOUND_CONFIG(c140_config)
17191719   MCFG_SOUND_ROUTE(0, "lspeaker", 0.75)
17201720   MCFG_SOUND_ROUTE(1, "rspeaker", 0.75)
r21519r21520
17651765
17661766   MCFG_SPEAKER_STANDARD_STEREO("lspeaker", "rspeaker")
17671767
1768   MCFG_SOUND_ADD("c140", C140, C140_SOUND_CLOCK) /* 21.333kHz */
1768   MCFG_C140_ADD("c140", C140_SOUND_CLOCK) /* 21.333kHz */
17691769   MCFG_SOUND_CONFIG(c140_config)
17701770   MCFG_SOUND_ROUTE(0, "lspeaker", 0.75)
17711771   MCFG_SOUND_ROUTE(1, "rspeaker", 0.75)
r21519r21520
18141814
18151815   MCFG_SPEAKER_STANDARD_STEREO("lspeaker", "rspeaker")
18161816
1817   MCFG_SOUND_ADD("c140", C140, C140_SOUND_CLOCK) /* 21.333kHz */
1817   MCFG_C140_ADD("c140", C140_SOUND_CLOCK) /* 21.333kHz */
18181818   MCFG_SOUND_CONFIG(c140_config)
18191819   MCFG_SOUND_ROUTE(0, "lspeaker", 0.75)
18201820   MCFG_SOUND_ROUTE(1, "rspeaker", 0.75)
r21519r21520
18651865
18661866   MCFG_SPEAKER_STANDARD_STEREO("lspeaker", "rspeaker")
18671867
1868   MCFG_SOUND_ADD("c140", C140, C140_SOUND_CLOCK) /* 21.333kHz */
1868   MCFG_C140_ADD("c140", C140_SOUND_CLOCK) /* 21.333kHz */
18691869   MCFG_SOUND_CONFIG(c140_config)
18701870   MCFG_SOUND_ROUTE(0, "lspeaker", 0.75)
18711871   MCFG_SOUND_ROUTE(1, "rspeaker", 0.75)
r21519r21520
19141914
19151915   MCFG_SPEAKER_STANDARD_STEREO("lspeaker", "rspeaker")
19161916
1917   MCFG_SOUND_ADD("c140", C140, C140_SOUND_CLOCK) /* 21.333kHz */
1917   MCFG_C140_ADD("c140", C140_SOUND_CLOCK) /* 21.333kHz */
19181918   MCFG_SOUND_CONFIG(c140_config)
19191919   MCFG_SOUND_ROUTE(0, "lspeaker", 1.0)
19201920   MCFG_SOUND_ROUTE(1, "rspeaker", 1.0)
trunk/src/mame/drivers/astrocde.c
r21519r21520
676676
677677static ADDRESS_MAP_START( port_map_stereo_pattern, AS_IO, 8, astrocde_state )
678678   AM_RANGE(0x0000, 0x0019) AM_MIRROR(0xff00) AM_MASK(0xffff) AM_READWRITE(astrocade_data_chip_register_r, astrocade_data_chip_register_w)
679   AM_RANGE(0x0050, 0x0058) AM_MIRROR(0xff00) AM_MASK(0xffff) AM_DEVWRITE_LEGACY("astrocade2", astrocade_sound_w)
679   AM_RANGE(0x0050, 0x0058) AM_MIRROR(0xff00) AM_MASK(0xffff) AM_DEVWRITE("astrocade2", astrocade_device, astrocade_sound_w)
680680   AM_RANGE(0x0078, 0x007e) AM_MIRROR(0xff00) AM_WRITE(astrocade_pattern_board_w)
681681   AM_RANGE(0xa55b, 0xa55b) AM_WRITE(protected_ram_enable_w)
682682ADDRESS_MAP_END
r21519r21520
684684
685685static ADDRESS_MAP_START( port_map_16col_pattern, AS_IO, 8, astrocde_state )
686686   AM_RANGE(0x0000, 0x0019) AM_MIRROR(0xff00) AM_MASK(0xffff) AM_READWRITE(astrocade_data_chip_register_r, astrocade_data_chip_register_w)
687   AM_RANGE(0x0050, 0x0058) AM_MIRROR(0xff00) AM_MASK(0xffff) AM_DEVWRITE_LEGACY("astrocade2", astrocade_sound_w)
687   AM_RANGE(0x0050, 0x0058) AM_MIRROR(0xff00) AM_MASK(0xffff) AM_DEVWRITE("astrocade2", astrocade_device, astrocade_sound_w)
688688   AM_RANGE(0x0078, 0x007e) AM_MIRROR(0xff00) AM_WRITE(astrocade_pattern_board_w)
689689   AM_RANGE(0x00bf, 0x00bf) AM_MIRROR(0xff00) AM_WRITE(profpac_page_select_w)
690690   AM_RANGE(0x00c3, 0x00c3) AM_MIRROR(0xff00) AM_READ(profpac_intercept_r)
r21519r21520
13251325   /* sound hardware */
13261326   MCFG_SPEAKER_STANDARD_MONO("mono")
13271327
1328   MCFG_SOUND_ADD("astrocade1",  ASTROCADE, ASTROCADE_CLOCK/4)
1328   MCFG_ASTROCADE_ADD("astrocade1", ASTROCADE_CLOCK/4)
13291329   MCFG_SOUND_ROUTE(ALL_OUTPUTS, "mono", 1.0)
13301330MACHINE_CONFIG_END
13311331
r21519r21520
13351335   /* sound hardware */
13361336   MCFG_SPEAKER_STANDARD_STEREO("lspeaker", "rspeaker")
13371337
1338   MCFG_SOUND_ADD("astrocade1",  ASTROCADE, ASTROCADE_CLOCK/4)
1338   MCFG_ASTROCADE_ADD("astrocade1", ASTROCADE_CLOCK/4)
13391339   MCFG_SOUND_ROUTE(ALL_OUTPUTS, "lspeaker", 1.0)
13401340
1341   MCFG_SOUND_ADD("astrocade2",  ASTROCADE, ASTROCADE_CLOCK/4)
1341   MCFG_ASTROCADE_ADD("astrocade2", ASTROCADE_CLOCK/4)
13421342   MCFG_SOUND_ROUTE(ALL_OUTPUTS, "rspeaker", 1.0)
13431343MACHINE_CONFIG_END
13441344
r21519r21520
14411441   MCFG_SPEAKER_ADD("upper", 0.0, 0.0, 1.0)
14421442   MCFG_SPEAKER_ADD("lower", 0.0, -0.5, 1.0)
14431443
1444   MCFG_SOUND_ADD("astrocade1",  ASTROCADE, ASTROCADE_CLOCK/4)
1444   MCFG_ASTROCADE_ADD("astrocade1", ASTROCADE_CLOCK/4)
14451445   MCFG_SOUND_ROUTE(ALL_OUTPUTS, "upper", 1.0)
14461446
1447   MCFG_SOUND_ADD("astrocade2",  ASTROCADE, ASTROCADE_CLOCK/4)
1447   MCFG_ASTROCADE_ADD("astrocade2", ASTROCADE_CLOCK/4)
14481448   MCFG_SOUND_ROUTE(ALL_OUTPUTS, "lower", 1.0)
14491449
14501450#if USE_FAKE_VOTRAX
trunk/src/mame/drivers/gal3.c
r21519r21520
438438   AM_RANGE(0x110000, 0x113fff) AM_RAM
439439/// AM_RANGE(0x120000, 0x120003) AM_RAM //2ieme byte
440440/// AM_RANGE(0x200000, 0x20017f) AM_RAM //C140
441   AM_RANGE(0x200000, 0x2037ff) AM_DEVREADWRITE8_LEGACY("c140_16a", c140_r, c140_w, 0x00ff)    //C140///////////
441   AM_RANGE(0x200000, 0x2037ff) AM_DEVREADWRITE8("c140_16a", c140_device, c140_r, c140_w, 0x00ff)    //C140///////////
442442/// AM_RANGE(0x201000, 0x20117f) AM_RAM //C140
443443/// AM_RANGE(0x202000, 0x20217f) AM_RAM //C140
444444/// AM_RANGE(0x203000, 0x20317f) AM_RAM //C140
445   AM_RANGE(0x204000, 0x2047ff) AM_DEVREADWRITE8_LEGACY("c140_16g", c140_r, c140_w, 0x00ff)    //C140
445   AM_RANGE(0x204000, 0x2047ff) AM_DEVREADWRITE8("c140_16g", c140_device, c140_r, c140_w, 0x00ff)    //C140
446446/// AM_RANGE(0x090000, 0xffffff) AM_RAM
447447ADDRESS_MAP_END
448448
r21519r21520
637637
638638   MCFG_SPEAKER_STANDARD_STEREO("lspeaker", "rspeaker")
639639
640   MCFG_SOUND_ADD("c140_16g", C140, 8000000/374)
640   MCFG_C140_ADD("c140_16g", 8000000/374)
641641   MCFG_SOUND_CONFIG(C140_interface)   //to be verified
642642   MCFG_SOUND_ROUTE(0, "lspeaker", 0.50)
643643   MCFG_SOUND_ROUTE(1, "rspeaker", 0.50)
644644
645   MCFG_SOUND_ADD("c140_16a", C140, 8000000/374)
645   MCFG_C140_ADD("c140_16a", 8000000/374)
646646   MCFG_SOUND_CONFIG(C140_interface)
647647   MCFG_SOUND_ROUTE(0, "lspeaker", 0.50)
648648   MCFG_SOUND_ROUTE(1, "rspeaker", 0.50)
trunk/src/mame/drivers/jpmsys5.c
r21519r21520
3030
3131#include "emu.h"
3232#include "includes/jpmsys5.h"
33#include "sound/saa1099.h"
3334#include "jpmsys5.lh"
3435
3536enum state { IDLE, START, DATA, STOP1, STOP2 };
r21519r21520
325326
326327static ADDRESS_MAP_START( 68000_awp_map_saa, AS_PROGRAM, 16, jpmsys5_state )
327328   JPM_SYS5_COMMON_MAP
328   AM_RANGE(0x0460a0, 0x0460a1) AM_DEVWRITE8_LEGACY("saa", saa1099_data_w, 0x00ff)
329   AM_RANGE(0x0460a2, 0x0460a3) AM_DEVWRITE8_LEGACY("saa", saa1099_control_w, 0x00ff)
329   AM_RANGE(0x0460a0, 0x0460a1) AM_DEVWRITE8("saa", saa1099_device, saa1099_data_w, 0x00ff)
330   AM_RANGE(0x0460a2, 0x0460a3) AM_DEVWRITE8("saa", saa1099_device, saa1099_control_w, 0x00ff)
330331   AM_RANGE(0x04c100, 0x04c105) AM_READWRITE(jpm_upd7759_r, jpm_upd7759_w) // do the SAA boards have the UPD?
331332ADDRESS_MAP_END
332333
r21519r21520
890891   MCFG_SOUND_ADD("upd7759", UPD7759, UPD7759_STANDARD_CLOCK)
891892   MCFG_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.30)
892893
893   MCFG_SOUND_ADD("saa", SAA1099, 4000000 /* guess */)
894   MCFG_SAA1099_ADD("saa", 4000000 /* guess */)
894895   MCFG_SOUND_ROUTE(ALL_OUTPUTS, "mono", 1.0)
895896
896897   /* 6840 PTM */
trunk/src/mame/drivers/st0016.c
r21519r21520
3232   AM_RANGE(0xd000, 0xdfff) AM_READ(st0016_sprite2_ram_r) AM_WRITE(st0016_sprite2_ram_w)
3333   AM_RANGE(0xe000, 0xe7ff) AM_RAM
3434   AM_RANGE(0xe800, 0xe87f) AM_RAM /* common ram */
35   AM_RANGE(0xe900, 0xe9ff) AM_DEVREADWRITE_LEGACY("stsnd", st0016_snd_r, st0016_snd_w) /* sound regs 8 x $20 bytes, see notes */
35   AM_RANGE(0xe900, 0xe9ff) AM_DEVREADWRITE("stsnd", st0016_device, st0016_snd_r, st0016_snd_w) /* sound regs 8 x $20 bytes, see notes */
3636   AM_RANGE(0xea00, 0xebff) AM_READ(st0016_palette_ram_r) AM_WRITE(st0016_palette_ram_w)
3737   AM_RANGE(0xec00, 0xec1f) AM_READ(st0016_character_ram_r) AM_WRITE(st0016_character_ram_w)
3838   AM_RANGE(0xf000, 0xffff) AM_RAM /* work ram */
r21519r21520
461461
462462   MCFG_SPEAKER_STANDARD_STEREO("lspeaker", "rspeaker")
463463
464   MCFG_SOUND_ADD("stsnd", ST0016, 0)
464   MCFG_ST0016_ADD("stsnd", 0)
465465   MCFG_SOUND_CONFIG(st0016_config)
466466   MCFG_SOUND_ROUTE(0, "lspeaker", 1.0)
467467   MCFG_SOUND_ROUTE(1, "rspeaker", 1.0)
trunk/src/mame/drivers/manohman.c
r21519r21520
153153static ADDRESS_MAP_START( manohman_map, AS_PROGRAM, 16, _manohman_state )
154154   AM_RANGE(0x000000, 0x01ffff) AM_ROM
155155   AM_RANGE(0x100000, 0x100001) AM_NOP     // smell to MAX696 watchdog...
156   AM_RANGE(0x300000, 0x300001) AM_DEVWRITE8_LEGACY("saa", saa1099_data_w, 0x00ff)
157   AM_RANGE(0x300002, 0x300003) AM_DEVWRITE8_LEGACY("saa", saa1099_control_w, 0x00ff)
156   AM_RANGE(0x300000, 0x300001) AM_DEVWRITE8("saa", saa1099_device, saa1099_data_w, 0x00ff)
157   AM_RANGE(0x300002, 0x300003) AM_DEVWRITE8("saa", saa1099_device, saa1099_control_w, 0x00ff)
158158   AM_RANGE(0x500000, 0x503fff) AM_RAM
159159   AM_RANGE(0x600006, 0x600007) AM_RAM     // write bitpatterns to compare with the 500000-503ff8 RAM testing.
160160//  AM_RANGE(0xYYYYYY, 0xYYYYYY) AM_RAM
r21519r21520
211211
212212   // sound hardware
213213   MCFG_SPEAKER_STANDARD_MONO("mono")
214   MCFG_SOUND_ADD("saa", SAA1099, MASTER_CLOCK /* guess */)
214   MCFG_SAA1099_ADD("saa", MASTER_CLOCK /* guess */)
215215   MCFG_SOUND_ROUTE(ALL_OUTPUTS, "mono", 1.0)
216216MACHINE_CONFIG_END
217217
trunk/src/mame/drivers/xorworld.c
r21519r21520
8383   AM_RANGE(0x200000, 0x200001) AM_READ_PORT("P1")
8484   AM_RANGE(0x400000, 0x400001) AM_READ_PORT("P2")
8585   AM_RANGE(0x600000, 0x600001) AM_READ_PORT("DSW")
86   AM_RANGE(0x800000, 0x800001) AM_DEVWRITE8_LEGACY("saa", saa1099_data_w, 0x00ff)
87   AM_RANGE(0x800002, 0x800003) AM_DEVWRITE8_LEGACY("saa", saa1099_control_w, 0x00ff)
86   AM_RANGE(0x800000, 0x800001) AM_DEVWRITE8("saa", saa1099_device, saa1099_data_w, 0x00ff)
87   AM_RANGE(0x800002, 0x800003) AM_DEVWRITE8("saa", saa1099_device, saa1099_control_w, 0x00ff)
8888   AM_RANGE(0xa00008, 0xa00009) AM_WRITE(eeprom_chip_select_w)
8989   AM_RANGE(0xa0000a, 0xa0000b) AM_WRITE(eeprom_serial_clock_w)
9090   AM_RANGE(0xa0000c, 0xa0000d) AM_WRITE(eeprom_data_w)
r21519r21520
196196
197197   // sound hardware
198198   MCFG_SPEAKER_STANDARD_MONO("mono")
199   MCFG_SOUND_ADD("saa", SAA1099, 8000000 /* guess */)
199   MCFG_SAA1099_ADD("saa", 8000000 /* guess */)
200200   MCFG_SOUND_ROUTE(ALL_OUTPUTS, "mono", 1.0)
201201MACHINE_CONFIG_END
202202
trunk/src/mame/audio/gomoku.c
r21519r21520
99#include "emu.h"
1010#include "includes/gomoku.h"
1111
12
13/* 4 voices max */
14#define MAX_VOICES 4
15
16
1712static const int samplerate = 48000;
1813static const int defgain = 48;
1914
2015
21/* this structure defines the parameters for a channel */
22struct sound_channel
23{
24   int channel;
25   int frequency;
26   int counter;
27   int volume;
28   int oneshotplaying;
29};
16// device type definition
17const device_type GOMOKU = &device_creator<gomoku_sound_device>;
3018
3119
32struct gomoku_sound_state
33{
34   /* data about the sound system */
35   sound_channel m_channel_list[MAX_VOICES];
36   sound_channel *m_last_channel;
20//**************************************************************************
21//  LIVE DEVICE
22//**************************************************************************
3723
38   /* global sound parameters */
39   const UINT8 *m_sound_rom;
40   int m_num_voices;
41   int m_sound_enable;
42   sound_stream *m_stream;
24//-------------------------------------------------
25//  gomoku_sound_device - constructor
26//-------------------------------------------------
4327
44   /* mixer tables and internal buffers */
45   INT16 *m_mixer_table;
46   INT16 *m_mixer_lookup;
47   short *m_mixer_buffer;
48   short *m_mixer_buffer_2;
28gomoku_sound_device::gomoku_sound_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
29   : device_t(mconfig, GOMOKU, "Gomoku Custom", tag, owner, clock),
30     device_sound_interface(mconfig, *this),
31     m_last_channel(NULL),
32     m_sound_rom(NULL),
33     m_num_voices(0),
34     m_sound_enable(0),
35     m_stream(NULL),
36     m_mixer_table(NULL),
37     m_mixer_lookup(NULL),
38     m_mixer_buffer(NULL),
39     m_mixer_buffer_2(NULL)
40{
41   memset(m_channel_list, 0, sizeof(gomoku_sound_channel)*GOMOKU_MAX_VOICES);
42   memset(m_soundregs1, 0, sizeof(UINT8)*0x20);
43   memset(m_soundregs2, 0, sizeof(UINT8)*0x20);
44}
4945
50   UINT8 m_soundregs1[0x20];
51   UINT8 m_soundregs2[0x20];
52};
5346
54INLINE gomoku_sound_state *get_safe_token( device_t *device )
47//-------------------------------------------------
48//  device_start - device-specific startup
49//-------------------------------------------------
50
51void gomoku_sound_device::device_start()
5552{
56   assert(device != NULL);
57   assert(device->type() == GOMOKU);
53   gomoku_sound_channel *voice;
54   int ch;
5855
59   return (gomoku_sound_state *)downcast<gomoku_sound_device *>(device)->token();
60}
56   /* get stream channels */
57   m_stream = stream_alloc(0, 1, samplerate);
6158
59   /* allocate a pair of buffers to mix into - 1 second's worth should be more than enough */
60   m_mixer_buffer = auto_alloc_array(machine(), short, 2 * samplerate);
61   m_mixer_buffer_2 = m_mixer_buffer + samplerate;
6262
63/* build a table to divide by the number of voices; gain is specified as gain*16 */
64static void make_mixer_table(device_t *device, int voices, int gain)
65{
66   gomoku_sound_state *state = get_safe_token(device);
67   int count = voices * 128;
68   int i;
63   /* build the mixer table */
64   make_mixer_table(8, defgain);
6965
70   /* allocate memory */
71   state->m_mixer_table = auto_alloc_array(device->machine(), INT16, 256 * voices);
66   /* extract globals from the interface */
67   m_num_voices = GOMOKU_MAX_VOICES;
68   m_last_channel = m_channel_list + m_num_voices;
7269
73   /* find the middle of the table */
74   state->m_mixer_lookup = state->m_mixer_table + (128 * voices);
70   m_sound_rom = memregion("gomoku")->base();
7571
76   /* fill in the table - 16 bit case */
77   for (i = 0; i < count; i++)
72   /* start with sound enabled, many games don't have a sound enable register */
73   m_sound_enable = 1;
74
75   /* reset all the voices */
76   for (ch = 0, voice = m_channel_list; voice < m_last_channel; ch++, voice++)
7877   {
79      int val = i * gain * 16 / voices;
80      if (val > 32767) val = 32767;
81      state->m_mixer_lookup[ i] = val;
82      state->m_mixer_lookup[-i] = -val;
78      voice->channel = ch;
79      voice->frequency = 0;
80      voice->counter = 0;
81      voice->volume = 0;
82      voice->oneshotplaying = 0;
8383   }
8484}
8585
8686
87/* generate sound to the mix buffer in mono */
88static STREAM_UPDATE( gomoku_update_mono )
87//-------------------------------------------------
88//  sound_stream_update - handle a stream update in mono
89//-------------------------------------------------
90
91void gomoku_sound_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples)
8992{
90   gomoku_sound_state *state = get_safe_token(device);
9193   stream_sample_t *buffer = outputs[0];
92   sound_channel *voice;
94   gomoku_sound_channel *voice;
9395   short *mix;
9496   int i, ch;
9597
9698   /* if no sound, we're done */
97   if (state->m_sound_enable == 0)
99   if (m_sound_enable == 0)
98100   {
99101      memset(buffer, 0, samples * sizeof(*buffer));
100102      return;
101103   }
102104
103105   /* zap the contents of the mixer buffer */
104   memset(state->m_mixer_buffer, 0, samples * sizeof(short));
106   memset(m_mixer_buffer, 0, samples * sizeof(short));
105107
106108   /* loop over each voice and add its contribution */
107   for (ch = 0, voice = state->m_channel_list; voice < state->m_last_channel; ch++, voice++)
109   for (ch = 0, voice = m_channel_list; voice < m_last_channel; ch++, voice++)
108110   {
109111      int f = 16 * voice->frequency;
110112      int v = voice->volume;
r21519r21520
116118         int c = voice->counter;
117119
118120         if (ch < 3)
119            w_base = 0x20 * (state->m_soundregs1[0x06 + (ch * 8)] & 0x0f);
121            w_base = 0x20 * (m_soundregs1[0x06 + (ch * 8)] & 0x0f);
120122         else
121            w_base = 0x100 * (state->m_soundregs2[0x1d] & 0x0f);
123            w_base = 0x100 * (m_soundregs2[0x1d] & 0x0f);
122124
123         mix = state->m_mixer_buffer;
125         mix = m_mixer_buffer;
124126
125127         /* add our contribution */
126128         for (i = 0; i < samples; i++)
r21519r21520
133135
134136               /* use full byte, first the high 4 bits, then the low 4 bits */
135137               if (c & 0x8000)
136                  *mix++ += ((state->m_sound_rom[offs] & 0x0f) - 8) * v;
138                  *mix++ += ((m_sound_rom[offs] & 0x0f) - 8) * v;
137139               else
138                  *mix++ += (((state->m_sound_rom[offs]>>4) & 0x0f) - 8) * v;
140                  *mix++ += (((m_sound_rom[offs]>>4) & 0x0f) - 8) * v;
139141            }
140142            else
141143            {
142144               int offs = (w_base + (c >> 16)) & 0x0fff;
143145
144               if (state->m_sound_rom[offs] == 0xff)
146               if (m_sound_rom[offs] == 0xff)
145147               {
146148                  voice->oneshotplaying = 0;
147149               }
r21519r21520
150152               {
151153                  /* use full byte, first the high 4 bits, then the low 4 bits */
152154                  if (c & 0x8000)
153                     *mix++ += ((state->m_sound_rom[offs] & 0x0f) - 8) * v;
155                     *mix++ += ((m_sound_rom[offs] & 0x0f) - 8) * v;
154156                  else
155                     *mix++ += (((state->m_sound_rom[offs]>>4) & 0x0f) - 8) * v;
157                     *mix++ += (((m_sound_rom[offs]>>4) & 0x0f) - 8) * v;
156158               }
157159            }
158160
r21519r21520
163165   }
164166
165167   /* mix it down */
166   mix = state->m_mixer_buffer;
168   mix = m_mixer_buffer;
167169   for (i = 0; i < samples; i++)
168      *buffer++ = state->m_mixer_lookup[*mix++];
170      *buffer++ = m_mixer_lookup[*mix++];
169171}
170172
171173
172
173static DEVICE_START( gomoku_sound )
174/* build a table to divide by the number of voices; gain is specified as gain*16 */
175void gomoku_sound_device::make_mixer_table(int voices, int gain)
174176{
175   gomoku_sound_state *state = get_safe_token(device);
176   running_machine &machine = device->machine();
177   sound_channel *voice;
178   int ch;
177   int count = voices * 128;
178   int i;
179179
180   /* get stream channels */
181   state->m_stream = device->machine().sound().stream_alloc(*device, 0, 1, samplerate, NULL, gomoku_update_mono);
180   /* allocate memory */
181   m_mixer_table = auto_alloc_array(machine(), INT16, 256 * voices);
182182
183   /* allocate a pair of buffers to mix into - 1 second's worth should be more than enough */
184   state->m_mixer_buffer = auto_alloc_array(machine, short, 2 * samplerate);
185   state->m_mixer_buffer_2 = state->m_mixer_buffer + samplerate;
183   /* find the middle of the table */
184   m_mixer_lookup = m_mixer_table + (128 * voices);
186185
187   /* build the mixer table */
188   make_mixer_table(device, 8, defgain);
189
190   /* extract globals from the interface */
191   state->m_num_voices = MAX_VOICES;
192   state->m_last_channel = state->m_channel_list + state->m_num_voices;
193
194   state->m_sound_rom = machine.root_device().memregion("gomoku")->base();
195
196   /* start with sound enabled, many games don't have a sound enable register */
197   state->m_sound_enable = 1;
198
199   /* reset all the voices */
200   for (ch = 0, voice = state->m_channel_list; voice < state->m_last_channel; ch++, voice++)
186   /* fill in the table - 16 bit case */
187   for (i = 0; i < count; i++)
201188   {
202      voice->channel = ch;
203      voice->frequency = 0;
204      voice->counter = 0;
205      voice->volume = 0;
206      voice->oneshotplaying = 0;
189      int val = i * gain * 16 / voices;
190      if (val > 32767) val = 32767;
191      m_mixer_lookup[ i] = val;
192      m_mixer_lookup[-i] = -val;
207193   }
208194}
209195
210196
211197/********************************************************************************/
212198
213WRITE8_DEVICE_HANDLER( gomoku_sound1_w )
199WRITE8_MEMBER( gomoku_sound_device::sound1_w )
214200{
215   gomoku_sound_state *state = get_safe_token(device);
216   sound_channel *voice;
201   gomoku_sound_channel *voice;
217202   int base;
218203   int ch;
219204
220205   /* update the streams */
221   state->m_stream->update();
206   m_stream->update();
222207
223208   /* set the register */
224   state->m_soundregs1[offset] = data;
209   m_soundregs1[offset] = data;
225210
226211   /* recompute all the voice parameters */
227   for (ch = 0, base = 0, voice = state->m_channel_list; voice < state->m_channel_list + 3; ch++, voice++, base += 8)
212   for (ch = 0, base = 0, voice = m_channel_list; voice < m_channel_list + 3; ch++, voice++, base += 8)
228213   {
229214      voice->channel = ch;
230      voice->frequency = state->m_soundregs1[0x02 + base] & 0x0f;
231      voice->frequency = voice->frequency * 16 + ((state->m_soundregs1[0x01 + base]) & 0x0f);
232      voice->frequency = voice->frequency * 16 + ((state->m_soundregs1[0x00 + base]) & 0x0f);
215      voice->frequency = m_soundregs1[0x02 + base] & 0x0f;
216      voice->frequency = voice->frequency * 16 + ((m_soundregs1[0x01 + base]) & 0x0f);
217      voice->frequency = voice->frequency * 16 + ((m_soundregs1[0x00 + base]) & 0x0f);
233218   }
234219}
235220
236WRITE8_DEVICE_HANDLER( gomoku_sound2_w )
221WRITE8_MEMBER( gomoku_sound_device::sound2_w )
237222{
238   gomoku_sound_state *state = get_safe_token(device);
239   sound_channel *voice;
223   gomoku_sound_channel *voice;
240224   int base;
241225   int ch;
242226
243227   /* update the streams */
244   state->m_stream->update();
228   m_stream->update();
245229
246230   /* set the register */
247   state->m_soundregs2[offset] = data;
231   m_soundregs2[offset] = data;
248232
249233   /* recompute all the voice parameters */
250   for (ch = 0, base = 0, voice = state->m_channel_list; voice < state->m_channel_list + 3; ch++, voice++, base += 8)
234   for (ch = 0, base = 0, voice = m_channel_list; voice < m_channel_list + 3; ch++, voice++, base += 8)
251235   {
252236      voice->channel = ch;
253      voice->volume = state->m_soundregs2[0x06 + base] & 0x0f;
237      voice->volume = m_soundregs2[0x06 + base] & 0x0f;
254238      voice->oneshotplaying = 0;
255239   }
256240
257241   if (offset == 0x1d)
258242   {
259      voice = &state->m_channel_list[3];
243      voice = &m_channel_list[3];
260244      voice->channel = 3;
261245
262246      // oneshot frequency is hand tune...
263      if ((state->m_soundregs2[0x1d] & 0x0f) < 0x0c)
247      if ((m_soundregs2[0x1d] & 0x0f) < 0x0c)
264248         voice->frequency = 3000 / 16;           // ichi, ni, san, yon, go
265249      else
266250         voice->frequency = 8000 / 16;           // shoot
r21519r21520
268252      voice->volume = 8;
269253      voice->counter = 0;
270254
271      if (state->m_soundregs2[0x1d] & 0x0f)
255      if (m_soundregs2[0x1d] & 0x0f)
272256         voice->oneshotplaying = 1;
273257      else
274258         voice->oneshotplaying = 0;
275259   }
276260}
277261
278
279const device_type GOMOKU = &device_creator<gomoku_sound_device>;
280
281gomoku_sound_device::gomoku_sound_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
282   : device_t(mconfig, GOMOKU, "Gomoku Custom", tag, owner, clock),
283      device_sound_interface(mconfig, *this)
284{
285   m_token = global_alloc_clear(gomoku_sound_state);
286}
287
288//-------------------------------------------------
289//  device_config_complete - perform any
290//  operations now that the configuration is
291//  complete
292//-------------------------------------------------
293
294void gomoku_sound_device::device_config_complete()
295{
296}
297
298//-------------------------------------------------
299//  device_start - device-specific startup
300//-------------------------------------------------
301
302void gomoku_sound_device::device_start()
303{
304   DEVICE_START_NAME( gomoku_sound )(this);
305}
306
307//-------------------------------------------------
308//  sound_stream_update - handle a stream update
309//-------------------------------------------------
310
311void gomoku_sound_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples)
312{
313   // should never get here
314   fatalerror("sound_stream_update called; not applicable to legacy sound devices\n");
315}
trunk/src/emu/sound/c140.c
r21519r21520
4646#include "emu.h"
4747#include "c140.h"
4848
49#define MAX_VOICE 24
50
5149struct voice_registers
5250{
5351   UINT8 volume_right;
r21519r21520
6563   UINT8 reserved[4];
6664};
6765
68struct VOICE
69{
70   long    ptoffset;
71   long    pos;
72   long    key;
73   //--work
74   long    lastdt;
75   long    prevdt;
76   long    dltdt;
77   //--reg
78   long    rvol;
79   long    lvol;
80   long    frequency;
81   long    bank;
82   long    mode;
8366
84   long    sample_start;
85   long    sample_end;
86   long    sample_loop;
87};
67// device type definition
68const device_type C140 = &device_creator<c140_device>;
8869
89struct c140_state
90{
91   int sample_rate;
92   sound_stream *stream;
93   int banking_type;
94   /* internal buffers */
95   INT16 *mixer_buffer_left;
96   INT16 *mixer_buffer_right;
9770
98   int baserate;
99   void *pRom;
100   UINT8 REG[0x200];
71//**************************************************************************
72//  LIVE DEVICE
73//**************************************************************************
10174
102   INT16 pcmtbl[8];        //2000.06.26 CAB
103
104   VOICE voi[MAX_VOICE];
105};
106
107INLINE c140_state *get_safe_token(device_t *device)
75INLINE int limit(INT32 in)
10876{
109   assert(device != NULL);
110   assert(device->type() == C140);
111   return (c140_state *)downcast<c140_device *>(device)->token();
77   if(in>0x7fff)       return 0x7fff;
78   else if(in<-0x8000) return -0x8000;
79   return in;
11280}
11381
11482
115static void init_voice( VOICE *v )
83//-------------------------------------------------
84//  c140_device - constructor
85//-------------------------------------------------
86
87c140_device::c140_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
88   : device_t(mconfig, C140, "C140", tag, owner, clock),
89     device_sound_interface(mconfig, *this),
90     m_sample_rate(0),
91     m_stream(NULL),
92     m_banking_type(0),
93     m_mixer_buffer_left(NULL),
94     m_mixer_buffer_right(NULL),
95     m_baserate(0),
96     m_pRom(NULL)
11697{
117   v->key=0;
118   v->ptoffset=0;
119   v->rvol=0;
120   v->lvol=0;
121   v->frequency=0;
122   v->bank=0;
123   v->mode=0;
124   v->sample_start=0;
125   v->sample_end=0;
126   v->sample_loop=0;
98   memset(m_REG, 0, sizeof(UINT8)*0x200);
99   memset(m_pcmtbl, 0, sizeof(INT16)*8);
127100}
128READ8_DEVICE_HANDLER( c140_r )
129{
130   c140_state *info = get_safe_token(device);
131   offset&=0x1ff;
132   return info->REG[offset];
133}
134101
135/*
136   find_sample: compute the actual address of a sample given it's
137   address and banking registers, as well as the board type.
138102
139   I suspect in "real life" this works like the Sega MultiPCM where the banking
140   is done by a small PAL or GAL external to the sound chip, which can be switched
141   per-game or at least per-PCB revision as addressing range needs grow.
142 */
143static long find_sample(c140_state *info, long adrs, long bank, int voice)
103//-------------------------------------------------
104//  device_start - device-specific startup
105//-------------------------------------------------
106
107void c140_device::device_start()
144108{
145   long newadr = 0;
109   const c140_interface *intf = (const c140_interface *)static_config();
146110
147   static const INT16 asic219banks[4] = { 0x1f7, 0x1f1, 0x1f3, 0x1f5 };
111   m_sample_rate=m_baserate=clock();
148112
149   adrs=(bank<<16)+adrs;
113   m_banking_type = intf->banking_type;
150114
151   switch (info->banking_type)
152   {
153      case C140_TYPE_SYSTEM2:
154         // System 2 banking
155         newadr = ((adrs&0x200000)>>2)|(adrs&0x7ffff);
156         break;
115   m_stream = stream_alloc(0, 2, m_sample_rate);
157116
158      case C140_TYPE_SYSTEM21:
159         // System 21 banking.
160         // similar to System 2's.
161         newadr = ((adrs&0x300000)>>1)+(adrs&0x7ffff);
162         break;
117   m_pRom=*region();
163118
164      case C140_TYPE_ASIC219:
165         // ASIC219's banking is fairly simple
166         newadr = ((info->REG[asic219banks[voice/4]]&0x3) * 0x20000) + adrs;
167         break;
168   }
169
170   return (newadr);
171}
172WRITE8_DEVICE_HANDLER( c140_w )
173{
174   c140_state *info = get_safe_token(device);
175   info->stream->update();
176
177   offset&=0x1ff;
178
179   // mirror the bank registers on the 219, fixes bkrtmaq (and probably xday2 based on notes in the HLE)
180   if ((offset >= 0x1f8) && (info->banking_type == C140_TYPE_ASIC219))
119   /* make decompress pcm table */     //2000.06.26 CAB
181120   {
182      offset -= 8;
121      int i;
122      INT32 segbase=0;
123      for(i=0;i<8;i++)
124      {
125         m_pcmtbl[i]=segbase;    //segment base value
126         segbase += 16<<i;
127      }
183128   }
184129
185   info->REG[offset]=data;
186   if( offset<0x180 )
130   memset(m_REG,0,sizeof(m_REG));
187131   {
188      VOICE *v = &info->voi[offset>>4];
189
190      if( (offset&0xf)==0x5 )
191      {
192         if( data&0x80 )
193         {
194            const struct voice_registers *vreg = (struct voice_registers *) &info->REG[offset&0x1f0];
195            v->key=1;
196            v->ptoffset=0;
197            v->pos=0;
198            v->lastdt=0;
199            v->prevdt=0;
200            v->dltdt=0;
201            v->bank = vreg->bank;
202            v->mode = data;
203
204            // on the 219 asic, addresses are in words
205            if (info->banking_type == C140_TYPE_ASIC219)
206            {
207               v->sample_loop = (vreg->loop_msb*256 + vreg->loop_lsb)*2;
208               v->sample_start = (vreg->start_msb*256 + vreg->start_lsb)*2;
209               v->sample_end = (vreg->end_msb*256 + vreg->end_lsb)*2;
210
211               #if 0
212               logerror("219: play v %d mode %02x start %x loop %x end %x\n",
213                  offset>>4, v->mode,
214                  find_sample(info, v->sample_start, v->bank, offset>>4),
215                  find_sample(info, v->sample_loop, v->bank, offset>>4),
216                  find_sample(info, v->sample_end, v->bank, offset>>4));
217               #endif
218            }
219            else
220            {
221               v->sample_loop = vreg->loop_msb*256 + vreg->loop_lsb;
222               v->sample_start = vreg->start_msb*256 + vreg->start_lsb;
223               v->sample_end = vreg->end_msb*256 + vreg->end_lsb;
224            }
225         }
226         else
227         {
228            v->key=0;
229         }
230      }
132      int i;
133      for(i=0;i<C140_MAX_VOICE;i++) init_voice( &m_voi[i] );
231134   }
232}
233135
234void c140_set_base(device_t *device, void *base)
235{
236   c140_state *info = get_safe_token(device);
237   info->pRom = base;
136   /* allocate a pair of buffers to mix into - 1 second's worth should be more than enough */
137   m_mixer_buffer_left = auto_alloc_array(machine(), INT16, 2 * m_sample_rate);
138   m_mixer_buffer_right = m_mixer_buffer_left + m_sample_rate;
238139}
239140
240INLINE int limit(INT32 in)
241{
242   if(in>0x7fff)       return 0x7fff;
243   else if(in<-0x8000) return -0x8000;
244   return in;
245}
246141
247static STREAM_UPDATE( update_stereo )
142//-------------------------------------------------
143//  sound_stream_update - handle a stream update
144//-------------------------------------------------
145
146void c140_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples)
248147{
249   c140_state *info = (c140_state *)param;
250148   int     i,j;
251149
252150   INT32   rvol,lvol;
r21519r21520
258156   INT32   frequency,delta,offset,pos;
259157   INT32   cnt, voicecnt;
260158   INT32   lastdt,prevdt,dltdt;
261   float   pbase=(float)info->baserate*2.0 / (float)info->sample_rate;
159   float   pbase=(float)m_baserate*2.0 / (float)m_sample_rate;
262160
263161   INT16   *lmix, *rmix;
264162
265   if(samples>info->sample_rate) samples=info->sample_rate;
163   if(samples>m_sample_rate) samples=m_sample_rate;
266164
267165   /* zap the contents of the mixer buffer */
268   memset(info->mixer_buffer_left, 0, samples * sizeof(INT16));
269   memset(info->mixer_buffer_right, 0, samples * sizeof(INT16));
166   memset(m_mixer_buffer_left, 0, samples * sizeof(INT16));
167   memset(m_mixer_buffer_right, 0, samples * sizeof(INT16));
270168
271169   /* get the number of voices to update */
272   voicecnt = (info->banking_type == C140_TYPE_ASIC219) ? 16 : 24;
170   voicecnt = (m_banking_type == C140_TYPE_ASIC219) ? 16 : 24;
273171
274172   //--- audio update
275173   for( i=0;i<voicecnt;i++ )
276174   {
277      VOICE *v = &info->voi[i];
278      const struct voice_registers *vreg = (struct voice_registers *)&info->REG[i*16];
175      C140_VOICE *v = &m_voi[i];
176      const struct voice_registers *vreg = (struct voice_registers *)&m_REG[i*16];
279177
280178      if( v->key )
281179      {
r21519r21520
288186         delta=(long)((float)frequency * pbase);
289187
290188         /* Calculate left/right channel volumes */
291         lvol=(vreg->volume_left*32)/MAX_VOICE; //32ch -> 24ch
292         rvol=(vreg->volume_right*32)/MAX_VOICE;
189         lvol=(vreg->volume_left*32)/C140_MAX_VOICE; //32ch -> 24ch
190         rvol=(vreg->volume_right*32)/C140_MAX_VOICE;
293191
294192         /* Set mixer outputs base pointers */
295         lmix = info->mixer_buffer_left;
296         rmix = info->mixer_buffer_right;
193         lmix = m_mixer_buffer_left;
194         rmix = m_mixer_buffer_right;
297195
298196         /* Retrieve sample start/end and calculate size */
299197         st=v->sample_start;
r21519r21520
301199         sz=ed-st;
302200
303201         /* Retrieve base pointer to the sample data */
304         pSampleData=(signed char*)((FPTR)info->pRom + find_sample(info, st, v->bank, i));
202         pSampleData=(signed char*)((FPTR)m_pRom + find_sample(st, v->bank, i));
305203
306204         /* Fetch back previous data pointers */
307205         offset=v->ptoffset;
r21519r21520
311209         dltdt=v->dltdt;
312210
313211         /* Switch on data type - compressed PCM is only for C140 */
314         if ((v->mode&8) && (info->banking_type != C140_TYPE_ASIC219))
212         if ((v->mode&8) && (m_banking_type != C140_TYPE_ASIC219))
315213         {
316214            //compressed PCM (maybe correct...)
317215            /* Loop for enough to fill sample buffer as requested */
r21519r21520
343241
344242                  /* decompress to 13bit range */     //2000.06.26 CAB
345243                  sdt=dt>>3;              //signed
346                  if(sdt<0)   sdt = (sdt<<(dt&7)) - info->pcmtbl[dt&7];
347                  else        sdt = (sdt<<(dt&7)) + info->pcmtbl[dt&7];
244                  if(sdt<0)   sdt = (sdt<<(dt&7)) - m_pcmtbl[dt&7];
245                  else        sdt = (sdt<<(dt&7)) + m_pcmtbl[dt&7];
348246
349247                  prevdt=lastdt;
350248                  lastdt=sdt;
r21519r21520
387285               {
388286                  prevdt=lastdt;
389287
390                  if (info->banking_type == C140_TYPE_ASIC219)
288                  if (m_banking_type == C140_TYPE_ASIC219)
391289                  {
392290                     lastdt = pSampleData[BYTE_XOR_BE(pos)];
393291
r21519r21520
426324   }
427325
428326   /* render to MAME's stream buffer */
429   lmix = info->mixer_buffer_left;
430   rmix = info->mixer_buffer_right;
327   lmix = m_mixer_buffer_left;
328   rmix = m_mixer_buffer_right;
431329   {
432330      stream_sample_t *dest1 = outputs[0];
433331      stream_sample_t *dest2 = outputs[1];
r21519r21520
439337   }
440338}
441339
442static DEVICE_START( c140 )
340
341READ8_MEMBER( c140_device::c140_r )
443342{
444   const c140_interface *intf = (const c140_interface *)device->static_config();
445   c140_state *info = get_safe_token(device);
343   offset&=0x1ff;
344   return m_REG[offset];
345}
446346
447   info->sample_rate=info->baserate=device->clock();
448347
449   info->banking_type = intf->banking_type;
348WRITE8_MEMBER( c140_device::c140_w )
349{
350   m_stream->update();
450351
451   info->stream = device->machine().sound().stream_alloc(*device,0,2,info->sample_rate,info,update_stereo);
352   offset&=0x1ff;
452353
453   info->pRom=*device->region();
454
455   /* make decompress pcm table */     //2000.06.26 CAB
354   // mirror the bank registers on the 219, fixes bkrtmaq (and probably xday2 based on notes in the HLE)
355   if ((offset >= 0x1f8) && (m_banking_type == C140_TYPE_ASIC219))
456356   {
457      int i;
458      INT32 segbase=0;
459      for(i=0;i<8;i++)
460      {
461         info->pcmtbl[i]=segbase;    //segment base value
462         segbase += 16<<i;
463      }
357      offset -= 8;
464358   }
465359
466   memset(info->REG,0,sizeof(info->REG));
360   m_REG[offset]=data;
361   if( offset<0x180 )
467362   {
468      int i;
469      for(i=0;i<MAX_VOICE;i++) init_voice( &info->voi[i] );
470   }
363      C140_VOICE *v = &m_voi[offset>>4];
471364
472   /* allocate a pair of buffers to mix into - 1 second's worth should be more than enough */
473   info->mixer_buffer_left = auto_alloc_array(device->machine(), INT16, 2 * info->sample_rate);
474   info->mixer_buffer_right = info->mixer_buffer_left + info->sample_rate;
475}
365      if( (offset&0xf)==0x5 )
366      {
367         if( data&0x80 )
368         {
369            const struct voice_registers *vreg = (struct voice_registers *) &m_REG[offset&0x1f0];
370            v->key=1;
371            v->ptoffset=0;
372            v->pos=0;
373            v->lastdt=0;
374            v->prevdt=0;
375            v->dltdt=0;
376            v->bank = vreg->bank;
377            v->mode = data;
476378
477const device_type C140 = &device_creator<c140_device>;
379            // on the 219 asic, addresses are in words
380            if (m_banking_type == C140_TYPE_ASIC219)
381            {
382               v->sample_loop = (vreg->loop_msb*256 + vreg->loop_lsb)*2;
383               v->sample_start = (vreg->start_msb*256 + vreg->start_lsb)*2;
384               v->sample_end = (vreg->end_msb*256 + vreg->end_lsb)*2;
478385
479c140_device::c140_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
480   : device_t(mconfig, C140, "C140", tag, owner, clock),
481      device_sound_interface(mconfig, *this)
482{
483   m_token = global_alloc_clear(c140_state);
386               #if 0
387               logerror("219: play v %d mode %02x start %x loop %x end %x\n",
388                  offset>>4, v->mode,
389                  find_sample(v->sample_start, v->bank, offset>>4),
390                  find_sample(v->sample_loop, v->bank, offset>>4),
391                  find_sample(v->sample_end, v->bank, offset>>4));
392               #endif
393            }
394            else
395            {
396               v->sample_loop = vreg->loop_msb*256 + vreg->loop_lsb;
397               v->sample_start = vreg->start_msb*256 + vreg->start_lsb;
398               v->sample_end = vreg->end_msb*256 + vreg->end_lsb;
399            }
400         }
401         else
402         {
403            v->key=0;
404         }
405      }
406   }
484407}
485408
486//-------------------------------------------------
487//  device_config_complete - perform any
488//  operations now that the configuration is
489//  complete
490//-------------------------------------------------
491409
492void c140_device::device_config_complete()
410void c140_device::set_base(void *base)
493411{
412   m_pRom = base;
494413}
495414
496//-------------------------------------------------
497//  device_start - device-specific startup
498//-------------------------------------------------
499415
500void c140_device::device_start()
416void c140_device::init_voice( C140_VOICE *v )
501417{
502   DEVICE_START_NAME( c140 )(this);
418   v->key=0;
419   v->ptoffset=0;
420   v->rvol=0;
421   v->lvol=0;
422   v->frequency=0;
423   v->bank=0;
424   v->mode=0;
425   v->sample_start=0;
426   v->sample_end=0;
427   v->sample_loop=0;
503428}
504429
505//-------------------------------------------------
506//  sound_stream_update - handle a stream update
507//-------------------------------------------------
508430
509void c140_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples)
431/*
432   find_sample: compute the actual address of a sample given it's
433   address and banking registers, as well as the board type.
434
435   I suspect in "real life" this works like the Sega MultiPCM where the banking
436   is done by a small PAL or GAL external to the sound chip, which can be switched
437   per-game or at least per-PCB revision as addressing range needs grow.
438 */
439long c140_device::find_sample(long adrs, long bank, int voice)
510440{
511   // should never get here
512   fatalerror("sound_stream_update called; not applicable to legacy sound devices\n");
441   long newadr = 0;
442
443   static const INT16 asic219banks[4] = { 0x1f7, 0x1f1, 0x1f3, 0x1f5 };
444
445   adrs=(bank<<16)+adrs;
446
447   switch (m_banking_type)
448   {
449      case C140_TYPE_SYSTEM2:
450         // System 2 banking
451         newadr = ((adrs&0x200000)>>2)|(adrs&0x7ffff);
452         break;
453
454      case C140_TYPE_SYSTEM21:
455         // System 21 banking.
456         // similar to System 2's.
457         newadr = ((adrs&0x300000)>>1)+(adrs&0x7ffff);
458         break;
459
460      case C140_TYPE_ASIC219:
461         // ASIC219's banking is fairly simple
462         newadr = ((m_REG[asic219banks[voice/4]]&0x3) * 0x20000) + adrs;
463         break;
464   }
465
466   return (newadr);
513467}
trunk/src/emu/sound/c140.h
r21519r21520
55#ifndef __C140_H__
66#define __C140_H__
77
8#include "devlegcy.h"
8#define C140_MAX_VOICE 24
99
10DECLARE_READ8_DEVICE_HANDLER( c140_r );
11DECLARE_WRITE8_DEVICE_HANDLER( c140_w );
12
13void c140_set_base(device_t *device, void *base);
14
1510enum
1611{
1712   C140_TYPE_SYSTEM2,
r21519r21520
1914   C140_TYPE_ASIC219
2015};
2116
22struct c140_interface {
17//**************************************************************************
18//  INTERFACE CONFIGURATION MACROS
19//**************************************************************************
20
21#define MCFG_C140_ADD(_tag, _clock) \
22   MCFG_DEVICE_ADD(_tag, C140, _clock)
23#define MCFG_C140_REPLACE(_tag, _clock) \
24   MCFG_DEVICE_REPLACE(_tag, C140, _clock)
25
26
27//**************************************************************************
28//  TYPE DEFINITIONS
29//**************************************************************************
30
31struct c140_interface
32{
2333   int banking_type;
2434};
2535
36
37struct C140_VOICE
38{
39    C140_VOICE() :
40     ptoffset(0),
41     pos(0),
42     key(0),
43     lastdt(0),
44     prevdt(0),
45     dltdt(0),
46     rvol(0),
47     lvol(0),
48     frequency(0),
49     bank(0),
50     mode(0),
51     sample_start(0),
52     sample_end(0),
53     sample_loop(0) {}
54   
55   long    ptoffset;
56   long    pos;
57   long    key;
58   //--work
59   long    lastdt;
60   long    prevdt;
61   long    dltdt;
62   //--reg
63   long    rvol;
64   long    lvol;
65   long    frequency;
66   long    bank;
67   long    mode;
68
69   long    sample_start;
70   long    sample_end;
71   long    sample_loop;
72};
73
74
75// ======================> c140_device
76
2677class c140_device : public device_t,
27                           public device_sound_interface
78               public device_sound_interface
2879{
2980public:
3081   c140_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
31   ~c140_device() { global_free(m_token); }
82   ~c140_device() { }
3283
33   // access to legacy token
34   void *token() const { assert(m_token != NULL); return m_token; }
3584protected:
3685   // device-level overrides
37   virtual void device_config_complete();
3886   virtual void device_start();
3987
4088   // sound stream update overrides
4189   virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples);
90
91public:
92    DECLARE_READ8_MEMBER( c140_r );
93    DECLARE_WRITE8_MEMBER( c140_w );
94
95public:
96    void set_base(void *base);
97
4298private:
43   // internal state
44   void *m_token;
99    void init_voice( C140_VOICE *v );
100    long find_sample(long adrs, long bank, int voice);
101
102private:
103   int m_sample_rate;
104   sound_stream *m_stream;
105   int m_banking_type;
106   /* internal buffers */
107   INT16 *m_mixer_buffer_left;
108   INT16 *m_mixer_buffer_right;
109
110   int m_baserate;
111   void *m_pRom;
112   UINT8 m_REG[0x200];
113
114   INT16 m_pcmtbl[8];        //2000.06.26 CAB
115
116   C140_VOICE m_voi[C140_MAX_VOICE];
45117};
46118
47119extern const device_type C140;
trunk/src/emu/sound/astrocde.c
r21519r21520
4343#include "astrocde.h"
4444
4545
46struct astrocade_state
47{
48   sound_stream *stream;       /* sound stream */
46// device type definition
47const device_type ASTROCADE = &device_creator<astrocade_device>;
4948
50   UINT8       reg[8];         /* 8 control registers */
5149
52   UINT8       master_count;   /* current master oscillator count */
53   UINT16      vibrato_clock;  /* current vibrato clock */
50//**************************************************************************
51//  LIVE DEVICE
52//**************************************************************************
5453
55   UINT8       noise_clock;    /* current noise generator clock */
56   UINT16      noise_state;    /* current noise LFSR state */
54//-------------------------------------------------
55//  astrocade_device - constructor
56//-------------------------------------------------
5757
58   UINT8       a_count;        /* current tone generator A count */
59   UINT8       a_state;        /* current tone generator A state */
58astrocade_device::astrocade_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
59   : device_t(mconfig, ASTROCADE, "Astrocade", tag, owner, clock),
60     device_sound_interface(mconfig, *this),
61     m_stream(NULL),
62     m_master_count(0),
63     m_vibrato_clock(0),
64     m_noise_clock(0),
65     m_noise_state(0),
66     m_a_count(0),
67     m_a_state(0),
68     m_b_count(0),
69     m_b_state(0),
70     m_c_count(0),
71     m_c_state(0)
72{
73   memset(m_reg, 0, sizeof(UINT8)*8);
74   memset(m_bitswap, 0, sizeof(UINT8)*256);
75}
6076
61   UINT8       b_count;        /* current tone generator B count */
62   UINT8       b_state;        /* current tone generator B state */
6377
64   UINT8       c_count;        /* current tone generator C count */
65   UINT8       c_state;        /* current tone generator C state */
78//-------------------------------------------------
79//  device_start - device-specific startup
80//-------------------------------------------------
6681
67   UINT8       bitswap[256];   /* bitswap table */
68};
82void astrocade_device::device_start()
83{
84   int i;
6985
86   /* generate a bitswap table for the noise */
87   for (i = 0; i < 256; i++)
88      m_bitswap[i] = BITSWAP8(i, 0,1,2,3,4,5,6,7);
7089
71INLINE astrocade_state *get_safe_token(device_t *device)
72{
73   assert(device != NULL);
74   assert(device->type() == ASTROCADE);
75   return (astrocade_state *)downcast<astrocade_device *>(device)->token();
90   /* allocate a stream for output */
91   m_stream = stream_alloc(0, 1, clock());
92
93   /* reset state */
94   device_reset();
95   state_save_register();
7696}
7797
7898
99//-------------------------------------------------
100//  sound_stream_update - handle a stream update
101//-------------------------------------------------
79102
80/*************************************
81 *
82 *  Core sound update
83 *
84 *************************************/
85
86static STREAM_UPDATE( astrocade_update )
103void astrocade_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples)
87104{
88   astrocade_state *chip = (astrocade_state *)param;
89105   stream_sample_t *dest = outputs[0];
90106   UINT16 noise_state;
91107   UINT8 master_count;
92108   UINT8 noise_clock;
93109
94110   /* load some locals */
95   master_count = chip->master_count;
96   noise_clock = chip->noise_clock;
97   noise_state = chip->noise_state;
111   master_count = m_master_count;
112   noise_clock = m_noise_clock;
113   noise_state = m_noise_state;
98114
99115   /* loop over samples */
100116   while (samples > 0)
r21519r21520
110126      samples -= samples_this_time;
111127
112128      /* sum the output of the tone generators */
113      if (chip->a_state)
114         cursample += chip->reg[6] & 0x0f;
115      if (chip->b_state)
116         cursample += chip->reg[6] >> 4;
117      if (chip->c_state)
118         cursample += chip->reg[5] & 0x0f;
129      if (m_a_state)
130         cursample += m_reg[6] & 0x0f;
131      if (m_b_state)
132         cursample += m_reg[6] >> 4;
133      if (m_c_state)
134         cursample += m_reg[5] & 0x0f;
119135
120136      /* add in the noise if it is enabled, based on the top bit of the LFSR */
121      if ((chip->reg[5] & 0x20) && (noise_state & 0x4000))
122         cursample += chip->reg[7] >> 4;
137      if ((m_reg[5] & 0x20) && (noise_state & 0x4000))
138         cursample += m_reg[7] >> 4;
123139
124140      /* scale to max and output */
125141      cursample = cursample * 32767 / 60;
r21519r21520
136152         noise_clock -= 64;
137153
138154         /* the same clock also controls the vibrato clock, which is a 13-bit counter */
139         chip->vibrato_clock++;
155         m_vibrato_clock++;
140156      }
141157
142158      /* clock the master oscillator; this is an 8-bit up counter */
r21519r21520
144160      if (master_count == 0)
145161      {
146162         /* reload based on mux value -- the value from the register is negative logic */
147         master_count = ~chip->reg[0];
163         master_count = ~m_reg[0];
148164
149165         /* mux value 0 means reload based on the vibrato control */
150         if ((chip->reg[5] & 0x10) == 0)
166         if ((m_reg[5] & 0x10) == 0)
151167         {
152168            /* vibrato speed (register 4 bits 6-7) selects one of the top 4 bits */
153169            /* of the 13-bit vibrato clock to use (0=highest freq, 3=lowest) */
154            if (!((chip->vibrato_clock >> (chip->reg[4] >> 6)) & 0x0200))
170            if (!((m_vibrato_clock >> (m_reg[4] >> 6)) & 0x0200))
155171            {
156172               /* if the bit is clear, we add the vibrato volume to the counter */
157               master_count += chip->reg[4] & 0x3f;
173               master_count += m_reg[4] & 0x3f;
158174            }
159175         }
160176
r21519r21520
163179         {
164180            /* the top 8 bits of the noise LFSR are ANDed with the noise volume */
165181            /* register and added to the count */
166            master_count += chip->bitswap[(noise_state >> 7) & 0xff] & chip->reg[7];
182            master_count += m_bitswap[(noise_state >> 7) & 0xff] & m_reg[7];
167183         }
168184
169185         /* clock tone A */
170         if (++chip->a_count == 0)
186         if (++m_a_count == 0)
171187         {
172            chip->a_state ^= 1;
173            chip->a_count = ~chip->reg[1];
188            m_a_state ^= 1;
189            m_a_count = ~m_reg[1];
174190         }
175191
176192         /* clock tone B */
177         if (++chip->b_count == 0)
193         if (++m_b_count == 0)
178194         {
179            chip->b_state ^= 1;
180            chip->b_count = ~chip->reg[2];
195            m_b_state ^= 1;
196            m_b_count = ~m_reg[2];
181197         }
182198
183199         /* clock tone C */
184         if (++chip->c_count == 0)
200         if (++m_c_count == 0)
185201         {
186            chip->c_state ^= 1;
187            chip->c_count = ~chip->reg[3];
202            m_c_state ^= 1;
203            m_c_count = ~m_reg[3];
188204         }
189205      }
190206   }
191207
192208   /* put back the locals */
193   chip->master_count = master_count;
194   chip->noise_clock = noise_clock;
195   chip->noise_state = noise_state;
209   m_master_count = master_count;
210   m_noise_clock = noise_clock;
211   m_noise_state = noise_state;
196212}
197213
198214
215//-------------------------------------------------
216//  device_reset - device-specific reset
217//-------------------------------------------------
199218
200/*************************************
201 *
202 *  Chip reset
203 *
204 *************************************/
205
206static DEVICE_RESET( astrocade )
219void astrocade_device::device_reset()
207220{
208   astrocade_state *chip = get_safe_token(device);
221   memset(m_reg, 0, sizeof(m_reg));
209222
210   memset(chip->reg, 0, sizeof(chip->reg));
223   m_master_count = 0;
224   m_vibrato_clock = 0;
211225
212   chip->master_count = 0;
213   chip->vibrato_clock = 0;
226   m_noise_clock = 0;
227   m_noise_state = 0;
214228
215   chip->noise_clock = 0;
216   chip->noise_state = 0;
229   m_a_count = 0;
230   m_a_state = 0;
217231
218   chip->a_count = 0;
219   chip->a_state = 0;
232   m_b_count = 0;
233   m_b_state = 0;
220234
221   chip->b_count = 0;
222   chip->b_state = 0;
223
224   chip->c_count = 0;
225   chip->c_state = 0;
235   m_c_count = 0;
236   m_c_state = 0;
226237}
227238
228239
229/*************************************
230 *
231 *  Save state registration
232 *
233 *************************************/
240//-------------------------------------------------
241//  Save state registration
242//-------------------------------------------------
234243
235static void astrocade_state_save_register(astrocade_state *chip, device_t *device)
244void astrocade_device::state_save_register()
236245{
237   device->save_item(NAME(chip->reg));
246   save_item(NAME(m_reg));
238247
239   device->save_item(NAME(chip->master_count));
240   device->save_item(NAME(chip->vibrato_clock));
248   save_item(NAME(m_master_count));
249   save_item(NAME(m_vibrato_clock));
241250
242   device->save_item(NAME(chip->noise_clock));
243   device->save_item(NAME(chip->noise_state));
251   save_item(NAME(m_noise_clock));
252   save_item(NAME(m_noise_state));
244253
245   device->save_item(NAME(chip->a_count));
246   device->save_item(NAME(chip->a_state));
254   save_item(NAME(m_a_count));
255   save_item(NAME(m_a_state));
247256
248   device->save_item(NAME(chip->b_count));
249   device->save_item(NAME(chip->b_state));
257   save_item(NAME(m_b_count));
258   save_item(NAME(m_b_state));
250259
251   device->save_item(NAME(chip->c_count));
252   device->save_item(NAME(chip->c_state));
260   save_item(NAME(m_c_count));
261   save_item(NAME(m_c_state));
253262}
254263
255264
256
257265/*************************************
258266 *
259 *  Chip initialization
260 *
261 *************************************/
262
263static DEVICE_START( astrocade )
264{
265   astrocade_state *chip = get_safe_token(device);
266   int i;
267
268   /* generate a bitswap table for the noise */
269   for (i = 0; i < 256; i++)
270      chip->bitswap[i] = BITSWAP8(i, 0,1,2,3,4,5,6,7);
271
272   /* allocate a stream for output */
273   chip->stream = device->machine().sound().stream_alloc(*device, 0, 1, device->clock(), chip, astrocade_update);
274
275   /* reset state */
276   DEVICE_RESET_CALL(astrocade);
277   astrocade_state_save_register(chip, device);
278}
279
280
281
282/*************************************
283 *
284267 *  Sound write accessors
285268 *
286269 *************************************/
287270
288WRITE8_DEVICE_HANDLER( astrocade_sound_w )
271WRITE8_MEMBER( astrocade_device::astrocade_sound_w )
289272{
290   astrocade_state *chip = get_safe_token(device);
291
292273   if ((offset & 8) != 0)
293274      offset = (offset >> 8) & 7;
294275   else
295276      offset &= 7;
296277
297278   /* update */
298   chip->stream->update();
279   m_stream->update();
299280
300281   /* stash the new register value */
301   chip->reg[offset & 7] = data;
282   m_reg[offset & 7] = data;
302283}
303284
304const device_type ASTROCADE = &device_creator<astrocade_device>;
305
306astrocade_device::astrocade_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
307   : device_t(mconfig, ASTROCADE, "Astrocade", tag, owner, clock),
308      device_sound_interface(mconfig, *this)
309{
310   m_token = global_alloc_clear(astrocade_state);
311}
312
313//-------------------------------------------------
314//  device_config_complete - perform any
315//  operations now that the configuration is
316//  complete
317//-------------------------------------------------
318
319void astrocade_device::device_config_complete()
320{
321}
322
323//-------------------------------------------------
324//  device_start - device-specific startup
325//-------------------------------------------------
326
327void astrocade_device::device_start()
328{
329   DEVICE_START_NAME( astrocade )(this);
330}
331
332//-------------------------------------------------
333//  device_reset - device-specific reset
334//-------------------------------------------------
335
336void astrocade_device::device_reset()
337{
338   DEVICE_RESET_NAME( astrocade )(this);
339}
340
341//-------------------------------------------------
342//  sound_stream_update - handle a stream update
343//-------------------------------------------------
344
345void astrocade_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples)
346{
347   // should never get here
348   fatalerror("sound_stream_update called; not applicable to legacy sound devices\n");
349}
trunk/src/emu/sound/astrocde.h
r21519r21520
33#ifndef __ASTROCDE_H__
44#define __ASTROCDE_H__
55
6#include "devlegcy.h"
76
8DECLARE_WRITE8_DEVICE_HANDLER( astrocade_sound_w );
7//**************************************************************************
8//  INTERFACE CONFIGURATION MACROS
9//**************************************************************************
910
11#define MCFG_ASTROCADE_ADD(_tag, _clock) \
12   MCFG_DEVICE_ADD(_tag, ASTROCADE, _clock)
13#define MCFG_ASTROCADE_REPLACE(_tag, _clock) \
14   MCFG_DEVICE_REPLACE(_tag, ASTROCADE, _clock)
15
16
17
18//**************************************************************************
19//  TYPE DEFINITIONS
20//**************************************************************************
21
22// ======================> astrocade_device
23
1024class astrocade_device : public device_t,
11                           public device_sound_interface
25                  public device_sound_interface
1226{
1327public:
1428   astrocade_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
15   ~astrocade_device() { global_free(m_token); }
29   ~astrocade_device() { }
1630
17   // access to legacy token
18   void *token() const { assert(m_token != NULL); return m_token; }
1931protected:
2032   // device-level overrides
21   virtual void device_config_complete();
2233   virtual void device_start();
2334   virtual void device_reset();
2435
2536   // sound stream update overrides
2637   virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples);
38
39public:
40    DECLARE_WRITE8_MEMBER( astrocade_sound_w );
41
2742private:
28   // internal state
29   void *m_token;
43    void state_save_register();
44
45private:
46   sound_stream *m_stream;       /* sound stream */
47
48   UINT8       m_reg[8];         /* 8 control registers */
49
50   UINT8       m_master_count;   /* current master oscillator count */
51   UINT16      m_vibrato_clock;  /* current vibrato clock */
52
53   UINT8       m_noise_clock;    /* current noise generator clock */
54   UINT16      m_noise_state;    /* current noise LFSR state */
55
56   UINT8       m_a_count;        /* current tone generator A count */
57   UINT8       m_a_state;        /* current tone generator A state */
58
59   UINT8       m_b_count;        /* current tone generator B count */
60   UINT8       m_b_state;        /* current tone generator B state */
61
62   UINT8       m_c_count;        /* current tone generator C count */
63   UINT8       m_c_state;        /* current tone generator C state */
64
65   UINT8       m_bitswap[256];   /* bitswap table */
3066};
3167
3268extern const device_type ASTROCADE;
trunk/src/emu/sound/st0016.c
r21519r21520
99#define VERBOSE (0)
1010#define LOG(x) do { if (VERBOSE) logerror x; } while (0)
1111
12struct st0016_device_state
13{
14   sound_stream * stream;
15   UINT8 **sound_ram;
16   int vpos[8], frac[8], lponce[8];
17   UINT8 regs[0x100];
18};
1912
20INLINE st0016_device_state *get_safe_token(device_t *device)
21{
22   assert(device != NULL);
23   assert(device->type() == ST0016);
24   return (st0016_device_state *)downcast<st0016_device *>(device)->token();
25}
13// device type definition
14const device_type ST0016 = &device_creator<st0016_device>;
2615
2716
28READ8_DEVICE_HANDLER( st0016_snd_r )
17//**************************************************************************
18//  LIVE DEVICE
19//**************************************************************************
20
21//-------------------------------------------------
22//  st0016_device - constructor
23//-------------------------------------------------
24
25st0016_device::st0016_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
26   : device_t(mconfig, ST0016, "ST0016", tag, owner, clock),
27     device_sound_interface(mconfig, *this),
28     m_stream(NULL),
29     m_sound_ram(NULL)
2930{
30   st0016_device_state *info = get_safe_token(device);
31   return info->regs[offset];
31   memset(m_vpos, 0, sizeof(int)*8);
32    memset(m_frac, 0, sizeof(int)*8);
33    memset(m_lponce, 0, sizeof(int)*8);
34   memset(m_regs, 0, sizeof(UINT8)*0x100);
3235}
3336
34WRITE8_DEVICE_HANDLER( st0016_snd_w )
35{
36   st0016_device_state *info = get_safe_token(device);
37   int voice = offset/32;
38   int reg = offset & 0x1f;
39   int oldreg = info->regs[offset];
40   int vbase = offset & ~0x1f;
4137
42   info->regs[offset] = data;
38//-------------------------------------------------
39//  device_start - device-specific startup
40//-------------------------------------------------
4341
44   if ((voice < 8) && (data != oldreg))
45   {
46      if ((reg == 0x16) && (data != 0))
47      {
48         info->vpos[voice] = info->frac[voice] = info->lponce[voice] = 0;
42void st0016_device::device_start()
43{
44   const st0016_interface *intf = (const st0016_interface *)static_config();
4945
50         LOG(("Key on V%02d: st %06x-%06x lp %06x-%06x frq %x flg %x\n", voice,
51            info->regs[vbase+2]<<16 | info->regs[vbase+1]<<8 | info->regs[vbase+2],
52            info->regs[vbase+0xe]<<16 | info->regs[vbase+0xd]<<8 | info->regs[vbase+0xc],
53            info->regs[vbase+6]<<16 | info->regs[vbase+5]<<8 | info->regs[vbase+4],
54            info->regs[vbase+0xa]<<16 | info->regs[vbase+0x9]<<8 | info->regs[vbase+0x8],
55            info->regs[vbase+0x11]<<8 | info->regs[vbase+0x10],
56            info->regs[vbase+0x16]));
57      }
58   }
46   m_sound_ram = intf->p_soundram;
47
48   m_stream = stream_alloc(0, 2, 44100);
5949}
6050
61static STREAM_UPDATE( st0016_update )
51
52//-------------------------------------------------
53//  sound_stream_update - handle a stream update
54//-------------------------------------------------
55
56void st0016_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples)
6257{
63   st0016_device_state *info = (st0016_device_state *)param;
64   UINT8 *sound_ram = *info->sound_ram;
58   UINT8 *sound_ram = *m_sound_ram;
6559   int v, i, snum;
6660   unsigned char *slot;
6761   INT32 mix[48000*2];
r21519r21520
7367
7468   for (v = 0; v < 8; v++)
7569   {
76      slot = (unsigned char *)&info->regs[v * 32];
70      slot = (unsigned char *)&m_regs[v * 32];
7771
7872      if (slot[0x16] & 0x06)
7973      {
r21519r21520
8781
8882         for (snum = 0; snum < samples; snum++)
8983         {
90            sample = sound_ram[(sptr + info->vpos[v])&0x1fffff]<<8;
84            sample = sound_ram[(sptr + m_vpos[v])&0x1fffff]<<8;
9185
9286            *mixp++ += (sample * (char)slot[0x14]) >> 8;
9387            *mixp++ += (sample * (char)slot[0x15]) >> 8;
9488
95            info->frac[v] += freq;
96            info->vpos[v] += (info->frac[v]>>16);
97            info->frac[v] &= 0xffff;
89            m_frac[v] += freq;
90            m_vpos[v] += (m_frac[v]>>16);
91            m_frac[v] &= 0xffff;
9892
9993            // stop if we're at the end
100            if (info->lponce[v])
94            if (m_lponce[v])
10195            {
10296               // we've looped once, check loop end rather than sample end
103               if ((info->vpos[v] + sptr) >= leptr)
97               if ((m_vpos[v] + sptr) >= leptr)
10498               {
105                  info->vpos[v] = (lsptr - sptr);
99                  m_vpos[v] = (lsptr - sptr);
106100               }
107101            }
108102            else
109103            {
110104               // not looped yet, check sample end
111               if ((info->vpos[v] + sptr) >= eptr)
105               if ((m_vpos[v] + sptr) >= eptr)
112106               {
113107                  if (slot[0x16] & 0x01)  // loop?
114108                  {
115                     info->vpos[v] = (lsptr - sptr);
116                     info->lponce[v] = 1;
109                     m_vpos[v] = (lsptr - sptr);
110                     m_lponce[v] = 1;
117111                  }
118112                  else
119113                  {
120114                     slot[0x16] = 0;
121                     info->vpos[v] = info->frac[v] = 0;
115                     m_vpos[v] = m_frac[v] = 0;
122116                  }
123117               }
124118            }
r21519r21520
134128   }
135129}
136130
137static DEVICE_START( st0016 )
138{
139   const st0016_interface *intf = (const st0016_interface *)device->static_config();
140   st0016_device_state *info = get_safe_token(device);
141131
142   info->sound_ram = intf->p_soundram;
143
144   info->stream = device->machine().sound().stream_alloc(*device, 0, 2, 44100, info, st0016_update);
145}
146
147const device_type ST0016 = &device_creator<st0016_device>;
148
149st0016_device::st0016_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
150   : device_t(mconfig, ST0016, "ST0016", tag, owner, clock),
151      device_sound_interface(mconfig, *this)
132READ8_MEMBER( st0016_device::st0016_snd_r )
152133{
153   m_token = global_alloc_clear(st0016_device_state);
134   return m_regs[offset];
154135}
155136
156//-------------------------------------------------
157//  device_config_complete - perform any
158//  operations now that the configuration is
159//  complete
160//-------------------------------------------------
161
162void st0016_device::device_config_complete()
137WRITE8_MEMBER( st0016_device::st0016_snd_w )
163138{
164}
139   int voice = offset/32;
140   int reg = offset & 0x1f;
141   int oldreg = m_regs[offset];
142   int vbase = offset & ~0x1f;
165143
166//-------------------------------------------------
167//  device_start - device-specific startup
168//-------------------------------------------------
144   m_regs[offset] = data;
169145
170void st0016_device::device_start()
171{
172   DEVICE_START_NAME( st0016 )(this);
173}
146   if ((voice < 8) && (data != oldreg))
147   {
148      if ((reg == 0x16) && (data != 0))
149      {
150         m_vpos[voice] = m_frac[voice] = m_lponce[voice] = 0;
174151
175//-------------------------------------------------
176//  sound_stream_update - handle a stream update
177//-------------------------------------------------
178
179void st0016_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples)
180{
181   // should never get here
182   fatalerror("sound_stream_update called; not applicable to legacy sound devices\n");
152         LOG(("Key on V%02d: st %06x-%06x lp %06x-%06x frq %x flg %x\n", voice,
153            m_regs[vbase+2]<<16   | m_regs[vbase+1]<<8   | m_regs[vbase+2],
154            m_regs[vbase+0xe]<<16 | m_regs[vbase+0xd]<<8 | m_regs[vbase+0xc],
155            m_regs[vbase+6]<<16   | m_regs[vbase+5]<<8   | m_regs[vbase+4],
156            m_regs[vbase+0xa]<<16 | m_regs[vbase+0x9]<<8 | m_regs[vbase+0x8],
157            m_regs[vbase+0x11]<<8 | m_regs[vbase+0x10],
158            m_regs[vbase+0x16]));
159      }
160   }
183161}
162
trunk/src/emu/sound/st0016.h
r21519r21520
33#ifndef __ST0016_H__
44#define __ST0016_H__
55
6#include "devlegcy.h"
76
7//**************************************************************************
8//  INTERFACE CONFIGURATION MACROS
9//**************************************************************************
10
11#define MCFG_ST0016_ADD(_tag, _clock) \
12   MCFG_DEVICE_ADD(_tag, ST0016, _clock)
13#define MCFG_ST0016_REPLACE(_tag, _clock) \
14   MCFG_DEVICE_REPLACE(_tag, ST0016, _clock)
15
16
17//**************************************************************************
18//  TYPE DEFINITIONS
19//**************************************************************************
20
821struct st0016_interface
922{
1023   UINT8 **p_soundram;
1124};
1225
13DECLARE_READ8_DEVICE_HANDLER( st0016_snd_r );
14DECLARE_WRITE8_DEVICE_HANDLER( st0016_snd_w );
1526
27// ======================> st0016_device
28
1629class st0016_device : public device_t,
17                           public device_sound_interface
30                 public device_sound_interface
1831{
1932public:
2033   st0016_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
21   ~st0016_device() { global_free(m_token); }
34   ~st0016_device() { }
2235
23   // access to legacy token
24   void *token() const { assert(m_token != NULL); return m_token; }
2536protected:
2637   // device-level overrides
27   virtual void device_config_complete();
2838   virtual void device_start();
2939
3040   // sound stream update overrides
3141   virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples);
42
43public:
44    DECLARE_READ8_MEMBER( st0016_snd_r );
45    DECLARE_WRITE8_MEMBER( st0016_snd_w );
46
3247private:
33   // internal state
34   void *m_token;
48   sound_stream *m_stream;
49   UINT8 **m_sound_ram;
50   int m_vpos[8];
51    int m_frac[8];
52    int m_lponce[8];
53   UINT8 m_regs[0x100];
3554};
3655
3756extern const device_type ST0016;
trunk/src/emu/sound/saa1099.c
r21519r21520
6666#include "emu.h"
6767#include "saa1099.h"
6868
69
7069#define LEFT    0x00
7170#define RIGHT   0x01
7271
73/* this structure defines a channel */
74struct saa1099_channel
75{
76   int frequency;          /* frequency (0x00..0xff) */
77   int freq_enable;        /* frequency enable */
78   int noise_enable;       /* noise enable */
79   int octave;             /* octave (0x00..0x07) */
80   int amplitude[2];       /* amplitude (0x00..0x0f) */
81   int envelope[2];        /* envelope (0x00..0x0f or 0x10 == off) */
82
83   /* vars to simulate the square wave */
84   double counter;
85   double freq;
86   int level;
87};
88
89/* this structure defines a noise channel */
90struct saa1099_noise
91{
92   /* vars to simulate the noise generator output */
93   double counter;
94   double freq;
95   int level;                      /* noise polynomal shifter */
96};
97
98/* this structure defines a SAA1099 chip */
99struct saa1099_state
100{
101   device_t *device;
102   sound_stream * stream;          /* our stream */
103   int noise_params[2];            /* noise generators parameters */
104   int env_enable[2];              /* envelope generators enable */
105   int env_reverse_right[2];       /* envelope reversed for right channel */
106   int env_mode[2];                /* envelope generators mode */
107   int env_bits[2];                /* non zero = 3 bits resolution */
108   int env_clock[2];               /* envelope clock mode (non-zero external) */
109   int env_step[2];                /* current envelope step */
110   int all_ch_enable;              /* all channels enable */
111   int sync_state;                 /* sync all channels */
112   int selected_reg;               /* selected register */
113   struct saa1099_channel channels[6];    /* channels */
114   struct saa1099_noise noise[2];  /* noise generators */
115   double sample_rate;
116};
117
11872static const int amplitude_lookup[16] = {
11973      0*32767/16,  1*32767/16,  2*32767/16,   3*32767/16,
12074      4*32767/16,  5*32767/16,  6*32767/16,   7*32767/16,
r21519r21520
166120};
167121
168122
169INLINE saa1099_state *get_safe_token(device_t *device)
123// device type definition
124const device_type SAA1099 = &device_creator<saa1099_device>;
125
126//**************************************************************************
127//  LIVE DEVICE
128//**************************************************************************
129
130//-------------------------------------------------
131//  saa1099_device - constructor
132//-------------------------------------------------
133
134saa1099_device::saa1099_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
135   : device_t(mconfig, SAA1099, "SAA1099", tag, owner, clock),
136     device_sound_interface(mconfig, *this),
137      m_stream(NULL),
138      m_all_ch_enable(0),
139      m_sync_state(0),
140      m_selected_reg(0),
141      m_sample_rate(0.0)
170142{
171   assert(device != NULL);
172   assert(device->type() == SAA1099);
173   return (saa1099_state *)downcast<saa1099_device *>(device)->token();
143    memset(m_noise_params, 0, sizeof(int)*2);
144    memset(m_env_enable, 0, sizeof(int)*2);
145    memset(m_env_reverse_right, 0, sizeof(int)*2);
146    memset(m_env_mode, 0, sizeof(int)*2);
147    memset(m_env_bits, 0, sizeof(int)*2);
148    memset(m_env_clock, 0, sizeof(int)*2);
149    memset(m_env_step, 0, sizeof(int)*2);
174150}
175151
176152
177static void saa1099_envelope(saa1099_state *saa, int ch)
153//-------------------------------------------------
154//  device_start - device-specific startup
155//-------------------------------------------------
156
157void saa1099_device::device_start()
178158{
179   if (saa->env_enable[ch])
180   {
181      int step, mode, mask;
182      mode = saa->env_mode[ch];
183      /* step from 0..63 and then loop in steps 32..63 */
184      step = saa->env_step[ch] =
185         ((saa->env_step[ch] + 1) & 0x3f) | (saa->env_step[ch] & 0x20);
159   /* copy global parameters */
160   m_sample_rate = clock() / 256;
186161
187      mask = 15;
188      if (saa->env_bits[ch])
189         mask &= ~1;     /* 3 bit resolution, mask LSB */
190
191      saa->channels[ch*3+0].envelope[ LEFT] =
192      saa->channels[ch*3+1].envelope[ LEFT] =
193      saa->channels[ch*3+2].envelope[ LEFT] = envelope[mode][step] & mask;
194      if (saa->env_reverse_right[ch] & 0x01)
195      {
196         saa->channels[ch*3+0].envelope[RIGHT] =
197         saa->channels[ch*3+1].envelope[RIGHT] =
198         saa->channels[ch*3+2].envelope[RIGHT] = (15 - envelope[mode][step]) & mask;
199      }
200      else
201      {
202         saa->channels[ch*3+0].envelope[RIGHT] =
203         saa->channels[ch*3+1].envelope[RIGHT] =
204         saa->channels[ch*3+2].envelope[RIGHT] = envelope[mode][step] & mask;
205      }
206   }
207   else
208   {
209      /* envelope mode off, set all envelope factors to 16 */
210      saa->channels[ch*3+0].envelope[ LEFT] =
211      saa->channels[ch*3+1].envelope[ LEFT] =
212      saa->channels[ch*3+2].envelope[ LEFT] =
213      saa->channels[ch*3+0].envelope[RIGHT] =
214      saa->channels[ch*3+1].envelope[RIGHT] =
215      saa->channels[ch*3+2].envelope[RIGHT] = 16;
216   }
162   /* for each chip allocate one stream */
163   m_stream = stream_alloc(0, 2, m_sample_rate);
217164}
218165
219166
220static STREAM_UPDATE( saa1099_update )
167//-------------------------------------------------
168//  sound_stream_update - handle a stream update
169//-------------------------------------------------
170
171void saa1099_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples)
221172{
222   saa1099_state *saa = (saa1099_state *)param;
223173   int j, ch;
224174
225175   /* if the channels are disabled we're done */
226   if (!saa->all_ch_enable)
176   if (!m_all_ch_enable)
227177   {
228178      /* init output data */
229179      memset(outputs[LEFT],0,samples*sizeof(*outputs[LEFT]));
r21519r21520
233183
234184   for (ch = 0; ch < 2; ch++)
235185   {
236      switch (saa->noise_params[ch])
186      switch (m_noise_params[ch])
237187      {
238      case 0: saa->noise[ch].freq = 31250.0 * 2; break;
239      case 1: saa->noise[ch].freq = 15625.0 * 2; break;
240      case 2: saa->noise[ch].freq =  7812.5 * 2; break;
241      case 3: saa->noise[ch].freq = saa->channels[ch * 3].freq; break;
188      case 0: m_noise[ch].freq = 31250.0 * 2; break;
189      case 1: m_noise[ch].freq = 15625.0 * 2; break;
190      case 2: m_noise[ch].freq =  7812.5 * 2; break;
191      case 3: m_noise[ch].freq = m_channels[ch * 3].freq; break;
242192      }
243193   }
244194
r21519r21520
250200      /* for each channel */
251201      for (ch = 0; ch < 6; ch++)
252202      {
253         if (saa->channels[ch].freq == 0.0)
254            saa->channels[ch].freq = (double)((2 * 15625) << saa->channels[ch].octave) /
255               (511.0 - (double)saa->channels[ch].frequency);
203         if (m_channels[ch].freq == 0.0)
204            m_channels[ch].freq = (double)((2 * 15625) << m_channels[ch].octave) /
205               (511.0 - (double)m_channels[ch].frequency);
256206
257207         /* check the actual position in the square wave */
258         saa->channels[ch].counter -= saa->channels[ch].freq;
259         while (saa->channels[ch].counter < 0)
208         m_channels[ch].counter -= m_channels[ch].freq;
209         while (m_channels[ch].counter < 0)
260210         {
261211            /* calculate new frequency now after the half wave is updated */
262            saa->channels[ch].freq = (double)((2 * 15625) << saa->channels[ch].octave) /
263               (511.0 - (double)saa->channels[ch].frequency);
212            m_channels[ch].freq = (double)((2 * 15625) << m_channels[ch].octave) /
213               (511.0 - (double)m_channels[ch].frequency);
264214
265            saa->channels[ch].counter += saa->sample_rate;
266            saa->channels[ch].level ^= 1;
215            m_channels[ch].counter += m_sample_rate;
216            m_channels[ch].level ^= 1;
267217
268218            /* eventually clock the envelope counters */
269            if (ch == 1 && saa->env_clock[0] == 0)
270               saa1099_envelope(saa, 0);
271            if (ch == 4 && saa->env_clock[1] == 0)
272               saa1099_envelope(saa, 1);
219            if (ch == 1 && m_env_clock[0] == 0)
220               saa1099_envelope(0);
221            if (ch == 4 && m_env_clock[1] == 0)
222               saa1099_envelope(1);
273223         }
274224
275225         /* if the noise is enabled */
276         if (saa->channels[ch].noise_enable)
226         if (m_channels[ch].noise_enable)
277227         {
278228            /* if the noise level is high (noise 0: chan 0-2, noise 1: chan 3-5) */
279            if (saa->noise[ch/3].level & 1)
229            if (m_noise[ch/3].level & 1)
280230            {
281231               /* subtract to avoid overflows, also use only half amplitude */
282               output_l -= saa->channels[ch].amplitude[ LEFT] * saa->channels[ch].envelope[ LEFT] / 16 / 2;
283               output_r -= saa->channels[ch].amplitude[RIGHT] * saa->channels[ch].envelope[RIGHT] / 16 / 2;
232               output_l -= m_channels[ch].amplitude[ LEFT] * m_channels[ch].envelope[ LEFT] / 16 / 2;
233               output_r -= m_channels[ch].amplitude[RIGHT] * m_channels[ch].envelope[RIGHT] / 16 / 2;
284234            }
285235         }
286236
287237         /* if the square wave is enabled */
288         if (saa->channels[ch].freq_enable)
238         if (m_channels[ch].freq_enable)
289239         {
290240            /* if the channel level is high */
291            if (saa->channels[ch].level & 1)
241            if (m_channels[ch].level & 1)
292242            {
293               output_l += saa->channels[ch].amplitude[ LEFT] * saa->channels[ch].envelope[ LEFT] / 16;
294               output_r += saa->channels[ch].amplitude[RIGHT] * saa->channels[ch].envelope[RIGHT] / 16;
243               output_l += m_channels[ch].amplitude[ LEFT] * m_channels[ch].envelope[ LEFT] / 16;
244               output_r += m_channels[ch].amplitude[RIGHT] * m_channels[ch].envelope[RIGHT] / 16;
295245            }
296246         }
297247      }
r21519r21520
299249      for (ch = 0; ch < 2; ch++)
300250      {
301251         /* check the actual position in noise generator */
302         saa->noise[ch].counter -= saa->noise[ch].freq;
303         while (saa->noise[ch].counter < 0)
252         m_noise[ch].counter -= m_noise[ch].freq;
253         while (m_noise[ch].counter < 0)
304254         {
305            saa->noise[ch].counter += saa->sample_rate;
306            if( ((saa->noise[ch].level & 0x4000) == 0) == ((saa->noise[ch].level & 0x0040) == 0) )
307               saa->noise[ch].level = (saa->noise[ch].level << 1) | 1;
255            m_noise[ch].counter += m_sample_rate;
256            if( ((m_noise[ch].level & 0x4000) == 0) == ((m_noise[ch].level & 0x0040) == 0) )
257               m_noise[ch].level = (m_noise[ch].level << 1) | 1;
308258            else
309               saa->noise[ch].level <<= 1;
259               m_noise[ch].level <<= 1;
310260         }
311261      }
312262      /* write sound data to the buffer */
r21519r21520
316266}
317267
318268
319
320static DEVICE_START( saa1099 )
269void saa1099_device::saa1099_envelope(int ch)
321270{
322   saa1099_state *saa = get_safe_token(device);
271   if (m_env_enable[ch])
272   {
273      int step, mode, mask;
274      mode = m_env_mode[ch];
275      /* step from 0..63 and then loop in steps 32..63 */
276      step = m_env_step[ch] =
277         ((m_env_step[ch] + 1) & 0x3f) | (m_env_step[ch] & 0x20);
323278
324   /* copy global parameters */
325   saa->device = device;
326   saa->sample_rate = device->clock() / 256;
279      mask = 15;
280      if (m_env_bits[ch])
281         mask &= ~1;     /* 3 bit resolution, mask LSB */
327282
328   /* for each chip allocate one stream */
329   saa->stream = device->machine().sound().stream_alloc(*device, 0, 2, saa->sample_rate, saa, saa1099_update);
283      m_channels[ch*3+0].envelope[ LEFT] =
284      m_channels[ch*3+1].envelope[ LEFT] =
285      m_channels[ch*3+2].envelope[ LEFT] = envelope[mode][step] & mask;
286      if (m_env_reverse_right[ch] & 0x01)
287      {
288         m_channels[ch*3+0].envelope[RIGHT] =
289         m_channels[ch*3+1].envelope[RIGHT] =
290         m_channels[ch*3+2].envelope[RIGHT] = (15 - envelope[mode][step]) & mask;
291      }
292      else
293      {
294         m_channels[ch*3+0].envelope[RIGHT] =
295         m_channels[ch*3+1].envelope[RIGHT] =
296         m_channels[ch*3+2].envelope[RIGHT] = envelope[mode][step] & mask;
297      }
298   }
299   else
300   {
301      /* envelope mode off, set all envelope factors to 16 */
302      m_channels[ch*3+0].envelope[ LEFT] =
303      m_channels[ch*3+1].envelope[ LEFT] =
304      m_channels[ch*3+2].envelope[ LEFT] =
305      m_channels[ch*3+0].envelope[RIGHT] =
306      m_channels[ch*3+1].envelope[RIGHT] =
307      m_channels[ch*3+2].envelope[RIGHT] = 16;
308   }
330309}
331310
332WRITE8_DEVICE_HANDLER( saa1099_control_w )
333{
334   saa1099_state *saa = get_safe_token(device);
335311
312WRITE8_MEMBER( saa1099_device::saa1099_control_w )
313{
336314   if ((data & 0xff) > 0x1c)
337315   {
338316      /* Error! */
339            logerror("%s: (SAA1099 '%s') Unknown register selected\n",device->machine().describe_context(), device->tag());
317      logerror("%s: (SAA1099 '%s') Unknown register selected\n", machine().describe_context(), tag());
340318   }
341319
342   saa->selected_reg = data & 0x1f;
343   if (saa->selected_reg == 0x18 || saa->selected_reg == 0x19)
320   m_selected_reg = data & 0x1f;
321   if (m_selected_reg == 0x18 || m_selected_reg == 0x19)
344322   {
345323      /* clock the envelope channels */
346      if (saa->env_clock[0])
347         saa1099_envelope(saa,0);
348      if (saa->env_clock[1])
349         saa1099_envelope(saa,1);
324      if (m_env_clock[0])
325         saa1099_envelope(0);
326      if (m_env_clock[1])
327         saa1099_envelope(1);
350328   }
351329}
352330
353331
354WRITE8_DEVICE_HANDLER( saa1099_data_w )
332WRITE8_MEMBER( saa1099_device::saa1099_data_w )
355333{
356   saa1099_state *saa = get_safe_token(device);
357   int reg = saa->selected_reg;
334   int reg = m_selected_reg;
358335   int ch;
359336
360337   /* first update the stream to this point in time */
361   saa->stream->update();
338   m_stream->update();
362339
363340   switch (reg)
364341   {
365342   /* channel i amplitude */
366343   case 0x00:  case 0x01:  case 0x02:  case 0x03:  case 0x04:  case 0x05:
367344      ch = reg & 7;
368      saa->channels[ch].amplitude[LEFT] = amplitude_lookup[data & 0x0f];
369      saa->channels[ch].amplitude[RIGHT] = amplitude_lookup[(data >> 4) & 0x0f];
345      m_channels[ch].amplitude[LEFT] = amplitude_lookup[data & 0x0f];
346      m_channels[ch].amplitude[RIGHT] = amplitude_lookup[(data >> 4) & 0x0f];
370347      break;
371348   /* channel i frequency */
372349   case 0x08:  case 0x09:  case 0x0a:  case 0x0b:  case 0x0c:  case 0x0d:
373350      ch = reg & 7;
374      saa->channels[ch].frequency = data & 0xff;
351      m_channels[ch].frequency = data & 0xff;
375352      break;
376353   /* channel i octave */
377354   case 0x10:  case 0x11:  case 0x12:
378355      ch = (reg - 0x10) << 1;
379      saa->channels[ch + 0].octave = data & 0x07;
380      saa->channels[ch + 1].octave = (data >> 4) & 0x07;
356      m_channels[ch + 0].octave = data & 0x07;
357      m_channels[ch + 1].octave = (data >> 4) & 0x07;
381358      break;
382359   /* channel i frequency enable */
383360   case 0x14:
384      saa->channels[0].freq_enable = data & 0x01;
385      saa->channels[1].freq_enable = data & 0x02;
386      saa->channels[2].freq_enable = data & 0x04;
387      saa->channels[3].freq_enable = data & 0x08;
388      saa->channels[4].freq_enable = data & 0x10;
389      saa->channels[5].freq_enable = data & 0x20;
361      m_channels[0].freq_enable = data & 0x01;
362      m_channels[1].freq_enable = data & 0x02;
363      m_channels[2].freq_enable = data & 0x04;
364      m_channels[3].freq_enable = data & 0x08;
365      m_channels[4].freq_enable = data & 0x10;
366      m_channels[5].freq_enable = data & 0x20;
390367      break;
391368   /* channel i noise enable */
392369   case 0x15:
393      saa->channels[0].noise_enable = data & 0x01;
394      saa->channels[1].noise_enable = data & 0x02;
395      saa->channels[2].noise_enable = data & 0x04;
396      saa->channels[3].noise_enable = data & 0x08;
397      saa->channels[4].noise_enable = data & 0x10;
398      saa->channels[5].noise_enable = data & 0x20;
370      m_channels[0].noise_enable = data & 0x01;
371      m_channels[1].noise_enable = data & 0x02;
372      m_channels[2].noise_enable = data & 0x04;
373      m_channels[3].noise_enable = data & 0x08;
374      m_channels[4].noise_enable = data & 0x10;
375      m_channels[5].noise_enable = data & 0x20;
399376      break;
400377   /* noise generators parameters */
401378   case 0x16:
402      saa->noise_params[0] = data & 0x03;
403      saa->noise_params[1] = (data >> 4) & 0x03;
379      m_noise_params[0] = data & 0x03;
380      m_noise_params[1] = (data >> 4) & 0x03;
404381      break;
405382   /* envelope generators parameters */
406383   case 0x18:  case 0x19:
407384      ch = reg - 0x18;
408      saa->env_reverse_right[ch] = data & 0x01;
409      saa->env_mode[ch] = (data >> 1) & 0x07;
410      saa->env_bits[ch] = data & 0x10;
411      saa->env_clock[ch] = data & 0x20;
412      saa->env_enable[ch] = data & 0x80;
385      m_env_reverse_right[ch] = data & 0x01;
386      m_env_mode[ch] = (data >> 1) & 0x07;
387      m_env_bits[ch] = data & 0x10;
388      m_env_clock[ch] = data & 0x20;
389      m_env_enable[ch] = data & 0x80;
413390      /* reset the envelope */
414      saa->env_step[ch] = 0;
391      m_env_step[ch] = 0;
415392      break;
416393   /* channels enable & reset generators */
417394   case 0x1c:
418      saa->all_ch_enable = data & 0x01;
419      saa->sync_state = data & 0x02;
395      m_all_ch_enable = data & 0x01;
396      m_sync_state = data & 0x02;
420397      if (data & 0x02)
421398      {
422399         int i;
423400
424401         /* Synch & Reset generators */
425         logerror("%s: (SAA1099 '%s') -reg 0x1c- Chip reset\n",device->machine().describe_context(), device->tag());
402         logerror("%s: (SAA1099 '%s') -reg 0x1c- Chip reset\n", machine().describe_context(), tag());
426403         for (i = 0; i < 6; i++)
427404         {
428            saa->channels[i].level = 0;
429            saa->channels[i].counter = 0.0;
405            m_channels[i].level = 0;
406            m_channels[i].counter = 0.0;
430407         }
431408      }
432409      break;
433410   default:    /* Error! */
434      logerror("%s: (SAA1099 '%s') Unknown operation (reg:%02x, data:%02x)\n",device->machine().describe_context(), device->tag(), reg, data);
411      logerror("%s: (SAA1099 '%s') Unknown operation (reg:%02x, data:%02x)\n", machine().describe_context(), tag(), reg, data);
435412   }
436413}
437
438const device_type SAA1099 = &device_creator<saa1099_device>;
439
440saa1099_device::saa1099_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
441   : device_t(mconfig, SAA1099, "SAA1099", tag, owner, clock),
442      device_sound_interface(mconfig, *this)
443{
444   m_token = global_alloc_clear(saa1099_state);
445}
446
447//-------------------------------------------------
448//  device_config_complete - perform any
449//  operations now that the configuration is
450//  complete
451//-------------------------------------------------
452
453void saa1099_device::device_config_complete()
454{
455}
456
457//-------------------------------------------------
458//  device_start - device-specific startup
459//-------------------------------------------------
460
461void saa1099_device::device_start()
462{
463   DEVICE_START_NAME( saa1099 )(this);
464}
465
466//-------------------------------------------------
467//  sound_stream_update - handle a stream update
468//-------------------------------------------------
469
470void saa1099_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples)
471{
472   // should never get here
473   fatalerror("sound_stream_update called; not applicable to legacy sound devices\n");
474}
trunk/src/emu/sound/saa1099.h
r21519r21520
1/**********************************************
2    Philips SAA1099 Sound driver
3**********************************************/
4
15#pragma once
26
37#ifndef __SAA1099_H__
r21519r21520
37#define __SAA1099_H__
48
5#include "devlegcy.h"
9//**************************************************************************
10//  INTERFACE CONFIGURATION MACROS
11//**************************************************************************
612
7/**********************************************
8    Philips SAA1099 Sound driver
9**********************************************/
13#define MCFG_SAA1099_ADD(_tag, _clock) \
14   MCFG_DEVICE_ADD(_tag, SAA1099, _clock)
15#define MCFG_SAA1099_REPLACE(_tag, _clock) \
16   MCFG_DEVICE_REPLACE(_tag, SAA1099, _clock)
1017
11DECLARE_WRITE8_DEVICE_HANDLER( saa1099_control_w );
12DECLARE_WRITE8_DEVICE_HANDLER( saa1099_data_w );
1318
19//**************************************************************************
20//  TYPE DEFINITIONS
21//**************************************************************************
22
23struct saa1099_channel
24{
25    saa1099_channel() :
26     frequency(0),
27     freq_enable(0),
28     noise_enable(0),
29     octave(0),
30     counter(0.0),
31     freq(0.0),
32     level(0)
33    {
34        memset(amplitude, 0, sizeof(int)*2);
35        memset(envelope, 0, sizeof(int)*2);
36    }
37   
38   int frequency;          /* frequency (0x00..0xff) */
39   int freq_enable;        /* frequency enable */
40   int noise_enable;       /* noise enable */
41   int octave;             /* octave (0x00..0x07) */
42   int amplitude[2];       /* amplitude (0x00..0x0f) */
43   int envelope[2];        /* envelope (0x00..0x0f or 0x10 == off) */
44
45   /* vars to simulate the square wave */
46   double counter;
47   double freq;
48   int level;
49};
50
51struct saa1099_noise
52{
53    saa1099_noise() :
54      counter(0.0),
55      freq(0.0),
56      level(0) {}
57   
58   /* vars to simulate the noise generator output */
59   double counter;
60   double freq;
61   int level;                      /* noise polynomal shifter */
62};
63
64
65// ======================> saa1099_device
66
1467class saa1099_device : public device_t,
15                           public device_sound_interface
68                  public device_sound_interface
1669{
1770public:
1871   saa1099_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
19   ~saa1099_device() { global_free(m_token); }
72   ~saa1099_device() { }
2073
21   // access to legacy token
22   void *token() const { assert(m_token != NULL); return m_token; }
2374protected:
2475   // device-level overrides
25   virtual void device_config_complete();
2676   virtual void device_start();
2777
2878   // sound stream update overrides
2979   virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples);
80
81public:
82    DECLARE_WRITE8_MEMBER( saa1099_control_w );
83    DECLARE_WRITE8_MEMBER( saa1099_data_w );
84
3085private:
31   // internal state
32   void *m_token;
86    void saa1099_envelope(int ch);
87
88private:
89    sound_stream *m_stream;          /* our stream */
90    int m_noise_params[2];            /* noise generators parameters */
91    int m_env_enable[2];              /* envelope generators enable */
92    int m_env_reverse_right[2];       /* envelope reversed for right channel */
93    int m_env_mode[2];                /* envelope generators mode */
94    int m_env_bits[2];                /* non zero = 3 bits resolution */
95    int m_env_clock[2];               /* envelope clock mode (non-zero external) */
96    int m_env_step[2];                /* current envelope step */
97    int m_all_ch_enable;              /* all channels enable */
98    int m_sync_state;                 /* sync all channels */
99    int m_selected_reg;               /* selected register */
100    saa1099_channel m_channels[6];    /* channels */
101    saa1099_noise m_noise[2];         /* noise generators */
102    double m_sample_rate;
33103};
34104
trunk/src/mess/machine/isa_gblaster.c
r21519r21520
1919*/
2020static MACHINE_CONFIG_FRAGMENT( game_blaster_config )
2121   MCFG_SPEAKER_STANDARD_MONO("mono")
22   MCFG_SOUND_ADD("saa1099.1", SAA1099, 4772720)
22   MCFG_SAA1099_ADD("saa1099.1", 4772720)
2323   MCFG_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.50)
24   MCFG_SOUND_ADD("saa1099.2", SAA1099, 4772720)
24   MCFG_SAA1099_ADD("saa1099.2", 4772720)
2525   MCFG_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.50)
2626MACHINE_CONFIG_END
2727
r21519r21520
3434{
3535   switch(offset)
3636   {
37      case 0 : saa1099_control_w( device, space, offset, data ); break;
38      case 1 : saa1099_data_w( device, space, offset, data ); break;
37      case 0 : dynamic_cast<saa1099_device*>(device)->saa1099_control_w( space, offset, data ); break;
38      case 1 : dynamic_cast<saa1099_device*>(device)->saa1099_data_w( space, offset, data ); break;
3939   }
4040}
4141
trunk/src/mess/machine/isa_sblaster.c
r21519r21520
9595   MCFG_SOUND_CONFIG(pc_ym3812_interface)
9696   MCFG_SOUND_ROUTE(ALL_OUTPUTS, "lspeaker", 3.00)
9797   MCFG_SOUND_ROUTE(ALL_OUTPUTS, "rspeaker", 3.00)
98   MCFG_SOUND_ADD("saa1099.1", SAA1099, 4772720)
98   MCFG_SAA1099_ADD("saa1099.1", 4772720)
9999   MCFG_SOUND_ROUTE(ALL_OUTPUTS, "lspeaker", 0.50)
100100   MCFG_SOUND_ROUTE(ALL_OUTPUTS, "rspeaker", 0.50)
101   MCFG_SOUND_ADD("saa1099.2", SAA1099, 4772720)
101   MCFG_SAA1099_ADD("saa1099.2", 4772720)
102102   MCFG_SOUND_ROUTE(ALL_OUTPUTS, "lspeaker", 0.50)
103103   MCFG_SOUND_ROUTE(ALL_OUTPUTS, "rspeaker", 0.50)
104104
r21519r21520
176176{
177177   switch(offset)
178178   {
179      case 0 : saa1099_control_w( device, space, offset, data ); break;
180      case 1 : saa1099_data_w( device, space, offset, data ); break;
179      case 0 : dynamic_cast<saa1099_device*>(device)->saa1099_control_w( space, offset, data ); break;
180      case 1 : dynamic_cast<saa1099_device*>(device)->saa1099_data_w( space, offset, data ); break;
181181   }
182182}
183183
trunk/src/mess/drivers/samcoupe.c
r21519r21520
314314   AM_RANGE(0x00fd, 0x00fd) AM_MIRROR(0xff00) AM_MASK(0xffff) AM_READWRITE(samcoupe_midi_r, samcoupe_midi_w)
315315   AM_RANGE(0x00fe, 0x00fe) AM_MIRROR(0xff00) AM_MASK(0xffff) AM_READWRITE(samcoupe_keyboard_r, samcoupe_border_w)
316316   AM_RANGE(0x00ff, 0x00ff) AM_MIRROR(0xff00) AM_MASK(0xffff) AM_READ(samcoupe_attributes_r)
317   AM_RANGE(0x00ff, 0x00ff) AM_MIRROR(0xfe00) AM_MASK(0xffff) AM_DEVWRITE_LEGACY("saa1099", saa1099_data_w)
318   AM_RANGE(0x01ff, 0x01ff) AM_MIRROR(0xfe00) AM_MASK(0xffff) AM_DEVWRITE_LEGACY("saa1099", saa1099_control_w)
317   AM_RANGE(0x00ff, 0x00ff) AM_MIRROR(0xfe00) AM_MASK(0xffff) AM_DEVWRITE("saa1099", saa1099_device, saa1099_data_w)
318   AM_RANGE(0x01ff, 0x01ff) AM_MIRROR(0xfe00) AM_MASK(0xffff) AM_DEVWRITE("saa1099", saa1099_device, saa1099_control_w)
319319ADDRESS_MAP_END
320320
321321
r21519r21520
551551   MCFG_SPEAKER_STANDARD_MONO("mono")
552552   MCFG_SOUND_ADD(SPEAKER_TAG, SPEAKER_SOUND, 0)
553553   MCFG_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.50)
554   MCFG_SOUND_ADD("saa1099", SAA1099, SAMCOUPE_XTAL_X1/3) /* 8 MHz */
554   MCFG_SAA1099_ADD("saa1099", SAMCOUPE_XTAL_X1/3) /* 8 MHz */
555555   MCFG_SOUND_ROUTE(ALL_OUTPUTS, "mono", 0.50)
556556
557557

Previous 199869 Revisions Next


© 1997-2024 The MAME Team