diff options
author | Sean Bartell <wingedtachikoma@gmail.com> | 2011-06-25 21:32:25 -0400 |
---|---|---|
committer | Nils Wallménius <nils@rockbox.org> | 2012-04-25 22:13:20 +0200 |
commit | f40bfc9267b13b54e6379dfe7539447662879d24 (patch) | |
tree | 9b20069d5e62809ff434061ad730096836f916f2 /lib/rbcodec/codecs/libgme/gbs_cpu.c | |
parent | a0009907de7a0107d49040d8a180f140e2eff299 (diff) | |
download | rockbox-f40bfc9267b13b54e6379dfe7539447662879d24.tar.gz rockbox-f40bfc9267b13b54e6379dfe7539447662879d24.zip |
Add codecs to librbcodec.
Change-Id: Id7f4717d51ed02d67cb9f9cb3c0ada4a81843f97
Reviewed-on: http://gerrit.rockbox.org/137
Reviewed-by: Nils Wallménius <nils@rockbox.org>
Tested-by: Nils Wallménius <nils@rockbox.org>
Diffstat (limited to 'lib/rbcodec/codecs/libgme/gbs_cpu.c')
-rw-r--r-- | lib/rbcodec/codecs/libgme/gbs_cpu.c | 120 |
1 files changed, 120 insertions, 0 deletions
diff --git a/lib/rbcodec/codecs/libgme/gbs_cpu.c b/lib/rbcodec/codecs/libgme/gbs_cpu.c new file mode 100644 index 0000000000..1015dd5358 --- /dev/null +++ b/lib/rbcodec/codecs/libgme/gbs_cpu.c | |||
@@ -0,0 +1,120 @@ | |||
1 | // Game_Music_Emu 0.6-pre. http://www.slack.net/~ant/ | ||
2 | |||
3 | #include "gbs_emu.h" | ||
4 | #include "blargg_endian.h" | ||
5 | |||
6 | /* Copyright (C) 2003-2009 Shay Green. This module is free software; you | ||
7 | can redistribute it and/or modify it under the terms of the GNU Lesser | ||
8 | General Public License as published by the Free Software Foundation; either | ||
9 | version 2.1 of the License, or (at your option) any later version. This | ||
10 | module is distributed in the hope that it will be useful, but WITHOUT ANY | ||
11 | WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | ||
12 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more | ||
13 | details. You should have received a copy of the GNU Lesser General Public | ||
14 | License along with this module; if not, write to the Free Software Foundation, | ||
15 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ | ||
16 | |||
17 | #include "blargg_source.h" | ||
18 | |||
19 | #ifndef LOG_MEM | ||
20 | #define LOG_MEM( addr, str, data ) data | ||
21 | #endif | ||
22 | |||
23 | int read_mem( struct Gbs_Emu* this, addr_t addr ) | ||
24 | { | ||
25 | int result = *Cpu_get_code( &this->cpu, addr ); | ||
26 | if ( (unsigned) (addr - io_addr) < io_size ) | ||
27 | result = Apu_read_register( &this->apu, Time( this ), addr ); | ||
28 | |||
29 | return LOG_MEM( addr, ">", result ); | ||
30 | } | ||
31 | |||
32 | static inline void write_io_inline( struct Gbs_Emu* this, int offset, int data, int base ) | ||
33 | { | ||
34 | if ( (unsigned) (offset - (io_addr - base)) < io_size ) | ||
35 | Apu_write_register( &this->apu, Time( this ), offset + base, data & 0xFF ); | ||
36 | else if ( (unsigned) (offset - (0xFF06 - base)) < 2 ) | ||
37 | update_timer( this ); | ||
38 | else if ( offset == io_base - base ) | ||
39 | this->ram [base - ram_addr + offset] = 0; // keep joypad return value 0 | ||
40 | else | ||
41 | this->ram [base - ram_addr + offset] = 0xFF; | ||
42 | } | ||
43 | |||
44 | void write_mem( struct Gbs_Emu* this, addr_t addr, int data ) | ||
45 | { | ||
46 | (void) LOG_MEM( addr, "<", data ); | ||
47 | |||
48 | int offset = addr - ram_addr; | ||
49 | if ( (unsigned) offset < 0x10000 - ram_addr ) | ||
50 | { | ||
51 | this->ram [offset] = data; | ||
52 | |||
53 | offset -= 0xE000 - ram_addr; | ||
54 | if ( (unsigned) offset < 0x1F80 ) | ||
55 | write_io_inline( this, offset, data, 0xE000 ); | ||
56 | } | ||
57 | else if ( (unsigned) (offset - (0x2000 - ram_addr)) < 0x2000 ) | ||
58 | { | ||
59 | set_bank( this, data & 0xFF ); | ||
60 | } | ||
61 | #ifndef NDEBUG | ||
62 | else if ( unsigned (addr - 0x8000) < 0x2000 || unsigned (addr - 0xE000) < 0x1F00 ) | ||
63 | { | ||
64 | /* dprintf( "Unmapped write $%04X\n", (unsigned) addr ); */ | ||
65 | } | ||
66 | #endif | ||
67 | } | ||
68 | |||
69 | static void write_io_( struct Gbs_Emu* this, int offset, int data ) | ||
70 | { | ||
71 | write_io_inline( this, offset, data, io_base ); | ||
72 | } | ||
73 | |||
74 | static inline void write_io( struct Gbs_Emu* this, int offset, int data ) | ||
75 | { | ||
76 | (void) LOG_MEM( offset + io_base, "<", data ); | ||
77 | |||
78 | this->ram [io_base - ram_addr + offset] = data; | ||
79 | if ( (unsigned) offset < 0x80 ) | ||
80 | write_io_( this, offset, data ); | ||
81 | } | ||
82 | |||
83 | static int read_io( struct Gbs_Emu* this, int offset ) | ||
84 | { | ||
85 | int const io_base = 0xFF00; | ||
86 | int result = this->ram [io_base - ram_addr + offset]; | ||
87 | |||
88 | if ( (unsigned) (offset - (io_addr - io_base)) < io_size ) | ||
89 | { | ||
90 | result = Apu_read_register( &this->apu, Time( this ), offset + io_base ); | ||
91 | (void) LOG_MEM( offset + io_base, ">", result ); | ||
92 | } | ||
93 | else | ||
94 | { | ||
95 | check( result == read_mem( offset + io_base ) ); | ||
96 | } | ||
97 | return result; | ||
98 | } | ||
99 | |||
100 | #define READ_FAST( emu, addr, out ) \ | ||
101 | {\ | ||
102 | out = READ_CODE( addr );\ | ||
103 | if ( (unsigned) (addr - io_addr) < io_size )\ | ||
104 | out = LOG_MEM( addr, ">", Apu_read_register( &emu->apu, TIME() + emu->end_time, addr ) );\ | ||
105 | else\ | ||
106 | check( out == Read_mem( emu, addr ) );\ | ||
107 | } | ||
108 | |||
109 | #define READ_MEM( emu, addr ) read_mem( emu, addr ) | ||
110 | #define WRITE_MEM( emu, addr, data ) write_mem( emu, addr, data ) | ||
111 | |||
112 | #define WRITE_IO( emu, addr, data ) write_io( emu, addr, data ) | ||
113 | #define READ_IO( emu, addr, out ) out = read_io( emu, addr ) | ||
114 | |||
115 | #define CPU_BEGIN \ | ||
116 | void run_cpu( struct Gbs_Emu* this )\ | ||
117 | { \ | ||
118 | struct Gb_Cpu* cpu = &this->cpu; | ||
119 | #include "gb_cpu_run.h" | ||
120 | } | ||