Mercurial > audlegacy
comparison Plugins/Input/console/Spc_Emu.cpp @ 477:8fc500c08b61 trunk
[svn] SPC length detection c/o Kiyoshi Aman <kiyoshi.aman -at- gmail.com>
author | nenolod |
---|---|
date | Thu, 19 Jan 2006 19:31:32 -0800 |
parents | 252843aac42f |
children | 0b9507985f0d |
comparison
equal
deleted
inserted
replaced
476:0389b92ed03f | 477:8fc500c08b61 |
---|---|
2 // Game_Music_Emu 0.2.4. http://www.slack.net/~ant/libs/ | 2 // Game_Music_Emu 0.2.4. http://www.slack.net/~ant/libs/ |
3 | 3 |
4 #include "Spc_Emu.h" | 4 #include "Spc_Emu.h" |
5 | 5 |
6 #include <string.h> | 6 #include <string.h> |
7 #include "abstract_file.h" | |
7 | 8 |
8 /* Copyright (C) 2004-2005 Shay Green. This module is free software; you | 9 /* Copyright (C) 2004-2005 Shay Green. This module is free software; you |
9 can redistribute it and/or modify it under the terms of the GNU Lesser | 10 can redistribute it and/or modify it under the terms of the GNU Lesser |
10 General Public License as published by the Free Software Foundation; either | 11 General Public License as published by the Free Software Foundation; either |
11 version 2.1 of the License, or (at your option) any later version. This | 12 version 2.1 of the License, or (at your option) any later version. This |
15 more details. You should have received a copy of the GNU Lesser General | 16 more details. You should have received a copy of the GNU Lesser General |
16 Public License along with this module; if not, write to the Free Software | 17 Public License along with this module; if not, write to the Free Software |
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ | 18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ |
18 | 19 |
19 #include BLARGG_SOURCE_BEGIN | 20 #include BLARGG_SOURCE_BEGIN |
21 | |
22 #ifndef RAISE_ERROR | |
23 #define RAISE_ERROR( str ) return str | |
24 #endif | |
25 | |
26 typedef Spc_Reader::error_t error_t; | |
20 | 27 |
21 Spc_Emu::Spc_Emu() | 28 Spc_Emu::Spc_Emu() |
22 { | 29 { |
23 resample_ratio = 1.0; | 30 resample_ratio = 1.0; |
24 use_resampler = false; | 31 use_resampler = false; |
109 assert( remain == 0 ); | 116 assert( remain == 0 ); |
110 | 117 |
111 return blargg_success; | 118 return blargg_success; |
112 } | 119 } |
113 | 120 |
121 Spc_Reader::Spc_Reader() : file( NULL ) { | |
122 } | |
123 | |
124 Spc_Reader::~Spc_Reader() { | |
125 close(); | |
126 } | |
127 | |
128 error_t Spc_Reader::open( const char* path ) | |
129 { | |
130 file = fopen( path, "rb" ); | |
131 if ( !file ) | |
132 RAISE_ERROR( "Couldn't open file" ); | |
133 return NULL; | |
134 } | |
135 | |
136 blargg_err_t Spc_Reader::read_head(Spc_Emu::header_t *header) { | |
137 fread(&header->tag, 1,35,file); | |
138 fread(&header->format, 1, 1,file); | |
139 fread(&header->version, 1, 1,file); | |
140 fread(&header->pc, 1, 2,file); | |
141 fread(&header->a, 1, 1,file); | |
142 fread(&header->x, 1, 1,file); | |
143 fread(&header->y, 1, 1,file); | |
144 fread(&header->psw, 1, 1,file); | |
145 fread(&header->sp, 1, 1,file); | |
146 fread(&header->unused, 1, 2,file); | |
147 fread(&header->song, 1,32,file); | |
148 fread(&header->game, 1,32,file); | |
149 fread(&header->dumper, 1,16,file); | |
150 fread(&header->comment, 1,32,file); | |
151 fread(&header->date, 1,11,file); | |
152 fread(&header->len_secs,1, 3,file); | |
153 fread(&header->fade_msec,1,5,file); | |
154 fread(&header->author, 1,32,file); | |
155 fread(&header->mute_mask,1,1,file); | |
156 fread(&header->emulator,1, 1,file); | |
157 fread(&header->unused2, 1,45,file); | |
158 } | |
159 | |
160 long Spc_Reader::size() const | |
161 { | |
162 long pos = tell(); | |
163 fseek( file, 0, SEEK_END ); | |
164 long result = tell(); | |
165 fseek( file, pos, SEEK_SET ); | |
166 return result; | |
167 } | |
168 | |
169 long Spc_Reader::read_avail( void* p, long s ) { | |
170 return fread( p, 1, s, file ); | |
171 } | |
172 | |
173 long Spc_Reader::tell() const { | |
174 return ftell( file ); | |
175 } | |
176 | |
177 error_t Spc_Reader::seek( long n ) | |
178 { | |
179 if ( fseek( file, n, SEEK_SET ) != 0 ) | |
180 RAISE_ERROR( "Error seeking in file" ); | |
181 return NULL; | |
182 } | |
183 | |
184 void Spc_Reader::close() | |
185 { | |
186 if ( file ) { | |
187 fclose( file ); | |
188 file = NULL; | |
189 } | |
190 } |