-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAudioHardware.cs
95 lines (84 loc) · 2.64 KB
/
AudioHardware.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
using System;
using System.Collections.Generic;
using System.Text;
namespace Chroma_Invaders
{
public class AudioHardware
{
private byte AudioPort3 = 0;
private byte AudioPort5 = 0;
public AudioHardware() {
}
public void HandleInput(byte input, byte port)
{
switch(port)
{
case 3:
AudioPort3 = input;
break;
case 5:
AudioPort5 = input;
break;
}
PlaySounds();
}
private void PlaySounds()
{
// UFO Sound
if (IsSet(AudioPort3, 0)) Emulator.Sounds[7].Play();
else Emulator.Sounds[7].Stop();
// Shot Sound
if (IsSet(AudioPort3, 1))
{
Unset(ref AudioPort3, 1);
Emulator.Sounds[6].PlayOneShot();
}
// Player Hit Sound
if (IsSet(AudioPort3, 2) && Emulator.Sounds[0].Status != Chroma.Audio.PlaybackStatus.Playing)
{
Emulator.HandleControllerVibrate(Emulator.Machine.Memory[0x2067] == 0x21 ? 1 : 2, 500);
Unset(ref AudioPort3, 2);
Emulator.Sounds[0].Play();
}
// Invader Hit Sound
if (IsSet(AudioPort3, 3) && Emulator.Sounds[5].Status != Chroma.Audio.PlaybackStatus.Playing)
{
Unset(ref AudioPort3, 3);
Emulator.Sounds[5].Play();
}
// Invader Walk Sounds
if (IsSet(AudioPort5, 0))
{
Unset(ref AudioPort5, 0);
Emulator.Sounds[1].PlayOneShot();
}
if (IsSet(AudioPort5, 1))
{
Unset(ref AudioPort5, 1);
Emulator.Sounds[2].PlayOneShot();
}
if (IsSet(AudioPort5, 2))
{
Unset(ref AudioPort5, 2);
Emulator.Sounds[3].PlayOneShot();
}
if (IsSet(AudioPort5, 3))
{
Unset(ref AudioPort5, 3);
Emulator.Sounds[4].PlayOneShot();
}
if (IsSet(AudioPort5, 4) && Emulator.Sounds[8].Status != Chroma.Audio.PlaybackStatus.Playing)
{
Unset(ref AudioPort5, 4);
Emulator.Sounds[8].PlayOneShot();
}
}
private bool IsSet(byte input, byte bit) {
return (input & (1 << bit)) > 0;
}
private void Unset(ref byte input, byte bit)
{
input &= (byte)(~(1 << bit));
}
}
}