update libgme
This commit is contained in:
1 parent
9dcdc9500d
commit
303d87f69d
116 files changed
+10531
-3087
No files matched your search
+36
-24
@@ -4,7 +4,7 @@ project(libgme)
|
||||
include (CheckCXXCompilerFlag)
|
||||
|
||||
# When version is changed, also change the one in gme/gme.h to match
|
||||
set(GME_VERSION 0.6.2 CACHE INTERNAL "libgme Version")
|
||||
set(GME_VERSION 0.6.3 CACHE INTERNAL "libgme Version")
|
||||
|
||||
# 2.6+ always assumes FATAL_ERROR, but 2.4 and below don't.
|
||||
# Of course, 2.4 might work, in which case you're welcome to drop
|
||||
@@ -48,10 +48,18 @@ if (NOT DEFINED USE_GME_SPC)
|
||||
SET(USE_GME_SPC 1 CACHE BOOL "Enable SNES SPC music emulation")
|
||||
endif()
|
||||
|
||||
if (NOT DEFINED GME_SPC_ISOLATED_ECHO_BUFFER)
|
||||
option(GME_SPC_ISOLATED_ECHO_BUFFER "Enable isolated echo buffer on SPC emulator to allow correct playing of \"dodgy\" SPC files made for various ROM hacks ran on ZSNES" OFF)
|
||||
endif()
|
||||
|
||||
if (NOT DEFINED USE_GME_VGM)
|
||||
SET(USE_GME_VGM 1 CACHE BOOL "Enable Sega VGM/VGZ music emulation")
|
||||
endif()
|
||||
|
||||
if (NOT DEFINED GME_YM2612_EMU)
|
||||
SET(GME_YM2612_EMU "Nuked" CACHE STRING "Which YM2612 emulator to use: \"Nuked\" (LGPLv2.1+), \"MAME\" (GPLv2+), or \"GENS\" (LGPLv2.1+)")
|
||||
endif()
|
||||
|
||||
if (USE_GME_NSFE AND NOT USE_GME_NSF)
|
||||
MESSAGE(" -- NSFE support requires NSF, enabling NSF support. --")
|
||||
SET(USE_GME_NSF 1 CACHE BOOL "Enable NES NSF music emulation" FORCE)
|
||||
@@ -59,32 +67,36 @@ endif()
|
||||
|
||||
option(BUILD_SHARED_LIBS "Build shared library (set to OFF for static library)" ON)
|
||||
|
||||
# Check for GCC "visibility" support.
|
||||
if (CMAKE_COMPILER_IS_GNUCXX)
|
||||
check_cxx_compiler_flag (-fvisibility=hidden __LIBGME_TEST_VISIBILITY)
|
||||
set (ENABLE_VISIBILITY OFF)
|
||||
if (__LIBGME_TEST_VISIBILITY)
|
||||
# get the gcc version
|
||||
exec_program(${CMAKE_CXX_COMPILER} ARGS --version OUTPUT_VARIABLE _gcc_version_info)
|
||||
string (REGEX MATCH "[3-9]\\.[0-9]\\.[0-9]" _gcc_version "${_gcc_version_info}")
|
||||
option(ENABLE_UBSAN "Enable Undefined Behavior Sanitizer error-checking" ON)
|
||||
|
||||
# gcc <4.1 had poor support for symbol visibility
|
||||
if ((${_gcc_version} VERSION_GREATER "4.1") OR (${_gcc_version} VERSION_EQUAL "4.1"))
|
||||
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden")
|
||||
set (ENABLE_VISIBILITY ON)
|
||||
add_definitions (-DLIBGME_VISIBILITY)
|
||||
option(BUILD_FRAMEWORK "Build framework instead of dylib (on macOS)" OFF)
|
||||
|
||||
# GCC >= 4.2 also correctly supports making inline members have hidden
|
||||
# visibility by default.
|
||||
if ((${_gcc_version} VERSION_GREATER "4.2") OR (${_gcc_version} VERSION_EQUAL "4.2"))
|
||||
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility-inlines-hidden")
|
||||
endif()
|
||||
endif()
|
||||
endif() # test visibility
|
||||
# Check for GCC/Clang "visibility" support.
|
||||
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU"
|
||||
OR
|
||||
CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
|
||||
|
||||
# Cache this result
|
||||
set( LIBGME_HAVE_GCC_VISIBILITY ${ENABLE_VISIBILITY} CACHE BOOL "GCC support for hidden visibility")
|
||||
endif (CMAKE_COMPILER_IS_GNUCXX)
|
||||
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -W -Wextra")
|
||||
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
|
||||
|
||||
# Assume we have visibility support on any compiler that supports C++11
|
||||
add_definitions (-DLIBGME_VISIBILITY)
|
||||
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden -fvisibility-inlines-hidden")
|
||||
|
||||
# Try to protect against undefined behavior from signed integer overflow
|
||||
# This has caused miscompilation of code already and there are other
|
||||
# potential uses; see https://bitbucket.org/mpyne/game-music-emu/issues/18/
|
||||
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fwrapv")
|
||||
|
||||
if (ENABLE_UBSAN)
|
||||
# GCC needs -static-libubsan
|
||||
if (NOT BUILD_SHARED_LIBS AND CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
|
||||
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=undefined -static-libubsan")
|
||||
else()
|
||||
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=undefined")
|
||||
endif()
|
||||
endif()
|
||||
endif ()
|
||||
|
||||
# Shared library defined here
|
||||
add_subdirectory(gme)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
Game_Music_Emu Change Log
|
||||
-------------------------
|
||||
|
||||
Please see the git version history (e.g. git shortlog tags/0.6.0..tags/0.6.1)
|
||||
for the accurate change log.
|
||||
Game_Music_Emu Change Log
|
||||
-------------------------
|
||||
|
||||
Please see the git version history (e.g. git shortlog tags/0.6.0..tags/0.6.1)
|
||||
for the accurate change log.
|
||||
@@ -15,3 +15,14 @@ add_custom_command(TARGET demo
|
||||
VERBATIM) # VERBATIM is essentially required, "please use correct command line kthx"
|
||||
|
||||
target_link_libraries(demo gme)
|
||||
|
||||
|
||||
add_executable(demo_mem Wave_Writer.cpp basics_mem.c)
|
||||
|
||||
add_custom_command(TARGET demo_mem
|
||||
POST_BUILD
|
||||
COMMAND cmake -E copy "${CMAKE_SOURCE_DIR}/test.vgz" ${CMAKE_CURRENT_BINARY_DIR}
|
||||
COMMENT "Add convenience copy of test.nsf file for demo application"
|
||||
VERBATIM) # VERBATIM is essentially required, "please use correct command line kthx"
|
||||
|
||||
target_link_libraries(demo_mem gme)
|
||||
@@ -1,8 +1,9 @@
|
||||
// Game_Music_Emu 0.6.0. http://www.slack.net/~ant/
|
||||
// Game_Music_Emu https://bitbucket.org/mpyne/game-music-emu/
|
||||
|
||||
#include "Wave_Writer.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
/* Copyright (C) 2003-2006 by Shay Green. Permission is hereby granted, free
|
||||
@@ -119,28 +120,29 @@ void Wave_Writer::close()
|
||||
flush();
|
||||
|
||||
// generate header
|
||||
long ds = sample_count_ * sizeof (sample_t);
|
||||
long rs = header_size - 8 + ds;
|
||||
int frame_size = chan_count * sizeof (sample_t);
|
||||
long bps = rate * frame_size;
|
||||
uint32_t ds = sample_count_ * sizeof (sample_t);
|
||||
uint32_t rs = header_size - 8 + ds;
|
||||
uint32_t frame_size = chan_count * sizeof (sample_t);
|
||||
uint32_t bps = rate * frame_size;
|
||||
|
||||
#define LE32(x) (unsigned char)(x), (unsigned char)((x)>>8), \
|
||||
(unsigned char)((x)>>16), (unsigned char)((x)>>24)
|
||||
|
||||
unsigned char header [header_size] =
|
||||
{
|
||||
'R','I','F','F',
|
||||
rs,rs>>8, // length of rest of file
|
||||
rs>>16,rs>>24,
|
||||
LE32(rs), // length of rest of file
|
||||
'W','A','V','E',
|
||||
'f','m','t',' ',
|
||||
0x10,0,0,0, // size of fmt chunk
|
||||
1,0, // uncompressed format
|
||||
chan_count,0, // channel count
|
||||
rate,rate >> 8, // sample rate
|
||||
rate>>16,rate>>24,
|
||||
bps,bps>>8, // bytes per second
|
||||
bps>>16,bps>>24,
|
||||
frame_size,0, // bytes per sample frame
|
||||
(unsigned char)chan_count,0,// channel count
|
||||
LE32(rate), // sample rate
|
||||
LE32(bps), // bytes per second
|
||||
(unsigned char)frame_size,0,// bytes per sample frame
|
||||
16,0, // bits per sample
|
||||
'd','a','t','a',
|
||||
ds,ds>>8,ds>>16,ds>>24// size of sample data
|
||||
LE32(ds) // size of sample data
|
||||
// ... // sample data
|
||||
};
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ int main(int argc, char *argv[])
|
||||
if ( argc >= 2 )
|
||||
filename = argv[1];
|
||||
|
||||
long sample_rate = 44100; /* number of samples per second */
|
||||
int sample_rate = 44100; /* number of samples per second */
|
||||
/* index of track to play (0 = first) */
|
||||
int track = argc >= 3 ? atoi(argv[2]) : 0;
|
||||
|
||||
|
||||
@@ -0,0 +1,84 @@
|
||||
/* C example that opens a game music file and records 10 seconds to "out.wav" */
|
||||
|
||||
#include "gme/gme.h"
|
||||
|
||||
#include "Wave_Writer.h" /* wave_ functions for writing sound file */
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
void handle_error( const char* str );
|
||||
|
||||
char * dump_file(const char*file_path, size_t *size)
|
||||
{
|
||||
FILE *in = fopen(file_path, "rb");
|
||||
char *buffer = NULL;
|
||||
if (!in)
|
||||
return NULL;
|
||||
fseek(in, 0, SEEK_END);
|
||||
(*size) = (size_t)ftell(in);
|
||||
fseek(in, 0, SEEK_SET);
|
||||
buffer = (char*)malloc(*size);
|
||||
fread(buffer, 1, *size, in);
|
||||
return buffer;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
const char *filename = "test.vgz"; /* Default file to open */
|
||||
if ( argc >= 2 )
|
||||
filename = argv[1];
|
||||
|
||||
int sample_rate = 44100; /* number of samples per second */
|
||||
/* index of track to play (0 = first) */
|
||||
int track = argc >= 3 ? atoi(argv[2]) : 0;
|
||||
|
||||
size_t file_size = 0;
|
||||
char *file_data = dump_file(filename, &file_size);
|
||||
if (!file_data)
|
||||
{
|
||||
printf( "Error: Can't dump %s!\n", filename );
|
||||
exit( EXIT_FAILURE );
|
||||
}
|
||||
|
||||
/* Open music file in new emulator */
|
||||
Music_Emu* emu;
|
||||
handle_error( gme_open_data(file_data, (long)file_size, &emu, sample_rate) );
|
||||
/* File dump is no more needed */
|
||||
free(file_data);
|
||||
|
||||
/* Start track */
|
||||
handle_error( gme_start_track( emu, track ) );
|
||||
|
||||
/* Begin writing to wave file */
|
||||
wave_open( sample_rate, "out.wav" );
|
||||
wave_enable_stereo();
|
||||
|
||||
/* Record 10 seconds of track */
|
||||
while ( gme_tell( emu ) < 10 * 1000L )
|
||||
{
|
||||
/* Sample buffer */
|
||||
#define buf_size 1024 /* can be any multiple of 2 */
|
||||
short buf [buf_size];
|
||||
|
||||
/* Fill sample buffer */
|
||||
handle_error( gme_play( emu, buf_size, buf ) );
|
||||
|
||||
/* Write samples to wave file */
|
||||
wave_write( buf, buf_size );
|
||||
}
|
||||
|
||||
/* Cleanup */
|
||||
gme_delete( emu );
|
||||
wave_close();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void handle_error( const char* str )
|
||||
{
|
||||
if ( str )
|
||||
{
|
||||
printf( "Error: %s\n", str ); getchar();
|
||||
exit( EXIT_FAILURE );
|
||||
}
|
||||
}
|
||||
+194
-194
@@ -1,194 +1,194 @@
|
||||
Game_Music_Emu 0.6.0 Design
|
||||
---------------------------
|
||||
This might be slightly out-of-date at times, but will be a big help in
|
||||
understanding the library implementation.
|
||||
|
||||
|
||||
Architecture
|
||||
------------
|
||||
The library is essentially a bunch of independent game music file
|
||||
emulators unified with a common interface.
|
||||
|
||||
Gme_File and Music_Emu provide a common interface to the emulators. The
|
||||
virtual functions are protected rather than public to allow pre- and
|
||||
post-processing of arguments and data in one place. This allows the
|
||||
emulator classes to assume that everything is set up properly when
|
||||
starting a track and playing samples.
|
||||
|
||||
All file input is done with the Data_Reader interface. Many derived
|
||||
classes are present, for the usual disk-based file and block of memory,
|
||||
to specialized adaptors for things like reading a subset of data or
|
||||
combining a block of memory with a Data_Reader to the remaining data.
|
||||
This makes the library much more flexible with regard to the source of
|
||||
game music file data. I still added a specialized load_mem() function to
|
||||
have the emulator keep a pointer to data already read in memory, for
|
||||
those formats whose files can be absolutely huge (GYM, some VGMs). This
|
||||
is important if for some reason the caller must load the data ahead of
|
||||
time, but doesn't want the emulator needlessly making a copy.
|
||||
|
||||
Since silence checking and fading are relatively complex, they are kept
|
||||
separate from basic file loading and track information, which are
|
||||
handled in the base class Gme_File. My original intent was to use
|
||||
Gme_File as the common base class for full emulators and track
|
||||
information-only readers, but implementing the C interface was much
|
||||
simpler if both derived from Music_Emu. User C++ code can still benefit
|
||||
from static checking by using Gme_File where only track information will
|
||||
be accessed.
|
||||
|
||||
Each emulator generally has three components: main emulator, CPU
|
||||
emulator, and sound chip emulator(s). Each component has minimal
|
||||
coupling, so use in a full emulator or stand alone is fairly easy. This
|
||||
modularity really helps reduce complexity. Blip_Buffer helps a lot with
|
||||
simplifying the APU interfaces and implementation.
|
||||
|
||||
The "classic" emulators derive from Classic_Emu, which handles
|
||||
Blip_Buffer filling and multiple channels. It uses Multi_Buffer for
|
||||
output, allowing you to derive a custom buffer that could output each
|
||||
voice to a separate sound channel and do different processing on each.
|
||||
At some point I'm going to implement a better Effects_Buffer that allows
|
||||
individual control of every channel.
|
||||
|
||||
In implementing the C interface, I wanted a way to specify an emulator
|
||||
type that didn't require linking in all the emulators. For each emulator
|
||||
type there is a global object with pointers to functions to create the
|
||||
emulator or a track information reader. The emulator type is thus a
|
||||
pointer to this, which conveniently allows for a NULL value. The user
|
||||
referencing this emulator type object is what ultimately links the
|
||||
emulator in (unless new Foo_Emu is used in C++, of course). This type
|
||||
also serves as a useful substitute for RTTI on older C++ compilers.
|
||||
|
||||
Addendum: I have since added gme_type_list(), which causes all listed
|
||||
emulators to be linked in. To avoid this, I make the list itself
|
||||
editable in blargg_config.h. Having a built-in list allows
|
||||
gme_load_file() to take a path and give back an emulator with the file
|
||||
loaded, which is extremely useful for new users.
|
||||
|
||||
|
||||
Interface conventions
|
||||
----------------------
|
||||
If a function retains a pointer to or replaces the value of an object
|
||||
passed, it takes a pointer so that it will be clear in the caller's
|
||||
source code that care is required.
|
||||
|
||||
Multi-word names have an underscore '_' separator between individual
|
||||
words.
|
||||
|
||||
Functions are named with lowercase words. Functions which perform an
|
||||
action with side-effects are named with a verb phrase (i.e. load, move,
|
||||
run). Functions which return the value of a piece of state are named
|
||||
using a noun phrase (i.e. loaded, moved, running).
|
||||
|
||||
Classes are named with capitalized words. Only the first letter of an
|
||||
acronym is capitalized. Class names are nouns, sometimes suggestive of
|
||||
what they do (i.e. File_Scanner).
|
||||
|
||||
Structure, enumeration, and typedefs to these and built-in types are
|
||||
named using lowercase words with a _t suffix.
|
||||
|
||||
Macros are named with all-uppercase words.
|
||||
|
||||
Internal names which can't be hidden due to technical reasons have an
|
||||
underscore '_' suffix.
|
||||
|
||||
|
||||
Managing Complexity
|
||||
-------------------
|
||||
Complexity has been a factor in most library decisions. Many features
|
||||
have been passed by due to the complexity they would add. Once
|
||||
complexity goes past a certain level, it mentally grasping the library
|
||||
in its entirety, at which point more defects will occur and be hard to
|
||||
find.
|
||||
|
||||
I chose 16-bit signed samples because it seems to be the most common
|
||||
format. Supporting multiple formats would add too much complexity to be
|
||||
worth it. Other formats can be obtained via conversion.
|
||||
|
||||
I've kept interfaces fairly lean, leaving many possible features
|
||||
untapped but easy to add if necessary. For example the classic emulators
|
||||
could have volume and frequency equalization adjusted separately for
|
||||
each channel, since they each have an associated Blip_Synth.
|
||||
|
||||
Source files of 400 lines or less seem to be the best size to limit
|
||||
complexity. In a few cases there is no reasonable way to split longer
|
||||
files, or there is benefit from having the source together in one file.
|
||||
|
||||
|
||||
Preventing Bugs
|
||||
---------------
|
||||
I've done many things to reduce the opportunity for defects. A general
|
||||
principle is to write code so that defects will be as visible as
|
||||
possible. I've used several techniques to achieve this.
|
||||
|
||||
I put assertions at key points where defects seem likely or where
|
||||
corruption due to a defect is likely to be visible. I've also put
|
||||
assertions where violations of the interface are likely. In emulators
|
||||
where I am unsure of exact hardware operation in a particular case, I
|
||||
output a debug-only message noting that this has occurred; many times I
|
||||
haven't implemented a hardware feature because nothing uses it. I've
|
||||
made code brittle where there is no clear reason flexibility; code
|
||||
written to handle every possibility sacrifices quality and reliability
|
||||
to handle vaguely defined situations.
|
||||
|
||||
|
||||
Flexibility through indirection
|
||||
-------------------------------
|
||||
I've tried to allow the most flexibility of modules by using indirection
|
||||
to allow extension by the user. This keeps each module simpler and more
|
||||
focused on its unique task.
|
||||
|
||||
The classic emulators use Multi_Buffer, which potentially allows a
|
||||
separate Blip_Buffer for each channel. This keeps emulators free of
|
||||
typical code to allow output in mono, stereo, panning, etc.
|
||||
|
||||
All emulators use a reader object to access file data, allowing it to be
|
||||
stored in a regular file, compressed archive, memory, or generated
|
||||
on-the-fly. Again, the library can be kept free of the particulars of
|
||||
file access and changes required to support new formats.
|
||||
|
||||
|
||||
Emulators in general
|
||||
--------------------
|
||||
When I wrote the first NES sound emulator, I stored most of the state in
|
||||
an emulator-specific format, with significant redundancy. In the
|
||||
register write function I decoded everything into named variables. I
|
||||
became tired of the verbosity and wanted to more closely model the
|
||||
hardware, so I moved to a style of storing the last written value to
|
||||
each register, along with as little other state as possible, mostly the
|
||||
internal hardware registers. While this involves slightly more
|
||||
recalculation, in most cases the emulation code is of comparable size.
|
||||
It also makes state save/restore (for use in a full emulator) much
|
||||
simpler. Finally, it makes debugging easier since the hardware registers
|
||||
used in emulation are obvious.
|
||||
|
||||
|
||||
CPU Cores
|
||||
---------
|
||||
I've spent lots of time coming up with techniques to optimize the CPU
|
||||
cores. Some of the most important: execute multiple instructions during
|
||||
an emulation call, keep state in local variables to allow register
|
||||
assignment, optimize state representation for most common instructions,
|
||||
defer status flag calculation until actually needed, read program code
|
||||
directly without a call to the memory read function, always pre-fetch
|
||||
the operand byte before decoding instruction, and emulate instructions
|
||||
using common blocks of code.
|
||||
|
||||
I've successfully used Nes_Cpu in a fairly complete NES emulator, and
|
||||
I'd like to make all the CPU emulators suitable for use in emulators. It
|
||||
seems a waste for them to be used only for the small amount of emulation
|
||||
necessary for game music files.
|
||||
|
||||
I debugged the CPU cores by writing a test shell that ran them in
|
||||
parallel with other CPU cores and compared all memory accesses and
|
||||
processor states at each step. This provided good value at little cost.
|
||||
|
||||
The CPU mapping page size is adjustable to allow the best tradeoff
|
||||
between memory/cache usage and handler granularity. The interface allows
|
||||
code to be somewhat independent of the page size.
|
||||
|
||||
I optimize program memory accesses to direct reads rather than calls to
|
||||
the memory read function. My assumption is that it would be difficult to
|
||||
get useful code out of hardware I/O addresses, so no software will
|
||||
intentionally execute out of I/O space. Since the page size can be
|
||||
changed easily, most program memory mapping schemes can be accommodated.
|
||||
This greatly reduces memory access function calls.
|
||||
|
||||
Game_Music_Emu 0.6.0 Design
|
||||
---------------------------
|
||||
This might be slightly out-of-date at times, but will be a big help in
|
||||
understanding the library implementation.
|
||||
|
||||
|
||||
Architecture
|
||||
------------
|
||||
The library is essentially a bunch of independent game music file
|
||||
emulators unified with a common interface.
|
||||
|
||||
Gme_File and Music_Emu provide a common interface to the emulators. The
|
||||
virtual functions are protected rather than public to allow pre- and
|
||||
post-processing of arguments and data in one place. This allows the
|
||||
emulator classes to assume that everything is set up properly when
|
||||
starting a track and playing samples.
|
||||
|
||||
All file input is done with the Data_Reader interface. Many derived
|
||||
classes are present, for the usual disk-based file and block of memory,
|
||||
to specialized adaptors for things like reading a subset of data or
|
||||
combining a block of memory with a Data_Reader to the remaining data.
|
||||
This makes the library much more flexible with regard to the source of
|
||||
game music file data. I still added a specialized load_mem() function to
|
||||
have the emulator keep a pointer to data already read in memory, for
|
||||
those formats whose files can be absolutely huge (GYM, some VGMs). This
|
||||
is important if for some reason the caller must load the data ahead of
|
||||
time, but doesn't want the emulator needlessly making a copy.
|
||||
|
||||
Since silence checking and fading are relatively complex, they are kept
|
||||
separate from basic file loading and track information, which are
|
||||
handled in the base class Gme_File. My original intent was to use
|
||||
Gme_File as the common base class for full emulators and track
|
||||
information-only readers, but implementing the C interface was much
|
||||
simpler if both derived from Music_Emu. User C++ code can still benefit
|
||||
from static checking by using Gme_File where only track information will
|
||||
be accessed.
|
||||
|
||||
Each emulator generally has three components: main emulator, CPU
|
||||
emulator, and sound chip emulator(s). Each component has minimal
|
||||
coupling, so use in a full emulator or stand alone is fairly easy. This
|
||||
modularity really helps reduce complexity. Blip_Buffer helps a lot with
|
||||
simplifying the APU interfaces and implementation.
|
||||
|
||||
The "classic" emulators derive from Classic_Emu, which handles
|
||||
Blip_Buffer filling and multiple channels. It uses Multi_Buffer for
|
||||
output, allowing you to derive a custom buffer that could output each
|
||||
voice to a separate sound channel and do different processing on each.
|
||||
At some point I'm going to implement a better Effects_Buffer that allows
|
||||
individual control of every channel.
|
||||
|
||||
In implementing the C interface, I wanted a way to specify an emulator
|
||||
type that didn't require linking in all the emulators. For each emulator
|
||||
type there is a global object with pointers to functions to create the
|
||||
emulator or a track information reader. The emulator type is thus a
|
||||
pointer to this, which conveniently allows for a NULL value. The user
|
||||
referencing this emulator type object is what ultimately links the
|
||||
emulator in (unless new Foo_Emu is used in C++, of course). This type
|
||||
also serves as a useful substitute for RTTI on older C++ compilers.
|
||||
|
||||
Addendum: I have since added gme_type_list(), which causes all listed
|
||||
emulators to be linked in. To avoid this, I make the list itself
|
||||
editable in blargg_config.h. Having a built-in list allows
|
||||
gme_load_file() to take a path and give back an emulator with the file
|
||||
loaded, which is extremely useful for new users.
|
||||
|
||||
|
||||
Interface conventions
|
||||
----------------------
|
||||
If a function retains a pointer to or replaces the value of an object
|
||||
passed, it takes a pointer so that it will be clear in the caller's
|
||||
source code that care is required.
|
||||
|
||||
Multi-word names have an underscore '_' separator between individual
|
||||
words.
|
||||
|
||||
Functions are named with lowercase words. Functions which perform an
|
||||
action with side-effects are named with a verb phrase (i.e. load, move,
|
||||
run). Functions which return the value of a piece of state are named
|
||||
using a noun phrase (i.e. loaded, moved, running).
|
||||
|
||||
Classes are named with capitalized words. Only the first letter of an
|
||||
acronym is capitalized. Class names are nouns, sometimes suggestive of
|
||||
what they do (i.e. File_Scanner).
|
||||
|
||||
Structure, enumeration, and typedefs to these and built-in types are
|
||||
named using lowercase words with a _t suffix.
|
||||
|
||||
Macros are named with all-uppercase words.
|
||||
|
||||
Internal names which can't be hidden due to technical reasons have an
|
||||
underscore '_' suffix.
|
||||
|
||||
|
||||
Managing Complexity
|
||||
-------------------
|
||||
Complexity has been a factor in most library decisions. Many features
|
||||
have been passed by due to the complexity they would add. Once
|
||||
complexity goes past a certain level, it mentally grasping the library
|
||||
in its entirety, at which point more defects will occur and be hard to
|
||||
find.
|
||||
|
||||
I chose 16-bit signed samples because it seems to be the most common
|
||||
format. Supporting multiple formats would add too much complexity to be
|
||||
worth it. Other formats can be obtained via conversion.
|
||||
|
||||
I've kept interfaces fairly lean, leaving many possible features
|
||||
untapped but easy to add if necessary. For example the classic emulators
|
||||
could have volume and frequency equalization adjusted separately for
|
||||
each channel, since they each have an associated Blip_Synth.
|
||||
|
||||
Source files of 400 lines or less seem to be the best size to limit
|
||||
complexity. In a few cases there is no reasonable way to split longer
|
||||
files, or there is benefit from having the source together in one file.
|
||||
|
||||
|
||||
Preventing Bugs
|
||||
---------------
|
||||
I've done many things to reduce the opportunity for defects. A general
|
||||
principle is to write code so that defects will be as visible as
|
||||
possible. I've used several techniques to achieve this.
|
||||
|
||||
I put assertions at key points where defects seem likely or where
|
||||
corruption due to a defect is likely to be visible. I've also put
|
||||
assertions where violations of the interface are likely. In emulators
|
||||
where I am unsure of exact hardware operation in a particular case, I
|
||||
output a debug-only message noting that this has occurred; many times I
|
||||
haven't implemented a hardware feature because nothing uses it. I've
|
||||
made code brittle where there is no clear reason flexibility; code
|
||||
written to handle every possibility sacrifices quality and reliability
|
||||
to handle vaguely defined situations.
|
||||
|
||||
|
||||
Flexibility through indirection
|
||||
-------------------------------
|
||||
I've tried to allow the most flexibility of modules by using indirection
|
||||
to allow extension by the user. This keeps each module simpler and more
|
||||
focused on its unique task.
|
||||
|
||||
The classic emulators use Multi_Buffer, which potentially allows a
|
||||
separate Blip_Buffer for each channel. This keeps emulators free of
|
||||
typical code to allow output in mono, stereo, panning, etc.
|
||||
|
||||
All emulators use a reader object to access file data, allowing it to be
|
||||
stored in a regular file, compressed archive, memory, or generated
|
||||
on-the-fly. Again, the library can be kept free of the particulars of
|
||||
file access and changes required to support new formats.
|
||||
|
||||
|
||||
Emulators in general
|
||||
--------------------
|
||||
When I wrote the first NES sound emulator, I stored most of the state in
|
||||
an emulator-specific format, with significant redundancy. In the
|
||||
register write function I decoded everything into named variables. I
|
||||
became tired of the verbosity and wanted to more closely model the
|
||||
hardware, so I moved to a style of storing the last written value to
|
||||
each register, along with as little other state as possible, mostly the
|
||||
internal hardware registers. While this involves slightly more
|
||||
recalculation, in most cases the emulation code is of comparable size.
|
||||
It also makes state save/restore (for use in a full emulator) much
|
||||
simpler. Finally, it makes debugging easier since the hardware registers
|
||||
used in emulation are obvious.
|
||||
|
||||
|
||||
CPU Cores
|
||||
---------
|
||||
I've spent lots of time coming up with techniques to optimize the CPU
|
||||
cores. Some of the most important: execute multiple instructions during
|
||||
an emulation call, keep state in local variables to allow register
|
||||
assignment, optimize state representation for most common instructions,
|
||||
defer status flag calculation until actually needed, read program code
|
||||
directly without a call to the memory read function, always pre-fetch
|
||||
the operand byte before decoding instruction, and emulate instructions
|
||||
using common blocks of code.
|
||||
|
||||
I've successfully used Nes_Cpu in a fairly complete NES emulator, and
|
||||
I'd like to make all the CPU emulators suitable for use in emulators. It
|
||||
seems a waste for them to be used only for the small amount of emulation
|
||||
necessary for game music files.
|
||||
|
||||
I debugged the CPU cores by writing a test shell that ran them in
|
||||
parallel with other CPU cores and compared all memory accesses and
|
||||
processor states at each step. This provided good value at little cost.
|
||||
|
||||
The CPU mapping page size is adjustable to allow the best tradeoff
|
||||
between memory/cache usage and handler granularity. The interface allows
|
||||
code to be somewhat independent of the page size.
|
||||
|
||||
I optimize program memory accesses to direct reads rather than calls to
|
||||
the memory read function. My assumption is that it would be difficult to
|
||||
get useful code out of hardware I/O addresses, so no software will
|
||||
intentionally execute out of I/O space. Since the page size can be
|
||||
changed easily, most program memory mapping schemes can be accommodated.
|
||||
This greatly reduces memory access function calls.
|
||||
|
||||
+376
-376
@@ -1,376 +1,376 @@
|
||||
Game_Music_Emu 0.6.2
|
||||
--------------------
|
||||
Author : Shay Green <gblargg@gmail.com>
|
||||
Maintainer : Michael Pyne <mpyne@purinchu.net>
|
||||
Website : https://bitbucket.org/mpyne/game-music-emu/
|
||||
Source : https://bitbucket.org/mpyne/game-music-emu/
|
||||
License : GNU Lesser General Public License (LGPL), see LICENSE.txt
|
||||
|
||||
Contents
|
||||
--------
|
||||
* Overview
|
||||
* Error handling
|
||||
* Emulator types
|
||||
* M3U playlist support
|
||||
* Information fields
|
||||
* Track length
|
||||
* Loading file data
|
||||
* Sound parameters
|
||||
* VGM/GYM YM2413 & YM2612 FM sound
|
||||
* Modular construction
|
||||
* Obscure features
|
||||
* Solving problems
|
||||
* Thanks
|
||||
|
||||
|
||||
Overview
|
||||
--------
|
||||
This library can open game music files, play tracks, and read game and
|
||||
track information tags. To play a game music file, do the following:
|
||||
|
||||
* Open the file with gme_open_file()
|
||||
* Start a track with gme_start_track();
|
||||
* Generate samples as needed with gme_play()
|
||||
* Play samples through speaker using your operating system
|
||||
* Delete emulator when done with gme_delete()
|
||||
|
||||
Your code must arrange for the generated samples to be played through
|
||||
the computer's speaker using whatever method your operating system
|
||||
requires.
|
||||
|
||||
There are many additional features available; you can:
|
||||
|
||||
* Determine of the type of a music file without opening it with
|
||||
gme_identify_*()
|
||||
* Load just the file's information tags with gme_info_only
|
||||
* Load from a block of memory rather than a file with gme_load_data()
|
||||
* Arrange for a fade-out at a particular time with gme_set_fade
|
||||
* Find when a track has ended with gme_track_ended()
|
||||
* Seek to a new time in the track with gme_seek()
|
||||
* Load an extended m3u playlist with gme_load_m3u()
|
||||
* Get a list of the voices (channels) and mute them individually with
|
||||
gme_voice_names() and gme_mute_voice()
|
||||
* Change the playback tempo without affecting pitch with gme_set_tempo()
|
||||
* Adjust treble/bass equalization with gme_set_equalizer()
|
||||
* Associate your own data with an emulator and later get it back with
|
||||
gme_set_user_data()
|
||||
* Register a function of yours to be called back when the emulator is
|
||||
deleted with gme_set_user_cleanup()
|
||||
|
||||
Refer to gme.h for a comprehensive summary of features.
|
||||
|
||||
|
||||
Error handling
|
||||
--------------
|
||||
Functions which can fail have a return type of gme_err_t, which is a
|
||||
pointer to an error string (const char*). If a function is successful it
|
||||
returns NULL. Errors that you can easily avoid are checked with debug
|
||||
assertions; gme_err_t return values are only used for genuine run-time
|
||||
errors that can't be easily predicted in advance (out of memory, I/O
|
||||
errors, incompatible file data). Your code should check all error
|
||||
values.
|
||||
|
||||
When loading a music file in the wrong emulator or trying to load a
|
||||
non-music file, gme_wrong_file_type is returned. You can check for this
|
||||
error in C++ like this:
|
||||
|
||||
gme_err_t err = gme_open_file( path, &emu );
|
||||
if ( err == gme_wrong_file_type )
|
||||
...
|
||||
|
||||
To check for minor problems, call gme_warning() to get a string
|
||||
describing the last warning. Your player should allow the user some way
|
||||
of knowing when this is the case, since these minor errors could affect
|
||||
playback. Without this information the user can't solve problems as
|
||||
well. When playing a track, gme_warning() returns minor playback-related
|
||||
problems (major playback problems end the track immediately and set the
|
||||
warning string).
|
||||
|
||||
|
||||
Emulator types
|
||||
--------------
|
||||
The library includes several game music emulators that each support a
|
||||
different file type. Each is identified by a gme_type_t constant defined
|
||||
in gme.h, for example gme_nsf_emu is for the NSF emulator. If you use
|
||||
gme_open_file() or gme_open_data(), the library does the work of
|
||||
determining the file type and creating an appropriate emulator. If you
|
||||
want more control over this process, read on.
|
||||
|
||||
There are two basic ways to identify a game music file's type: look at
|
||||
its file extension, or read the header data. The library includes
|
||||
functions to help with both methods. The first is preferable because it
|
||||
is fast and the most common way to identify files. Sometimes the
|
||||
extension is lost or wrong, so the header must be read.
|
||||
|
||||
Use gme_identify_extension() to find the correct game music type based
|
||||
on a filename. To identify a file based on its extension and header
|
||||
contents, use gme_identify_file(). If you read the header data yourself,
|
||||
use gme_identify_header().
|
||||
|
||||
If you want to remove support for some music types to reduce your
|
||||
executable size, edit GME_TYPE_LIST in blargg_config.h. For example, to
|
||||
support just NSF and GBS, use this:
|
||||
|
||||
#define GME_TYPE_LIST \
|
||||
gme_nsf_type,\
|
||||
gme_gbs_type
|
||||
|
||||
|
||||
M3U playlist support
|
||||
--------------------
|
||||
The library supports playlists in an extended m3u format with
|
||||
gme_load_m3u() to give track names and times to multi-song formats: AY,
|
||||
GBS, HES, KSS, NSF, NSFE, and SAP. Some aspects of the file format
|
||||
itself is not well-defined so some m3u files won't work properly
|
||||
(particularly those provided with KSS files). Only m3u files referencing
|
||||
a single file are supported; your code must handle m3u files covering
|
||||
more than one game music file, though it can use the built-in m3u
|
||||
parsing provided by the library.
|
||||
|
||||
|
||||
Information fields
|
||||
------------------
|
||||
Support is provided for the various text fields and length information
|
||||
in a file with gme_track_info(). If you just need track information for
|
||||
a file (for example, building a playlist), use gme_new_info() in place
|
||||
of gme_new_emu(), load the file normally, then you can access the track
|
||||
count and info, but nothing else.
|
||||
|
||||
M3U VGM GYM SPC SAP NSFE NSF AY GBS HES KSS
|
||||
-------------------------------------------------------
|
||||
Track Count | * * * * * * * * *
|
||||
|
|
||||
System | * * * * * * * * * *
|
||||
|
|
||||
Game | * * * * * * *
|
||||
|
|
||||
Song | * * * * * * *
|
||||
|
|
||||
Author | * * * * * * * *
|
||||
|
|
||||
Copyright | * * * * * * * *
|
||||
|
|
||||
Comment | * * * *
|
||||
|
|
||||
Dumper | * * * *
|
||||
|
|
||||
Length | * * * * * *
|
||||
|
|
||||
Intro Length| * * *
|
||||
|
|
||||
Loop Length | * * *
|
||||
|
||||
As listed above, the HES and KSS file formats don't include a track
|
||||
count, and tracks are often scattered over the 0-255 range, so an m3u
|
||||
playlist for these is a must.
|
||||
|
||||
Unavailable text fields are set to an empty string and times to -1. Your
|
||||
code should be prepared for any combination of available and unavailable
|
||||
fields, as a particular music file might not use all of the supported
|
||||
fields listed above.
|
||||
|
||||
Currently text fields are truncated to 255 characters. Obscure fields of
|
||||
some formats are not currently decoded; contact me if you want one
|
||||
added.
|
||||
|
||||
|
||||
Track length
|
||||
------------
|
||||
The library leaves it up to you as to when to stop playing a track. You
|
||||
can ask for available length information and then tell the library what
|
||||
time it should start fading the track with gme_set_fade(). By default it
|
||||
also continually checks for 6 or more seconds of silence to mark the end
|
||||
of a track. Here is a reasonable algorithm you can use to decide how
|
||||
long to play a track:
|
||||
|
||||
* If the track length is > 0, use it
|
||||
* If the loop length > 0, play for intro + loop * 2
|
||||
* Otherwise, default to 2.5 minutes (150000 msec)
|
||||
|
||||
If you want to play a track longer than normal, be sure the loop length
|
||||
isn't zero. See Music_Player.cpp around line 145 for example code.
|
||||
|
||||
By default, the library skips silence at the beginning of a track. It
|
||||
also continually checks for the end of a non-looping track by watching
|
||||
for 6 seconds of unbroken silence. When doing this is scans *ahead* by
|
||||
several seconds so it can report the end of the track after only one
|
||||
second of silence has actually played. This feature can be disabled with
|
||||
gme_ignore_silence().
|
||||
|
||||
|
||||
Loading file data
|
||||
-----------------
|
||||
The library allows file data to be loaded in many different ways. All
|
||||
load functions return an error which you should check. The following
|
||||
examples assume these variables:
|
||||
|
||||
Music_Emu* emu;
|
||||
gme_err_t error;
|
||||
|
||||
If you're letting the library determine a file's type, you can use
|
||||
either gme_open_file() or gme_open_data():
|
||||
|
||||
error = gme_open_file( pathname, &emu );
|
||||
error = gme_open_data( pointer, size, &emu );
|
||||
|
||||
If you're manually determining file type and using used gme_new_emu() to
|
||||
create an emulator, you can use the following methods of loading:
|
||||
|
||||
* From a block of memory:
|
||||
|
||||
error = gme_load_data( emu, pointer, size );
|
||||
|
||||
* Have library call your function to read data:
|
||||
|
||||
gme_err_t my_read( void* my_data, void* out, long count )
|
||||
{
|
||||
// code that reads 'count' bytes into 'out' buffer
|
||||
// and return 0 if no error
|
||||
}
|
||||
|
||||
error = gme_load_custom( emu, my_read, file_size, my_data );
|
||||
|
||||
|
||||
Sound parameters
|
||||
----------------
|
||||
All emulators support an arbitrary output sampling rate. A rate of 44100
|
||||
Hz should work well on most systems. Since band-limited synthesis is
|
||||
used, a sampling rate above 48000 Hz is not necessary and will actually
|
||||
reduce sound quality and performance.
|
||||
|
||||
All emulators also support adjustable gain, mainly for the purpose of
|
||||
getting consistent volume between different music formats and avoiding
|
||||
excessive modulation. The gain can only be set *before* setting the
|
||||
emulator's sampling rate, so it's not useful as a general volume
|
||||
control. The default gains of emulators are set so that they give
|
||||
generally similar volumes, though some soundtracks are significantly
|
||||
louder or quieter than normal.
|
||||
|
||||
Some emulators support adjustable treble and bass frequency equalization
|
||||
(AY, GBS, HES, KSS, NSF, NSFE, SAP, VGM) using set_equalizer().
|
||||
Parameters are specified using gme_equalizer_t eq = { treble_dB,
|
||||
bass_freq }. Treble_dB sets the treble level (in dB), where 0.0 dB gives
|
||||
normal treble; -200.0 dB is quite muffled, and 5.0 dB emphasizes treble
|
||||
for an extra crisp sound. Bass_freq sets the frequency where bass
|
||||
response starts to diminish; 15 Hz is normal, 0 Hz gives maximum bass,
|
||||
and 15000 Hz removes all bass. For example, the following makes the
|
||||
sound extra-crisp but lacking bass:
|
||||
|
||||
gme_equalizer_t eq = { 5.0, 1000 };
|
||||
gme_set_equalizer( music_emu, &eq );
|
||||
|
||||
Each emulator's equalization defaults to approximate the particular
|
||||
console's sound quality; this default can be determined by calling
|
||||
equalizer() just after creating the emulator. The Music_Emu::tv_eq
|
||||
profile gives sound as if coming from a TV speaker, and some emulators
|
||||
include other profiles for different versions of the system. For
|
||||
example, to use Famicom sound equalization with the NSF emulator, do the
|
||||
following:
|
||||
|
||||
music_emu->set_equalizer( Nsf_Emu::famicom_eq );
|
||||
|
||||
|
||||
VGM/GYM YM2413 & YM2612 FM sound
|
||||
--------------------------------
|
||||
The library plays Sega Genesis/Mega Drive music using a YM2612 FM sound
|
||||
chip emulator based on the Gens project. Because this has some
|
||||
inaccuracies, other YM2612 emulators can be used in its place by
|
||||
re-implementing the interface in YM2612_Emu.h. Available on my website
|
||||
is a modified version of MAME's YM2612 emulator, which sounds better in
|
||||
some ways and whose author is still making improvements.
|
||||
|
||||
VGM music files using the YM2413 FM sound chip are also supported, but a
|
||||
YM2413 emulator isn't included with the library due to technical
|
||||
reasons. I have put one of the available YM2413 emulators on my website
|
||||
that can be used directly.
|
||||
|
||||
|
||||
Modular construction
|
||||
--------------------
|
||||
The library is made of many fairly independent modules. If you're using
|
||||
only one music file emulator, you can eliminate many of the library
|
||||
sources from your program. Refer to the files list in readme.txt to get
|
||||
a general idea of what can be removed, and be sure to edit GME_TYPE_LIST
|
||||
(see "Emulator types" above). Post to the forum if you'd like me to put
|
||||
together a smaller version for a particular use, as this only takes me a
|
||||
few minutes to do.
|
||||
|
||||
If you want to use one of the individual sound chip emulators (or CPU
|
||||
cores) in your own console emulator, first check the libraries page on
|
||||
my website since I have released several of them as stand alone
|
||||
libraries with included documentation and examples on their use. If you
|
||||
don't find it as a standalone library, contact me and I'll consider
|
||||
separating it.
|
||||
|
||||
The "classic" sound chips use my Blip_Buffer library, which greatly
|
||||
simplifies their implementation and efficiently handles band-limited
|
||||
synthesis. It is also available as a stand alone library with
|
||||
documentation and many examples.
|
||||
|
||||
|
||||
Obscure features
|
||||
----------------
|
||||
The library's flexibility allows many possibilities. Contact me if you
|
||||
want help implementing ideas or removing limitations.
|
||||
|
||||
* Uses no global/static variables, allowing multiple instances of any
|
||||
emulator. This is useful in a music player if you want to allow
|
||||
simultaneous recording or scanning of other tracks while one is already
|
||||
playing. This will also be useful if your platform disallows global
|
||||
data.
|
||||
|
||||
* Emulators that support a custom sound buffer can have *every* voice
|
||||
routed to a different Blip_Buffer, allowing custom processing on each
|
||||
voice. For example you could record a Game Boy track as a 4-channel
|
||||
sound file.
|
||||
|
||||
* Defining BLIP_BUFFER_FAST uses lower quality, less-multiply-intensive
|
||||
synthesis on "classic" emulators, which might help on some really old
|
||||
processors. This significantly lowers sound quality and prevents treble
|
||||
equalization. Try this if your platform's processor isn't fast enough
|
||||
for normal quality. Even on my ten-year-old 400 MHz Mac, this reduces
|
||||
processor usage at most by about 0.6% (from 4% to 3.4%), hardly worth
|
||||
the quality loss.
|
||||
|
||||
|
||||
Solving problems
|
||||
----------------
|
||||
If you're having problems, try the following:
|
||||
|
||||
* If you're getting garbled sound, try this simple siren generator in
|
||||
place of your call to play(). This will quickly tell whether the problem
|
||||
is in the library or in your code.
|
||||
|
||||
static void play_siren( long count, short* out )
|
||||
{
|
||||
static double a, a2;
|
||||
while ( count-- )
|
||||
*out++ = 0x2000 * sin( a += .1 + .05*sin( a2+=.00005 ) );
|
||||
}
|
||||
|
||||
* Enable debugging support in your environment. This enables assertions
|
||||
and other run-time checks.
|
||||
|
||||
* Turn the compiler's optimizer is off. Sometimes an optimizer generates
|
||||
bad code.
|
||||
|
||||
* If multiple threads are being used, ensure that only one at a time is
|
||||
accessing a given set of objects from the library. This library is not
|
||||
in general thread-safe, though independent objects can be used in
|
||||
separate threads.
|
||||
|
||||
* If all else fails, see if the demos work.
|
||||
|
||||
|
||||
Thanks
|
||||
------
|
||||
Big thanks to Chris Moeller (kode54) for help with library testing and
|
||||
feedback, for maintaining the Foobar2000 plugin foo_gep based on it, and
|
||||
for original work on openspc++ that was used when developing Spc_Emu.
|
||||
Brad Martin's excellent OpenSPC SNES DSP emulator worked well from the
|
||||
start. Also thanks to Richard Bannister, Mahendra Tallur, Shazz,
|
||||
nenolod, theHobbit, Johan Samuelsson, and nes6502 for testing, using,
|
||||
and giving feedback for the library in their respective game music
|
||||
players. More recently, Lucas Paul and Michael Pyne have helped nudge the
|
||||
library into a public repository and get its interface more stable for use
|
||||
in shared libraries.
|
||||
Game_Music_Emu 0.6.3
|
||||
--------------------
|
||||
Author : Shay Green <gblargg@gmail.com>
|
||||
Maintainer : Michael Pyne <mpyne@purinchu.net>
|
||||
Website : https://bitbucket.org/mpyne/game-music-emu/
|
||||
Source : https://bitbucket.org/mpyne/game-music-emu/
|
||||
License : GNU Lesser General Public License (LGPL), see LICENSE.txt
|
||||
|
||||
Contents
|
||||
--------
|
||||
* Overview
|
||||
* Error handling
|
||||
* Emulator types
|
||||
* M3U playlist support
|
||||
* Information fields
|
||||
* Track length
|
||||
* Loading file data
|
||||
* Sound parameters
|
||||
* VGM/GYM YM2413 & YM2612 FM sound
|
||||
* Modular construction
|
||||
* Obscure features
|
||||
* Solving problems
|
||||
* Thanks
|
||||
|
||||
|
||||
Overview
|
||||
--------
|
||||
This library can open game music files, play tracks, and read game and
|
||||
track information tags. To play a game music file, do the following:
|
||||
|
||||
* Open the file with gme_open_file()
|
||||
* Start a track with gme_start_track();
|
||||
* Generate samples as needed with gme_play()
|
||||
* Play samples through speaker using your operating system
|
||||
* Delete emulator when done with gme_delete()
|
||||
|
||||
Your code must arrange for the generated samples to be played through
|
||||
the computer's speaker using whatever method your operating system
|
||||
requires.
|
||||
|
||||
There are many additional features available; you can:
|
||||
|
||||
* Determine of the type of a music file without opening it with
|
||||
gme_identify_*()
|
||||
* Load just the file's information tags with gme_info_only
|
||||
* Load from a block of memory rather than a file with gme_load_data()
|
||||
* Arrange for a fade-out at a particular time with gme_set_fade
|
||||
* Find when a track has ended with gme_track_ended()
|
||||
* Seek to a new time in the track with gme_seek()
|
||||
* Load an extended m3u playlist with gme_load_m3u()
|
||||
* Get a list of the voices (channels) and mute them individually with
|
||||
gme_voice_names() and gme_mute_voice()
|
||||
* Change the playback tempo without affecting pitch with gme_set_tempo()
|
||||
* Adjust treble/bass equalization with gme_set_equalizer()
|
||||
* Associate your own data with an emulator and later get it back with
|
||||
gme_set_user_data()
|
||||
* Register a function of yours to be called back when the emulator is
|
||||
deleted with gme_set_user_cleanup()
|
||||
|
||||
Refer to gme.h for a comprehensive summary of features.
|
||||
|
||||
|
||||
Error handling
|
||||
--------------
|
||||
Functions which can fail have a return type of gme_err_t, which is a
|
||||
pointer to an error string (const char*). If a function is successful it
|
||||
returns NULL. Errors that you can easily avoid are checked with debug
|
||||
assertions; gme_err_t return values are only used for genuine run-time
|
||||
errors that can't be easily predicted in advance (out of memory, I/O
|
||||
errors, incompatible file data). Your code should check all error
|
||||
values.
|
||||
|
||||
When loading a music file in the wrong emulator or trying to load a
|
||||
non-music file, gme_wrong_file_type is returned. You can check for this
|
||||
error in C++ like this:
|
||||
|
||||
gme_err_t err = gme_open_file( path, &emu );
|
||||
if ( err == gme_wrong_file_type )
|
||||
...
|
||||
|
||||
To check for minor problems, call gme_warning() to get a string
|
||||
describing the last warning. Your player should allow the user some way
|
||||
of knowing when this is the case, since these minor errors could affect
|
||||
playback. Without this information the user can't solve problems as
|
||||
well. When playing a track, gme_warning() returns minor playback-related
|
||||
problems (major playback problems end the track immediately and set the
|
||||
warning string).
|
||||
|
||||
|
||||
Emulator types
|
||||
--------------
|
||||
The library includes several game music emulators that each support a
|
||||
different file type. Each is identified by a gme_type_t constant defined
|
||||
in gme.h, for example gme_nsf_emu is for the NSF emulator. If you use
|
||||
gme_open_file() or gme_open_data(), the library does the work of
|
||||
determining the file type and creating an appropriate emulator. If you
|
||||
want more control over this process, read on.
|
||||
|
||||
There are two basic ways to identify a game music file's type: look at
|
||||
its file extension, or read the header data. The library includes
|
||||
functions to help with both methods. The first is preferable because it
|
||||
is fast and the most common way to identify files. Sometimes the
|
||||
extension is lost or wrong, so the header must be read.
|
||||
|
||||
Use gme_identify_extension() to find the correct game music type based
|
||||
on a filename. To identify a file based on its extension and header
|
||||
contents, use gme_identify_file(). If you read the header data yourself,
|
||||
use gme_identify_header().
|
||||
|
||||
If you want to remove support for some music types to reduce your
|
||||
executable size, edit GME_TYPE_LIST in blargg_config.h. For example, to
|
||||
support just NSF and GBS, use this:
|
||||
|
||||
#define GME_TYPE_LIST \
|
||||
gme_nsf_type,\
|
||||
gme_gbs_type
|
||||
|
||||
|
||||
M3U playlist support
|
||||
--------------------
|
||||
The library supports playlists in an extended m3u format with
|
||||
gme_load_m3u() to give track names and times to multi-song formats: AY,
|
||||
GBS, HES, KSS, NSF, NSFE, and SAP. Some aspects of the file format
|
||||
itself is not well-defined so some m3u files won't work properly
|
||||
(particularly those provided with KSS files). Only m3u files referencing
|
||||
a single file are supported; your code must handle m3u files covering
|
||||
more than one game music file, though it can use the built-in m3u
|
||||
parsing provided by the library.
|
||||
|
||||
|
||||
Information fields
|
||||
------------------
|
||||
Support is provided for the various text fields and length information
|
||||
in a file with gme_track_info(). If you just need track information for
|
||||
a file (for example, building a playlist), use gme_new_info() in place
|
||||
of gme_new_emu(), load the file normally, then you can access the track
|
||||
count and info, but nothing else.
|
||||
|
||||
M3U VGM GYM SPC SAP NSFE NSF AY GBS HES KSS
|
||||
-------------------------------------------------------
|
||||
Track Count | * * * * * * * * *
|
||||
|
|
||||
System | * * * * * * * * * *
|
||||
|
|
||||
Game | * * * * * * *
|
||||
|
|
||||
Song | * * * * * * *
|
||||
|
|
||||
Author | * * * * * * * *
|
||||
|
|
||||
Copyright | * * * * * * * *
|
||||
|
|
||||
Comment | * * * *
|
||||
|
|
||||
Dumper | * * * *
|
||||
|
|
||||
Length | * * * * * *
|
||||
|
|
||||
Intro Length| * * *
|
||||
|
|
||||
Loop Length | * * *
|
||||
|
||||
As listed above, the HES and KSS file formats don't include a track
|
||||
count, and tracks are often scattered over the 0-255 range, so an m3u
|
||||
playlist for these is a must.
|
||||
|
||||
Unavailable text fields are set to an empty string and times to -1. Your
|
||||
code should be prepared for any combination of available and unavailable
|
||||
fields, as a particular music file might not use all of the supported
|
||||
fields listed above.
|
||||
|
||||
Currently text fields are truncated to 255 characters. Obscure fields of
|
||||
some formats are not currently decoded; contact me if you want one
|
||||
added.
|
||||
|
||||
|
||||
Track length
|
||||
------------
|
||||
The library leaves it up to you as to when to stop playing a track. You
|
||||
can ask for available length information and then tell the library what
|
||||
time it should start fading the track with gme_set_fade(). By default it
|
||||
also continually checks for 6 or more seconds of silence to mark the end
|
||||
of a track. Here is a reasonable algorithm you can use to decide how
|
||||
long to play a track:
|
||||
|
||||
* If the track length is > 0, use it
|
||||
* If the loop length > 0, play for intro + loop * 2
|
||||
* Otherwise, default to 2.5 minutes (150000 msec)
|
||||
|
||||
If you want to play a track longer than normal, be sure the loop length
|
||||
isn't zero. See Music_Player.cpp around line 145 for example code.
|
||||
|
||||
By default, the library skips silence at the beginning of a track. It
|
||||
also continually checks for the end of a non-looping track by watching
|
||||
for 6 seconds of unbroken silence. When doing this is scans *ahead* by
|
||||
several seconds so it can report the end of the track after only one
|
||||
second of silence has actually played. This feature can be disabled with
|
||||
gme_ignore_silence().
|
||||
|
||||
|
||||
Loading file data
|
||||
-----------------
|
||||
The library allows file data to be loaded in many different ways. All
|
||||
load functions return an error which you should check. The following
|
||||
examples assume these variables:
|
||||
|
||||
Music_Emu* emu;
|
||||
gme_err_t error;
|
||||
|
||||
If you're letting the library determine a file's type, you can use
|
||||
either gme_open_file() or gme_open_data():
|
||||
|
||||
error = gme_open_file( pathname, &emu );
|
||||
error = gme_open_data( pointer, size, &emu );
|
||||
|
||||
If you're manually determining file type and using used gme_new_emu() to
|
||||
create an emulator, you can use the following methods of loading:
|
||||
|
||||
* From a block of memory:
|
||||
|
||||
error = gme_load_data( emu, pointer, size );
|
||||
|
||||
* Have library call your function to read data:
|
||||
|
||||
gme_err_t my_read( void* my_data, void* out, long count )
|
||||
{
|
||||
// code that reads 'count' bytes into 'out' buffer
|
||||
// and return 0 if no error
|
||||
}
|
||||
|
||||
error = gme_load_custom( emu, my_read, file_size, my_data );
|
||||
|
||||
|
||||
Sound parameters
|
||||
----------------
|
||||
All emulators support an arbitrary output sampling rate. A rate of 44100
|
||||
Hz should work well on most systems. Since band-limited synthesis is
|
||||
used, a sampling rate above 48000 Hz is not necessary and will actually
|
||||
reduce sound quality and performance.
|
||||
|
||||
All emulators also support adjustable gain, mainly for the purpose of
|
||||
getting consistent volume between different music formats and avoiding
|
||||
excessive modulation. The gain can only be set *before* setting the
|
||||
emulator's sampling rate, so it's not useful as a general volume
|
||||
control. The default gains of emulators are set so that they give
|
||||
generally similar volumes, though some soundtracks are significantly
|
||||
louder or quieter than normal.
|
||||
|
||||
Some emulators support adjustable treble and bass frequency equalization
|
||||
(AY, GBS, HES, KSS, NSF, NSFE, SAP, VGM) using set_equalizer().
|
||||
Parameters are specified using gme_equalizer_t eq = { treble_dB,
|
||||
bass_freq }. Treble_dB sets the treble level (in dB), where 0.0 dB gives
|
||||
normal treble; -200.0 dB is quite muffled, and 5.0 dB emphasizes treble
|
||||
for an extra crisp sound. Bass_freq sets the frequency where bass
|
||||
response starts to diminish; 15 Hz is normal, 0 Hz gives maximum bass,
|
||||
and 15000 Hz removes all bass. For example, the following makes the
|
||||
sound extra-crisp but lacking bass:
|
||||
|
||||
gme_equalizer_t eq = { 5.0, 1000 };
|
||||
gme_set_equalizer( music_emu, &eq );
|
||||
|
||||
Each emulator's equalization defaults to approximate the particular
|
||||
console's sound quality; this default can be determined by calling
|
||||
equalizer() just after creating the emulator. The Music_Emu::tv_eq
|
||||
profile gives sound as if coming from a TV speaker, and some emulators
|
||||
include other profiles for different versions of the system. For
|
||||
example, to use Famicom sound equalization with the NSF emulator, do the
|
||||
following:
|
||||
|
||||
music_emu->set_equalizer( Nsf_Emu::famicom_eq );
|
||||
|
||||
|
||||
VGM/GYM YM2413 & YM2612 FM sound
|
||||
--------------------------------
|
||||
The library plays Sega Genesis/Mega Drive music using a YM2612 FM sound
|
||||
chip emulator based on the Gens project. Because this has some
|
||||
inaccuracies, other YM2612 emulators can be used in its place by
|
||||
re-implementing the interface in YM2612_Emu.h. Available on my website
|
||||
is a modified version of MAME's YM2612 emulator, which sounds better in
|
||||
some ways and whose author is still making improvements.
|
||||
|
||||
VGM music files using the YM2413 FM sound chip are also supported, but a
|
||||
YM2413 emulator isn't included with the library due to technical
|
||||
reasons. I have put one of the available YM2413 emulators on my website
|
||||
that can be used directly.
|
||||
|
||||
|
||||
Modular construction
|
||||
--------------------
|
||||
The library is made of many fairly independent modules. If you're using
|
||||
only one music file emulator, you can eliminate many of the library
|
||||
sources from your program. Refer to the files list in readme.txt to get
|
||||
a general idea of what can be removed, and be sure to edit GME_TYPE_LIST
|
||||
(see "Emulator types" above). Post to the forum if you'd like me to put
|
||||
together a smaller version for a particular use, as this only takes me a
|
||||
few minutes to do.
|
||||
|
||||
If you want to use one of the individual sound chip emulators (or CPU
|
||||
cores) in your own console emulator, first check the libraries page on
|
||||
my website since I have released several of them as stand alone
|
||||
libraries with included documentation and examples on their use. If you
|
||||
don't find it as a standalone library, contact me and I'll consider
|
||||
separating it.
|
||||
|
||||
The "classic" sound chips use my Blip_Buffer library, which greatly
|
||||
simplifies their implementation and efficiently handles band-limited
|
||||
synthesis. It is also available as a stand alone library with
|
||||
documentation and many examples.
|
||||
|
||||
|
||||
Obscure features
|
||||
----------------
|
||||
The library's flexibility allows many possibilities. Contact me if you
|
||||
want help implementing ideas or removing limitations.
|
||||
|
||||
* Uses no global/static variables, allowing multiple instances of any
|
||||
emulator. This is useful in a music player if you want to allow
|
||||
simultaneous recording or scanning of other tracks while one is already
|
||||
playing. This will also be useful if your platform disallows global
|
||||
data.
|
||||
|
||||
* Emulators that support a custom sound buffer can have *every* voice
|
||||
routed to a different Blip_Buffer, allowing custom processing on each
|
||||
voice. For example you could record a Game Boy track as a 4-channel
|
||||
sound file.
|
||||
|
||||
* Defining BLIP_BUFFER_FAST uses lower quality, less-multiply-intensive
|
||||
synthesis on "classic" emulators, which might help on some really old
|
||||
processors. This significantly lowers sound quality and prevents treble
|
||||
equalization. Try this if your platform's processor isn't fast enough
|
||||
for normal quality. Even on my ten-year-old 400 MHz Mac, this reduces
|
||||
processor usage at most by about 0.6% (from 4% to 3.4%), hardly worth
|
||||
the quality loss.
|
||||
|
||||
|
||||
Solving problems
|
||||
----------------
|
||||
If you're having problems, try the following:
|
||||
|
||||
* If you're getting garbled sound, try this simple siren generator in
|
||||
place of your call to play(). This will quickly tell whether the problem
|
||||
is in the library or in your code.
|
||||
|
||||
static void play_siren( long count, short* out )
|
||||
{
|
||||
static double a, a2;
|
||||
while ( count-- )
|
||||
*out++ = 0x2000 * sin( a += .1 + .05*sin( a2+=.00005 ) );
|
||||
}
|
||||
|
||||
* Enable debugging support in your environment. This enables assertions
|
||||
and other run-time checks.
|
||||
|
||||
* Turn the compiler's optimizer is off. Sometimes an optimizer generates
|
||||
bad code.
|
||||
|
||||
* If multiple threads are being used, ensure that only one at a time is
|
||||
accessing a given set of objects from the library. This library is not
|
||||
in general thread-safe, though independent objects can be used in
|
||||
separate threads.
|
||||
|
||||
* If all else fails, see if the demos work.
|
||||
|
||||
|
||||
Thanks
|
||||
------
|
||||
Big thanks to Chris Moeller (kode54) for help with library testing and
|
||||
feedback, for maintaining the Foobar2000 plugin foo_gep based on it, and
|
||||
for original work on openspc++ that was used when developing Spc_Emu.
|
||||
Brad Martin's excellent OpenSPC SNES DSP emulator worked well from the
|
||||
start. Also thanks to Richard Bannister, Mahendra Tallur, Shazz,
|
||||
nenolod, theHobbit, Johan Samuelsson, and nes6502 for testing, using,
|
||||
and giving feedback for the library in their respective game music
|
||||
players. More recently, Lucas Paul and Michael Pyne have helped nudge the
|
||||
library into a public repository and get its interface more stable for use
|
||||
in shared libraries.
|
||||
@@ -1,4 +1,4 @@
|
||||
// Game_Music_Emu 0.6.0. http://www.slack.net/~ant/
|
||||
// Game_Music_Emu https://bitbucket.org/mpyne/game-music-emu/
|
||||
|
||||
#include "Ay_Apu.h"
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// AY-3-8910 sound chip emulator
|
||||
|
||||
// Game_Music_Emu 0.6.0
|
||||
// Game_Music_Emu https://bitbucket.org/mpyne/game-music-emu/
|
||||
#ifndef AY_APU_H
|
||||
#define AY_APU_H
|
||||
|
||||
|
||||
+51
-58
@@ -1,4 +1,4 @@
|
||||
// Game_Music_Emu 0.6.0. http://www.slack.net/~ant/
|
||||
// Game_Music_Emu https://bitbucket.org/mpyne/game-music-emu/
|
||||
|
||||
/*
|
||||
Last validated with zexall 2006.11.21 5:26 PM
|
||||
@@ -110,7 +110,7 @@ void Ay_Cpu::reset( void* m )
|
||||
#define R16( n, shift, offset )\
|
||||
(*(uint16_t*) ((char*) r16_ - (offset >> (shift - 1)) + ((n) >> (shift - 1))))
|
||||
|
||||
#define CASE5( a, b, c, d, e ) case 0x##a:case 0x##b:case 0x##c:case 0x##d:case 0x##e
|
||||
#define CASE5( a, b, c, d, e ) /* FALLTHRU */ case 0x##a:case 0x##b:case 0x##c:case 0x##d:case 0x##e
|
||||
#define CASE6( a, b, c, d, e, f ) CASE5( a, b, c, d, e ): case 0x##f
|
||||
#define CASE7( a, b, c, d, e, f, g ) CASE6( a, b, c, d, e, f ): case 0x##g
|
||||
#define CASE8( a, b, c, d, e, f, g, h ) CASE7( a, b, c, d, e, f, g ): case 0x##h
|
||||
@@ -136,11 +136,6 @@ static byte const ed_dd_timing [0x100] = {
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
};
|
||||
|
||||
// even on x86, using short and unsigned char was slower
|
||||
typedef int fint16;
|
||||
typedef unsigned fuint16;
|
||||
typedef unsigned fuint8;
|
||||
|
||||
bool Ay_Cpu::run( cpu_time_t end_time )
|
||||
{
|
||||
set_end_time( end_time );
|
||||
@@ -148,8 +143,6 @@ bool Ay_Cpu::run( cpu_time_t end_time )
|
||||
this->state = &s;
|
||||
bool warning = false;
|
||||
|
||||
typedef BOOST::int8_t int8_t;
|
||||
|
||||
union {
|
||||
regs_t rg;
|
||||
pairs_t rp;
|
||||
@@ -160,10 +153,10 @@ bool Ay_Cpu::run( cpu_time_t end_time )
|
||||
|
||||
cpu_time_t s_time = s.time;
|
||||
uint8_t* const mem = this->mem; // cache
|
||||
fuint16 pc = r.pc;
|
||||
fuint16 sp = r.sp;
|
||||
fuint16 ix = r.ix; // TODO: keep in memory for direct access?
|
||||
fuint16 iy = r.iy;
|
||||
uint16_t pc = r.pc;
|
||||
uint16_t sp = r.sp;
|
||||
uint16_t ix = r.ix; // TODO: keep in memory for direct access?
|
||||
uint16_t iy = r.iy;
|
||||
int flags = r.b.flags;
|
||||
|
||||
goto loop;
|
||||
@@ -182,7 +175,7 @@ loop:
|
||||
check( (unsigned) ix < 0x10000 );
|
||||
check( (unsigned) iy < 0x10000 );
|
||||
|
||||
fuint8 opcode;
|
||||
uint8_t opcode;
|
||||
opcode = READ_PROG( pc );
|
||||
pc++;
|
||||
|
||||
@@ -206,7 +199,7 @@ loop:
|
||||
11,10,10, 4,17,11, 7,11,11, 6,10, 4,17, 8, 7,11, // F
|
||||
};
|
||||
|
||||
fuint16 data;
|
||||
uint16_t data;
|
||||
data = base_timing [opcode];
|
||||
if ( (s_time += data) >= 0 )
|
||||
goto possibly_out_of_time;
|
||||
@@ -262,7 +255,7 @@ possibly_out_of_time:
|
||||
goto loop;
|
||||
|
||||
case 0x3A:{// LD A,(addr)
|
||||
fuint16 addr = GET_ADDR();
|
||||
uint16_t addr = GET_ADDR();
|
||||
pc += 2;
|
||||
rg.a = READ( addr );
|
||||
goto loop;
|
||||
@@ -277,7 +270,7 @@ possibly_out_of_time:
|
||||
|
||||
// JR
|
||||
#define JR( cond ) {\
|
||||
int disp = (BOOST::int8_t) data;\
|
||||
int disp = (int8_t) data;\
|
||||
pc++;\
|
||||
if ( !(cond) )\
|
||||
goto jr_not_taken;\
|
||||
@@ -349,7 +342,7 @@ possibly_out_of_time:
|
||||
|
||||
case 0xCD:{// CALL addr
|
||||
call_taken:
|
||||
fuint16 addr = pc + 2;
|
||||
uint16_t addr = pc + 2;
|
||||
pc = GET_ADDR();
|
||||
sp = uint16_t (sp - 2);
|
||||
WRITE_WORD( sp, addr );
|
||||
@@ -366,7 +359,7 @@ possibly_out_of_time:
|
||||
CASE7( C7, CF, D7, DF, E7, EF, F7 ):
|
||||
data = pc;
|
||||
pc = opcode & 0x38;
|
||||
goto push_data;
|
||||
goto push_data; /* fallthrough */
|
||||
|
||||
// PUSH/POP
|
||||
case 0xF5: // PUSH AF
|
||||
@@ -398,7 +391,7 @@ possibly_out_of_time:
|
||||
// ADC/ADD/SBC/SUB
|
||||
case 0x96: // SUB (HL)
|
||||
case 0x86: // ADD (HL)
|
||||
flags &= ~C01;
|
||||
flags &= ~C01; /* fallthrough */
|
||||
case 0x9E: // SBC (HL)
|
||||
case 0x8E: // ADC (HL)
|
||||
data = READ( rp.hl );
|
||||
@@ -406,7 +399,7 @@ possibly_out_of_time:
|
||||
|
||||
case 0xD6: // SUB A,imm
|
||||
case 0xC6: // ADD imm
|
||||
flags &= ~C01;
|
||||
flags &= ~C01; /* fallthrough */
|
||||
case 0xDE: // SBC A,imm
|
||||
case 0xCE: // ADC imm
|
||||
pc++;
|
||||
@@ -414,7 +407,7 @@ possibly_out_of_time:
|
||||
|
||||
CASE7( 90, 91, 92, 93, 94, 95, 97 ): // SUB r
|
||||
CASE7( 80, 81, 82, 83, 84, 85, 87 ): // ADD r
|
||||
flags &= ~C01;
|
||||
flags &= ~C01; /* fallthrough */
|
||||
CASE7( 98, 99, 9A, 9B, 9C, 9D, 9F ): // SBC r
|
||||
CASE7( 88, 89, 8A, 8B, 8C, 8D, 8F ): // ADC r
|
||||
data = R8( opcode & 7, 0 );
|
||||
@@ -659,21 +652,21 @@ possibly_out_of_time:
|
||||
goto loop;
|
||||
|
||||
case 0x2A:{// LD HL,(addr)
|
||||
fuint16 addr = GET_ADDR();
|
||||
uint16_t addr = GET_ADDR();
|
||||
pc += 2;
|
||||
rp.hl = READ_WORD( addr );
|
||||
goto loop;
|
||||
}
|
||||
|
||||
case 0x32:{// LD (addr),A
|
||||
fuint16 addr = GET_ADDR();
|
||||
uint16_t addr = GET_ADDR();
|
||||
pc += 2;
|
||||
WRITE( addr, rg.a );
|
||||
goto loop;
|
||||
}
|
||||
|
||||
case 0x22:{// LD (addr),HL
|
||||
fuint16 addr = GET_ADDR();
|
||||
uint16_t addr = GET_ADDR();
|
||||
pc += 2;
|
||||
WRITE_WORD( addr, rp.hl );
|
||||
goto loop;
|
||||
@@ -696,7 +689,7 @@ possibly_out_of_time:
|
||||
// Rotate
|
||||
|
||||
case 0x07:{// RLCA
|
||||
fuint16 temp = rg.a;
|
||||
uint16_t temp = rg.a;
|
||||
temp = (temp << 1) | (temp >> 7);
|
||||
flags = (flags & (S80 | Z40 | P04)) |
|
||||
(temp & (F20 | F08 | C01));
|
||||
@@ -705,7 +698,7 @@ possibly_out_of_time:
|
||||
}
|
||||
|
||||
case 0x0F:{// RRCA
|
||||
fuint16 temp = rg.a;
|
||||
uint16_t temp = rg.a;
|
||||
flags = (flags & (S80 | Z40 | P04)) |
|
||||
(temp & C01);
|
||||
temp = (temp << 7) | (temp >> 1);
|
||||
@@ -724,7 +717,7 @@ possibly_out_of_time:
|
||||
}
|
||||
|
||||
case 0x1F:{// RRA
|
||||
fuint16 temp = (flags << 7) | (rg.a >> 1);
|
||||
uint16_t temp = (flags << 7) | (rg.a >> 1);
|
||||
flags = (flags & (S80 | Z40 | P04)) |
|
||||
(temp & (F20 | F08)) |
|
||||
(rg.a & C01);
|
||||
@@ -734,7 +727,7 @@ possibly_out_of_time:
|
||||
|
||||
// Misc
|
||||
case 0x2F:{// CPL
|
||||
fuint16 temp = ~rg.a;
|
||||
uint16_t temp = ~rg.a;
|
||||
flags = (flags & (S80 | Z40 | P04 | C01)) |
|
||||
(temp & (F20 | F08)) |
|
||||
(H10 | N02);
|
||||
@@ -760,21 +753,21 @@ possibly_out_of_time:
|
||||
goto loop;
|
||||
|
||||
case 0xE3:{// EX (SP),HL
|
||||
fuint16 temp = READ_WORD( sp );
|
||||
uint16_t temp = READ_WORD( sp );
|
||||
WRITE_WORD( sp, rp.hl );
|
||||
rp.hl = temp;
|
||||
goto loop;
|
||||
}
|
||||
|
||||
case 0xEB:{// EX DE,HL
|
||||
fuint16 temp = rp.hl;
|
||||
uint16_t temp = rp.hl;
|
||||
rp.hl = rp.de;
|
||||
rp.de = temp;
|
||||
goto loop;
|
||||
}
|
||||
|
||||
case 0xD9:{// EXX DE,HL
|
||||
fuint16 temp = r.alt.w.bc;
|
||||
uint16_t temp = r.alt.w.bc;
|
||||
r.alt.w.bc = rp.bc;
|
||||
rp.bc = temp;
|
||||
|
||||
@@ -815,7 +808,7 @@ possibly_out_of_time:
|
||||
// Rotate left
|
||||
|
||||
#define RLC( read, write ) {\
|
||||
fuint8 result = read;\
|
||||
uint8_t result = read;\
|
||||
result = uint8_t (result << 1) | (result >> 7);\
|
||||
flags = SZ28P( result ) | (result & C01);\
|
||||
write;\
|
||||
@@ -834,7 +827,7 @@ possibly_out_of_time:
|
||||
}
|
||||
|
||||
#define RL( read, write ) {\
|
||||
fuint16 result = (read << 1) | (flags & C01);\
|
||||
uint16_t result = (read << 1) | (flags & C01);\
|
||||
flags = SZ28PC( result );\
|
||||
write;\
|
||||
goto loop;\
|
||||
@@ -852,7 +845,7 @@ possibly_out_of_time:
|
||||
}
|
||||
|
||||
#define SLA( read, add, write ) {\
|
||||
fuint16 result = (read << 1) | add;\
|
||||
uint16_t result = (read << 1) | add;\
|
||||
flags = SZ28PC( result );\
|
||||
write;\
|
||||
goto loop;\
|
||||
@@ -883,7 +876,7 @@ possibly_out_of_time:
|
||||
// Rotate right
|
||||
|
||||
#define RRC( read, write ) {\
|
||||
fuint8 result = read;\
|
||||
uint8_t result = read;\
|
||||
flags = result & C01;\
|
||||
result = uint8_t (result << 7) | (result >> 1);\
|
||||
flags |= SZ28P( result );\
|
||||
@@ -903,8 +896,8 @@ possibly_out_of_time:
|
||||
}
|
||||
|
||||
#define RR( read, write ) {\
|
||||
fuint8 result = read;\
|
||||
fuint8 temp = result & C01;\
|
||||
uint8_t result = read;\
|
||||
uint8_t temp = result & C01;\
|
||||
result = uint8_t (flags << 7) | (result >> 1);\
|
||||
flags = SZ28P( result ) | temp;\
|
||||
write;\
|
||||
@@ -923,7 +916,7 @@ possibly_out_of_time:
|
||||
}
|
||||
|
||||
#define SRA( read, write ) {\
|
||||
fuint8 result = read;\
|
||||
uint8_t result = read;\
|
||||
flags = result & C01;\
|
||||
result = (result & 0x80) | (result >> 1);\
|
||||
flags |= SZ28P( result );\
|
||||
@@ -943,7 +936,7 @@ possibly_out_of_time:
|
||||
}
|
||||
|
||||
#define SRL( read, write ) {\
|
||||
fuint8 result = read;\
|
||||
uint8_t result = read;\
|
||||
flags = result & C01;\
|
||||
result >>= 1;\
|
||||
flags |= SZ28P( result );\
|
||||
@@ -1069,7 +1062,7 @@ possibly_out_of_time:
|
||||
flags = (flags & C01) | SZ28P( temp );
|
||||
goto loop;
|
||||
}
|
||||
|
||||
|
||||
case 0x71: // OUT (C),0
|
||||
rg.flags = 0;
|
||||
CASE7( 41, 49, 51, 59, 61, 69, 79 ): // OUT (C),r
|
||||
@@ -1084,7 +1077,7 @@ possibly_out_of_time:
|
||||
case 0x43: // LD (ADDR),BC
|
||||
case 0x53: // LD (ADDR),DE
|
||||
temp = R16( data, 4, 0x43 );
|
||||
fuint16 addr = GET_ADDR();
|
||||
uint16_t addr = GET_ADDR();
|
||||
pc += 2;
|
||||
WRITE_WORD( addr, temp );
|
||||
goto loop;
|
||||
@@ -1092,21 +1085,21 @@ possibly_out_of_time:
|
||||
|
||||
case 0x4B: // LD BC,(ADDR)
|
||||
case 0x5B:{// LD DE,(ADDR)
|
||||
fuint16 addr = GET_ADDR();
|
||||
uint16_t addr = GET_ADDR();
|
||||
pc += 2;
|
||||
R16( data, 4, 0x4B ) = READ_WORD( addr );
|
||||
goto loop;
|
||||
}
|
||||
|
||||
case 0x7B:{// LD SP,(ADDR)
|
||||
fuint16 addr = GET_ADDR();
|
||||
uint16_t addr = GET_ADDR();
|
||||
pc += 2;
|
||||
sp = READ_WORD( addr );
|
||||
goto loop;
|
||||
}
|
||||
|
||||
case 0x67:{// RRD
|
||||
fuint8 temp = READ( rp.hl );
|
||||
uint8_t temp = READ( rp.hl );
|
||||
WRITE( rp.hl, (rg.a << 4) | (temp >> 4) );
|
||||
temp = (rg.a & 0xF0) | (temp & 0x0F);
|
||||
flags = (flags & C01) | SZ28P( temp );
|
||||
@@ -1115,7 +1108,7 @@ possibly_out_of_time:
|
||||
}
|
||||
|
||||
case 0x6F:{// RLD
|
||||
fuint8 temp = READ( rp.hl );
|
||||
uint8_t temp = READ( rp.hl );
|
||||
WRITE( rp.hl, (temp << 4) | (rg.a & 0x0F) );
|
||||
temp = (rg.a & 0xF0) | (temp >> 4);
|
||||
flags = (flags & C01) | SZ28P( temp );
|
||||
@@ -1139,7 +1132,7 @@ possibly_out_of_time:
|
||||
case 0xA1: // CPI
|
||||
case 0xB1: // CPIR
|
||||
inc = +1;
|
||||
fuint16 addr = rp.hl;
|
||||
uint16_t addr = rp.hl;
|
||||
rp.hl = addr + inc;
|
||||
int temp = READ( addr );
|
||||
|
||||
@@ -1172,7 +1165,7 @@ possibly_out_of_time:
|
||||
case 0xA0: // LDI
|
||||
case 0xB0: // LDIR
|
||||
inc = +1;
|
||||
fuint16 addr = rp.hl;
|
||||
uint16_t addr = rp.hl;
|
||||
rp.hl = addr + inc;
|
||||
int temp = READ( addr );
|
||||
|
||||
@@ -1204,7 +1197,7 @@ possibly_out_of_time:
|
||||
case 0xA3: // OUTI
|
||||
case 0xB3: // OTIR
|
||||
inc = +1;
|
||||
fuint16 addr = rp.hl;
|
||||
uint16_t addr = rp.hl;
|
||||
rp.hl = addr + inc;
|
||||
int temp = READ( addr );
|
||||
|
||||
@@ -1230,7 +1223,7 @@ possibly_out_of_time:
|
||||
case 0xB2: // INIR
|
||||
inc = +1;
|
||||
|
||||
fuint16 addr = rp.hl;
|
||||
uint16_t addr = rp.hl;
|
||||
rp.hl = addr + inc;
|
||||
|
||||
int temp = IN( rp.bc );
|
||||
@@ -1295,7 +1288,7 @@ possibly_out_of_time:
|
||||
|
||||
//////////////////////////////////////// DD/FD prefix
|
||||
{
|
||||
fuint16 ixy;
|
||||
uint16_t ixy;
|
||||
case 0xDD:
|
||||
ixy = ix;
|
||||
goto ix_prefix;
|
||||
@@ -1316,7 +1309,7 @@ possibly_out_of_time:
|
||||
|
||||
case 0x96: // SUB (IXY+disp)
|
||||
case 0x86: // ADD (IXY+disp)
|
||||
flags &= ~C01;
|
||||
flags &= ~C01; /*fallthrough*/
|
||||
case 0x9E: // SBC (IXY+disp)
|
||||
case 0x8E: // ADC (IXY+disp)
|
||||
pc++;
|
||||
@@ -1326,7 +1319,7 @@ possibly_out_of_time:
|
||||
|
||||
case 0x94: // SUB HXY
|
||||
case 0x84: // ADD HXY
|
||||
flags &= ~C01;
|
||||
flags &= ~C01; /*fallthrough*/
|
||||
case 0x9C: // SBC HXY
|
||||
case 0x8C: // ADC HXY
|
||||
opcode = data;
|
||||
@@ -1335,7 +1328,7 @@ possibly_out_of_time:
|
||||
|
||||
case 0x95: // SUB LXY
|
||||
case 0x85: // ADD LXY
|
||||
flags &= ~C01;
|
||||
flags &= ~C01; /* fallthrough */
|
||||
case 0x9D: // SBC LXY
|
||||
case 0x8D: // ADC LXY
|
||||
opcode = data;
|
||||
@@ -1490,7 +1483,7 @@ possibly_out_of_time:
|
||||
goto loop;
|
||||
|
||||
case 0x22:{// LD (ADDR),IXY
|
||||
fuint16 addr = GET_ADDR();
|
||||
uint16_t addr = GET_ADDR();
|
||||
pc += 2;
|
||||
WRITE_WORD( addr, ixy );
|
||||
goto loop;
|
||||
@@ -1502,7 +1495,7 @@ possibly_out_of_time:
|
||||
goto set_ixy;
|
||||
|
||||
case 0x2A:{// LD IXY,(addr)
|
||||
fuint16 addr = GET_ADDR();
|
||||
uint16_t addr = GET_ADDR();
|
||||
ixy = READ_WORD( addr );
|
||||
pc += 2;
|
||||
goto set_ixy;
|
||||
@@ -1526,7 +1519,7 @@ possibly_out_of_time:
|
||||
case 0x3E: goto srl_data_addr; // SRL (IXY)
|
||||
|
||||
CASE8( 46, 4E, 56, 5E, 66, 6E, 76, 7E ):{// BIT b,(IXY+disp)
|
||||
fuint8 temp = READ( data );
|
||||
uint8_t temp = READ( data );
|
||||
int masked = temp & 1 << (data2 >> 3 & 7);
|
||||
flags = (flags & C01) | H10 |
|
||||
(masked & S80) |
|
||||
@@ -1628,7 +1621,7 @@ possibly_out_of_time:
|
||||
goto loop;
|
||||
|
||||
case 0xE3:{// EX (SP),IXY
|
||||
fuint16 temp = READ_WORD( sp );
|
||||
uint16_t temp = READ_WORD( sp );
|
||||
WRITE_WORD( sp, ixy );
|
||||
ixy = temp;
|
||||
goto set_ixy;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// Z80 CPU emulator
|
||||
|
||||
// Game_Music_Emu 0.6.0
|
||||
// Game_Music_Emu https://bitbucket.org/mpyne/game-music-emu/
|
||||
#ifndef AY_CPU_H
|
||||
#define AY_CPU_H
|
||||
|
||||
@@ -28,9 +28,6 @@ public:
|
||||
void set_time( cpu_time_t t ) { state->time = t - state->base; }
|
||||
void adjust_time( int delta ) { state->time += delta; }
|
||||
|
||||
typedef BOOST::uint8_t uint8_t;
|
||||
typedef BOOST::uint16_t uint16_t;
|
||||
|
||||
#if BLARGG_BIG_ENDIAN
|
||||
struct regs_t { uint8_t b, c, d, e, h, l, flags, a; };
|
||||
#else
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
// Game_Music_Emu 0.6.0. http://www.slack.net/~ant/
|
||||
// Game_Music_Emu https://bitbucket.org/mpyne/game-music-emu/
|
||||
|
||||
#include "Ay_Emu.h"
|
||||
|
||||
#include "blargg_endian.h"
|
||||
#include <string.h>
|
||||
|
||||
#include <algorithm> // min, max
|
||||
|
||||
/* Copyright (C) 2006 Shay Green. This module is free software; you
|
||||
can redistribute it and/or modify it under the terms of the GNU Lesser
|
||||
General Public License as published by the Free Software Foundation; either
|
||||
@@ -24,6 +26,9 @@ long const cpc_clock = 2000000;
|
||||
unsigned const ram_start = 0x4000;
|
||||
int const osc_count = Ay_Apu::osc_count + 1;
|
||||
|
||||
using std::min;
|
||||
using std::max;
|
||||
|
||||
Ay_Emu::Ay_Emu()
|
||||
{
|
||||
beeper_output = 0;
|
||||
@@ -50,7 +55,7 @@ static byte const* get_data( Ay_Emu::file_t const& file, byte const* ptr, int mi
|
||||
long pos = ptr - (byte const*) file.header;
|
||||
long file_size = file.end - (byte const*) file.header;
|
||||
assert( (unsigned long) pos <= (unsigned long) file_size - 2 );
|
||||
int offset = (BOOST::int16_t) get_be16( ptr );
|
||||
int offset = (int16_t) get_be16( ptr );
|
||||
if ( !offset || blargg_ulong (pos + offset) > blargg_ulong (file_size - min_size) )
|
||||
return 0;
|
||||
return ptr + offset;
|
||||
@@ -117,7 +122,7 @@ static Music_Emu* new_ay_emu () { return BLARGG_NEW Ay_Emu ; }
|
||||
static Music_Emu* new_ay_file() { return BLARGG_NEW Ay_File; }
|
||||
|
||||
static gme_type_t_ const gme_ay_type_ = { "ZX Spectrum", 0, &new_ay_emu, &new_ay_file, "AY", 1 };
|
||||
gme_type_t const gme_ay_type = &gme_ay_type_;
|
||||
extern gme_type_t const gme_ay_type = &gme_ay_type_;
|
||||
|
||||
// Setup
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// Sinclair Spectrum AY music file emulator
|
||||
|
||||
// Game_Music_Emu 0.6.0
|
||||
// Game_Music_Emu https://bitbucket.org/mpyne/game-music-emu/
|
||||
#ifndef AY_EMU_H
|
||||
#define AY_EMU_H
|
||||
|
||||
|
||||
@@ -231,6 +231,11 @@ private:
|
||||
public:
|
||||
Blip_Synth() : impl( impulses, quality ) { }
|
||||
#endif
|
||||
|
||||
// disable broken defaulted constructors, Blip_Synth_ isn't safe to move/copy
|
||||
Blip_Synth<quality, range> (const Blip_Synth<quality, range> &) = delete;
|
||||
Blip_Synth<quality, range> ( Blip_Synth<quality, range> &&) = delete;
|
||||
Blip_Synth<quality, range>& operator=(const Blip_Synth<quality, range> &) = delete;
|
||||
};
|
||||
|
||||
// Low-pass equalization parameters
|
||||
|
||||
+70
-11
@@ -14,6 +14,15 @@ set(libgme_SRCS Blip_Buffer.cpp
|
||||
Music_Emu.cpp
|
||||
)
|
||||
|
||||
# static builds need to find static zlib (and static forms of other needed
|
||||
# libraries. Ensure CMake looks only for static libs if we're doing a static
|
||||
# build. See https://stackoverflow.com/a/44738756
|
||||
if(NOT BUILD_SHARED_LIBS)
|
||||
set(CMAKE_FIND_LIBRARY_SUFFIXES ".a")
|
||||
endif()
|
||||
|
||||
find_package(ZLIB QUIET)
|
||||
|
||||
# Ay_Apu is very popular around here
|
||||
if (USE_GME_AY OR USE_GME_KSS)
|
||||
set(libgme_SRCS ${libgme_SRCS}
|
||||
@@ -23,9 +32,25 @@ endif()
|
||||
|
||||
# so is Ym2612_Emu
|
||||
if (USE_GME_VGM OR USE_GME_GYM)
|
||||
set(libgme_SRCS ${libgme_SRCS}
|
||||
Ym2612_Emu.cpp
|
||||
)
|
||||
if(GME_YM2612_EMU STREQUAL "Nuked")
|
||||
add_definitions(-DVGM_YM2612_NUKED)
|
||||
set(libgme_SRCS ${libgme_SRCS}
|
||||
Ym2612_Nuked.cpp
|
||||
)
|
||||
message("VGM/GYM: Nuked OPN2 emulator will be used")
|
||||
elseif(GME_YM2612_EMU STREQUAL "MAME")
|
||||
add_definitions(-DVGM_YM2612_MAME)
|
||||
set(libgme_SRCS ${libgme_SRCS}
|
||||
Ym2612_MAME.cpp
|
||||
)
|
||||
message("VGM/GYM: MAME YM2612 emulator will be used")
|
||||
else()
|
||||
add_definitions(-DVGM_YM2612_GENS)
|
||||
set(libgme_SRCS ${libgme_SRCS}
|
||||
Ym2612_GENS.cpp
|
||||
)
|
||||
message("VGM/GYM: GENS 2.10 emulator will be used")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# But none are as popular as Sms_Apu
|
||||
@@ -112,6 +137,9 @@ if (USE_GME_SPC)
|
||||
Spc_Emu.cpp
|
||||
Spc_Filter.cpp
|
||||
)
|
||||
if (GME_SPC_ISOLATED_ECHO_BUFFER)
|
||||
add_definitions(-DSPC_ISOLATED_ECHO_BUFFER)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if (USE_GME_VGM)
|
||||
@@ -125,14 +153,13 @@ if (USE_GME_VGM)
|
||||
endif()
|
||||
|
||||
# These headers are part of the generic gme interface.
|
||||
set (EXPORTED_HEADERS gme.h)
|
||||
set (EXPORTED_HEADERS gme.h blargg_source.h)
|
||||
|
||||
# Run during cmake phase, so this is available during make
|
||||
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/gme_types.h.in
|
||||
${CMAKE_CURRENT_BINARY_DIR}/gme_types.h)
|
||||
|
||||
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/libgme.pc.in
|
||||
${CMAKE_CURRENT_BINARY_DIR}/libgme.pc @ONLY)
|
||||
# while building a macOS framework, exported headers must be in the source
|
||||
# list, or the header files aren't copied to the bundle.
|
||||
if (BUILD_FRAMEWORK)
|
||||
set(libgme_SRCS ${libgme_SRCS} ${EXPORTED_HEADERS})
|
||||
endif()
|
||||
|
||||
# On some platforms we may need to change headers or whatnot based on whether
|
||||
# we're building the library or merely using the library. The following is
|
||||
@@ -145,6 +172,18 @@ include_directories(${CMAKE_CURRENT_BINARY_DIR})
|
||||
# Add library to be compiled.
|
||||
add_library(gme ${libgme_SRCS})
|
||||
|
||||
if(ZLIB_FOUND)
|
||||
message(" ** ZLib library located, compressed file formats will be supported")
|
||||
target_compile_definitions(gme PRIVATE -DHAVE_ZLIB_H)
|
||||
target_include_directories(gme PRIVATE ${ZLIB_INCLUDE_DIRS})
|
||||
target_link_libraries(gme ${ZLIB_LIBRARIES})
|
||||
# Is not to be installed though
|
||||
|
||||
set(PKG_CONFIG_ZLIB -lz) # evaluated in libgme.pc.in
|
||||
else()
|
||||
message("ZLib library not found, disabling support for compressed formats such as VGZ")
|
||||
endif()
|
||||
|
||||
# The version is the release. The "soversion" is the API version. As long
|
||||
# as only build fixes are performed (i.e. no backwards-incompatible changes
|
||||
# to the API), the SOVERSION should be the same even when bumping up VERSION.
|
||||
@@ -154,9 +193,29 @@ set_target_properties(gme
|
||||
PROPERTIES VERSION ${GME_VERSION}
|
||||
SOVERSION 0)
|
||||
|
||||
# macOS framework build
|
||||
if(BUILD_FRAMEWORK)
|
||||
set_target_properties(gme
|
||||
PROPERTIES FRAMEWORK TRUE
|
||||
FRAMEWORK_VERSION A
|
||||
MACOSX_FRAMEWORK_IDENTIFIER net.mpyne.gme
|
||||
VERSION ${GME_VERSION}
|
||||
SOVERSION 0
|
||||
PUBLIC_HEADER "${EXPORTED_HEADERS}")
|
||||
endif()
|
||||
|
||||
install(TARGETS gme LIBRARY DESTINATION lib${LIB_SUFFIX}
|
||||
RUNTIME DESTINATION bin # DLL platforms
|
||||
ARCHIVE DESTINATION lib) # DLL platforms
|
||||
ARCHIVE DESTINATION lib # DLL platforms
|
||||
FRAMEWORK DESTINATION /Library/Frameworks) # macOS framework
|
||||
|
||||
|
||||
# Run during cmake phase, so this is available during make
|
||||
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/gme_types.h.in
|
||||
${CMAKE_CURRENT_BINARY_DIR}/gme_types.h)
|
||||
|
||||
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/libgme.pc.in
|
||||
${CMAKE_CURRENT_BINARY_DIR}/libgme.pc @ONLY)
|
||||
|
||||
install(FILES ${EXPORTED_HEADERS} DESTINATION include/gme)
|
||||
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libgme.pc DESTINATION lib${LIB_SUFFIX}/pkgconfig)
|
||||
@@ -1,4 +1,4 @@
|
||||
// Game_Music_Emu 0.6.0. http://www.slack.net/~ant/
|
||||
// Game_Music_Emu https://bitbucket.org/mpyne/game-music-emu/
|
||||
|
||||
#include "Classic_Emu.h"
|
||||
|
||||
@@ -54,6 +54,12 @@ blargg_err_t Classic_Emu::set_sample_rate_( long rate )
|
||||
return buf->set_sample_rate( rate, 1000 / 20 );
|
||||
}
|
||||
|
||||
blargg_err_t Classic_Emu::set_multi_channel ( bool is_enabled )
|
||||
{
|
||||
RETURN_ERR( Music_Emu::set_multi_channel_( is_enabled ) );
|
||||
return 0;
|
||||
}
|
||||
|
||||
void Classic_Emu::mute_voices_( int mask )
|
||||
{
|
||||
Music_Emu::mute_voices_( mask );
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// Common aspects of emulators which use Blip_Buffer for sound output
|
||||
|
||||
// Game_Music_Emu 0.6.0
|
||||
// Game_Music_Emu https://bitbucket.org/mpyne/game-music-emu/
|
||||
#ifndef CLASSIC_EMU_H
|
||||
#define CLASSIC_EMU_H
|
||||
|
||||
@@ -13,6 +13,7 @@ public:
|
||||
Classic_Emu();
|
||||
~Classic_Emu();
|
||||
void set_buffer( Multi_Buffer* );
|
||||
blargg_err_t set_multi_channel( bool is_enabled ) override;
|
||||
protected:
|
||||
// Services
|
||||
enum { wave_type = 0x100, noise_type = 0x200, mixed_type = wave_type | noise_type };
|
||||
|
||||
+222
-100
@@ -6,6 +6,7 @@
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <algorithm>
|
||||
|
||||
/* Copyright (C) 2005-2006 Shay Green. This module is free software; you
|
||||
can redistribute it and/or modify it under the terms of the GNU Lesser
|
||||
@@ -20,6 +21,16 @@ Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */
|
||||
|
||||
#include "blargg_source.h"
|
||||
|
||||
#ifdef HAVE_ZLIB_H
|
||||
#include <zlib.h>
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
static const unsigned char gz_magic[2] = {0x1f, 0x8b}; /* gzip magic header */
|
||||
#endif /* HAVE_ZLIB_H */
|
||||
|
||||
using std::min;
|
||||
using std::max;
|
||||
|
||||
const char Data_Reader::eof_error [] = "Unexpected end of file";
|
||||
|
||||
#define RETURN_VALIDITY_CHECK( cond ) \
|
||||
@@ -34,10 +45,10 @@ blargg_err_t Data_Reader::read( void* p, long s )
|
||||
{
|
||||
if ( result >= 0 && result < s )
|
||||
return eof_error;
|
||||
|
||||
|
||||
return "Read error";
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -106,11 +117,11 @@ long Remaining_Reader::read_first( void* out, long count )
|
||||
long first = header_end - header;
|
||||
if ( first )
|
||||
{
|
||||
if ( first > count )
|
||||
if ( first > count || first < 0 )
|
||||
first = count;
|
||||
void const* old = header;
|
||||
header += first;
|
||||
memcpy( out, old, first );
|
||||
memcpy( out, old, (size_t) first );
|
||||
}
|
||||
return first;
|
||||
}
|
||||
@@ -142,36 +153,128 @@ blargg_err_t Remaining_Reader::read( void* out, long count )
|
||||
// Mem_File_Reader
|
||||
|
||||
Mem_File_Reader::Mem_File_Reader( const void* p, long s ) :
|
||||
begin( (const char*) p ),
|
||||
size_( max( 0l, s ) )
|
||||
m_begin( (const char*) p ),
|
||||
m_size( max( 0l, s ) ),
|
||||
m_pos( 0l )
|
||||
{
|
||||
pos = 0;
|
||||
#ifdef HAVE_ZLIB_H
|
||||
if( !m_begin )
|
||||
return;
|
||||
|
||||
if ( gz_decompress() )
|
||||
{
|
||||
debug_printf( "Loaded compressed data\n" );
|
||||
m_ownedPtr = true;
|
||||
}
|
||||
#endif /* HAVE_ZLIB_H */
|
||||
}
|
||||
|
||||
long Mem_File_Reader::size() const { return size_; }
|
||||
|
||||
#ifdef HAVE_ZLIB_H
|
||||
Mem_File_Reader::~Mem_File_Reader()
|
||||
{
|
||||
if ( m_ownedPtr )
|
||||
free( const_cast<char*>( m_begin ) ); // see gz_compress for the malloc
|
||||
}
|
||||
#endif
|
||||
|
||||
long Mem_File_Reader::size() const { return m_size; }
|
||||
|
||||
long Mem_File_Reader::read_avail( void* p, long s )
|
||||
{
|
||||
long r = remain();
|
||||
s = max( 0l, s );
|
||||
if ( s > r )
|
||||
if ( s > r || s < 0 )
|
||||
s = r;
|
||||
memcpy( p, begin + pos, s );
|
||||
pos += s;
|
||||
memcpy( p, m_begin + m_pos, static_cast<size_t>(s) );
|
||||
m_pos += s;
|
||||
return s;
|
||||
}
|
||||
|
||||
long Mem_File_Reader::tell() const { return pos; }
|
||||
long Mem_File_Reader::tell() const { return m_pos; }
|
||||
|
||||
blargg_err_t Mem_File_Reader::seek( long n )
|
||||
{
|
||||
RETURN_VALIDITY_CHECK( n >= 0 );
|
||||
if ( n > size_ )
|
||||
if ( n > m_size )
|
||||
return eof_error;
|
||||
pos = n;
|
||||
m_pos = n;
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef HAVE_ZLIB_H
|
||||
|
||||
bool Mem_File_Reader::gz_decompress()
|
||||
{
|
||||
if ( m_size >= 2 && memcmp(m_begin, gz_magic, 2) != 0 )
|
||||
{
|
||||
/* Don't try to decompress non-GZ files, just assign input pointer */
|
||||
return false;
|
||||
}
|
||||
|
||||
using vec_size = size_t;
|
||||
const vec_size full_length = static_cast<vec_size>( m_size );
|
||||
const vec_size half_length = static_cast<vec_size>( m_size / 2 );
|
||||
|
||||
// We use malloc/friends here so we can realloc to grow buffer if needed
|
||||
char *raw_data = reinterpret_cast<char *> ( malloc( full_length ) );
|
||||
size_t raw_data_size = full_length;
|
||||
if ( !raw_data )
|
||||
return false;
|
||||
|
||||
z_stream strm;
|
||||
strm.next_in = const_cast<Bytef *>( reinterpret_cast<const Bytef *>( m_begin ) );
|
||||
strm.avail_in = static_cast<uInt>( m_size );
|
||||
strm.total_out = 0;
|
||||
strm.zalloc = Z_NULL;
|
||||
strm.zfree = Z_NULL;
|
||||
|
||||
bool done = false;
|
||||
|
||||
// Adding 16 sets bit 4, which enables zlib to auto-detect the
|
||||
// header.
|
||||
if ( inflateInit2(&strm, (16 + MAX_WBITS)) != Z_OK )
|
||||
{
|
||||
free( raw_data );
|
||||
return false;
|
||||
}
|
||||
|
||||
while ( !done )
|
||||
{
|
||||
/* If our output buffer is too small */
|
||||
if ( strm.total_out >= raw_data_size )
|
||||
{
|
||||
raw_data_size += half_length;
|
||||
raw_data = reinterpret_cast<char *>( realloc( raw_data, raw_data_size ) );
|
||||
if ( !raw_data ) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
strm.next_out = reinterpret_cast<Bytef *>( raw_data + strm.total_out );
|
||||
strm.avail_out = static_cast<uInt>( static_cast<uLong>( raw_data_size ) - strm.total_out );
|
||||
|
||||
/* Inflate another chunk. */
|
||||
int err = inflate( &strm, Z_SYNC_FLUSH );
|
||||
if ( err == Z_STREAM_END )
|
||||
done = true;
|
||||
else if ( err != Z_OK )
|
||||
break;
|
||||
}
|
||||
|
||||
if ( inflateEnd(&strm) != Z_OK )
|
||||
{
|
||||
free( raw_data );
|
||||
return false;
|
||||
}
|
||||
|
||||
m_begin = raw_data;
|
||||
m_size = static_cast<long>( strm.total_out );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
#endif /* HAVE_ZLIB_H */
|
||||
|
||||
|
||||
// Callback_Reader
|
||||
|
||||
Callback_Reader::Callback_Reader( callback_t c, long size, void* d ) :
|
||||
@@ -197,25 +300,72 @@ blargg_err_t Callback_Reader::read( void* out, long count )
|
||||
RETURN_VALIDITY_CHECK( count >= 0 );
|
||||
if ( count > remain_ )
|
||||
return eof_error;
|
||||
return callback( data, out, count );
|
||||
return callback( data, out, (int) count );
|
||||
}
|
||||
|
||||
// Std_File_Reader
|
||||
|
||||
Std_File_Reader::Std_File_Reader() : file_( 0 ) { }
|
||||
#ifdef HAVE_ZLIB_H
|
||||
|
||||
static const char* get_gzip_eof( const char* path, long* eof )
|
||||
{
|
||||
FILE* file = fopen( path, "rb" );
|
||||
if ( !file )
|
||||
return "Couldn't open file";
|
||||
|
||||
unsigned char buf [4];
|
||||
bool found_eof = false;
|
||||
if ( fread( buf, 2, 1, file ) > 0 && buf [0] == 0x1F && buf [1] == 0x8B )
|
||||
{
|
||||
fseek( file, -4, SEEK_END );
|
||||
if ( fread( buf, 4, 1, file ) > 0 ) {
|
||||
*eof = get_le32( buf );
|
||||
found_eof = true;
|
||||
}
|
||||
}
|
||||
if ( !found_eof )
|
||||
{
|
||||
fseek( file, 0, SEEK_END );
|
||||
*eof = ftell( file );
|
||||
}
|
||||
const char* err = (ferror( file ) || feof( file )) ? "Couldn't get file size" : nullptr;
|
||||
fclose( file );
|
||||
return err;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
Std_File_Reader::Std_File_Reader() :
|
||||
file_( nullptr )
|
||||
#ifdef HAVE_ZLIB_H
|
||||
, size_( 0 )
|
||||
#endif
|
||||
{ }
|
||||
|
||||
Std_File_Reader::~Std_File_Reader() { close(); }
|
||||
|
||||
blargg_err_t Std_File_Reader::open( const char* path )
|
||||
{
|
||||
#ifdef HAVE_ZLIB_H
|
||||
// zlib transparently handles uncompressed data if magic header
|
||||
// not present but we still need to grab size
|
||||
RETURN_ERR( get_gzip_eof( path, &size_ ) );
|
||||
file_ = gzopen( path, "rb" );
|
||||
#else
|
||||
file_ = fopen( path, "rb" );
|
||||
#endif
|
||||
|
||||
if ( !file_ )
|
||||
return "Couldn't open file";
|
||||
return 0;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
long Std_File_Reader::size() const
|
||||
{
|
||||
#ifdef HAVE_ZLIB_H
|
||||
if ( file_ )
|
||||
return size_; // Set for both compressed and uncompressed modes
|
||||
#endif
|
||||
long pos = tell();
|
||||
fseek( (FILE*) file_, 0, SEEK_END );
|
||||
long result = tell();
|
||||
@@ -225,25 +375,64 @@ long Std_File_Reader::size() const
|
||||
|
||||
long Std_File_Reader::read_avail( void* p, long s )
|
||||
{
|
||||
return fread( p, 1, max( 0l, s ), (FILE*) file_ );
|
||||
#ifdef HAVE_ZLIB_H
|
||||
if ( file_ && s > 0 && static_cast<unsigned long>(s) <= UINT_MAX ) {
|
||||
return gzread( reinterpret_cast<gzFile>(file_),
|
||||
p, static_cast<unsigned>(s) );
|
||||
}
|
||||
return 0l;
|
||||
#else
|
||||
const size_t readLength = static_cast<size_t>( max( 0l, s ) );
|
||||
const auto result = fread( p, 1, readLength, reinterpret_cast<FILE*>(file_) );
|
||||
return static_cast<long>( result );
|
||||
#endif /* HAVE_ZLIB_H */
|
||||
}
|
||||
|
||||
blargg_err_t Std_File_Reader::read( void* p, long s )
|
||||
{
|
||||
RETURN_VALIDITY_CHECK( s > 0 );
|
||||
if ( s == (long) fread( p, 1, s, (FILE*) file_ ) )
|
||||
RETURN_VALIDITY_CHECK( s > 0 && static_cast<unsigned long>(s) <= UINT_MAX );
|
||||
#ifdef HAVE_ZLIB_H
|
||||
if ( file_ )
|
||||
{
|
||||
const auto &gzfile = reinterpret_cast<gzFile>( file_ );
|
||||
if ( s == gzread( gzfile, p, static_cast<unsigned>( s ) ) )
|
||||
return nullptr;
|
||||
if ( gzeof( gzfile ) )
|
||||
return eof_error;
|
||||
return "Couldn't read from GZ file";
|
||||
}
|
||||
#endif
|
||||
const auto &file = reinterpret_cast<FILE*>( file_ );
|
||||
if ( s == static_cast<long>( fread( p, 1, static_cast<size_t>(s), file ) ) )
|
||||
return 0;
|
||||
if ( feof( (FILE*) file_ ) )
|
||||
if ( feof( file ) )
|
||||
return eof_error;
|
||||
return "Couldn't read from file";
|
||||
}
|
||||
|
||||
long Std_File_Reader::tell() const { return ftell( (FILE*) file_ ); }
|
||||
long Std_File_Reader::tell() const
|
||||
{
|
||||
#ifdef HAVE_ZLIB_H
|
||||
if ( file_ )
|
||||
return gztell( reinterpret_cast<gzFile>( file_ ) );
|
||||
#endif
|
||||
return ftell( reinterpret_cast<FILE*>( file_ ) );
|
||||
}
|
||||
|
||||
blargg_err_t Std_File_Reader::seek( long n )
|
||||
{
|
||||
if ( !fseek( (FILE*) file_, n, SEEK_SET ) )
|
||||
return 0;
|
||||
#ifdef HAVE_ZLIB_H
|
||||
if ( file_ )
|
||||
{
|
||||
if ( gzseek( reinterpret_cast<gzFile>( file_ ), n, SEEK_SET ) >= 0 )
|
||||
return nullptr;
|
||||
if ( n > size_ )
|
||||
return eof_error;
|
||||
return "Error seeking in GZ file";
|
||||
}
|
||||
#endif
|
||||
if ( !fseek( reinterpret_cast<FILE*>( file_ ), n, SEEK_SET ) )
|
||||
return nullptr;
|
||||
if ( n > size() )
|
||||
return eof_error;
|
||||
return "Error seeking in file";
|
||||
@@ -253,79 +442,12 @@ void Std_File_Reader::close()
|
||||
{
|
||||
if ( file_ )
|
||||
{
|
||||
fclose( (FILE*) file_ );
|
||||
file_ = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// Gzip_File_Reader
|
||||
|
||||
#ifdef HAVE_ZLIB_H
|
||||
|
||||
#include "zlib.h"
|
||||
|
||||
static const char* get_gzip_eof( const char* path, long* eof )
|
||||
{
|
||||
FILE* file = fopen( path, "rb" );
|
||||
if ( !file )
|
||||
return "Couldn't open file";
|
||||
|
||||
unsigned char buf [4];
|
||||
if ( fread( buf, 2, 1, file ) > 0 && buf [0] == 0x1F && buf [1] == 0x8B )
|
||||
{
|
||||
fseek( file, -4, SEEK_END );
|
||||
fread( buf, 4, 1, file );
|
||||
*eof = get_le32( buf );
|
||||
}
|
||||
else
|
||||
{
|
||||
fseek( file, 0, SEEK_END );
|
||||
*eof = ftell( file );
|
||||
}
|
||||
const char* err = (ferror( file ) || feof( file )) ? "Couldn't get file size" : 0;
|
||||
fclose( file );
|
||||
return err;
|
||||
}
|
||||
|
||||
Gzip_File_Reader::Gzip_File_Reader() : file_( 0 ) { }
|
||||
|
||||
Gzip_File_Reader::~Gzip_File_Reader() { close(); }
|
||||
|
||||
blargg_err_t Gzip_File_Reader::open( const char* path )
|
||||
{
|
||||
close();
|
||||
|
||||
RETURN_ERR( get_gzip_eof( path, &size_ ) );
|
||||
|
||||
file_ = gzopen( path, "rb" );
|
||||
if ( !file_ )
|
||||
return "Couldn't open file";
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
long Gzip_File_Reader::size() const { return size_; }
|
||||
|
||||
long Gzip_File_Reader::read_avail( void* p, long s ) { return gzread( file_, p, s ); }
|
||||
|
||||
long Gzip_File_Reader::tell() const { return gztell( file_ ); }
|
||||
|
||||
blargg_err_t Gzip_File_Reader::seek( long n )
|
||||
{
|
||||
if ( gzseek( file_, n, SEEK_SET ) >= 0 )
|
||||
return 0;
|
||||
if ( n > size_ )
|
||||
return eof_error;
|
||||
return "Error seeking in file";
|
||||
}
|
||||
|
||||
void Gzip_File_Reader::close()
|
||||
{
|
||||
if ( file_ )
|
||||
{
|
||||
gzclose( file_ );
|
||||
file_ = 0;
|
||||
}
|
||||
}
|
||||
|
||||
gzclose( reinterpret_cast<gzFile>( file_ ) );
|
||||
#else
|
||||
fclose( reinterpret_cast<FILE*>( file_ ) );
|
||||
#endif
|
||||
file_ = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
+23
-27
@@ -6,6 +6,10 @@
|
||||
|
||||
#include "blargg_common.h"
|
||||
|
||||
#ifdef HAVE_ZLIB_H
|
||||
#include <zlib.h>
|
||||
#endif
|
||||
|
||||
// Supports reading and finding out how many bytes are remaining
|
||||
class Data_Reader {
|
||||
public:
|
||||
@@ -65,25 +69,39 @@ public:
|
||||
long tell() const;
|
||||
blargg_err_t seek( long );
|
||||
private:
|
||||
void* file_;
|
||||
void* file_; // Either FILE* or zlib's gzFile
|
||||
#ifdef HAVE_ZLIB_H
|
||||
long size_; // TODO: Fix ABI compat
|
||||
#endif /* HAVE_ZLIB_H */
|
||||
};
|
||||
|
||||
// Treats range of memory as a file
|
||||
class Mem_File_Reader : public File_Reader {
|
||||
public:
|
||||
Mem_File_Reader( const void*, long size );
|
||||
|
||||
#ifdef HAVE_ZLIB_H
|
||||
~Mem_File_Reader( );
|
||||
#endif /* HAVE_ZLIB_H */
|
||||
|
||||
public:
|
||||
long size() const;
|
||||
long read_avail( void*, long );
|
||||
long tell() const;
|
||||
blargg_err_t seek( long );
|
||||
private:
|
||||
const char* const begin;
|
||||
const long size_;
|
||||
long pos;
|
||||
#ifdef HAVE_ZLIB_H
|
||||
bool gz_decompress();
|
||||
#endif /* HAVE_ZLIB_H */
|
||||
|
||||
const char* m_begin;
|
||||
long m_size;
|
||||
long m_pos;
|
||||
#ifdef HAVE_ZLIB_H
|
||||
bool m_ownedPtr = false; // set if we must free m_begin
|
||||
#endif /* HAVE_ZLIB_H */
|
||||
};
|
||||
|
||||
|
||||
// Makes it look like there are only count bytes remaining
|
||||
class Subset_Reader : public Data_Reader {
|
||||
public:
|
||||
@@ -128,26 +146,4 @@ private:
|
||||
long remain_;
|
||||
};
|
||||
|
||||
#ifdef HAVE_ZLIB_H
|
||||
#include <zlib.h>
|
||||
|
||||
// Gzip compressed file reader
|
||||
class Gzip_File_Reader : public File_Reader {
|
||||
public:
|
||||
blargg_err_t open( const char* path );
|
||||
void close();
|
||||
|
||||
public:
|
||||
Gzip_File_Reader();
|
||||
~Gzip_File_Reader();
|
||||
long size() const;
|
||||
long read_avail( void*, long );
|
||||
long tell() const;
|
||||
blargg_err_t seek( long );
|
||||
private:
|
||||
gzFile file_;
|
||||
long size_;
|
||||
};
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -1,4 +1,4 @@
|
||||
// Game_Music_Emu 0.6.0. http://www.slack.net/~ant/
|
||||
// Game_Music_Emu https://bitbucket.org/mpyne/game-music-emu/
|
||||
|
||||
#include "Dual_Resampler.h"
|
||||
|
||||
@@ -68,9 +68,13 @@ void Dual_Resampler::play_frame_( Blip_Buffer& blip_buf, dsample_t* out )
|
||||
assert( blip_buf.samples_avail() == pair_count );
|
||||
|
||||
resampler.write( new_count );
|
||||
|
||||
|
||||
#ifdef NDEBUG // Avoid warning when asserts are disabled
|
||||
resampler.read( sample_buf.begin(), sample_buf_size );
|
||||
#else
|
||||
long count = resampler.read( sample_buf.begin(), sample_buf_size );
|
||||
assert( count == (long) sample_buf_size );
|
||||
#endif
|
||||
|
||||
mix_samples( blip_buf, out );
|
||||
blip_buf.remove_samples( pair_count );
|
||||
@@ -118,12 +122,12 @@ void Dual_Resampler::mix_samples( Blip_Buffer& blip_buf, dsample_t* out )
|
||||
{
|
||||
int s = sn.read();
|
||||
blargg_long l = (blargg_long) in [0] * 2 + s;
|
||||
if ( (BOOST::int16_t) l != l )
|
||||
if ( (int16_t) l != l )
|
||||
l = 0x7FFF - (l >> 24);
|
||||
|
||||
sn.next( bass );
|
||||
blargg_long r = (blargg_long) in [1] * 2 + s;
|
||||
if ( (BOOST::int16_t) r != r )
|
||||
if ( (int16_t) r != r )
|
||||
r = 0x7FFF - (r >> 24);
|
||||
|
||||
in += 2;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// Combination of Fir_Resampler and Blip_Buffer mixing. Used by Sega FM emulators.
|
||||
|
||||
// Game_Music_Emu 0.6.0
|
||||
// Game_Music_Emu https://bitbucket.org/mpyne/game-music-emu/
|
||||
#ifndef DUAL_RESAMPLER_H
|
||||
#define DUAL_RESAMPLER_H
|
||||
|
||||
|
||||
+227
-157
@@ -1,8 +1,9 @@
|
||||
// Game_Music_Emu 0.6.0. http://www.slack.net/~ant/
|
||||
// Game_Music_Emu https://bitbucket.org/mpyne/game-music-emu/
|
||||
|
||||
#include "Effects_Buffer.h"
|
||||
|
||||
#include <string.h>
|
||||
#include <algorithm>
|
||||
|
||||
/* Copyright (C) 2003-2006 Shay Green. This module is free software; you
|
||||
can redistribute it and/or modify it under the terms of the GNU Lesser
|
||||
@@ -23,6 +24,9 @@ Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */
|
||||
|
||||
typedef blargg_long fixed_t;
|
||||
|
||||
using std::min;
|
||||
using std::max;
|
||||
|
||||
#define TO_FIXED( f ) fixed_t ((f) * (1L << 15) + 0.5)
|
||||
#define FMUL( x, y ) (((x) * (y)) >> 15)
|
||||
|
||||
@@ -63,29 +67,49 @@ void Effects_Buffer::set_depth( double d )
|
||||
config( c );
|
||||
}
|
||||
|
||||
Effects_Buffer::Effects_Buffer( bool center_only ) : Multi_Buffer( 2 )
|
||||
Effects_Buffer::Effects_Buffer( int num_voices, bool center_only )
|
||||
: Multi_Buffer( 2*num_voices )
|
||||
, max_voices(num_voices)
|
||||
, bufs(max_voices * (center_only ? (max_buf_count - 4) : max_buf_count))
|
||||
, chan_types(max_voices * chan_types_count)
|
||||
, stereo_remain(0)
|
||||
, effect_remain(0)
|
||||
// TODO: Reorder buf_count to be initialized before bufs to factor out channel sizing
|
||||
, buf_count(max_voices * (center_only ? (max_buf_count - 4) : max_buf_count))
|
||||
, effects_enabled(false)
|
||||
, reverb_buf(max_voices, std::vector<blip_sample_t>(reverb_size))
|
||||
, echo_buf(max_voices, std::vector<blip_sample_t>(echo_size))
|
||||
, reverb_pos(max_voices)
|
||||
, echo_pos(max_voices)
|
||||
{
|
||||
buf_count = center_only ? max_buf_count - 4 : max_buf_count;
|
||||
|
||||
echo_pos = 0;
|
||||
reverb_pos = 0;
|
||||
|
||||
stereo_remain = 0;
|
||||
effect_remain = 0;
|
||||
effects_enabled = false;
|
||||
set_depth( 0 );
|
||||
}
|
||||
|
||||
Effects_Buffer::~Effects_Buffer() { }
|
||||
Effects_Buffer::~Effects_Buffer()
|
||||
{}
|
||||
|
||||
blargg_err_t Effects_Buffer::set_sample_rate( long rate, int msec )
|
||||
{
|
||||
if ( !echo_buf.size() )
|
||||
RETURN_ERR( echo_buf.resize( echo_size ) );
|
||||
|
||||
if ( !reverb_buf.size() )
|
||||
RETURN_ERR( reverb_buf.resize( reverb_size ) );
|
||||
|
||||
try
|
||||
{
|
||||
for(int i=0; i<max_voices; i++)
|
||||
{
|
||||
if ( !echo_buf[i].size() )
|
||||
{
|
||||
echo_buf[i].resize( echo_size );
|
||||
}
|
||||
|
||||
if ( !reverb_buf[i].size() )
|
||||
{
|
||||
reverb_buf[i].resize( reverb_size );
|
||||
}
|
||||
}
|
||||
}
|
||||
catch(std::bad_alloc& ba)
|
||||
{
|
||||
return "Out of memory";
|
||||
}
|
||||
|
||||
for ( int i = 0; i < buf_count; i++ )
|
||||
RETURN_ERR( bufs [i].set_sample_rate( rate, msec ) );
|
||||
|
||||
@@ -111,12 +135,16 @@ void Effects_Buffer::clear()
|
||||
{
|
||||
stereo_remain = 0;
|
||||
effect_remain = 0;
|
||||
if ( echo_buf.size() )
|
||||
memset( &echo_buf [0], 0, echo_size * sizeof echo_buf [0] );
|
||||
|
||||
if ( reverb_buf.size() )
|
||||
memset( &reverb_buf [0], 0, reverb_size * sizeof reverb_buf [0] );
|
||||
|
||||
|
||||
for(int i=0; i<max_voices; i++)
|
||||
{
|
||||
if ( echo_buf[i].size() )
|
||||
memset( &echo_buf[i][0], 0, echo_size * sizeof echo_buf[i][0] );
|
||||
|
||||
if ( reverb_buf[i].size() )
|
||||
memset( &reverb_buf[i][0], 0, reverb_size * sizeof reverb_buf[i][0] );
|
||||
}
|
||||
|
||||
for ( int i = 0; i < buf_count; i++ )
|
||||
bufs [i].clear();
|
||||
}
|
||||
@@ -135,12 +163,17 @@ void Effects_Buffer::config( const config_t& cfg )
|
||||
channels_changed();
|
||||
|
||||
// clear echo and reverb buffers
|
||||
if ( !config_.effects_enabled && cfg.effects_enabled && echo_buf.size() )
|
||||
// ensure the echo/reverb buffers have already been allocated, so this method can be
|
||||
// called before set_sample_rate is called
|
||||
if ( !config_.effects_enabled && cfg.effects_enabled && echo_buf[0].size() )
|
||||
{
|
||||
memset( &echo_buf [0], 0, echo_size * sizeof echo_buf [0] );
|
||||
memset( &reverb_buf [0], 0, reverb_size * sizeof reverb_buf [0] );
|
||||
for(int i=0; i<max_voices; i++)
|
||||
{
|
||||
memset( &echo_buf[i][0], 0, echo_size * sizeof echo_buf[i][0] );
|
||||
memset( &reverb_buf[i][0], 0, reverb_size * sizeof reverb_buf[i][0] );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
config_ = cfg;
|
||||
|
||||
if ( config_.effects_enabled )
|
||||
@@ -170,73 +203,87 @@ void Effects_Buffer::config( const config_t& cfg )
|
||||
chans.echo_delay_r = pin_range( echo_size - 1 - (echo_sample_delay + delay_offset),
|
||||
echo_size - 1 );
|
||||
|
||||
chan_types [0].center = &bufs [0];
|
||||
chan_types [0].left = &bufs [3];
|
||||
chan_types [0].right = &bufs [4];
|
||||
|
||||
chan_types [1].center = &bufs [1];
|
||||
chan_types [1].left = &bufs [3];
|
||||
chan_types [1].right = &bufs [4];
|
||||
|
||||
chan_types [2].center = &bufs [2];
|
||||
chan_types [2].left = &bufs [5];
|
||||
chan_types [2].right = &bufs [6];
|
||||
for(int i=0; i<max_voices; i++)
|
||||
{
|
||||
chan_types [i*chan_types_count+0].center = &bufs [i*max_buf_count+0];
|
||||
chan_types [i*chan_types_count+0].left = &bufs [i*max_buf_count+3];
|
||||
chan_types [i*chan_types_count+0].right = &bufs [i*max_buf_count+4];
|
||||
|
||||
chan_types [i*chan_types_count+1].center = &bufs [i*max_buf_count+1];
|
||||
chan_types [i*chan_types_count+1].left = &bufs [i*max_buf_count+3];
|
||||
chan_types [i*chan_types_count+1].right = &bufs [i*max_buf_count+4];
|
||||
|
||||
chan_types [i*chan_types_count+2].center = &bufs [i*max_buf_count+2];
|
||||
chan_types [i*chan_types_count+2].left = &bufs [i*max_buf_count+5];
|
||||
chan_types [i*chan_types_count+2].right = &bufs [i*max_buf_count+6];
|
||||
}
|
||||
assert( 2 < chan_types_count );
|
||||
}
|
||||
else
|
||||
{
|
||||
// set up outputs
|
||||
for ( unsigned i = 0; i < chan_types_count; i++ )
|
||||
for(int i=0; i<max_voices; i++)
|
||||
{
|
||||
channel_t& c = chan_types [i];
|
||||
c.center = &bufs [0];
|
||||
c.left = &bufs [1];
|
||||
c.right = &bufs [2];
|
||||
// set up outputs
|
||||
for ( int j = 0; j < chan_types_count; j++ )
|
||||
{
|
||||
channel_t& c = chan_types [i*chan_types_count+j];
|
||||
c.center = &bufs [i*max_buf_count+0];
|
||||
c.left = &bufs [i*max_buf_count+1];
|
||||
c.right = &bufs [i*max_buf_count+2];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( buf_count < max_buf_count )
|
||||
if ( buf_count < max_buf_count ) // if center_only
|
||||
{
|
||||
for ( int i = 0; i < chan_types_count; i++ )
|
||||
for(int i=0; i<max_voices; i++)
|
||||
{
|
||||
channel_t& c = chan_types [i];
|
||||
c.left = c.center;
|
||||
c.right = c.center;
|
||||
for ( int j = 0; j < chan_types_count; j++ )
|
||||
{
|
||||
channel_t& c = chan_types [i*chan_types_count+j];
|
||||
c.left = c.center;
|
||||
c.right = c.center;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Effects_Buffer::channel_t Effects_Buffer::channel( int i, int type )
|
||||
{
|
||||
int out = 2;
|
||||
int out = chan_types_count-1;
|
||||
if ( !type )
|
||||
{
|
||||
out = i % 5;
|
||||
if ( out > 2 )
|
||||
out = 2;
|
||||
if ( out > chan_types_count-1 )
|
||||
out = chan_types_count-1;
|
||||
}
|
||||
else if ( !(type & noise_type) && (type & type_index_mask) % 3 != 0 )
|
||||
{
|
||||
out = type & 1;
|
||||
}
|
||||
return chan_types [out];
|
||||
return chan_types [(i%max_voices)*chan_types_count+out];
|
||||
}
|
||||
|
||||
void Effects_Buffer::end_frame( blip_time_t clock_count )
|
||||
{
|
||||
int bufs_used = 0;
|
||||
for ( int i = 0; i < buf_count; i++ )
|
||||
{
|
||||
bufs_used |= bufs [i].clear_modified() << i;
|
||||
bufs [i].end_frame( clock_count );
|
||||
}
|
||||
|
||||
int stereo_mask = (config_.effects_enabled ? 0x78 : 0x06);
|
||||
if ( (bufs_used & stereo_mask) && buf_count == max_buf_count )
|
||||
stereo_remain = bufs [0].samples_avail() + bufs [0].output_latency();
|
||||
|
||||
if ( effects_enabled || config_.effects_enabled )
|
||||
effect_remain = bufs [0].samples_avail() + bufs [0].output_latency();
|
||||
|
||||
const int buf_count_per_voice = buf_count/max_voices;
|
||||
for ( int v = 0; v < max_voices; v++ ) // foreach voice
|
||||
{
|
||||
for ( int i = 0; i < buf_count_per_voice; i++) // foreach buffer of that voice
|
||||
{
|
||||
bufs_used |= bufs [v*buf_count_per_voice + i].clear_modified() << i;
|
||||
bufs [v*buf_count_per_voice + i].end_frame( clock_count );
|
||||
|
||||
if ( (bufs_used & stereo_mask) && buf_count == max_voices*max_buf_count )
|
||||
stereo_remain = max(stereo_remain, bufs [v*buf_count_per_voice + i].samples_avail() + bufs [v*buf_count_per_voice + i].output_latency());
|
||||
if ( effects_enabled || config_.effects_enabled )
|
||||
effect_remain = max(effect_remain, bufs [v*buf_count_per_voice + i].samples_avail() + bufs [v*buf_count_per_voice + i].output_latency());
|
||||
}
|
||||
bufs_used = 0;
|
||||
}
|
||||
|
||||
effects_enabled = config_.effects_enabled;
|
||||
}
|
||||
@@ -248,15 +295,17 @@ long Effects_Buffer::samples_avail() const
|
||||
|
||||
long Effects_Buffer::read_samples( blip_sample_t* out, long total_samples )
|
||||
{
|
||||
require( total_samples % 2 == 0 ); // count must be even
|
||||
|
||||
const int n_channels = max_voices * 2;
|
||||
const int buf_count_per_voice = buf_count/max_voices;
|
||||
|
||||
require( total_samples % n_channels == 0 ); // as many items needed to fill at least one frame
|
||||
|
||||
long remain = bufs [0].samples_avail();
|
||||
if ( remain > (total_samples >> 1) )
|
||||
remain = (total_samples >> 1);
|
||||
total_samples = remain;
|
||||
total_samples = remain = min( remain, total_samples/n_channels );
|
||||
|
||||
while ( remain )
|
||||
{
|
||||
int active_bufs = buf_count;
|
||||
int active_bufs = buf_count_per_voice;
|
||||
long count = remain;
|
||||
|
||||
// optimizing mixing to skip any channels which had nothing added
|
||||
@@ -286,7 +335,7 @@ long Effects_Buffer::read_samples( blip_sample_t* out, long total_samples )
|
||||
active_bufs = 1;
|
||||
}
|
||||
|
||||
out += count * 2;
|
||||
out += count * n_channels;
|
||||
remain -= count;
|
||||
|
||||
stereo_remain -= count;
|
||||
@@ -297,23 +346,31 @@ long Effects_Buffer::read_samples( blip_sample_t* out, long total_samples )
|
||||
if ( effect_remain < 0 )
|
||||
effect_remain = 0;
|
||||
|
||||
for ( int i = 0; i < buf_count; i++ )
|
||||
// skip the output from any buffers that didn't contribute to the sound output
|
||||
// during this frame (e.g. if we only render mono then only the very first buf
|
||||
// is 'active')
|
||||
for ( int v = 0; v < max_voices; v++ ) // foreach voice
|
||||
{
|
||||
if ( i < active_bufs )
|
||||
bufs [i].remove_samples( count );
|
||||
else
|
||||
bufs [i].remove_silence( count ); // keep time synchronized
|
||||
for ( int i = 0; i < buf_count_per_voice; i++) // foreach buffer of that voice
|
||||
{
|
||||
if ( i < active_bufs )
|
||||
bufs [v*buf_count_per_voice + i].remove_samples( count );
|
||||
else // keep time synchronized
|
||||
bufs [v*buf_count_per_voice + i].remove_silence( count );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return total_samples * 2;
|
||||
return total_samples * n_channels;
|
||||
}
|
||||
|
||||
void Effects_Buffer::mix_mono( blip_sample_t* out_, blargg_long count )
|
||||
{
|
||||
for(int i=0; i<max_voices; i++)
|
||||
{
|
||||
blip_sample_t* BLIP_RESTRICT out = out_;
|
||||
int const bass = BLIP_READER_BASS( bufs [0] );
|
||||
BLIP_READER_BEGIN( c, bufs [0] );
|
||||
int const bass = BLIP_READER_BASS( bufs [i*max_buf_count+0] );
|
||||
BLIP_READER_BEGIN( c, bufs [i*max_buf_count+0] );
|
||||
|
||||
// unrolled loop
|
||||
for ( blargg_long n = count >> 1; n; --n )
|
||||
@@ -324,41 +381,45 @@ void Effects_Buffer::mix_mono( blip_sample_t* out_, blargg_long count )
|
||||
blargg_long cs1 = BLIP_READER_READ( c );
|
||||
BLIP_READER_NEXT( c, bass );
|
||||
|
||||
if ( (BOOST::int16_t) cs0 != cs0 )
|
||||
if ( (int16_t) cs0 != cs0 )
|
||||
cs0 = 0x7FFF - (cs0 >> 24);
|
||||
((BOOST::uint32_t*) out) [0] = ((BOOST::uint16_t) cs0) | (cs0 << 16);
|
||||
((uint32_t*) out) [i*2+0] = ((uint16_t) cs0) | (uint16_t(cs0) << 16);
|
||||
|
||||
if ( (BOOST::int16_t) cs1 != cs1 )
|
||||
if ( (int16_t) cs1 != cs1 )
|
||||
cs1 = 0x7FFF - (cs1 >> 24);
|
||||
((BOOST::uint32_t*) out) [1] = ((BOOST::uint16_t) cs1) | (cs1 << 16);
|
||||
out += 4;
|
||||
((uint32_t*) out) [i*2+1] = ((uint16_t) cs1) | (uint16_t(cs1) << 16);
|
||||
out += max_voices*4;
|
||||
}
|
||||
|
||||
if ( count & 1 )
|
||||
{
|
||||
int s = BLIP_READER_READ( c );
|
||||
BLIP_READER_NEXT( c, bass );
|
||||
out [0] = s;
|
||||
out [1] = s;
|
||||
if ( (BOOST::int16_t) s != s )
|
||||
out [i*2+0] = s;
|
||||
out [i*2+1] = s;
|
||||
if ( (int16_t) s != s )
|
||||
{
|
||||
s = 0x7FFF - (s >> 24);
|
||||
out [0] = s;
|
||||
out [1] = s;
|
||||
out [i*2+0] = s;
|
||||
out [i*2+1] = s;
|
||||
}
|
||||
}
|
||||
|
||||
BLIP_READER_END( c, bufs [0] );
|
||||
BLIP_READER_END( c, bufs [i*max_buf_count+0] );
|
||||
}
|
||||
}
|
||||
|
||||
void Effects_Buffer::mix_stereo( blip_sample_t* out_, blargg_long count )
|
||||
void Effects_Buffer::mix_stereo( blip_sample_t* out_, blargg_long frames )
|
||||
{
|
||||
for(int i=0; i<max_voices; i++)
|
||||
{
|
||||
blip_sample_t* BLIP_RESTRICT out = out_;
|
||||
int const bass = BLIP_READER_BASS( bufs [0] );
|
||||
BLIP_READER_BEGIN( c, bufs [0] );
|
||||
BLIP_READER_BEGIN( l, bufs [1] );
|
||||
BLIP_READER_BEGIN( r, bufs [2] );
|
||||
|
||||
int const bass = BLIP_READER_BASS( bufs [i*max_buf_count+0] );
|
||||
BLIP_READER_BEGIN( c, bufs [i*max_buf_count+0] );
|
||||
BLIP_READER_BEGIN( l, bufs [i*max_buf_count+1] );
|
||||
BLIP_READER_BEGIN( r, bufs [i*max_buf_count+2] );
|
||||
|
||||
int count = frames;
|
||||
while ( count-- )
|
||||
{
|
||||
int cs = BLIP_READER_READ( c );
|
||||
@@ -368,36 +429,41 @@ void Effects_Buffer::mix_stereo( blip_sample_t* out_, blargg_long count )
|
||||
BLIP_READER_NEXT( l, bass );
|
||||
BLIP_READER_NEXT( r, bass );
|
||||
|
||||
if ( (BOOST::int16_t) left != left )
|
||||
if ( (int16_t) left != left )
|
||||
left = 0x7FFF - (left >> 24);
|
||||
|
||||
out [0] = left;
|
||||
out [1] = right;
|
||||
if ( (int16_t) right != right )
|
||||
right = 0x7FFF - (right >> 24);
|
||||
|
||||
out [i*2+0] = left;
|
||||
out [i*2+1] = right;
|
||||
|
||||
out += 2;
|
||||
out += max_voices*2;
|
||||
|
||||
if ( (BOOST::int16_t) right != right )
|
||||
out [-1] = 0x7FFF - (right >> 24);
|
||||
}
|
||||
|
||||
BLIP_READER_END( r, bufs [2] );
|
||||
BLIP_READER_END( l, bufs [1] );
|
||||
BLIP_READER_END( c, bufs [0] );
|
||||
BLIP_READER_END( r, bufs [i*max_buf_count+2] );
|
||||
BLIP_READER_END( l, bufs [i*max_buf_count+1] );
|
||||
BLIP_READER_END( c, bufs [i*max_buf_count+0] );
|
||||
}
|
||||
}
|
||||
|
||||
void Effects_Buffer::mix_mono_enhanced( blip_sample_t* out_, blargg_long count )
|
||||
void Effects_Buffer::mix_mono_enhanced( blip_sample_t* out_, blargg_long frames )
|
||||
{
|
||||
for(int i=0; i<max_voices; i++)
|
||||
{
|
||||
blip_sample_t* BLIP_RESTRICT out = out_;
|
||||
int const bass = BLIP_READER_BASS( bufs [2] );
|
||||
BLIP_READER_BEGIN( center, bufs [2] );
|
||||
BLIP_READER_BEGIN( sq1, bufs [0] );
|
||||
BLIP_READER_BEGIN( sq2, bufs [1] );
|
||||
int const bass = BLIP_READER_BASS( bufs [i*max_buf_count+2] );
|
||||
BLIP_READER_BEGIN( center, bufs [i*max_buf_count+2] );
|
||||
BLIP_READER_BEGIN( sq1, bufs [i*max_buf_count+0] );
|
||||
BLIP_READER_BEGIN( sq2, bufs [i*max_buf_count+1] );
|
||||
|
||||
blip_sample_t* const reverb_buf = this->reverb_buf.begin();
|
||||
blip_sample_t* const echo_buf = this->echo_buf.begin();
|
||||
int echo_pos = this->echo_pos;
|
||||
int reverb_pos = this->reverb_pos;
|
||||
blip_sample_t* const reverb_buf = &this->reverb_buf[i][0];
|
||||
blip_sample_t* const echo_buf = &this->echo_buf[i][0];
|
||||
int echo_pos = this->echo_pos[i];
|
||||
int reverb_pos = this->reverb_pos[i];
|
||||
|
||||
int count = frames;
|
||||
while ( count-- )
|
||||
{
|
||||
int sum1_s = BLIP_READER_READ( sq1 );
|
||||
@@ -430,42 +496,45 @@ void Effects_Buffer::mix_mono_enhanced( blip_sample_t* out_, blargg_long count )
|
||||
echo_buf [echo_pos] = sum3_s;
|
||||
echo_pos = (echo_pos + 1) & echo_mask;
|
||||
|
||||
if ( (BOOST::int16_t) left != left )
|
||||
if ( (int16_t) left != left )
|
||||
left = 0x7FFF - (left >> 24);
|
||||
|
||||
out [0] = left;
|
||||
out [1] = right;
|
||||
|
||||
out += 2;
|
||||
|
||||
if ( (BOOST::int16_t) right != right )
|
||||
out [-1] = 0x7FFF - (right >> 24);
|
||||
if ( (int16_t) right != right )
|
||||
right = 0x7FFF - (right >> 24);
|
||||
|
||||
out [i*2+0] = left;
|
||||
out [i*2+1] = right;
|
||||
out += max_voices*2;
|
||||
}
|
||||
this->reverb_pos = reverb_pos;
|
||||
this->echo_pos = echo_pos;
|
||||
this->reverb_pos[i] = reverb_pos;
|
||||
this->echo_pos[i] = echo_pos;
|
||||
|
||||
BLIP_READER_END( sq1, bufs [0] );
|
||||
BLIP_READER_END( sq2, bufs [1] );
|
||||
BLIP_READER_END( center, bufs [2] );
|
||||
BLIP_READER_END( sq1, bufs [i*max_buf_count+0] );
|
||||
BLIP_READER_END( sq2, bufs [i*max_buf_count+1] );
|
||||
BLIP_READER_END( center, bufs [i*max_buf_count+2] );
|
||||
}
|
||||
}
|
||||
|
||||
void Effects_Buffer::mix_enhanced( blip_sample_t* out_, blargg_long count )
|
||||
void Effects_Buffer::mix_enhanced( blip_sample_t* out_, blargg_long frames )
|
||||
{
|
||||
for(int i=0; i<max_voices; i++)
|
||||
{
|
||||
blip_sample_t* BLIP_RESTRICT out = out_;
|
||||
int const bass = BLIP_READER_BASS( bufs [2] );
|
||||
BLIP_READER_BEGIN( center, bufs [2] );
|
||||
BLIP_READER_BEGIN( l1, bufs [3] );
|
||||
BLIP_READER_BEGIN( r1, bufs [4] );
|
||||
BLIP_READER_BEGIN( l2, bufs [5] );
|
||||
BLIP_READER_BEGIN( r2, bufs [6] );
|
||||
BLIP_READER_BEGIN( sq1, bufs [0] );
|
||||
BLIP_READER_BEGIN( sq2, bufs [1] );
|
||||
int const bass = BLIP_READER_BASS( bufs [i*max_buf_count+2] );
|
||||
BLIP_READER_BEGIN( center, bufs [i*max_buf_count+2] );
|
||||
BLIP_READER_BEGIN( l1, bufs [i*max_buf_count+3] );
|
||||
BLIP_READER_BEGIN( r1, bufs [i*max_buf_count+4] );
|
||||
BLIP_READER_BEGIN( l2, bufs [i*max_buf_count+5] );
|
||||
BLIP_READER_BEGIN( r2, bufs [i*max_buf_count+6] );
|
||||
BLIP_READER_BEGIN( sq1, bufs [i*max_buf_count+0] );
|
||||
BLIP_READER_BEGIN( sq2, bufs [i*max_buf_count+1] );
|
||||
|
||||
blip_sample_t* const reverb_buf = this->reverb_buf.begin();
|
||||
blip_sample_t* const echo_buf = this->echo_buf.begin();
|
||||
int echo_pos = this->echo_pos;
|
||||
int reverb_pos = this->reverb_pos;
|
||||
blip_sample_t* const reverb_buf = &this->reverb_buf[i][0];
|
||||
blip_sample_t* const echo_buf = &this->echo_buf[i][0];
|
||||
int echo_pos = this->echo_pos[i];
|
||||
int reverb_pos = this->reverb_pos[i];
|
||||
|
||||
int count = frames;
|
||||
while ( count-- )
|
||||
{
|
||||
int sum1_s = BLIP_READER_READ( sq1 );
|
||||
@@ -504,26 +573,27 @@ void Effects_Buffer::mix_enhanced( blip_sample_t* out_, blargg_long count )
|
||||
echo_buf [echo_pos] = sum3_s;
|
||||
echo_pos = (echo_pos + 1) & echo_mask;
|
||||
|
||||
if ( (BOOST::int16_t) left != left )
|
||||
if ( (int16_t) left != left )
|
||||
left = 0x7FFF - (left >> 24);
|
||||
|
||||
out [0] = left;
|
||||
out [1] = right;
|
||||
|
||||
out += 2;
|
||||
|
||||
if ( (BOOST::int16_t) right != right )
|
||||
out [-1] = 0x7FFF - (right >> 24);
|
||||
if ( (int16_t) right != right )
|
||||
right = 0x7FFF - (right >> 24);
|
||||
|
||||
out [i*2+0] = left;
|
||||
out [i*2+1] = right;
|
||||
|
||||
out += max_voices*2;
|
||||
}
|
||||
this->reverb_pos = reverb_pos;
|
||||
this->echo_pos = echo_pos;
|
||||
this->reverb_pos[i] = reverb_pos;
|
||||
this->echo_pos[i] = echo_pos;
|
||||
|
||||
BLIP_READER_END( l1, bufs [3] );
|
||||
BLIP_READER_END( r1, bufs [4] );
|
||||
BLIP_READER_END( l2, bufs [5] );
|
||||
BLIP_READER_END( r2, bufs [6] );
|
||||
BLIP_READER_END( sq1, bufs [0] );
|
||||
BLIP_READER_END( sq2, bufs [1] );
|
||||
BLIP_READER_END( center, bufs [2] );
|
||||
BLIP_READER_END( l1, bufs [i*max_buf_count+3] );
|
||||
BLIP_READER_END( r1, bufs [i*max_buf_count+4] );
|
||||
BLIP_READER_END( l2, bufs [i*max_buf_count+5] );
|
||||
BLIP_READER_END( r2, bufs [i*max_buf_count+6] );
|
||||
BLIP_READER_END( sq1, bufs [i*max_buf_count+0] );
|
||||
BLIP_READER_END( sq2, bufs [i*max_buf_count+1] );
|
||||
BLIP_READER_END( center, bufs [i*max_buf_count+2] );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,17 +1,21 @@
|
||||
// Multi-channel effects buffer with panning, echo and reverb
|
||||
|
||||
// Game_Music_Emu 0.6.0
|
||||
// Game_Music_Emu https://bitbucket.org/mpyne/game-music-emu/
|
||||
#ifndef EFFECTS_BUFFER_H
|
||||
#define EFFECTS_BUFFER_H
|
||||
|
||||
#include "Multi_Buffer.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
// Effects_Buffer uses several buffers and outputs stereo sample pairs.
|
||||
class Effects_Buffer : public Multi_Buffer {
|
||||
public:
|
||||
// nVoices indicates the number of voices for which buffers will be allocated
|
||||
// to make Effects_Buffer work as "mix everything to one", nVoices will be 1
|
||||
// If center_only is true, only center buffers are created and
|
||||
// less memory is used.
|
||||
Effects_Buffer( bool center_only = false );
|
||||
Effects_Buffer( int nVoices = 1, bool center_only = false );
|
||||
|
||||
// Channel Effect Center Pan
|
||||
// ---------------------------------
|
||||
@@ -50,21 +54,21 @@ public:
|
||||
long samples_avail() const;
|
||||
private:
|
||||
typedef long fixed_t;
|
||||
|
||||
int max_voices;
|
||||
enum { max_buf_count = 7 };
|
||||
Blip_Buffer bufs [max_buf_count];
|
||||
std::vector<Blip_Buffer> bufs;
|
||||
enum { chan_types_count = 3 };
|
||||
channel_t chan_types [3];
|
||||
std::vector<channel_t> chan_types;
|
||||
config_t config_;
|
||||
long stereo_remain;
|
||||
long effect_remain;
|
||||
int buf_count;
|
||||
bool effects_enabled;
|
||||
|
||||
blargg_vector<blip_sample_t> reverb_buf;
|
||||
blargg_vector<blip_sample_t> echo_buf;
|
||||
int reverb_pos;
|
||||
int echo_pos;
|
||||
std::vector<std::vector<blip_sample_t> > reverb_buf;
|
||||
std::vector<std::vector<blip_sample_t> > echo_buf;
|
||||
std::vector<int> reverb_pos;
|
||||
std::vector<int> echo_pos;
|
||||
|
||||
struct {
|
||||
fixed_t pan_1_levels [2];
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Game_Music_Emu 0.6.0. http://www.slack.net/~ant/
|
||||
// Game_Music_Emu https://bitbucket.org/mpyne/game-music-emu/
|
||||
|
||||
#include "Fir_Resampler.h"
|
||||
|
||||
@@ -188,6 +188,8 @@ int Fir_Resampler_::skip_input( long count )
|
||||
{
|
||||
int remain = write_pos - buf.begin();
|
||||
int max_count = remain - width_ * stereo;
|
||||
if ( max_count < 0 )
|
||||
return 0;
|
||||
if ( count > max_count )
|
||||
count = max_count;
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// Finite impulse response (FIR) resampler with adjustable FIR size
|
||||
|
||||
// Game_Music_Emu 0.6.0
|
||||
// Game_Music_Emu https://bitbucket.org/mpyne/game-music-emu/
|
||||
#ifndef FIR_RESAMPLER_H
|
||||
#define FIR_RESAMPLER_H
|
||||
|
||||
@@ -109,51 +109,66 @@ int Fir_Resampler<width>::read( sample_t* out_begin, blargg_long count )
|
||||
|
||||
count >>= 1;
|
||||
|
||||
// Resampling can add noise so don't actually do it if we've matched sample
|
||||
// rate
|
||||
const double ratio1 = ratio() - 1.0;
|
||||
const bool should_resample =
|
||||
( ratio1 >= 0 ? ratio1 : -ratio1 ) >= 0.00001;
|
||||
|
||||
if ( end_pos - in >= width * stereo )
|
||||
{
|
||||
end_pos -= width * stereo;
|
||||
do
|
||||
{
|
||||
count--;
|
||||
|
||||
// accumulate in extended precision
|
||||
blargg_long l = 0;
|
||||
blargg_long r = 0;
|
||||
|
||||
const sample_t* i = in;
|
||||
if ( count < 0 )
|
||||
break;
|
||||
|
||||
for ( int n = width / 2; n; --n )
|
||||
if( !should_resample )
|
||||
{
|
||||
int pt0 = imp [0];
|
||||
l += pt0 * i [0];
|
||||
r += pt0 * i [1];
|
||||
int pt1 = imp [1];
|
||||
imp += 2;
|
||||
l += pt1 * i [2];
|
||||
r += pt1 * i [3];
|
||||
i += 4;
|
||||
out [0] = static_cast<sample_t>( in [0] );
|
||||
out [1] = static_cast<sample_t>( in [1] );
|
||||
}
|
||||
else
|
||||
{
|
||||
// accumulate in extended precision
|
||||
blargg_long l = 0;
|
||||
blargg_long r = 0;
|
||||
|
||||
const sample_t* i = in;
|
||||
|
||||
for ( int n = width / 2; n; --n )
|
||||
{
|
||||
int pt0 = imp [0];
|
||||
l += pt0 * i [0];
|
||||
r += pt0 * i [1];
|
||||
int pt1 = imp [1];
|
||||
imp += 2;
|
||||
l += pt1 * i [2];
|
||||
r += pt1 * i [3];
|
||||
i += 4;
|
||||
}
|
||||
|
||||
remain--;
|
||||
|
||||
l >>= 15;
|
||||
r >>= 15;
|
||||
|
||||
in += (skip * stereo) & stereo;
|
||||
skip >>= 1;
|
||||
|
||||
if ( !remain )
|
||||
{
|
||||
imp = impulses [0];
|
||||
skip = skip_bits;
|
||||
remain = res;
|
||||
}
|
||||
|
||||
out [0] = (sample_t) l;
|
||||
out [1] = (sample_t) r;
|
||||
}
|
||||
|
||||
remain--;
|
||||
|
||||
l >>= 15;
|
||||
r >>= 15;
|
||||
|
||||
in += (skip * stereo) & stereo;
|
||||
skip >>= 1;
|
||||
in += step;
|
||||
|
||||
if ( !remain )
|
||||
{
|
||||
imp = impulses [0];
|
||||
skip = skip_bits;
|
||||
remain = res;
|
||||
}
|
||||
|
||||
out [0] = (sample_t) l;
|
||||
out [1] = (sample_t) r;
|
||||
out += 2;
|
||||
}
|
||||
while ( in <= end_pos );
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include "Gb_Apu.h"
|
||||
|
||||
#include <string.h>
|
||||
#include <algorithm>
|
||||
|
||||
/* Copyright (C) 2003-2006 Shay Green. This module is free software; you
|
||||
can redistribute it and/or modify it under the terms of the GNU Lesser
|
||||
@@ -20,6 +21,9 @@ Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */
|
||||
unsigned const vol_reg = 0xFF24;
|
||||
unsigned const status_reg = 0xFF26;
|
||||
|
||||
using std::min;
|
||||
using std::max;
|
||||
|
||||
Gb_Apu::Gb_Apu()
|
||||
{
|
||||
square1.synth = &square_synth;
|
||||
@@ -123,7 +127,7 @@ void Gb_Apu::reset()
|
||||
0x84,0x40,0x43,0xAA,0x2D,0x78,0x92,0x3C, // wave table
|
||||
0x60,0x59,0x59,0xB0,0x34,0xB8,0x2E,0xDA
|
||||
};
|
||||
memcpy( wave.wave, initial_wave, sizeof wave.wave );
|
||||
memcpy( wave.wave, initial_wave, sizeof initial_wave );
|
||||
}
|
||||
|
||||
void Gb_Apu::run_until( blip_time_t end_time )
|
||||
|
||||
@@ -68,7 +68,7 @@ private:
|
||||
Gb_Square square2;
|
||||
Gb_Wave wave;
|
||||
Gb_Noise noise;
|
||||
BOOST::uint8_t regs [register_count];
|
||||
uint8_t regs [register_count];
|
||||
Gb_Square::Synth square_synth; // used by squares
|
||||
Gb_Wave::Synth other_synth; // used by wave and noise
|
||||
|
||||
|
||||
+17
-16
@@ -1,4 +1,4 @@
|
||||
// Game_Music_Emu 0.6.0. http://www.slack.net/~ant/
|
||||
// Game_Music_Emu https://bitbucket.org/mpyne/game-music-emu/
|
||||
|
||||
#include "Gb_Cpu.h"
|
||||
|
||||
@@ -96,8 +96,6 @@ bool Gb_Cpu::run( blargg_long cycle_count )
|
||||
this->state = &s;
|
||||
memcpy( &s, &this->state_, sizeof s );
|
||||
|
||||
typedef BOOST::uint16_t uint16_t;
|
||||
|
||||
#if BLARGG_BIG_ENDIAN
|
||||
#define R8( n ) (r8_ [n])
|
||||
#elif BLARGG_LITTLE_ENDIAN
|
||||
@@ -110,11 +108,11 @@ bool Gb_Cpu::run( blargg_long cycle_count )
|
||||
core_regs_t rg; // individual registers
|
||||
|
||||
struct {
|
||||
BOOST::uint16_t bc, de, hl, unused; // pairs
|
||||
uint16_t bc, de, hl, unused; // pairs
|
||||
} rp;
|
||||
|
||||
uint8_t r8_ [8]; // indexed registers (use R8 macro due to endian dependence)
|
||||
BOOST::uint16_t r16 [4]; // indexed pairs
|
||||
uint16_t r16 [4]; // indexed pairs
|
||||
};
|
||||
BOOST_STATIC_ASSERT( sizeof rg == 8 && sizeof rp == 8 );
|
||||
|
||||
@@ -162,7 +160,7 @@ loop:
|
||||
#define BRANCH( cond )\
|
||||
{\
|
||||
pc++;\
|
||||
int offset = (BOOST::int8_t) data;\
|
||||
int offset = (int8_t) data;\
|
||||
if ( !(cond) ) goto loop;\
|
||||
pc = uint16_t (pc + offset);\
|
||||
goto loop;\
|
||||
@@ -262,7 +260,7 @@ loop:
|
||||
if ( flags & z_flag )
|
||||
goto loop;
|
||||
call:
|
||||
pc -= 2;
|
||||
pc -= 2; // FALLTHRU
|
||||
case 0xCD: // CALL (most-common)
|
||||
data = pc + 2;
|
||||
pc = GET_ADDR();
|
||||
@@ -276,6 +274,7 @@ loop:
|
||||
case 0xC8: // RNZ (next-most-common)
|
||||
if ( !(flags & z_flag) )
|
||||
goto loop;
|
||||
// FALLTHRU
|
||||
case 0xC9: // RET (most common)
|
||||
ret:
|
||||
pc = READ( sp );
|
||||
@@ -433,7 +432,7 @@ loop:
|
||||
goto rl_comm;
|
||||
|
||||
case 0x3E: // SRL (HL)
|
||||
data += 0x10; // bump up to 0x4n to avoid preserving sign bit
|
||||
data += 0x10; /* fallthrough */ // bump up to 0x4n to avoid preserving sign bit
|
||||
case 0x1E: // RR (HL)
|
||||
case 0x0E: // RRC (HL)
|
||||
case 0x2E: // SRA (HL)
|
||||
@@ -441,7 +440,7 @@ loop:
|
||||
goto rr_comm;
|
||||
|
||||
case 0x38: case 0x39: case 0x3A: case 0x3B: case 0x3C: case 0x3D: case 0x3F: // SRL A
|
||||
data += 0x10; // bump up to 0x4n
|
||||
data += 0x10; /* fallthrough */ // bump up to 0x4n
|
||||
case 0x18: case 0x19: case 0x1A: case 0x1B: case 0x1C: case 0x1D: case 0x1F: // RR A
|
||||
case 0x08: case 0x09: case 0x0A: case 0x0B: case 0x0C: case 0x0D: case 0x0F: // RRC A
|
||||
case 0x28: case 0x29: case 0x2A: case 0x2B: case 0x2C: case 0x2D: case 0x2F: // SRA A
|
||||
@@ -450,6 +449,7 @@ loop:
|
||||
|
||||
} // CB op
|
||||
assert( false ); // unhandled CB op
|
||||
// fallthrough
|
||||
|
||||
case 0x07: // RLCA
|
||||
case 0x17: // RLA
|
||||
@@ -682,7 +682,7 @@ loop:
|
||||
unsigned prev;
|
||||
|
||||
case 0xF8: // LD HL,SP+imm
|
||||
temp = BOOST::int8_t (data); // sign-extend to 16 bits
|
||||
temp = int8_t (data); // sign-extend to 16 bits
|
||||
pc++;
|
||||
flags = 0;
|
||||
temp += sp;
|
||||
@@ -690,7 +690,7 @@ loop:
|
||||
goto add_16_hl;
|
||||
|
||||
case 0xE8: // ADD SP,IMM
|
||||
temp = BOOST::int8_t (data); // sign-extend to 16 bits
|
||||
temp = int8_t (data); // sign-extend to 16 bits
|
||||
pc++;
|
||||
flags = 0;
|
||||
temp += sp;
|
||||
@@ -824,11 +824,11 @@ loop:
|
||||
|
||||
case 0xA6: // AND (HL)
|
||||
data = READ( rp.hl );
|
||||
pc--;
|
||||
pc--; // FALLTHRU
|
||||
case 0xE6: // AND IMM
|
||||
pc++;
|
||||
and_comm:
|
||||
rg.a &= data;
|
||||
rg.a &= data; // FALLTHRU
|
||||
case 0xA7: // AND A
|
||||
flags = h_flag | (((rg.a - 1) >> 1) & z_flag);
|
||||
goto loop;
|
||||
@@ -844,11 +844,11 @@ loop:
|
||||
|
||||
case 0xB6: // OR (HL)
|
||||
data = READ( rp.hl );
|
||||
pc--;
|
||||
pc--; // FALLTHRU
|
||||
case 0xF6: // OR IMM
|
||||
pc++;
|
||||
or_comm:
|
||||
rg.a |= data;
|
||||
rg.a |= data; // FALLTHRU
|
||||
case 0xB7: // OR A
|
||||
flags = ((rg.a - 1) >> 1) & z_flag;
|
||||
goto loop;
|
||||
@@ -864,7 +864,7 @@ loop:
|
||||
|
||||
case 0xAE: // XOR (HL)
|
||||
data = READ( rp.hl );
|
||||
pc--;
|
||||
pc--; // FALLTHRU
|
||||
case 0xEE: // XOR IMM
|
||||
pc++;
|
||||
xor_comm:
|
||||
@@ -914,6 +914,7 @@ loop:
|
||||
case 0xFF:
|
||||
if ( pc == idle_addr + 1 )
|
||||
goto stop;
|
||||
// FALLTHRU
|
||||
case 0xC7: case 0xCF: case 0xD7: case 0xDF: // RST
|
||||
case 0xE7: case 0xEF: case 0xF7:
|
||||
data = pc;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// Nintendo Game Boy CPU emulator
|
||||
// Treats every instruction as taking 4 cycles
|
||||
|
||||
// Game_Music_Emu 0.6.0
|
||||
// Game_Music_Emu https://bitbucket.org/mpyne/game-music-emu/
|
||||
#ifndef GB_CPU_H
|
||||
#define GB_CPU_H
|
||||
|
||||
@@ -13,8 +13,6 @@ typedef unsigned gb_addr_t; // 16-bit CPU address
|
||||
class Gb_Cpu {
|
||||
enum { clocks_per_instr = 4 };
|
||||
public:
|
||||
typedef BOOST::uint8_t uint8_t;
|
||||
|
||||
// Clear registers and map all pages to unmapped
|
||||
void reset( void* unmapped = 0 );
|
||||
|
||||
@@ -39,7 +37,7 @@ public:
|
||||
|
||||
struct registers_t : core_regs_t {
|
||||
long pc; // more than 16 bits to allow overflow detection
|
||||
BOOST::uint16_t sp;
|
||||
uint16_t sp;
|
||||
};
|
||||
registers_t r;
|
||||
|
||||
@@ -81,7 +79,7 @@ private:
|
||||
void set_code_page( int, uint8_t* );
|
||||
};
|
||||
|
||||
inline BOOST::uint8_t* Gb_Cpu::get_code( gb_addr_t addr )
|
||||
inline uint8_t* Gb_Cpu::get_code( gb_addr_t addr )
|
||||
{
|
||||
return state->code_map [addr >> page_shift] + addr
|
||||
#if !BLARGG_NONPORTABLE
|
||||
|
||||
@@ -312,7 +312,7 @@ void Gb_Apu::write_osc( int index, int reg, int data )
|
||||
switch ( index )
|
||||
{
|
||||
case 0:
|
||||
sq = &square1;
|
||||
sq = &square1; // FALLTHRU
|
||||
case 1:
|
||||
if ( sq->write_register( reg, data ) && index == 0 )
|
||||
{
|
||||
|
||||
@@ -15,7 +15,7 @@ struct Gb_Osc
|
||||
Blip_Buffer* outputs [4]; // NULL, right, left, center
|
||||
Blip_Buffer* output;
|
||||
int output_select;
|
||||
BOOST::uint8_t* regs; // osc's 5 registers
|
||||
uint8_t* regs; // osc's 5 registers
|
||||
|
||||
int delay;
|
||||
int last_amp;
|
||||
@@ -68,7 +68,7 @@ struct Gb_Wave : Gb_Osc
|
||||
Synth const* synth;
|
||||
int wave_pos;
|
||||
enum { wave_size = 32 };
|
||||
BOOST::uint8_t wave [wave_size];
|
||||
uint8_t wave [wave_size];
|
||||
|
||||
void write_register( int, int );
|
||||
void run( blip_time_t, blip_time_t, int playing );
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Game_Music_Emu 0.6.0. http://www.slack.net/~ant/
|
||||
// Game_Music_Emu https://bitbucket.org/mpyne/game-music-emu/
|
||||
|
||||
#include "Gbs_Emu.h"
|
||||
|
||||
@@ -101,7 +101,7 @@ static Music_Emu* new_gbs_emu () { return BLARGG_NEW Gbs_Emu ; }
|
||||
static Music_Emu* new_gbs_file() { return BLARGG_NEW Gbs_File; }
|
||||
|
||||
static gme_type_t_ const gme_gbs_type_ = { "Game Boy", 0, &new_gbs_emu, &new_gbs_file, "GBS", 1 };
|
||||
gme_type_t const gme_gbs_type = &gme_gbs_type_;
|
||||
extern gme_type_t const gme_gbs_type = &gme_gbs_type_;
|
||||
|
||||
// Setup
|
||||
|
||||
@@ -175,7 +175,7 @@ void Gbs_Emu::update_timer()
|
||||
play_period = blip_time_t (play_period / tempo());
|
||||
}
|
||||
|
||||
static BOOST::uint8_t const sound_data [Gb_Apu::register_count] = {
|
||||
static uint8_t const sound_data [Gb_Apu::register_count] = {
|
||||
0x80, 0xBF, 0x00, 0x00, 0xBF, // square 1
|
||||
0x00, 0x3F, 0x00, 0x00, 0xBF, // square 2
|
||||
0x7F, 0xFF, 0x9F, 0x00, 0xBF, // wave
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// Nintendo Game Boy GBS music file emulator
|
||||
|
||||
// Game_Music_Emu 0.6.0
|
||||
// Game_Music_Emu https://bitbucket.org/mpyne/game-music-emu/
|
||||
#ifndef GBS_EMU_H
|
||||
#define GBS_EMU_H
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Game_Music_Emu 0.6.0. http://www.slack.net/~ant/
|
||||
// Game_Music_Emu https://bitbucket.org/mpyne/game-music-emu/
|
||||
|
||||
#include "Gme_File.h"
|
||||
|
||||
@@ -208,9 +208,9 @@ blargg_err_t Gme_File::track_info( track_info_t* out, int track ) const
|
||||
|
||||
M3u_Playlist::entry_t const& e = playlist [track];
|
||||
copy_field_( out->song, e.name );
|
||||
if ( e.length >= 0 ) out->length = e.length * 1000L;
|
||||
if ( e.intro >= 0 ) out->intro_length = e.intro * 1000L;
|
||||
if ( e.loop >= 0 ) out->loop_length = e.loop * 1000L;
|
||||
if ( e.length >= 0 ) out->length = e.length;
|
||||
if ( e.intro >= 0 ) out->intro_length = e.intro;
|
||||
if ( e.loop >= 0 ) out->loop_length = e.loop;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
// Common interface to game music file loading and information
|
||||
|
||||
// Game_Music_Emu 0.6.0
|
||||
// Game_Music_Emu https://bitbucket.org/mpyne/game-music-emu/
|
||||
#ifndef GME_FILE_H
|
||||
#define GME_FILE_H
|
||||
|
||||
@@ -105,7 +105,7 @@ public:
|
||||
Gme_File();
|
||||
virtual ~Gme_File();
|
||||
BLARGG_DISABLE_NOTHROW
|
||||
typedef BOOST::uint8_t byte;
|
||||
typedef uint8_t byte;
|
||||
protected:
|
||||
// Services
|
||||
void set_track_count( int n ) { track_count_ = raw_track_count_ = n; }
|
||||
@@ -154,11 +154,7 @@ Music_Emu* gme_new_( Music_Emu*, long sample_rate );
|
||||
{ Gme_File::copy_field_( out->name, in.name, sizeof in.name ); }
|
||||
|
||||
#ifndef GME_FILE_READER
|
||||
#ifdef HAVE_ZLIB_H
|
||||
#define GME_FILE_READER Gzip_File_Reader
|
||||
#else
|
||||
#define GME_FILE_READER Std_File_Reader
|
||||
#endif
|
||||
#define GME_FILE_READER Std_File_Reader
|
||||
#elif defined (GME_FILE_READER_INCLUDE)
|
||||
#include GME_FILE_READER_INCLUDE
|
||||
#endif
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Game_Music_Emu 0.6.0. http://www.slack.net/~ant/
|
||||
// Game_Music_Emu https://bitbucket.org/mpyne/game-music-emu/
|
||||
|
||||
#include "Gym_Emu.h"
|
||||
|
||||
@@ -162,7 +162,7 @@ static Music_Emu* new_gym_emu () { return BLARGG_NEW Gym_Emu ; }
|
||||
static Music_Emu* new_gym_file() { return BLARGG_NEW Gym_File; }
|
||||
|
||||
static gme_type_t_ const gme_gym_type_ = { "Sega Genesis", 1, &new_gym_emu, &new_gym_file, "GYM", 0 };
|
||||
gme_type_t const gme_gym_type = &gme_gym_type_;
|
||||
extern gme_type_t const gme_gym_type = &gme_gym_type_;
|
||||
|
||||
// Setup
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// Sega Genesis/Mega Drive GYM music file emulator
|
||||
// Includes with PCM timing recovery to improve sample quality.
|
||||
|
||||
// Game_Music_Emu 0.6.0
|
||||
// Game_Music_Emu https://bitbucket.org/mpyne/game-music-emu/
|
||||
#ifndef GYM_EMU_H
|
||||
#define GYM_EMU_H
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Game_Music_Emu 0.6.0. http://www.slack.net/~ant/
|
||||
// Game_Music_Emu https://bitbucket.org/mpyne/game-music-emu/
|
||||
|
||||
#include "Hes_Apu.h"
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// Turbo Grafx 16 (PC Engine) PSG sound chip emulator
|
||||
|
||||
// Game_Music_Emu 0.6.0
|
||||
// Game_Music_Emu https://bitbucket.org/mpyne/game-music-emu/
|
||||
#ifndef HES_APU_H
|
||||
#define HES_APU_H
|
||||
|
||||
|
||||
+236
-240
File diff suppressed because it is too large.
Load diff
@@ -1,6 +1,6 @@
|
||||
// PC Engine CPU emulator for use with HES music files
|
||||
|
||||
// Game_Music_Emu 0.6.0
|
||||
// Game_Music_Emu https://bitbucket.org/mpyne/game-music-emu/
|
||||
#ifndef HES_CPU_H
|
||||
#define HES_CPU_H
|
||||
|
||||
@@ -12,8 +12,6 @@ enum { future_hes_time = INT_MAX / 2 + 1 };
|
||||
|
||||
class Hes_Cpu {
|
||||
public:
|
||||
typedef BOOST::uint8_t uint8_t;
|
||||
|
||||
void reset();
|
||||
|
||||
enum { page_size = 0x2000 };
|
||||
@@ -27,7 +25,7 @@ public:
|
||||
|
||||
// not kept updated during a call to run()
|
||||
struct registers_t {
|
||||
BOOST::uint16_t pc;
|
||||
uint16_t pc;
|
||||
uint8_t a;
|
||||
uint8_t x;
|
||||
uint8_t y;
|
||||
@@ -86,7 +84,7 @@ private:
|
||||
inline int update_end_time( hes_time_t end, hes_time_t irq );
|
||||
};
|
||||
|
||||
inline BOOST::uint8_t const* Hes_Cpu::get_code( hes_addr_t addr )
|
||||
inline uint8_t const* Hes_Cpu::get_code( hes_addr_t addr )
|
||||
{
|
||||
return state->code_map [addr >> page_shift] + addr
|
||||
#if !BLARGG_NONPORTABLE
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
// Game_Music_Emu 0.6.0. http://www.slack.net/~ant/
|
||||
// Game_Music_Emu https://bitbucket.org/mpyne/game-music-emu/
|
||||
|
||||
#include "Hes_Emu.h"
|
||||
|
||||
#include "blargg_endian.h"
|
||||
#include <string.h>
|
||||
#include <algorithm>
|
||||
|
||||
/* Copyright (C) 2006 Shay Green. This module is free software; you
|
||||
can redistribute it and/or modify it under the terms of the GNU Lesser
|
||||
@@ -25,6 +26,9 @@ int const unmapped = 0xFF;
|
||||
|
||||
long const period_60hz = 262 * 455L; // scanlines * clocks per scanline
|
||||
|
||||
using std::min;
|
||||
using std::max;
|
||||
|
||||
Hes_Emu::Hes_Emu()
|
||||
{
|
||||
timer.raw_load = 0;
|
||||
@@ -133,7 +137,7 @@ static Music_Emu* new_hes_emu () { return BLARGG_NEW Hes_Emu ; }
|
||||
static Music_Emu* new_hes_file() { return BLARGG_NEW Hes_File; }
|
||||
|
||||
static gme_type_t_ const gme_hes_type_ = { "PC Engine", 256, &new_hes_emu, &new_hes_file, "HES", 1 };
|
||||
gme_type_t const gme_hes_type = &gme_hes_type_;
|
||||
extern gme_type_t const gme_hes_type = &gme_hes_type_;
|
||||
|
||||
|
||||
// Setup
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// TurboGrafx-16/PC Engine HES music file emulator
|
||||
|
||||
// Game_Music_Emu 0.6.0
|
||||
// Game_Music_Emu https://bitbucket.org/mpyne/game-music-emu/
|
||||
#ifndef HES_EMU_H
|
||||
#define HES_EMU_H
|
||||
|
||||
|
||||
+50
-56
@@ -1,4 +1,4 @@
|
||||
// Game_Music_Emu 0.6.0. http://www.slack.net/~ant/
|
||||
// Game_Music_Emu https://bitbucket.org/mpyne/game-music-emu/
|
||||
|
||||
/*
|
||||
Last validated with zexall 2006.11.14 2:19 PM
|
||||
@@ -136,7 +136,7 @@ void Kss_Cpu::map_mem( unsigned addr, blargg_ulong size, void* write, void const
|
||||
#define R16( n, shift, offset )\
|
||||
(*(uint16_t*) ((char*) r16_ - (offset >> (shift - 1)) + ((n) >> (shift - 1))))
|
||||
|
||||
#define CASE5( a, b, c, d, e ) case 0x##a:case 0x##b:case 0x##c:case 0x##d:case 0x##e
|
||||
#define CASE5( a, b, c, d, e ) /*FALLTHRU*/ case 0x##a:case 0x##b:case 0x##c:case 0x##d:case 0x##e
|
||||
#define CASE6( a, b, c, d, e, f ) CASE5( a, b, c, d, e ): case 0x##f
|
||||
#define CASE7( a, b, c, d, e, f, g ) CASE6( a, b, c, d, e, f ): case 0x##g
|
||||
#define CASE8( a, b, c, d, e, f, g, h ) CASE7( a, b, c, d, e, f, g ): case 0x##h
|
||||
@@ -162,11 +162,6 @@ static byte const ed_dd_timing [0x100] = {
|
||||
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,0x00,0x00,0x00,0x00,0x00,0x00,
|
||||
};
|
||||
|
||||
// even on x86, using short and unsigned char was slower
|
||||
typedef int fint16;
|
||||
typedef unsigned fuint16;
|
||||
typedef unsigned fuint8;
|
||||
|
||||
bool Kss_Cpu::run( cpu_time_t end_time )
|
||||
{
|
||||
set_end_time( end_time );
|
||||
@@ -174,8 +169,6 @@ bool Kss_Cpu::run( cpu_time_t end_time )
|
||||
this->state = &s;
|
||||
bool warning = false;
|
||||
|
||||
typedef BOOST::int8_t int8_t;
|
||||
|
||||
union {
|
||||
regs_t rg;
|
||||
pairs_t rp;
|
||||
@@ -185,10 +178,10 @@ bool Kss_Cpu::run( cpu_time_t end_time )
|
||||
rg = this->r.b;
|
||||
|
||||
cpu_time_t s_time = s.time;
|
||||
fuint16 pc = r.pc;
|
||||
fuint16 sp = r.sp;
|
||||
fuint16 ix = r.ix; // TODO: keep in memory for direct access?
|
||||
fuint16 iy = r.iy;
|
||||
uint_fast32_t pc = r.pc;
|
||||
uint_fast32_t sp = r.sp;
|
||||
uint_fast32_t ix = r.ix; // TODO: keep in memory for direct access?
|
||||
uint_fast32_t iy = r.iy;
|
||||
int flags = r.b.flags;
|
||||
|
||||
goto loop;
|
||||
@@ -210,7 +203,7 @@ loop:
|
||||
uint8_t const* instr = s.read [pc >> page_shift];
|
||||
#define GET_ADDR() GET_LE16( instr )
|
||||
|
||||
fuint8 opcode;
|
||||
uint_fast8_t opcode;
|
||||
|
||||
// TODO: eliminate this special case
|
||||
#if BLARGG_NONPORTABLE
|
||||
@@ -243,7 +236,7 @@ loop:
|
||||
11,10,10, 4,17,11, 7,11,11, 6,10, 4,17, 8, 7,11, // F
|
||||
};
|
||||
|
||||
fuint16 data;
|
||||
uint_fast16_t data;
|
||||
data = base_timing [opcode];
|
||||
if ( (s_time += data) >= 0 )
|
||||
goto possibly_out_of_time;
|
||||
@@ -299,7 +292,7 @@ possibly_out_of_time:
|
||||
goto loop;
|
||||
|
||||
case 0x3A:{// LD A,(addr)
|
||||
fuint16 addr = GET_ADDR();
|
||||
uint_fast16_t addr = GET_ADDR();
|
||||
pc += 2;
|
||||
rg.a = READ( addr );
|
||||
goto loop;
|
||||
@@ -315,7 +308,7 @@ possibly_out_of_time:
|
||||
// JR
|
||||
// TODO: more efficient way to handle negative branch that wraps PC around
|
||||
#define JR( cond ) {\
|
||||
int offset = (BOOST::int8_t) data;\
|
||||
int offset = (int8_t) data;\
|
||||
pc++;\
|
||||
if ( !(cond) )\
|
||||
goto jr_not_taken;\
|
||||
@@ -387,7 +380,7 @@ possibly_out_of_time:
|
||||
|
||||
case 0xCD:{// CALL addr
|
||||
call_taken:
|
||||
fuint16 addr = pc + 2;
|
||||
uint_fast16_t addr = pc + 2;
|
||||
pc = GET_ADDR();
|
||||
sp = uint16_t (sp - 2);
|
||||
WRITE_WORD( sp, addr );
|
||||
@@ -397,6 +390,7 @@ possibly_out_of_time:
|
||||
case 0xFF: // RST
|
||||
if ( pc > idle_addr )
|
||||
goto hit_idle_addr;
|
||||
// FALLTHRU
|
||||
CASE7( C7, CF, D7, DF, E7, EF, F7 ):
|
||||
data = pc;
|
||||
pc = opcode & 0x38;
|
||||
@@ -432,7 +426,7 @@ possibly_out_of_time:
|
||||
// ADC/ADD/SBC/SUB
|
||||
case 0x96: // SUB (HL)
|
||||
case 0x86: // ADD (HL)
|
||||
flags &= ~C01;
|
||||
flags &= ~C01; // FALLTHRU
|
||||
case 0x9E: // SBC (HL)
|
||||
case 0x8E: // ADC (HL)
|
||||
data = READ( rp.hl );
|
||||
@@ -440,7 +434,7 @@ possibly_out_of_time:
|
||||
|
||||
case 0xD6: // SUB A,imm
|
||||
case 0xC6: // ADD imm
|
||||
flags &= ~C01;
|
||||
flags &= ~C01; // FALLTHRU
|
||||
case 0xDE: // SBC A,imm
|
||||
case 0xCE: // ADC imm
|
||||
pc++;
|
||||
@@ -693,21 +687,21 @@ possibly_out_of_time:
|
||||
goto loop;
|
||||
|
||||
case 0x2A:{// LD HL,(addr)
|
||||
fuint16 addr = GET_ADDR();
|
||||
uint_fast16_t addr = GET_ADDR();
|
||||
pc += 2;
|
||||
rp.hl = READ_WORD( addr );
|
||||
goto loop;
|
||||
}
|
||||
|
||||
case 0x32:{// LD (addr),A
|
||||
fuint16 addr = GET_ADDR();
|
||||
uint_fast16_t addr = GET_ADDR();
|
||||
pc += 2;
|
||||
WRITE( addr, rg.a );
|
||||
goto loop;
|
||||
}
|
||||
|
||||
case 0x22:{// LD (addr),HL
|
||||
fuint16 addr = GET_ADDR();
|
||||
uint_fast16_t addr = GET_ADDR();
|
||||
pc += 2;
|
||||
WRITE_WORD( addr, rp.hl );
|
||||
goto loop;
|
||||
@@ -730,7 +724,7 @@ possibly_out_of_time:
|
||||
// Rotate
|
||||
|
||||
case 0x07:{// RLCA
|
||||
fuint16 temp = rg.a;
|
||||
uint_fast16_t temp = rg.a;
|
||||
temp = (temp << 1) | (temp >> 7);
|
||||
flags = (flags & (S80 | Z40 | P04)) |
|
||||
(temp & (F20 | F08 | C01));
|
||||
@@ -739,7 +733,7 @@ possibly_out_of_time:
|
||||
}
|
||||
|
||||
case 0x0F:{// RRCA
|
||||
fuint16 temp = rg.a;
|
||||
uint_fast16_t temp = rg.a;
|
||||
flags = (flags & (S80 | Z40 | P04)) |
|
||||
(temp & C01);
|
||||
temp = (temp << 7) | (temp >> 1);
|
||||
@@ -753,12 +747,12 @@ possibly_out_of_time:
|
||||
flags = (flags & (S80 | Z40 | P04)) |
|
||||
(temp & (F20 | F08)) |
|
||||
(temp >> 8);
|
||||
rg.a = temp;
|
||||
rg.a = (uint8_t)temp;
|
||||
goto loop;
|
||||
}
|
||||
|
||||
case 0x1F:{// RRA
|
||||
fuint16 temp = (flags << 7) | (rg.a >> 1);
|
||||
uint_fast16_t temp = (flags << 7) | (rg.a >> 1);
|
||||
flags = (flags & (S80 | Z40 | P04)) |
|
||||
(temp & (F20 | F08)) |
|
||||
(rg.a & C01);
|
||||
@@ -768,7 +762,7 @@ possibly_out_of_time:
|
||||
|
||||
// Misc
|
||||
case 0x2F:{// CPL
|
||||
fuint16 temp = ~rg.a;
|
||||
uint_fast16_t temp = ~rg.a;
|
||||
flags = (flags & (S80 | Z40 | P04 | C01)) |
|
||||
(temp & (F20 | F08)) |
|
||||
(H10 | N02);
|
||||
@@ -794,21 +788,21 @@ possibly_out_of_time:
|
||||
goto loop;
|
||||
|
||||
case 0xE3:{// EX (SP),HL
|
||||
fuint16 temp = READ_WORD( sp );
|
||||
uint_fast16_t temp = READ_WORD( sp );
|
||||
WRITE_WORD( sp, rp.hl );
|
||||
rp.hl = temp;
|
||||
goto loop;
|
||||
}
|
||||
|
||||
case 0xEB:{// EX DE,HL
|
||||
fuint16 temp = rp.hl;
|
||||
uint_fast16_t temp = rp.hl;
|
||||
rp.hl = rp.de;
|
||||
rp.de = temp;
|
||||
goto loop;
|
||||
}
|
||||
|
||||
case 0xD9:{// EXX DE,HL
|
||||
fuint16 temp = r.alt.w.bc;
|
||||
uint_fast16_t temp = r.alt.w.bc;
|
||||
r.alt.w.bc = rp.bc;
|
||||
rp.bc = temp;
|
||||
|
||||
@@ -849,7 +843,7 @@ possibly_out_of_time:
|
||||
// Rotate left
|
||||
|
||||
#define RLC( read, write ) {\
|
||||
fuint8 result = read;\
|
||||
uint_fast8_t result = read;\
|
||||
result = uint8_t (result << 1) | (result >> 7);\
|
||||
flags = SZ28P( result ) | (result & C01);\
|
||||
write;\
|
||||
@@ -868,7 +862,7 @@ possibly_out_of_time:
|
||||
}
|
||||
|
||||
#define RL( read, write ) {\
|
||||
fuint16 result = (read << 1) | (flags & C01);\
|
||||
uint_fast16_t result = (read << 1) | (flags & C01);\
|
||||
flags = SZ28PC( result );\
|
||||
write;\
|
||||
goto loop;\
|
||||
@@ -886,7 +880,7 @@ possibly_out_of_time:
|
||||
}
|
||||
|
||||
#define SLA( read, add, write ) {\
|
||||
fuint16 result = (read << 1) | add;\
|
||||
uint_fast16_t result = (read << 1) | add;\
|
||||
flags = SZ28PC( result );\
|
||||
write;\
|
||||
goto loop;\
|
||||
@@ -917,7 +911,7 @@ possibly_out_of_time:
|
||||
// Rotate right
|
||||
|
||||
#define RRC( read, write ) {\
|
||||
fuint8 result = read;\
|
||||
uint_fast8_t result = read;\
|
||||
flags = result & C01;\
|
||||
result = uint8_t (result << 7) | (result >> 1);\
|
||||
flags |= SZ28P( result );\
|
||||
@@ -937,8 +931,8 @@ possibly_out_of_time:
|
||||
}
|
||||
|
||||
#define RR( read, write ) {\
|
||||
fuint8 result = read;\
|
||||
fuint8 temp = result & C01;\
|
||||
uint_fast8_t result = read;\
|
||||
uint_fast8_t temp = result & C01;\
|
||||
result = uint8_t (flags << 7) | (result >> 1);\
|
||||
flags = SZ28P( result ) | temp;\
|
||||
write;\
|
||||
@@ -957,7 +951,7 @@ possibly_out_of_time:
|
||||
}
|
||||
|
||||
#define SRA( read, write ) {\
|
||||
fuint8 result = read;\
|
||||
uint_fast8_t result = read;\
|
||||
flags = result & C01;\
|
||||
result = (result & 0x80) | (result >> 1);\
|
||||
flags |= SZ28P( result );\
|
||||
@@ -977,7 +971,7 @@ possibly_out_of_time:
|
||||
}
|
||||
|
||||
#define SRL( read, write ) {\
|
||||
fuint8 result = read;\
|
||||
uint_fast8_t result = read;\
|
||||
flags = result & C01;\
|
||||
result >>= 1;\
|
||||
flags |= SZ28P( result );\
|
||||
@@ -1121,7 +1115,7 @@ possibly_out_of_time:
|
||||
case 0x43: // LD (ADDR),BC
|
||||
case 0x53: // LD (ADDR),DE
|
||||
temp = R16( data, 4, 0x43 );
|
||||
fuint16 addr = GET_ADDR();
|
||||
uint_fast16_t addr = GET_ADDR();
|
||||
pc += 2;
|
||||
WRITE_WORD( addr, temp );
|
||||
goto loop;
|
||||
@@ -1129,21 +1123,21 @@ possibly_out_of_time:
|
||||
|
||||
case 0x4B: // LD BC,(ADDR)
|
||||
case 0x5B:{// LD DE,(ADDR)
|
||||
fuint16 addr = GET_ADDR();
|
||||
uint_fast16_t addr = GET_ADDR();
|
||||
pc += 2;
|
||||
R16( data, 4, 0x4B ) = READ_WORD( addr );
|
||||
goto loop;
|
||||
}
|
||||
|
||||
case 0x7B:{// LD SP,(ADDR)
|
||||
fuint16 addr = GET_ADDR();
|
||||
uint_fast16_t addr = GET_ADDR();
|
||||
pc += 2;
|
||||
sp = READ_WORD( addr );
|
||||
goto loop;
|
||||
}
|
||||
|
||||
case 0x67:{// RRD
|
||||
fuint8 temp = READ( rp.hl );
|
||||
uint_fast8_t temp = READ( rp.hl );
|
||||
WRITE( rp.hl, (rg.a << 4) | (temp >> 4) );
|
||||
temp = (rg.a & 0xF0) | (temp & 0x0F);
|
||||
flags = (flags & C01) | SZ28P( temp );
|
||||
@@ -1152,7 +1146,7 @@ possibly_out_of_time:
|
||||
}
|
||||
|
||||
case 0x6F:{// RLD
|
||||
fuint8 temp = READ( rp.hl );
|
||||
uint_fast8_t temp = READ( rp.hl );
|
||||
WRITE( rp.hl, (temp << 4) | (rg.a & 0x0F) );
|
||||
temp = (rg.a & 0xF0) | (temp >> 4);
|
||||
flags = (flags & C01) | SZ28P( temp );
|
||||
@@ -1176,7 +1170,7 @@ possibly_out_of_time:
|
||||
case 0xA1: // CPI
|
||||
case 0xB1: // CPIR
|
||||
inc = +1;
|
||||
fuint16 addr = rp.hl;
|
||||
uint_fast16_t addr = rp.hl;
|
||||
rp.hl = addr + inc;
|
||||
int temp = READ( addr );
|
||||
|
||||
@@ -1209,7 +1203,7 @@ possibly_out_of_time:
|
||||
case 0xA0: // LDI
|
||||
case 0xB0: // LDIR
|
||||
inc = +1;
|
||||
fuint16 addr = rp.hl;
|
||||
uint_fast16_t addr = rp.hl;
|
||||
rp.hl = addr + inc;
|
||||
int temp = READ( addr );
|
||||
|
||||
@@ -1241,7 +1235,7 @@ possibly_out_of_time:
|
||||
case 0xA3: // OUTI
|
||||
case 0xB3: // OTIR
|
||||
inc = +1;
|
||||
fuint16 addr = rp.hl;
|
||||
uint_fast16_t addr = rp.hl;
|
||||
rp.hl = addr + inc;
|
||||
int temp = READ( addr );
|
||||
|
||||
@@ -1267,7 +1261,7 @@ possibly_out_of_time:
|
||||
case 0xB2: // INIR
|
||||
inc = +1;
|
||||
|
||||
fuint16 addr = rp.hl;
|
||||
uint_fast16_t addr = rp.hl;
|
||||
rp.hl = addr + inc;
|
||||
|
||||
int temp = IN( rp.bc );
|
||||
@@ -1332,7 +1326,7 @@ possibly_out_of_time:
|
||||
|
||||
//////////////////////////////////////// DD/FD prefix
|
||||
{
|
||||
fuint16 ixy;
|
||||
uint_fast16_t ixy;
|
||||
case 0xDD:
|
||||
ixy = ix;
|
||||
goto ix_prefix;
|
||||
@@ -1354,7 +1348,7 @@ possibly_out_of_time:
|
||||
|
||||
case 0x96: // SUB (IXY+disp)
|
||||
case 0x86: // ADD (IXY+disp)
|
||||
flags &= ~C01;
|
||||
flags &= ~C01; // FALLTHRU
|
||||
case 0x9E: // SBC (IXY+disp)
|
||||
case 0x8E: // ADC (IXY+disp)
|
||||
pc++;
|
||||
@@ -1364,7 +1358,7 @@ possibly_out_of_time:
|
||||
|
||||
case 0x94: // SUB HXY
|
||||
case 0x84: // ADD HXY
|
||||
flags &= ~C01;
|
||||
flags &= ~C01; // FALLTHRU
|
||||
case 0x9C: // SBC HXY
|
||||
case 0x8C: // ADC HXY
|
||||
opcode = data;
|
||||
@@ -1373,7 +1367,7 @@ possibly_out_of_time:
|
||||
|
||||
case 0x95: // SUB LXY
|
||||
case 0x85: // ADD LXY
|
||||
flags &= ~C01;
|
||||
flags &= ~C01; // FALLTHRU
|
||||
case 0x9D: // SBC LXY
|
||||
case 0x8D: // ADC LXY
|
||||
opcode = data;
|
||||
@@ -1528,7 +1522,7 @@ possibly_out_of_time:
|
||||
goto loop;
|
||||
|
||||
case 0x22:{// LD (ADDR),IXY
|
||||
fuint16 addr = GET_ADDR();
|
||||
uint_fast16_t addr = GET_ADDR();
|
||||
pc += 2;
|
||||
WRITE_WORD( addr, ixy );
|
||||
goto loop;
|
||||
@@ -1540,7 +1534,7 @@ possibly_out_of_time:
|
||||
goto set_ixy;
|
||||
|
||||
case 0x2A:{// LD IXY,(addr)
|
||||
fuint16 addr = GET_ADDR();
|
||||
uint_fast16_t addr = GET_ADDR();
|
||||
ixy = READ_WORD( addr );
|
||||
pc += 2;
|
||||
goto set_ixy;
|
||||
@@ -1564,7 +1558,7 @@ possibly_out_of_time:
|
||||
case 0x3E: goto srl_data_addr; // SRL (IXY)
|
||||
|
||||
CASE8( 46, 4E, 56, 5E, 66, 6E, 76, 7E ):{// BIT b,(IXY+disp)
|
||||
fuint8 temp = READ( data );
|
||||
uint_fast8_t temp = READ( data );
|
||||
int masked = temp & 1 << (data2 >> 3 & 7);
|
||||
flags = (flags & C01) | H10 |
|
||||
(masked & S80) |
|
||||
@@ -1666,7 +1660,7 @@ possibly_out_of_time:
|
||||
goto loop;
|
||||
|
||||
case 0xE3:{// EX (SP),IXY
|
||||
fuint16 temp = READ_WORD( sp );
|
||||
uint_fast16_t temp = READ_WORD( sp );
|
||||
WRITE_WORD( sp, ixy );
|
||||
ixy = temp;
|
||||
goto set_ixy;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// Z80 CPU emulator
|
||||
|
||||
// Game_Music_Emu 0.6.0
|
||||
// Game_Music_Emu https://bitbucket.org/mpyne/game-music-emu/
|
||||
#ifndef KSS_CPU_H
|
||||
#define KSS_CPU_H
|
||||
|
||||
@@ -15,8 +15,6 @@ void kss_cpu_write( class Kss_Cpu*, unsigned addr, int data );
|
||||
|
||||
class Kss_Cpu {
|
||||
public:
|
||||
typedef BOOST::uint8_t uint8_t;
|
||||
|
||||
// Clear registers and map all pages to unmapped
|
||||
void reset( void* unmapped_write, void const* unmapped_read );
|
||||
|
||||
@@ -39,8 +37,6 @@ public:
|
||||
void set_time( cpu_time_t t ) { state->time = t - state->base; }
|
||||
void adjust_time( int delta ) { state->time += delta; }
|
||||
|
||||
typedef BOOST::uint16_t uint16_t;
|
||||
|
||||
#if BLARGG_BIG_ENDIAN
|
||||
struct regs_t { uint8_t b, c, d, e, h, l, flags, a; };
|
||||
#else
|
||||
@@ -104,12 +100,12 @@ public:
|
||||
#define KSS_CPU_PAGE_OFFSET( addr ) ((addr) & (page_size - 1))
|
||||
#endif
|
||||
|
||||
inline BOOST::uint8_t* Kss_Cpu::write( unsigned addr )
|
||||
inline uint8_t* Kss_Cpu::write( unsigned addr )
|
||||
{
|
||||
return state->write [addr >> page_shift] + KSS_CPU_PAGE_OFFSET( addr );
|
||||
}
|
||||
|
||||
inline BOOST::uint8_t const* Kss_Cpu::read( unsigned addr )
|
||||
inline uint8_t const* Kss_Cpu::read( unsigned addr )
|
||||
{
|
||||
return state->read [addr >> page_shift] + KSS_CPU_PAGE_OFFSET( addr );
|
||||
}
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
// Game_Music_Emu 0.6.0. http://www.slack.net/~ant/
|
||||
// Game_Music_Emu https://bitbucket.org/mpyne/game-music-emu/
|
||||
|
||||
#include "Kss_Emu.h"
|
||||
|
||||
#include "blargg_endian.h"
|
||||
#include <string.h>
|
||||
#include <algorithm>
|
||||
|
||||
/* Copyright (C) 2006 Shay Green. This module is free software; you
|
||||
can redistribute it and/or modify it under the terms of the GNU Lesser
|
||||
@@ -21,6 +22,9 @@ Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */
|
||||
long const clock_rate = 3579545;
|
||||
int const osc_count = Ay_Apu::osc_count + Scc_Apu::osc_count;
|
||||
|
||||
using std::min;
|
||||
using std::max;
|
||||
|
||||
Kss_Emu::Kss_Emu()
|
||||
{
|
||||
sn = 0;
|
||||
@@ -102,7 +106,7 @@ static Music_Emu* new_kss_emu () { return BLARGG_NEW Kss_Emu ; }
|
||||
static Music_Emu* new_kss_file() { return BLARGG_NEW Kss_File; }
|
||||
|
||||
static gme_type_t_ const gme_kss_type_ = { "MSX", 256, &new_kss_emu, &new_kss_file, "KSS", 0x03 };
|
||||
gme_type_t const gme_kss_type = &gme_kss_type_;
|
||||
extern gme_type_t const gme_kss_type = &gme_kss_type_;
|
||||
|
||||
|
||||
// Setup
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// MSX computer KSS music file emulator
|
||||
|
||||
// Game_Music_Emu 0.6.0
|
||||
// Game_Music_Emu https://bitbucket.org/mpyne/game-music-emu/
|
||||
#ifndef KSS_EMU_H
|
||||
#define KSS_EMU_H
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Game_Music_Emu 0.6.0. http://www.slack.net/~ant/
|
||||
// Game_Music_Emu https://bitbucket.org/mpyne/game-music-emu/
|
||||
|
||||
#include "Kss_Scc_Apu.h"
|
||||
|
||||
@@ -43,7 +43,7 @@ void Scc_Apu::run_until( blip_time_t end_time )
|
||||
volume = (regs [0x8A + index] & 0x0F) * (amp_range / 256 / 15);
|
||||
}
|
||||
|
||||
BOOST::int8_t const* wave = (BOOST::int8_t*) regs + index * wave_size;
|
||||
int8_t const* wave = (int8_t*) regs + index * wave_size;
|
||||
if ( index == osc_count - 1 )
|
||||
wave -= wave_size; // last two oscs share wave
|
||||
{
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// Konami SCC sound chip emulator
|
||||
|
||||
// Game_Music_Emu 0.6.0
|
||||
// Game_Music_Emu https://bitbucket.org/mpyne/game-music-emu/
|
||||
#ifndef KSS_SCC_APU_H
|
||||
#define KSS_SCC_APU_H
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Game_Music_Emu 0.6.0. http://www.slack.net/~ant/
|
||||
// Game_Music_Emu https://bitbucket.org/mpyne/game-music-emu/
|
||||
|
||||
#include "M3u_Playlist.h"
|
||||
#include "Music_Emu.h"
|
||||
@@ -52,9 +52,9 @@ blargg_err_t Gme_File::load_m3u( const char* path ) { return load_m3u_( playlist
|
||||
|
||||
blargg_err_t Gme_File::load_m3u( Data_Reader& in ) { return load_m3u_( playlist.load( in ) ); }
|
||||
|
||||
BLARGG_EXPORT gme_err_t gme_load_m3u( Music_Emu* me, const char* path ) { return me->load_m3u( path ); }
|
||||
gme_err_t gme_load_m3u( Music_Emu* me, const char* path ) { return me->load_m3u( path ); }
|
||||
|
||||
BLARGG_EXPORT gme_err_t gme_load_m3u_data( Music_Emu* me, const void* data, long size )
|
||||
gme_err_t gme_load_m3u_data( Music_Emu* me, const void* data, long size )
|
||||
{
|
||||
Mem_File_Reader in( data, size );
|
||||
return me->load_m3u( in );
|
||||
@@ -153,6 +153,23 @@ static char* parse_int_( char* in, int* out )
|
||||
return in;
|
||||
}
|
||||
|
||||
static char* parse_mil_( char* in, int* out )
|
||||
{
|
||||
int n = 0;
|
||||
int x = 100;
|
||||
while ( 1 )
|
||||
{
|
||||
unsigned d = from_dec( *in );
|
||||
if ( d > 9 )
|
||||
break;
|
||||
in++;
|
||||
n += d * x;
|
||||
x /= 10;
|
||||
*out = n;
|
||||
}
|
||||
return in;
|
||||
}
|
||||
|
||||
static char* parse_int( char* in, int* out, int* result )
|
||||
{
|
||||
return next_field( parse_int_( in, out ), result );
|
||||
@@ -200,13 +217,22 @@ static char* parse_time_( char* in, int* out )
|
||||
if ( n >= 0 )
|
||||
{
|
||||
*out = n;
|
||||
if ( *in == ':' )
|
||||
while ( *in == ':' )
|
||||
{
|
||||
n = -1;
|
||||
in = parse_int_( in + 1, &n );
|
||||
if ( n >= 0 )
|
||||
*out = *out * 60 + n;
|
||||
}
|
||||
*out *= 1000;
|
||||
|
||||
if ( *in == '.' )
|
||||
{
|
||||
n = -1;
|
||||
in = parse_mil_( in + 1, &n );
|
||||
if ( n >= 0 )
|
||||
*out += n;
|
||||
}
|
||||
}
|
||||
return in;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// M3U playlist file parser, with support for subtrack information
|
||||
|
||||
// Game_Music_Emu 0.6.0
|
||||
// Game_Music_Emu https://bitbucket.org/mpyne/game-music-emu/
|
||||
#ifndef M3U_PLAYLIST_H
|
||||
#define M3U_PLAYLIST_H
|
||||
|
||||
@@ -36,7 +36,7 @@ public:
|
||||
bool decimal_track; // true if track was specified in hex
|
||||
// integers are -1 if not present
|
||||
int track; // 1-based
|
||||
int length; // seconds
|
||||
int length; // milliseconds
|
||||
int intro;
|
||||
int loop;
|
||||
int fade;
|
||||
|
||||
@@ -81,7 +81,7 @@ void Stereo_Buffer::clock_rate( long rate )
|
||||
|
||||
void Stereo_Buffer::bass_freq( int bass )
|
||||
{
|
||||
for ( unsigned i = 0; i < buf_count; i++ )
|
||||
for ( int i = 0; i < buf_count; i++ )
|
||||
bufs [i].bass_freq( bass );
|
||||
}
|
||||
|
||||
@@ -96,7 +96,7 @@ void Stereo_Buffer::clear()
|
||||
void Stereo_Buffer::end_frame( blip_time_t clock_count )
|
||||
{
|
||||
stereo_added = 0;
|
||||
for ( unsigned i = 0; i < buf_count; i++ )
|
||||
for ( int i = 0; i < buf_count; i++ )
|
||||
{
|
||||
stereo_added |= bufs [i].clear_modified() << i;
|
||||
bufs [i].end_frame( clock_count );
|
||||
@@ -161,11 +161,11 @@ void Stereo_Buffer::mix_stereo( blip_sample_t* out_, blargg_long count )
|
||||
int c = BLIP_READER_READ( center );
|
||||
blargg_long l = c + BLIP_READER_READ( left );
|
||||
blargg_long r = c + BLIP_READER_READ( right );
|
||||
if ( (BOOST::int16_t) l != l )
|
||||
if ( (int16_t) l != l )
|
||||
l = 0x7FFF - (l >> 24);
|
||||
|
||||
BLIP_READER_NEXT( center, bass );
|
||||
if ( (BOOST::int16_t) r != r )
|
||||
if ( (int16_t) r != r )
|
||||
r = 0x7FFF - (r >> 24);
|
||||
|
||||
BLIP_READER_NEXT( left, bass );
|
||||
@@ -191,11 +191,11 @@ void Stereo_Buffer::mix_stereo_no_center( blip_sample_t* out_, blargg_long count
|
||||
for ( ; count; --count )
|
||||
{
|
||||
blargg_long l = BLIP_READER_READ( left );
|
||||
if ( (BOOST::int16_t) l != l )
|
||||
if ( (int16_t) l != l )
|
||||
l = 0x7FFF - (l >> 24);
|
||||
|
||||
blargg_long r = BLIP_READER_READ( right );
|
||||
if ( (BOOST::int16_t) r != r )
|
||||
if ( (int16_t) r != r )
|
||||
r = 0x7FFF - (r >> 24);
|
||||
|
||||
BLIP_READER_NEXT( left, bass );
|
||||
@@ -219,7 +219,7 @@ void Stereo_Buffer::mix_mono( blip_sample_t* out_, blargg_long count )
|
||||
for ( ; count; --count )
|
||||
{
|
||||
blargg_long s = BLIP_READER_READ( center );
|
||||
if ( (BOOST::int16_t) s != s )
|
||||
if ( (int16_t) s != s )
|
||||
s = 0x7FFF - (s >> 24);
|
||||
|
||||
BLIP_READER_NEXT( center, bass );
|
||||
|
||||
+44
-10
@@ -1,9 +1,10 @@
|
||||
// Game_Music_Emu 0.6.0. http://www.slack.net/~ant/
|
||||
// Game_Music_Emu https://bitbucket.org/mpyne/game-music-emu/
|
||||
|
||||
#include "Music_Emu.h"
|
||||
|
||||
#include "Multi_Buffer.h"
|
||||
#include <string.h>
|
||||
#include <algorithm>
|
||||
|
||||
/* Copyright (C) 2003-2006 Shay Green. This module is free software; you
|
||||
can redistribute it and/or modify it under the terms of the GNU Lesser
|
||||
@@ -18,12 +19,14 @@ Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */
|
||||
|
||||
#include "blargg_source.h"
|
||||
|
||||
int const stereo = 2; // number of channels for stereo
|
||||
int const silence_max = 6; // seconds
|
||||
int const silence_threshold = 0x10;
|
||||
long const fade_block_size = 512;
|
||||
int const fade_shift = 8; // fade ends with gain at 1.0 / (1 << fade_shift)
|
||||
|
||||
using std::min;
|
||||
using std::max;
|
||||
|
||||
Music_Emu::equalizer_t const Music_Emu::tv_eq =
|
||||
Music_Emu::make_equalizer( -8.0, 180 );
|
||||
|
||||
@@ -52,7 +55,7 @@ void Music_Emu::unload()
|
||||
Music_Emu::Music_Emu()
|
||||
{
|
||||
effects_buffer = 0;
|
||||
|
||||
multi_channel_ = false;
|
||||
sample_rate_ = 0;
|
||||
mute_mask_ = 0;
|
||||
tempo_ = 1.0;
|
||||
@@ -65,6 +68,8 @@ Music_Emu::Music_Emu()
|
||||
equalizer_.treble = -1.0;
|
||||
equalizer_.bass = 60;
|
||||
|
||||
emu_autoload_playback_limit_ = true;
|
||||
|
||||
static const char* const names [] = {
|
||||
"Voice 1", "Voice 2", "Voice 3", "Voice 4",
|
||||
"Voice 5", "Voice 6", "Voice 7", "Voice 8"
|
||||
@@ -96,6 +101,25 @@ void Music_Emu::set_equalizer( equalizer_t const& eq )
|
||||
set_equalizer_( eq );
|
||||
}
|
||||
|
||||
bool Music_Emu::multi_channel() const
|
||||
{
|
||||
return this->multi_channel_;
|
||||
}
|
||||
|
||||
blargg_err_t Music_Emu::set_multi_channel( bool )
|
||||
{
|
||||
// by default not supported, derived may override this
|
||||
return "unsupported for this emulator type";
|
||||
}
|
||||
|
||||
blargg_err_t Music_Emu::set_multi_channel_( bool isEnabled )
|
||||
{
|
||||
// multi channel support must be set at the very beginning
|
||||
require( !sample_rate() );
|
||||
multi_channel_ = isEnabled;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void Music_Emu::mute_voice( int index, bool mute )
|
||||
{
|
||||
require( (unsigned) index < (unsigned) voice_count() );
|
||||
@@ -145,7 +169,7 @@ blargg_err_t Music_Emu::start_track( int track )
|
||||
if ( !ignore_silence_ )
|
||||
{
|
||||
// play until non-silence or end of track
|
||||
for ( long end = max_initial_silence * stereo * sample_rate(); emu_time < end; )
|
||||
for ( long end = max_initial_silence * out_channels() * sample_rate(); emu_time < end; )
|
||||
{
|
||||
fill_buf();
|
||||
if ( buf_remain | (int) emu_track_ended_ )
|
||||
@@ -169,13 +193,23 @@ void Music_Emu::end_track_if_error( blargg_err_t err )
|
||||
}
|
||||
}
|
||||
|
||||
bool Music_Emu::autoload_playback_limit() const
|
||||
{
|
||||
return emu_autoload_playback_limit_;
|
||||
}
|
||||
|
||||
void Music_Emu::set_autoload_playback_limit( bool do_autoload_limit )
|
||||
{
|
||||
emu_autoload_playback_limit_ = do_autoload_limit;
|
||||
}
|
||||
|
||||
// Tell/Seek
|
||||
|
||||
blargg_long Music_Emu::msec_to_samples( blargg_long msec ) const
|
||||
{
|
||||
blargg_long sec = msec / 1000;
|
||||
msec -= sec * 1000;
|
||||
return (sec * sample_rate() + msec * sample_rate() / 1000) * stereo;
|
||||
return (sec * sample_rate() + msec * sample_rate() / 1000) * out_channels();
|
||||
}
|
||||
|
||||
long Music_Emu::tell_samples() const
|
||||
@@ -185,7 +219,7 @@ long Music_Emu::tell_samples() const
|
||||
|
||||
long Music_Emu::tell() const
|
||||
{
|
||||
blargg_long rate = sample_rate() * stereo;
|
||||
blargg_long rate = sample_rate() * out_channels();
|
||||
blargg_long sec = out_time / rate;
|
||||
return sec * 1000 + (out_time - sec * rate) * 1000 / rate;
|
||||
}
|
||||
@@ -263,7 +297,7 @@ blargg_err_t Music_Emu::skip_( long count )
|
||||
|
||||
void Music_Emu::set_fade( long start_msec, long length_msec )
|
||||
{
|
||||
fade_step = sample_rate() * length_msec / (fade_block_size * fade_shift * 1000 / stereo);
|
||||
fade_step = sample_rate() * length_msec / (fade_block_size * fade_shift * 1000 / out_channels());
|
||||
fade_start = msec_to_samples( start_msec );
|
||||
}
|
||||
|
||||
@@ -345,7 +379,7 @@ blargg_err_t Music_Emu::play( long out_count, sample_t* out )
|
||||
else
|
||||
{
|
||||
require( current_track() >= 0 );
|
||||
require( out_count % stereo == 0 );
|
||||
require( out_count % out_channels() == 0 );
|
||||
|
||||
assert( emu_time >= out_time );
|
||||
|
||||
@@ -365,7 +399,7 @@ blargg_err_t Music_Emu::play( long out_count, sample_t* out )
|
||||
memset( out, 0, pos * sizeof *out );
|
||||
silence_count -= pos;
|
||||
|
||||
if ( emu_time - silence_time > silence_max * stereo * sample_rate() )
|
||||
if ( emu_time - silence_time > silence_max * out_channels() * sample_rate() )
|
||||
{
|
||||
track_ended_ = emu_track_ended_ = true;
|
||||
silence_count = 0;
|
||||
@@ -401,7 +435,7 @@ blargg_err_t Music_Emu::play( long out_count, sample_t* out )
|
||||
}
|
||||
}
|
||||
|
||||
if ( out_time > fade_start )
|
||||
if ( fade_start >= 0 && out_time > fade_start )
|
||||
handle_fade( out_count, out );
|
||||
}
|
||||
out_time += out_count;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// Common interface to game music file emulators
|
||||
|
||||
// Game_Music_Emu 0.6.0
|
||||
// Game_Music_Emu https://bitbucket.org/mpyne/game-music-emu/
|
||||
#ifndef MUSIC_EMU_H
|
||||
#define MUSIC_EMU_H
|
||||
|
||||
@@ -13,6 +13,11 @@ public:
|
||||
|
||||
// Set output sample rate. Must be called only once before loading file.
|
||||
blargg_err_t set_sample_rate( long sample_rate );
|
||||
|
||||
// specifies if all 8 voices get rendered to their own stereo channel
|
||||
// default implementation of Music_Emu always returns not supported error (i.e. no multichannel support by default)
|
||||
// derived emus must override this if they support multichannel rendering
|
||||
virtual blargg_err_t set_multi_channel( bool is_enabled );
|
||||
|
||||
// Start a track, where 0 is the first track. Also clears warning string.
|
||||
blargg_err_t start_track( int );
|
||||
@@ -35,6 +40,8 @@ public:
|
||||
|
||||
// Names of voices
|
||||
const char** voice_names() const;
|
||||
|
||||
bool multi_channel() const;
|
||||
|
||||
// Track status/control
|
||||
|
||||
@@ -60,6 +67,13 @@ public:
|
||||
// true. Fade time can be changed while track is playing.
|
||||
void set_fade( long start_msec, long length_msec = 8000 );
|
||||
|
||||
// Controls whether or not to automatically load and obey track length
|
||||
// metadata for supported emulators.
|
||||
//
|
||||
// @since 0.6.2.
|
||||
bool autoload_playback_limit() const;
|
||||
void set_autoload_playback_limit( bool do_autoload_limit );
|
||||
|
||||
// Disable automatic end-of-track detection and skipping of silence at beginning
|
||||
void ignore_silence( bool disable = true );
|
||||
|
||||
@@ -127,6 +141,7 @@ protected:
|
||||
double gain() const { return gain_; }
|
||||
double tempo() const { return tempo_; }
|
||||
void remute_voices();
|
||||
blargg_err_t set_multi_channel_( bool is_enabled );
|
||||
|
||||
virtual blargg_err_t set_sample_rate_( long sample_rate ) = 0;
|
||||
virtual void set_equalizer_( equalizer_t const& ) { }
|
||||
@@ -149,7 +164,11 @@ private:
|
||||
int mute_mask_;
|
||||
double tempo_;
|
||||
double gain_;
|
||||
|
||||
bool multi_channel_;
|
||||
|
||||
// returns the number of output channels, i.e. usually 2 for stereo, unlesss multi_channel_ == true
|
||||
int out_channels() const { return this->multi_channel() ? 2*8 : 2; }
|
||||
|
||||
long sample_rate_;
|
||||
blargg_long msec_to_samples( blargg_long msec ) const;
|
||||
|
||||
@@ -158,6 +177,7 @@ private:
|
||||
blargg_long out_time; // number of samples played since start of track
|
||||
blargg_long emu_time; // number of samples emulator has generated since start of track
|
||||
bool emu_track_ended_; // emulator has reached end of track
|
||||
bool emu_autoload_playback_limit_; // whether to load and obey track length by default
|
||||
volatile bool track_ended_;
|
||||
void clear_track_vars();
|
||||
void end_track_if_error( blargg_err_t );
|
||||
@@ -179,7 +199,7 @@ private:
|
||||
void emu_play( long count, sample_t* out );
|
||||
|
||||
Multi_Buffer* effects_buffer;
|
||||
friend Music_Emu* gme_new_emu( gme_type_t, int );
|
||||
friend Music_Emu* gme_internal_new_emu_( gme_type_t, int, bool );
|
||||
friend void gme_set_stereo_depth( Music_Emu*, double );
|
||||
};
|
||||
|
||||
|
||||
+64
-75
@@ -1,4 +1,4 @@
|
||||
// Game_Music_Emu 0.6.0. http://www.slack.net/~ant/
|
||||
// Game_Music_Emu https://bitbucket.org/mpyne/game-music-emu/
|
||||
|
||||
#include "Nes_Cpu.h"
|
||||
|
||||
@@ -114,25 +114,20 @@ void Nes_Cpu::map_code( nes_addr_t start, unsigned size, void const* data, bool
|
||||
#define GET_SP() ((sp - 1) & 0xFF)
|
||||
#define PUSH( v ) ((sp = (sp - 1) | 0x100), WRITE_LOW( sp, v ))
|
||||
|
||||
// even on x86, using short and unsigned char was slower
|
||||
typedef int fint16;
|
||||
typedef unsigned fuint16;
|
||||
typedef unsigned fuint8;
|
||||
|
||||
bool Nes_Cpu::run( nes_time_t end_time )
|
||||
{
|
||||
set_end_time( end_time );
|
||||
state_t s = this->state_;
|
||||
this->state = &s;
|
||||
// even on x86, using s.time in place of s_time was slower
|
||||
fint16 s_time = s.time;
|
||||
int16_t s_time = s.time;
|
||||
|
||||
// registers
|
||||
fuint16 pc = r.pc;
|
||||
fuint8 a = r.a;
|
||||
fuint8 x = r.x;
|
||||
fuint8 y = r.y;
|
||||
fuint16 sp;
|
||||
uint16_t pc = r.pc;
|
||||
uint8_t a = r.a;
|
||||
uint8_t x = r.x;
|
||||
uint8_t y = r.y;
|
||||
uint16_t sp;
|
||||
SET_SP( r.sp );
|
||||
|
||||
// status flags
|
||||
@@ -152,11 +147,11 @@ bool Nes_Cpu::run( nes_time_t end_time )
|
||||
nz |= ~in & st_z;\
|
||||
} while ( 0 )
|
||||
|
||||
fuint8 status;
|
||||
fuint16 c; // carry set if (c & 0x100) != 0
|
||||
fuint16 nz; // Z set if (nz & 0xFF) == 0, N set if (nz & 0x8080) != 0
|
||||
uint8_t status;
|
||||
uint16_t c; // carry set if (c & 0x100) != 0
|
||||
uint16_t nz; // Z set if (nz & 0xFF) == 0, N set if (nz & 0x8080) != 0
|
||||
{
|
||||
fuint8 temp = r.status;
|
||||
uint8_t temp = r.status;
|
||||
SET_STATUS( temp );
|
||||
}
|
||||
|
||||
@@ -173,7 +168,7 @@ loop:
|
||||
check( -32768 <= s_time && s_time < 32767 );
|
||||
|
||||
uint8_t const* instr = s.code_map [pc >> page_bits];
|
||||
fuint8 opcode;
|
||||
uint8_t opcode;
|
||||
|
||||
// TODO: eliminate this special case
|
||||
#if BLARGG_NONPORTABLE
|
||||
@@ -206,7 +201,7 @@ loop:
|
||||
3,5,0,8,4,4,6,6,2,4,2,7,4,4,7,7 // F
|
||||
}; // 0x00 was 7 and 0xF2 was 2
|
||||
|
||||
fuint16 data;
|
||||
uint16_t data;
|
||||
|
||||
#if !BLARGG_CPU_X86
|
||||
if ( s_time >= 0 )
|
||||
@@ -247,13 +242,13 @@ possibly_out_of_time:
|
||||
#define INC_DEC_XY( reg, n ) reg = uint8_t (nz = reg + n); goto loop;
|
||||
|
||||
#define IND_Y( cross, out ) {\
|
||||
fuint16 temp = READ_LOW( data ) + y;\
|
||||
uint16_t temp = READ_LOW( data ) + y;\
|
||||
out = temp + 0x100 * READ_LOW( uint8_t (data + 1) );\
|
||||
cross( temp );\
|
||||
}
|
||||
|
||||
#define IND_X( out ) {\
|
||||
fuint16 temp = data + x;\
|
||||
uint16_t temp = data + x;\
|
||||
out = 0x100 * READ_LOW( uint8_t (temp + 1) ) + READ_LOW( uint8_t (temp) );\
|
||||
}
|
||||
|
||||
@@ -265,7 +260,7 @@ case op + 0x0C: /* (ind),y */\
|
||||
IND_Y( HANDLE_PAGE_CROSSING, data )\
|
||||
goto ptr##op;\
|
||||
case op + 0x10: /* zp,X */\
|
||||
data = uint8_t (data + x);\
|
||||
data = uint8_t (data + x);/* FALLTHRU */\
|
||||
case op + 0x00: /* zp */\
|
||||
data = READ_LOW( data );\
|
||||
goto imm##op;\
|
||||
@@ -275,23 +270,23 @@ case op + 0x14: /* abs,Y */\
|
||||
case op + 0x18: /* abs,X */\
|
||||
data += x;\
|
||||
ind##op:\
|
||||
HANDLE_PAGE_CROSSING( data );\
|
||||
HANDLE_PAGE_CROSSING( data );/* FALLTHRU */\
|
||||
case op + 0x08: /* abs */\
|
||||
ADD_PAGE();\
|
||||
ptr##op:\
|
||||
FLUSH_TIME();\
|
||||
data = READ( data );\
|
||||
CACHE_TIME();\
|
||||
CACHE_TIME();/*FALLTHRU*/\
|
||||
case op + 0x04: /* imm */\
|
||||
imm##op:
|
||||
|
||||
// TODO: more efficient way to handle negative branch that wraps PC around
|
||||
#define BRANCH( cond )\
|
||||
{\
|
||||
fint16 offset = (BOOST::int8_t) data;\
|
||||
fuint16 extra_clock = (++pc & 0xFF) + offset;\
|
||||
int16_t offset = (int8_t) data;\
|
||||
uint16_t extra_clock = (++pc & 0xFF) + offset;\
|
||||
if ( !(cond) ) goto dec_clock_loop;\
|
||||
pc = BOOST::uint16_t (pc + offset);\
|
||||
pc = uint16_t (pc + offset);\
|
||||
s_time += extra_clock >> 8 & 1;\
|
||||
goto loop;\
|
||||
}
|
||||
@@ -312,7 +307,7 @@ imm##op:
|
||||
BRANCH( (uint8_t) nz );
|
||||
|
||||
case 0x20: { // JSR
|
||||
fuint16 temp = pc + 1;
|
||||
uint16_t temp = pc + 1;
|
||||
pc = GET_ADDR();
|
||||
WRITE_LOW( 0x100 | (sp - 1), temp >> 8 );
|
||||
sp = (sp - 2) | 0x100;
|
||||
@@ -344,7 +339,7 @@ imm##op:
|
||||
BRANCH( !(uint8_t) nz );
|
||||
|
||||
case 0x95: // STA zp,x
|
||||
data = uint8_t (data + x);
|
||||
data = uint8_t (data + x);/*FALLTHRU*/
|
||||
case 0x85: // STA zp
|
||||
pc++;
|
||||
WRITE_LOW( data, a );
|
||||
@@ -378,7 +373,7 @@ imm##op:
|
||||
goto loop;
|
||||
|
||||
{
|
||||
fuint16 addr;
|
||||
uint16_t addr;
|
||||
|
||||
case 0x99: // STA abs,Y
|
||||
addr = y + GET_ADDR();
|
||||
@@ -434,7 +429,7 @@ imm##op:
|
||||
|
||||
// common read instructions
|
||||
{
|
||||
fuint16 addr;
|
||||
uint16_t addr;
|
||||
|
||||
case 0xA1: // LDA (ind,X)
|
||||
IND_X( addr )
|
||||
@@ -492,23 +487,23 @@ imm##op:
|
||||
// Load/store
|
||||
|
||||
case 0x94: // STY zp,x
|
||||
data = uint8_t (data + x);
|
||||
data = uint8_t (data + x); // FALLTHRU
|
||||
case 0x84: // STY zp
|
||||
pc++;
|
||||
WRITE_LOW( data, y );
|
||||
goto loop;
|
||||
|
||||
case 0x96: // STX zp,y
|
||||
data = uint8_t (data + y);
|
||||
data = uint8_t (data + y); // FALLTHRU
|
||||
case 0x86: // STX zp
|
||||
pc++;
|
||||
WRITE_LOW( data, x );
|
||||
goto loop;
|
||||
|
||||
case 0xB6: // LDX zp,y
|
||||
data = uint8_t (data + y);
|
||||
data = uint8_t (data + y); // FALLTHRU
|
||||
case 0xA6: // LDX zp
|
||||
data = READ_LOW( data );
|
||||
data = READ_LOW( data ); // FALLTHRU
|
||||
case 0xA2: // LDX #imm
|
||||
pc++;
|
||||
x = data;
|
||||
@@ -516,9 +511,9 @@ imm##op:
|
||||
goto loop;
|
||||
|
||||
case 0xB4: // LDY zp,x
|
||||
data = uint8_t (data + x);
|
||||
data = uint8_t (data + x); // FALLTHRU
|
||||
case 0xA4: // LDY zp
|
||||
data = READ_LOW( data );
|
||||
data = READ_LOW( data ); // FALLTHRU
|
||||
case 0xA0: // LDY #imm
|
||||
pc++;
|
||||
y = data;
|
||||
@@ -527,7 +522,7 @@ imm##op:
|
||||
|
||||
case 0xBC: // LDY abs,X
|
||||
data += x;
|
||||
HANDLE_PAGE_CROSSING( data );
|
||||
HANDLE_PAGE_CROSSING( data );/*FALLTHRU*/
|
||||
case 0xAC:{// LDY abs
|
||||
unsigned addr = data + 0x100 * GET_MSB();
|
||||
pc += 2;
|
||||
@@ -539,7 +534,7 @@ imm##op:
|
||||
|
||||
case 0xBE: // LDX abs,y
|
||||
data += y;
|
||||
HANDLE_PAGE_CROSSING( data );
|
||||
HANDLE_PAGE_CROSSING( data );/*FALLTHRU*/
|
||||
case 0xAE:{// LDX abs
|
||||
unsigned addr = data + 0x100 * GET_MSB();
|
||||
pc += 2;
|
||||
@@ -550,7 +545,7 @@ imm##op:
|
||||
}
|
||||
|
||||
{
|
||||
fuint8 temp;
|
||||
uint8_t temp;
|
||||
case 0x8C: // STY abs
|
||||
temp = y;
|
||||
goto store_abs;
|
||||
@@ -583,7 +578,7 @@ imm##op:
|
||||
}
|
||||
|
||||
case 0xE4: // CPX zp
|
||||
data = READ_LOW( data );
|
||||
data = READ_LOW( data );/*FALLTHRU*/
|
||||
case 0xE0: // CPX #imm
|
||||
cpx_data:
|
||||
nz = x - data;
|
||||
@@ -602,7 +597,7 @@ imm##op:
|
||||
}
|
||||
|
||||
case 0xC4: // CPY zp
|
||||
data = READ_LOW( data );
|
||||
data = READ_LOW( data );/*FALLTHRU*/
|
||||
case 0xC0: // CPY #imm
|
||||
cpy_data:
|
||||
nz = y - data;
|
||||
@@ -659,8 +654,8 @@ imm##op:
|
||||
|
||||
ARITH_ADDR_MODES( 0x65 ) // ADC
|
||||
adc_imm: {
|
||||
fint16 carry = c >> 8 & 1;
|
||||
fint16 ov = (a ^ 0x80) + carry + (BOOST::int8_t) data; // sign-extend
|
||||
int16_t carry = c >> 8 & 1;
|
||||
int16_t ov = (a ^ 0x80) + carry + (int8_t) data; // sign-extend
|
||||
status &= ~st_v;
|
||||
status |= ov >> 2 & 0x40;
|
||||
c = nz = a + data + carry;
|
||||
@@ -672,7 +667,7 @@ imm##op:
|
||||
// Shift/rotate
|
||||
|
||||
case 0x4A: // LSR A
|
||||
c = 0;
|
||||
c = 0;/*FALLTHRU*/
|
||||
case 0x6A: // ROR A
|
||||
nz = c >> 1 & 0x80;
|
||||
c = a << 8;
|
||||
@@ -688,7 +683,7 @@ imm##op:
|
||||
|
||||
case 0x2A: { // ROL A
|
||||
nz = a << 1;
|
||||
fint16 temp = c >> 8 & 1;
|
||||
int16_t temp = c >> 8 & 1;
|
||||
c = nz;
|
||||
nz |= temp;
|
||||
a = (uint8_t) nz;
|
||||
@@ -696,9 +691,9 @@ imm##op:
|
||||
}
|
||||
|
||||
case 0x5E: // LSR abs,X
|
||||
data += x;
|
||||
data += x;/*FALLTHRU*/
|
||||
case 0x4E: // LSR abs
|
||||
c = 0;
|
||||
c = 0;/*FALLTHRU*/
|
||||
case 0x6E: // ROR abs
|
||||
ror_abs: {
|
||||
ADD_PAGE();
|
||||
@@ -714,9 +709,9 @@ imm##op:
|
||||
goto rol_abs;
|
||||
|
||||
case 0x1E: // ASL abs,X
|
||||
data += x;
|
||||
data += x;/*FALLTHRU*/
|
||||
case 0x0E: // ASL abs
|
||||
c = 0;
|
||||
c = 0;/*FALLTHRU*/
|
||||
case 0x2E: // ROL abs
|
||||
rol_abs:
|
||||
ADD_PAGE();
|
||||
@@ -738,9 +733,9 @@ imm##op:
|
||||
goto ror_zp;
|
||||
|
||||
case 0x56: // LSR zp,x
|
||||
data = uint8_t (data + x);
|
||||
data = uint8_t (data + x);/*FALLTHRU*/
|
||||
case 0x46: // LSR zp
|
||||
c = 0;
|
||||
c = 0;/*FALLTHRU*/
|
||||
case 0x66: // ROR zp
|
||||
ror_zp: {
|
||||
int temp = READ_LOW( data );
|
||||
@@ -754,9 +749,9 @@ imm##op:
|
||||
goto rol_zp;
|
||||
|
||||
case 0x16: // ASL zp,x
|
||||
data = uint8_t (data + x);
|
||||
data = uint8_t (data + x);/*FALLTHRU*/
|
||||
case 0x06: // ASL zp
|
||||
c = 0;
|
||||
c = 0;/*FALLTHRU*/
|
||||
case 0x26: // ROL zp
|
||||
rol_zp:
|
||||
nz = c >> 8 & 1;
|
||||
@@ -772,15 +767,15 @@ imm##op:
|
||||
INC_DEC_XY( y, -1 )
|
||||
|
||||
case 0xF6: // INC zp,x
|
||||
data = uint8_t (data + x);
|
||||
data = uint8_t (data + x);/*FALLTHRU*/
|
||||
case 0xE6: // INC zp
|
||||
nz = 1;
|
||||
goto add_nz_zp;
|
||||
|
||||
case 0xD6: // DEC zp,x
|
||||
data = uint8_t (data + x);
|
||||
data = uint8_t (data + x);/*FALLTHRU*/
|
||||
case 0xC6: // DEC zp
|
||||
nz = (unsigned) -1;
|
||||
nz = (uint16_t) -1;
|
||||
add_nz_zp:
|
||||
nz += READ_LOW( data );
|
||||
write_nz_zp:
|
||||
@@ -805,7 +800,7 @@ imm##op:
|
||||
case 0xCE: // DEC abs
|
||||
data = GET_ADDR();
|
||||
dec_ptr:
|
||||
nz = (unsigned) -1;
|
||||
nz = (uint16_t) -1;
|
||||
inc_common:
|
||||
FLUSH_TIME();
|
||||
nz += READ( data );
|
||||
@@ -846,7 +841,7 @@ imm##op:
|
||||
goto loop;
|
||||
|
||||
case 0x40:{// RTI
|
||||
fuint8 temp = READ_LOW( sp );
|
||||
uint8_t temp = READ_LOW( sp );
|
||||
pc = READ_LOW( 0x100 | (sp - 0xFF) );
|
||||
pc |= READ_LOW( 0x100 | (sp - 0xFE) ) * 0x100;
|
||||
sp = (sp - 0xFD) | 0x100;
|
||||
@@ -863,9 +858,9 @@ imm##op:
|
||||
}
|
||||
|
||||
case 0x28:{// PLP
|
||||
fuint8 temp = READ_LOW( sp );
|
||||
uint8_t temp = READ_LOW( sp );
|
||||
sp = (sp - 0xFF) | 0x100;
|
||||
fuint8 changed = status ^ temp;
|
||||
uint8_t changed = status ^ temp;
|
||||
SET_STATUS( temp );
|
||||
if ( !(changed & st_i) )
|
||||
goto loop; // I flag didn't change
|
||||
@@ -875,7 +870,7 @@ imm##op:
|
||||
}
|
||||
|
||||
case 0x08: { // PHP
|
||||
fuint8 temp;
|
||||
uint8_t temp;
|
||||
CALC_STATUS( temp );
|
||||
PUSH( temp | (st_b | st_r) );
|
||||
goto loop;
|
||||
@@ -897,7 +892,7 @@ imm##op:
|
||||
// Flags
|
||||
|
||||
case 0x38: // SEC
|
||||
c = (unsigned) ~0;
|
||||
c = (uint16_t) ~0;
|
||||
goto loop;
|
||||
|
||||
case 0x18: // CLC
|
||||
@@ -968,9 +963,9 @@ imm##op:
|
||||
|
||||
// SKW - Skip word
|
||||
case 0x1C: case 0x3C: case 0x5C: case 0x7C: case 0xDC: case 0xFC:
|
||||
HANDLE_PAGE_CROSSING( data + x );
|
||||
HANDLE_PAGE_CROSSING( data + x );/*FALLTHRU*/
|
||||
case 0x0C:
|
||||
pc++;
|
||||
pc++;/*FALLTHRU*/
|
||||
// SKB - Skip byte
|
||||
case 0x74: case 0x04: case 0x14: case 0x34: case 0x44: case 0x54: case 0x64:
|
||||
case 0x80: case 0x82: case 0x89: case 0xC2: case 0xD4: case 0xE2: case 0xF4:
|
||||
@@ -983,12 +978,6 @@ imm##op:
|
||||
|
||||
case bad_opcode: // HLT
|
||||
pc--;
|
||||
if ( pc > 0xFFFF )
|
||||
{
|
||||
// handle wrap-around (assumes caller has put page of HLT at 0x10000)
|
||||
pc &= 0xFFFF;
|
||||
goto loop;
|
||||
}
|
||||
case 0x02: case 0x12: case 0x22: case 0x32: case 0x42: case 0x52:
|
||||
case 0x62: case 0x72: case 0x92: case 0xB2: case 0xD2:
|
||||
goto stop;
|
||||
@@ -996,15 +985,15 @@ imm##op:
|
||||
// Unimplemented
|
||||
|
||||
case 0xFF: // force 256-entry jump table for optimization purposes
|
||||
c |= 1;
|
||||
c |= 1;/*FALLTHRU*/
|
||||
default:
|
||||
check( (unsigned) opcode <= 0xFF );
|
||||
// skip over proper number of bytes
|
||||
static unsigned char const illop_lens [8] = {
|
||||
0x40, 0x40, 0x40, 0x80, 0x40, 0x40, 0x80, 0xA0
|
||||
};
|
||||
fuint8 opcode = instr [-1];
|
||||
fint16 len = illop_lens [opcode >> 2 & 7] >> (opcode << 1 & 6) & 3;
|
||||
uint8_t opcode = instr [-1];
|
||||
int16_t len = illop_lens [opcode >> 2 & 7] >> (opcode << 1 & 6) & 3;
|
||||
if ( opcode == 0x9C )
|
||||
len = 2;
|
||||
pc += len;
|
||||
@@ -1035,7 +1024,7 @@ interrupt:
|
||||
pc = GET_LE16( &READ_PROG( 0xFFFA ) + result_ );
|
||||
|
||||
sp = (sp - 3) | 0x100;
|
||||
fuint8 temp;
|
||||
uint8_t temp;
|
||||
CALC_STATUS( temp );
|
||||
temp |= st_r;
|
||||
if ( result_ )
|
||||
@@ -1071,7 +1060,7 @@ stop:
|
||||
r.y = y;
|
||||
|
||||
{
|
||||
fuint8 temp;
|
||||
uint8_t temp;
|
||||
CALC_STATUS( temp );
|
||||
r.status = temp;
|
||||
}
|
||||
|
||||
+8
-10
@@ -1,6 +1,6 @@
|
||||
// NES 6502 CPU emulator
|
||||
|
||||
// Game_Music_Emu 0.6.0
|
||||
// Game_Music_Emu https://bitbucket.org/mpyne/game-music-emu/
|
||||
#ifndef NES_CPU_H
|
||||
#define NES_CPU_H
|
||||
|
||||
@@ -12,8 +12,6 @@ enum { future_nes_time = INT_MAX / 2 + 1 };
|
||||
|
||||
class Nes_Cpu {
|
||||
public:
|
||||
typedef BOOST::uint8_t uint8_t;
|
||||
|
||||
// Clear registers, map low memory and its three mirrors to address 0,
|
||||
// and mirror unmapped_page in remaining memory
|
||||
void reset( void const* unmapped_page = 0 );
|
||||
@@ -32,12 +30,12 @@ public:
|
||||
|
||||
// NES 6502 registers. Not kept updated during a call to run().
|
||||
struct registers_t {
|
||||
BOOST::uint16_t pc;
|
||||
BOOST::uint8_t a;
|
||||
BOOST::uint8_t x;
|
||||
BOOST::uint8_t y;
|
||||
BOOST::uint8_t status;
|
||||
BOOST::uint8_t sp;
|
||||
uint16_t pc;
|
||||
uint8_t a;
|
||||
uint8_t x;
|
||||
uint8_t y;
|
||||
uint8_t status;
|
||||
uint8_t sp;
|
||||
};
|
||||
registers_t r;
|
||||
|
||||
@@ -84,7 +82,7 @@ private:
|
||||
inline int update_end_time( nes_time_t end, nes_time_t irq );
|
||||
};
|
||||
|
||||
inline BOOST::uint8_t const* Nes_Cpu::get_code( nes_addr_t addr )
|
||||
inline uint8_t const* Nes_Cpu::get_code( nes_addr_t addr )
|
||||
{
|
||||
return state->code_map [addr >> page_bits] + addr
|
||||
#if !BLARGG_NONPORTABLE
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Game_Music_Emu 0.6.0. http://www.slack.net/~ant/
|
||||
// Game_Music_Emu https://bitbucket.org/mpyne/game-music-emu/
|
||||
|
||||
#include "Nes_Fme7_Apu.h"
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// Sunsoft FME-7 sound emulator
|
||||
|
||||
// Game_Music_Emu 0.6.0
|
||||
// Game_Music_Emu https://bitbucket.org/mpyne/game-music-emu/
|
||||
#ifndef NES_FME7_APU_H
|
||||
#define NES_FME7_APU_H
|
||||
|
||||
@@ -10,10 +10,10 @@
|
||||
struct fme7_apu_state_t
|
||||
{
|
||||
enum { reg_count = 14 };
|
||||
BOOST::uint8_t regs [reg_count];
|
||||
BOOST::uint8_t phases [3]; // 0 or 1
|
||||
BOOST::uint8_t latch;
|
||||
BOOST::uint16_t delays [3]; // a, b, c
|
||||
uint8_t regs [reg_count];
|
||||
uint8_t phases [3]; // 0 or 1
|
||||
uint8_t latch;
|
||||
uint16_t delays [3]; // a, b, c
|
||||
};
|
||||
|
||||
class Nes_Fme7_Apu : private fme7_apu_state_t {
|
||||
|
||||
@@ -90,7 +90,7 @@ void Nes_Namco_Apu::run_until( blip_time_t nes_end_time )
|
||||
osc.delay = 0;
|
||||
if ( time < end_time )
|
||||
{
|
||||
const BOOST::uint8_t* osc_reg = ® [i * 8 + 0x40];
|
||||
const uint8_t* osc_reg = ® [i * 8 + 0x40];
|
||||
if ( !(osc_reg [4] & 0xE0) )
|
||||
continue;
|
||||
|
||||
|
||||
@@ -54,24 +54,24 @@ private:
|
||||
int addr_reg;
|
||||
|
||||
enum { reg_count = 0x80 };
|
||||
BOOST::uint8_t reg [reg_count];
|
||||
uint8_t reg [reg_count];
|
||||
Blip_Synth<blip_good_quality,15> synth;
|
||||
|
||||
BOOST::uint8_t& access();
|
||||
uint8_t& access();
|
||||
void run_until( blip_time_t );
|
||||
};
|
||||
/*
|
||||
struct namco_state_t
|
||||
{
|
||||
BOOST::uint8_t regs [0x80];
|
||||
BOOST::uint8_t addr;
|
||||
BOOST::uint8_t unused;
|
||||
BOOST::uint8_t positions [8];
|
||||
BOOST::uint32_t delays [8];
|
||||
uint8_t regs [0x80];
|
||||
uint8_t addr;
|
||||
uint8_t unused;
|
||||
uint8_t positions [8];
|
||||
uint32_t delays [8];
|
||||
};
|
||||
*/
|
||||
|
||||
inline BOOST::uint8_t& Nes_Namco_Apu::access()
|
||||
inline uint8_t& Nes_Namco_Apu::access()
|
||||
{
|
||||
int addr = addr_reg & 0x7F;
|
||||
if ( addr_reg & 0x80 )
|
||||
|
||||
@@ -40,7 +40,7 @@ private:
|
||||
|
||||
struct Vrc6_Osc
|
||||
{
|
||||
BOOST::uint8_t regs [3];
|
||||
uint8_t regs [3];
|
||||
Blip_Buffer* output;
|
||||
int delay;
|
||||
int last_amp;
|
||||
@@ -66,11 +66,11 @@ private:
|
||||
|
||||
struct vrc6_apu_state_t
|
||||
{
|
||||
BOOST::uint8_t regs [3] [3];
|
||||
BOOST::uint8_t saw_amp;
|
||||
BOOST::uint16_t delays [3];
|
||||
BOOST::uint8_t phases [3];
|
||||
BOOST::uint8_t unused;
|
||||
uint8_t regs [3] [3];
|
||||
uint8_t saw_amp;
|
||||
uint16_t delays [3];
|
||||
uint8_t phases [3];
|
||||
uint8_t unused;
|
||||
};
|
||||
|
||||
inline void Nes_Vrc6_Apu::osc_output( int i, Blip_Buffer* buf )
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
// Game_Music_Emu 0.6.0. http://www.slack.net/~ant/
|
||||
// Game_Music_Emu https://bitbucket.org/mpyne/game-music-emu/
|
||||
|
||||
#include "Nsf_Emu.h"
|
||||
|
||||
#include "blargg_endian.h"
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <algorithm>
|
||||
|
||||
#if !NSF_EMU_APU_ONLY
|
||||
#include "Nes_Namco_Apu.h"
|
||||
@@ -31,6 +32,9 @@ int const fme7_flag = 0x20;
|
||||
|
||||
long const clock_divisor = 12;
|
||||
|
||||
using std::min;
|
||||
using std::max;
|
||||
|
||||
Nsf_Emu::equalizer_t const Nsf_Emu::nes_eq =
|
||||
Music_Emu::make_equalizer( -1.0, 80 );
|
||||
Nsf_Emu::equalizer_t const Nsf_Emu::famicom_eq =
|
||||
@@ -130,7 +134,7 @@ static Music_Emu* new_nsf_emu () { return BLARGG_NEW Nsf_Emu ; }
|
||||
static Music_Emu* new_nsf_file() { return BLARGG_NEW Nsf_File; }
|
||||
|
||||
static gme_type_t_ const gme_nsf_type_ = { "Nintendo NES", 0, &new_nsf_emu, &new_nsf_file, "NSF", 1 };
|
||||
gme_type_t const gme_nsf_type = &gme_nsf_type_;
|
||||
extern gme_type_t const gme_nsf_type = &gme_nsf_type_;
|
||||
|
||||
|
||||
// Setup
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// Nintendo NES/Famicom NSF music file emulator
|
||||
|
||||
// Game_Music_Emu 0.6.0
|
||||
// Game_Music_Emu https://bitbucket.org/mpyne/game-music-emu/
|
||||
#ifndef NSF_EMU_H
|
||||
#define NSF_EMU_H
|
||||
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
// Game_Music_Emu 0.6.0. http://www.slack.net/~ant/
|
||||
// Game_Music_Emu https://bitbucket.org/mpyne/game-music-emu/
|
||||
|
||||
#include "Nsfe_Emu.h"
|
||||
|
||||
#include "blargg_endian.h"
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#include <algorithm>
|
||||
|
||||
/* Copyright (C) 2005-2006 Shay Green. This module is free software; you
|
||||
can redistribute it and/or modify it under the terms of the GNU Lesser
|
||||
@@ -19,6 +20,9 @@ Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */
|
||||
|
||||
#include "blargg_source.h"
|
||||
|
||||
using std::min;
|
||||
using std::max;
|
||||
|
||||
Nsfe_Info::Nsfe_Info() { playlist_disabled = false; }
|
||||
|
||||
Nsfe_Info::~Nsfe_Info() { }
|
||||
@@ -135,7 +139,7 @@ blargg_err_t Nsfe_Info::load( Data_Reader& in, Nsf_Emu* nsf_emu )
|
||||
blargg_long size = get_le32( block_header [0] );
|
||||
blargg_long tag = get_le32( block_header [1] );
|
||||
|
||||
if ( size <= 0 )
|
||||
if ( size < 0 )
|
||||
return "Corrupt file";
|
||||
|
||||
//debug_printf( "tag: %c%c%c%c\n", char(tag), char(tag>>8), char(tag>>16), char(tag>>24) );
|
||||
@@ -243,7 +247,7 @@ blargg_err_t Nsfe_Info::track_info_( track_info_t* out, int track ) const
|
||||
int remapped = remap_track( track );
|
||||
if ( (unsigned) remapped < track_times.size() )
|
||||
{
|
||||
long length = (BOOST::int32_t) get_le32( track_times [remapped] );
|
||||
long length = (int32_t) get_le32( track_times [remapped] );
|
||||
if ( length > 0 )
|
||||
out->length = length;
|
||||
}
|
||||
@@ -301,7 +305,7 @@ static Music_Emu* new_nsfe_emu () { return BLARGG_NEW Nsfe_Emu ; }
|
||||
static Music_Emu* new_nsfe_file() { return BLARGG_NEW Nsfe_File; }
|
||||
|
||||
static gme_type_t_ const gme_nsfe_type_ = { "Nintendo NES", 0, &new_nsfe_emu, &new_nsfe_file, "NSFE", 1 };
|
||||
gme_type_t const gme_nsfe_type = &gme_nsfe_type_;
|
||||
extern gme_type_t const gme_nsfe_type = &gme_nsfe_type_;
|
||||
|
||||
|
||||
blargg_err_t Nsfe_Emu::load_( Data_Reader& in )
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// Nintendo NES/Famicom NSFE music file emulator
|
||||
|
||||
// Game_Music_Emu 0.6.0
|
||||
// Game_Music_Emu https://bitbucket.org/mpyne/game-music-emu/
|
||||
#ifndef NSFE_EMU_H
|
||||
#define NSFE_EMU_H
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Game_Music_Emu 0.6.0. http://www.slack.net/~ant/
|
||||
// Game_Music_Emu https://bitbucket.org/mpyne/game-music-emu/
|
||||
|
||||
#include "Sap_Apu.h"
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// Atari POKEY sound chip emulator
|
||||
|
||||
// Game_Music_Emu 0.6.0
|
||||
// Game_Music_Emu https://bitbucket.org/mpyne/game-music-emu/
|
||||
#ifndef SAP_APU_H
|
||||
#define SAP_APU_H
|
||||
|
||||
|
||||
+60
-67
@@ -1,4 +1,4 @@
|
||||
// Game_Music_Emu 0.6.0. http://www.slack.net/~ant/
|
||||
// Game_Music_Emu https://bitbucket.org/mpyne/game-music-emu/
|
||||
|
||||
#include "Sap_Cpu.h"
|
||||
|
||||
@@ -68,27 +68,21 @@ void Sap_Cpu::reset( void* new_mem )
|
||||
#define GET_SP() ((sp - 1) & 0xFF)
|
||||
#define PUSH( v ) ((sp = (sp - 1) | 0x100), WRITE_LOW( sp, v ))
|
||||
|
||||
// even on x86, using short and unsigned char was slower
|
||||
typedef int fint16;
|
||||
typedef unsigned fuint16;
|
||||
typedef unsigned fuint8;
|
||||
typedef blargg_long fint32;
|
||||
|
||||
bool Sap_Cpu::run( sap_time_t end_time )
|
||||
{
|
||||
bool illegal_encountered = false;
|
||||
set_end_time( end_time );
|
||||
state_t s = this->state_;
|
||||
this->state = &s;
|
||||
fint32 s_time = s.time;
|
||||
int32_t s_time = s.time;
|
||||
uint8_t* const mem = this->mem; // cache
|
||||
|
||||
// registers
|
||||
fuint16 pc = r.pc;
|
||||
fuint8 a = r.a;
|
||||
fuint8 x = r.x;
|
||||
fuint8 y = r.y;
|
||||
fuint16 sp;
|
||||
uint16_t pc = r.pc;
|
||||
uint8_t a = r.a;
|
||||
uint8_t x = r.x;
|
||||
uint8_t y = r.y;
|
||||
uint16_t sp;
|
||||
SET_SP( r.sp );
|
||||
|
||||
// status flags
|
||||
@@ -108,11 +102,11 @@ bool Sap_Cpu::run( sap_time_t end_time )
|
||||
nz |= ~in & st_z;\
|
||||
} while ( 0 )
|
||||
|
||||
fuint8 status;
|
||||
fuint16 c; // carry set if (c & 0x100) != 0
|
||||
fuint16 nz; // Z set if (nz & 0xFF) == 0, N set if (nz & 0x8080) != 0
|
||||
uint8_t status;
|
||||
uint16_t c; // carry set if (c & 0x100) != 0
|
||||
uint16_t nz; // Z set if (nz & 0xFF) == 0, N set if (nz & 0x8080) != 0
|
||||
{
|
||||
fuint8 temp = r.status;
|
||||
uint8_t temp = r.status;
|
||||
SET_STATUS( temp );
|
||||
}
|
||||
|
||||
@@ -135,7 +129,7 @@ loop:
|
||||
check( (unsigned) x < 0x100 );
|
||||
check( (unsigned) y < 0x100 );
|
||||
|
||||
fuint8 opcode = mem [pc];
|
||||
uint8_t opcode = mem [pc];
|
||||
pc++;
|
||||
uint8_t const* instr = mem + pc;
|
||||
|
||||
@@ -159,7 +153,7 @@ loop:
|
||||
3,5,2,8,4,4,6,6,2,4,2,7,4,4,7,7 // F
|
||||
}; // 0x00 was 7
|
||||
|
||||
fuint16 data;
|
||||
uint16_t data;
|
||||
data = clock_table [opcode];
|
||||
if ( (s_time += data) >= 0 )
|
||||
goto possibly_out_of_time;
|
||||
@@ -191,13 +185,13 @@ possibly_out_of_time:
|
||||
#define INC_DEC_XY( reg, n ) reg = uint8_t (nz = reg + n); goto loop;
|
||||
|
||||
#define IND_Y( cross, out ) {\
|
||||
fuint16 temp = READ_LOW( data ) + y;\
|
||||
uint16_t temp = READ_LOW( data ) + y;\
|
||||
out = temp + 0x100 * READ_LOW( uint8_t (data + 1) );\
|
||||
cross( temp );\
|
||||
}
|
||||
|
||||
#define IND_X( out ) {\
|
||||
fuint16 temp = data + x;\
|
||||
uint16_t temp = data + x;\
|
||||
out = 0x100 * READ_LOW( uint8_t (temp + 1) ) + READ_LOW( uint8_t (temp) );\
|
||||
}
|
||||
|
||||
@@ -209,7 +203,7 @@ case op + 0x0C: /* (ind),y */\
|
||||
IND_Y( HANDLE_PAGE_CROSSING, data )\
|
||||
goto ptr##op;\
|
||||
case op + 0x10: /* zp,X */\
|
||||
data = uint8_t (data + x);\
|
||||
data = uint8_t (data + x);/*FALLTHRU*/\
|
||||
case op + 0x00: /* zp */\
|
||||
data = READ_LOW( data );\
|
||||
goto imm##op;\
|
||||
@@ -219,21 +213,21 @@ case op + 0x14: /* abs,Y */\
|
||||
case op + 0x18: /* abs,X */\
|
||||
data += x;\
|
||||
ind##op:\
|
||||
HANDLE_PAGE_CROSSING( data );\
|
||||
HANDLE_PAGE_CROSSING( data );/*FALLTHRU*/\
|
||||
case op + 0x08: /* abs */\
|
||||
ADD_PAGE();\
|
||||
ptr##op:\
|
||||
FLUSH_TIME();\
|
||||
data = READ( data );\
|
||||
CACHE_TIME();\
|
||||
CACHE_TIME();/*FALLTHRU*/\
|
||||
case op + 0x04: /* imm */\
|
||||
imm##op:
|
||||
|
||||
// TODO: more efficient way to handle negative branch that wraps PC around
|
||||
#define BRANCH( cond )\
|
||||
{\
|
||||
fint16 offset = (BOOST::int8_t) data;\
|
||||
fuint16 extra_clock = (++pc & 0xFF) + offset;\
|
||||
int16_t offset = (int8_t) data;\
|
||||
uint16_t extra_clock = (++pc & 0xFF) + offset;\
|
||||
if ( !(cond) ) goto dec_clock_loop;\
|
||||
pc += offset;\
|
||||
s_time += extra_clock >> 8 & 1;\
|
||||
@@ -256,7 +250,7 @@ imm##op:
|
||||
BRANCH( (uint8_t) nz );
|
||||
|
||||
case 0x20: { // JSR
|
||||
fuint16 temp = pc + 1;
|
||||
uint16_t temp = pc + 1;
|
||||
pc = GET_ADDR();
|
||||
WRITE_LOW( 0x100 | (sp - 1), temp >> 8 );
|
||||
sp = (sp - 2) | 0x100;
|
||||
@@ -288,7 +282,7 @@ imm##op:
|
||||
BRANCH( !(uint8_t) nz );
|
||||
|
||||
case 0x95: // STA zp,x
|
||||
data = uint8_t (data + x);
|
||||
data = uint8_t (data + x);/*FALLTHRU*/
|
||||
case 0x85: // STA zp
|
||||
pc++;
|
||||
WRITE_LOW( data, a );
|
||||
@@ -322,7 +316,7 @@ imm##op:
|
||||
goto loop;
|
||||
|
||||
{
|
||||
fuint16 addr;
|
||||
uint16_t addr;
|
||||
|
||||
case 0x99: // STA abs,Y
|
||||
addr = y + GET_ADDR();
|
||||
@@ -378,7 +372,7 @@ imm##op:
|
||||
|
||||
// common read instructions
|
||||
{
|
||||
fuint16 addr;
|
||||
uint16_t addr;
|
||||
|
||||
case 0xA1: // LDA (ind,X)
|
||||
IND_X( addr )
|
||||
@@ -436,23 +430,23 @@ imm##op:
|
||||
// Load/store
|
||||
|
||||
case 0x94: // STY zp,x
|
||||
data = uint8_t (data + x);
|
||||
data = uint8_t (data + x);/*FALLTHRU*/
|
||||
case 0x84: // STY zp
|
||||
pc++;
|
||||
WRITE_LOW( data, y );
|
||||
goto loop;
|
||||
|
||||
case 0x96: // STX zp,y
|
||||
data = uint8_t (data + y);
|
||||
data = uint8_t (data + y);/*FALLTHRU*/
|
||||
case 0x86: // STX zp
|
||||
pc++;
|
||||
WRITE_LOW( data, x );
|
||||
goto loop;
|
||||
|
||||
case 0xB6: // LDX zp,y
|
||||
data = uint8_t (data + y);
|
||||
data = uint8_t (data + y);/*FALLTHRU*/
|
||||
case 0xA6: // LDX zp
|
||||
data = READ_LOW( data );
|
||||
data = READ_LOW( data );/*FALLTHRU*/
|
||||
case 0xA2: // LDX #imm
|
||||
pc++;
|
||||
x = data;
|
||||
@@ -460,9 +454,9 @@ imm##op:
|
||||
goto loop;
|
||||
|
||||
case 0xB4: // LDY zp,x
|
||||
data = uint8_t (data + x);
|
||||
data = uint8_t (data + x);/*FALLTHRU*/
|
||||
case 0xA4: // LDY zp
|
||||
data = READ_LOW( data );
|
||||
data = READ_LOW( data );/*FALLTHRU*/
|
||||
case 0xA0: // LDY #imm
|
||||
pc++;
|
||||
y = data;
|
||||
@@ -471,7 +465,7 @@ imm##op:
|
||||
|
||||
case 0xBC: // LDY abs,X
|
||||
data += x;
|
||||
HANDLE_PAGE_CROSSING( data );
|
||||
HANDLE_PAGE_CROSSING( data );/*FALLTHRU*/
|
||||
case 0xAC:{// LDY abs
|
||||
unsigned addr = data + 0x100 * GET_MSB();
|
||||
pc += 2;
|
||||
@@ -483,7 +477,7 @@ imm##op:
|
||||
|
||||
case 0xBE: // LDX abs,y
|
||||
data += y;
|
||||
HANDLE_PAGE_CROSSING( data );
|
||||
HANDLE_PAGE_CROSSING( data );/*FALLTHRU*/
|
||||
case 0xAE:{// LDX abs
|
||||
unsigned addr = data + 0x100 * GET_MSB();
|
||||
pc += 2;
|
||||
@@ -494,7 +488,7 @@ imm##op:
|
||||
}
|
||||
|
||||
{
|
||||
fuint8 temp;
|
||||
uint8_t temp;
|
||||
case 0x8C: // STY abs
|
||||
temp = y;
|
||||
goto store_abs;
|
||||
@@ -527,7 +521,7 @@ imm##op:
|
||||
}
|
||||
|
||||
case 0xE4: // CPX zp
|
||||
data = READ_LOW( data );
|
||||
data = READ_LOW( data );/*FALLTHRU*/
|
||||
case 0xE0: // CPX #imm
|
||||
cpx_data:
|
||||
nz = x - data;
|
||||
@@ -546,7 +540,7 @@ imm##op:
|
||||
}
|
||||
|
||||
case 0xC4: // CPY zp
|
||||
data = READ_LOW( data );
|
||||
data = READ_LOW( data ); // FALLTHRU
|
||||
case 0xC0: // CPY #imm
|
||||
cpy_data:
|
||||
nz = y - data;
|
||||
@@ -604,8 +598,8 @@ imm##op:
|
||||
ARITH_ADDR_MODES( 0x65 ) // ADC
|
||||
adc_imm: {
|
||||
check( !(status & st_d) );
|
||||
fint16 carry = c >> 8 & 1;
|
||||
fint16 ov = (a ^ 0x80) + carry + (BOOST::int8_t) data; // sign-extend
|
||||
int16_t carry = c >> 8 & 1;
|
||||
int16_t ov = (a ^ 0x80) + carry + (int8_t) data; // sign-extend
|
||||
status &= ~st_v;
|
||||
status |= ov >> 2 & 0x40;
|
||||
c = nz = a + data + carry;
|
||||
@@ -617,7 +611,7 @@ imm##op:
|
||||
// Shift/rotate
|
||||
|
||||
case 0x4A: // LSR A
|
||||
c = 0;
|
||||
c = 0;/*FALLTHRU*/
|
||||
case 0x6A: // ROR A
|
||||
nz = c >> 1 & 0x80;
|
||||
c = a << 8;
|
||||
@@ -633,7 +627,7 @@ imm##op:
|
||||
|
||||
case 0x2A: { // ROL A
|
||||
nz = a << 1;
|
||||
fint16 temp = c >> 8 & 1;
|
||||
int16_t temp = c >> 8 & 1;
|
||||
c = nz;
|
||||
nz |= temp;
|
||||
a = (uint8_t) nz;
|
||||
@@ -641,9 +635,9 @@ imm##op:
|
||||
}
|
||||
|
||||
case 0x5E: // LSR abs,X
|
||||
data += x;
|
||||
data += x;/*FALLTHRU*/
|
||||
case 0x4E: // LSR abs
|
||||
c = 0;
|
||||
c = 0;/*FALLTHRU*/
|
||||
case 0x6E: // ROR abs
|
||||
ror_abs: {
|
||||
ADD_PAGE();
|
||||
@@ -659,9 +653,9 @@ imm##op:
|
||||
goto rol_abs;
|
||||
|
||||
case 0x1E: // ASL abs,X
|
||||
data += x;
|
||||
data += x;/*FALLTHRU*/
|
||||
case 0x0E: // ASL abs
|
||||
c = 0;
|
||||
c = 0;/*FALLTHRU*/
|
||||
case 0x2E: // ROL abs
|
||||
rol_abs:
|
||||
ADD_PAGE();
|
||||
@@ -683,9 +677,9 @@ imm##op:
|
||||
goto ror_zp;
|
||||
|
||||
case 0x56: // LSR zp,x
|
||||
data = uint8_t (data + x);
|
||||
data = uint8_t (data + x);/*FALLTHRU*/
|
||||
case 0x46: // LSR zp
|
||||
c = 0;
|
||||
c = 0;/*FALLTHRU*/
|
||||
case 0x66: // ROR zp
|
||||
ror_zp: {
|
||||
int temp = READ_LOW( data );
|
||||
@@ -699,9 +693,9 @@ imm##op:
|
||||
goto rol_zp;
|
||||
|
||||
case 0x16: // ASL zp,x
|
||||
data = uint8_t (data + x);
|
||||
data = uint8_t (data + x);/*FALLTHRU*/
|
||||
case 0x06: // ASL zp
|
||||
c = 0;
|
||||
c = 0;/*FALLTHRU*/
|
||||
case 0x26: // ROL zp
|
||||
rol_zp:
|
||||
nz = c >> 8 & 1;
|
||||
@@ -717,15 +711,15 @@ imm##op:
|
||||
INC_DEC_XY( y, -1 )
|
||||
|
||||
case 0xF6: // INC zp,x
|
||||
data = uint8_t (data + x);
|
||||
data = uint8_t (data + x);/*FALLTHRU*/
|
||||
case 0xE6: // INC zp
|
||||
nz = 1;
|
||||
goto add_nz_zp;
|
||||
|
||||
case 0xD6: // DEC zp,x
|
||||
data = uint8_t (data + x);
|
||||
data = uint8_t (data + x);/*FALLTHRU*/
|
||||
case 0xC6: // DEC zp
|
||||
nz = (unsigned) -1;
|
||||
nz = (uint16_t) -1;
|
||||
add_nz_zp:
|
||||
nz += READ_LOW( data );
|
||||
write_nz_zp:
|
||||
@@ -750,7 +744,7 @@ imm##op:
|
||||
case 0xCE: // DEC abs
|
||||
data = GET_ADDR();
|
||||
dec_ptr:
|
||||
nz = (unsigned) -1;
|
||||
nz = (uint16_t) -1;
|
||||
inc_common:
|
||||
FLUSH_TIME();
|
||||
nz += READ( data );
|
||||
@@ -791,7 +785,7 @@ imm##op:
|
||||
goto loop;
|
||||
|
||||
case 0x40:{// RTI
|
||||
fuint8 temp = READ_LOW( sp );
|
||||
uint8_t temp = READ_LOW( sp );
|
||||
pc = READ_LOW( 0x100 | (sp - 0xFF) );
|
||||
pc |= READ_LOW( 0x100 | (sp - 0xFE) ) * 0x100;
|
||||
sp = (sp - 0xFD) | 0x100;
|
||||
@@ -811,9 +805,9 @@ imm##op:
|
||||
}
|
||||
|
||||
case 0x28:{// PLP
|
||||
fuint8 temp = READ_LOW( sp );
|
||||
uint8_t temp = READ_LOW( sp );
|
||||
sp = (sp - 0xFF) | 0x100;
|
||||
fuint8 changed = status ^ temp;
|
||||
uint8_t changed = status ^ temp;
|
||||
SET_STATUS( temp );
|
||||
if ( !(changed & st_i) )
|
||||
goto loop; // I flag didn't change
|
||||
@@ -823,7 +817,7 @@ imm##op:
|
||||
}
|
||||
|
||||
case 0x08: { // PHP
|
||||
fuint8 temp;
|
||||
uint8_t temp;
|
||||
CALC_STATUS( temp );
|
||||
PUSH( temp | (st_b | st_r) );
|
||||
goto loop;
|
||||
@@ -843,7 +837,7 @@ imm##op:
|
||||
// Flags
|
||||
|
||||
case 0x38: // SEC
|
||||
c = (unsigned) ~0;
|
||||
c = (uint16_t) ~0;
|
||||
goto loop;
|
||||
|
||||
case 0x18: // CLC
|
||||
@@ -912,9 +906,9 @@ imm##op:
|
||||
|
||||
// SKW - Skip word
|
||||
case 0x1C: case 0x3C: case 0x5C: case 0x7C: case 0xDC: case 0xFC:
|
||||
HANDLE_PAGE_CROSSING( data + x );
|
||||
HANDLE_PAGE_CROSSING( data + x );/*FALLTHRU*/
|
||||
case 0x0C:
|
||||
pc++;
|
||||
pc++;/*FALLTHRU*/
|
||||
// SKB - Skip byte
|
||||
case 0x74: case 0x04: case 0x14: case 0x34: case 0x44: case 0x54: case 0x64:
|
||||
case 0x80: case 0x82: case 0x89: case 0xC2: case 0xD4: case 0xE2: case 0xF4:
|
||||
@@ -932,7 +926,6 @@ imm##op:
|
||||
//case 0x62: case 0x72: case 0x92: case 0xB2: case 0xD2: case 0xF2:
|
||||
|
||||
default:
|
||||
assert( (unsigned) opcode <= 0xFF );
|
||||
illegal_encountered = true;
|
||||
pc--;
|
||||
goto stop;
|
||||
@@ -956,7 +949,7 @@ interrupt:
|
||||
pc = GET_LE16( &READ_PROG( 0xFFFA ) + result_ );
|
||||
|
||||
sp = (sp - 3) | 0x100;
|
||||
fuint8 temp;
|
||||
uint8_t temp;
|
||||
CALC_STATUS( temp );
|
||||
temp |= st_r;
|
||||
if ( result_ )
|
||||
@@ -998,7 +991,7 @@ stop:
|
||||
r.y = y;
|
||||
|
||||
{
|
||||
fuint8 temp;
|
||||
uint8_t temp;
|
||||
CALC_STATUS( temp );
|
||||
r.status = temp;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// Atari 6502 CPU emulator
|
||||
|
||||
// Game_Music_Emu 0.6.0
|
||||
// Game_Music_Emu https://bitbucket.org/mpyne/game-music-emu/
|
||||
#ifndef SAP_CPU_H
|
||||
#define SAP_CPU_H
|
||||
|
||||
@@ -12,8 +12,6 @@ enum { future_sap_time = INT_MAX / 2 + 1 };
|
||||
|
||||
class Sap_Cpu {
|
||||
public:
|
||||
typedef BOOST::uint8_t uint8_t;
|
||||
|
||||
// Clear all registers and keep pointer to 64K memory passed in
|
||||
void reset( void* mem_64k );
|
||||
|
||||
@@ -23,12 +21,12 @@ public:
|
||||
|
||||
// Registers are not updated until run() returns (except I flag in status)
|
||||
struct registers_t {
|
||||
BOOST::uint16_t pc;
|
||||
BOOST::uint8_t a;
|
||||
BOOST::uint8_t x;
|
||||
BOOST::uint8_t y;
|
||||
BOOST::uint8_t status;
|
||||
BOOST::uint8_t sp;
|
||||
uint16_t pc;
|
||||
uint8_t a;
|
||||
uint8_t x;
|
||||
uint8_t y;
|
||||
uint8_t status;
|
||||
uint8_t sp;
|
||||
};
|
||||
registers_t r;
|
||||
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
// Game_Music_Emu 0.6.0. http://www.slack.net/~ant/
|
||||
// Game_Music_Emu https://bitbucket.org/mpyne/game-music-emu/
|
||||
|
||||
#include "Sap_Emu.h"
|
||||
|
||||
#include "blargg_endian.h"
|
||||
#include <string.h>
|
||||
#include <algorithm>
|
||||
|
||||
/* Copyright (C) 2006 Shay Green. This module is free software; you
|
||||
can redistribute it and/or modify it under the terms of the GNU Lesser
|
||||
@@ -20,6 +21,9 @@ Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */
|
||||
|
||||
long const base_scanline_period = 114;
|
||||
|
||||
using std::min;
|
||||
using std::max;
|
||||
|
||||
Sap_Emu::Sap_Emu()
|
||||
{
|
||||
set_type( gme_sap_type );
|
||||
@@ -236,8 +240,7 @@ static Music_Emu* new_sap_emu () { return BLARGG_NEW Sap_Emu ; }
|
||||
static Music_Emu* new_sap_file() { return BLARGG_NEW Sap_File; }
|
||||
|
||||
static gme_type_t_ const gme_sap_type_ = { "Atari XL", 0, &new_sap_emu, &new_sap_file, "SAP", 1 };
|
||||
gme_type_t const gme_sap_type = &gme_sap_type_;
|
||||
|
||||
extern gme_type_t const gme_sap_type = &gme_sap_type_;
|
||||
|
||||
// Setup
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// Atari XL/XE SAP music file emulator
|
||||
|
||||
// Game_Music_Emu 0.6.0
|
||||
// Game_Music_Emu https://bitbucket.org/mpyne/game-music-emu/
|
||||
#ifndef SAP_EMU_H
|
||||
#define SAP_EMU_H
|
||||
|
||||
@@ -54,8 +54,7 @@ private:
|
||||
// large items
|
||||
struct {
|
||||
byte padding1 [0x100];
|
||||
byte ram [0x10000];
|
||||
byte padding2 [0x100];
|
||||
byte ram [0x10000 + 0x100];
|
||||
} mem;
|
||||
Sap_Apu_Impl apu_impl;
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// SPC emulation support: init, sample buffering, reset, SPC loading
|
||||
|
||||
// Game_Music_Emu 0.6.0. http://www.slack.net/~ant/
|
||||
// Game_Music_Emu https://bitbucket.org/mpyne/game-music-emu/
|
||||
|
||||
#include "Snes_Spc.h"
|
||||
|
||||
@@ -143,8 +143,8 @@ void Snes_Spc::ram_loaded()
|
||||
load_regs( &RAM [0xF0] );
|
||||
|
||||
// Put STOP instruction around memory to catch PC underflow/overflow
|
||||
memset( m.ram.padding1, cpu_pad_fill, sizeof m.ram.padding1 );
|
||||
memset( m.ram.padding2, cpu_pad_fill, sizeof m.ram.padding2 );
|
||||
memset( m.ram.padding1, cpu_pad_fill, sizeof m.ram.padding1 );
|
||||
memset( m.ram.ram + 0x10000, cpu_pad_fill, sizeof m.ram.padding1 );
|
||||
}
|
||||
|
||||
// Registers were just loaded. Applies these new values.
|
||||
@@ -248,6 +248,8 @@ blargg_err_t Snes_Spc::load_spc( void const* data, long size )
|
||||
|
||||
void Snes_Spc::clear_echo()
|
||||
{
|
||||
// Allows playback of dodgy Super Mario World mod SPCs
|
||||
#ifndef SPC_ISOLATED_ECHO_BUFFER
|
||||
if ( !(dsp.read( Spc_Dsp::r_flg ) & 0x20) )
|
||||
{
|
||||
int addr = 0x100 * dsp.read( Spc_Dsp::r_esa );
|
||||
@@ -256,6 +258,7 @@ void Snes_Spc::clear_echo()
|
||||
end = 0x10000;
|
||||
memset( &RAM [addr], 0xFF, end - addr );
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
||||
+20
-24
@@ -1,16 +1,16 @@
|
||||
// SNES SPC-700 APU emulator
|
||||
|
||||
// Game_Music_Emu 0.6.0
|
||||
// Game_Music_Emu https://bitbucket.org/mpyne/game-music-emu/
|
||||
#ifndef SNES_SPC_H
|
||||
#define SNES_SPC_H
|
||||
|
||||
#include "Spc_Dsp.h"
|
||||
#include "blargg_endian.h"
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
struct Snes_Spc {
|
||||
public:
|
||||
typedef BOOST::uint8_t uint8_t;
|
||||
|
||||
// Must be called once before using
|
||||
blargg_err_t init();
|
||||
|
||||
@@ -108,12 +108,12 @@ public:
|
||||
// TODO: document
|
||||
struct regs_t
|
||||
{
|
||||
int pc;
|
||||
int a;
|
||||
int x;
|
||||
int y;
|
||||
int psw;
|
||||
int sp;
|
||||
uint16_t pc;
|
||||
uint8_t a;
|
||||
uint8_t x;
|
||||
uint8_t y;
|
||||
uint8_t psw;
|
||||
uint8_t sp;
|
||||
};
|
||||
regs_t& smp_regs() { return m.cpu_regs; }
|
||||
|
||||
@@ -123,8 +123,6 @@ public:
|
||||
public:
|
||||
BLARGG_DISABLE_NOTHROW
|
||||
|
||||
typedef BOOST::uint16_t uint16_t;
|
||||
|
||||
// Time relative to m_spc_time. Speeds up code a bit by eliminating need to
|
||||
// constantly add m_spc_time to time from CPU. CPU uses time that ends at
|
||||
// 0 to eliminate reloading end time every instruction. It pays off.
|
||||
@@ -184,13 +182,11 @@ private:
|
||||
|
||||
struct
|
||||
{
|
||||
// padding to neutralize address overflow
|
||||
union {
|
||||
uint8_t padding1 [0x100];
|
||||
uint16_t align; // makes compiler align data for 16-bit access
|
||||
} padding1 [1];
|
||||
uint8_t ram [0x10000];
|
||||
uint8_t padding2 [0x100];
|
||||
// padding to neutralize address overflow -- but this is
|
||||
// still undefined behavior! TODO: remove and instead properly
|
||||
// guard usage of emulated memory
|
||||
uint8_t padding1 [0x100];
|
||||
alignas(uint16_t) uint8_t ram [0x10000 + 0x100];
|
||||
} ram;
|
||||
};
|
||||
state_t m;
|
||||
@@ -226,13 +222,13 @@ private:
|
||||
Timer* run_timer ( Timer* t, rel_time_t );
|
||||
int dsp_read ( rel_time_t );
|
||||
void dsp_write ( int data, rel_time_t );
|
||||
void cpu_write_smp_reg_( int data, rel_time_t, int addr );
|
||||
void cpu_write_smp_reg ( int data, rel_time_t, int addr );
|
||||
void cpu_write_high ( int data, int i, rel_time_t );
|
||||
void cpu_write ( int data, int addr, rel_time_t );
|
||||
void cpu_write_smp_reg_( int data, rel_time_t, uint16_t addr );
|
||||
void cpu_write_smp_reg ( int data, rel_time_t, uint16_t addr );
|
||||
void cpu_write_high ( int data, uint8_t i );
|
||||
void cpu_write ( int data, uint16_t addr, rel_time_t );
|
||||
int cpu_read_smp_reg ( int i, rel_time_t );
|
||||
int cpu_read ( int addr, rel_time_t );
|
||||
unsigned CPU_mem_bit ( uint8_t const* pc, rel_time_t );
|
||||
int cpu_read ( uint16_t addr, rel_time_t );
|
||||
unsigned CPU_mem_bit ( uint16_t pc, rel_time_t );
|
||||
|
||||
bool check_echo_access ( int addr );
|
||||
uint8_t* run_until_( time_t end_time );
|
||||
|
||||
+15
-29
@@ -1,6 +1,6 @@
|
||||
// Core SPC emulation: CPU, timers, SMP registers, memory
|
||||
|
||||
// Game_Music_Emu 0.6.0. http://www.slack.net/~ant/
|
||||
// Game_Music_Emu https://bitbucket.org/mpyne/game-music-emu/
|
||||
|
||||
#include "Snes_Spc.h"
|
||||
|
||||
@@ -284,7 +284,7 @@ static unsigned char const glitch_probs [3] [256] =
|
||||
// If write isn't preceded by read, data has this added to it
|
||||
int const no_read_before_write = 0x2000;
|
||||
|
||||
void Snes_Spc::cpu_write_smp_reg_( int data, rel_time_t time, int addr )
|
||||
void Snes_Spc::cpu_write_smp_reg_( int data, rel_time_t time, uint16_t addr )
|
||||
{
|
||||
switch ( addr )
|
||||
{
|
||||
@@ -385,7 +385,7 @@ void Snes_Spc::cpu_write_smp_reg_( int data, rel_time_t time, int addr )
|
||||
}
|
||||
}
|
||||
|
||||
void Snes_Spc::cpu_write_smp_reg( int data, rel_time_t time, int addr )
|
||||
void Snes_Spc::cpu_write_smp_reg( int data, rel_time_t time, uint16_t addr )
|
||||
{
|
||||
if ( addr == r_dspdata ) // 99%
|
||||
dsp_write( data, time );
|
||||
@@ -393,33 +393,23 @@ void Snes_Spc::cpu_write_smp_reg( int data, rel_time_t time, int addr )
|
||||
cpu_write_smp_reg_( data, time, addr );
|
||||
}
|
||||
|
||||
void Snes_Spc::cpu_write_high( int data, int i, rel_time_t time )
|
||||
void Snes_Spc::cpu_write_high( int data, uint8_t i )
|
||||
{
|
||||
if ( i < rom_size )
|
||||
{
|
||||
m.hi_ram [i] = (uint8_t) data;
|
||||
if ( m.rom_enabled )
|
||||
RAM [i + rom_addr] = m.rom [i]; // restore overwritten ROM
|
||||
}
|
||||
else
|
||||
{
|
||||
assert( RAM [i + rom_addr] == (uint8_t) data );
|
||||
RAM [i + rom_addr] = cpu_pad_fill; // restore overwritten padding
|
||||
cpu_write( data, i + rom_addr - 0x10000, time );
|
||||
}
|
||||
assert ( i < rom_size );
|
||||
m.hi_ram [i] = (uint8_t) data;
|
||||
if ( m.rom_enabled )
|
||||
RAM [i + rom_addr] = m.rom [i]; // restore overwritten ROM
|
||||
}
|
||||
|
||||
int const bits_in_int = CHAR_BIT * sizeof (int);
|
||||
|
||||
void Snes_Spc::cpu_write( int data, int addr, rel_time_t time )
|
||||
void Snes_Spc::cpu_write( int data, uint16_t addr, rel_time_t time )
|
||||
{
|
||||
MEM_ACCESS( time, addr )
|
||||
|
||||
// RAM
|
||||
RAM [addr] = (uint8_t) data;
|
||||
int reg = addr - 0xF0;
|
||||
if ( reg >= 0 ) // 64%
|
||||
if ( addr >= 0xF0 ) // 64%
|
||||
{
|
||||
const uint16_t reg = addr - 0xF0;
|
||||
// $F0-$FF
|
||||
if ( reg < reg_count ) // 87%
|
||||
{
|
||||
@@ -437,12 +427,8 @@ void Snes_Spc::cpu_write( int data, int addr, rel_time_t time )
|
||||
cpu_write_smp_reg( data, time, reg );
|
||||
}
|
||||
// High mem/address wrap-around
|
||||
else
|
||||
{
|
||||
reg -= rom_addr - 0xF0;
|
||||
if ( reg >= 0 ) // 1% in IPL ROM area or address wrapped around
|
||||
cpu_write_high( data, reg, time );
|
||||
}
|
||||
else if ( addr >= rom_addr ) // 1% in IPL ROM area or address wrapped around
|
||||
cpu_write_high( data, addr - rom_addr );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -463,7 +449,7 @@ inline int Snes_Spc::cpu_read_smp_reg( int reg, rel_time_t time )
|
||||
return result;
|
||||
}
|
||||
|
||||
int Snes_Spc::cpu_read( int addr, rel_time_t time )
|
||||
int Snes_Spc::cpu_read( uint16_t addr, rel_time_t time )
|
||||
{
|
||||
MEM_ACCESS( time, addr )
|
||||
|
||||
@@ -507,7 +493,7 @@ int Snes_Spc::cpu_read( int addr, rel_time_t time )
|
||||
|
||||
// Prefix and suffix for CPU emulator function
|
||||
#define SPC_CPU_RUN_FUNC \
|
||||
BOOST::uint8_t* Snes_Spc::run_until_( time_t end_time )\
|
||||
uint8_t* Snes_Spc::run_until_( time_t end_time )\
|
||||
{\
|
||||
rel_time_t rel_time = m.spc_time - end_time;\
|
||||
assert( rel_time <= 0 );\
|
||||
|
||||
+63
-102
@@ -1,4 +1,4 @@
|
||||
// Game_Music_Emu 0.6.0. http://www.slack.net/~ant/
|
||||
// Game_Music_Emu https://bitbucket.org/mpyne/game-music-emu/
|
||||
|
||||
/* Copyright (C) 2004-2007 Shay Green. This module is free software; you
|
||||
can redistribute it and/or modify it under the terms of the GNU Lesser
|
||||
@@ -66,62 +66,37 @@ Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */
|
||||
#define READ_DP( time, addr ) READ ( time, DP_ADDR( addr ) )
|
||||
#define WRITE_DP( time, addr, data ) WRITE( time, DP_ADDR( addr ), data )
|
||||
|
||||
#define READ_PROG16( addr ) GET_LE16( ram + (addr) )
|
||||
#define READ_PROG16( addr ) (RAM [(addr) & 0xffff] | (RAM [((addr) + 1) & 0xffff] << 8))
|
||||
|
||||
#define SET_PC( n ) (pc = ram + (n))
|
||||
#define GET_PC() (pc - ram)
|
||||
#define READ_PC( pc ) (*(pc))
|
||||
#define READ_PC16( pc ) GET_LE16( pc )
|
||||
#define SET_PC( n ) (pc = n)
|
||||
#define GET_PC() (pc)
|
||||
#define READ_PC( pc ) (ram [pc])
|
||||
#define READ_PC16( pc ) READ_PROG16( pc )
|
||||
|
||||
// TODO: remove non-wrapping versions?
|
||||
#define SPC_NO_SP_WRAPAROUND 0
|
||||
#define SET_SP( v ) (sp = v)
|
||||
#define GET_SP() ((uint8_t) (sp))
|
||||
|
||||
#define SET_SP( v ) (sp = ram + 0x101 + ((uint8_t) v))
|
||||
#define GET_SP() (uint8_t (sp - 0x101 - ram))
|
||||
|
||||
#if SPC_NO_SP_WRAPAROUND
|
||||
#define PUSH16( v ) (sp -= 2, SET_LE16( sp, v ))
|
||||
#define PUSH( v ) (void) (*--sp = (uint8_t) (v))
|
||||
#define POP( out ) (void) ((out) = *sp++)
|
||||
|
||||
#else
|
||||
#define PUSH16( data )\
|
||||
{\
|
||||
int addr = (sp -= 2) - ram;\
|
||||
if ( addr > 0x100 )\
|
||||
{\
|
||||
SET_LE16( sp, data );\
|
||||
}\
|
||||
else\
|
||||
{\
|
||||
ram [(uint8_t) addr + 0x100] = (uint8_t) data;\
|
||||
sp [1] = (uint8_t) (data >> 8);\
|
||||
sp += 0x100;\
|
||||
}\
|
||||
PUSH( (data & 0xff00) >> 8 );\
|
||||
PUSH( data & 0xff );\
|
||||
}
|
||||
|
||||
#define PUSH( data )\
|
||||
{\
|
||||
*--sp = (uint8_t) (data);\
|
||||
if ( sp - ram == 0x100 )\
|
||||
sp += 0x100;\
|
||||
ram [0x100 + sp] = (uint8_t) (data);\
|
||||
--sp;\
|
||||
}
|
||||
|
||||
#define POP( out )\
|
||||
{\
|
||||
out = *sp++;\
|
||||
if ( sp - ram == 0x201 )\
|
||||
{\
|
||||
out = sp [-0x101];\
|
||||
sp -= 0x100;\
|
||||
}\
|
||||
++sp;\
|
||||
out = ram [0x100 + sp];\
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#define MEM_BIT( rel ) CPU_mem_bit( pc, rel_time + rel )
|
||||
|
||||
unsigned Snes_Spc::CPU_mem_bit( uint8_t const* pc, rel_time_t rel_time )
|
||||
unsigned Snes_Spc::CPU_mem_bit( uint16_t pc, rel_time_t rel_time )
|
||||
{
|
||||
unsigned addr = READ_PC16( pc );
|
||||
unsigned t = READ( 0, addr & 0x1FFF ) >> (addr >> 13);
|
||||
@@ -163,11 +138,11 @@ int const nz_neg_mask = 0x880; // either bit set indicates N flag set
|
||||
SPC_CPU_RUN_FUNC
|
||||
{
|
||||
uint8_t* const ram = RAM;
|
||||
int a = m.cpu_regs.a;
|
||||
int x = m.cpu_regs.x;
|
||||
int y = m.cpu_regs.y;
|
||||
uint8_t const* pc;
|
||||
uint8_t* sp;
|
||||
uint8_t a = m.cpu_regs.a;
|
||||
uint8_t x = m.cpu_regs.x;
|
||||
uint8_t y = m.cpu_regs.y;
|
||||
uint16_t pc;
|
||||
uint8_t sp;
|
||||
int psw;
|
||||
int c;
|
||||
int nz;
|
||||
@@ -183,7 +158,7 @@ SPC_CPU_RUN_FUNC
|
||||
// Main loop
|
||||
|
||||
cbranch_taken_loop:
|
||||
pc += *(BOOST::int8_t const*) pc;
|
||||
pc += (int8_t) ram [pc];
|
||||
inc_pc_loop:
|
||||
pc++;
|
||||
loop:
|
||||
@@ -195,7 +170,7 @@ loop:
|
||||
check( (unsigned) x < 0x100 );
|
||||
check( (unsigned) y < 0x100 );
|
||||
|
||||
opcode = *pc;
|
||||
opcode = ram [pc];
|
||||
if ( (rel_time += m.cycle_table [opcode]) > 0 )
|
||||
goto out_of_time;
|
||||
|
||||
@@ -218,7 +193,8 @@ loop:
|
||||
*/
|
||||
|
||||
// TODO: if PC is at end of memory, this will get wrong operand (very obscure)
|
||||
data = *++pc;
|
||||
pc++;
|
||||
data = ram [pc];
|
||||
switch ( opcode )
|
||||
{
|
||||
|
||||
@@ -227,10 +203,10 @@ loop:
|
||||
#define BRANCH( cond )\
|
||||
{\
|
||||
pc++;\
|
||||
pc += (BOOST::int8_t) data;\
|
||||
pc += (int8_t) data;\
|
||||
if ( cond )\
|
||||
goto loop;\
|
||||
pc -= (BOOST::int8_t) data;\
|
||||
pc -= (int8_t) data;\
|
||||
rel_time -= 2;\
|
||||
goto loop;\
|
||||
}
|
||||
@@ -249,23 +225,12 @@ loop:
|
||||
}
|
||||
|
||||
case 0x6F:// RET
|
||||
#if SPC_NO_SP_WRAPAROUND
|
||||
{
|
||||
SET_PC( GET_LE16( sp ) );
|
||||
sp += 2;
|
||||
uint8_t l, h;
|
||||
POP( l );
|
||||
POP( h );
|
||||
SET_PC( l | (h << 8) );
|
||||
}
|
||||
#else
|
||||
{
|
||||
int addr = sp - ram;
|
||||
SET_PC( GET_LE16( sp ) );
|
||||
sp += 2;
|
||||
if ( addr < 0x1FF )
|
||||
goto loop;
|
||||
|
||||
SET_PC( sp [-0x101] * 0x100 + ram [(uint8_t) addr + 0x100] );
|
||||
sp -= 0x100;
|
||||
}
|
||||
#endif
|
||||
goto loop;
|
||||
|
||||
case 0xE4: // MOV a,dp
|
||||
@@ -294,8 +259,7 @@ loop:
|
||||
REGS [i] = (uint8_t) data;
|
||||
|
||||
// Registers other than $F2 and $F4-$F7
|
||||
//if ( i != 2 && i != 4 && i != 5 && i != 6 && i != 7 )
|
||||
if ( ((~0x2F00 << (bits_in_int - 16)) << i) < 0 ) // 12%
|
||||
if ( i != 2 && (i < 4 || i > 7)) // 12%
|
||||
cpu_write_smp_reg( data, rel_time, i );
|
||||
}
|
||||
}
|
||||
@@ -328,7 +292,7 @@ loop:
|
||||
#endif
|
||||
goto loop;
|
||||
|
||||
#define CASE( n ) case n:
|
||||
#define CASE( n ) /*FALLTHRU*/case n:
|
||||
|
||||
// Define common address modes based on opcode for immediate mode. Execution
|
||||
// ends with data set to the address of the operand.
|
||||
@@ -347,13 +311,13 @@ loop:
|
||||
data += y;\
|
||||
goto abs_##op;\
|
||||
CASE( op + 0x0D ) /* abs+X */\
|
||||
data += x;\
|
||||
data += x;/*FALLTHRU*/\
|
||||
CASE( op - 0x03 ) /* abs */\
|
||||
abs_##op:\
|
||||
data += 0x100 * READ_PC( ++pc );\
|
||||
goto end_##op;\
|
||||
CASE( op + 0x0C ) /* dp+X */\
|
||||
data = (uint8_t) (data + x);
|
||||
data = (uint8_t) (data + x);/*FALLTHRU*/
|
||||
|
||||
#define ADDR_MODES_NO_DP( op )\
|
||||
ADDR_MODES_( op )\
|
||||
@@ -385,7 +349,7 @@ loop:
|
||||
goto inc_pc_loop;
|
||||
|
||||
case 0xF9: // MOV X,dp+Y
|
||||
data = (uint8_t) (data + y);
|
||||
data = (uint8_t) (data + y);/*FALLTHRU*/
|
||||
case 0xF8: // MOV X,dp
|
||||
READ_DP_TIMER( 0, data, x = nz );
|
||||
goto inc_pc_loop;
|
||||
@@ -393,14 +357,14 @@ loop:
|
||||
case 0xE9: // MOV X,abs
|
||||
data = READ_PC16( pc );
|
||||
++pc;
|
||||
data = READ( 0, data );
|
||||
data = READ( 0, data );/*FALLTHRU*/
|
||||
case 0xCD: // MOV X,imm
|
||||
x = data;
|
||||
nz = data;
|
||||
goto inc_pc_loop;
|
||||
|
||||
case 0xFB: // MOV Y,dp+X
|
||||
data = (uint8_t) (data + x);
|
||||
data = (uint8_t) (data + x);/*FALLTHRU*/
|
||||
case 0xEB: // MOV Y,dp
|
||||
// 70% from timer
|
||||
pc++;
|
||||
@@ -440,13 +404,13 @@ loop:
|
||||
}
|
||||
|
||||
case 0xD9: // MOV dp+Y,X
|
||||
data = (uint8_t) (data + y);
|
||||
data = (uint8_t) (data + y);/*FALLTHRU*/
|
||||
case 0xD8: // MOV dp,X
|
||||
WRITE( 0, data + dp, x );
|
||||
goto inc_pc_loop;
|
||||
|
||||
case 0xDB: // MOV dp+X,Y
|
||||
data = (uint8_t) (data + x);
|
||||
data = (uint8_t) (data + x);/*FALLTHRU*/
|
||||
case 0xCB: // MOV dp,Y
|
||||
WRITE( 0, data + dp, y );
|
||||
goto inc_pc_loop;
|
||||
@@ -492,7 +456,7 @@ loop:
|
||||
|
||||
#define LOGICAL_OP( op, func )\
|
||||
ADDR_MODES( op ) /* addr */\
|
||||
data = READ( 0, data );\
|
||||
data = READ( 0, data );/*FALLTHRU*/\
|
||||
case op: /* imm */\
|
||||
nz = a func##= data;\
|
||||
goto inc_pc_loop;\
|
||||
@@ -504,7 +468,7 @@ loop:
|
||||
case op + 0x01: /* dp,dp */\
|
||||
data = READ_DP( -3, data );\
|
||||
case op + 0x10:{/*dp,imm*/\
|
||||
uint8_t const* addr2 = pc + 1;\
|
||||
uint16_t addr2 = pc + 1;\
|
||||
pc += 2;\
|
||||
addr = READ_PC( addr2 ) + dp;\
|
||||
}\
|
||||
@@ -523,7 +487,7 @@ loop:
|
||||
// 4. 8-BIT ARITHMETIC OPERATION COMMANDS
|
||||
|
||||
ADDR_MODES( 0x68 ) // CMP addr
|
||||
data = READ( 0, data );
|
||||
data = READ( 0, data );/*FALLTHRU*/
|
||||
case 0x68: // CMP imm
|
||||
nz = a - data;
|
||||
c = ~nz;
|
||||
@@ -538,7 +502,7 @@ loop:
|
||||
goto loop;
|
||||
|
||||
case 0x69: // CMP dp,dp
|
||||
data = READ_DP( -3, data );
|
||||
data = READ_DP( -3, data );/*FALLTHRU*/
|
||||
case 0x78: // CMP dp,imm
|
||||
nz = READ_DP( -1, READ_PC( ++pc ) ) - data;
|
||||
c = ~nz;
|
||||
@@ -552,7 +516,7 @@ loop:
|
||||
data = READ_PC16( pc );
|
||||
pc++;
|
||||
cmp_x_addr:
|
||||
data = READ( 0, data );
|
||||
data = READ( 0, data );/*FALLTHRU*/
|
||||
case 0xC8: // CMP X,imm
|
||||
nz = x - data;
|
||||
c = ~nz;
|
||||
@@ -566,7 +530,7 @@ loop:
|
||||
data = READ_PC16( pc );
|
||||
pc++;
|
||||
cmp_y_addr:
|
||||
data = READ( 0, data );
|
||||
data = READ( 0, data );/*FALLTHRU*/
|
||||
case 0xAD: // CMP Y,imm
|
||||
nz = y - data;
|
||||
c = ~nz;
|
||||
@@ -641,7 +605,7 @@ loop:
|
||||
|
||||
case 0x9B: // DEC dp+X
|
||||
case 0xBB: // INC dp+X
|
||||
data = (uint8_t) (data + x);
|
||||
data = (uint8_t) (data + x); /* fallthrough */
|
||||
case 0x8B: // DEC dp
|
||||
case 0xAB: // INC dp
|
||||
data += dp;
|
||||
@@ -659,7 +623,7 @@ loop:
|
||||
// 7. SHIFT, ROTATION COMMANDS
|
||||
|
||||
case 0x5C: // LSR A
|
||||
c = 0;
|
||||
c = 0; /*fallthrough*/
|
||||
case 0x7C:{// ROR A
|
||||
nz = (c >> 1 & 0x80) | (a >> 1);
|
||||
c = a << 8;
|
||||
@@ -668,7 +632,7 @@ loop:
|
||||
}
|
||||
|
||||
case 0x1C: // ASL A
|
||||
c = 0;
|
||||
c = 0; /*fallthrough*/
|
||||
case 0x3C:{// ROL A
|
||||
int temp = c >> 8 & 1;
|
||||
c = a << 1;
|
||||
@@ -682,14 +646,14 @@ loop:
|
||||
data += dp;
|
||||
goto rol_mem;
|
||||
case 0x1B: // ASL dp+X
|
||||
c = 0;
|
||||
c = 0; /*fallthrough*/
|
||||
case 0x3B: // ROL dp+X
|
||||
data = (uint8_t) (data + x);
|
||||
data = (uint8_t) (data + x); /*fallthrough*/
|
||||
case 0x2B: // ROL dp
|
||||
data += dp;
|
||||
goto rol_mem;
|
||||
case 0x0C: // ASL abs
|
||||
c = 0;
|
||||
c = 0; /*fallthrough*/
|
||||
case 0x2C: // ROL abs
|
||||
data = READ_PC16( pc );
|
||||
pc++;
|
||||
@@ -704,14 +668,14 @@ loop:
|
||||
data += dp;
|
||||
goto ror_mem;
|
||||
case 0x5B: // LSR dp+X
|
||||
c = 0;
|
||||
c = 0; /*fallthrough*/
|
||||
case 0x7B: // ROR dp+X
|
||||
data = (uint8_t) (data + x);
|
||||
data = (uint8_t) (data + x); /*fallthrough*/
|
||||
case 0x6B: // ROR dp
|
||||
data += dp;
|
||||
goto ror_mem;
|
||||
case 0x4C: // LSR abs
|
||||
c = 0;
|
||||
c = 0; /*fallthrough*/
|
||||
case 0x6C: // ROR abs
|
||||
data = READ_PC16( pc );
|
||||
pc++;
|
||||
@@ -878,7 +842,7 @@ loop:
|
||||
// 12. BRANCHING COMMANDS
|
||||
|
||||
case 0x2F: // BRA rel
|
||||
pc += (BOOST::int8_t) data;
|
||||
pc += (int8_t) data;
|
||||
goto inc_pc_loop;
|
||||
|
||||
case 0x30: // BMI
|
||||
@@ -1002,10 +966,12 @@ loop:
|
||||
|
||||
{
|
||||
int temp;
|
||||
uint8_t l, h;
|
||||
case 0x7F: // RET1
|
||||
temp = *sp;
|
||||
SET_PC( GET_LE16( sp + 1 ) );
|
||||
SET_SP( GET_SP() + 3 );
|
||||
POP (temp);
|
||||
POP (l);
|
||||
POP (h);
|
||||
SET_PC( l | (h << 8) );
|
||||
goto set_psw;
|
||||
case 0x8E: // POP PSW
|
||||
POP( temp );
|
||||
@@ -1180,11 +1146,8 @@ loop:
|
||||
|
||||
case 0xFF:{// STOP
|
||||
// handle PC wrap-around
|
||||
unsigned addr = GET_PC() - 1;
|
||||
if ( addr >= 0x10000 )
|
||||
if ( pc == 0x0000 )
|
||||
{
|
||||
addr &= 0xFFFF;
|
||||
SET_PC( addr );
|
||||
debug_printf( "SPC: PC wrapped around\n" );
|
||||
goto loop;
|
||||
}
|
||||
@@ -1199,14 +1162,12 @@ loop:
|
||||
} // switch
|
||||
|
||||
assert( 0 ); // catch any unhandled instructions
|
||||
}
|
||||
}
|
||||
out_of_time:
|
||||
rel_time -= m.cycle_table [*pc]; // undo partial execution of opcode
|
||||
rel_time -= m.cycle_table [ ram [pc] ]; // undo partial execution of opcode
|
||||
stop:
|
||||
|
||||
// Uncache registers
|
||||
if ( GET_PC() >= 0x10000 )
|
||||
debug_printf( "SPC: PC wrapped around\n" );
|
||||
m.cpu_regs.pc = (uint16_t) GET_PC();
|
||||
m.cpu_regs.sp = ( uint8_t) GET_SP();
|
||||
m.cpu_regs.a = ( uint8_t) a;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Game_Music_Emu 0.6.0. http://www.slack.net/~ant/
|
||||
// Game_Music_Emu https://bitbucket.org/mpyne/game-music-emu/
|
||||
|
||||
#include "Spc_Dsp.h"
|
||||
|
||||
@@ -28,11 +28,11 @@ Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */
|
||||
|
||||
|
||||
// TODO: add to blargg_endian.h
|
||||
#define GET_LE16SA( addr ) ((BOOST::int16_t) GET_LE16( addr ))
|
||||
#define GET_LE16SA( addr ) ((int16_t) GET_LE16( addr ))
|
||||
#define GET_LE16A( addr ) GET_LE16( addr )
|
||||
#define SET_LE16A( addr, data ) SET_LE16( addr, data )
|
||||
|
||||
static BOOST::uint8_t const initial_regs [Spc_Dsp::register_count] =
|
||||
static uint8_t const initial_regs [Spc_Dsp::register_count] =
|
||||
{
|
||||
0x45,0x8B,0x5A,0x9A,0xE4,0x82,0x1B,0x78,0x00,0x00,0xAA,0x96,0x89,0x0E,0xE0,0x80,
|
||||
0x2A,0x49,0x3D,0xBA,0x14,0xA0,0xAC,0xC5,0x00,0x00,0x51,0xBB,0x9C,0x4E,0x7B,0xFF,
|
||||
@@ -192,6 +192,9 @@ void Spc_Dsp::run( int clock_count )
|
||||
return;
|
||||
|
||||
uint8_t* const ram = m.ram;
|
||||
#ifdef SPC_ISOLATED_ECHO_BUFFER
|
||||
uint8_t* const echo_ram = m.echo_ram;
|
||||
#endif
|
||||
uint8_t const* const dir = &ram [REG(dir) * 0x100];
|
||||
int const slow_gaussian = (REG(pmon) >> 1) | REG(non);
|
||||
int const noise_rate = REG(flg) & 0x1F;
|
||||
@@ -498,8 +501,9 @@ void Spc_Dsp::run( int clock_count )
|
||||
// Decode four samples
|
||||
for ( end = pos + 4; pos < end; pos++, nybbles <<= 4 )
|
||||
{
|
||||
// Extract upper nybble and scale appropriately
|
||||
int s = ((int16_t) nybbles >> right_shift) << left_shift;
|
||||
// Extract upper nybble and scale appropriately. Every cast is
|
||||
// necessary to maintain correctness and avoid undef behavior
|
||||
int s = int16_t(uint16_t((int16_t) nybbles >> right_shift) << left_shift);
|
||||
|
||||
// Apply IIR filter (8 is the most commonly used)
|
||||
int const filter = brr_header & 0x0C;
|
||||
@@ -547,7 +551,12 @@ skip_brr:
|
||||
|
||||
// Echo position
|
||||
int echo_offset = m.echo_offset;
|
||||
#ifdef SPC_ISOLATED_ECHO_BUFFER
|
||||
// And here, we win no awards for accuracy, but gain playback of dodgy Super Mario World mod SPCs
|
||||
uint8_t* const echo_ptr = &echo_ram [(REG(esa) * 0x100 + echo_offset) & 0xFFFF];
|
||||
#else
|
||||
uint8_t* const echo_ptr = &ram [(REG(esa) * 0x100 + echo_offset) & 0xFFFF];
|
||||
#endif
|
||||
if ( !echo_offset )
|
||||
m.echo_length = (REG(edl) & 0x0F) * 0x800;
|
||||
echo_offset += 4;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// Fast SNES SPC-700 DSP emulator (about 3x speed of accurate one)
|
||||
|
||||
// Game_Music_Emu 0.6.0
|
||||
// Game_Music_Emu https://bitbucket.org/mpyne/game-music-emu/
|
||||
#ifndef SPC_DSP_H
|
||||
#define SPC_DSP_H
|
||||
|
||||
@@ -8,8 +8,6 @@
|
||||
|
||||
struct Spc_Dsp {
|
||||
public:
|
||||
typedef BOOST::uint8_t uint8_t;
|
||||
|
||||
// Setup
|
||||
|
||||
// Initializes DSP and has it use the 64K RAM provided
|
||||
@@ -89,9 +87,6 @@ public:
|
||||
public:
|
||||
BLARGG_DISABLE_NOTHROW
|
||||
|
||||
typedef BOOST::int8_t int8_t;
|
||||
typedef BOOST::int16_t int16_t;
|
||||
|
||||
enum { echo_hist_size = 8 };
|
||||
|
||||
enum env_mode_t { env_release, env_attack, env_decay, env_sustain };
|
||||
@@ -115,6 +110,11 @@ private:
|
||||
{
|
||||
uint8_t regs [register_count];
|
||||
|
||||
#ifdef SPC_ISOLATED_ECHO_BUFFER
|
||||
// Echo buffer, for dodgy SPC rips that were only made to work in dodgy emulators
|
||||
uint8_t echo_ram [64 * 1024];
|
||||
#endif
|
||||
|
||||
// Echo history keeps most recent 8 samples (twice the size to simplify wrap handling)
|
||||
int echo_hist [echo_hist_size * 2] [2];
|
||||
int (*echo_hist_pos) [2]; // &echo_hist [0 to 7]
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
// Game_Music_Emu 0.6.0. http://www.slack.net/~ant/
|
||||
// Game_Music_Emu https://bitbucket.org/mpyne/game-music-emu/
|
||||
|
||||
#include "Spc_Emu.h"
|
||||
|
||||
#include "blargg_endian.h"
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <algorithm>
|
||||
|
||||
/* Copyright (C) 2004-2006 Shay Green. This module is free software; you
|
||||
can redistribute it and/or modify it under the terms of the GNU Lesser
|
||||
@@ -19,6 +20,9 @@ Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */
|
||||
|
||||
#include "blargg_source.h"
|
||||
|
||||
using std::min;
|
||||
using std::max;
|
||||
|
||||
// TODO: support Spc_Filter's bass
|
||||
|
||||
Spc_Emu::Spc_Emu()
|
||||
@@ -244,7 +248,7 @@ static Music_Emu* new_spc_emu () { return BLARGG_NEW Spc_Emu ; }
|
||||
static Music_Emu* new_spc_file() { return BLARGG_NEW Spc_File; }
|
||||
|
||||
static gme_type_t_ const gme_spc_type_ = { "Super Nintendo", 1, &new_spc_emu, &new_spc_file, "SPC", 0 };
|
||||
gme_type_t const gme_spc_type = &gme_spc_type_;
|
||||
extern gme_type_t const gme_spc_type = &gme_spc_type_;
|
||||
|
||||
|
||||
// Setup
|
||||
@@ -299,6 +303,12 @@ blargg_err_t Spc_Emu::start_track_( int track )
|
||||
RETURN_ERR( apu.load_spc( file_data, file_size ) );
|
||||
filter.set_gain( (int) (gain() * SPC_Filter::gain_unit) );
|
||||
apu.clear_echo();
|
||||
track_info_t spc_info;
|
||||
RETURN_ERR( track_info_( &spc_info, track ) );
|
||||
|
||||
// Set a default track length, need a non-zero fadeout
|
||||
if ( autoload_playback_limit() && ( spc_info.length > 0 ) )
|
||||
set_fade ( spc_info.length, 50 );
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// Super Nintendo SPC music file emulator
|
||||
|
||||
// Game_Music_Emu 0.6.0
|
||||
// Game_Music_Emu https://bitbucket.org/mpyne/game-music-emu/
|
||||
#ifndef SPC_EMU_H
|
||||
#define SPC_EMU_H
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Game_Music_Emu 0.6.0. http://www.slack.net/~ant/
|
||||
// Game_Music_Emu https://bitbucket.org/mpyne/game-music-emu/
|
||||
|
||||
#include "Spc_Filter.h"
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// Simple low-pass and high-pass filter to better match sound output of a SNES
|
||||
|
||||
// Game_Music_Emu 0.6.0
|
||||
// Game_Music_Emu https://bitbucket.org/mpyne/game-music-emu/
|
||||
#ifndef SPC_FILTER_H
|
||||
#define SPC_FILTER_H
|
||||
|
||||
|
||||
+115
-28
@@ -1,10 +1,11 @@
|
||||
// Game_Music_Emu 0.6.0. http://www.slack.net/~ant/
|
||||
// Game_Music_Emu https://bitbucket.org/mpyne/game-music-emu/
|
||||
|
||||
#include "Vgm_Emu.h"
|
||||
|
||||
#include "blargg_endian.h"
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
#include <algorithm>
|
||||
|
||||
/* Copyright (C) 2003-2006 Shay Green. This module is free software; you
|
||||
can redistribute it and/or modify it under the terms of the GNU Lesser
|
||||
@@ -21,7 +22,10 @@ Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */
|
||||
|
||||
double const fm_gain = 3.0; // FM emulators are internally quieter to avoid 16-bit overflow
|
||||
double const rolloff = 0.990;
|
||||
double const oversample_factor = 1.5;
|
||||
double const oversample_factor = 1.0;
|
||||
|
||||
using std::min;
|
||||
using std::max;
|
||||
|
||||
Vgm_Emu::Vgm_Emu()
|
||||
{
|
||||
@@ -203,10 +207,10 @@ static Music_Emu* new_vgm_emu () { return BLARGG_NEW Vgm_Emu ; }
|
||||
static Music_Emu* new_vgm_file() { return BLARGG_NEW Vgm_File; }
|
||||
|
||||
static gme_type_t_ const gme_vgm_type_ = { "Sega SMS/Genesis", 1, &new_vgm_emu, &new_vgm_file, "VGM", 1 };
|
||||
gme_type_t const gme_vgm_type = &gme_vgm_type_;
|
||||
extern gme_type_t const gme_vgm_type = &gme_vgm_type_;
|
||||
|
||||
static gme_type_t_ const gme_vgz_type_ = { "Sega SMS/Genesis", 1, &new_vgm_emu, &new_vgm_file, "VGZ", 1 };
|
||||
gme_type_t const gme_vgz_type = &gme_vgz_type_;
|
||||
extern gme_type_t const gme_vgz_type = &gme_vgz_type_;
|
||||
|
||||
|
||||
// Setup
|
||||
@@ -233,16 +237,59 @@ blargg_err_t Vgm_Emu::set_sample_rate_( long sample_rate )
|
||||
return Classic_Emu::set_sample_rate_( sample_rate );
|
||||
}
|
||||
|
||||
blargg_err_t Vgm_Emu::set_multi_channel ( bool is_enabled )
|
||||
{
|
||||
// we acutally should check here whether this is classic emu or not
|
||||
// however set_multi_channel() is called before setup_fm() resulting in uninited is_classic_emu()
|
||||
// hard code it to unsupported
|
||||
#if 0
|
||||
if ( is_classic_emu() )
|
||||
{
|
||||
RETURN_ERR( Music_Emu::set_multi_channel_( is_enabled ) );
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
(void) is_enabled;
|
||||
return "multichannel rendering not supported for YM2*** FM sound chip emulators";
|
||||
}
|
||||
}
|
||||
|
||||
void Vgm_Emu::update_eq( blip_eq_t const& eq )
|
||||
{
|
||||
psg.treble_eq( eq );
|
||||
psg[0].treble_eq( eq );
|
||||
if ( psg_dual )
|
||||
psg[1].treble_eq( eq );
|
||||
dac_synth.treble_eq( eq );
|
||||
}
|
||||
|
||||
void Vgm_Emu::set_voice( int i, Blip_Buffer* c, Blip_Buffer* l, Blip_Buffer* r )
|
||||
{
|
||||
if ( i < psg.osc_count )
|
||||
psg.osc_output( i, c, l, r );
|
||||
if ( psg_dual )
|
||||
{
|
||||
if ( psg_t6w28 )
|
||||
{
|
||||
// TODO: Make proper output of each PSG chip: 0 - all right, 1 - all left
|
||||
if ( i < psg[0].osc_count )
|
||||
psg[0].osc_output( i, c, r, r );
|
||||
if ( i < psg[1].osc_count )
|
||||
psg[1].osc_output( i, c, l, l );
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( i < psg[0].osc_count )
|
||||
psg[0].osc_output( i, c, l, r );
|
||||
if ( i < psg[1].osc_count )
|
||||
psg[1].osc_output( i, c, l, r );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( i < psg[0].osc_count )
|
||||
psg[0].osc_output( i, c, l, r );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void Vgm_Emu::mute_voices_( int mask )
|
||||
@@ -251,21 +298,26 @@ void Vgm_Emu::mute_voices_( int mask )
|
||||
dac_synth.output( &blip_buf );
|
||||
if ( uses_fm )
|
||||
{
|
||||
psg.output( (mask & 0x80) ? 0 : &blip_buf );
|
||||
if ( ym2612.enabled() )
|
||||
psg[0].output( (mask & 0x80) ? 0 : &blip_buf );
|
||||
if ( psg_dual )
|
||||
psg[1].output( (mask & 0x80) ? 0 : &blip_buf );
|
||||
if ( ym2612[0].enabled() )
|
||||
{
|
||||
dac_synth.volume( (mask & 0x40) ? 0.0 : 0.1115 / 256 * fm_gain * gain() );
|
||||
ym2612.mute_voices( mask );
|
||||
ym2612[0].mute_voices( mask );
|
||||
if ( ym2612[1].enabled() )
|
||||
ym2612[1].mute_voices( mask );
|
||||
}
|
||||
|
||||
if ( ym2413.enabled() )
|
||||
if ( ym2413[0].enabled() )
|
||||
{
|
||||
int m = mask & 0x3F;
|
||||
if ( mask & 0x20 )
|
||||
m |= 0x01E0; // channels 5-8
|
||||
if ( mask & 0x40 )
|
||||
m |= 0x3E00;
|
||||
ym2413.mute_voices( m );
|
||||
ym2413[0].mute_voices( m );
|
||||
if ( ym2413[1].enabled() )
|
||||
ym2413[1].mute_voices( m );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -287,6 +339,9 @@ blargg_err_t Vgm_Emu::load_mem_( byte const* new_data, long new_size )
|
||||
psg_rate = get_le32( h.psg_rate );
|
||||
if ( !psg_rate )
|
||||
psg_rate = 3579545;
|
||||
psg_dual = ( psg_rate & 0x40000000 ) != 0;
|
||||
psg_t6w28 = ( psg_rate & 0x80000000 ) != 0;
|
||||
psg_rate &= 0x0FFFFFFF;
|
||||
blip_buf.clock_rate( psg_rate );
|
||||
|
||||
data = new_data;
|
||||
@@ -297,7 +352,7 @@ blargg_err_t Vgm_Emu::load_mem_( byte const* new_data, long new_size )
|
||||
if ( get_le32( h.loop_offset ) )
|
||||
loop_begin = &data [get_le32( h.loop_offset ) + offsetof (header_t,loop_offset)];
|
||||
|
||||
set_voice_count( psg.osc_count );
|
||||
set_voice_count( psg[0].osc_count );
|
||||
|
||||
RETURN_ERR( setup_fm() );
|
||||
|
||||
@@ -314,7 +369,9 @@ blargg_err_t Vgm_Emu::load_mem_( byte const* new_data, long new_size )
|
||||
blargg_err_t Vgm_Emu::setup_fm()
|
||||
{
|
||||
long ym2612_rate = get_le32( header().ym2612_rate );
|
||||
bool ym2612_dual = ( ym2612_rate & 0x40000000 ) != 0;
|
||||
long ym2413_rate = get_le32( header().ym2413_rate );
|
||||
bool ym2413_dual = ( ym2413_rate & 0x40000000 ) != 0;
|
||||
if ( ym2413_rate && get_le32( header().version ) < 0x110 )
|
||||
update_fm_rates( &ym2413_rate, &ym2612_rate );
|
||||
|
||||
@@ -324,39 +381,59 @@ blargg_err_t Vgm_Emu::setup_fm()
|
||||
|
||||
if ( ym2612_rate )
|
||||
{
|
||||
ym2612_rate &= ~0xC0000000;
|
||||
uses_fm = true;
|
||||
if ( disable_oversampling_ )
|
||||
fm_rate = ym2612_rate / 144.0;
|
||||
Dual_Resampler::setup( fm_rate / blip_buf.sample_rate(), rolloff, fm_gain * gain() );
|
||||
RETURN_ERR( ym2612.set_rate( fm_rate, ym2612_rate ) );
|
||||
ym2612.enable( true );
|
||||
RETURN_ERR( ym2612[0].set_rate( fm_rate, ym2612_rate ) );
|
||||
ym2612[0].enable( true );
|
||||
if ( ym2612_dual )
|
||||
{
|
||||
RETURN_ERR( ym2612[1].set_rate( fm_rate, ym2612_rate ) );
|
||||
ym2612[1].enable( true );
|
||||
}
|
||||
set_voice_count( 8 );
|
||||
}
|
||||
|
||||
if ( !uses_fm && ym2413_rate )
|
||||
{
|
||||
ym2413_rate &= ~0xC0000000;
|
||||
uses_fm = true;
|
||||
if ( disable_oversampling_ )
|
||||
fm_rate = ym2413_rate / 72.0;
|
||||
Dual_Resampler::setup( fm_rate / blip_buf.sample_rate(), rolloff, fm_gain * gain() );
|
||||
int result = ym2413.set_rate( fm_rate, ym2413_rate );
|
||||
int result = ym2413[0].set_rate( fm_rate, ym2413_rate );
|
||||
if ( result == 2 )
|
||||
return "YM2413 FM sound isn't supported";
|
||||
CHECK_ALLOC( !result );
|
||||
ym2413.enable( true );
|
||||
ym2413[0].enable( true );
|
||||
if ( ym2413_dual )
|
||||
{
|
||||
ym2413[1].enable( true );
|
||||
int result = ym2413[1].set_rate( fm_rate, ym2413_rate );
|
||||
if ( result == 2 )
|
||||
return "YM2413 FM sound isn't supported";
|
||||
CHECK_ALLOC( !result );
|
||||
}
|
||||
set_voice_count( 8 );
|
||||
}
|
||||
|
||||
if ( uses_fm )
|
||||
{
|
||||
RETURN_ERR( Dual_Resampler::reset( blip_buf.length() * blip_buf.sample_rate() / 1000 ) );
|
||||
psg.volume( 0.135 * fm_gain * gain() );
|
||||
psg[0].volume( 0.135 * fm_gain * gain() );
|
||||
if ( psg_dual )
|
||||
psg[1].volume( 0.135 * fm_gain * gain() );
|
||||
}
|
||||
else
|
||||
{
|
||||
ym2612.enable( false );
|
||||
ym2413.enable( false );
|
||||
psg.volume( gain() );
|
||||
ym2612[0].enable( false );
|
||||
ym2612[1].enable( false );
|
||||
ym2413[0].enable( false );
|
||||
ym2413[1].enable( false );
|
||||
psg[0].volume( gain() );
|
||||
psg[1].volume( gain() );
|
||||
}
|
||||
|
||||
return 0;
|
||||
@@ -367,7 +444,9 @@ blargg_err_t Vgm_Emu::setup_fm()
|
||||
blargg_err_t Vgm_Emu::start_track_( int track )
|
||||
{
|
||||
RETURN_ERR( Classic_Emu::start_track_( track ) );
|
||||
psg.reset( get_le16( header().noise_feedback ), header().noise_width );
|
||||
psg[0].reset( get_le16( header().noise_feedback ), header().noise_width );
|
||||
if ( psg_dual )
|
||||
psg[1].reset( get_le16( header().noise_feedback ), header().noise_width );
|
||||
|
||||
dac_disabled = -1;
|
||||
pos = data + header_size;
|
||||
@@ -385,11 +464,17 @@ blargg_err_t Vgm_Emu::start_track_( int track )
|
||||
|
||||
if ( uses_fm )
|
||||
{
|
||||
if ( ym2413.enabled() )
|
||||
ym2413.reset();
|
||||
if ( ym2413[0].enabled() )
|
||||
ym2413[0].reset();
|
||||
|
||||
if ( ym2413[1].enabled() )
|
||||
ym2413[1].reset();
|
||||
|
||||
if ( ym2612.enabled() )
|
||||
ym2612.reset();
|
||||
if ( ym2612[0].enabled() )
|
||||
ym2612[0].reset();
|
||||
|
||||
if ( ym2612[1].enabled() )
|
||||
ym2612[1].reset();
|
||||
|
||||
fm_time_offset = 0;
|
||||
blip_buf.clear();
|
||||
@@ -401,7 +486,9 @@ blargg_err_t Vgm_Emu::start_track_( int track )
|
||||
blargg_err_t Vgm_Emu::run_clocks( blip_time_t& time_io, int msec )
|
||||
{
|
||||
time_io = run_commands( msec * vgm_rate / 1000 );
|
||||
psg.end_frame( time_io );
|
||||
psg[0].end_frame( time_io );
|
||||
if ( psg_dual )
|
||||
psg[1].end_frame( time_io );
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// Sega Master System/Mark III, Sega Genesis/Mega Drive, BBC Micro VGM music file emulator
|
||||
|
||||
// Game_Music_Emu 0.6.0
|
||||
// Game_Music_Emu https://bitbucket.org/mpyne/game-music-emu/
|
||||
#ifndef VGM_EMU_H
|
||||
#define VGM_EMU_H
|
||||
|
||||
@@ -17,6 +17,8 @@ public:
|
||||
// TODO: move into Music_Emu and rename to something like supports_custom_buffer()
|
||||
bool is_classic_emu() const { return !uses_fm; }
|
||||
|
||||
blargg_err_t set_multi_channel ( bool is_enabled ) override;
|
||||
|
||||
// Disable running FM chips at higher than normal rate. Will result in slightly
|
||||
// more aliasing of high notes.
|
||||
void disable_oversampling( bool disable = true ) { disable_oversampling_ = disable; }
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Game_Music_Emu 0.6.0. http://www.slack.net/~ant/
|
||||
// Game_Music_Emu https://bitbucket.org/mpyne/game-music-emu/
|
||||
|
||||
#include "Vgm_Emu.h"
|
||||
|
||||
@@ -36,6 +36,12 @@ enum {
|
||||
cmd_pcm_delay = 0x80,
|
||||
cmd_pcm_seek = 0xE0,
|
||||
|
||||
cmd_gg_stereo_2 = 0x3F,
|
||||
cmd_psg_2 = 0x30,
|
||||
cmd_ym2413_2 = 0xA1,
|
||||
cmd_ym2612_2_port0 = 0xA2,
|
||||
cmd_ym2612_2_port1 = 0xA3,
|
||||
|
||||
pcm_block_type = 0x00,
|
||||
ym2612_dac_port = 0x2A
|
||||
};
|
||||
@@ -142,13 +148,21 @@ blip_time_t Vgm_Emu_Impl::run_commands( vgm_time_t end_time )
|
||||
break;
|
||||
|
||||
case cmd_gg_stereo:
|
||||
psg.write_ggstereo( to_blip_time( vgm_time ), *pos++ );
|
||||
psg[0].write_ggstereo( to_blip_time( vgm_time ), *pos++ );
|
||||
break;
|
||||
|
||||
case cmd_psg:
|
||||
psg.write_data( to_blip_time( vgm_time ), *pos++ );
|
||||
psg[0].write_data( to_blip_time( vgm_time ), *pos++ );
|
||||
break;
|
||||
|
||||
case cmd_gg_stereo_2:
|
||||
psg[1].write_ggstereo( to_blip_time( vgm_time ), *pos++ );
|
||||
break;
|
||||
|
||||
case cmd_psg_2:
|
||||
psg[1].write_data( to_blip_time( vgm_time ), *pos++ );
|
||||
break;
|
||||
|
||||
case cmd_delay:
|
||||
vgm_time += pos [1] * 0x100L + pos [0];
|
||||
pos += 2;
|
||||
@@ -159,8 +173,14 @@ blip_time_t Vgm_Emu_Impl::run_commands( vgm_time_t end_time )
|
||||
break;
|
||||
|
||||
case cmd_ym2413:
|
||||
if ( ym2413.run_until( to_fm_time( vgm_time ) ) )
|
||||
ym2413.write( pos [0], pos [1] );
|
||||
if ( ym2413[0].run_until( to_fm_time( vgm_time ) ) )
|
||||
ym2413[0].write( pos [0], pos [1] );
|
||||
pos += 2;
|
||||
break;
|
||||
|
||||
case cmd_ym2413_2:
|
||||
if ( ym2413[1].run_until( to_fm_time( vgm_time ) ) )
|
||||
ym2413[1].write( pos [0], pos [1] );
|
||||
pos += 2;
|
||||
break;
|
||||
|
||||
@@ -169,24 +189,47 @@ blip_time_t Vgm_Emu_Impl::run_commands( vgm_time_t end_time )
|
||||
{
|
||||
write_pcm( vgm_time, pos [1] );
|
||||
}
|
||||
else if ( ym2612.run_until( to_fm_time( vgm_time ) ) )
|
||||
else if ( ym2612[0].run_until( to_fm_time( vgm_time ) ) )
|
||||
{
|
||||
if ( pos [0] == 0x2B )
|
||||
{
|
||||
dac_disabled = (pos [1] >> 7 & 1) - 1;
|
||||
dac_amp |= dac_disabled;
|
||||
}
|
||||
ym2612.write0( pos [0], pos [1] );
|
||||
ym2612[0].write0( pos [0], pos [1] );
|
||||
}
|
||||
pos += 2;
|
||||
break;
|
||||
|
||||
case cmd_ym2612_port1:
|
||||
if ( ym2612.run_until( to_fm_time( vgm_time ) ) )
|
||||
ym2612.write1( pos [0], pos [1] );
|
||||
if ( ym2612[0].run_until( to_fm_time( vgm_time ) ) )
|
||||
ym2612[0].write1( pos [0], pos [1] );
|
||||
pos += 2;
|
||||
break;
|
||||
|
||||
|
||||
case cmd_ym2612_2_port0:
|
||||
if ( pos [0] == ym2612_dac_port )
|
||||
{
|
||||
write_pcm( vgm_time, pos [1] );
|
||||
}
|
||||
else if ( ym2612[1].run_until( to_fm_time( vgm_time ) ) )
|
||||
{
|
||||
if ( pos [0] == 0x2B )
|
||||
{
|
||||
dac_disabled = (pos [1] >> 7 & 1) - 1;
|
||||
dac_amp |= dac_disabled;
|
||||
}
|
||||
ym2612[1].write0( pos [0], pos [1] );
|
||||
}
|
||||
pos += 2;
|
||||
break;
|
||||
|
||||
case cmd_ym2612_2_port1:
|
||||
if ( ym2612[1].run_until( to_fm_time( vgm_time ) ) )
|
||||
ym2612[1].write1( pos [0], pos [1] );
|
||||
pos += 2;
|
||||
break;
|
||||
|
||||
case cmd_data_block: {
|
||||
check( *pos == cmd_end );
|
||||
int type = pos [1];
|
||||
@@ -246,24 +289,39 @@ int Vgm_Emu_Impl::play_frame( blip_time_t blip_time, int sample_count, sample_t*
|
||||
vgm_time++;
|
||||
//debug_printf( "pairs: %d, min_pairs: %d\n", pairs, min_pairs );
|
||||
|
||||
if ( ym2612.enabled() )
|
||||
if ( ym2612[0].enabled() )
|
||||
{
|
||||
ym2612.begin_frame( buf );
|
||||
ym2612[0].begin_frame( buf );
|
||||
if ( ym2612[1].enabled() )
|
||||
ym2612[1].begin_frame( buf );
|
||||
memset( buf, 0, pairs * stereo * sizeof *buf );
|
||||
}
|
||||
else if ( ym2413.enabled() )
|
||||
else if ( ym2413[0].enabled() )
|
||||
{
|
||||
ym2413.begin_frame( buf );
|
||||
ym2413[0].begin_frame( buf );
|
||||
if ( ym2413[1].enabled() )
|
||||
ym2413[1].begin_frame( buf );
|
||||
memset( buf, 0, pairs * stereo * sizeof *buf );
|
||||
}
|
||||
|
||||
run_commands( vgm_time );
|
||||
ym2612.run_until( pairs );
|
||||
ym2413.run_until( pairs );
|
||||
|
||||
if ( ym2612[0].enabled() )
|
||||
ym2612[0].run_until( pairs );
|
||||
if ( ym2612[1].enabled() )
|
||||
ym2612[1].run_until( pairs );
|
||||
|
||||
if ( ym2413[0].enabled() )
|
||||
ym2413[0].run_until( pairs );
|
||||
if ( ym2413[1].enabled() )
|
||||
ym2413[1].run_until( pairs );
|
||||
|
||||
fm_time_offset = (vgm_time * fm_time_factor + fm_time_offset) -
|
||||
((long) pairs << fm_time_bits);
|
||||
|
||||
psg.end_frame( blip_time );
|
||||
psg[0].end_frame( blip_time );
|
||||
if ( psg_dual )
|
||||
psg[1].end_frame( blip_time );
|
||||
|
||||
return pairs * stereo;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// Low-level parts of Vgm_Emu
|
||||
|
||||
// Game_Music_Emu 0.6.0
|
||||
// Game_Music_Emu https://bitbucket.org/mpyne/game-music-emu/
|
||||
#ifndef VGM_EMU_IMPL_H
|
||||
#define VGM_EMU_IMPL_H
|
||||
|
||||
@@ -58,11 +58,13 @@ protected:
|
||||
int dac_disabled; // -1 if disabled
|
||||
void write_pcm( vgm_time_t, int amp );
|
||||
|
||||
Ym_Emu<Ym2612_Emu> ym2612;
|
||||
Ym_Emu<Ym2413_Emu> ym2413;
|
||||
Ym_Emu<Ym2612_Emu> ym2612[2];
|
||||
Ym_Emu<Ym2413_Emu> ym2413[2];
|
||||
|
||||
Blip_Buffer blip_buf;
|
||||
Sms_Apu psg;
|
||||
Sms_Apu psg[2];
|
||||
bool psg_dual;
|
||||
bool psg_t6w28;
|
||||
Blip_Synth<blip_med_quality,1> dac_synth;
|
||||
|
||||
friend class Vgm_Emu;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
|
||||
// Use in place of Ym2413_Emu.cpp and ym2413.c to disable support for this chip
|
||||
|
||||
// Game_Music_Emu 0.6.0. http://www.slack.net/~ant/
|
||||
// Game_Music_Emu https://bitbucket.org/mpyne/game-music-emu/
|
||||
|
||||
#include "Ym2413_Emu.h"
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// YM2413 FM sound chip emulator interface
|
||||
|
||||
// Game_Music_Emu 0.6.0
|
||||
// Game_Music_Emu https://bitbucket.org/mpyne/game-music-emu/
|
||||
#ifndef YM2413_EMU_H
|
||||
#define YM2413_EMU_H
|
||||
|
||||
|
||||
+15
-34
@@ -1,38 +1,19 @@
|
||||
// YM2612 FM sound chip emulator interface
|
||||
|
||||
// Game_Music_Emu 0.6.0
|
||||
#ifndef YM2612_EMU_H
|
||||
#define YM2612_EMU_H
|
||||
|
||||
struct Ym2612_Impl;
|
||||
|
||||
class Ym2612_Emu {
|
||||
Ym2612_Impl* impl;
|
||||
public:
|
||||
Ym2612_Emu() { impl = 0; }
|
||||
~Ym2612_Emu();
|
||||
|
||||
// Set output sample rate and chip clock rates, in Hz. Returns non-zero
|
||||
// if error.
|
||||
const char* set_rate( double sample_rate, double clock_rate );
|
||||
|
||||
// Reset to power-up state
|
||||
void reset();
|
||||
|
||||
// Mute voice n if bit n (1 << n) of mask is set
|
||||
enum { channel_count = 6 };
|
||||
void mute_voices( int mask );
|
||||
|
||||
// Write addr to register 0 then data to register 1
|
||||
void write0( int addr, int data );
|
||||
|
||||
// Write addr to register 2 then data to register 3
|
||||
void write1( int addr, int data );
|
||||
|
||||
// Run and add pair_count samples into current output buffer contents
|
||||
typedef short sample_t;
|
||||
enum { out_chan_count = 2 }; // stereo
|
||||
void run( int pair_count, sample_t* out );
|
||||
};
|
||||
// Game_Music_Emu https://bitbucket.org/mpyne/game-music-emu/
|
||||
|
||||
#ifdef VGM_YM2612_GENS // LGPL v2.1+ license
|
||||
#include "Ym2612_GENS.h"
|
||||
typedef Ym2612_GENS_Emu Ym2612_Emu;
|
||||
#endif
|
||||
|
||||
#ifdef VGM_YM2612_NUKED // LGPL v2.1+ license
|
||||
#include "Ym2612_Nuked.h"
|
||||
typedef Ym2612_Nuked_Emu Ym2612_Emu;
|
||||
#endif
|
||||
|
||||
#ifdef VGM_YM2612_MAME // GPL v2+ license
|
||||
#include "Ym2612_MAME.h"
|
||||
typedef Ym2612_MAME_Emu Ym2612_Emu;
|
||||
#endif
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,38 @@
|
||||
// YM2612 FM sound chip emulator interface
|
||||
|
||||
// Game_Music_Emu https://bitbucket.org/mpyne/game-music-emu/
|
||||
#ifndef YM2612_EMU_H
|
||||
#define YM2612_EMU_H
|
||||
|
||||
struct Ym2612_GENS_Impl;
|
||||
|
||||
class Ym2612_GENS_Emu {
|
||||
Ym2612_GENS_Impl* impl;
|
||||
public:
|
||||
Ym2612_GENS_Emu() { impl = 0; }
|
||||
~Ym2612_GENS_Emu();
|
||||
|
||||
// Set output sample rate and chip clock rates, in Hz. Returns non-zero
|
||||
// if error.
|
||||
const char* set_rate( double sample_rate, double clock_rate );
|
||||
|
||||
// Reset to power-up state
|
||||
void reset();
|
||||
|
||||
// Mute voice n if bit n (1 << n) of mask is set
|
||||
enum { channel_count = 6 };
|
||||
void mute_voices( int mask );
|
||||
|
||||
// Write addr to register 0 then data to register 1
|
||||
void write0( int addr, int data );
|
||||
|
||||
// Write addr to register 2 then data to register 3
|
||||
void write1( int addr, int data );
|
||||
|
||||
// Run and add pair_count samples into current output buffer contents
|
||||
typedef short sample_t;
|
||||
enum { out_chan_count = 2 }; // stereo
|
||||
void run( int pair_count, sample_t* out );
|
||||
};
|
||||
|
||||
#endif
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,38 @@
|
||||
// YM2612 FM sound chip emulator interface
|
||||
|
||||
// Game_Music_Emu https://bitbucket.org/mpyne/game-music-emu/
|
||||
#ifndef YM2612_EMU_H
|
||||
#define YM2612_EMU_H
|
||||
|
||||
typedef void Ym2612_MAME_Impl;
|
||||
|
||||
class Ym2612_MAME_Emu {
|
||||
Ym2612_MAME_Impl* impl;
|
||||
public:
|
||||
Ym2612_MAME_Emu();
|
||||
~Ym2612_MAME_Emu();
|
||||
|
||||
// Set output sample rate and chip clock rates, in Hz. Returns non-zero
|
||||
// if error.
|
||||
const char* set_rate( double sample_rate, double clock_rate );
|
||||
|
||||
// Reset to power-up state
|
||||
void reset();
|
||||
|
||||
// Mute voice n if bit n (1 << n) of mask is set
|
||||
enum { channel_count = 6 };
|
||||
void mute_voices( int mask );
|
||||
|
||||
// Write addr to register 0 then data to register 1
|
||||
void write0( int addr, int data );
|
||||
|
||||
// Write addr to register 2 then data to register 3
|
||||
void write1( int addr, int data );
|
||||
|
||||
// Run and add pair_count samples into current output buffer contents
|
||||
typedef short sample_t;
|
||||
enum { out_chan_count = 2 }; // stereo
|
||||
void run( int pair_count, sample_t* out );
|
||||
};
|
||||
|
||||
#endif
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,41 @@
|
||||
// YM2612 FM sound chip emulator interface
|
||||
|
||||
// Game_Music_Emu https://bitbucket.org/mpyne/game-music-emu/
|
||||
#ifndef YM2612_EMU_H
|
||||
#define YM2612_EMU_H
|
||||
|
||||
typedef void Ym2612_Nuked_Impl;
|
||||
|
||||
class Ym2612_Nuked_Emu {
|
||||
Ym2612_Nuked_Impl* impl;
|
||||
double prev_sample_rate;
|
||||
double prev_clock_rate;
|
||||
public:
|
||||
Ym2612_Nuked_Emu();
|
||||
~Ym2612_Nuked_Emu();
|
||||
|
||||
// Set output sample rate and chip clock rates, in Hz. Returns non-zero
|
||||
// if error.
|
||||
const char* set_rate( double sample_rate, double clock_rate );
|
||||
|
||||
// Reset to power-up state
|
||||
void reset();
|
||||
|
||||
// Mute voice n if bit n (1 << n) of mask is set
|
||||
enum { channel_count = 6 };
|
||||
void mute_voices( int mask );
|
||||
|
||||
// Write addr to register 0 then data to register 1
|
||||
void write0( int addr, int data );
|
||||
|
||||
// Write addr to register 2 then data to register 3
|
||||
void write1( int addr, int data );
|
||||
|
||||
// Run and add pair_count samples into current output buffer contents
|
||||
typedef short sample_t;
|
||||
enum { out_chan_count = 2 }; // stereo
|
||||
void run( int pair_count, sample_t* out );
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -80,6 +80,9 @@ public:
|
||||
#define BLARGG_4CHAR( a, b, c, d ) \
|
||||
((a&0xFF)*0x1000000L + (b&0xFF)*0x10000L + (c&0xFF)*0x100L + (d&0xFF))
|
||||
|
||||
#define BLARGG_2CHAR( a, b ) \
|
||||
((a&0xFF)*0x100L + (b&0xFF))
|
||||
|
||||
// BOOST_STATIC_ASSERT( expr ): Generates compile error if expr is 0.
|
||||
#ifndef BOOST_STATIC_ASSERT
|
||||
#ifdef _MSC_VER
|
||||
@@ -132,51 +135,12 @@ public:
|
||||
typedef unsigned blargg_ulong;
|
||||
#endif
|
||||
|
||||
// BOOST::int8_t etc.
|
||||
// int8_t etc.
|
||||
|
||||
// HAVE_STDINT_H: If defined, use <stdint.h> for int8_t etc.
|
||||
#if defined (HAVE_STDINT_H)
|
||||
// TODO: Add CMake check for this, although I'd likely just point affected
|
||||
// persons to a real compiler...
|
||||
#if 1 || defined (HAVE_STDINT_H)
|
||||
#include <stdint.h>
|
||||
#define BOOST
|
||||
|
||||
// HAVE_INTTYPES_H: If defined, use <stdint.h> for int8_t etc.
|
||||
#elif defined (HAVE_INTTYPES_H)
|
||||
#include <inttypes.h>
|
||||
#define BOOST
|
||||
|
||||
#else
|
||||
struct BOOST
|
||||
{
|
||||
#if UCHAR_MAX == 0xFF && SCHAR_MAX == 0x7F
|
||||
typedef signed char int8_t;
|
||||
typedef unsigned char uint8_t;
|
||||
#else
|
||||
// No suitable 8-bit type available
|
||||
typedef struct see_blargg_common_h int8_t;
|
||||
typedef struct see_blargg_common_h uint8_t;
|
||||
#endif
|
||||
|
||||
#if USHRT_MAX == 0xFFFF
|
||||
typedef short int16_t;
|
||||
typedef unsigned short uint16_t;
|
||||
#else
|
||||
// No suitable 16-bit type available
|
||||
typedef struct see_blargg_common_h int16_t;
|
||||
typedef struct see_blargg_common_h uint16_t;
|
||||
#endif
|
||||
|
||||
#if ULONG_MAX == 0xFFFFFFFF
|
||||
typedef long int32_t;
|
||||
typedef unsigned long uint32_t;
|
||||
#elif UINT_MAX == 0xFFFFFFFF
|
||||
typedef int int32_t;
|
||||
typedef unsigned int uint32_t;
|
||||
#else
|
||||
// No suitable 32-bit type available
|
||||
typedef struct see_blargg_common_h int32_t;
|
||||
typedef struct see_blargg_common_h uint32_t;
|
||||
#endif
|
||||
};
|
||||
#endif
|
||||
|
||||
#if __GNUC__ >= 3
|
||||
|
||||
@@ -123,15 +123,15 @@ inline void set_be32( void* p, blargg_ulong n )
|
||||
#if BLARGG_NONPORTABLE
|
||||
// Optimized implementation if byte order is known
|
||||
#if BLARGG_LITTLE_ENDIAN
|
||||
#define GET_LE16( addr ) (*(BOOST::uint16_t*) (addr))
|
||||
#define GET_LE32( addr ) (*(BOOST::uint32_t*) (addr))
|
||||
#define SET_LE16( addr, data ) (void) (*(BOOST::uint16_t*) (addr) = (data))
|
||||
#define SET_LE32( addr, data ) (void) (*(BOOST::uint32_t*) (addr) = (data))
|
||||
#define GET_LE16( addr ) (*(uint16_t*) (addr))
|
||||
#define GET_LE32( addr ) (*(uint32_t*) (addr))
|
||||
#define SET_LE16( addr, data ) (void) (*(uint16_t*) (addr) = (data))
|
||||
#define SET_LE32( addr, data ) (void) (*(uint32_t*) (addr) = (data))
|
||||
#elif BLARGG_BIG_ENDIAN
|
||||
#define GET_BE16( addr ) (*(BOOST::uint16_t*) (addr))
|
||||
#define GET_BE32( addr ) (*(BOOST::uint32_t*) (addr))
|
||||
#define SET_BE16( addr, data ) (void) (*(BOOST::uint16_t*) (addr) = (data))
|
||||
#define SET_BE32( addr, data ) (void) (*(BOOST::uint32_t*) (addr) = (data))
|
||||
#define GET_BE16( addr ) (*(uint16_t*) (addr))
|
||||
#define GET_BE32( addr ) (*(uint32_t*) (addr))
|
||||
#define SET_BE16( addr, data ) (void) (*(uint16_t*) (addr) = (data))
|
||||
#define SET_BE32( addr, data ) (void) (*(uint32_t*) (addr) = (data))
|
||||
|
||||
#if BLARGG_CPU_POWERPC
|
||||
// PowerPC has special byte-reversed instructions
|
||||
@@ -172,13 +172,13 @@ inline void set_be32( void* p, blargg_ulong n )
|
||||
|
||||
// auto-selecting versions
|
||||
|
||||
inline void set_le( BOOST::uint16_t* p, unsigned n ) { SET_LE16( p, n ); }
|
||||
inline void set_le( BOOST::uint32_t* p, blargg_ulong n ) { SET_LE32( p, n ); }
|
||||
inline void set_be( BOOST::uint16_t* p, unsigned n ) { SET_BE16( p, n ); }
|
||||
inline void set_be( BOOST::uint32_t* p, blargg_ulong n ) { SET_BE32( p, n ); }
|
||||
inline unsigned get_le( BOOST::uint16_t* p ) { return GET_LE16( p ); }
|
||||
inline blargg_ulong get_le( BOOST::uint32_t* p ) { return GET_LE32( p ); }
|
||||
inline unsigned get_be( BOOST::uint16_t* p ) { return GET_BE16( p ); }
|
||||
inline blargg_ulong get_be( BOOST::uint32_t* p ) { return GET_BE32( p ); }
|
||||
inline void set_le( uint16_t* p, unsigned n ) { SET_LE16( p, n ); }
|
||||
inline void set_le( uint32_t* p, blargg_ulong n ) { SET_LE32( p, n ); }
|
||||
inline void set_be( uint16_t* p, unsigned n ) { SET_BE16( p, n ); }
|
||||
inline void set_be( uint32_t* p, blargg_ulong n ) { SET_BE32( p, n ); }
|
||||
inline unsigned get_le( uint16_t* p ) { return GET_LE16( p ); }
|
||||
inline blargg_ulong get_le( uint32_t* p ) { return GET_LE32( p ); }
|
||||
inline unsigned get_be( uint16_t* p ) { return GET_BE16( p ); }
|
||||
inline blargg_ulong get_be( uint32_t* p ) { return GET_BE32( p ); }
|
||||
|
||||
#endif
|
||||
@@ -1,26 +1,26 @@
|
||||
/* Included at the beginning of library source files, after all other #include lines.
|
||||
Sets up helpful macros and services used in my source code. They don't need
|
||||
module an annoying module prefix on their names since they are defined after
|
||||
all other #include lines. */
|
||||
* Sets up helpful macros and services used in my source code. They don't need
|
||||
* module an annoying module prefix on their names since they are defined after
|
||||
* all other #include lines. */
|
||||
|
||||
#ifndef BLARGG_SOURCE_H
|
||||
#define BLARGG_SOURCE_H
|
||||
|
||||
// If debugging is enabled, abort program if expr is false. Meant for checking
|
||||
// internal state and consistency. A failed assertion indicates a bug in the module.
|
||||
// void assert( bool expr );
|
||||
/* If debugging is enabled, abort program if expr is false. Meant for checking
|
||||
* internal state and consistency. A failed assertion indicates a bug in the module.
|
||||
* void assert( bool expr ); */
|
||||
#include <assert.h>
|
||||
|
||||
// If debugging is enabled and expr is false, abort program. Meant for checking
|
||||
// caller-supplied parameters and operations that are outside the control of the
|
||||
// module. A failed requirement indicates a bug outside the module.
|
||||
// void require( bool expr );
|
||||
/* If debugging is enabled and expr is false, abort program. Meant for checking
|
||||
* caller-supplied parameters and operations that are outside the control of the
|
||||
* module. A failed requirement indicates a bug outside the module.
|
||||
* void require( bool expr ); */
|
||||
#undef require
|
||||
#define require( expr ) assert( expr )
|
||||
|
||||
// Use to provide hints to compiler for optimized code layout in situations where we
|
||||
// can almost always expect a conditional to go one way or the other. Should only be
|
||||
// used in situations where an unexpected branch is truly exceptional though!
|
||||
/* Use to provide hints to compiler for optimized code layout in situations where we
|
||||
* can almost always expect a conditional to go one way or the other. Should only be
|
||||
* used in situations where an unexpected branch is truly exceptional though! */
|
||||
#undef likely
|
||||
#undef unlikely
|
||||
#ifdef __GNUC__
|
||||
@@ -31,91 +31,57 @@ all other #include lines. */
|
||||
#define unlikely( x ) (x)
|
||||
#endif
|
||||
|
||||
// Like printf() except output goes to debug log file. Might be defined to do
|
||||
// nothing (not even evaluate its arguments).
|
||||
// void debug_printf( const char* format, ... );
|
||||
static inline void blargg_dprintf_( const char*, ... ) { }
|
||||
#undef debug_printf
|
||||
#define debug_printf (1) ? (void) 0 : blargg_dprintf_
|
||||
/* Like printf() except output goes to debug log file. Might be defined to do
|
||||
* nothing (not even evaluate its arguments).
|
||||
* void debug_printf( const char* format, ... ); */
|
||||
#if defined(__cplusplus)
|
||||
static inline void blargg_dprintf_( const char* fmt_str, ... ) { (void) fmt_str; }
|
||||
#undef debug_printf
|
||||
#define debug_printf (1) ? (void) 0 : blargg_dprintf_
|
||||
#endif
|
||||
|
||||
// If enabled, evaluate expr and if false, make debug log entry with source file
|
||||
// and line. Meant for finding situations that should be examined further, but that
|
||||
// don't indicate a problem. In all cases, execution continues normally.
|
||||
/* If enabled, evaluate expr and if false, make debug log entry with source file
|
||||
* and line. Meant for finding situations that should be examined further, but that
|
||||
* don't indicate a problem. In all cases, execution continues normally. */
|
||||
#undef check
|
||||
#define check( expr ) ((void) 0)
|
||||
|
||||
// If expr yields error string, return it from current function, otherwise continue.
|
||||
/* If expr yields error string, return it from current function, otherwise continue. */
|
||||
#undef RETURN_ERR
|
||||
#define RETURN_ERR( expr ) do { \
|
||||
blargg_err_t blargg_return_err_ = (expr); \
|
||||
if ( blargg_return_err_ ) return blargg_return_err_; \
|
||||
} while ( 0 )
|
||||
|
||||
// If ptr is 0, return out of memory error string.
|
||||
/* If ptr is 0, return out of memory error string. */
|
||||
#undef CHECK_ALLOC
|
||||
#define CHECK_ALLOC( ptr ) do { if ( (ptr) == 0 ) return "Out of memory"; } while ( 0 )
|
||||
|
||||
// Avoid any macros which evaluate their arguments multiple times
|
||||
#undef min
|
||||
#undef max
|
||||
|
||||
#define DEF_MIN_MAX( type ) \
|
||||
static inline type min( type x, type y ) { if ( x < y ) return x; return y; }\
|
||||
static inline type max( type x, type y ) { if ( y < x ) return x; return y; }
|
||||
|
||||
DEF_MIN_MAX( int )
|
||||
DEF_MIN_MAX( unsigned )
|
||||
DEF_MIN_MAX( long )
|
||||
DEF_MIN_MAX( unsigned long )
|
||||
DEF_MIN_MAX( float )
|
||||
DEF_MIN_MAX( double )
|
||||
|
||||
#undef DEF_MIN_MAX
|
||||
|
||||
/*
|
||||
// using const references generates crappy code, and I am currenly only using these
|
||||
// for built-in types, so they take arguments by value
|
||||
|
||||
// TODO: remove
|
||||
inline int min( int x, int y )
|
||||
template<class T>
|
||||
inline T min( T x, T y )
|
||||
{
|
||||
if ( x < y )
|
||||
return x;
|
||||
return y;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
inline T max( T x, T y )
|
||||
{
|
||||
if ( x < y )
|
||||
return y;
|
||||
return x;
|
||||
}
|
||||
*/
|
||||
|
||||
// TODO: good idea? bad idea?
|
||||
/* TODO: good idea? bad idea? */
|
||||
#undef byte
|
||||
#define byte byte_
|
||||
typedef unsigned char byte;
|
||||
|
||||
// Setup compiler defines useful for exporting required public API symbols in gme.cpp
|
||||
/* Setup compiler defines useful for exporting required public API symbols in gme.cpp */
|
||||
#ifndef BLARGG_EXPORT
|
||||
#if defined (_WIN32) && defined(BLARGG_BUILD_DLL)
|
||||
#define BLARGG_EXPORT __declspec(dllexport)
|
||||
#elif defined (LIBGME_VISIBILITY)
|
||||
#if defined (_WIN32)
|
||||
#if defined(BLARGG_BUILD_DLL)
|
||||
#define BLARGG_EXPORT __declspec(dllexport)
|
||||
#else
|
||||
#define BLARGG_EXPORT /* Leave blank: friendly with both static and shared linking */
|
||||
#endif
|
||||
#elif defined (LIBGME_VISIBILITY) && defined(__cplusplus)
|
||||
#define BLARGG_EXPORT __attribute__((visibility ("default")))
|
||||
#else
|
||||
#define BLARGG_EXPORT
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// deprecated
|
||||
/* deprecated */
|
||||
#define BLARGG_CHECK_ALLOC CHECK_ALLOC
|
||||
#define BLARGG_RETURN_ERR RETURN_ERR
|
||||
|
||||
// BLARGG_SOURCE_BEGIN: If defined, #included, allowing redefition of debug_printf and check
|
||||
/* BLARGG_SOURCE_BEGIN: If defined, #included, allowing redefition of debug_printf and check */
|
||||
#ifdef BLARGG_SOURCE_BEGIN
|
||||
#include BLARGG_SOURCE_BEGIN
|
||||
#endif
|
||||
|
||||
+113
-71
@@ -1,4 +1,4 @@
|
||||
// Game_Music_Emu 0.6.0. http://www.slack.net/~ant/
|
||||
// Game_Music_Emu https://bitbucket.org/mpyne/game-music-emu/
|
||||
|
||||
#include "Music_Emu.h"
|
||||
|
||||
@@ -23,7 +23,7 @@ Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */
|
||||
|
||||
#include "blargg_source.h"
|
||||
|
||||
BLARGG_EXPORT gme_type_t const* gme_type_list()
|
||||
gme_type_t const* gme_type_list()
|
||||
{
|
||||
static gme_type_t const gme_type_list_ [] = {
|
||||
#ifdef GME_TYPE_LIST
|
||||
@@ -67,7 +67,7 @@ BLARGG_EXPORT gme_type_t const* gme_type_list()
|
||||
return gme_type_list_;
|
||||
}
|
||||
|
||||
BLARGG_EXPORT const char* gme_identify_header( void const* header )
|
||||
const char* gme_identify_header( void const* header )
|
||||
{
|
||||
switch ( get_be32( header ) )
|
||||
{
|
||||
@@ -83,6 +83,8 @@ BLARGG_EXPORT const char* gme_identify_header( void const* header )
|
||||
case BLARGG_4CHAR('S','N','E','S'): return "SPC";
|
||||
case BLARGG_4CHAR('V','g','m',' '): return "VGM";
|
||||
}
|
||||
if (get_be16(header) == BLARGG_2CHAR(0x1F, 0x8B))
|
||||
return "VGZ";
|
||||
return "";
|
||||
}
|
||||
|
||||
@@ -96,22 +98,30 @@ static void to_uppercase( const char* in, int len, char* out )
|
||||
*out = 0; // extension too long
|
||||
}
|
||||
|
||||
BLARGG_EXPORT gme_type_t gme_identify_extension( const char* extension_ )
|
||||
gme_type_t gme_identify_extension( const char* extension_ )
|
||||
{
|
||||
char const* end = strrchr( extension_, '.' );
|
||||
if ( end )
|
||||
extension_ = end + 1;
|
||||
|
||||
|
||||
char extension [6];
|
||||
to_uppercase( extension_, sizeof extension, extension );
|
||||
|
||||
|
||||
for ( gme_type_t const* types = gme_type_list(); *types; types++ )
|
||||
if ( !strcmp( extension, (*types)->extension_ ) )
|
||||
return *types;
|
||||
return 0;
|
||||
}
|
||||
|
||||
BLARGG_EXPORT gme_err_t gme_identify_file( const char* path, gme_type_t* type_out )
|
||||
const char *gme_type_extension( gme_type_t music_type )
|
||||
{
|
||||
const gme_type_t_ *const music_typeinfo = static_cast<const gme_type_t_ *>( music_type );
|
||||
if ( music_type )
|
||||
return music_typeinfo->extension_;
|
||||
return "";
|
||||
}
|
||||
|
||||
gme_err_t gme_identify_file( const char* path, gme_type_t* type_out )
|
||||
{
|
||||
*type_out = gme_identify_extension( path );
|
||||
// TODO: don't examine header if file has extension?
|
||||
@@ -123,44 +133,44 @@ BLARGG_EXPORT gme_err_t gme_identify_file( const char* path, gme_type_t* type_ou
|
||||
RETURN_ERR( in.read( header, sizeof header ) );
|
||||
*type_out = gme_identify_extension( gme_identify_header( header ) );
|
||||
}
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
BLARGG_EXPORT gme_err_t gme_open_data( void const* data, long size, Music_Emu** out, int sample_rate )
|
||||
gme_err_t gme_open_data( void const* data, long size, Music_Emu** out, int sample_rate )
|
||||
{
|
||||
require( (data || !size) && out );
|
||||
*out = 0;
|
||||
|
||||
|
||||
gme_type_t file_type = 0;
|
||||
if ( size >= 4 )
|
||||
file_type = gme_identify_extension( gme_identify_header( data ) );
|
||||
if ( !file_type )
|
||||
return gme_wrong_file_type;
|
||||
|
||||
|
||||
Music_Emu* emu = gme_new_emu( file_type, sample_rate );
|
||||
CHECK_ALLOC( emu );
|
||||
|
||||
|
||||
gme_err_t err = gme_load_data( emu, data, size );
|
||||
|
||||
|
||||
if ( err )
|
||||
delete emu;
|
||||
else
|
||||
*out = emu;
|
||||
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
BLARGG_EXPORT gme_err_t gme_open_file( const char* path, Music_Emu** out, int sample_rate )
|
||||
gme_err_t gme_open_file( const char* path, Music_Emu** out, int sample_rate )
|
||||
{
|
||||
require( path && out );
|
||||
*out = 0;
|
||||
|
||||
|
||||
GME_FILE_READER in;
|
||||
RETURN_ERR( in.open( path ) );
|
||||
|
||||
|
||||
char header [4];
|
||||
int header_size = 0;
|
||||
|
||||
|
||||
gme_type_t file_type = gme_identify_extension( path );
|
||||
if ( !file_type )
|
||||
{
|
||||
@@ -170,41 +180,61 @@ BLARGG_EXPORT gme_err_t gme_open_file( const char* path, Music_Emu** out, int sa
|
||||
}
|
||||
if ( !file_type )
|
||||
return gme_wrong_file_type;
|
||||
|
||||
|
||||
Music_Emu* emu = gme_new_emu( file_type, sample_rate );
|
||||
CHECK_ALLOC( emu );
|
||||
|
||||
|
||||
// optimization: avoids seeking/re-reading header
|
||||
Remaining_Reader rem( header, header_size, &in );
|
||||
gme_err_t err = emu->load( rem );
|
||||
in.close();
|
||||
|
||||
|
||||
if ( err )
|
||||
delete emu;
|
||||
else
|
||||
*out = emu;
|
||||
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
BLARGG_EXPORT Music_Emu* gme_new_emu( gme_type_t type, int rate )
|
||||
void gme_set_autoload_playback_limit( Music_Emu *emu, int do_autoload_limit )
|
||||
{
|
||||
emu->set_autoload_playback_limit( do_autoload_limit != 0 );
|
||||
}
|
||||
|
||||
int gme_autoload_playback_limit( Music_Emu *const emu )
|
||||
{
|
||||
return emu->autoload_playback_limit();
|
||||
}
|
||||
|
||||
// Used to implement gme_new_emu and gme_new_emu_multi_channel
|
||||
Music_Emu* gme_internal_new_emu_( gme_type_t type, int rate, bool multi_channel )
|
||||
{
|
||||
if ( type )
|
||||
{
|
||||
if ( rate == gme_info_only )
|
||||
return type->new_info();
|
||||
|
||||
|
||||
Music_Emu* me = type->new_emu();
|
||||
if ( me )
|
||||
{
|
||||
#if !GME_DISABLE_STEREO_DEPTH
|
||||
me->set_multi_channel( multi_channel );
|
||||
|
||||
if ( type->flags_ & 1 )
|
||||
{
|
||||
me->effects_buffer = BLARGG_NEW Effects_Buffer;
|
||||
if ( me->multi_channel() )
|
||||
{
|
||||
me->effects_buffer = BLARGG_NEW Effects_Buffer(8);
|
||||
}
|
||||
else
|
||||
{
|
||||
me->effects_buffer = BLARGG_NEW Effects_Buffer(1);
|
||||
}
|
||||
if ( me->effects_buffer )
|
||||
me->set_buffer( me->effects_buffer );
|
||||
}
|
||||
|
||||
|
||||
if ( !(type->flags_ & 1) || me->effects_buffer )
|
||||
#endif
|
||||
{
|
||||
@@ -220,55 +250,66 @@ BLARGG_EXPORT Music_Emu* gme_new_emu( gme_type_t type, int rate )
|
||||
return 0;
|
||||
}
|
||||
|
||||
BLARGG_EXPORT gme_err_t gme_load_file( Music_Emu* me, const char* path ) { return me->load_file( path ); }
|
||||
Music_Emu* gme_new_emu( gme_type_t type, int rate )
|
||||
{
|
||||
return gme_internal_new_emu_( type, rate, false /* no multichannel */);
|
||||
}
|
||||
|
||||
BLARGG_EXPORT gme_err_t gme_load_data( Music_Emu* me, void const* data, long size )
|
||||
Music_Emu* gme_new_emu_multi_channel( gme_type_t type, int rate )
|
||||
{
|
||||
// multi-channel emulator (if possible, not all emu types support multi-channel)
|
||||
return gme_internal_new_emu_( type, rate, true /* multichannel */);
|
||||
}
|
||||
|
||||
gme_err_t gme_load_file( Music_Emu* me, const char* path ) { return me->load_file( path ); }
|
||||
|
||||
gme_err_t gme_load_data( Music_Emu* me, void const* data, long size )
|
||||
{
|
||||
Mem_File_Reader in( data, size );
|
||||
return me->load( in );
|
||||
}
|
||||
|
||||
BLARGG_EXPORT gme_err_t gme_load_custom( Music_Emu* me, gme_reader_t func, long size, void* data )
|
||||
gme_err_t gme_load_custom( Music_Emu* me, gme_reader_t func, long size, void* data )
|
||||
{
|
||||
Callback_Reader in( func, size, data );
|
||||
return me->load( in );
|
||||
}
|
||||
|
||||
BLARGG_EXPORT void gme_delete( Music_Emu* me ) { delete me; }
|
||||
void gme_delete( Music_Emu* me ) { delete me; }
|
||||
|
||||
BLARGG_EXPORT gme_type_t gme_type( Music_Emu const* me ) { return me->type(); }
|
||||
gme_type_t gme_type( Music_Emu const* me ) { return me->type(); }
|
||||
|
||||
BLARGG_EXPORT const char* gme_warning( Music_Emu* me ) { return me->warning(); }
|
||||
const char* gme_warning( Music_Emu* me ) { return me->warning(); }
|
||||
|
||||
BLARGG_EXPORT int gme_track_count( Music_Emu const* me ) { return me->track_count(); }
|
||||
int gme_track_count( Music_Emu const* me ) { return me->track_count(); }
|
||||
|
||||
struct gme_info_t_ : gme_info_t
|
||||
{
|
||||
track_info_t info;
|
||||
|
||||
|
||||
BLARGG_DISABLE_NOTHROW
|
||||
};
|
||||
|
||||
BLARGG_EXPORT gme_err_t gme_track_info( Music_Emu const* me, gme_info_t** out, int track )
|
||||
gme_err_t gme_track_info( Music_Emu const* me, gme_info_t** out, int track )
|
||||
{
|
||||
*out = NULL;
|
||||
|
||||
|
||||
gme_info_t_* info = BLARGG_NEW gme_info_t_;
|
||||
CHECK_ALLOC( info );
|
||||
|
||||
|
||||
gme_err_t err = me->track_info( &info->info, track );
|
||||
if ( err )
|
||||
{
|
||||
gme_free_info( info );
|
||||
return err;
|
||||
}
|
||||
|
||||
|
||||
#define COPY(name) info->name = info->info.name;
|
||||
|
||||
|
||||
COPY( length );
|
||||
COPY( intro_length );
|
||||
COPY( loop_length );
|
||||
|
||||
|
||||
info->i4 = -1;
|
||||
info->i5 = -1;
|
||||
info->i6 = -1;
|
||||
@@ -281,7 +322,7 @@ BLARGG_EXPORT gme_err_t gme_track_info( Music_Emu const* me, gme_info_t** out, i
|
||||
info->i13 = -1;
|
||||
info->i14 = -1;
|
||||
info->i15 = -1;
|
||||
|
||||
|
||||
info->s7 = "";
|
||||
info->s8 = "";
|
||||
info->s9 = "";
|
||||
@@ -291,7 +332,7 @@ BLARGG_EXPORT gme_err_t gme_track_info( Music_Emu const* me, gme_info_t** out, i
|
||||
info->s13 = "";
|
||||
info->s14 = "";
|
||||
info->s15 = "";
|
||||
|
||||
|
||||
COPY( system );
|
||||
COPY( game );
|
||||
COPY( song );
|
||||
@@ -299,9 +340,9 @@ BLARGG_EXPORT gme_err_t gme_track_info( Music_Emu const* me, gme_info_t** out, i
|
||||
COPY( copyright );
|
||||
COPY( comment );
|
||||
COPY( dumper );
|
||||
|
||||
|
||||
#undef COPY
|
||||
|
||||
|
||||
info->play_length = info->length;
|
||||
if ( info->play_length <= 0 )
|
||||
{
|
||||
@@ -309,18 +350,18 @@ BLARGG_EXPORT gme_err_t gme_track_info( Music_Emu const* me, gme_info_t** out, i
|
||||
if ( info->play_length <= 0 )
|
||||
info->play_length = 150 * 1000; // 2.5 minutes
|
||||
}
|
||||
|
||||
|
||||
*out = info;
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
BLARGG_EXPORT void gme_free_info( gme_info_t* info )
|
||||
void gme_free_info( gme_info_t* info )
|
||||
{
|
||||
delete STATIC_CAST(gme_info_t_*,info);
|
||||
}
|
||||
|
||||
BLARGG_EXPORT void gme_set_stereo_depth( Music_Emu* me, double depth )
|
||||
void gme_set_stereo_depth( Music_Emu* me, double depth )
|
||||
{
|
||||
#if !GME_DISABLE_STEREO_DEPTH
|
||||
if ( me->effects_buffer )
|
||||
@@ -328,28 +369,29 @@ BLARGG_EXPORT void gme_set_stereo_depth( Music_Emu* me, double depth )
|
||||
#endif
|
||||
}
|
||||
|
||||
BLARGG_EXPORT void* gme_user_data ( Music_Emu const* me ) { return me->user_data(); }
|
||||
BLARGG_EXPORT void gme_set_user_data ( Music_Emu* me, void* new_user_data ) { me->set_user_data( new_user_data ); }
|
||||
BLARGG_EXPORT void gme_set_user_cleanup(Music_Emu* me, gme_user_cleanup_t func ) { me->set_user_cleanup( func ); }
|
||||
void* gme_user_data ( Music_Emu const* me ) { return me->user_data(); }
|
||||
void gme_set_user_data ( Music_Emu* me, void* new_user_data ) { me->set_user_data( new_user_data ); }
|
||||
void gme_set_user_cleanup(Music_Emu* me, gme_user_cleanup_t func ) { me->set_user_cleanup( func ); }
|
||||
|
||||
BLARGG_EXPORT gme_err_t gme_start_track ( Music_Emu* me, int index ) { return me->start_track( index ); }
|
||||
BLARGG_EXPORT gme_err_t gme_play ( Music_Emu* me, int n, short* p ) { return me->play( n, p ); }
|
||||
BLARGG_EXPORT void gme_set_fade ( Music_Emu* me, int start_msec ) { me->set_fade( start_msec ); }
|
||||
BLARGG_EXPORT int gme_track_ended ( Music_Emu const* me ) { return me->track_ended(); }
|
||||
BLARGG_EXPORT int gme_tell ( Music_Emu const* me ) { return me->tell(); }
|
||||
BLARGG_EXPORT int gme_tell_samples ( Music_Emu const* me ) { return me->tell_samples(); }
|
||||
BLARGG_EXPORT gme_err_t gme_seek ( Music_Emu* me, int msec ) { return me->seek( msec ); }
|
||||
BLARGG_EXPORT gme_err_t gme_seek_samples ( Music_Emu* me, int n ) { return me->seek_samples( n ); }
|
||||
BLARGG_EXPORT int gme_voice_count ( Music_Emu const* me ) { return me->voice_count(); }
|
||||
BLARGG_EXPORT void gme_ignore_silence ( Music_Emu* me, int disable ) { me->ignore_silence( disable != 0 ); }
|
||||
BLARGG_EXPORT void gme_set_tempo ( Music_Emu* me, double t ) { me->set_tempo( t ); }
|
||||
BLARGG_EXPORT void gme_mute_voice ( Music_Emu* me, int index, int mute ) { me->mute_voice( index, mute != 0 ); }
|
||||
BLARGG_EXPORT void gme_mute_voices ( Music_Emu* me, int mask ) { me->mute_voices( mask ); }
|
||||
BLARGG_EXPORT void gme_enable_accuracy( Music_Emu* me, int enabled ) { me->enable_accuracy( enabled ); }
|
||||
BLARGG_EXPORT void gme_clear_playlist ( Music_Emu* me ) { me->clear_playlist(); }
|
||||
BLARGG_EXPORT int gme_type_multitrack( gme_type_t t ) { return t->track_count != 1; }
|
||||
gme_err_t gme_start_track ( Music_Emu* me, int index ) { return me->start_track( index ); }
|
||||
gme_err_t gme_play ( Music_Emu* me, int n, short* p ) { return me->play( n, p ); }
|
||||
void gme_set_fade ( Music_Emu* me, int start_msec ) { me->set_fade( start_msec ); }
|
||||
int gme_track_ended ( Music_Emu const* me ) { return me->track_ended(); }
|
||||
int gme_tell ( Music_Emu const* me ) { return me->tell(); }
|
||||
int gme_tell_samples ( Music_Emu const* me ) { return me->tell_samples(); }
|
||||
gme_err_t gme_seek ( Music_Emu* me, int msec ) { return me->seek( msec ); }
|
||||
gme_err_t gme_seek_samples ( Music_Emu* me, int n ) { return me->seek_samples( n ); }
|
||||
int gme_voice_count ( Music_Emu const* me ) { return me->voice_count(); }
|
||||
void gme_ignore_silence ( Music_Emu* me, int disable ) { me->ignore_silence( disable != 0 ); }
|
||||
void gme_set_tempo ( Music_Emu* me, double t ) { me->set_tempo( t ); }
|
||||
void gme_mute_voice ( Music_Emu* me, int index, int mute ) { me->mute_voice( index, mute != 0 ); }
|
||||
void gme_mute_voices ( Music_Emu* me, int mask ) { me->mute_voices( mask ); }
|
||||
void gme_enable_accuracy( Music_Emu* me, int enabled ) { me->enable_accuracy( enabled ); }
|
||||
void gme_clear_playlist ( Music_Emu* me ) { me->clear_playlist(); }
|
||||
int gme_type_multitrack( gme_type_t t ) { return t->track_count != 1; }
|
||||
int gme_multi_channel ( Music_Emu const* me ) { return me->multi_channel(); }
|
||||
|
||||
BLARGG_EXPORT void gme_set_equalizer ( Music_Emu* me, gme_equalizer_t const* eq )
|
||||
void gme_set_equalizer ( Music_Emu* me, gme_equalizer_t const* eq )
|
||||
{
|
||||
Music_Emu::equalizer_t e = me->equalizer();
|
||||
e.treble = eq->treble;
|
||||
@@ -357,7 +399,7 @@ BLARGG_EXPORT void gme_set_equalizer ( Music_Emu* me, gme_equalizer_t cons
|
||||
me->set_equalizer( e );
|
||||
}
|
||||
|
||||
BLARGG_EXPORT void gme_equalizer( Music_Emu const* me, gme_equalizer_t* out )
|
||||
void gme_equalizer( Music_Emu const* me, gme_equalizer_t* out )
|
||||
{
|
||||
gme_equalizer_t e = gme_equalizer_t(); // Default-init all fields to 0.0f
|
||||
e.treble = me->equalizer().treble;
|
||||
@@ -365,13 +407,13 @@ BLARGG_EXPORT void gme_equalizer( Music_Emu const* me, gme_equalizer_t* out )
|
||||
*out = e;
|
||||
}
|
||||
|
||||
BLARGG_EXPORT const char* gme_voice_name( Music_Emu const* me, int i )
|
||||
const char* gme_voice_name( Music_Emu const* me, int i )
|
||||
{
|
||||
assert( (unsigned) i < (unsigned) me->voice_count() );
|
||||
return me->voice_names() [i];
|
||||
}
|
||||
|
||||
BLARGG_EXPORT const char* gme_type_system( gme_type_t type )
|
||||
const char* gme_type_system( gme_type_t type )
|
||||
{
|
||||
assert( type );
|
||||
return type->system;
|
||||
|
||||
+90
-49
@@ -1,14 +1,16 @@
|
||||
/* Game music emulator library C interface (also usable from C++) */
|
||||
|
||||
/* Game_Music_Emu 0.6.1 */
|
||||
/* Game_Music_Emu 0.6.3 */
|
||||
#ifndef GME_H
|
||||
#define GME_H
|
||||
|
||||
#include "blargg_source.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define GME_VERSION 0x000601 /* 1 byte major, 1 byte minor, 1 byte patch-level */
|
||||
#define GME_VERSION 0x000603 /* 1 byte major, 1 byte minor, 1 byte patch-level */
|
||||
|
||||
/* Error string returned by library functions, or NULL if no error (success) */
|
||||
typedef const char* gme_err_t;
|
||||
@@ -20,41 +22,60 @@ typedef struct Music_Emu Music_Emu;
|
||||
/******** Basic operations ********/
|
||||
|
||||
/* Create emulator and load game music file/data into it. Sets *out to new emulator. */
|
||||
gme_err_t gme_open_file( const char path [], Music_Emu** out, int sample_rate );
|
||||
BLARGG_EXPORT gme_err_t gme_open_file( const char path [], Music_Emu** out, int sample_rate );
|
||||
|
||||
/* Number of tracks available */
|
||||
int gme_track_count( Music_Emu const* );
|
||||
BLARGG_EXPORT int gme_track_count( Music_Emu const* );
|
||||
|
||||
/* Start a track, where 0 is the first track */
|
||||
gme_err_t gme_start_track( Music_Emu*, int index );
|
||||
BLARGG_EXPORT gme_err_t gme_start_track( Music_Emu*, int index );
|
||||
|
||||
/* Generate 'count' 16-bit signed samples info 'out'. Output is in stereo. */
|
||||
gme_err_t gme_play( Music_Emu*, int count, short out [] );
|
||||
BLARGG_EXPORT gme_err_t gme_play( Music_Emu*, int count, short out [] );
|
||||
|
||||
/* Finish using emulator and free memory */
|
||||
void gme_delete( Music_Emu* );
|
||||
BLARGG_EXPORT void gme_delete( Music_Emu* );
|
||||
|
||||
|
||||
/******** Track position/length ********/
|
||||
|
||||
/* Set time to start fading track out. Once fade ends track_ended() returns true.
|
||||
Fade time can be changed while track is playing. */
|
||||
void gme_set_fade( Music_Emu*, int start_msec );
|
||||
BLARGG_EXPORT void gme_set_fade( Music_Emu*, int start_msec );
|
||||
|
||||
/**
|
||||
* If do_autoload_limit is nonzero, then automatically load track length
|
||||
* metadata (if present) and terminate playback once the track length has been
|
||||
* reached. Otherwise playback will continue for an arbitrary period of time
|
||||
* until a prolonged period of silence is detected.
|
||||
*
|
||||
* Not all individual emulators support this setting.
|
||||
*
|
||||
* By default, playback limits are loaded and applied.
|
||||
*
|
||||
* @since 0.6.2
|
||||
*/
|
||||
BLARGG_EXPORT void gme_set_autoload_playback_limit( Music_Emu *, int do_autoload_limit );
|
||||
|
||||
/** See gme_set_autoload_playback_limit.
|
||||
* @since 0.6.2
|
||||
*/
|
||||
BLARGG_EXPORT int gme_autoload_playback_limit( Music_Emu const* );
|
||||
|
||||
/* True if a track has reached its end */
|
||||
int gme_track_ended( Music_Emu const* );
|
||||
BLARGG_EXPORT int gme_track_ended( Music_Emu const* );
|
||||
|
||||
/* Number of milliseconds (1000 = one second) played since beginning of track */
|
||||
int gme_tell( Music_Emu const* );
|
||||
BLARGG_EXPORT int gme_tell( Music_Emu const* );
|
||||
|
||||
/* Number of samples generated since beginning of track */
|
||||
int gme_tell_samples( Music_Emu const* );
|
||||
BLARGG_EXPORT int gme_tell_samples( Music_Emu const* );
|
||||
|
||||
/* Seek to new time in track. Seeking backwards or far forward can take a while. */
|
||||
gme_err_t gme_seek( Music_Emu*, int msec );
|
||||
BLARGG_EXPORT gme_err_t gme_seek( Music_Emu*, int msec );
|
||||
|
||||
/* Equivalent to restarting track then skipping n samples */
|
||||
gme_err_t gme_seek_samples( Music_Emu*, int n );
|
||||
BLARGG_EXPORT gme_err_t gme_seek_samples( Music_Emu*, int n );
|
||||
|
||||
|
||||
/******** Informational ********/
|
||||
@@ -65,24 +86,24 @@ enum { gme_info_only = -1 };
|
||||
|
||||
/* Most recent warning string, or NULL if none. Clears current warning after returning.
|
||||
Warning is also cleared when loading a file and starting a track. */
|
||||
const char* gme_warning( Music_Emu* );
|
||||
BLARGG_EXPORT const char* gme_warning( Music_Emu* );
|
||||
|
||||
/* Load m3u playlist file (must be done after loading music) */
|
||||
gme_err_t gme_load_m3u( Music_Emu*, const char path [] );
|
||||
BLARGG_EXPORT gme_err_t gme_load_m3u( Music_Emu*, const char path [] );
|
||||
|
||||
/* Clear any loaded m3u playlist and any internal playlist that the music format
|
||||
supports (NSFE for example). */
|
||||
void gme_clear_playlist( Music_Emu* );
|
||||
BLARGG_EXPORT void gme_clear_playlist( Music_Emu* );
|
||||
|
||||
/* Gets information for a particular track (length, name, author, etc.).
|
||||
Must be freed after use. */
|
||||
typedef struct gme_info_t gme_info_t;
|
||||
gme_err_t gme_track_info( Music_Emu const*, gme_info_t** out, int track );
|
||||
BLARGG_EXPORT gme_err_t gme_track_info( Music_Emu const*, gme_info_t** out, int track );
|
||||
|
||||
/* Frees track information */
|
||||
void gme_free_info( gme_info_t* );
|
||||
BLARGG_EXPORT void gme_free_info( gme_info_t* );
|
||||
|
||||
struct gme_info_t
|
||||
struct BLARGG_EXPORT gme_info_t
|
||||
{
|
||||
/* times in milliseconds; -1 if unknown */
|
||||
int length; /* total length, if file specifies it */
|
||||
@@ -112,32 +133,32 @@ struct gme_info_t
|
||||
|
||||
/* Adjust stereo echo depth, where 0.0 = off and 1.0 = maximum. Has no effect for
|
||||
GYM, SPC, and Sega Genesis VGM music */
|
||||
void gme_set_stereo_depth( Music_Emu*, double depth );
|
||||
BLARGG_EXPORT void gme_set_stereo_depth( Music_Emu*, double depth );
|
||||
|
||||
/* Disable automatic end-of-track detection and skipping of silence at beginning
|
||||
if ignore is true */
|
||||
void gme_ignore_silence( Music_Emu*, int ignore );
|
||||
BLARGG_EXPORT void gme_ignore_silence( Music_Emu*, int ignore );
|
||||
|
||||
/* Adjust song tempo, where 1.0 = normal, 0.5 = half speed, 2.0 = double speed.
|
||||
Track length as returned by track_info() assumes a tempo of 1.0. */
|
||||
void gme_set_tempo( Music_Emu*, double tempo );
|
||||
BLARGG_EXPORT void gme_set_tempo( Music_Emu*, double tempo );
|
||||
|
||||
/* Number of voices used by currently loaded file */
|
||||
int gme_voice_count( Music_Emu const* );
|
||||
BLARGG_EXPORT int gme_voice_count( Music_Emu const* );
|
||||
|
||||
/* Name of voice i, from 0 to gme_voice_count() - 1 */
|
||||
const char* gme_voice_name( Music_Emu const*, int i );
|
||||
BLARGG_EXPORT const char* gme_voice_name( Music_Emu const*, int i );
|
||||
|
||||
/* Mute/unmute voice i, where voice 0 is first voice */
|
||||
void gme_mute_voice( Music_Emu*, int index, int mute );
|
||||
BLARGG_EXPORT void gme_mute_voice( Music_Emu*, int index, int mute );
|
||||
|
||||
/* Set muting state of all voices at once using a bit mask, where -1 mutes all
|
||||
voices, 0 unmutes them all, 0x01 mutes just the first voice, etc. */
|
||||
void gme_mute_voices( Music_Emu*, int muting_mask );
|
||||
BLARGG_EXPORT void gme_mute_voices( Music_Emu*, int muting_mask );
|
||||
|
||||
/* Frequency equalizer parameters (see gme.txt) */
|
||||
/* Implementers: If modified, also adjust Music_Emu::make_equalizer as needed */
|
||||
typedef struct gme_equalizer_t
|
||||
typedef struct BLARGG_EXPORT gme_equalizer_t
|
||||
{
|
||||
double treble; /* -50.0 = muffled, 0 = flat, +5.0 = extra-crisp */
|
||||
double bass; /* 1 = full bass, 90 = average, 16000 = almost no bass */
|
||||
@@ -146,13 +167,13 @@ typedef struct gme_equalizer_t
|
||||
} gme_equalizer_t;
|
||||
|
||||
/* Get current frequency equalizater parameters */
|
||||
void gme_equalizer( Music_Emu const*, gme_equalizer_t* out );
|
||||
BLARGG_EXPORT void gme_equalizer( Music_Emu const*, gme_equalizer_t* out );
|
||||
|
||||
/* Change frequency equalizer parameters */
|
||||
void gme_set_equalizer( Music_Emu*, gme_equalizer_t const* eq );
|
||||
BLARGG_EXPORT void gme_set_equalizer( Music_Emu*, gme_equalizer_t const* eq );
|
||||
|
||||
/* Enables/disables most accurate sound emulation options */
|
||||
void gme_enable_accuracy( Music_Emu*, int enabled );
|
||||
BLARGG_EXPORT void gme_enable_accuracy( Music_Emu*, int enabled );
|
||||
|
||||
|
||||
/******** Game music types ********/
|
||||
@@ -161,7 +182,7 @@ void gme_enable_accuracy( Music_Emu*, int enabled );
|
||||
typedef const struct gme_type_t_* gme_type_t;
|
||||
|
||||
/* Emulator type constants for each supported file type */
|
||||
extern const gme_type_t
|
||||
extern BLARGG_EXPORT const gme_type_t
|
||||
gme_ay_type,
|
||||
gme_gbs_type,
|
||||
gme_gym_type,
|
||||
@@ -175,69 +196,89 @@ extern const gme_type_t
|
||||
gme_vgz_type;
|
||||
|
||||
/* Type of this emulator */
|
||||
gme_type_t gme_type( Music_Emu const* );
|
||||
BLARGG_EXPORT gme_type_t gme_type( Music_Emu const* );
|
||||
|
||||
/* Pointer to array of all music types, with NULL entry at end. Allows a player linked
|
||||
to this library to support new music types without having to be updated. */
|
||||
gme_type_t const* gme_type_list();
|
||||
BLARGG_EXPORT gme_type_t const* gme_type_list();
|
||||
|
||||
/* Name of game system for this music file type */
|
||||
const char* gme_type_system( gme_type_t );
|
||||
BLARGG_EXPORT const char* gme_type_system( gme_type_t );
|
||||
|
||||
/* True if this music file type supports multiple tracks */
|
||||
int gme_type_multitrack( gme_type_t );
|
||||
BLARGG_EXPORT int gme_type_multitrack( gme_type_t );
|
||||
|
||||
/* whether the pcm output retrieved by gme_play() will have all 8 voices rendered to their
|
||||
* individual stereo channel or (if false) these voices get mixed into one single stereo channel
|
||||
* @since 0.6.2 */
|
||||
BLARGG_EXPORT int gme_multi_channel( Music_Emu const* );
|
||||
|
||||
/******** Advanced file loading ********/
|
||||
|
||||
/* Error returned if file type is not supported */
|
||||
extern const char* const gme_wrong_file_type;
|
||||
extern BLARGG_EXPORT const char* const gme_wrong_file_type;
|
||||
|
||||
/* Same as gme_open_file(), but uses file data already in memory. Makes copy of data. */
|
||||
gme_err_t gme_open_data( void const* data, long size, Music_Emu** out, int sample_rate );
|
||||
/* Same as gme_open_file(), but uses file data already in memory. Makes copy of data.
|
||||
* The resulting Music_Emu object will be set to single channel mode. */
|
||||
BLARGG_EXPORT gme_err_t gme_open_data( void const* data, long size, Music_Emu** out, int sample_rate );
|
||||
|
||||
/* Determine likely game music type based on first four bytes of file. Returns
|
||||
string containing proper file suffix (i.e. "NSF", "SPC", etc.) or "" if
|
||||
file header is not recognized. */
|
||||
const char* gme_identify_header( void const* header );
|
||||
BLARGG_EXPORT const char* gme_identify_header( void const* header );
|
||||
|
||||
/* Get corresponding music type for file path or extension passed in. */
|
||||
gme_type_t gme_identify_extension( const char path_or_extension [] );
|
||||
BLARGG_EXPORT gme_type_t gme_identify_extension( const char path_or_extension [] );
|
||||
|
||||
/**
|
||||
* Get typical file extension for a given music type. This is not a replacement
|
||||
* for a file content identification library (but see gme_identify_header).
|
||||
*
|
||||
* @since 0.6.2
|
||||
*/
|
||||
BLARGG_EXPORT const char* gme_type_extension( gme_type_t music_type );
|
||||
|
||||
/* Determine file type based on file's extension or header (if extension isn't recognized).
|
||||
Sets *type_out to type, or 0 if unrecognized or error. */
|
||||
gme_err_t gme_identify_file( const char path [], gme_type_t* type_out );
|
||||
BLARGG_EXPORT gme_err_t gme_identify_file( const char path [], gme_type_t* type_out );
|
||||
|
||||
/* Create new emulator and set sample rate. Returns NULL if out of memory. If you only need
|
||||
track information, pass gme_info_only for sample_rate. */
|
||||
Music_Emu* gme_new_emu( gme_type_t, int sample_rate );
|
||||
BLARGG_EXPORT Music_Emu* gme_new_emu( gme_type_t, int sample_rate );
|
||||
|
||||
/* Create new multichannel emulator and set sample rate. Returns NULL if out of memory.
|
||||
* If you only need track information, pass gme_info_only for sample_rate.
|
||||
* (see gme_multi_channel for more information on multichannel support)
|
||||
* @since 0.6.2
|
||||
*/
|
||||
BLARGG_EXPORT Music_Emu* gme_new_emu_multi_channel( gme_type_t, int sample_rate );
|
||||
|
||||
/* Load music file into emulator */
|
||||
gme_err_t gme_load_file( Music_Emu*, const char path [] );
|
||||
BLARGG_EXPORT gme_err_t gme_load_file( Music_Emu*, const char path [] );
|
||||
|
||||
/* Load music file from memory into emulator. Makes a copy of data passed. */
|
||||
gme_err_t gme_load_data( Music_Emu*, void const* data, long size );
|
||||
BLARGG_EXPORT gme_err_t gme_load_data( Music_Emu*, void const* data, long size );
|
||||
|
||||
/* Load music file using custom data reader function that will be called to
|
||||
read file data. Most emulators load the entire file in one read call. */
|
||||
typedef gme_err_t (*gme_reader_t)( void* your_data, void* out, int count );
|
||||
gme_err_t gme_load_custom( Music_Emu*, gme_reader_t, long file_size, void* your_data );
|
||||
BLARGG_EXPORT gme_err_t gme_load_custom( Music_Emu*, gme_reader_t, long file_size, void* your_data );
|
||||
|
||||
/* Load m3u playlist file from memory (must be done after loading music) */
|
||||
gme_err_t gme_load_m3u_data( Music_Emu*, void const* data, long size );
|
||||
BLARGG_EXPORT gme_err_t gme_load_m3u_data( Music_Emu*, void const* data, long size );
|
||||
|
||||
|
||||
/******** User data ********/
|
||||
|
||||
/* Set/get pointer to data you want to associate with this emulator.
|
||||
You can use this for whatever you want. */
|
||||
void gme_set_user_data( Music_Emu*, void* new_user_data );
|
||||
void* gme_user_data( Music_Emu const* );
|
||||
BLARGG_EXPORT void gme_set_user_data( Music_Emu*, void* new_user_data );
|
||||
BLARGG_EXPORT void* gme_user_data( Music_Emu const* );
|
||||
|
||||
/* Register cleanup function to be called when deleting emulator, or NULL to
|
||||
clear it. Passes user_data to cleanup function. */
|
||||
typedef void (*gme_user_cleanup_t)( void* user_data );
|
||||
void gme_set_user_cleanup( Music_Emu*, gme_user_cleanup_t func );
|
||||
BLARGG_EXPORT void gme_set_user_cleanup( Music_Emu*, gme_user_cleanup_t func );
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
Loaded 100 of 116 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user