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

« back to all changes in this revision

Viewing changes to src/emucore/Cart3F.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: Cart3F.cxx,v 1.18 2008/03/28 23:29:13 stephena Exp $
 
17
// $Id: Cart3F.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 "TIA.hxx"
30
32
  myImage = new uInt8[mySize];
31
33
 
32
34
  // Copy the ROM image into my buffer
33
 
  for(uInt32 addr = 0; addr < mySize; ++addr)
34
 
  {
35
 
    myImage[addr] = image[addr];
36
 
  }
 
35
  memcpy(myImage, image, mySize);
 
36
 
 
37
  // Remember startup bank
 
38
  myStartBank = 0;
37
39
}
38
40
 
39
41
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
45
47
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
46
48
void Cartridge3F::reset()
47
49
{
48
 
  // We'll map bank 0 into the first segment upon reset
49
 
  bank(0);
 
50
  // We'll map the startup bank into the first segment upon reset
 
51
  bank(myStartBank);
50
52
}
51
53
 
52
54
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
62
64
  // Set the page accessing methods for the hot spots (for 100% emulation
63
65
  // we need to chain any accesses below 0x40 to the TIA. Our poke() method
64
66
  // does this via mySystem->tiaPoke(...), at least until we come up with a
65
 
  // cleaner way to do it.)
 
67
  // cleaner way to do it).
66
68
  System::PageAccess access;
 
69
  access.directPeekBase = 0;
 
70
  access.directPokeBase = 0;
 
71
  access.device = this;
 
72
  access.type = System::PA_READWRITE;
67
73
  for(uInt32 i = 0x00; i < 0x40; i += (1 << shift))
68
 
  {
69
 
    access.directPeekBase = 0;
70
 
    access.directPokeBase = 0;
71
 
    access.device = this;
72
74
    mySystem->setPageAccess(i >> shift, access);
73
 
  }
74
75
 
75
76
  // Setup the second segment to always point to the last ROM slice
 
77
  access.directPokeBase = 0;
 
78
  access.device = this;
 
79
  access.type = System::PA_READ;
76
80
  for(uInt32 j = 0x1800; j < 0x2000; j += (1 << shift))
77
81
  {
78
 
    access.device = this;
79
82
    access.directPeekBase = &myImage[(mySize - 2048) + (j & 0x07FF)];
80
 
    access.directPokeBase = 0;
81
83
    mySystem->setPageAccess(j >> shift, access);
82
84
  }
83
85
 
84
 
  // Install pages for bank 0 into the first segment
85
 
  bank(0);
 
86
  // Install pages for startup bank into the first segment
 
87
  bank(myStartBank);
86
88
}
87
89
 
88
90
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
89
91
uInt8 Cartridge3F::peek(uInt16 address)
90
92
{
91
 
  address = address & 0x0FFF;
 
93
  address &= 0x0FFF;
92
94
 
93
95
  if(address < 0x0800)
94
96
  {
95
 
    return myImage[(address & 0x07FF) + myCurrentBank * 2048];
 
97
    return myImage[(address & 0x07FF) + (myCurrentBank << 11)];
96
98
  }
97
99
  else
98
100
  {
101
103
}
102
104
 
103
105
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
104
 
void Cartridge3F::poke(uInt16 address, uInt8 value)
 
106
bool Cartridge3F::poke(uInt16 address, uInt8 value)
105
107
{
106
 
  address = address & 0x0FFF;
 
108
  address &= 0x0FFF;
107
109
 
108
110
  // Switch banks if necessary
109
111
  if(address <= 0x003F)
111
113
    bank(value);
112
114
  }
113
115
 
 
116
  // Pass the poke through to the TIA. In a real Atari, both the cart and the
 
117
  // TIA see the address lines, and both react accordingly. In Stella, each
 
118
  // 64-byte chunk of address space is "owned" by only one device. If we
 
119
  // don't chain the poke to the TIA, then the TIA can't see it...
114
120
  mySystem->tia().poke(address, value);
 
121
 
 
122
  return false;
115
123
}
116
124
 
117
125
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
118
126
void Cartridge3F::bank(uInt16 bank)
119
127
120
 
  if(myBankLocked) return;
 
128
  if(bankLocked()) return;
121
129
 
122
130
  // Make sure the bank they're asking for is reasonable
123
 
  if((uInt32)bank * 2048 < mySize)
 
131
  if(((uInt32)bank << 11) < mySize)
124
132
  {
125
133
    myCurrentBank = bank;
126
134
  }
128
136
  {
129
137
    // Oops, the bank they're asking for isn't valid so let's wrap it
130
138
    // around to a valid bank number
131
 
    myCurrentBank = bank % (mySize / 2048);
 
139
    myCurrentBank = bank % (mySize >> 11);
132
140
  }
133
141
 
134
 
  uInt32 offset = myCurrentBank * 2048;
 
142
  uInt32 offset = myCurrentBank << 11;
135
143
  uInt16 shift = mySystem->pageShift();
136
144
 
137
145
  // Setup the page access methods for the current bank
138
146
  System::PageAccess access;
 
147
  access.directPokeBase = 0;
139
148
  access.device = this;
140
 
  access.directPokeBase = 0;
 
149
  access.type = System::PA_READ;
141
150
 
142
151
  // Map ROM image into the system
143
152
  for(uInt32 address = 0x1000; address < 0x1800; address += (1 << shift))
145
154
    access.directPeekBase = &myImage[offset + (address & 0x07FF)];
146
155
    mySystem->setPageAccess(address >> shift, access);
147
156
  }
 
157
  myBankChanged = true;
148
158
}
149
159
 
150
160
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
151
 
int Cartridge3F::bank()
 
161
uInt16 Cartridge3F::bank() const
152
162
{
153
163
  return myCurrentBank;
154
164
}
155
165
 
156
166
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
157
 
int Cartridge3F::bankCount()
 
167
uInt16 Cartridge3F::bankCount() const
158
168
{
159
 
  return mySize / 2048;
 
169
  return mySize >> 11;
160
170
}
161
171
 
162
172
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
163
173
bool Cartridge3F::patch(uInt16 address, uInt8 value)
164
174
{
165
 
  address = address & 0x0FFF;
 
175
  address &= 0x0FFF;
 
176
 
166
177
  if(address < 0x0800)
167
 
  {
168
 
    myImage[(address & 0x07FF) + myCurrentBank * 2048] = value;
169
 
  }
 
178
    myImage[(address & 0x07FF) + (myCurrentBank << 11)] = value;
170
179
  else
171
 
  {
172
180
    myImage[(address & 0x07FF) + mySize - 2048] = value;
173
 
  }
174
 
  return true;
 
181
 
 
182
  return myBankChanged = true;
175
183
176
184
 
177
185
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
178
 
uInt8* Cartridge3F::getImage(int& size)
 
186
const uInt8* Cartridge3F::getImage(int& size) const
179
187
{
180
188
  size = mySize;
181
 
  return &myImage[0];
 
189
  return myImage;
182
190
}
183
191
 
184
192
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
185
193
bool Cartridge3F::save(Serializer& out) const
186
194
{
187
 
  string cart = name();
 
195
  const string& cart = name();
188
196
 
189
197
  try
190
198
  {
193
201
  }
194
202
  catch(const char* msg)
195
203
  {
196
 
    cerr << msg << endl;
197
 
    return false;
198
 
  }
199
 
  catch(...)
200
 
  {
201
 
    cerr << "Unknown error in save state for " << cart << endl;
 
204
    cerr << "ERROR: Cartridge3F::save" << endl << "  " << msg << endl;
202
205
    return false;
203
206
  }
204
207
 
206
209
}
207
210
 
208
211
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
209
 
bool Cartridge3F::load(Deserializer& in)
 
212
bool Cartridge3F::load(Serializer& in)
210
213
{
211
 
  string cart = name();
 
214
  const string& cart = name();
212
215
 
213
216
  try
214
217
  {
219
222
  }
220
223
  catch(const char* msg)
221
224
  {
222
 
    cerr << msg << endl;
223
 
    return false;
224
 
  }
225
 
  catch(...)
226
 
  {
227
 
    cerr << "Unknown error in load state for " << cart << endl;
 
225
    cerr << "ERROR: Cartridge3F::load" << endl << "  " << msg << endl;
228
226
    return false;
229
227
  }
230
228