Updated for preliminary Pitfall II support.

git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@15 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba
This commit is contained in:
bwmott 2001-12-30 18:43:30 +00:00
parent cb1a8d4565
commit cf68f6d4b4
4 changed files with 456 additions and 6 deletions

View File

@ -13,7 +13,7 @@
## See the file "license" for information on usage and redistribution of ## See the file "license" for information on usage and redistribution of
## this file, and for a DISCLAIMER OF ALL WARRANTIES. ## this file, and for a DISCLAIMER OF ALL WARRANTIES.
## ##
## $Id: makefile,v 1.1.1.1 2001-12-27 19:54:18 bwmott Exp $ ## $Id: makefile,v 1.2 2001-12-30 18:43:30 bwmott Exp $
##============================================================================ ##============================================================================
##============================================================================ ##============================================================================
@ -124,9 +124,9 @@ solaris-x:
############################################################################### ###############################################################################
M6502_OBJS = D6502.o Device.o M6502.o M6502Low.o M6502Hi.o NullDev.o System.o M6502_OBJS = D6502.o Device.o M6502.o M6502Low.o M6502Hi.o NullDev.o System.o
CORE_OBJS = Booster.o Cart.o Cart2K.o Cart3F.o Cart4K.o CartAR.o CartE0.o \ CORE_OBJS = Booster.o Cart.o Cart2K.o Cart3F.o Cart4K.o CartAR.o CartDPC.o \
CartE7.o CartF4SC.o CartF6.o CartF6SC.o CartF8.o CartF8SC.o \ CartE0.o CartE7.o CartF4SC.o CartF6.o CartF6SC.o CartF8.o \
CartFASC.o CartFE.o CartMC.o Console.o \ CartF8SC.o CartFASC.o CartFE.o CartMC.o Console.o \
Control.o DefProps.o Driving.o \ Control.o DefProps.o Driving.o \
Event.o Joystick.o Keyboard.o M6532.o MD5.o MediaSrc.o Paddles.o \ Event.o Joystick.o Keyboard.o M6532.o MD5.o MediaSrc.o Paddles.o \
Props.o PropsSet.o Random.o Sound.o Switches.o TIA.o \ Props.o PropsSet.o Random.o Sound.o Switches.o TIA.o \
@ -205,6 +205,9 @@ Cart4K.o: $(CORE)/Cart4K.cxx
CartAR.o: $(CORE)/CartAR.cxx CartAR.o: $(CORE)/CartAR.cxx
$(CXX) -c $(CXXFLAGS) $(OPTIONS) $(CORE)/CartAR.cxx $(CXX) -c $(CXXFLAGS) $(OPTIONS) $(CORE)/CartAR.cxx
CartDPC.o: $(CORE)/CartDPC.cxx
$(CXX) -c $(CXXFLAGS) $(OPTIONS) $(CORE)/CartDPC.cxx
CartE0.o: $(CORE)/CartE0.cxx CartE0.o: $(CORE)/CartE0.cxx
$(CXX) -c $(CXXFLAGS) $(OPTIONS) $(CORE)/CartE0.cxx $(CXX) -c $(CXXFLAGS) $(OPTIONS) $(CORE)/CartE0.cxx

View File

@ -8,12 +8,12 @@
// SS SS tt ee ll ll aa aa // SS SS tt ee ll ll aa aa
// SSSS ttt eeeee llll llll aaaaa // SSSS ttt eeeee llll llll aaaaa
// //
// Copyright (c) 1995-1998 by Bradford W. Mott // Copyright (c) 1995-2002 by Bradford W. Mott
// //
// See the file "license" for information on usage and redistribution of // See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES. // this file, and for a DISCLAIMER OF ALL WARRANTIES.
// //
// $Id: Cart.cxx,v 1.1.1.1 2001-12-27 19:54:18 bwmott Exp $ // $Id: Cart.cxx,v 1.2 2001-12-30 18:43:30 bwmott Exp $
//============================================================================ //============================================================================
#include <assert.h> #include <assert.h>
@ -23,6 +23,7 @@
#include "Cart3F.hxx" #include "Cart3F.hxx"
#include "Cart4K.hxx" #include "Cart4K.hxx"
#include "CartAR.hxx" #include "CartAR.hxx"
#include "CartDPC.hxx"
#include "CartE0.hxx" #include "CartE0.hxx"
#include "CartE7.hxx" #include "CartE7.hxx"
#include "CartF4SC.hxx" #include "CartF4SC.hxx"
@ -60,6 +61,8 @@ Cartridge* Cartridge::create(const uInt8* image, uInt32 size,
cartridge = new Cartridge4K(image); cartridge = new Cartridge4K(image);
else if(type == "AR") else if(type == "AR")
cartridge = new CartridgeAR(image, size); cartridge = new CartridgeAR(image, size);
else if(type == "DPC")
cartridge = new CartridgeDPC(image, size);
else if(type == "E0") else if(type == "E0")
cartridge = new CartridgeE0(image); cartridge = new CartridgeE0(image);
else if(type == "E7") else if(type == "E7")
@ -129,6 +132,7 @@ string Cartridge::autodetectType(const uInt8* image, uInt32 size)
{"3b76242691730b2dd22ec0ceab351bc6", "E7"}, // He-Man {"3b76242691730b2dd22ec0ceab351bc6", "E7"}, // He-Man
{"ac7c2260378975614192ca2bc3d20e0b", "FE"}, // Decathlon {"ac7c2260378975614192ca2bc3d20e0b", "FE"}, // Decathlon
{"4f618c2429138e0280969193ed6c107e", "FE"}, // Robot Tank {"4f618c2429138e0280969193ed6c107e", "FE"}, // Robot Tank
{"6d842c96d5a01967be9680080dd5be54", "DPC"}, // Pitfall II
{(char*)0, (char*)0} {(char*)0, (char*)0}
}; };

View File

@ -0,0 +1,317 @@
//============================================================================
//
// SSSS tt lll lll
// SS SS tt ll ll
// SS tttttt eeee ll ll aaaa
// SSSS tt ee ee ll ll aa
// SS tt eeeeee ll ll aaaaa -- "An Atari 2600 VCS Emulator"
// SS SS tt ee ll ll aa aa
// SSSS ttt eeeee llll llll aaaaa
//
// Copyright (c) 1995-2002 by Bradford W. Mott
//
// See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//
// $Id: CartDPC.cxx,v 1.1 2001-12-30 18:43:30 bwmott Exp $
//============================================================================
#include <assert.h>
#include "CartDPC.hxx"
#include "System.hxx"
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
CartridgeDPC::CartridgeDPC(const uInt8* image, uInt32 size)
{
// Copy the program ROM image into my buffer
for(uInt32 addr = 0; addr < 8192; ++addr)
{
myProgramImage[addr] = image[addr];
}
// Copy the display ROM image into my buffer
for(uInt32 addr = 0; addr < 2048; ++addr)
{
myDisplayImage[addr] = image[8192 + addr];
}
// Initialize the DPC data fetcher registers
for(uInt16 i = 0; i < 8; ++i)
{
myBottoms[i] = myCounters[i] = myFlags[i] = myTops[i] = 0;
}
// Initialize the DPC's random number generator register (must be non-zero)
myRandomNumber = 1;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
CartridgeDPC::~CartridgeDPC()
{
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
const char* CartridgeDPC::name() const
{
return "CartridgeDPC";
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void CartridgeDPC::reset()
{
// Upon reset we switch to bank 1
bank(1);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void CartridgeDPC::install(System& system)
{
mySystem = &system;
uInt16 shift = mySystem->pageShift();
uInt16 mask = mySystem->pageMask();
// Make sure the system we're being installed in has a page size that'll work
assert(((0x1080 & mask) == 0) && ((0x1100 & mask) == 0));
// Set the page accessing methods for the hot spots
System::PageAccess access;
for(uInt32 i = (0x1FF8 & ~mask); i < 0x2000; i += (1 << shift))
{
access.directPeekBase = 0;
access.directPokeBase = 0;
access.device = this;
mySystem->setPageAccess(i >> shift, access);
}
// Set the page accessing method for the DPC reading & writing pages
for(uInt32 j = 0x1000; j < 0x1080; j += (1 << shift))
{
access.directPeekBase = 0;
access.directPokeBase = 0;
access.device = this;
mySystem->setPageAccess(j >> shift, access);
}
// Install pages for bank 1
bank(1);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
inline void CartridgeDPC::clockRandomNumberGenerator()
{
// Table for computing the input bit of the random number generator's
// shift register (it's the NOT of the EOR of four bits)
static uInt8 f[16] = {
1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1
};
// Using bits 7, 5, 4, & 3 of the shift register compute the input
// bit for the shift register
uInt8 bit = f[((myRandomNumber >> 3) & 0x07) |
((myRandomNumber & 0x80) ? 0x08 : 0x00)];
// Update the shift register
myRandomNumber = (myRandomNumber << 1) | bit;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
uInt8 CartridgeDPC::peek(uInt16 address)
{
address = address & 0x0FFF;
// Clock the random number generator. This should be done for every
// cartridge access, however, we're only doing it for the DPC and
// hot-spot accesses to save time.
clockRandomNumberGenerator();
if(address < 0x0040)
{
// Get the index of the data fetcher that's being accessed
uInt32 index = address & 0x07;
uInt32 function = (address >> 3) & 0x07;
// Update flag register for this data fetcher
if((myCounters[index] & 0x00ff) == myTops[index])
{
myFlags[index] = 0xff;
}
else if((myCounters[index] & 0x00ff) == myBottoms[index])
{
myFlags[index] = 0x00;
}
switch(function)
{
case 0x00:
{
// Is this a random number read
if(index < 4)
{
return myRandomNumber;
}
else
{
// TODO: Replace with sound read code
return 0;
}
}
// DFx display data read
case 0x01:
{
uInt8 r = myDisplayImage[2047 - myCounters[index]];
myCounters[index] = (myCounters[index] - 1) & 0x07ff;
return r;
}
// DFx display data read AND'd w/flag
case 0x02:
{
uInt8 r = myDisplayImage[2047 - myCounters[index]] & myFlags[index];
myCounters[index] = (myCounters[index] - 1) & 0x07ff;
return r;
}
// DFx flag
case 0x07:
{
uInt8 r = myFlags[index];
myCounters[index] = (myCounters[index] - 1) & 0x07ff;
return r;
}
default:
{
return 0;
}
}
}
else
{
// Switch banks if necessary
switch(address)
{
case 0x0FF8:
// Set the current bank to the lower 4k bank
bank(0);
break;
case 0x0FF9:
// Set the current bank to the upper 4k bank
bank(1);
break;
default:
break;
}
return myProgramImage[myCurrentBank * 4096 + address];
}
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void CartridgeDPC::poke(uInt16 address, uInt8 value)
{
address = address & 0x0FFF;
// Clock the random number generator. This should be done for every
// cartridge access, however, we're only doing it for the DPC and
// hot-spot accesses to save time.
clockRandomNumberGenerator();
if((address >= 0x0040) && (address < 0x0080))
{
// Get the index of the data fetcher that's being accessed
uInt32 index = address & 0x07;
uInt32 function = (address >> 3) & 0x07;
switch(function)
{
// DFx top count
case 0x00:
{
myTops[index] = value;
break;
}
// DFx bottom count
case 0x01:
{
myBottoms[index] = value;
break;
}
// DFx counter low
case 0x02:
{
myCounters[index] = (myCounters[index] & 0x0700) | (uInt16)value;
break;
}
// DFx counter high
case 0x03:
{
myFlags[index] = 0x00;
myCounters[index] = (((uInt16)value & 0x07) << 8) |
(myCounters[index] & 0x00ff);
// TODO: Handle music data fetchers
break;
}
// Random Number Generator Reset
case 0x06:
{
myRandomNumber = 1;
break;
}
default:
{
break;
}
}
}
else
{
// Switch banks if necessary
switch(address)
{
case 0x0FF8:
// Set the current bank to the lower 4k bank
bank(0);
break;
case 0x0FF9:
// Set the current bank to the upper 4k bank
bank(1);
break;
default:
break;
}
}
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void CartridgeDPC::bank(uInt16 bank)
{
// Remember what bank we're in
myCurrentBank = bank;
uInt16 offset = myCurrentBank * 4096;
uInt16 shift = mySystem->pageShift();
uInt16 mask = mySystem->pageMask();
// Setup the page access methods for the current bank
System::PageAccess access;
access.device = this;
access.directPokeBase = 0;
// Map Program ROM image into the system
for(uInt32 address = 0x1080; address < (0x1FF8U & ~mask);
address += (1 << shift))
{
access.directPeekBase = &myProgramImage[offset + (address & 0x0FFF)];
mySystem->setPageAccess(address >> shift, access);
}
}

View File

@ -0,0 +1,126 @@
//============================================================================
//
// SSSS tt lll lll
// SS SS tt ll ll
// SS tttttt eeee ll ll aaaa
// SSSS tt ee ee ll ll aa
// SS tt eeeeee ll ll aaaaa -- "An Atari 2600 VCS Emulator"
// SS SS tt ee ll ll aa aa
// SSSS ttt eeeee llll llll aaaaa
//
// Copyright (c) 1995-2002 by Bradford W. Mott
//
// See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
//
// $Id: CartDPC.hxx,v 1.1 2001-12-30 18:43:30 bwmott Exp $
//============================================================================
#ifndef CARTRIDGEDCP_HXX
#define CARTRIDGEDCP_HXX
class CartridgeDPC;
#include "bspf.hxx"
#include "Cart.hxx"
/**
Cartridge class used for Pitfall II. There are two 4K program banks, a
2K display bank, and the DPC chip. For complete details on the DPC chip
see David P. Crane's United States Patent Number 4,644,495.
@author Bradford W. Mott
@version $Id: CartDPC.hxx,v 1.1 2001-12-30 18:43:30 bwmott Exp $
*/
class CartridgeDPC : public Cartridge
{
public:
/**
Create a new cartridge using the specified image
@param image Pointer to the ROM image
*/
CartridgeDPC(const uInt8* image, uInt32 size);
/**
Destructor
*/
virtual ~CartridgeDPC();
public:
/**
Get a null terminated string which is the device's name (i.e. "M6532")
@return The name of the device
*/
virtual const char* name() const;
/**
Reset device to its power-on state
*/
virtual void reset();
/**
Install cartridge in the specified system. Invoked by the system
when the cartridge is attached to it.
@param system The system the device should install itself in
*/
virtual void install(System& system);
public:
/**
Get the byte at the specified address.
@return The byte at the specified address
*/
virtual uInt8 peek(uInt16 address);
/**
Change the byte at the specified address to the given value
@param address The address where the value should be stored
@param value The value to be stored at the address
*/
virtual void poke(uInt16 address, uInt8 value);
private:
/**
Install pages for the specified bank in the system
@param bank The bank that should be installed in the system
*/
void bank(uInt16 bank);
/**
Clocks the random number generator to move it to its next state
*/
void clockRandomNumberGenerator();
private:
// Indicates which bank is currently active
uInt16 myCurrentBank;
// The 8K program ROM image of the cartridge
uInt8 myProgramImage[8192];
// The 2K display ROM image of the cartridge
uInt8 myDisplayImage[2048];
// The bottom registers for the data fetchers
uInt8 myBottoms[8];
// The counter registers for the data fetchers
uInt16 myCounters[8];
// The flag registers for the data fetchers
uInt8 myFlags[8];
// The random number generator register
uInt8 myRandomNumber;
// The top registers for the data fetchers
uInt8 myTops[8];
};
#endif