
#ifndef sn76489_h
#define sn76489_h

//for debugging purposes
//#define SAMPLE_COUNTER

#define NoiseInitialState 0x8000
#define FB_SEGAVDP  0x0009
#define SRW_SEGAVDP 16

class SN76489 {
	_System* _sys;
	DSound& dsound;

	int registers[8];

	int* vol[4];
	int* freq[4];

	bool phase[4];
	int counter[4];
	u8 latched;
	int NoiseShiftRegister;
	int NoiseFreq;

	Blip_Synth<blip_high_quality, 64 * 2>* synth;

	static const int PSGVolume[16];

	Blip_Buffer buf;

	void initBlip() ;
	void add_cycles(u8 cycles);
	void runTone(u8 i);
	void runNoise(u8 i);
	void sampleCounter();
	unsigned samples_executed, samples_count;
	time_t prev_t, curr_t;

public:
	SN76489(_System* _sys, DSound& dsound);
	~SN76489() {}
	void write(u8 data);
	void power();
	void enter();

	unsigned get_samples_executed() { return samples_executed; }
};

#endif