~ubuntu-branches/ubuntu/trusty/vice/trusty

« back to all changes in this revision

Viewing changes to src/arch/beos/ui_sidcart.cc

  • Committer: Package Import Robot
  • Author(s): Laszlo Boszormenyi (GCS)
  • Date: 2013-07-28 20:38:23 UTC
  • mfrom: (1.2.5)
  • mto: This revision was merged to the branch mainline in revision 27.
  • Revision ID: package-import@ubuntu.com-20130728203823-w495rps5wuykespp
Tags: upstream-2.4.dfsg
ImportĀ upstreamĀ versionĀ 2.4.dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * ui_sidcart.cc - SID cart settings
 
3
 *
 
4
 * Written by
 
5
 *  Marcus Sutton <loggedoubt@gmail.com>
 
6
 *
 
7
 * This file is part of VICE, the Versatile Commodore Emulator.
 
8
 * See README for copyright notice.
 
9
 *
 
10
 *  This program is free software; you can redistribute it and/or modify
 
11
 *  it under the terms of the GNU General Public License as published by
 
12
 *  the Free Software Foundation; either version 2 of the License, or
 
13
 *  (at your option) any later version.
 
14
 *
 
15
 *  This program is distributed in the hope that it will be useful,
 
16
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
17
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
18
 *  GNU General Public License for more details.
 
19
 *
 
20
 *  You should have received a copy of the GNU General Public License
 
21
 *  along with this program; if not, write to the Free Software
 
22
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
 
23
 *  02111-1307  USA.
 
24
 *
 
25
 */
 
26
 
 
27
#include <Box.h>
 
28
#include <CheckBox.h>
 
29
#include <OptionPopUp.h>
 
30
#include <RadioButton.h>
 
31
#include <Slider.h>
 
32
#include <string.h>
 
33
#include <Window.h>
 
34
 
 
35
#include <stdlib.h>
 
36
 
 
37
extern "C" {
 
38
#include "constants.h"
 
39
#include "machine.h"
 
40
#include "resources.h"
 
41
#include "sid.h"
 
42
#include "ui.h"
 
43
#include "ui_sidcart.h"
 
44
#include "util.h"
 
45
#include "vsync.h"
 
46
}
 
47
 
 
48
static char *samplingmode[] = {
 
49
    "fast sampling",
 
50
    "interpolating",
 
51
    "resampling",
 
52
    "fast resampling",
 
53
    NULL
 
54
};
 
55
 
 
56
static sid_engine_model_t **sid_engine_model_list;
 
57
 
 
58
static char **sidaddresspair;
 
59
static char **sidclockpair;
 
60
 
 
61
class SidCartWindow : public BWindow {
 
62
        BOptionPopUp *engine_model_popup;
 
63
        BSlider *passbandslider;
 
64
        BBox *addressbox;
 
65
        BBox *clockbox;
 
66
        BBox *residbox;
 
67
 
 
68
        void EnableBoxedControls(BBox *box, int enable);
 
69
        void EnableReSidControls(int engine);
 
70
        void EnableControls();
 
71
    public:
 
72
        SidCartWindow();
 
73
        ~SidCartWindow();
 
74
        virtual void MessageReceived(BMessage *msg);
 
75
};
 
76
 
 
77
static SidCartWindow *sidcartwindow = NULL;
 
78
 
 
79
void SidCartWindow::EnableBoxedControls(BBox *box, int enable)
 
80
{
 
81
    int32 children, i;
 
82
 
 
83
    children = box->CountChildren();
 
84
    for (i = 0; i < children; i++) {
 
85
        ((BControl *)box->ChildAt(i))->SetEnabled(enable);
 
86
    }
 
87
 
 
88
}
 
89
 
 
90
void SidCartWindow::EnableReSidControls(int engine)
 
91
{
 
92
    int enable;
 
93
 
 
94
    enable = ((BControl *)FindView("SidCart"))->Value();
 
95
    EnableBoxedControls(residbox, enable && ((engine == SID_ENGINE_RESID) || (engine == SID_ENGINE_RESID_FP)));
 
96
}
 
97
 
 
98
void SidCartWindow::EnableControls()
 
99
{
 
100
    int enable, engine;
 
101
 
 
102
    enable = ((BControl *)FindView("SidCart"))->Value();
 
103
    engine_model_popup->SetEnabled(enable);
 
104
    ((BControl *)FindView("SidFilters"))->SetEnabled(enable);
 
105
    EnableBoxedControls(addressbox, enable);
 
106
    EnableBoxedControls(clockbox, enable);
 
107
    if (machine_class == VICE_MACHINE_PLUS4) {
 
108
        ((BControl *)FindView("DIGIBLASTER"))->SetEnabled(enable);
 
109
    }
 
110
 
 
111
    resources_get_int("SidEngine", &engine);
 
112
    EnableReSidControls(engine);
 
113
}
 
114
 
 
115
SidCartWindow::SidCartWindow() 
 
116
    : BWindow(BRect(250, 50, 500, 340), "SID cartridge settings", B_TITLED_WINDOW_LOOK, B_MODAL_APP_WINDOW_FEEL, B_NOT_ZOOMABLE | B_NOT_RESIZABLE) 
 
117
{
 
118
    BMessage *msg;
 
119
    BCheckBox *checkbox;
 
120
    BRect r;
 
121
    BRadioButton *radiobutton;
 
122
    BView *background;
 
123
    int engine, res_val, i;
 
124
 
 
125
    r = Bounds();
 
126
    background = new BView(r, NULL,  B_FOLLOW_NONE, B_WILL_DRAW);
 
127
    background->SetViewColor(220, 220, 220, 0);
 
128
    AddChild(background);
 
129
 
 
130
    /* SID cart emulation */
 
131
    resources_get_int("SidCart", &res_val);
 
132
    checkbox = new BCheckBox(BRect(10, 10, 240, 25), "SidCart", "Enable SID cartridge", new BMessage(MESSAGE_SIDCART_ENABLE));
 
133
    checkbox->SetValue(res_val);
 
134
    background->AddChild(checkbox);
 
135
 
 
136
    /* SID model */
 
137
    sid_engine_model_list = sid_get_engine_model_list();
 
138
    resources_get_int("SidModel", &i);
 
139
    resources_get_int("SidEngine", &engine);
 
140
    res_val = engine << 8;
 
141
    res_val |= i;
 
142
    engine_model_popup = new BOptionPopUp(BRect(10, 35, 240, 59), "SID Engine/Model", "SID Engine/Model", new BMessage(MESSAGE_SIDCART_MODEL));
 
143
    for (i = 0; sid_engine_model_list[i] != NULL; i++) {
 
144
        engine_model_popup->AddOption(sid_engine_model_list[i]->name, sid_engine_model_list[i]->value);
 
145
    }
 
146
    engine_model_popup->SelectOptionFor(res_val);
 
147
    background->AddChild(engine_model_popup);
 
148
 
 
149
    /* SID filter */
 
150
    resources_get_int("SidFilters", &res_val);
 
151
    checkbox = new BCheckBox(BRect(10, 60, 240, 75), "SidFilters", "SID filters", new BMessage(MESSAGE_SIDCART_FILTERS));
 
152
    checkbox->SetValue(res_val);
 
153
    background->AddChild(checkbox);
 
154
 
 
155
    /* SID address */
 
156
    addressbox = new BBox(BRect(10, 85, 120, 145), "SID address");
 
157
    addressbox->SetViewColor(220, 220, 220, 0);
 
158
    addressbox->SetLabel("SID address");
 
159
    background->AddChild(addressbox);
 
160
 
 
161
    resources_get_int("SidAddress", &res_val);
 
162
    for (i = 0; i < 2; i++) {
 
163
        msg = new BMessage(MESSAGE_SIDCART_ADDRESS);
 
164
        msg->AddInt32("address", i);
 
165
        radiobutton = new BRadioButton(BRect(10, 15 + i * 20, 100, 30 + i * 20), sidaddresspair[i], sidaddresspair[i], msg);
 
166
        radiobutton->SetValue(res_val == i);
 
167
        addressbox->AddChild(radiobutton);
 
168
    }
 
169
 
 
170
    /* SID clock */
 
171
    clockbox = new BBox(BRect(130, 85, 240, 145), "SID clock");
 
172
    clockbox->SetViewColor(220, 220, 220, 0);
 
173
    clockbox->SetLabel("SID clock");
 
174
    background->AddChild(clockbox);
 
175
 
 
176
    resources_get_int("SidClock", &res_val);
 
177
    for (i = 0; i < 2; i++) {
 
178
        msg = new BMessage(MESSAGE_SIDCART_CLOCK);
 
179
        msg->AddInt32("clock", i);
 
180
        radiobutton = new BRadioButton(BRect(10, 15 + i * 20, 100, 30 + i * 20), sidclockpair[i], sidclockpair[i], msg);
 
181
        radiobutton->SetValue(res_val == i);
 
182
        clockbox->AddChild(radiobutton);
 
183
    }
 
184
 
 
185
    /* DIGIBLASTER */
 
186
    if (machine_class == VICE_MACHINE_PLUS4) {
 
187
        resources_get_int("DIGIBLASTER", &res_val);
 
188
        checkbox = new BCheckBox(BRect(10, 155, 240, 170), "DIGIBLASTER", "Enable digiblaster add-on", new BMessage(MESSAGE_SIDCART_DIGIBLASTER));
 
189
        checkbox->SetValue(res_val);
 
190
        background->AddChild(checkbox);
 
191
    } else {
 
192
        ResizeTo(250, 265);
 
193
    }
 
194
 
 
195
    /* reSID settings */
 
196
    r = Bounds();
 
197
    r.InsetBy(10, 10);
 
198
    r.top = r.bottom - 100;
 
199
    residbox = new BBox(r, "reSID/reSID-fp settings");
 
200
    residbox->SetViewColor(220, 220, 220, 0);
 
201
    residbox->SetLabel("reSID/reSID-fp settings");
 
202
    background->AddChild(residbox);
 
203
    r = residbox->Bounds();
 
204
 
 
205
    /* sampling method */
 
206
    resources_get_int("SidResidSampling", &res_val);
 
207
    for (i = 0; samplingmode[i] != NULL; i++) {
 
208
        msg = new BMessage(MESSAGE_SIDCART_RESIDSAMPLING);
 
209
        msg->AddInt32("mode", i);
 
210
        radiobutton = new BRadioButton(BRect(10, 15 + i * 20, r.Width() / 2 - 10, 30 + i * 20), samplingmode[i], samplingmode[i], msg);
 
211
        radiobutton->SetValue(res_val == i);
 
212
        residbox->AddChild(radiobutton);
 
213
    }
 
214
 
 
215
    resources_get_int("SidResidPassband", &res_val);
 
216
    passbandslider = new BSlider(BRect(r.Width() / 2 + 10, 20, r.Width() - 10, 60), "Passband", "Passband", new BMessage(MESSAGE_SIDCART_RESIDPASSBAND), 0, 90, B_TRIANGLE_THUMB);
 
217
    passbandslider->SetValue(res_val);
 
218
    passbandslider->SetHashMarkCount(10);
 
219
    passbandslider->SetHashMarks(B_HASH_MARKS_BOTTOM);
 
220
    passbandslider->SetLimitLabels("0", "90");
 
221
    residbox->AddChild(passbandslider);
 
222
 
 
223
    EnableControls();
 
224
 
 
225
    Show();
 
226
}
 
227
 
 
228
SidCartWindow::~SidCartWindow() 
 
229
{
 
230
    sidcartwindow = NULL;
 
231
}
 
232
 
 
233
void SidCartWindow::MessageReceived(BMessage *msg)
 
234
{
 
235
    int32 engine, val;
 
236
 
 
237
    switch (msg->what) {
 
238
        case MESSAGE_SIDCART_ENABLE:
 
239
            resources_toggle("SidCart", (int *)&val);
 
240
            EnableControls();
 
241
            break;
 
242
        case MESSAGE_SIDCART_MODEL:
 
243
            val = engine_model_popup->Value();
 
244
            engine = val >> 8;
 
245
            val &= 0xff;
 
246
            sid_set_engine_model(engine, val);
 
247
            EnableReSidControls(engine);
 
248
            break;
 
249
        case MESSAGE_SIDCART_FILTERS:
 
250
            resources_toggle("SidFilters", (int *)&val);
 
251
            break;
 
252
        case MESSAGE_SIDCART_ADDRESS:
 
253
            val = msg->FindInt32("address");
 
254
            resources_set_int("SidAddress", (int)val);
 
255
            break;
 
256
        case MESSAGE_SIDCART_CLOCK:
 
257
            val = msg->FindInt32("clock");
 
258
            resources_set_int("SidClock", (int)val);
 
259
            break;
 
260
        case MESSAGE_SIDCART_DIGIBLASTER:
 
261
            resources_toggle("DIGIBLASTER", (int *)&val);
 
262
            break;
 
263
        case MESSAGE_SIDCART_RESIDSAMPLING:
 
264
            val = msg->FindInt32("mode");
 
265
            resources_set_int("SidResidSampling", val);
 
266
            break;
 
267
        case MESSAGE_SIDCART_RESIDPASSBAND:
 
268
            resources_set_int("SidResidPassband", passbandslider->Value());
 
269
            break;
 
270
        default:
 
271
            BWindow::MessageReceived(msg);
 
272
    }
 
273
}
 
274
 
 
275
void ui_sidcart(char **cartaddresspair, char **cartclockpair)
 
276
{
 
277
    thread_id sidcartthread;
 
278
    status_t exit_value;
 
279
 
 
280
    if (sidcartwindow != NULL) {
 
281
        return;
 
282
    }
 
283
 
 
284
    sidaddresspair = cartaddresspair;
 
285
    sidclockpair = cartclockpair;
 
286
 
 
287
    sidcartwindow = new SidCartWindow;
 
288
 
 
289
    vsync_suspend_speed_eval();
 
290
 
 
291
    /* wait until window closed */
 
292
    sidcartthread = sidcartwindow->Thread();
 
293
    wait_for_thread(sidcartthread, &exit_value);
 
294
}