~ubuntu-branches/debian/sid/stella/sid

« back to all changes in this revision

Viewing changes to src/debugger/gui/CartCMWidget.cxx

  • Committer: Package Import Robot
  • Author(s): Stephen Kitt
  • Date: 2013-06-28 09:53:13 UTC
  • mfrom: (1.3.6)
  • Revision ID: package-import@ubuntu.com-20130628095313-j8jkkgxpvx1t18ym
Tags: 3.9-1
New upstream version.

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-2013 by Bradford W. Mott, Stephen Anthony
 
12
// and the Stella Team
 
13
//
 
14
// See the file "License.txt" for information on usage and redistribution of
 
15
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
 
16
//
 
17
// $Id: CartCMWidget.cxx 2743 2013-05-29 16:27:12Z stephena $
 
18
//============================================================================
 
19
 
 
20
#include "CartCM.hxx"
 
21
#include "RiotDebug.hxx"
 
22
#include "DataGridWidget.hxx"
 
23
#include "EditTextWidget.hxx"
 
24
#include "PopUpWidget.hxx"
 
25
#include "ToggleBitWidget.hxx"
 
26
#include "CartCMWidget.hxx"
 
27
 
 
28
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 
29
CartridgeCMWidget::CartridgeCMWidget(
 
30
      GuiObject* boss, const GUI::Font& font,
 
31
      int x, int y, int w, int h, CartridgeCM& cart)
 
32
  : CartDebugWidget(boss, font, x, y, w, h),
 
33
    myCart(cart)
 
34
{
 
35
  uInt16 size = 4 * 4096;
 
36
 
 
37
  string info =
 
38
    "CM cartridge, four 4K banks + 2K RAM\n"
 
39
    "2K RAM accessible @ $1800 - $1FFF in read or write-only mode "
 
40
    "(no separate ports)\n"
 
41
    "All TIA controller registers (INPT0-INPT5) and RIOT SWCHA are "
 
42
    "used to control the cart functionality\n"
 
43
    "Startup bank = 3 (ROM), RAM disabled\n";
 
44
 
 
45
  int xpos = 10,
 
46
      ypos = addBaseInformation(size, "CompuMate", info) + myLineHeight;
 
47
 
 
48
  VariantList items;
 
49
  items.push_back(" 0 ");
 
50
  items.push_back(" 1 ");
 
51
  items.push_back(" 2 ");
 
52
  items.push_back(" 3 ");
 
53
  myBank =
 
54
    new PopUpWidget(boss, font, xpos, ypos-2, font.getStringWidth(" 0 "),
 
55
                    myLineHeight, items, "Set bank: ",
 
56
                    font.getStringWidth("Set bank: "), kBankChanged);
 
57
  myBank->setTarget(this);
 
58
  addFocusWidget(myBank);
 
59
 
 
60
  // Raw SWCHA value (this will be broken down further in other UI elements)
 
61
  int lwidth = font.getStringWidth("Current column: ");
 
62
  ypos += myLineHeight + 8;
 
63
  new StaticTextWidget(boss, font, xpos, ypos+2, lwidth, myFontHeight,
 
64
                       "Current SWCHA: ", kTextAlignLeft);
 
65
  xpos += lwidth;
 
66
  mySWCHA = new ToggleBitWidget(boss, font, xpos, ypos, 8, 1);
 
67
  mySWCHA->setTarget(this);
 
68
  mySWCHA->setEditable(false);
 
69
 
 
70
  // Current column number
 
71
  xpos = 10;  ypos += myLineHeight + 5;
 
72
  new StaticTextWidget(boss, font, xpos, ypos, lwidth,
 
73
        myFontHeight, "Current column: ", kTextAlignLeft);
 
74
  xpos += lwidth;
 
75
 
 
76
  myColumn = new DataGridWidget(boss, font, xpos, ypos-2, 1, 1, 2, 8, kBASE_16);
 
77
  myColumn->setTarget(this);
 
78
  myColumn->setEditable(false);
 
79
 
 
80
  // Relevant pins of SWCHA
 
81
  xpos = 30;
 
82
 
 
83
  // D6 (column part)
 
84
  ypos += myLineHeight + 8;
 
85
  myIncrease = new CheckboxWidget(boss, font, xpos, ypos, "Increase Column");
 
86
  myIncrease->setTarget(this);
 
87
  myIncrease->setEditable(false);
 
88
 
 
89
  int orig_ypos = ypos;  // save for when we go to the next column
 
90
 
 
91
  // D5 (column part)
 
92
  ypos += myLineHeight + 4;
 
93
  myReset = new CheckboxWidget(boss, font, xpos, ypos, "Reset Column");
 
94
  myReset->setTarget(this);
 
95
  myReset->setEditable(false);
 
96
 
 
97
  // Row inputs
 
98
  ypos += myLineHeight + 4;
 
99
  myRow[0] = new CheckboxWidget(boss, font, xpos, ypos, "Row 0");
 
100
  myRow[0]->setTarget(this);
 
101
  myRow[0]->setEditable(false);
 
102
  ypos += myLineHeight + 4;
 
103
  myRow[1] = new CheckboxWidget(boss, font, xpos, ypos, "Row 1");
 
104
  myRow[1]->setTarget(this);
 
105
  myRow[1]->setEditable(false);
 
106
  ypos += myLineHeight + 4;
 
107
  myRow[2] = new CheckboxWidget(boss, font, xpos, ypos, "Row 2");
 
108
  myRow[2]->setTarget(this);
 
109
  myRow[2]->setEditable(false);
 
110
  ypos += myLineHeight + 4;
 
111
  myRow[3] = new CheckboxWidget(boss, font, xpos, ypos, "Row 3");
 
112
  myRow[3]->setTarget(this);
 
113
  myRow[3]->setEditable(false);
 
114
 
 
115
  // Func and Shift keys
 
116
  ypos += myLineHeight + 4;
 
117
  myFunc = new CheckboxWidget(boss, font, xpos, ypos, "FUNC key pressed");
 
118
  myFunc->setTarget(this);
 
119
  myFunc->setEditable(false);
 
120
  ypos += myLineHeight + 4;
 
121
  myShift = new CheckboxWidget(boss, font, xpos, ypos, "Shift key pressed");
 
122
  myShift->setTarget(this);
 
123
  myShift->setEditable(false);
 
124
 
 
125
  // Move to next column
 
126
  xpos += myShift->getWidth() + 20;  ypos = orig_ypos;
 
127
 
 
128
  // D7
 
129
  myAudIn = new CheckboxWidget(boss, font, xpos, ypos, "Audio Input");
 
130
  myAudIn->setTarget(this);
 
131
  myAudIn->setEditable(false);
 
132
 
 
133
  // D6 (audio part)
 
134
  ypos += myLineHeight + 4;
 
135
  myAudOut = new CheckboxWidget(boss, font, xpos, ypos, "Audio Output");
 
136
  myAudOut->setTarget(this);
 
137
  myAudOut->setEditable(false);
 
138
 
 
139
  // Ram state (combination of several bits in SWCHA)
 
140
  ypos += myLineHeight + 8;
 
141
  lwidth = font.getStringWidth("Ram State: ");
 
142
  new StaticTextWidget(boss, font, xpos, ypos, lwidth,
 
143
        myFontHeight, "Ram State: ", kTextAlignLeft);
 
144
  myRAM = new EditTextWidget(boss, font, xpos+lwidth, ypos-1,
 
145
              font.getStringWidth(" Write-only "), myLineHeight, "");
 
146
  myRAM->setEditable(false);
 
147
}
 
148
 
 
149
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 
150
void CartridgeCMWidget::saveOldState()
 
151
{
 
152
  myOldState.swcha = myCart.mySWCHA;
 
153
  myOldState.column = myCart.myColumn;
 
154
}
 
155
 
 
156
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 
157
void CartridgeCMWidget::loadConfig()
 
158
{
 
159
  myBank->setSelected(myCart.myCurrentBank);
 
160
 
 
161
  RiotDebug& riot = Debugger::debugger().riotDebug();
 
162
  const RiotState& state = (RiotState&) riot.getState();
 
163
 
 
164
  uInt8 swcha = myCart.mySWCHA;
 
165
 
 
166
  // SWCHA
 
167
  BoolArray oldbits, newbits, changed;
 
168
  Debugger::set_bits(myOldState.swcha, oldbits);
 
169
  Debugger::set_bits(swcha, newbits);
 
170
 
 
171
  for(uInt32 i = 0; i < oldbits.size(); ++i)
 
172
    changed.push_back(oldbits[i] != newbits[i]);
 
173
  mySWCHA->setState(newbits, changed);
 
174
 
 
175
  // Column
 
176
  myColumn->setList(0, myCart.myColumn, myCart.myColumn != myOldState.column);
 
177
 
 
178
  // Various bits from SWCHA and INPTx
 
179
  myIncrease->setState(swcha & 0x40);
 
180
  myReset->setState(swcha & 0x20);
 
181
  myRow[0]->setState(!(state.INPT4 & 0x80));
 
182
  myRow[1]->setState(!(swcha & 0x04));
 
183
  myRow[2]->setState(!(state.INPT5 & 0x80));
 
184
  myRow[3]->setState(!(swcha & 0x08));
 
185
  myFunc->setState(state.INPT0 & 0x80);
 
186
  myShift->setState(state.INPT3 & 0x80);
 
187
 
 
188
  // Audio in and out (used for communicating with the external cassette)
 
189
  myAudIn->setState(swcha & 0x80);
 
190
  myAudOut->setState(swcha & 0x40);
 
191
 
 
192
  // RAM state (several bits from SWCHA)
 
193
  const string& ram = swcha & 0x10 ? " Inactive" :
 
194
                        swcha & 0x20 ? " Read-only" : " Write-only";
 
195
  myRAM->setText(ram, (swcha & 0x30) != (myOldState.swcha & 0x30));
 
196
 
 
197
  CartDebugWidget::loadConfig();
 
198
}
 
199
 
 
200
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 
201
void CartridgeCMWidget::handleCommand(CommandSender* sender,
 
202
                                      int cmd, int data, int id)
 
203
{
 
204
  if(cmd == kBankChanged)
 
205
  {
 
206
    myCart.unlockBank();
 
207
    myCart.mySWCHA &= 0xFC;
 
208
    myCart.mySWCHA |= myBank->getSelected();
 
209
    myCart.bank(myCart.mySWCHA & 0x03);
 
210
    myCart.lockBank();
 
211
    invalidate();
 
212
  }
 
213
}
 
214
 
 
215
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 
216
string CartridgeCMWidget::bankState()
 
217
{
 
218
  ostringstream& buf = buffer();
 
219
 
 
220
  buf << "Bank = " << myCart.myCurrentBank
 
221
      << ", RAM is" << (myCart.mySWCHA & 0x10 ? " Inactive" :
 
222
         myCart.mySWCHA & 0x20 ? " Read-only" : " Write-only");
 
223
 
 
224
  return buf.str();
 
225
}