1 // Sinclair Spectrum AY music file emulator
2 
3 // Game_Music_Emu https://bitbucket.org/mpyne/game-music-emu/
4 #ifndef AY_EMU_H
5 #define AY_EMU_H
6 
7 #include "Classic_Emu.h"
8 #include "Ay_Apu.h"
9 #include "Ay_Cpu.h"
10 
11 class Ay_Emu : private Ay_Cpu, public Classic_Emu {
12 	typedef Ay_Cpu cpu;
13 public:
14 	// AY file header
15 	enum { header_size = 0x14 };
16 	struct header_t
17 	{
18 		byte tag [8];
19 		byte vers;
20 		byte player;
21 		byte unused [2];
22 		byte author [2];
23 		byte comment [2];
24 		byte max_track;
25 		byte first_track;
26 		byte track_info [2];
27 	};
28 
static_type()29 	static gme_type_t static_type() { return gme_ay_type; }
30 public:
31 	Ay_Emu();
32 	~Ay_Emu();
33 	struct file_t {
34 		header_t const* header;
35 		byte const* end;
36 		byte const* tracks;
37 	};
38 protected:
39 	blargg_err_t track_info_( track_info_t*, int track ) const;
40 	blargg_err_t load_mem_( byte const*, long );
41 	blargg_err_t start_track_( int );
42 	blargg_err_t run_clocks( blip_time_t&, int );
43 	void set_tempo_( double );
44 	void set_voice( int, Blip_Buffer*, Blip_Buffer*, Blip_Buffer* );
45 	void update_eq( blip_eq_t const& );
46 private:
47 	file_t file;
48 
49 	cpu_time_t play_period;
50 	cpu_time_t next_play;
51 	Blip_Buffer* beeper_output;
52 	int beeper_delta;
53 	int last_beeper;
54 	int apu_addr;
55 	int cpc_latch;
56 	bool spectrum_mode;
57 	bool cpc_mode;
58 
59 	// large items
60 	struct {
61 		byte padding1 [0x100];
62 		byte ram [0x10000 + 0x100];
63 	} mem;
64 	Ay_Apu apu;
65 	friend void ay_cpu_out( Ay_Cpu*, cpu_time_t, unsigned addr, int data );
66 	void cpu_out_misc( cpu_time_t, unsigned addr, int data );
67 };
68 
69 #endif
70