//1// Copyright (c) 2004 K. Wilkins2//3// This software is provided 'as-is', without any express or implied warranty.4// In no event will the authors be held liable for any damages arising from5// the use of this software.6//7// Permission is granted to anyone to use this software for any purpose,8// including commercial applications, and to alter it and redistribute it9// freely, subject to the following restrictions:10//11// 1. The origin of this software must not be misrepresented; you must not12// claim that you wrote the original software. If you use this software13// in a product, an acknowledgment in the product documentation would be14// appreciated but is not required.15//16// 2. Altered source versions must be plainly marked as such, and must not17// be misrepresented as being the original software.18//19// 3. This notice may not be removed or altered from any source distribution.20//2122//////////////////////////////////////////////////////////////////////////////23// Handy - An Atari Lynx Emulator //24// Copyright (c) 1996,1997 //25// K. Wilkins //26//////////////////////////////////////////////////////////////////////////////27// Lynx memory map class //28//////////////////////////////////////////////////////////////////////////////29// //30// This class provides the register $FFF9 functionality to the emulator, it //31// sets which devices can be seen by the CPU. //32// //33// K. Wilkins //34// August 1997 //35// //36//////////////////////////////////////////////////////////////////////////////37// Revision History: //38// ----------------- //39// //40// 01Aug1997 KW Document header added & class documented. //41// //42//////////////////////////////////////////////////////////////////////////////4344#define MEMMAP_CPP4546//#include <crtdbg.h>47//#define TRACE_MEMMAP4849#include "system.h"50#include "memmap.h"5152#include <string.h>5354// IGNORE THIS TEXT, now overridden by new system55//56// We will hold 16 different memory maps for the "top" area which are selected57// on the basis of mMemMap->mSelector:58//59// Code Vect ROM Mikie Susie60//----------------------------------------------------61// (Default) 0000 V R M S62// 0001 V R M RAM63// 0001 V R RAM S64// 0011 V R RAM RAM65// 0100 V RAM M S66// ..67// ..68// 1111 RAM RAM RAM RAM69//70// Get it.....71//72// We can then index with mMemoryHandlers[mMemMap->mSelector][addr] for speed73//7475CMemMap::CMemMap(CSystem& parent)76:mSystem(parent)77{78Reset();79}808182void CMemMap::Reset(void)83{8485// Initialise ALL pointers to RAM then overload to correct86for(int loop=0;loop<SYSTEM_SIZE;loop++) mSystem.mMemoryHandlers[loop]=mSystem.mRam;8788// Special case for ourselves.89mSystem.mMemoryHandlers[0xFFF8]=mSystem.mRam;90mSystem.mMemoryHandlers[0xFFF9]=mSystem.mMemMap;9192mSusieEnabled=-1;93mMikieEnabled=-1;94mRomEnabled=-1;95mVectorsEnabled=-1;9697// Initialise everything correctly98Poke(0,0);99100}101102103INLINE void CMemMap::Poke(uint32 addr, uint8 data)104{105TRACE_MEMMAP1("Poke() - Data %02x",data);106107int newstate,loop;108109// FC00-FCFF Susie area110newstate=(data&0x01)?FALSE:TRUE;111if(newstate!=mSusieEnabled)112{113mSusieEnabled=newstate;114115if(mSusieEnabled)116{117for(loop=SUSIE_START;loop<SUSIE_START+SUSIE_SIZE;loop++) mSystem.mMemoryHandlers[loop]=mSystem.mSusie;118}119else120{121for(loop=SUSIE_START;loop<SUSIE_START+SUSIE_SIZE;loop++) mSystem.mMemoryHandlers[loop]=mSystem.mRam;122}123}124125// FD00-FCFF Mikie area126newstate=(data&0x02)?FALSE:TRUE;127if(newstate!=mMikieEnabled)128{129mMikieEnabled=newstate;130131if(mMikieEnabled)132{133for(loop=MIKIE_START;loop<MIKIE_START+MIKIE_SIZE;loop++) mSystem.mMemoryHandlers[loop]=mSystem.mMikie;134}135else136{137for(loop=MIKIE_START;loop<MIKIE_START+MIKIE_SIZE;loop++) mSystem.mMemoryHandlers[loop]=mSystem.mRam;138}139}140141// FE00-FFF7 Rom area142newstate=(data&0x04)?FALSE:TRUE;143if(newstate!=mRomEnabled)144{145mRomEnabled=newstate;146147if(mRomEnabled)148{149for(loop=BROM_START;loop<BROM_START+(BROM_SIZE-8);loop++) mSystem.mMemoryHandlers[loop]=mSystem.mRom;150}151else152{153for(loop=BROM_START;loop<BROM_START+(BROM_SIZE-8);loop++) mSystem.mMemoryHandlers[loop]=mSystem.mRam;154}155}156157// FFFA-FFFF Vector area - Overload ROM space158newstate=(data&0x08)?FALSE:TRUE;159if(newstate!=mVectorsEnabled)160{161mVectorsEnabled=newstate;162163if(mVectorsEnabled)164{165for(loop=VECTOR_START;loop<VECTOR_START+VECTOR_SIZE;loop++) mSystem.mMemoryHandlers[loop]=mSystem.mRom;166}167else168{169for(loop=VECTOR_START;loop<VECTOR_START+VECTOR_SIZE;loop++) mSystem.mMemoryHandlers[loop]=mSystem.mRam;170}171}172173174}175176INLINE uint8 CMemMap::Peek(uint32 addr)177{178uint8 retval=0;179180retval+=(mSusieEnabled)?0:0x01;181retval+=(mMikieEnabled)?0:0x02;182retval+=(mRomEnabled)?0:0x04;183retval+=(mVectorsEnabled)?0:0x08;184TRACE_MEMMAP1("Peek() - Data %02x",retval);185return retval;186}187188SYNCFUNC(CMemMap)189{190NSS(mMikieEnabled);191NSS(mSusieEnabled);192NSS(mRomEnabled);193NSS(mVectorsEnabled);194195if (isReader)196{197// force regenerate memory handlers198uint8 current = Peek(0);199Poke(0, ~current);200Poke(0, current);201}202}203204205