Debian Codegraph @

thirdparty/ymfm/src/ymfm_misc.cpp

raw
1 // BSD 3-Clause License
2 //
3 // Copyright (c) 2021, Aaron Giles
4 // All rights reserved.
5 //
6 // Redistribution and use in source and binary forms, with or without
7 // modification, are permitted provided that the following conditions are met:
8 //
9 // 1. Redistributions of source code must retain the above copyright notice, this
10 // list of conditions and the following disclaimer.
11 //
12 // 2. Redistributions in binary form must reproduce the above copyright notice,
13 // this list of conditions and the following disclaimer in the documentation
14 // and/or other materials provided with the distribution.
15 //
16 // 3. Neither the name of the copyright holder nor the names of its
17 // contributors may be used to endorse or promote products derived from
18 // this software without specific prior written permission.
19 //
20 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23 // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24 // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26 // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27 // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28 // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
31 #include "ymfm_misc.h"
32
33 namespace ymfm
34 {
35
36 //*********************************************************
37 // YM2149
38 //*********************************************************
39
40 //-------------------------------------------------
41 // ym2149 - constructor
42 //-------------------------------------------------
43
44 ym2149::ym2149(ymfm_interface &intf) :
45 m_address(0),
46 m_ssg(intf)
47 {
48 }
49
50
51 //-------------------------------------------------
52 // reset - reset the system
53 //-------------------------------------------------
54
55 void ym2149::reset()
56 {
57 // reset the engines
58 m_ssg.reset();
59 }
60
61
62 //-------------------------------------------------
63 // save_restore - save or restore the data
64 //-------------------------------------------------
65
66 void ym2149::save_restore(ymfm_saved_state &state)
67 {
68 state.save_restore(m_address);
69 m_ssg.save_restore(state);
70 }
71
72
73 //-------------------------------------------------
74 // read_data - read the data register
75 //-------------------------------------------------
76
77 uint8_t ym2149::read_data()
78 {
79 return m_ssg.read(m_address & 0x0f);
80 }
81
82
83 //-------------------------------------------------
84 // read - handle a read from the device
85 //-------------------------------------------------
86
87 uint8_t ym2149::read(uint32_t offset)
88 {
89 uint8_t result = 0xff;
90 switch (offset & 3) // BC2,BC1
91 {
92 case 0: // inactive
93 break;
94
95 case 1: // address
96 break;
97
98 case 2: // inactive
99 break;
100
101 case 3: // read
102 result = read_data();
103 break;
104 }
105 return result;
106 }
107
108
109 //-------------------------------------------------
110 // write_address - handle a write to the address
111 // register
112 //-------------------------------------------------
113
114 void ym2149::write_address(uint8_t data)
115 {
116 // just set the address
117 m_address = data;
118 }
119
120
121 //-------------------------------------------------
122 // write - handle a write to the register
123 // interface
124 //-------------------------------------------------
125
126 void ym2149::write_data(uint8_t data)
127 {
128 m_ssg.write(m_address & 0x0f, data);
129 }
130
131
132 //-------------------------------------------------
133 // write - handle a write to the register
134 // interface
135 //-------------------------------------------------
136
137 void ym2149::write(uint32_t offset, uint8_t data)
138 {
139 switch (offset & 3) // BC2,BC1
140 {
141 case 0: // address
142 write_address(data);
143 break;
144
145 case 1: // inactive
146 break;
147
148 case 2: // write
149 write_data(data);
150 break;
151
152 case 3: // address
153 write_address(data);
154 break;
155 }
156 }
157
158
159 //-------------------------------------------------
160 // generate - generate samples of SSG sound
161 //-------------------------------------------------
162
163 void ym2149::generate(output_data *output, uint32_t numsamples)
164 {
165 for (uint32_t samp = 0; samp < numsamples; samp++, output++)
166 {
167 // clock the SSG
168 m_ssg.clock();
169
170 // YM2149 keeps the three SSG outputs independent
171 m_ssg.output(*output);
172 }
173 }
174
175 }