cog/Frameworks/GME/gme/Sap_Cpu.cpp

97 lines
2.5 KiB
C++
Raw Normal View History

2013-09-28 03:24:23 +00:00
// $package. http://www.slack.net/~ant/
2007-10-11 23:11:58 +00:00
2013-09-28 03:24:23 +00:00
#include "Sap_Core.h"
2007-10-11 23:11:58 +00:00
#include "blargg_endian.h"
2013-09-28 03:24:23 +00:00
//#define CPU_LOG_MAX 100000
2007-10-11 23:11:58 +00:00
//#include "nes_cpu_log.h"
2013-09-28 03:24:23 +00:00
/* Copyright (C) 2003-2008 Shay Green. This module is free software; you
2007-10-11 23:11:58 +00:00
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"
2013-09-28 03:24:23 +00:00
// functions defined in same file as CPU emulator to help compiler's optimizer
2007-10-11 23:11:58 +00:00
2013-09-28 03:24:23 +00:00
int Sap_Core::read_d40b()
2007-10-11 23:11:58 +00:00
{
2013-09-28 03:24:23 +00:00
//dprintf( "D40B read\n" );
check( cpu.time() >= frame_start );
return ((unsigned) (cpu.time() - frame_start) / scanline_period % lines_per_frame) / 2;
2007-10-11 23:11:58 +00:00
}
2013-09-28 03:24:23 +00:00
void Sap_Core::write_D2xx( int d2xx, int data )
2007-10-11 23:11:58 +00:00
{
2013-09-28 03:24:23 +00:00
addr_t const base = 0xD200;
2007-10-11 23:11:58 +00:00
2013-09-28 03:24:23 +00:00
if ( d2xx < apu_.io_size )
2007-10-11 23:11:58 +00:00
{
2013-09-28 03:24:23 +00:00
apu_.write_data( time(), d2xx + base, data );
return;
2007-10-11 23:11:58 +00:00
}
2013-09-28 03:24:23 +00:00
if ( (unsigned) (d2xx - 0x10) < apu2_.io_size && info.stereo )
2007-10-11 23:11:58 +00:00
{
2013-09-28 03:24:23 +00:00
apu2_.write_data( time(), d2xx + (base - 0x10), data );
return;
2007-10-11 23:11:58 +00:00
}
2013-09-28 03:24:23 +00:00
if ( d2xx == 0xD40A - base )
2007-10-11 23:11:58 +00:00
{
2013-09-28 03:24:23 +00:00
dprintf( "D40A write\n" );
time_t t = cpu.time();
time_t into_line = (t - frame_start) % scanline_period;
cpu.set_end_time( t - into_line + scanline_period );
return;
2007-10-11 23:11:58 +00:00
}
2013-09-28 03:24:23 +00:00
if ( (d2xx & ~0x0010) != 0x0F || data != 0x03 )
dprintf( "Unmapped write $%04X <- $%02X\n", d2xx + base, data );
2007-10-11 23:11:58 +00:00
}
2013-09-28 03:24:23 +00:00
inline int Sap_Core::read_mem( addr_t addr )
{
int result = mem.ram [addr];
if ( addr == 0xD40B )
result = read_d40b();
else if ( (addr & 0xF900) == 0xD000 )
dprintf( "Unmapped read $%04X\n", addr );
return result;
}
2007-10-11 23:11:58 +00:00
2013-09-28 03:24:23 +00:00
#define READ_LOW( addr ) (ram [addr])
#define WRITE_LOW( addr, data ) (ram [addr] = data)
2007-10-11 23:11:58 +00:00
2013-09-28 03:24:23 +00:00
#define READ_MEM( addr ) read_mem( addr )
#define WRITE_MEM( addr, data ) \
{\
ram [addr] = data;\
int d2xx = addr - 0xD200;\
if ( (unsigned) d2xx < 0x100 )\
write_D2xx( d2xx, data );\
}
2007-10-11 23:11:58 +00:00
2013-09-28 03:24:23 +00:00
#define CPU cpu
#define FLAT_MEM ram
2007-10-11 23:11:58 +00:00
2013-09-28 03:24:23 +00:00
#define CPU_BEGIN \
bool Sap_Core::run_cpu( time_t end )\
{\
CPU.set_end_time( end );\
byte* const ram = this->mem.ram; /* cache */
2007-10-11 23:11:58 +00:00
2013-09-28 03:24:23 +00:00
#include "Nes_Cpu_run.h"
2007-10-11 23:11:58 +00:00
2013-09-28 03:24:23 +00:00
return cpu.time_past_end() < 0;
2007-10-11 23:11:58 +00:00
}