Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
alexbevi
GitHub Repository: alexbevi/BizHawk
Path: blob/master/lynx/memmap.cpp
2 views
1
//
2
// Copyright (c) 2004 K. Wilkins
3
//
4
// This software is provided 'as-is', without any express or implied warranty.
5
// In no event will the authors be held liable for any damages arising from
6
// the use of this software.
7
//
8
// Permission is granted to anyone to use this software for any purpose,
9
// including commercial applications, and to alter it and redistribute it
10
// freely, subject to the following restrictions:
11
//
12
// 1. The origin of this software must not be misrepresented; you must not
13
// claim that you wrote the original software. If you use this software
14
// in a product, an acknowledgment in the product documentation would be
15
// appreciated but is not required.
16
//
17
// 2. Altered source versions must be plainly marked as such, and must not
18
// be misrepresented as being the original software.
19
//
20
// 3. This notice may not be removed or altered from any source distribution.
21
//
22
23
//////////////////////////////////////////////////////////////////////////////
24
// Handy - An Atari Lynx Emulator //
25
// Copyright (c) 1996,1997 //
26
// K. Wilkins //
27
//////////////////////////////////////////////////////////////////////////////
28
// Lynx memory map class //
29
//////////////////////////////////////////////////////////////////////////////
30
// //
31
// This class provides the register $FFF9 functionality to the emulator, it //
32
// sets which devices can be seen by the CPU. //
33
// //
34
// K. Wilkins //
35
// August 1997 //
36
// //
37
//////////////////////////////////////////////////////////////////////////////
38
// Revision History: //
39
// ----------------- //
40
// //
41
// 01Aug1997 KW Document header added & class documented. //
42
// //
43
//////////////////////////////////////////////////////////////////////////////
44
45
#define MEMMAP_CPP
46
47
//#include <crtdbg.h>
48
//#define TRACE_MEMMAP
49
50
#include "system.h"
51
#include "memmap.h"
52
53
#include <string.h>
54
55
// IGNORE THIS TEXT, now overridden by new system
56
//
57
// We will hold 16 different memory maps for the "top" area which are selected
58
// on the basis of mMemMap->mSelector:
59
//
60
// Code Vect ROM Mikie Susie
61
//----------------------------------------------------
62
// (Default) 0000 V R M S
63
// 0001 V R M RAM
64
// 0001 V R RAM S
65
// 0011 V R RAM RAM
66
// 0100 V RAM M S
67
// ..
68
// ..
69
// 1111 RAM RAM RAM RAM
70
//
71
// Get it.....
72
//
73
// We can then index with mMemoryHandlers[mMemMap->mSelector][addr] for speed
74
//
75
76
CMemMap::CMemMap(CSystem& parent)
77
:mSystem(parent)
78
{
79
Reset();
80
}
81
82
83
void CMemMap::Reset(void)
84
{
85
86
// Initialise ALL pointers to RAM then overload to correct
87
for(int loop=0;loop<SYSTEM_SIZE;loop++) mSystem.mMemoryHandlers[loop]=mSystem.mRam;
88
89
// Special case for ourselves.
90
mSystem.mMemoryHandlers[0xFFF8]=mSystem.mRam;
91
mSystem.mMemoryHandlers[0xFFF9]=mSystem.mMemMap;
92
93
mSusieEnabled=-1;
94
mMikieEnabled=-1;
95
mRomEnabled=-1;
96
mVectorsEnabled=-1;
97
98
// Initialise everything correctly
99
Poke(0,0);
100
101
}
102
103
104
INLINE void CMemMap::Poke(uint32 addr, uint8 data)
105
{
106
TRACE_MEMMAP1("Poke() - Data %02x",data);
107
108
int newstate,loop;
109
110
// FC00-FCFF Susie area
111
newstate=(data&0x01)?FALSE:TRUE;
112
if(newstate!=mSusieEnabled)
113
{
114
mSusieEnabled=newstate;
115
116
if(mSusieEnabled)
117
{
118
for(loop=SUSIE_START;loop<SUSIE_START+SUSIE_SIZE;loop++) mSystem.mMemoryHandlers[loop]=mSystem.mSusie;
119
}
120
else
121
{
122
for(loop=SUSIE_START;loop<SUSIE_START+SUSIE_SIZE;loop++) mSystem.mMemoryHandlers[loop]=mSystem.mRam;
123
}
124
}
125
126
// FD00-FCFF Mikie area
127
newstate=(data&0x02)?FALSE:TRUE;
128
if(newstate!=mMikieEnabled)
129
{
130
mMikieEnabled=newstate;
131
132
if(mMikieEnabled)
133
{
134
for(loop=MIKIE_START;loop<MIKIE_START+MIKIE_SIZE;loop++) mSystem.mMemoryHandlers[loop]=mSystem.mMikie;
135
}
136
else
137
{
138
for(loop=MIKIE_START;loop<MIKIE_START+MIKIE_SIZE;loop++) mSystem.mMemoryHandlers[loop]=mSystem.mRam;
139
}
140
}
141
142
// FE00-FFF7 Rom area
143
newstate=(data&0x04)?FALSE:TRUE;
144
if(newstate!=mRomEnabled)
145
{
146
mRomEnabled=newstate;
147
148
if(mRomEnabled)
149
{
150
for(loop=BROM_START;loop<BROM_START+(BROM_SIZE-8);loop++) mSystem.mMemoryHandlers[loop]=mSystem.mRom;
151
}
152
else
153
{
154
for(loop=BROM_START;loop<BROM_START+(BROM_SIZE-8);loop++) mSystem.mMemoryHandlers[loop]=mSystem.mRam;
155
}
156
}
157
158
// FFFA-FFFF Vector area - Overload ROM space
159
newstate=(data&0x08)?FALSE:TRUE;
160
if(newstate!=mVectorsEnabled)
161
{
162
mVectorsEnabled=newstate;
163
164
if(mVectorsEnabled)
165
{
166
for(loop=VECTOR_START;loop<VECTOR_START+VECTOR_SIZE;loop++) mSystem.mMemoryHandlers[loop]=mSystem.mRom;
167
}
168
else
169
{
170
for(loop=VECTOR_START;loop<VECTOR_START+VECTOR_SIZE;loop++) mSystem.mMemoryHandlers[loop]=mSystem.mRam;
171
}
172
}
173
174
175
}
176
177
INLINE uint8 CMemMap::Peek(uint32 addr)
178
{
179
uint8 retval=0;
180
181
retval+=(mSusieEnabled)?0:0x01;
182
retval+=(mMikieEnabled)?0:0x02;
183
retval+=(mRomEnabled)?0:0x04;
184
retval+=(mVectorsEnabled)?0:0x08;
185
TRACE_MEMMAP1("Peek() - Data %02x",retval);
186
return retval;
187
}
188
189
SYNCFUNC(CMemMap)
190
{
191
NSS(mMikieEnabled);
192
NSS(mSusieEnabled);
193
NSS(mRomEnabled);
194
NSS(mVectorsEnabled);
195
196
if (isReader)
197
{
198
// force regenerate memory handlers
199
uint8 current = Peek(0);
200
Poke(0, ~current);
201
Poke(0, current);
202
}
203
}
204
205