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

« back to all changes in this revision

Viewing changes to src/emucore/CartF6SC.cxx

  • Committer: Bazaar Package Importer
  • Author(s): Tom Lear
  • Date: 1999-11-06 16:41:05 UTC
  • Revision ID: james.westby@ubuntu.com-19991106164105-iygopamo5mpcozvx
Tags: upstream-1.1
ImportĀ upstreamĀ versionĀ 1.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//============================================================================
 
2
//
 
3
//   SSSS    tt          lll  lll       
 
4
//  SS  SS   tt           ll   ll        
 
5
//  SS     tttttt  eeee   ll   ll   aaaa 
 
6
//   SSSS    tt   ee  ee  ll   ll      aa
 
7
//      SS   tt   eeeeee  ll   ll   aaaaa  --  "An Atari 2600 VCS Emulator"
 
8
//  SS  SS   tt   ee      ll   ll  aa  aa
 
9
//   SSSS     ttt  eeeee llll llll  aaaaa
 
10
//
 
11
// Copyright (c) 1995-1998 by Bradford W. Mott
 
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: CartF6SC.cxx,v 1.2 1998/07/15 20:30:48 bwmott Exp $
 
17
//============================================================================
 
18
 
 
19
#include <assert.h>
 
20
#include "CartF6SC.hxx"
 
21
#include "Random.hxx"
 
22
#include "System.hxx"
 
23
 
 
24
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 
25
CartridgeF6SC::CartridgeF6SC(const uInt8* image)
 
26
{
 
27
  // Copy the ROM image into my buffer
 
28
  for(uInt32 addr = 0; addr < 16384; ++addr)
 
29
  {
 
30
    myImage[addr] = image[addr];
 
31
  }
 
32
 
 
33
  // Initialize RAM with random values
 
34
  Random random;
 
35
  for(uInt32 i = 0; i < 128; ++i)
 
36
  {
 
37
    myRAM[i] = random.next();
 
38
  }
 
39
}
 
40
 
 
41
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 
42
CartridgeF6SC::~CartridgeF6SC()
 
43
{
 
44
}
 
45
 
 
46
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 
47
const char* CartridgeF6SC::name() const
 
48
{
 
49
  return "CartridgeF6SC";
 
50
}
 
51
 
 
52
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 
53
void CartridgeF6SC::reset()
 
54
{
 
55
  // Upon reset we switch to bank 0
 
56
  bank(0);
 
57
}
 
58
 
 
59
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 
60
void CartridgeF6SC::install(System& system)
 
61
{
 
62
  mySystem = &system;
 
63
  uInt16 shift = mySystem->pageShift();
 
64
  uInt16 mask = mySystem->pageMask();
 
65
 
 
66
  // Make sure the system we're being installed in has a page size that'll work
 
67
  assert(((0x1080 & mask) == 0) && ((0x1100 & mask) == 0));
 
68
 
 
69
  // Set the page accessing methods for the hot spots
 
70
  System::PageAccess access;
 
71
  for(uInt32 i = (0x1FF6 & ~mask); i < 0x2000; i += (1 << shift))
 
72
  {
 
73
    access.directPeekBase = 0;
 
74
    access.directPokeBase = 0;
 
75
    access.device = this;
 
76
    mySystem->setPageAccess(i >> shift, access);
 
77
  }
 
78
 
 
79
  // Set the page accessing method for the RAM writing pages
 
80
  for(uInt32 j = 0x1000; j < 0x1080; j += (1 << shift))
 
81
  {
 
82
    access.device = this;
 
83
    access.directPeekBase = 0;
 
84
    access.directPokeBase = &myRAM[j & 0x007F];
 
85
    mySystem->setPageAccess(j >> shift, access);
 
86
  }
 
87
 
 
88
  // Set the page accessing method for the RAM reading pages
 
89
  for(uInt32 k = 0x1080; k < 0x1100; k += (1 << shift))
 
90
  {
 
91
    access.device = this;
 
92
    access.directPeekBase = &myRAM[k & 0x007F];
 
93
    access.directPokeBase = 0;
 
94
    mySystem->setPageAccess(k >> shift, access);
 
95
  }
 
96
 
 
97
  // Install pages for bank 0
 
98
  bank(0);
 
99
}
 
100
 
 
101
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 
102
uInt8 CartridgeF6SC::peek(uInt16 address)
 
103
{
 
104
  address = address & 0x0FFF;
 
105
 
 
106
  // Switch banks if necessary
 
107
  switch(address)
 
108
  {
 
109
    case 0x0FF6:
 
110
      // Set the current bank to the first 4k bank
 
111
      bank(0);
 
112
      break;
 
113
 
 
114
    case 0x0FF7:
 
115
      // Set the current bank to the second 4k bank
 
116
      bank(1);
 
117
      break;
 
118
 
 
119
    case 0x0FF8:
 
120
      // Set the current bank to the third 4k bank
 
121
      bank(2);
 
122
      break;
 
123
 
 
124
    case 0x0FF9:
 
125
      // Set the current bank to the forth 4k bank
 
126
      bank(3);
 
127
      break;
 
128
 
 
129
    default:
 
130
      break;
 
131
  }
 
132
  
 
133
  // NOTE: This does not handle accessing RAM, however, this function
 
134
  // should never be called for RAM because of the way page accessing
 
135
  // has been setup
 
136
  return myImage[myCurrentBank * 4096 + address];
 
137
}
 
138
 
 
139
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 
140
void CartridgeF6SC::poke(uInt16 address, uInt8)
 
141
{
 
142
  address = address & 0x0FFF;
 
143
 
 
144
  // Switch banks if necessary
 
145
  switch(address)
 
146
  {
 
147
    case 0x0FF6:
 
148
      // Set the current bank to the first 4k bank
 
149
      bank(0);
 
150
      break;
 
151
 
 
152
    case 0x0FF7:
 
153
      // Set the current bank to the second 4k bank
 
154
      bank(1);
 
155
      break;
 
156
 
 
157
    case 0x0FF8:
 
158
      // Set the current bank to the third 4k bank
 
159
      bank(2);
 
160
      break;
 
161
 
 
162
    case 0x0FF9:
 
163
      // Set the current bank to the forth 4k bank
 
164
      bank(3);
 
165
      break;
 
166
 
 
167
    default:
 
168
      break;
 
169
  }
 
170
 
 
171
  // NOTE: This does not handle accessing RAM, however, this function
 
172
  // should never be called for RAM because of the way page accessing
 
173
  // has been setup
 
174
}
 
175
 
 
176
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 
177
void CartridgeF6SC::bank(uInt16 bank)
 
178
 
179
  // Remember what bank we're in
 
180
  myCurrentBank = bank;
 
181
  uInt16 offset = myCurrentBank * 4096;
 
182
  uInt16 shift = mySystem->pageShift();
 
183
  uInt16 mask = mySystem->pageMask();
 
184
 
 
185
  // Setup the page access methods for the current bank
 
186
  System::PageAccess access;
 
187
  access.device = this;
 
188
  access.directPokeBase = 0;
 
189
 
 
190
  // Map ROM image into the system
 
191
  for(uInt32 address = 0x1100; address < (0x1FF6U & ~mask);
 
192
      address += (1 << shift))
 
193
  {
 
194
    access.directPeekBase = &myImage[offset + (address & 0x0FFF)];
 
195
    mySystem->setPageAccess(address >> shift, access);
 
196
  }
 
197
}
 
198