1 // license:BSD-3-Clause
2 // copyright-holders:R. Belmont
3 /*
4     vboy.h - Virtual Boy audio emulation
5 
6     By Richard Bannister and Gil Pedersen.
7     MESS device adaptation by R. Belmont
8 */
9 #ifndef MAME_AUDIO_VBOY_H
10 #define MAME_AUDIO_VBOY_H
11 
12 #pragma once
13 
14 
15 //**************************************************************************
16 //  TYPE DEFINITIONS
17 //**************************************************************************
18 
19 // ======================> vboysnd_device
20 
21 class vboysnd_device : public device_t, public device_sound_interface
22 {
23 public:
24 	// construction/destruction
25 	vboysnd_device(const machine_config &mconfig, const char *tag, device_t *owner, uint32_t clock = 5'000'000);
26 
27 	uint8_t read(offs_t offset);
28 	void write(offs_t offset, uint8_t data);
29 
30 	sound_stream *m_stream;
31 
32 protected:
33 	static constexpr unsigned CHANNELS        = 4;
34 
35 	struct s_snd_channel {
36 		int8_t        playing;    // the sound is playing
37 
38 		// state when sound was enabled
39 		uint32_t      env_steptime;       // Envelope step time
40 		uint8_t       env0;               // Envelope data
41 		uint8_t       env1;               // Envelope data
42 		uint8_t       volLeft;            // Left output volume
43 		uint8_t       volRight;           // Right output volume
44 		uint8_t       sample[580];        // sample to play
45 		int         sample_len;         // length of sample
46 
47 		// values that change, as the sample is played
48 		int         offset;             // current offset in sample
49 		int         time;               // the duration that this sample is to be played
50 		uint8_t       envelope;           // Current envelope level (604)
51 		int         env_time;           // The duration between envelope decay/grow (608)
52 	};
53 
54 	struct s_regchan {
55 		int32_t sINT;
56 		int32_t sLRV;
57 		int32_t sFQL;
58 		int32_t sFQH;
59 		int32_t sEV0;
60 		int32_t sEV1;
61 		int32_t sRAM;
62 	};
63 
64 	struct s_sreg {
65 		// Sound registers structure
66 		s_regchan c[4];
67 	};
68 
69 	// device-level overrides
70 	virtual void device_start() override;
71 	virtual void device_clock_changed() override;
72 	virtual void device_reset() override;
73 	virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr) override;
74 
75 	virtual void sound_stream_update(sound_stream &stream, std::vector<read_stream_view> const &inputs, std::vector<write_stream_view> &outputs) override;
76 
77 	s_snd_channel snd_channel[5];
78 
79 	uint16_t waveFreq2LenTbl[2048];
80 	uint16_t waveTimer2LenTbl[32];
81 	uint16_t waveEnv2LenTbl[8];
82 
83 	emu_timer *m_timer;
84 
85 	uint8_t m_aram[0x600];
86 };
87 
88 // device type definition
89 DECLARE_DEVICE_TYPE(VBOYSND, vboysnd_device)
90 
91 #endif //MAME_AUDIO_VBOY_H
92