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-2019 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
18#include "CartE0.hxx"
19#include "PopUpWidget.hxx"
20#include "CartE0Widget.hxx"
21
22static const char* const seg0[] = {
23 "0 ($FFE0)", "1 ($FFE1)", "2 ($FFE2)", "3 ($FFE3)",
24 "4 ($FFE4)", "5 ($FFE5)", "6 ($FFE6)", "7 ($FFE7)"
25};
26static const char* const seg1[] = {
27 "0 ($FFE8)", "1 ($FFE9)", "2 ($FFEA)", "3 ($FFEB)",
28 "4 ($FFEC)", "5 ($FFED)", "6 ($FFEE)", "7 ($FFEF)"
29};
30static const char* const seg2[] = {
31 "0 ($FFF0)", "1 ($FFF1)", "2 ($FFF2)", "3 ($FFF3)",
32 "4 ($FFF4)", "5 ($FFF5)", "6 ($FFF6)", "7 ($FFF7)"
33};
34
35// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
36CartridgeE0Widget::CartridgeE0Widget(
37 GuiObject* boss, const GUI::Font& lfont, const GUI::Font& nfont,
38 int x, int y, int w, int h, CartridgeE0& cart)
39 : CartDebugWidget(boss, lfont, nfont, x, y, w, h),
40 myCart(cart)
41{
42 uInt32 size = 8 * 1024;
43
44 string info =
45 "E0 cartridge, eight 1K slices\n"
46 "Segment 0 accessible @ $F000 - $F3FF\n"
47 " Hotspots $FE0 to $FE7\n"
48 "Segment 1 accessible @ $F400 - $F7FF\n"
49 " Hotspots $FE8 to $FEF\n"
50 "Segment 2 accessible @ $F800 - $FBFF\n"
51 " Hotspots $FF0 to $FF7\n"
52 "Segment 3 accessible @ $FC00 - $FFFF\n"
53 " Always points to last 1K of ROM\n"
54 "Startup slices = 4 / 5 / 6 or undetermined\n";
55
56#if 0
57 // Eventually, we should query this from the debugger/disassembler
58 uInt16 start = (cart.myImage[size-3] << 8) | cart.myImage[size-4];
59 start -= start % 0x1000;
60 info << "Bank RORG" << " = $" << HEX4 << start << "\n";
61#endif
62 int xpos = 2,
63 ypos = addBaseInformation(size, "Parker Brothers", info) + myLineHeight;
64
65 VariantList items0, items1, items2;
66 for(int i = 0; i < 8; ++i)
67 {
68 VarList::push_back(items0, seg0[i]);
69 VarList::push_back(items1, seg1[i]);
70 VarList::push_back(items2, seg2[i]);
71 }
72
73 const int lwidth = _font.getStringWidth("Set slice for segment X ");
74 mySlice0 =
75 new PopUpWidget(boss, _font, xpos, ypos-2, _font.getStringWidth("7 ($FFF7)"),
76 myLineHeight, items0, "Set slice for segment 0 ",
77 lwidth, kSlice0Changed);
78 mySlice0->setTarget(this);
79 addFocusWidget(mySlice0);
80 ypos += mySlice0->getHeight() + 4;
81
82 mySlice1 =
83 new PopUpWidget(boss, _font, xpos, ypos-2, _font.getStringWidth("7 ($FFF7)"),
84 myLineHeight, items1, "Set slice for segment 1 ",
85 lwidth, kSlice1Changed);
86 mySlice1->setTarget(this);
87 addFocusWidget(mySlice1);
88 ypos += mySlice1->getHeight() + 4;
89
90 mySlice2 =
91 new PopUpWidget(boss, _font, xpos, ypos-2, _font.getStringWidth("7 ($FFF7)"),
92 myLineHeight, items2, "Set slice for segment 2 ",
93 lwidth, kSlice2Changed);
94 mySlice2->setTarget(this);
95 addFocusWidget(mySlice2);
96}
97
98// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
99void CartridgeE0Widget::loadConfig()
100{
101 mySlice0->setSelectedIndex(myCart.myCurrentSlice[0]);
102 mySlice1->setSelectedIndex(myCart.myCurrentSlice[1]);
103 mySlice2->setSelectedIndex(myCart.myCurrentSlice[2]);
104
105 CartDebugWidget::loadConfig();
106}
107
108// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
109void CartridgeE0Widget::handleCommand(CommandSender* sender,
110 int cmd, int data, int id)
111{
112 myCart.unlockBank();
113
114 switch(cmd)
115 {
116 case kSlice0Changed:
117 myCart.segmentZero(mySlice0->getSelected());
118 break;
119 case kSlice1Changed:
120 myCart.segmentOne(mySlice1->getSelected());
121 break;
122 case kSlice2Changed:
123 myCart.segmentTwo(mySlice2->getSelected());
124 break;
125 }
126
127 myCart.lockBank();
128 invalidate();
129}
130
131// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
132string CartridgeE0Widget::bankState()
133{
134 ostringstream& buf = buffer();
135
136 buf << "Slices: " << std::dec
137 << seg0[myCart.myCurrentSlice[0]] << " / "
138 << seg1[myCart.myCurrentSlice[1]] << " / "
139 << seg2[myCart.myCurrentSlice[2]];
140
141 return buf.str();
142}
143