| 282 | } |
| 283 | |
| 284 | func (apu *APU) writeControl(value byte) { |
| 285 | apu.pulse1.enabled = value&1 == 1 |
| 286 | apu.pulse2.enabled = value&2 == 2 |
| 287 | apu.triangle.enabled = value&4 == 4 |
| 288 | apu.noise.enabled = value&8 == 8 |
| 289 | apu.dmc.enabled = value&16 == 16 |
| 290 | if !apu.pulse1.enabled { |
| 291 | apu.pulse1.lengthValue = 0 |
| 292 | } |
| 293 | if !apu.pulse2.enabled { |
| 294 | apu.pulse2.lengthValue = 0 |
| 295 | } |
| 296 | if !apu.triangle.enabled { |
| 297 | apu.triangle.lengthValue = 0 |
| 298 | } |
| 299 | if !apu.noise.enabled { |
| 300 | apu.noise.lengthValue = 0 |
| 301 | } |
| 302 | if !apu.dmc.enabled { |
| 303 | apu.dmc.currentLength = 0 |
| 304 | } else { |
| 305 | if apu.dmc.currentLength == 0 { |
| 306 | apu.dmc.restart() |
| 307 | } |
| 308 | } |
| 309 | } |
| 310 | |
| 311 | func (apu *APU) writeFrameCounter(value byte) { |
| 312 | apu.framePeriod = 4 + (value>>7)&1 |