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

« back to all changes in this revision

Viewing changes to src/emucore/CartSB.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
17
// $Id: CartSB.cxx,v 1.0 2007/10/11
17
18
//============================================================================
18
19
 
19
20
#include <cassert>
 
21
#include <cstring>
20
22
 
21
23
#include "System.hxx"
22
24
#include "CartSB.hxx"
23
25
 
24
26
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
25
27
CartridgeSB::CartridgeSB(const uInt8* image, uInt32 size)
26
 
  : mySize(size),
27
 
    myLastBank((mySize>>12)-1)
 
28
  : mySize(size)
28
29
{
29
30
  // Allocate array for the ROM image
30
31
  myImage = new uInt8[mySize];
31
32
 
32
33
  // Copy the ROM image into my buffer
33
 
  for(uInt32 addr = 0; addr < mySize; ++addr)
34
 
    myImage[addr] = image[addr];
 
34
  memcpy(myImage, image, mySize);
 
35
 
 
36
  // Remember startup bank
 
37
  myStartBank = (mySize >> 12) - 1;
35
38
}
36
39
 
37
40
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
43
46
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
44
47
void CartridgeSB::reset()
45
48
{
46
 
  // Upon reset we switch to the last bank
47
 
  bank(myLastBank);
 
49
  // Upon reset we switch to the startup bank
 
50
  bank(myStartBank);
48
51
}
49
52
 
50
53
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
68
71
  myHotSpotPageAccess[6] = mySystem->getPageAccess(0x0E00 >> shift);
69
72
  myHotSpotPageAccess[7] = mySystem->getPageAccess(0x0F00 >> shift);
70
73
 
 
74
  System::PageAccess access;
 
75
 
71
76
  // Set the page accessing methods for the hot spots
72
 
  System::PageAccess access;
 
77
  access.directPeekBase = 0;
 
78
  access.directPokeBase = 0;
 
79
  access.device = this;
 
80
  access.type = System::PA_READ;
73
81
  for(uInt32 i = 0x0800; i < 0x0FFF; i += (1 << shift))
74
 
  {
75
 
    access.directPeekBase = 0;
76
 
    access.directPokeBase = 0;
77
 
    access.device = this;
78
82
    mySystem->setPageAccess(i >> shift, access);
79
 
  }
80
83
 
81
84
  // Install pages for startup bank
82
 
  bank(myLastBank);
 
85
  bank(myStartBank);
83
86
}
84
87
 
85
88
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
86
89
uInt8 CartridgeSB::peek(uInt16 address)
87
90
{
88
 
  address = address & (0x17FF+(mySize>>12));
 
91
  address = address & (0x17FF + (mySize >> 12));
89
92
 
90
93
  // Switch banks if necessary
91
94
  if ((address & 0x1800) == 0x0800)
92
 
    bank(address & myLastBank);
 
95
    bank(address & myStartBank);
93
96
 
94
97
  if(!(address & 0x1000))
95
98
  {
103
106
}
104
107
 
105
108
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
106
 
void CartridgeSB::poke(uInt16 address, uInt8 value)
 
109
bool CartridgeSB::poke(uInt16 address, uInt8 value)
107
110
{
108
 
  address = address & (0x17FF+(mySize>>12));
 
111
  address = address & (0x17FF + (mySize >> 12));
109
112
 
110
113
  // Switch banks if necessary
111
114
  if((address & 0x1800) == 0x0800)
112
 
    bank(address & myLastBank);
 
115
    bank(address & myStartBank);
113
116
 
114
117
  if(!(address & 0x1000))
115
118
  {
118
121
    int hotspot = ((address & 0x0F00) >> 8) - 8;
119
122
    myHotSpotPageAccess[hotspot].device->poke(address, value);
120
123
  }
 
124
  return false;
121
125
}
122
126
 
123
127
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
124
128
void CartridgeSB::bank(uInt16 bank)
125
129
126
 
  if(myBankLocked) return;
 
130
  if(bankLocked()) return;
127
131
 
128
132
  // Remember what bank we're in
129
133
  myCurrentBank = bank;
130
 
  uInt32 offset = myCurrentBank * 4096;
 
134
  uInt32 offset = myCurrentBank << 12;
131
135
  uInt16 shift = mySystem->pageShift();
132
136
 
133
137
  // Setup the page access methods for the current bank
134
138
  System::PageAccess access;
 
139
  access.directPokeBase = 0;
135
140
  access.device = this;
136
 
  access.directPokeBase = 0;
 
141
  access.type = System::PA_READ;
137
142
 
138
143
  // Map ROM image into the system
139
144
  for(uInt32 address = 0x1000; address < 0x2000; address += (1 << shift))
141
146
    access.directPeekBase = &myImage[offset + (address & 0x0FFF)];
142
147
    mySystem->setPageAccess(address >> shift, access);
143
148
  }
 
149
  myBankChanged = true;
144
150
}
145
151
 
146
152
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
147
 
int CartridgeSB::bank()
 
153
uInt16 CartridgeSB::bank() const
148
154
{
149
155
  return myCurrentBank;
150
156
}
151
157
 
152
158
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
153
 
int CartridgeSB::bankCount()
 
159
uInt16 CartridgeSB::bankCount() const
154
160
{
155
 
  return mySize>>12;
 
161
  return mySize >> 12;
156
162
}
157
163
 
158
164
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
159
165
bool CartridgeSB::patch(uInt16 address, uInt8 value)
160
166
{
161
 
  address &= 0x0fff;
162
 
  myImage[myCurrentBank * 4096] = value;
163
 
  bank(myCurrentBank); // TODO: see if this is really necessary
164
 
  return true;
 
167
  myImage[(myCurrentBank << 12) + (address & 0x0FFF)] = value;
 
168
  return myBankChanged = true;
165
169
166
170
 
167
 
 
168
171
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
169
 
uInt8* CartridgeSB::getImage(int& size)
 
172
const uInt8* CartridgeSB::getImage(int& size) const
170
173
{
171
174
  size = mySize;
172
 
  return &myImage[0];
 
175
  return myImage;
173
176
}
174
177
 
175
178
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
176
179
bool CartridgeSB::save(Serializer& out) const
177
180
{
178
 
  string cart = name();
 
181
  const string& cart = name();
179
182
 
180
183
  try
181
184
  {
182
185
    out.putString(cart);
183
186
    out.putInt(myCurrentBank);
184
187
  }
185
 
  catch(char *msg)
186
 
  {
187
 
    cerr << msg << endl;
188
 
    return false;
189
 
  }
190
 
  catch(...)
191
 
  {
192
 
    cerr << "Unknown error in save state for " << cart << endl;
 
188
  catch(const char* msg)
 
189
  {
 
190
    cerr << "ERROR: CartridgeSB::save" << endl << "  " << msg << endl;
193
191
    return false;
194
192
  }
195
193
 
197
195
}
198
196
 
199
197
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
200
 
bool CartridgeSB::load(Deserializer& in)
 
198
bool CartridgeSB::load(Serializer& in)
201
199
{
202
 
  string cart = name();
 
200
  const string& cart = name();
203
201
 
204
202
  try
205
203
  {
208
206
 
209
207
    myCurrentBank = (uInt16)in.getInt();
210
208
  }
211
 
  catch(char *msg)
212
 
  {
213
 
    cerr << msg << endl;
214
 
    return false;
215
 
  }
216
 
  catch(...)
217
 
  {
218
 
    cerr << "Unknown error in load state for " << cart << endl;
 
209
  catch(const char* msg)
 
210
  {
 
211
    cerr << "ERROR: CartridgeSB::load" << endl << "  " << msg << endl;
219
212
    return false;
220
213
  }
221
214