diff Plugins/Input/console/Spc_Cpu.h @ 90:252843aac42f trunk

[svn] Import the initial sources for console music support.
author nenolod
date Tue, 01 Nov 2005 19:57:26 -0800
parents
children 7c5e886205ef
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Plugins/Input/console/Spc_Cpu.h	Tue Nov 01 19:57:26 2005 -0800
@@ -0,0 +1,61 @@
+
+// Super Nintendo (SNES) SPC-700 CPU emulator
+
+// Game_Music_Emu 0.2.4. Copyright (C) 2004 Shay Green. GNU LGPL license.
+
+#ifndef SPC_CPU_H
+#define SPC_CPU_H
+
+#include "blargg_common.h"
+
+typedef unsigned spc_addr_t;
+typedef long spc_time_t;
+
+class Snes_Spc;
+
+class Spc_Cpu {
+	typedef BOOST::uint8_t uint8_t;
+	uint8_t* const ram;
+	spc_time_t remain_;
+	Snes_Spc& emu;
+public:
+	// Keeps pointer to ram and spc
+	Spc_Cpu( uint8_t ram [0x10000], Snes_Spc* spc );
+	
+	// SPC-700 registers. *Not* kept updated during a call to run().
+	struct registers_t {
+		unsigned short pc;
+		uint8_t a;
+		uint8_t x;
+		uint8_t y;
+		uint8_t status;
+		uint8_t sp;
+	} r;
+	
+	// Run CPU for at least 'count' cycles. Return the number of cycles remaining
+	// when emulation stopped (negative if extra cycles were emulated). Emulation
+	// stops when there are no more remaining cycles or an unhandled instruction
+	// is encountered (STOP, SLEEP, and any others not yet implemented). In the
+	// latter case, the return value is greater than zero.
+	spc_time_t run( spc_time_t count );
+	
+	// Number of clock cycles remaining for current run() call
+	spc_time_t remain() const;
+	
+	// Access memory as the emulated CPU does
+	int  read ( spc_addr_t );
+	void write( spc_addr_t, int );
+	
+private:
+	// noncopyable
+	Spc_Cpu( const Spc_Cpu& );
+	Spc_Cpu& operator = ( const Spc_Cpu& );
+	unsigned mem_bit( spc_addr_t );
+};
+
+inline spc_time_t Spc_Cpu::remain() const {
+	return remain_;
+}
+
+#endif
+