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

« back to all changes in this revision

Viewing changes to src/emucore/m6502/src/System.hxx

  • 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:
1
 
//============================================================================
2
 
//
3
 
// MM     MM  6666  555555  0000   2222
4
 
// MMMM MMMM 66  66 55     00  00 22  22
5
 
// MM MMM MM 66     55     00  00     22
6
 
// MM  M  MM 66666  55555  00  00  22222  --  "A 6502 Microprocessor Emulator"
7
 
// MM     MM 66  66     55 00  00 22
8
 
// MM     MM 66  66 55  55 00  00 22
9
 
// MM     MM  6666   5555   0000  222222
10
 
//
11
 
// Copyright (c) 1995-2008 by Bradford W. Mott and the Stella team
12
 
//
13
 
// See the file "license" for information on usage and redistribution of
14
 
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
15
 
//
16
 
// $Id: System.hxx,v 1.19 2008/02/19 12:33:07 stephena Exp $
17
 
//============================================================================
18
 
 
19
 
#ifndef SYSTEM_HXX
20
 
#define SYSTEM_HXX
21
 
 
22
 
class Device;
23
 
class M6502;
24
 
class M6532;
25
 
class TIA;
26
 
class NullDevice;
27
 
 
28
 
#include "bspf.hxx"
29
 
#include "Device.hxx"
30
 
#include "NullDev.hxx"
31
 
#include "Serializable.hxx"
32
 
 
33
 
/**
34
 
  This class represents a system consisting of a 6502 microprocessor
35
 
  and a set of devices.  The devices are mapped into an addressing
36
 
  space of 2^n bytes (1 <= n <= 16).  The addressing space is broken
37
 
  into 2^m byte pages (1 <= m <= n), where a page is the smallest unit
38
 
  a device can use when installing itself in the system.
39
 
 
40
 
  In general the addressing space will be 8192 (2^13) bytes for a 
41
 
  6507 based system and 65536 (2^16) bytes for a 6502 based system.
42
 
 
43
 
  TODO: To allow for dynamic code generation we probably need to
44
 
        add a tag to each page that indicates if it is read only
45
 
        memory.  We also need to notify the processor anytime a
46
 
        page access method is changed so that it can clear the
47
 
        dynamic code for that page of memory.
48
 
 
49
 
  @author  Bradford W. Mott
50
 
  @version $Id: System.hxx,v 1.19 2008/02/19 12:33:07 stephena Exp $
51
 
*/
52
 
class System : public Serializable
53
 
{
54
 
  public:
55
 
    /**
56
 
      Create a new system with an addressing space of 2^n bytes and
57
 
      pages of 2^m bytes.
58
 
 
59
 
      @param n Log base 2 of the addressing space size
60
 
      @param m Log base 2 of the page size
61
 
    */
62
 
    System(uInt16 n, uInt16 m);
63
 
 
64
 
    /**
65
 
      Destructor
66
 
    */
67
 
    virtual ~System();
68
 
 
69
 
  public:
70
 
    /**
71
 
      Reset the system cycle counter, the attached devices, and the
72
 
      attached processor of the system.
73
 
    */
74
 
    void reset();
75
 
 
76
 
    /**
77
 
      Attach the specified device and claim ownership of it.  The device 
78
 
      will be asked to install itself.
79
 
 
80
 
      @param device The device to attach to the system
81
 
    */
82
 
    void attach(Device* device);
83
 
 
84
 
    /**
85
 
      Attach the specified processor and claim ownership of it.  The
86
 
      processor will be asked to install itself.
87
 
 
88
 
      @param m6502 The 6502 microprocessor to attach to the system
89
 
    */
90
 
    void attach(M6502* m6502);
91
 
 
92
 
    /**
93
 
      Attach the specified processor and claim ownership of it.  The
94
 
      processor will be asked to install itself.
95
 
 
96
 
      @param m6532 The 6532 microprocessor to attach to the system
97
 
    */
98
 
    void attach(M6532* m6532);
99
 
 
100
 
    /**
101
 
      Attach the specified TIA device and claim ownership of it.  The device 
102
 
      will be asked to install itself.
103
 
 
104
 
      @param tia The TIA device to attach to the system
105
 
    */
106
 
    void attach(TIA* tia);
107
 
 
108
 
  public:
109
 
    /**
110
 
      Answer the 6502 microprocessor attached to the system.  If a
111
 
      processor has not been attached calling this function will fail.
112
 
 
113
 
      @return The attached 6502 microprocessor
114
 
    */
115
 
    M6502& m6502()
116
 
    {
117
 
      return *myM6502;
118
 
    }
119
 
 
120
 
    /**
121
 
      Answer the 6532 processor attached to the system.  If a
122
 
      processor has not been attached calling this function will fail.
123
 
 
124
 
      @return The attached 6532 microprocessor
125
 
    */
126
 
    M6532& m6532()
127
 
    {
128
 
      return *myM6532;
129
 
    }
130
 
 
131
 
    /**
132
 
      Answer the TIA device attached to the system.
133
 
 
134
 
      @return The attached TIA device
135
 
    */
136
 
    TIA& tia()
137
 
    {
138
 
      return *myTIA;
139
 
    }
140
 
 
141
 
    /**
142
 
      Get the null device associated with the system.  Every system 
143
 
      has a null device associated with it that's used by pages which 
144
 
      aren't mapped to "real" devices.
145
 
 
146
 
      @return The null device associated with the system
147
 
    */
148
 
    NullDevice& nullDevice()
149
 
    {
150
 
      return myNullDevice;
151
 
    }
152
 
 
153
 
    /**
154
 
      Get the total number of pages available in the system.
155
 
 
156
 
      @return The total number of pages available
157
 
    */
158
 
    uInt16 numberOfPages() const
159
 
    {
160
 
      return myNumberOfPages;
161
 
    }
162
 
 
163
 
    /**
164
 
      Get the amount to right shift an address by to obtain its page.
165
 
 
166
 
      @return The amount to right shift an address by to get its page
167
 
    */
168
 
    uInt16 pageShift() const
169
 
    {
170
 
      return myPageShift;
171
 
    }
172
 
 
173
 
    /**
174
 
      Get the mask to apply to an address to obtain its page offset.
175
 
 
176
 
      @return The mask to apply to an address to obtain its page offset
177
 
    */
178
 
    uInt16 pageMask() const
179
 
    {
180
 
      return myPageMask;
181
 
    }
182
 
 
183
 
  public:
184
 
    /**
185
 
      Get the number of system cycles which have passed since the last
186
 
      time cycles were reset or the system was reset.
187
 
 
188
 
      @return The number of system cycles which have passed
189
 
    */
190
 
    uInt32 cycles() const 
191
 
    { 
192
 
      return myCycles; 
193
 
    }
194
 
 
195
 
    /**
196
 
      Increment the system cycles by the specified number of cycles.
197
 
 
198
 
      @param amount The amount to add to the system cycles counter
199
 
    */
200
 
    void incrementCycles(uInt32 amount) 
201
 
    { 
202
 
      myCycles += amount; 
203
 
    }
204
 
 
205
 
    /**
206
 
      Reset the system cycle count to zero.  The first thing that
207
 
      happens is that all devices are notified of the reset by invoking 
208
 
      their systemCyclesReset method then the system cycle count is 
209
 
      reset to zero.
210
 
    */
211
 
    void resetCycles();
212
 
 
213
 
  public:
214
 
    /**
215
 
      Get the current state of the data bus in the system.  The current
216
 
      state is the last data that was accessed by the system.
217
 
 
218
 
      @return the data bus state
219
 
    */  
220
 
    inline uInt8 getDataBusState() const
221
 
    {
222
 
      return myDataBusState;
223
 
    }
224
 
 
225
 
    /**
226
 
      Get the byte at the specified address.  No masking of the
227
 
      address occurs before it's sent to the device mapped at
228
 
      the address.
229
 
 
230
 
      @return The byte at the specified address
231
 
    */
232
 
    uInt8 peek(uInt16 address);
233
 
 
234
 
    /**
235
 
      Change the byte at the specified address to the given value.
236
 
      No masking of the address occurs before it's sent to the device
237
 
      mapped at the address.
238
 
 
239
 
      @param address The address where the value should be stored
240
 
      @param value The value to be stored at the address
241
 
    */
242
 
    void poke(uInt16 address, uInt8 value);
243
 
 
244
 
    /**
245
 
      Lock/unlock the data bus. When the bus is locked, peek() and
246
 
      poke() don't update the bus state. The bus should be unlocked
247
 
      while the CPU is running (normal emulation, or when the debugger
248
 
      is stepping/advancing). It should be locked while the debugger
249
 
      is active but not running the CPU. This is so the debugger can
250
 
      use System.peek() to examine memory/registers without changing
251
 
      the state of the system.
252
 
    */
253
 
    void lockDataBus();
254
 
    void unlockDataBus();
255
 
 
256
 
  public:
257
 
    /**
258
 
      Structure used to specify access methods for a page
259
 
    */
260
 
    struct PageAccess
261
 
    {
262
 
      /**
263
 
        Pointer to a block of memory or the null pointer.  The null pointer
264
 
        indicates that the device's peek method should be invoked for reads
265
 
        to this page, while other values are the base address of an array 
266
 
        to directly access for reads to this page.
267
 
      */
268
 
      uInt8* directPeekBase;
269
 
 
270
 
      /**
271
 
        Pointer to a block of memory or the null pointer.  The null pointer
272
 
        indicates that the device's poke method should be invoked for writes
273
 
        to this page, while other values are the base address of an array 
274
 
        to directly access for pokes to this page.
275
 
      */
276
 
      uInt8* directPokeBase;
277
 
 
278
 
      /**
279
 
        Pointer to the device associated with this page or to the system's 
280
 
        null device if the page hasn't been mapped to a device
281
 
      */
282
 
      Device* device;
283
 
    };
284
 
 
285
 
    /**
286
 
      Set the page accessing method for the specified page.
287
 
 
288
 
      @param page The page accessing methods should be set for
289
 
      @param access The accessing methods to be used by the page
290
 
    */
291
 
    void setPageAccess(uInt16 page, const PageAccess& access);
292
 
 
293
 
    /**
294
 
      Get the page accessing method for the specified page.
295
 
 
296
 
      @param page The page to get accessing methods for
297
 
      @return The accessing methods used by the page
298
 
    */
299
 
    const PageAccess& getPageAccess(uInt16 page);
300
 
 
301
 
    /**
302
 
      Save the current state of this system to the given Serializer.
303
 
 
304
 
      @param out  The Serializer object to use
305
 
      @return  False on any errors, else true
306
 
    */
307
 
    bool save(Serializer& out) const;
308
 
 
309
 
    /**
310
 
      Load the current state of this system from the given Deserializer.
311
 
 
312
 
      @param in  The Deserializer object to use
313
 
      @return  False on any errors, else true
314
 
    */
315
 
    bool load(Deserializer& in);
316
 
 
317
 
    /**
318
 
      Get a descriptor for the device name (used in error checking).
319
 
 
320
 
      @return The name of the object
321
 
    */
322
 
    virtual string name() const { return "System"; }
323
 
 
324
 
  private:
325
 
    // Mask to apply to an address before accessing memory
326
 
    const uInt16 myAddressMask;
327
 
 
328
 
    // Amount to shift an address by to determine what page it's on
329
 
    const uInt16 myPageShift;
330
 
 
331
 
    // Mask to apply to an address to obtain its page offset
332
 
    const uInt16 myPageMask;
333
 
 
334
 
    // Number of pages in the system
335
 
    const uInt16 myNumberOfPages;
336
 
 
337
 
    // Pointer to a dynamically allocated array of PageAccess structures
338
 
    PageAccess* myPageAccessTable;
339
 
 
340
 
    // Array of all the devices attached to the system
341
 
    Device* myDevices[100];
342
 
 
343
 
    // Number of devices attached to the system
344
 
    uInt32 myNumberOfDevices;
345
 
 
346
 
    // 6502 processor attached to the system or the null pointer
347
 
    M6502* myM6502;
348
 
 
349
 
    // 6532 processor attached to the system or the null pointer
350
 
    M6532* myM6532;
351
 
 
352
 
    // TIA device attached to the system or the null pointer
353
 
    TIA* myTIA;
354
 
 
355
 
    // Number of system cycles executed since the last reset
356
 
    uInt32 myCycles;
357
 
 
358
 
    // Null device to use for page which are not installed
359
 
    NullDevice myNullDevice; 
360
 
 
361
 
    // The current state of the Data Bus
362
 
    uInt8 myDataBusState;
363
 
 
364
 
    // Whether or not peek() updates the data bus state. This
365
 
    // is true during normal emulation, and false when the
366
 
    // debugger is active.
367
 
    bool myDataBusLocked;
368
 
 
369
 
  private:
370
 
    // Copy constructor isn't supported by this class so make it private
371
 
    System(const System&);
372
 
 
373
 
    // Assignment operator isn't supported by this class so make it private
374
 
    System& operator = (const System&);
375
 
};
376
 
 
377
 
#endif