Minor fixes to Game_Music_Emu
parent
5c0cf35a1a
commit
0ee11cb9a1
|
@ -1,92 +0,0 @@
|
|||
// Z80 CPU emulator
|
||||
|
||||
// Game_Music_Emu 0.5.2
|
||||
#ifndef AY_CPU_H
|
||||
#define AY_CPU_H
|
||||
|
||||
#include "blargg_endian.h"
|
||||
|
||||
typedef blargg_long cpu_time_t;
|
||||
|
||||
// must be defined by caller
|
||||
void ay_cpu_out( class Ay_Cpu*, cpu_time_t, unsigned addr, int data );
|
||||
int ay_cpu_in( class Ay_Cpu*, unsigned addr );
|
||||
|
||||
class Ay_Cpu {
|
||||
public:
|
||||
// Clear all registers and keep pointer to 64K memory passed in
|
||||
void reset( void* mem_64k );
|
||||
|
||||
// Run until specified time is reached. Returns true if suspicious/unsupported
|
||||
// instruction was encountered at any point during run.
|
||||
bool run( cpu_time_t end_time );
|
||||
|
||||
// Time of beginning of next instruction
|
||||
cpu_time_t time() const { return state->time + state->base; }
|
||||
|
||||
// Alter current time. Not supported during run() call.
|
||||
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
|
||||
struct regs_t { uint8_t c, b, e, d, l, h, a, flags; };
|
||||
#endif
|
||||
BOOST_STATIC_ASSERT( sizeof (regs_t) == 8 );
|
||||
|
||||
struct pairs_t { uint16_t bc, de, hl, fa; };
|
||||
|
||||
// Registers are not updated until run() returns
|
||||
struct registers_t {
|
||||
uint16_t pc;
|
||||
uint16_t sp;
|
||||
uint16_t ix;
|
||||
uint16_t iy;
|
||||
union {
|
||||
regs_t b; // b.b, b.c, b.d, b.e, b.h, b.l, b.flags, b.a
|
||||
pairs_t w; // w.bc, w.de, w.hl. w.fa
|
||||
};
|
||||
union {
|
||||
regs_t b;
|
||||
pairs_t w;
|
||||
} alt;
|
||||
uint8_t iff1;
|
||||
uint8_t iff2;
|
||||
uint8_t r;
|
||||
uint8_t i;
|
||||
uint8_t im;
|
||||
};
|
||||
//registers_t r; (below for efficiency)
|
||||
|
||||
// can read this far past end of memory
|
||||
enum { cpu_padding = 0x100 };
|
||||
|
||||
public:
|
||||
Ay_Cpu();
|
||||
private:
|
||||
uint8_t szpc [0x200];
|
||||
uint8_t* mem;
|
||||
cpu_time_t end_time_;
|
||||
struct state_t {
|
||||
cpu_time_t base;
|
||||
cpu_time_t time;
|
||||
};
|
||||
state_t* state; // points to state_ or a local copy within run()
|
||||
state_t state_;
|
||||
void set_end_time( cpu_time_t t );
|
||||
public:
|
||||
registers_t r;
|
||||
};
|
||||
|
||||
inline void Ay_Cpu::set_end_time( cpu_time_t t )
|
||||
{
|
||||
cpu_time_t delta = state->base - t;
|
||||
state->base = t;
|
||||
state->time += delta;
|
||||
}
|
||||
|
||||
#endif
|
|
@ -1,124 +0,0 @@
|
|||
// Z80 CPU emulator
|
||||
|
||||
// Game_Music_Emu 0.5.2
|
||||
#ifndef KSS_CPU_H
|
||||
#define KSS_CPU_H
|
||||
|
||||
#include "blargg_endian.h"
|
||||
|
||||
typedef blargg_long cpu_time_t;
|
||||
|
||||
// must be defined by caller
|
||||
void kss_cpu_out( class Kss_Cpu*, cpu_time_t, unsigned addr, int data );
|
||||
int kss_cpu_in( class Kss_Cpu*, cpu_time_t, unsigned addr );
|
||||
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 );
|
||||
|
||||
// Map memory. Start and size must be multiple of page_size.
|
||||
enum { page_size = 0x2000 };
|
||||
void map_mem( unsigned addr, blargg_ulong size, void* write, void const* read );
|
||||
|
||||
// Map address to page
|
||||
uint8_t* write( unsigned addr );
|
||||
uint8_t const* read( unsigned addr );
|
||||
|
||||
// Run until specified time is reached. Returns true if suspicious/unsupported
|
||||
// instruction was encountered at any point during run.
|
||||
bool run( cpu_time_t end_time );
|
||||
|
||||
// Time of beginning of next instruction
|
||||
cpu_time_t time() const { return state->time + state->base; }
|
||||
|
||||
// Alter current time. Not supported during run() call.
|
||||
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
|
||||
struct regs_t { uint8_t c, b, e, d, l, h, a, flags; };
|
||||
#endif
|
||||
BOOST_STATIC_ASSERT( sizeof (regs_t) == 8 );
|
||||
|
||||
struct pairs_t { uint16_t bc, de, hl, fa; };
|
||||
|
||||
// Registers are not updated until run() returns
|
||||
struct registers_t {
|
||||
uint16_t pc;
|
||||
uint16_t sp;
|
||||
uint16_t ix;
|
||||
uint16_t iy;
|
||||
union {
|
||||
regs_t b; // b.b, b.c, b.d, b.e, b.h, b.l, b.flags, b.a
|
||||
pairs_t w; // w.bc, w.de, w.hl. w.fa
|
||||
};
|
||||
union {
|
||||
regs_t b;
|
||||
pairs_t w;
|
||||
} alt;
|
||||
uint8_t iff1;
|
||||
uint8_t iff2;
|
||||
uint8_t r;
|
||||
uint8_t i;
|
||||
uint8_t im;
|
||||
};
|
||||
//registers_t r; (below for efficiency)
|
||||
|
||||
enum { idle_addr = 0xFFFF };
|
||||
|
||||
// can read this far past end of a page
|
||||
enum { cpu_padding = 0x100 };
|
||||
|
||||
public:
|
||||
Kss_Cpu();
|
||||
enum { page_shift = 13 };
|
||||
enum { page_count = 0x10000 >> page_shift };
|
||||
private:
|
||||
uint8_t szpc [0x200];
|
||||
cpu_time_t end_time_;
|
||||
struct state_t {
|
||||
uint8_t const* read [page_count + 1];
|
||||
uint8_t * write [page_count + 1];
|
||||
cpu_time_t base;
|
||||
cpu_time_t time;
|
||||
};
|
||||
state_t* state; // points to state_ or a local copy within run()
|
||||
state_t state_;
|
||||
void set_end_time( cpu_time_t t );
|
||||
void set_page( int i, void* write, void const* read );
|
||||
public:
|
||||
registers_t r;
|
||||
};
|
||||
|
||||
#if BLARGG_NONPORTABLE
|
||||
#define KSS_CPU_PAGE_OFFSET( addr ) (addr)
|
||||
#else
|
||||
#define KSS_CPU_PAGE_OFFSET( addr ) ((addr) & (page_size - 1))
|
||||
#endif
|
||||
|
||||
inline BOOST::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 )
|
||||
{
|
||||
return state->read [addr >> page_shift] + KSS_CPU_PAGE_OFFSET( addr );
|
||||
}
|
||||
|
||||
inline void Kss_Cpu::set_end_time( cpu_time_t t )
|
||||
{
|
||||
cpu_time_t delta = state->base - t;
|
||||
state->base = t;
|
||||
state->time += delta;
|
||||
}
|
||||
|
||||
#endif
|
|
@ -1,83 +0,0 @@
|
|||
// Atari 6502 CPU emulator
|
||||
|
||||
// Game_Music_Emu 0.5.2
|
||||
#ifndef SAP_CPU_H
|
||||
#define SAP_CPU_H
|
||||
|
||||
#include "blargg_common.h"
|
||||
|
||||
typedef blargg_long sap_time_t; // clock cycle count
|
||||
typedef unsigned sap_addr_t; // 16-bit address
|
||||
enum { future_sap_time = LONG_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 );
|
||||
|
||||
// Run until specified time is reached. Returns true if suspicious/unsupported
|
||||
// instruction was encountered at any point during run.
|
||||
bool run( sap_time_t end_time );
|
||||
|
||||
// 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;
|
||||
};
|
||||
registers_t r;
|
||||
|
||||
enum { idle_addr = 0xFEFF };
|
||||
|
||||
// Time of beginning of next instruction to be executed
|
||||
sap_time_t time() const { return state->time + state->base; }
|
||||
void set_time( sap_time_t t ) { state->time = t - state->base; }
|
||||
void adjust_time( int delta ) { state->time += delta; }
|
||||
|
||||
sap_time_t irq_time() const { return irq_time_; }
|
||||
void set_irq_time( sap_time_t );
|
||||
|
||||
sap_time_t end_time() const { return end_time_; }
|
||||
void set_end_time( sap_time_t );
|
||||
|
||||
public:
|
||||
Sap_Cpu() { state = &state_; }
|
||||
enum { irq_inhibit = 0x04 };
|
||||
private:
|
||||
struct state_t {
|
||||
sap_time_t base;
|
||||
sap_time_t time;
|
||||
};
|
||||
state_t* state; // points to state_ or a local copy within run()
|
||||
state_t state_;
|
||||
sap_time_t irq_time_;
|
||||
sap_time_t end_time_;
|
||||
uint8_t* mem;
|
||||
|
||||
inline sap_time_t update_end_time( sap_time_t end, sap_time_t irq );
|
||||
};
|
||||
|
||||
inline sap_time_t Sap_Cpu::update_end_time( sap_time_t t, sap_time_t irq )
|
||||
{
|
||||
if ( irq < t && !(r.status & irq_inhibit) ) t = irq;
|
||||
sap_time_t delta = state->base - t;
|
||||
state->base = t;
|
||||
return delta;
|
||||
}
|
||||
|
||||
inline void Sap_Cpu::set_irq_time( sap_time_t t )
|
||||
{
|
||||
state->time += update_end_time( end_time_, (irq_time_ = t) );
|
||||
}
|
||||
|
||||
inline void Sap_Cpu::set_end_time( sap_time_t t )
|
||||
{
|
||||
state->time += update_end_time( (end_time_ = t), irq_time_ );
|
||||
}
|
||||
|
||||
#endif
|
|
@ -1,48 +0,0 @@
|
|||
// Private oscillators used by Sms_Apu
|
||||
|
||||
// Sms_Snd_Emu 0.1.4
|
||||
#ifndef SMS_OSCS_H
|
||||
#define SMS_OSCS_H
|
||||
|
||||
#include "Blip_Buffer.h"
|
||||
|
||||
struct Sms_Osc
|
||||
{
|
||||
Blip_Buffer* outputs [4]; // NULL, right, left, center
|
||||
Blip_Buffer* output;
|
||||
int output_select;
|
||||
|
||||
int delay;
|
||||
int last_amp;
|
||||
int volume;
|
||||
|
||||
Sms_Osc();
|
||||
void reset();
|
||||
};
|
||||
|
||||
struct Sms_Square : Sms_Osc
|
||||
{
|
||||
int period;
|
||||
int phase;
|
||||
|
||||
typedef Blip_Synth<blip_good_quality,1> Synth;
|
||||
const Synth* synth;
|
||||
|
||||
void reset();
|
||||
void run( blip_time_t, blip_time_t );
|
||||
};
|
||||
|
||||
struct Sms_Noise : Sms_Osc
|
||||
{
|
||||
const int* period;
|
||||
unsigned shifter;
|
||||
unsigned feedback;
|
||||
|
||||
typedef Blip_Synth<blip_med_quality,1> Synth;
|
||||
Synth synth;
|
||||
|
||||
void reset();
|
||||
void run( blip_time_t, blip_time_t );
|
||||
};
|
||||
|
||||
#endif
|
|
@ -1,314 +0,0 @@
|
|||
// Game_Music_Emu 0.5.2. http://www.slack.net/~ant/
|
||||
|
||||
#include "Vgm_Emu.h"
|
||||
|
||||
#include <math.h>
|
||||
#include <string.h>
|
||||
#include "blargg_endian.h"
|
||||
|
||||
/* 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
|
||||
General Public License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version. This
|
||||
module is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
|
||||
details. You should have received a copy of the GNU Lesser General Public
|
||||
License along with this module; if not, write to the Free Software Foundation,
|
||||
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */
|
||||
|
||||
#include "blargg_source.h"
|
||||
|
||||
enum {
|
||||
cmd_gg_stereo = 0x4F,
|
||||
cmd_psg = 0x50,
|
||||
cmd_ym2413 = 0x51,
|
||||
cmd_ym2612_port0 = 0x52,
|
||||
cmd_ym2612_port1 = 0x53,
|
||||
cmd_ym2151 = 0x54,
|
||||
cmd_delay = 0x61,
|
||||
cmd_delay_735 = 0x62,
|
||||
cmd_delay_882 = 0x63,
|
||||
cmd_byte_delay = 0x64,
|
||||
cmd_end = 0x66,
|
||||
cmd_data_block = 0x67,
|
||||
cmd_short_delay = 0x70,
|
||||
cmd_pcm_delay = 0x80,
|
||||
cmd_pcm_seek = 0xE0,
|
||||
|
||||
pcm_block_type = 0x00,
|
||||
ym2612_dac_port = 0x2A
|
||||
};
|
||||
|
||||
inline int command_len( int command )
|
||||
{
|
||||
switch ( command >> 4 )
|
||||
{
|
||||
case 0x03:
|
||||
case 0x04:
|
||||
return 2;
|
||||
|
||||
case 0x05:
|
||||
case 0x0A:
|
||||
case 0x0B:
|
||||
return 3;
|
||||
|
||||
case 0x0C:
|
||||
case 0x0D:
|
||||
return 4;
|
||||
|
||||
case 0x0E:
|
||||
case 0x0F:
|
||||
return 5;
|
||||
}
|
||||
|
||||
check( false );
|
||||
return 1;
|
||||
}
|
||||
|
||||
template<class Emu>
|
||||
inline void Ym_Emu<Emu>::begin_frame( short* p )
|
||||
{
|
||||
require( enabled() );
|
||||
out = p;
|
||||
last_time = 0;
|
||||
}
|
||||
|
||||
template<class Emu>
|
||||
inline int Ym_Emu<Emu>::run_until( int time )
|
||||
{
|
||||
int count = time - last_time;
|
||||
if ( count > 0 )
|
||||
{
|
||||
if ( last_time < 0 )
|
||||
return false;
|
||||
last_time = time;
|
||||
short* p = out;
|
||||
out += count * Emu::out_chan_count;
|
||||
Emu::run( count, p );
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
inline Vgm_Emu_Impl::fm_time_t Vgm_Emu_Impl::to_fm_time( vgm_time_t t ) const
|
||||
{
|
||||
return (t * fm_time_factor + fm_time_offset) >> fm_time_bits;
|
||||
}
|
||||
|
||||
inline blip_time_t Vgm_Emu_Impl::to_blip_time( vgm_time_t t ) const
|
||||
{
|
||||
return (t * blip_time_factor) >> blip_time_bits;
|
||||
}
|
||||
|
||||
void Vgm_Emu_Impl::write_pcm( vgm_time_t vgm_time, int amp )
|
||||
{
|
||||
blip_time_t blip_time = to_blip_time( vgm_time );
|
||||
int old = dac_amp;
|
||||
int delta = amp - old;
|
||||
dac_amp = amp;
|
||||
if ( old >= 0 )
|
||||
dac_synth.offset_inline( blip_time, delta, &blip_buf );
|
||||
else
|
||||
dac_amp |= dac_disabled;
|
||||
}
|
||||
|
||||
blip_time_t Vgm_Emu_Impl::run_commands( vgm_time_t end_time )
|
||||
{
|
||||
vgm_time_t vgm_time = this->vgm_time;
|
||||
byte const* pos = this->pos;
|
||||
if ( pos >= data_end )
|
||||
{
|
||||
set_track_ended();
|
||||
if ( pos > data_end )
|
||||
set_warning( "Stream lacked end event" );
|
||||
}
|
||||
|
||||
while ( vgm_time < end_time && pos < data_end )
|
||||
{
|
||||
// TODO: be sure there are enough bytes left in stream for particular command
|
||||
// so we don't read past end
|
||||
switch ( *pos++ )
|
||||
{
|
||||
case cmd_end:
|
||||
pos = loop_begin; // if not looped, loop_begin == data_end
|
||||
break;
|
||||
|
||||
case cmd_delay_735:
|
||||
vgm_time += 735;
|
||||
break;
|
||||
|
||||
case cmd_delay_882:
|
||||
vgm_time += 882;
|
||||
break;
|
||||
|
||||
case cmd_gg_stereo:
|
||||
psg.write_ggstereo( to_blip_time( vgm_time ), *pos++ );
|
||||
break;
|
||||
|
||||
case cmd_psg:
|
||||
psg.write_data( to_blip_time( vgm_time ), *pos++ );
|
||||
break;
|
||||
|
||||
case cmd_delay:
|
||||
vgm_time += pos [1] * 0x100L + pos [0];
|
||||
pos += 2;
|
||||
break;
|
||||
|
||||
case cmd_byte_delay:
|
||||
vgm_time += *pos++;
|
||||
break;
|
||||
|
||||
case cmd_ym2413:
|
||||
if ( ym2413.run_until( to_fm_time( vgm_time ) ) )
|
||||
ym2413.write( pos [0], pos [1] );
|
||||
pos += 2;
|
||||
break;
|
||||
|
||||
case cmd_ym2612_port0:
|
||||
if ( pos [0] == ym2612_dac_port )
|
||||
{
|
||||
write_pcm( vgm_time, pos [1] );
|
||||
}
|
||||
else if ( ym2612.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] );
|
||||
}
|
||||
pos += 2;
|
||||
break;
|
||||
|
||||
case cmd_ym2612_port1:
|
||||
if ( ym2612.run_until( to_fm_time( vgm_time ) ) )
|
||||
ym2612.write1( pos [0], pos [1] );
|
||||
pos += 2;
|
||||
break;
|
||||
|
||||
case cmd_data_block: {
|
||||
check( *pos == cmd_end );
|
||||
int type = pos [1];
|
||||
long size = get_le32( pos + 2 );
|
||||
pos += 6;
|
||||
if ( type == pcm_block_type )
|
||||
pcm_data = pos;
|
||||
pos += size;
|
||||
break;
|
||||
}
|
||||
|
||||
case cmd_pcm_seek:
|
||||
pcm_pos = pcm_data + pos [3] * 0x1000000L + pos [2] * 0x10000L +
|
||||
pos [1] * 0x100L + pos [0];
|
||||
pos += 4;
|
||||
break;
|
||||
|
||||
default:
|
||||
int cmd = pos [-1];
|
||||
switch ( cmd & 0xF0 )
|
||||
{
|
||||
case cmd_pcm_delay:
|
||||
write_pcm( vgm_time, *pcm_pos++ );
|
||||
vgm_time += cmd & 0x0F;
|
||||
break;
|
||||
|
||||
case cmd_short_delay:
|
||||
vgm_time += (cmd & 0x0F) + 1;
|
||||
break;
|
||||
|
||||
case 0x50:
|
||||
pos += 2;
|
||||
break;
|
||||
|
||||
default:
|
||||
pos += command_len( cmd ) - 1;
|
||||
set_warning( "Unknown stream event" );
|
||||
}
|
||||
}
|
||||
}
|
||||
vgm_time -= end_time;
|
||||
this->pos = pos;
|
||||
this->vgm_time = vgm_time;
|
||||
|
||||
return to_blip_time( end_time );
|
||||
}
|
||||
|
||||
int Vgm_Emu_Impl::play_frame( blip_time_t blip_time, int sample_count, sample_t* buf )
|
||||
{
|
||||
// to do: timing is working mostly by luck
|
||||
|
||||
int min_pairs = sample_count >> 1;
|
||||
int vgm_time = ((long) min_pairs << fm_time_bits) / fm_time_factor - 1;
|
||||
assert( to_fm_time( vgm_time ) <= min_pairs );
|
||||
int pairs = min_pairs;
|
||||
while ( (pairs = to_fm_time( vgm_time )) < min_pairs )
|
||||
vgm_time++;
|
||||
//dprintf( "pairs: %d, min_pairs: %d\n", pairs, min_pairs );
|
||||
|
||||
if ( ym2612.enabled() )
|
||||
{
|
||||
ym2612.begin_frame( buf );
|
||||
memset( buf, 0, pairs * stereo * sizeof *buf );
|
||||
}
|
||||
else if ( ym2413.enabled() )
|
||||
{
|
||||
ym2413.begin_frame( buf );
|
||||
}
|
||||
|
||||
run_commands( vgm_time );
|
||||
ym2612.run_until( pairs );
|
||||
ym2413.run_until( pairs );
|
||||
|
||||
fm_time_offset = (vgm_time * fm_time_factor + fm_time_offset) -
|
||||
((long) pairs << fm_time_bits);
|
||||
|
||||
psg.end_frame( blip_time );
|
||||
|
||||
return pairs * stereo;
|
||||
}
|
||||
|
||||
// Update pre-1.10 header FM rates by scanning commands
|
||||
void Vgm_Emu_Impl::update_fm_rates( long* ym2413_rate, long* ym2612_rate ) const
|
||||
{
|
||||
byte const* p = data + 0x40;
|
||||
while ( p < data_end )
|
||||
{
|
||||
switch ( *p )
|
||||
{
|
||||
case cmd_end:
|
||||
return;
|
||||
|
||||
case cmd_psg:
|
||||
case cmd_byte_delay:
|
||||
p += 2;
|
||||
break;
|
||||
|
||||
case cmd_delay:
|
||||
p += 3;
|
||||
break;
|
||||
|
||||
case cmd_data_block:
|
||||
p += 7 + get_le32( p + 3 );
|
||||
break;
|
||||
|
||||
case cmd_ym2413:
|
||||
*ym2612_rate = 0;
|
||||
return;
|
||||
|
||||
case cmd_ym2612_port0:
|
||||
case cmd_ym2612_port1:
|
||||
*ym2612_rate = *ym2413_rate;
|
||||
*ym2413_rate = 0;
|
||||
return;
|
||||
|
||||
case cmd_ym2151:
|
||||
*ym2413_rate = 0;
|
||||
*ym2612_rate = 0;
|
||||
return;
|
||||
|
||||
default:
|
||||
p += command_len( *p );
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,71 +0,0 @@
|
|||
// Low-level parts of Vgm_Emu
|
||||
|
||||
// Game_Music_Emu 0.5.2
|
||||
#ifndef VGM_EMU_IMPL_H
|
||||
#define VGM_EMU_IMPL_H
|
||||
|
||||
#include "Dual_Resampler.h"
|
||||
#include "Classic_Emu.h"
|
||||
#include "Ym2413_Emu.h"
|
||||
#include "Ym2612_Emu.h"
|
||||
#include "Sms_Apu.h"
|
||||
|
||||
template<class Emu>
|
||||
class Ym_Emu : public Emu {
|
||||
protected:
|
||||
int last_time;
|
||||
short* out;
|
||||
enum { disabled_time = -1 };
|
||||
public:
|
||||
Ym_Emu() : last_time( disabled_time ), out( NULL ) { }
|
||||
void enable( bool b ) { last_time = b ? 0 : disabled_time; }
|
||||
bool enabled() const { return last_time != disabled_time; }
|
||||
void begin_frame( short* p );
|
||||
int run_until( int time );
|
||||
};
|
||||
|
||||
class Vgm_Emu_Impl : public Classic_Emu, private Dual_Resampler {
|
||||
public:
|
||||
typedef Classic_Emu::sample_t sample_t;
|
||||
protected:
|
||||
enum { stereo = 2 };
|
||||
|
||||
typedef int vgm_time_t;
|
||||
|
||||
enum { fm_time_bits = 12 };
|
||||
typedef int fm_time_t;
|
||||
long fm_time_offset;
|
||||
int fm_time_factor;
|
||||
fm_time_t to_fm_time( vgm_time_t ) const;
|
||||
|
||||
enum { blip_time_bits = 12 };
|
||||
int blip_time_factor;
|
||||
blip_time_t to_blip_time( vgm_time_t ) const;
|
||||
|
||||
byte const* data;
|
||||
byte const* loop_begin;
|
||||
byte const* data_end;
|
||||
void update_fm_rates( long* ym2413_rate, long* ym2612_rate ) const;
|
||||
|
||||
vgm_time_t vgm_time;
|
||||
byte const* pos;
|
||||
blip_time_t run_commands( vgm_time_t );
|
||||
int play_frame( blip_time_t blip_time, int sample_count, sample_t* buf );
|
||||
|
||||
byte const* pcm_data;
|
||||
byte const* pcm_pos;
|
||||
int dac_amp;
|
||||
int dac_disabled; // -1 if disabled
|
||||
void write_pcm( vgm_time_t, int amp );
|
||||
|
||||
Ym_Emu<Ym2612_Emu> ym2612;
|
||||
Ym_Emu<Ym2413_Emu> ym2413;
|
||||
|
||||
Blip_Buffer blip_buf;
|
||||
Sms_Apu psg;
|
||||
Blip_Synth<blip_med_quality,1> dac_synth;
|
||||
|
||||
friend class Vgm_Emu;
|
||||
};
|
||||
|
||||
#endif
|
|
@ -1,72 +0,0 @@
|
|||
|
||||
#include "Gbs_Emu.h"
|
||||
|
||||
#include "blargg_source.h"
|
||||
|
||||
int Gbs_Emu::cpu_read( gb_addr_t addr )
|
||||
{
|
||||
int result = *cpu::get_code( addr );
|
||||
if ( unsigned (addr - Gb_Apu::start_addr) < Gb_Apu::register_count )
|
||||
result = apu.read_register( clock(), addr );
|
||||
#ifndef NDEBUG
|
||||
else if ( unsigned (addr - 0x8000) < 0x2000 || unsigned (addr - 0xE000) < 0x1F00 )
|
||||
dprintf( "Read from unmapped memory $%.4x\n", (unsigned) addr );
|
||||
else if ( unsigned (addr - 0xFF01) < 0xFF80 - 0xFF01 )
|
||||
dprintf( "Unhandled I/O read 0x%4X\n", (unsigned) addr );
|
||||
#endif
|
||||
return result;
|
||||
}
|
||||
|
||||
void Gbs_Emu::cpu_write( gb_addr_t addr, int data )
|
||||
{
|
||||
unsigned offset = addr - ram_addr;
|
||||
if ( offset <= 0xFFFF - ram_addr )
|
||||
{
|
||||
ram [offset] = data;
|
||||
if ( (addr ^ 0xE000) <= 0x1F80 - 1 )
|
||||
{
|
||||
if ( unsigned (addr - Gb_Apu::start_addr) < Gb_Apu::register_count )
|
||||
{
|
||||
GME_APU_HOOK( this, addr - Gb_Apu::start_addr, data );
|
||||
apu.write_register( clock(), addr, data );
|
||||
}
|
||||
else if ( (addr ^ 0xFF06) < 2 )
|
||||
update_timer();
|
||||
else if ( addr == joypad_addr )
|
||||
ram [offset] = 0; // keep joypad return value 0
|
||||
else
|
||||
ram [offset] = 0xFF;
|
||||
|
||||
//if ( addr == 0xFFFF )
|
||||
// dprintf( "Wrote interrupt mask\n" );
|
||||
}
|
||||
}
|
||||
else if ( (addr ^ 0x2000) <= 0x2000 - 1 )
|
||||
{
|
||||
set_bank( data );
|
||||
}
|
||||
#ifndef NDEBUG
|
||||
else if ( unsigned (addr - 0x8000) < 0x2000 || unsigned (addr - 0xE000) < 0x1F00 )
|
||||
{
|
||||
dprintf( "Wrote to unmapped memory $%.4x\n", (unsigned) addr );
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#define CPU_READ_FAST( cpu, addr, time, out ) \
|
||||
CPU_READ_FAST_( STATIC_CAST(Gbs_Emu*,cpu), addr, time, out )
|
||||
|
||||
#define CPU_READ_FAST_( emu, addr, time, out ) \
|
||||
{\
|
||||
out = READ_PROG( addr );\
|
||||
if ( unsigned (addr - Gb_Apu::start_addr) <= Gb_Apu::register_count )\
|
||||
out = emu->apu.read_register( emu->cpu_time - time * clocks_per_instr, addr );\
|
||||
else\
|
||||
check( out == emu->cpu_read( addr ) );\
|
||||
}
|
||||
|
||||
#define CPU_READ( cpu, addr, time ) \
|
||||
STATIC_CAST(Gbs_Emu*,cpu)->cpu_read( addr )
|
||||
|
||||
#define CPU_WRITE( cpu, addr, data, time ) \
|
||||
STATIC_CAST(Gbs_Emu*,cpu)->cpu_write( addr, data )
|
|
@ -1,10 +1,14 @@
|
|||
Game_Music_Emu 0.5.2
|
||||
Game_Music_Emu 0.6.0 Pre-release
|
||||
--------------------
|
||||
Author : Shay Green <gblargg@gmail.com>
|
||||
Author : Chris Moeller <kode54@gmail.com>
|
||||
Website: http://www.slack.net/~ant/libs/
|
||||
Website: http://bitbucket.com/kode54/Game_Music_Emu
|
||||
Forum : http://groups.google.com/group/blargg-sound-libs
|
||||
License: GNU Lesser General Public License (LGPL)
|
||||
|
||||
NOTE: This file has not been fully updated yet!
|
||||
|
||||
Contents
|
||||
--------
|
||||
* Overview
|
||||
|
|
|
@ -1,101 +0,0 @@
|
|||
|
||||
#include "Hes_Emu.h"
|
||||
|
||||
#include "blargg_source.h"
|
||||
|
||||
int Hes_Emu::cpu_read( hes_addr_t addr )
|
||||
{
|
||||
check( addr <= 0xFFFF );
|
||||
int result = *cpu::get_code( addr );
|
||||
if ( mmr [addr >> page_shift] == 0xFF )
|
||||
result = cpu_read_( addr );
|
||||
return result;
|
||||
}
|
||||
|
||||
void Hes_Emu::cpu_write( hes_addr_t addr, int data )
|
||||
{
|
||||
check( addr <= 0xFFFF );
|
||||
byte* out = write_pages [addr >> page_shift];
|
||||
addr &= page_size - 1;
|
||||
if ( out )
|
||||
out [addr] = data;
|
||||
else if ( mmr [addr >> page_shift] == 0xFF )
|
||||
cpu_write_( addr, data );
|
||||
}
|
||||
|
||||
inline byte const* Hes_Emu::cpu_set_mmr( int page, int bank )
|
||||
{
|
||||
write_pages [page] = 0;
|
||||
if ( bank < 0x80 )
|
||||
return rom.at_addr( bank * (blargg_long) page_size );
|
||||
|
||||
byte* data = 0;
|
||||
switch ( bank )
|
||||
{
|
||||
case 0xF8:
|
||||
data = cpu::ram;
|
||||
break;
|
||||
|
||||
case 0xF9:
|
||||
case 0xFA:
|
||||
case 0xFB:
|
||||
data = &sgx [(bank - 0xF9) * page_size];
|
||||
break;
|
||||
|
||||
default:
|
||||
if ( bank != 0xFF )
|
||||
dprintf( "Unmapped bank $%02X\n", bank );
|
||||
return rom.unmapped();
|
||||
}
|
||||
|
||||
write_pages [page] = data;
|
||||
return data;
|
||||
}
|
||||
|
||||
#define CPU_READ_FAST( cpu, addr, time, out ) \
|
||||
CPU_READ_FAST_( STATIC_CAST(Hes_Emu*,cpu), addr, time, out )
|
||||
|
||||
#define CPU_READ_FAST_( cpu, addr, time, out ) \
|
||||
{\
|
||||
out = READ_PROG( addr );\
|
||||
if ( mmr [addr >> page_shift] == 0xFF )\
|
||||
{\
|
||||
FLUSH_TIME();\
|
||||
out = cpu->cpu_read_( addr );\
|
||||
CACHE_TIME();\
|
||||
}\
|
||||
}
|
||||
|
||||
#define CPU_WRITE_FAST( cpu, addr, data, time ) \
|
||||
CPU_WRITE_FAST_( STATIC_CAST(Hes_Emu*,cpu), addr, data, time )
|
||||
|
||||
#define CPU_WRITE_FAST_( cpu, addr, data, time ) \
|
||||
{\
|
||||
byte* out = cpu->write_pages [addr >> page_shift];\
|
||||
addr &= page_size - 1;\
|
||||
if ( out )\
|
||||
{\
|
||||
out [addr] = data;\
|
||||
}\
|
||||
else if ( mmr [addr >> page_shift] == 0xFF )\
|
||||
{\
|
||||
FLUSH_TIME();\
|
||||
cpu->cpu_write_( addr, data );\
|
||||
CACHE_TIME();\
|
||||
}\
|
||||
}
|
||||
|
||||
#define CPU_READ( cpu, addr, time ) \
|
||||
STATIC_CAST(Hes_Emu*,cpu)->cpu_read( addr )
|
||||
|
||||
#define CPU_WRITE( cpu, addr, data, time ) \
|
||||
STATIC_CAST(Hes_Emu*,cpu)->cpu_write( addr, data )
|
||||
|
||||
#define CPU_WRITE_VDP( cpu, addr, data, time ) \
|
||||
STATIC_CAST(Hes_Emu*,cpu)->cpu_write_vdp( addr, data )
|
||||
|
||||
#define CPU_SET_MMR( cpu, page, bank ) \
|
||||
STATIC_CAST(Hes_Emu*,cpu)->cpu_set_mmr( page, bank )
|
||||
|
||||
#define CPU_DONE( cpu, time, result_out ) \
|
||||
result_out = STATIC_CAST(Hes_Emu*,cpu)->cpu_done()
|
|
@ -1,83 +0,0 @@
|
|||
|
||||
#include "Nsf_Emu.h"
|
||||
|
||||
#if !NSF_EMU_APU_ONLY
|
||||
#include "Nes_Namco_Apu.h"
|
||||
#endif
|
||||
|
||||
#include "blargg_source.h"
|
||||
|
||||
int Nsf_Emu::cpu_read( nes_addr_t addr )
|
||||
{
|
||||
int result;
|
||||
|
||||
result = cpu::low_mem [addr & 0x7FF];
|
||||
if ( !(addr & 0xE000) )
|
||||
goto exit;
|
||||
|
||||
result = *cpu::get_code( addr );
|
||||
if ( addr > 0x7FFF )
|
||||
goto exit;
|
||||
|
||||
result = sram [addr & (sizeof sram - 1)];
|
||||
if ( addr > 0x5FFF )
|
||||
goto exit;
|
||||
|
||||
if ( addr == Nes_Apu::status_addr )
|
||||
return apu.read_status( cpu::time() );
|
||||
|
||||
#if !NSF_EMU_APU_ONLY
|
||||
if ( addr == Nes_Namco_Apu::data_reg_addr && namco )
|
||||
return namco->read_data();
|
||||
#endif
|
||||
|
||||
result = addr >> 8; // simulate open bus
|
||||
|
||||
if ( addr != 0x2002 )
|
||||
dprintf( "Read unmapped $%.4X\n", (unsigned) addr );
|
||||
|
||||
exit:
|
||||
return result;
|
||||
}
|
||||
|
||||
void Nsf_Emu::cpu_write( nes_addr_t addr, int data )
|
||||
{
|
||||
{
|
||||
nes_addr_t offset = addr ^ sram_addr;
|
||||
if ( offset < sizeof sram )
|
||||
{
|
||||
sram [offset] = data;
|
||||
return;
|
||||
}
|
||||
}
|
||||
{
|
||||
int temp = addr & 0x7FF;
|
||||
if ( !(addr & 0xE000) )
|
||||
{
|
||||
cpu::low_mem [temp] = data;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if ( unsigned (addr - Nes_Apu::start_addr) <= Nes_Apu::end_addr - Nes_Apu::start_addr )
|
||||
{
|
||||
GME_APU_HOOK( this, addr - Nes_Apu::start_addr, data );
|
||||
apu.write_register( cpu::time(), addr, data );
|
||||
return;
|
||||
}
|
||||
|
||||
unsigned bank = addr - bank_select_addr;
|
||||
if ( bank < bank_count )
|
||||
{
|
||||
blargg_long offset = rom.mask_addr( data * (blargg_long) bank_size );
|
||||
if ( offset >= rom.size() )
|
||||
set_warning( "Invalid bank" );
|
||||
cpu::map_code( (bank + 8) * bank_size, bank_size, rom.at_addr( offset ) );
|
||||
return;
|
||||
}
|
||||
|
||||
cpu_write_misc( addr, data );
|
||||
}
|
||||
|
||||
#define CPU_READ( cpu, addr, time ) STATIC_CAST(Nsf_Emu&,*cpu).cpu_read( addr )
|
||||
#define CPU_WRITE( cpu, addr, data, time ) STATIC_CAST(Nsf_Emu&,*cpu).cpu_write( addr, data )
|
|
@ -1,26 +0,0 @@
|
|||
|
||||
#include "Sap_Emu.h"
|
||||
|
||||
#include "blargg_source.h"
|
||||
|
||||
#define CPU_WRITE( cpu, addr, data, time ) STATIC_CAST(Sap_Emu&,*cpu).cpu_write( addr, data )
|
||||
|
||||
void Sap_Emu::cpu_write( sap_addr_t addr, int data )
|
||||
{
|
||||
mem.ram [addr] = data;
|
||||
if ( (addr >> 8) == 0xD2 )
|
||||
cpu_write_( addr, data );
|
||||
}
|
||||
|
||||
#ifdef NDEBUG
|
||||
#define CPU_READ( cpu, addr, time ) READ_LOW( addr )
|
||||
#else
|
||||
#define CPU_READ( cpu, addr, time ) STATIC_CAST(Sap_Emu&,*cpu).cpu_read( addr )
|
||||
|
||||
int Sap_Emu::cpu_read( sap_addr_t addr )
|
||||
{
|
||||
if ( (addr & 0xF900) == 0xD000 )
|
||||
dprintf( "Unmapped read $%04X\n", addr );
|
||||
return mem.ram [addr];
|
||||
}
|
||||
#endif
|
Loading…
Reference in New Issue