summaryrefslogtreecommitdiffstatshomepage
path: root/src/mess/audio/vboy.h
blob: 8849ecf292ee00f82256e3a77e4449de0546ce39 (plain) (blame)
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
96
97
98
99
100
101
102
103
104
105
106
107
108
// license:BSD-3-Clause
// copyright-holders:R. Belmont
/*
    vboy.h - Virtual Boy audio emulation

    By Richard Bannister and Gil Pedersen.
    MESS device adaptation by R. Belmont
*/

#pragma once

#ifndef __VBOY_SND_H__
#define __VBOY_SND_H__

//**************************************************************************
//  CONSTANTS
//**************************************************************************

#define AUDIO_FREQ      44100
#define CHANNELS        4

//**************************************************************************
//  INTERFACE CONFIGURATION MACROS
//**************************************************************************

#define MCFG_VBOYSND_ADD(_tag) \
	MCFG_DEVICE_ADD(_tag, VBOYSND, AUDIO_FREQ)

#define MCFG_VBOYSND_REPLACE(_tag) \
	MCFG_DEVICE_REPLACE(_tag, VBOYSND, AUDIO_FREQ)

//**************************************************************************
//  TYPE DEFINITIONS
//**************************************************************************

struct s_snd_channel {
	INT8        playing;    // the sound is playing

	// state when sound was enabled
	UINT32      env_steptime;       // Envelope step time
	UINT8       env0;               // Envelope data
	UINT8       env1;               // Envelope data
	UINT8       volLeft;            // Left output volume
	UINT8       volRight;           // Right output volume
	UINT8       sample[580];        // sample to play
	int         sample_len;         // length of sample

	// values that change, as the sample is played
	int         offset;             // current offset in sample
	int         time;               // the duration that this sample is to be played
	UINT8       envelope;           // Current envelope level (604)
	int         env_time;           // The duration between envelope decay/grow (608)
};

struct s_regchan {
	INT32 sINT;
	INT32 sLRV;
	INT32 sFQL;
	INT32 sFQH;
	INT32 sEV0;
	INT32 sEV1;
	INT32 sRAM;
};

struct s_sreg {
	// Sound registers structure
	s_regchan c[4];
};

// ======================> vboysnd_device

class vboysnd_device : public device_t, public device_sound_interface
{
public:
	// construction/destruction
	vboysnd_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);

	DECLARE_READ8_MEMBER(read);
	DECLARE_WRITE8_MEMBER(write);

	sound_stream *m_stream;

protected:
	// device-level overrides
	virtual void device_start();
	virtual void device_reset();
	virtual void device_timer(emu_timer &timer, device_timer_id id, int param, void *ptr);

	virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples);

	// inline data
	s_sreg sound_registers(void);

	s_snd_channel snd_channel[5];

	UINT16 waveFreq2LenTbl[2048];
	UINT16 waveTimer2LenTbl[32];
	UINT16 waveEnv2LenTbl[8];

	emu_timer *m_timer;

	UINT8 m_aram[0x600];
};

// device type definition
extern const device_type VBOYSND;

#endif //__VBOY_SND_H__