summaryrefslogtreecommitdiff
path: root/lib/rbcodec/codecs/libgme/hes_cpu.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/rbcodec/codecs/libgme/hes_cpu.c')
-rw-r--r--lib/rbcodec/codecs/libgme/hes_cpu.c121
1 files changed, 121 insertions, 0 deletions
diff --git a/lib/rbcodec/codecs/libgme/hes_cpu.c b/lib/rbcodec/codecs/libgme/hes_cpu.c
new file mode 100644
index 0000000000..6b833b3b98
--- /dev/null
+++ b/lib/rbcodec/codecs/libgme/hes_cpu.c
@@ -0,0 +1,121 @@
1// Game_Music_Emu 0.5.2. http://www.slack.net/~ant/
2
3#include "hes_emu.h"
4
5#include "blargg_endian.h"
6
7//#include "hes_cpu_log.h"
8
9/* Copyright (C) 2003-2006 Shay Green. This module is free software; you
10can redistribute it and/or modify it under the terms of the GNU Lesser
11General Public License as published by the Free Software Foundation; either
12version 2.1 of the License, or (at your option) any later version. This
13module is distributed in the hope that it will be useful, but WITHOUT ANY
14WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
16details. You should have received a copy of the GNU Lesser General Public
17License along with this module; if not, write to the Free Software Foundation,
18Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */
19
20#include "blargg_source.h"
21#define PAGE HES_CPU_PAGE
22
23int read_mem( struct Hes_Emu* this, hes_addr_t addr )
24{
25 check( addr < 0x10000 );
26 int result = *Cpu_get_code( &this->cpu, addr );
27 if ( this->cpu.mmr [PAGE( addr )] == 0xFF )
28 result = read_mem_( this, addr );
29 return result;
30}
31
32void write_mem( struct Hes_Emu* this, hes_addr_t addr, int data )
33{
34 check( addr < 0x10000 );
35 byte* out = this->write_pages [PAGE( addr )];
36 if ( out )
37 out [addr & (page_size - 1)] = data;
38 else if ( this->cpu.mmr [PAGE( addr )] == 0xFF )
39 write_mem_( this, addr, data );
40}
41
42void set_mmr( struct Hes_Emu* this, int page, int bank )
43{
44 this->write_pages [page] = 0;
45 byte* data = Rom_at_addr( &this->rom, bank * page_size );
46 if ( bank >= 0x80 )
47 {
48 data = 0;
49 switch ( bank )
50 {
51 case 0xF8:
52 data = this->ram;
53 break;
54
55 case 0xF9:
56 case 0xFA:
57 case 0xFB:
58 data = &this->sgx [(bank - 0xF9) * page_size];
59 break;
60
61 default:
62 /* if ( bank != 0xFF )
63 dprintf( "Unmapped bank $%02X\n", bank ); */
64 data = this->rom.unmapped;
65 goto end;
66 }
67
68 this->write_pages [page] = data;
69 }
70end:
71 Cpu_set_mmr( &this->cpu, page, bank, data );
72}
73
74#define READ_FAST( addr, out ) \
75{\
76 out = READ_CODE( addr );\
77 if ( cpu->mmr [PAGE( addr )] == 0xFF )\
78 {\
79 FLUSH_TIME();\
80 out = read_mem_( this, addr );\
81 CACHE_TIME();\
82 }\
83}
84
85#define WRITE_FAST( addr, data ) \
86{\
87 int page = PAGE( addr );\
88 byte* out = this->write_pages [page];\
89 addr &= page_size - 1;\
90 if ( out )\
91 {\
92 out [addr] = data;\
93 }\
94 else if ( cpu->mmr [page] == 0xFF )\
95 {\
96 FLUSH_TIME();\
97 write_mem_( this, addr, data );\
98 CACHE_TIME();\
99 }\
100}
101
102#define READ_LOW( addr ) (this->ram [addr])
103#define WRITE_LOW( addr, data ) (this->ram [addr] = data)
104#define READ_MEM( addr ) read_mem( this, addr )
105#define WRITE_MEM( addr, data ) write_mem( this, addr, data )
106#define WRITE_VDP( addr, data ) write_vdp( this, addr, data )
107#define CPU_DONE( result_out ) { FLUSH_TIME(); result_out = cpu_done( this ); CACHE_TIME(); }
108#define SET_MMR( reg, bank ) set_mmr( this, reg, bank )
109
110#define IDLE_ADDR idle_addr
111
112#define CPU_BEGIN \
113bool run_cpu( struct Hes_Emu* this, hes_time_t end_time )\
114{\
115 struct Hes_Cpu* cpu = &this->cpu;\
116 Cpu_set_end_time( cpu, end_time );
117
118 #include "hes_cpu_run.h"
119
120 return illegal_encountered;
121}