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/z80_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/z80_cpu.c')
-rw-r--r-- | apps/codecs/libgme/z80_cpu.c | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/apps/codecs/libgme/z80_cpu.c b/apps/codecs/libgme/z80_cpu.c new file mode 100644 index 0000000000..9151350067 --- /dev/null +++ b/apps/codecs/libgme/z80_cpu.c | |||
@@ -0,0 +1,85 @@ | |||
1 | // Game_Music_Emu 0.6-pre. http://www.slack.net/~ant/ | ||
2 | |||
3 | #include "z80_cpu.h" | ||
4 | |||
5 | /* Copyright (C) 2006-2008 Shay Green. This module is free software; you | ||
6 | can redistribute it and/or modify it under the terms of the GNU Lesser | ||
7 | General Public License as published by the Free Software Foundation; either | ||
8 | version 2.1 of the License, or (at your option) any later version. This | ||
9 | module is distributed in the hope that it will be useful, but WITHOUT ANY | ||
10 | WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | ||
11 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more | ||
12 | details. You should have received a copy of the GNU Lesser General Public | ||
13 | License along with this module; if not, write to the Free Software Foundation, | ||
14 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ | ||
15 | |||
16 | #include "blargg_source.h" | ||
17 | |||
18 | // flags, named with hex value for clarity | ||
19 | int const S80 = 0x80; | ||
20 | int const Z40 = 0x40; | ||
21 | int const F20 = 0x20; | ||
22 | int const H10 = 0x10; | ||
23 | int const F08 = 0x08; | ||
24 | int const V04 = 0x04; | ||
25 | int const P04 = 0x04; | ||
26 | int const N02 = 0x02; | ||
27 | int const C01 = 0x01; | ||
28 | |||
29 | void Z80_init( struct Z80_Cpu* this ) | ||
30 | { | ||
31 | this->cpu_state = &this->cpu_state_; | ||
32 | |||
33 | int i; | ||
34 | for ( i = 0x100; --i >= 0; ) | ||
35 | { | ||
36 | int p, even = 1; | ||
37 | for ( p = i; p; p >>= 1 ) | ||
38 | even ^= p; | ||
39 | int n = (i & (S80 | F20 | F08)) | ((even & 1) * P04); | ||
40 | this->szpc [i] = n; | ||
41 | this->szpc [i + 0x100] = n | C01; | ||
42 | } | ||
43 | this->szpc [0x000] |= Z40; | ||
44 | this->szpc [0x100] |= Z40; | ||
45 | } | ||
46 | |||
47 | inline void set_page( struct Z80_Cpu* this, int i, void* write, void const* read ) | ||
48 | { | ||
49 | int offset = Z80_CPU_OFFSET( i * page_size ); | ||
50 | byte * write2 = STATIC_CAST(byte *,write) - offset; | ||
51 | byte const* read2 = STATIC_CAST(byte const*,read ) - offset; | ||
52 | this->cpu_state_.write [i] = write2; | ||
53 | this->cpu_state_.read [i] = read2; | ||
54 | this->cpu_state->write [i] = write2; | ||
55 | this->cpu_state->read [i] = read2; | ||
56 | } | ||
57 | |||
58 | void Z80_reset( struct Z80_Cpu* this, void* unmapped_write, void const* unmapped_read ) | ||
59 | { | ||
60 | check( this->cpu_state == &this->cpu_state_ ); | ||
61 | this->cpu_state = &this->cpu_state_; | ||
62 | this->cpu_state_.time = 0; | ||
63 | this->cpu_state_.base = 0; | ||
64 | this->end_time_ = 0; | ||
65 | |||
66 | int i; | ||
67 | for ( i = 0; i < page_count + 1; i++ ) | ||
68 | set_page( this, i, unmapped_write, unmapped_read ); | ||
69 | |||
70 | memset( &this->r, 0, sizeof this->r ); | ||
71 | } | ||
72 | |||
73 | void Z80_map_mem( struct Z80_Cpu* this, addr_t start, int size, void* write, void const* read ) | ||
74 | { | ||
75 | // address range must begin and end on page boundaries | ||
76 | require( start % page_size == 0 ); | ||
77 | require( size % page_size == 0 ); | ||
78 | require( start + size <= 0x10000 ); | ||
79 | |||
80 | int offset; | ||
81 | for ( offset = 0; offset < size; offset += page_size ) | ||
82 | set_page( this, (start + offset) >> page_bits, | ||
83 | STATIC_CAST(char *,write) + offset, | ||
84 | STATIC_CAST(char const*,read ) + offset ); | ||
85 | } | ||