~ubuntu-branches/ubuntu/oneiric/xmms2/oneiric

« back to all changes in this revision

Viewing changes to src/plugins/gme/gme/Gb_Cpu.h

  • Committer: Bazaar Package Importer
  • Author(s): Benjamin Drung
  • Date: 2010-03-07 04:11:24 UTC
  • mfrom: (1.1.7 upstream) (6.1.13 sid)
  • Revision ID: james.westby@ubuntu.com-20100307041124-df7p8f9yejg1u1qn
Tags: 0.7DrNo-3ubuntu1
* Merge from Debian unstable (LP: #532278), remaining changes:
  - Use PulseAudio as default output plugin.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// Nintendo Game Boy CPU emulator
2
 
// Treats every instruction as taking 4 cycles
3
 
 
4
 
// Game_Music_Emu 0.5.2
5
 
#ifndef GB_CPU_H
6
 
#define GB_CPU_H
7
 
 
8
 
#include "blargg_common.h"
9
 
#include "blargg_endian.h"
10
 
 
11
 
typedef unsigned gb_addr_t; // 16-bit CPU address
12
 
 
13
 
class Gb_Cpu {
14
 
        enum { clocks_per_instr = 4 };
15
 
public:
16
 
        typedef BOOST::uint8_t uint8_t;
17
 
        
18
 
        // Clear registers and map all pages to unmapped
19
 
        void reset( void* unmapped = 0 );
20
 
        
21
 
        // Map code memory (memory accessed via the program counter). Start and size
22
 
        // must be multiple of page_size.
23
 
        enum { page_size = 0x2000 };
24
 
        void map_code( gb_addr_t start, unsigned size, void* code );
25
 
        
26
 
        uint8_t* get_code( gb_addr_t );
27
 
        
28
 
        // Push a byte on the stack
29
 
        void push_byte( int );
30
 
        
31
 
        // Game Boy Z80 registers. *Not* kept updated during a call to run().
32
 
        struct core_regs_t {
33
 
        #if BLARGG_BIG_ENDIAN
34
 
                uint8_t b, c, d, e, h, l, flags, a;
35
 
        #else
36
 
                uint8_t c, b, e, d, l, h, a, flags;
37
 
        #endif
38
 
        };
39
 
        
40
 
        struct registers_t : core_regs_t {
41
 
                long pc; // more than 16 bits to allow overflow detection
42
 
                BOOST::uint16_t sp;
43
 
        };
44
 
        registers_t r;
45
 
        
46
 
        // Interrupt enable flag set by EI and cleared by DI
47
 
        //bool interrupts_enabled; // unused
48
 
        
49
 
        // Base address for RST vectors (normally 0)
50
 
        gb_addr_t rst_base;
51
 
        
52
 
        // If CPU executes opcode 0xFF at this address, it treats as illegal instruction
53
 
        enum { idle_addr = 0xF00D };
54
 
        
55
 
        // Run CPU for at least 'count' cycles and return false, or return true if
56
 
        // illegal instruction is encountered.
57
 
        bool run( blargg_long count );
58
 
        
59
 
        // Number of clock cycles remaining for most recent run() call
60
 
        blargg_long remain() const { return state->remain * clocks_per_instr; }
61
 
        
62
 
        // Can read this many bytes past end of a page
63
 
        enum { cpu_padding = 8 };
64
 
        
65
 
public:
66
 
        Gb_Cpu() : rst_base( 0 ) { state = &state_; }
67
 
        enum { page_shift = 13 };
68
 
        enum { page_count = 0x10000 >> page_shift };
69
 
private:
70
 
        // noncopyable
71
 
        Gb_Cpu( const Gb_Cpu& );
72
 
        Gb_Cpu& operator = ( const Gb_Cpu& );
73
 
        
74
 
        struct state_t {
75
 
                uint8_t* code_map [page_count + 1];
76
 
                blargg_long remain;
77
 
        };
78
 
        state_t* state; // points to state_ or a local copy within run()
79
 
        state_t state_;
80
 
        
81
 
        void set_code_page( int, uint8_t* );
82
 
};
83
 
 
84
 
inline BOOST::uint8_t* Gb_Cpu::get_code( gb_addr_t addr )
85
 
{
86
 
        return state->code_map [addr >> page_shift] + addr
87
 
        #if !BLARGG_NONPORTABLE
88
 
                % (unsigned) page_size
89
 
        #endif
90
 
        ;
91
 
}
92
 
 
93
 
#endif