~ubuntu-branches/debian/squeeze/stella/squeeze

« back to all changes in this revision

Viewing changes to src/emucore/CartE0.cxx

  • Committer: Bazaar Package Importer
  • Author(s): Stephen Kitt
  • Date: 2010-07-12 23:49:36 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20100712234936-juawrr3etzhr2qpv
Tags: 3.1.2-1
* New maintainer (closes: #532039).
* New upstream version (closes: #461121):
  - includes launcher (closes: #396058).
* Fix the reference to the X Window System in the description (closes:
  #411815).
* Move to main, DFSG-free ROMs are available (see README.Debian).
* Enhance the package description.
* Drop the libslang2-dev dependency (closes: #560274).
* Remove the Encoding entry from stella.desktop.
* Avoid ignoring errors when cleaning.
* Add ${misc:Depends} to the package dependencies.
* Provide a doc-base file to install the documentation using doc-base.
* Switch to debhelper 7 with a simplified rules file.
* Use autotools-dev to provide updated configuration files.
* Update to Standards-Version 3.9.0:
  - Move to menu section Applications/Emulators.
  - Move the homepage declaration.
* Re-write the manpage.

Show diffs side-by-side

added added

removed removed

Lines of Context:
8
8
//  SS  SS   tt   ee      ll   ll  aa  aa
9
9
//   SSSS     ttt  eeeee llll llll  aaaaa
10
10
//
11
 
// Copyright (c) 1995-2008 by Bradford W. Mott and the Stella team
 
11
// Copyright (c) 1995-2010 by Bradford W. Mott, Stephen Anthony
 
12
// and the Stella Team
12
13
//
13
 
// See the file "license" for information on usage and redistribution of
 
14
// See the file "License.txt" for information on usage and redistribution of
14
15
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
15
16
//
16
 
// $Id: CartE0.cxx,v 1.16 2008/03/28 23:29:13 stephena Exp $
 
17
// $Id: CartE0.cxx 2012 2010-04-14 22:35:46Z stephena $
17
18
//============================================================================
18
19
 
19
20
#include <cassert>
 
21
#include <cstring>
20
22
 
21
23
#include "System.hxx"
22
24
#include "CartE0.hxx"
25
27
CartridgeE0::CartridgeE0(const uInt8* image)
26
28
{
27
29
  // Copy the ROM image into my buffer
28
 
  for(uInt32 addr = 0; addr < 8192; ++addr)
29
 
  {
30
 
    myImage[addr] = image[addr];
31
 
  }
 
30
  memcpy(myImage, image, 8192);
32
31
}
33
32
 
34
33
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
43
42
  segmentZero(4);
44
43
  segmentOne(5);
45
44
  segmentTwo(6);
 
45
 
 
46
  myBankChanged = true;
46
47
}
47
48
 
48
49
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
56
57
  assert(((0x1000 & mask) == 0) && ((0x1400 & mask) == 0) &&
57
58
      ((0x1800 & mask) == 0) && ((0x1C00 & mask) == 0));
58
59
 
 
60
  System::PageAccess access;
 
61
 
59
62
  // Set the page acessing methods for the first part of the last segment
60
 
  System::PageAccess access;
61
63
  access.directPokeBase = 0;
62
64
  access.device = this;
 
65
  access.type = System::PA_READ;
63
66
  for(uInt32 i = 0x1C00; i < (0x1FE0U & ~mask); i += (1 << shift))
64
67
  {
65
68
    access.directPeekBase = &myImage[7168 + (i & 0x03FF)];
71
74
  access.directPeekBase = 0;
72
75
  access.directPokeBase = 0;
73
76
  access.device = this;
 
77
  access.type = System::PA_READ;
74
78
  for(uInt32 j = (0x1FE0 & ~mask); j < 0x2000; j += (1 << shift))
75
 
  {
76
79
    mySystem->setPageAccess(j >> shift, access);
77
 
  }
78
80
 
79
81
  // Install some default slices for the other segments
80
82
  segmentZero(4);
85
87
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
86
88
uInt8 CartridgeE0::peek(uInt16 address)
87
89
{
88
 
  address = address & 0x0FFF;
 
90
  address &= 0x0FFF;
89
91
 
90
92
  // Switch banks if necessary
91
93
  if((address >= 0x0FE0) && (address <= 0x0FE7))
105
107
}
106
108
 
107
109
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
108
 
void CartridgeE0::poke(uInt16 address, uInt8)
 
110
bool CartridgeE0::poke(uInt16 address, uInt8)
109
111
{
110
 
  address = address & 0x0FFF;
 
112
  address &= 0x0FFF;
111
113
 
112
114
  // Switch banks if necessary
113
115
  if((address >= 0x0FE0) && (address <= 0x0FE7))
122
124
  {
123
125
    segmentTwo(address & 0x0007);
124
126
  }
 
127
  return false;
125
128
}
126
129
 
127
130
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
128
131
void CartridgeE0::segmentZero(uInt16 slice)
129
132
130
 
  if(myBankLocked) return;
 
133
  if(bankLocked()) return;
131
134
 
132
135
  // Remember the new slice
133
136
  myCurrentSlice[0] = slice;
136
139
 
137
140
  // Setup the page access methods for the current bank
138
141
  System::PageAccess access;
 
142
  access.directPokeBase = 0;
139
143
  access.device = this;
140
 
  access.directPokeBase = 0;
 
144
  access.type = System::PA_READ;
141
145
 
142
146
  for(uInt32 address = 0x1000; address < 0x1400; address += (1 << shift))
143
147
  {
144
148
    access.directPeekBase = &myImage[offset + (address & 0x03FF)];
145
149
    mySystem->setPageAccess(address >> shift, access);
146
150
  }
 
151
  myBankChanged = true;
147
152
}
148
153
 
149
154
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
150
155
void CartridgeE0::segmentOne(uInt16 slice)
151
156
152
 
  if(myBankLocked) return;
 
157
  if(bankLocked()) return;
153
158
 
154
159
  // Remember the new slice
155
160
  myCurrentSlice[1] = slice;
158
163
 
159
164
  // Setup the page access methods for the current bank
160
165
  System::PageAccess access;
 
166
  access.directPokeBase = 0;
161
167
  access.device = this;
162
 
  access.directPokeBase = 0;
 
168
  access.type = System::PA_READ;
163
169
 
164
170
  for(uInt32 address = 0x1400; address < 0x1800; address += (1 << shift))
165
171
  {
166
172
    access.directPeekBase = &myImage[offset + (address & 0x03FF)];
167
173
    mySystem->setPageAccess(address >> shift, access);
168
174
  }
 
175
  myBankChanged = true;
169
176
}
170
177
 
171
178
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
172
179
void CartridgeE0::segmentTwo(uInt16 slice)
173
180
174
 
  if(myBankLocked) return;
 
181
  if(bankLocked()) return;
175
182
 
176
183
  // Remember the new slice
177
184
  myCurrentSlice[2] = slice;
180
187
 
181
188
  // Setup the page access methods for the current bank
182
189
  System::PageAccess access;
 
190
  access.directPokeBase = 0;
183
191
  access.device = this;
184
 
  access.directPokeBase = 0;
 
192
  access.type = System::PA_READ;
185
193
 
186
194
  for(uInt32 address = 0x1800; address < 0x1C00; address += (1 << shift))
187
195
  {
188
196
    access.directPeekBase = &myImage[offset + (address & 0x03FF)];
189
197
    mySystem->setPageAccess(address >> shift, access);
190
198
  }
 
199
  myBankChanged = true;
191
200
}
192
201
 
193
202
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
197
206
}
198
207
 
199
208
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
200
 
int CartridgeE0::bank()
 
209
uInt16 CartridgeE0::bank() const
201
210
{
202
211
  // Doesn't support bankswitching in the normal sense
203
212
  return 0;
204
213
}
205
214
 
206
215
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
207
 
int CartridgeE0::bankCount()
 
216
uInt16 CartridgeE0::bankCount() const
208
217
{
209
218
  // Doesn't support bankswitching in the normal sense
 
219
  // There is one 'virtual' bank that can change in many different ways
210
220
  return 1;
211
221
}
212
222
 
213
223
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
214
224
bool CartridgeE0::patch(uInt16 address, uInt8 value)
215
225
{
216
 
  address = address & 0x0FFF;
 
226
  address &= 0x0FFF;
217
227
  myImage[(myCurrentSlice[address >> 10] << 10) + (address & 0x03FF)] = value;
218
228
  return true;
219
229
220
230
 
221
231
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
222
 
uInt8* CartridgeE0::getImage(int& size)
 
232
const uInt8* CartridgeE0::getImage(int& size) const
223
233
{
224
234
  size = 8192;
225
 
  return &myImage[0];
 
235
  return myImage;
226
236
}
227
237
 
228
238
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
229
239
bool CartridgeE0::save(Serializer& out) const
230
240
{
231
 
  string cart = name();
 
241
  const string& cart = name();
232
242
 
233
243
  try
234
244
  {
240
250
  }
241
251
  catch(const char* msg)
242
252
  {
243
 
    cerr << msg << endl;
244
 
    return false;
245
 
  }
246
 
  catch(...)
247
 
  {
248
 
    cerr << "Unknown error in save state for " << cart << endl;
 
253
    cerr << "ERROR: CartridgeE0::save" << endl << "  " << msg << endl;
249
254
    return false;
250
255
  }
251
256
 
253
258
}
254
259
 
255
260
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
256
 
bool CartridgeE0::load(Deserializer& in)
 
261
bool CartridgeE0::load(Serializer& in)
257
262
{
258
 
  string cart = name();
 
263
  const string& cart = name();
259
264
 
260
265
  try
261
266
  {
268
273
  }
269
274
  catch(const char* msg)
270
275
  {
271
 
    cerr << msg << endl;
272
 
    return false;
273
 
  }
274
 
  catch(...)
275
 
  {
276
 
    cerr << "Unknown error in load state for " << cart << endl;
 
276
    cerr << "ERROR: CartridgeE0::load" << endl << "  " << msg << endl;
277
277
    return false;
278
278
  }
279
279