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/z80_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/z80_cpu.c')
-rw-r--r-- | lib/rbcodec/codecs/libgme/z80_cpu.c | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/lib/rbcodec/codecs/libgme/z80_cpu.c b/lib/rbcodec/codecs/libgme/z80_cpu.c new file mode 100644 index 0000000000..a31236020e --- /dev/null +++ b/lib/rbcodec/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 | static 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 | } | ||