File: CartFASC.cxx

package info (click to toggle)
stella 0.7-2
  • links: PTS
  • area: non-free
  • in suites: hamm, slink
  • size: 864 kB
  • ctags: 1,158
  • sloc: cpp: 6,615; ansic: 492; makefile: 224; asm: 31
file content (145 lines) | stat: -rw-r--r-- 4,092 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
//============================================================================
//
//    SSSS    tt          lll  lll              
//   SS  SS   tt           ll   ll                
//   SS     tttttt  eeee   ll   ll   aaaa    "An Atari 2600 VCS Emulator"
//    SSSS    tt   ee  ee  ll   ll      aa      
//       SS   tt   eeeeee  ll   ll   aaaaa   Copyright (c) 1995,1996,1997
//   SS  SS   tt   ee      ll   ll  aa  aa         Bradford W. Mott
//    SSSS     ttt  eeeee llll llll  aaaaa    
//
//============================================================================

/**
  The 12K cartridge class used by CBS' RAM Plus cartridges. There
  are 3 4K banks and 256-bytes of RAM.

  @author  Bradford W. Mott
  @version $Id: CartFASC.cxx,v 1.2 1997/05/17 19:00:04 bwmott Exp $
*/

#include "CartFASC.hxx"
#include "System.hxx"

//============================================================================
// Constructor
//============================================================================
CartridgeFASC::CartridgeFASC(System& system, uByte* image)
    : Cartridge(system),
      myImageOffset(0),
      myRAMOffset(0)
{
  // Copy the ROM image into my buffer
  for(uWord bank = 0; bank < 3; ++bank)
  {
    for(uWord addr = 0; addr < 4096; ++addr)
    {
      myImage[(bank * 4096) + addr] = image[(bank * 4096) + addr];
    }
  }

  // Map all of my addresses in the system
  for(uWord addr = 0; addr < 8192; ++addr)
  {
    if(addr & 0x1000)
    {
      // Is this read address mapped to the cartridge RAM
      if((addr & 0x0f00) == 0x0100)
      {
        mySystem.mapPeek(addr, *this, &myRAM[addr & 0x00ff], &myRAMOffset);
      }
      // Is this read address a "hot spot" or a read from "no where"
      else if(((addr & 0x0fff) == 0x0ff8) || ((addr & 0x0fff) == 0x0ff9) ||
          ((addr & 0x0fff) == 0x0ffA) || ((addr & 0x0f00) == 0x0000))
      {
        mySystem.mapPeek(addr, *this);
      }
      // Is this read address mapped to the standard ROM image
      else
      {
        mySystem.mapPeek(addr, *this, 
            &myImage[addr & 0x0fff], &myImageOffset);
      }

      // Is this write address mapped to the cartridge RAM
      if((addr & 0x0f00) == 0x0000)
        mySystem.mapPoke(addr, *this, &myRAM[addr & 0x00ff]);
      else
        mySystem.mapPoke(addr, *this);
    }
  }

  // Reset myself
  reset();
}
 
//============================================================================
// Destructor
//============================================================================
CartridgeFASC::~CartridgeFASC()
{
}

//============================================================================
// Reset to my power on state
//============================================================================
void CartridgeFASC::reset()
{
  // RAM's addressing offset is always zero
  myRAMOffset = 0;

  // Start execution in bank #2
  myImageOffset = 2 * 4096;
}

//============================================================================
// Answer the byte at the given address
//============================================================================
uByte CartridgeFASC::peek(uWord addr)
{
  // Switch banks if necessary
  switch (addr & 0x0fff)
  {
    case 0x0ff8:    // Bank #0
      myImageOffset = 0 * 4096;
      break;

    case 0x0ff9:    // Bank #1
      myImageOffset = 1 * 4096;
      break;

    case 0x0ffA:    // Bank #2
      myImageOffset = 2 * 4096;
      break;

    default:
      break; 
  }
  return myImage[myImageOffset + (addr & 0x0fff)];
}

//============================================================================
// Store value in the given address
//============================================================================
void CartridgeFASC::poke(uWord addr, uByte)
{
  // Switch banks if necessary
  switch (addr & 0x0fff)
  {
    case 0x0ff8:    // Bank #0
      myImageOffset = 0 * 4096;
      break;

    case 0x0ff9:    // Bank #1
      myImageOffset = 1 * 4096;
      break;

    case 0x0ffA:    // Bank #2
      myImageOffset = 2 * 4096;
      break;

    default:
      break; 
  }
}