File: CartE7.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 (110 lines) | stat: -rw-r--r-- 3,755 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
//============================================================================
//
//    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    
//
//============================================================================

/**
  This is the M-Network Bankswitching method (E7).  There are two 2K
  slices, 8 ROM banks, and 2K of RAM.  The RAM is broken into two
  1K pieces.  One 1K piece goes into slice 0 if selected and the other
  one is broken into four 256-byte parts.

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

#include "CartE7.hxx"
#include "System.hxx"

//============================================================================
// Constructor
//============================================================================
CartridgeE7::CartridgeE7(System& system, uByte* image)
    : Cartridge(system)
{
  // Copy the image into my image buffer
  for(uWord t = 0; t < 16384; ++t)
    myImage[t] = image[t];

  // Map all of my addresses in the system
  for(uWord addr = 0; addr < 8192; ++addr)
  {
    if(addr & 0x1000)
    {
      if(((addr & 0x0FFF) >= 0x0FE0) && ((addr & 0x0FFF) <= 0x0FFB))
        mySystem.mapPeek(addr, *this);
      else if((addr & 0x0FFF) <= 0x07FF)
        mySystem.mapPeek(addr, *this, &myImage[addr & 0x07ff], 
          &myImageOffset[0]);
      else if(((addr & 0x0FFF) >= 0x900) && ((addr & 0x0FFF) <= 0x9FF))
        mySystem.mapPeek(addr, *this, &myRAM[addr & 0x00ff], 
          &myRAMOffset);
      else if((addr & 0x0FFF) >= 0x0A00)
        mySystem.mapPeek(addr, *this, &myImage[addr & 0x07ff], 
          &myImageOffset[1]);
      else
        mySystem.mapPeek(addr, *this);

      mySystem.mapPoke(addr, *this);
    }
  }

  // Reset myself
  reset();
}

//============================================================================
// Destructor
//============================================================================
CartridgeE7::~CartridgeE7()
{
}

//============================================================================
// Reset to power on state
//============================================================================
void CartridgeE7::reset()
{
  myImageOffset[0] = 0 * 2048;
  myImageOffset[1] = 7 * 2048;
}

//============================================================================
// Answer the byte at the given address
//============================================================================
uByte CartridgeE7::peek(uWord addr)
{
  if((addr >= 0x1fe0) && (addr <= 0x1fe6))
    myImageOffset[0] = (addr & 07) * 2048;
  else if(addr == 0x1fe7)
    myImageOffset[0] = 8 * 2048;
  else if((addr >= 0x1fe8) && (addr <= 0x1feb))
    myRAMOffset = (addr & 03) * 256;

  return 0;
}

//============================================================================
// Store value in the given address
//============================================================================
void CartridgeE7::poke(uWord addr, uByte value)
{
  if((addr >= 0x1000) && (addr <= 0x13ff))
    myImage[8 * 2048 + (addr & 0x03ff)] = value;
  else if((addr >= 0x1800) && (addr <= 0x18ff))
    myRAM[myRAMOffset + (addr & 0x00ff)] = value;
  else if((addr >= 0x1fe0) && (addr <= 0x1fe6))
    myImageOffset[0] = (addr & 07) * 2048;
  else if(addr == 0x1fe7)
    myImageOffset[0] = 8 * 2048;
  else if((addr >= 0x1fe8) && (addr <= 0x1feb))
    myRAMOffset = (addr & 03) * 256;
}