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

« back to all changes in this revision

Viewing changes to src/emucore/M6532.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: M6532.cxx,v 1.27 2008/05/22 17:54:54 stephena Exp $
 
17
// $Id: M6532.cxx 2012 2010-04-14 22:35:46Z stephena $
17
18
//============================================================================
18
19
 
19
 
#include <assert.h>
 
20
#include <cassert>
 
21
#include <iostream>
 
22
 
20
23
#include "Console.hxx"
21
 
#include "M6532.hxx"
22
 
#include "Random.hxx"
23
24
#include "Switches.hxx"
24
25
#include "System.hxx"
25
 
#include "Serializer.hxx"
26
 
#include "Deserializer.hxx"
27
 
#include <iostream>
 
26
 
 
27
#include "M6532.hxx"
28
28
 
29
29
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
30
30
M6532::M6532(const Console& console)
31
31
  : myConsole(console)
32
32
{
 
33
}
 
34
 
 
35
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 
36
M6532::~M6532()
 
37
{
 
38
}
 
39
 
 
40
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 
41
void M6532::reset()
 
42
{
33
43
  // Randomize the 128 bytes of memory
34
 
  class Random random;
35
 
 
36
44
  for(uInt32 t = 0; t < 128; ++t)
37
 
  {
38
 
    myRAM[t] = random.next();
39
 
  }
40
 
 
41
 
  // Initialize other data members
42
 
  reset();
43
 
}
44
 
 
45
 
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
46
 
M6532::~M6532()
47
 
{
48
 
}
49
 
 
50
 
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
51
 
void M6532::reset()
52
 
{
53
 
  class Random random;
 
45
    myRAM[t] = mySystem->randGenerator().next();
54
46
 
55
47
  // The timer absolutely cannot be initialized to zero; some games will
56
48
  // loop or hang (notably Solaris and H.E.R.O.)
57
 
  myTimer = (0xff - (random.next() % 0xfe)) << 10;
 
49
  myTimer = (0xff - (mySystem->randGenerator().next() % 0xfe)) << 10;
58
50
  myIntervalShift = 10;
59
51
  myCyclesWhenTimerSet = 0;
60
52
  myInterruptEnabled = false;
99
91
  
100
92
  // All accesses are to the given device
101
93
  System::PageAccess access;
 
94
  access.directPeekBase = 0; 
 
95
  access.directPokeBase = 0;
102
96
  access.device = &device;
 
97
  access.type = System::PA_READWRITE;
103
98
 
104
99
  // We're installing in a 2600 system
105
100
  for(int address = 0; address < 8192; address += (1 << shift))
106
 
  {
107
101
    if((address & 0x1080) == 0x0080)
108
 
    {
109
 
      access.directPeekBase = 0; 
110
 
      access.directPokeBase = 0;
111
102
      mySystem->setPageAccess(address >> shift, access);
112
 
    }
113
 
  }
114
103
}
115
104
 
116
105
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
196
185
    case 0x05:    // Interrupt Flag
197
186
    case 0x07:
198
187
    {
199
 
      if((timerClocks() >= 0) || myInterruptEnabled && myInterruptTriggered)
 
188
      if((timerClocks() >= 0) || (myInterruptEnabled && myInterruptTriggered))
200
189
        return 0x00;
201
190
      else
202
191
        return 0x80;
213
202
}
214
203
 
215
204
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
216
 
void M6532::poke(uInt16 addr, uInt8 value)
 
205
bool M6532::poke(uInt16 addr, uInt8 value)
217
206
{
218
207
  // Access RAM directly.  Originally, accesses to RAM could bypass
219
208
  // this method and its pages could be installed directly into the
222
211
  if((addr & 0x1080) == 0x0080 && (addr & 0x0200) == 0x0000)
223
212
  {
224
213
    myRAM[addr & 0x007f] = value;
225
 
    return;
 
214
    return true;
226
215
  }
227
216
 
228
217
  // A2 distinguishes I/O registers from the timer
253
242
      }
254
243
 
255
244
      default:    // Port B I/O & DDR Registers (Console switches)
256
 
        break;    // hardwired as read-only
 
245
        return false;  // hardwired as read-only
257
246
    }
258
247
  }
 
248
  return true;
259
249
}
260
250
 
261
251
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
301
291
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
302
292
bool M6532::save(Serializer& out) const
303
293
{
304
 
  string device = name();
 
294
  const string& device = name();
305
295
 
306
296
  try
307
297
  {
326
316
    out.putByte((char)myOutTimer[2]);
327
317
    out.putByte((char)myOutTimer[3]);
328
318
  }
329
 
  catch(char *msg)
330
 
  {
331
 
    cerr << msg << endl;
332
 
    return false;
333
 
  }
334
 
  catch(...)
335
 
  {
336
 
    cerr << "Unknown error in save state for " << device << endl;
 
319
  catch(const char* msg)
 
320
  {
 
321
    cerr << "ERROR: M6532::save" << endl << "  " << msg << endl;
337
322
    return false;
338
323
  }
339
324
 
341
326
}
342
327
 
343
328
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
344
 
bool M6532::load(Deserializer& in)
 
329
bool M6532::load(Serializer& in)
345
330
{
346
 
  string device = name();
 
331
  const string& device = name();
347
332
 
348
333
  try
349
334
  {
369
354
    myOutTimer[2] = (uInt8) in.getByte();
370
355
    myOutTimer[3] = (uInt8) in.getByte();
371
356
  }
372
 
  catch(char *msg)
373
 
  {
374
 
    cerr << msg << endl;
375
 
    return false;
376
 
  }
377
 
  catch(...)
378
 
  {
379
 
    cerr << "Unknown error in load state for " << device << endl;
 
357
  catch(const char* msg)
 
358
  {
 
359
    cerr << "ERROR: M6532::load" << endl << "  " << msg << endl;
380
360
    return false;
381
361
  }
382
362