comparison src/console/Ay_Cpu.h @ 316:fb513e10174e trunk

[svn] - merge libconsole-blargg into mainline libconsole: + obsoletes plugins-ugly:sapplug
author nenolod
date Thu, 30 Nov 2006 19:54:33 -0800
parents
children 986f098da058
comparison
equal deleted inserted replaced
315:2294f3a6f136 316:fb513e10174e
1 // Z80 CPU emulator
2
3 // Game_Music_Emu 0.5.1
4 #ifndef AY_CPU_H
5 #define AY_CPU_H
6
7 #include "blargg_endian.h"
8
9 typedef blargg_long cpu_time_t;
10
11 // must be defined by caller
12 void ay_cpu_out( class Ay_Cpu*, cpu_time_t, unsigned addr, int data );
13 int ay_cpu_in( class Ay_Cpu*, unsigned addr );
14
15 class Ay_Cpu {
16 public:
17 // Clear all registers and keep pointer to 64K memory passed in
18 void reset( void* mem_64k );
19
20 // Run until specified time is reached. Returns true if suspicious/unsupported
21 // instruction was encountered at any point during run.
22 bool run( cpu_time_t end_time );
23
24 // Time of beginning of next instruction
25 cpu_time_t time() const { return state->time + state->base; }
26
27 // Alter current time. Not supported during run() call.
28 void set_time( cpu_time_t t ) { state->time = t - state->base; }
29 void adjust_time( int delta ) { state->time += delta; }
30
31 typedef BOOST::uint8_t uint8_t;
32 typedef BOOST::uint16_t uint16_t;
33
34 #if BLARGG_BIG_ENDIAN
35 struct regs_t { uint8_t b, c, d, e, h, l, flags, a; };
36 #else
37 struct regs_t { uint8_t c, b, e, d, l, h, a, flags; };
38 #endif
39 BOOST_STATIC_ASSERT( sizeof (regs_t) == 8 );
40
41 struct pairs_t { uint16_t bc, de, hl, fa; };
42
43 // Registers are not updated until run() returns
44 struct registers_t {
45 uint16_t pc;
46 uint16_t sp;
47 uint16_t ix;
48 uint16_t iy;
49 union {
50 regs_t b; // b.b, b.c, b.d, b.e, b.h, b.l, b.flags, b.a
51 pairs_t w; // w.bc, w.de, w.hl. w.fa
52 };
53 union {
54 regs_t b;
55 pairs_t w;
56 } alt;
57 uint8_t iff1;
58 uint8_t iff2;
59 uint8_t r;
60 uint8_t i;
61 uint8_t im;
62 };
63 //registers_t r; (below for efficiency)
64
65 // can read this far past end of memory
66 enum { cpu_padding = 0x100 };
67
68 public:
69 Ay_Cpu();
70 private:
71 uint8_t szpc [0x200];
72 uint8_t* mem;
73 cpu_time_t end_time_;
74 struct state_t {
75 cpu_time_t base;
76 cpu_time_t time;
77 };
78 state_t* state; // points to state_ or a local copy within run()
79 state_t state_;
80 void set_end_time( cpu_time_t t );
81 public:
82 registers_t r;
83 };
84
85 inline void Ay_Cpu::set_end_time( cpu_time_t t )
86 {
87 cpu_time_t delta = state->base - t;
88 state->base = t;
89 state->time += delta;
90 }
91
92 #endif