~ubuntu-branches/debian/sid/mame/sid

« back to all changes in this revision

Viewing changes to mess/src/emu/audio/generic.c

  • Committer: Package Import Robot
  • Author(s): Jordi Mallach, Jordi Mallach, Emmanuel Kasper
  • Date: 2011-12-19 22:56:27 UTC
  • mfrom: (0.1.2)
  • Revision ID: package-import@ubuntu.com-20111219225627-ub5oga1oys4ogqzm
Tags: 0.144-1
[ Jordi Mallach ]
* Fix syntax errors in DEP5 copyright file (lintian).
* Use a versioned copyright Format specification field.
* Update Vcs-* URLs.
* Move transitional packages to the new metapackages section, and make
  them priority extra.
* Remove references to GNU/Linux and MESS sources from copyright.
* Add build variables for s390x.
* Use .xz tarballs as it cuts 4MB for the upstream sources.
* Add nplayers.ini as a patch. Update copyright file to add CC-BY-SA-3.0.

[ Emmanuel Kasper ]
* New upstream release. Closes: #651538.
* Add Free Desktop compliant png icons of various sizes taken from
  the hydroxygen iconset
* Mess is now built from a new source package, to avoid possible source
  incompatibilities between mame and the mess overlay.
* Mame-tools are not built from the mame source package anymore, but
  from the mess source package

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/***************************************************************************
2
 
 
3
 
    generic.c
4
 
 
5
 
    Generic simple sound functions.
6
 
 
7
 
    Copyright Nicola Salmoria and the MAME Team.
8
 
    Visit http://mamedev.org for licensing and usage restrictions.
9
 
 
10
 
***************************************************************************/
11
 
 
12
 
#include "emu.h"
13
 
 
14
 
 
15
 
 
16
 
/***************************************************************************
17
 
    TYPE DEFINITIONS
18
 
***************************************************************************/
19
 
 
20
 
struct _generic_audio_private
21
 
{
22
 
        UINT16          latch_clear_value;
23
 
        UINT16          latched_value[4];
24
 
        UINT8           latch_read[4];
25
 
};
26
 
 
27
 
 
28
 
 
29
 
/***************************************************************************
30
 
    INITIALIZATION
31
 
***************************************************************************/
32
 
 
33
 
/*-------------------------------------------------
34
 
    generic_sound_init - initialize globals and
35
 
    register for save states
36
 
-------------------------------------------------*/
37
 
 
38
 
int generic_sound_init(running_machine &machine)
39
 
{
40
 
        generic_audio_private *state;
41
 
 
42
 
        state = machine.generic_audio_data = auto_alloc_clear(machine, generic_audio_private);
43
 
 
44
 
        /* register globals with the save state system */
45
 
        state_save_register_global_array(machine, state->latched_value);
46
 
        state_save_register_global_array(machine, state->latch_read);
47
 
 
48
 
        return 0;
49
 
}
50
 
 
51
 
 
52
 
 
53
 
/***************************************************************************
54
 
 
55
 
    Many games use a master-slave CPU setup. Typically, the main CPU writes
56
 
    a command to some register, and then writes to another register to trigger
57
 
    an interrupt on the slave CPU (the interrupt might also be triggered by
58
 
    the first write). The slave CPU, notified by the interrupt, goes and reads
59
 
    the command.
60
 
 
61
 
***************************************************************************/
62
 
 
63
 
/*-------------------------------------------------
64
 
    latch_callback - time-delayed callback to
65
 
    set a latch value
66
 
-------------------------------------------------*/
67
 
 
68
 
static TIMER_CALLBACK( latch_callback )
69
 
{
70
 
        generic_audio_private *state = machine.generic_audio_data;
71
 
        UINT16 value = param >> 8;
72
 
        int which = param & 0xff;
73
 
 
74
 
        /* if the latch hasn't been read and the value is changed, log a warning */
75
 
        if (!state->latch_read[which] && state->latched_value[which] != value)
76
 
                logerror("Warning: sound latch %d written before being read. Previous: %02x, new: %02x\n", which, state->latched_value[which], value);
77
 
 
78
 
        /* store the new value and mark it not read */
79
 
        state->latched_value[which] = value;
80
 
        state->latch_read[which] = 0;
81
 
}
82
 
 
83
 
 
84
 
/*-------------------------------------------------
85
 
    latch_w - handle a write to a given latch
86
 
-------------------------------------------------*/
87
 
 
88
 
INLINE void latch_w(address_space *space, int which, UINT16 value)
89
 
{
90
 
        space->machine().scheduler().synchronize(FUNC(latch_callback), which | (value << 8));
91
 
}
92
 
 
93
 
 
94
 
/*-------------------------------------------------
95
 
    latch_r - handle a read from a given latch
96
 
-------------------------------------------------*/
97
 
 
98
 
INLINE UINT16 latch_r(address_space *space, int which)
99
 
{
100
 
        generic_audio_private *state = space->machine().generic_audio_data;
101
 
        state->latch_read[which] = 1;
102
 
        return state->latched_value[which];
103
 
}
104
 
 
105
 
 
106
 
/*-------------------------------------------------
107
 
    latch_clear - clear a given latch
108
 
-------------------------------------------------*/
109
 
 
110
 
INLINE void latch_clear(address_space *space, int which)
111
 
{
112
 
        generic_audio_private *state = space->machine().generic_audio_data;
113
 
        state->latched_value[which] = state->latch_clear_value;
114
 
}
115
 
 
116
 
 
117
 
/*-------------------------------------------------
118
 
    soundlatch_w - global write handlers for
119
 
    writing to sound latches
120
 
-------------------------------------------------*/
121
 
 
122
 
WRITE8_HANDLER( soundlatch_w )        { latch_w(space, 0, data); }
123
 
WRITE16_HANDLER( soundlatch_word_w )  { latch_w(space, 0, data); }
124
 
WRITE8_HANDLER( soundlatch2_w )       { latch_w(space, 1, data); }
125
 
WRITE16_HANDLER( soundlatch2_word_w ) { latch_w(space, 1, data); }
126
 
WRITE8_HANDLER( soundlatch3_w )       { latch_w(space, 2, data); }
127
 
WRITE16_HANDLER( soundlatch3_word_w ) { latch_w(space, 2, data); }
128
 
WRITE8_HANDLER( soundlatch4_w )       { latch_w(space, 3, data); }
129
 
WRITE16_HANDLER( soundlatch4_word_w ) { latch_w(space, 3, data); }
130
 
 
131
 
 
132
 
/*-------------------------------------------------
133
 
    soundlatch_r - global read handlers for
134
 
    reading from sound latches
135
 
-------------------------------------------------*/
136
 
 
137
 
READ8_HANDLER( soundlatch_r )         { return latch_r(space, 0); }
138
 
READ16_HANDLER( soundlatch_word_r )   { return latch_r(space, 0); }
139
 
READ8_HANDLER( soundlatch2_r )        { return latch_r(space, 1); }
140
 
READ16_HANDLER( soundlatch2_word_r )  { return latch_r(space, 1); }
141
 
READ8_HANDLER( soundlatch3_r )        { return latch_r(space, 2); }
142
 
READ16_HANDLER( soundlatch3_word_r )  { return latch_r(space, 2); }
143
 
READ8_HANDLER( soundlatch4_r )        { return latch_r(space, 3); }
144
 
READ16_HANDLER( soundlatch4_word_r )  { return latch_r(space, 3); }
145
 
 
146
 
 
147
 
/*-------------------------------------------------
148
 
    soundlatch_clear_w - global write handlers
149
 
    for clearing sound latches
150
 
-------------------------------------------------*/
151
 
 
152
 
WRITE8_HANDLER( soundlatch_clear_w )  { latch_clear(space, 0); }
153
 
WRITE8_HANDLER( soundlatch2_clear_w ) { latch_clear(space, 1); }
154
 
WRITE8_HANDLER( soundlatch3_clear_w ) { latch_clear(space, 2); }
155
 
WRITE8_HANDLER( soundlatch4_clear_w ) { latch_clear(space, 3); }
156
 
 
157
 
 
158
 
/*-------------------------------------------------
159
 
    soundlatch_setclearedvalue - set the "clear"
160
 
    value for all sound latches
161
 
-------------------------------------------------*/
162
 
 
163
 
void soundlatch_setclearedvalue(running_machine &machine, int value)
164
 
{
165
 
        generic_audio_private *state = machine.generic_audio_data;
166
 
        assert_always(machine.phase() == MACHINE_PHASE_INIT, "Can only call soundlatch_setclearedvalue at init time!");
167
 
        state->latch_clear_value = value;
168
 
}