diff options
author | Andree Buschmann <AndreeBuschmann@t-online.de> | 2011-08-07 20:01:04 +0000 |
---|---|---|
committer | Andree Buschmann <AndreeBuschmann@t-online.de> | 2011-08-07 20:01:04 +0000 |
commit | acb0917556fc33681c1df5a530cf754193e67705 (patch) | |
tree | 052a47097009a210e4aed9c207bd6aa4828cc000 /apps/codecs/libgme/gbs_cpu.c | |
parent | 93c6f1329a5691a8be158cefe15641bd1daf9ef8 (diff) | |
download | rockbox-acb0917556fc33681c1df5a530cf754193e67705.tar.gz rockbox-acb0917556fc33681c1df5a530cf754193e67705.zip |
Submit initial patch from FS#12176. Adds support for several new game music formats (AY, GBS, HES, KSS, SGC, VGM and VGZ) and replaces the current NSF and NSFE with a new implementation based on a port of the Game Music Emu library 'GME'. This first submit does not cover the full functionality provided by the author's original patch: Coleco-SGV is not supported, some GME-specific m3u-support has been removed and IRAM is not used yet. Further changes are very likely to follow this submit. Thanks to Mauricio Garrido.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@30264 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/codecs/libgme/gbs_cpu.c')
-rw-r--r-- | apps/codecs/libgme/gbs_cpu.c | 120 |
1 files changed, 120 insertions, 0 deletions
diff --git a/apps/codecs/libgme/gbs_cpu.c b/apps/codecs/libgme/gbs_cpu.c new file mode 100644 index 0000000000..5a27bf6abe --- /dev/null +++ b/apps/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 | 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 | void Write_io_( struct Gbs_Emu* this, int offset, int data ) | ||
70 | { | ||
71 | Write_io_inline( this, offset, data, io_base ); | ||
72 | } | ||
73 | |||
74 | 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 | 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 | } | ||