~ubuntu-branches/ubuntu/precise/vice/precise

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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
/*
 * ui.c - The user interface for Vice/2.
 *
 * Written by
 *  Thomas Bretz <tbretz@gsi.de>
 *
 * This file is part of VICE, the Versatile Commodore Emulator.
 * See README for copyright notice.
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
 *  02111-1307  USA.
 *
 */

#include "vice.h"

#define INCL_WINSYS        // SYSCLR_*
#define INCL_WININPUT      // VK_*
#define INCL_WINDIALOGS    // WinSendDlgItemMsg
#define INCL_WINBUTTONS    // BS_DEFAULT
#define INCL_WINFRAMEMGR
#define INCL_WINPOINTERS   // WinLoadPointer
#define INCL_DOSDATETIME   // Date and time values
#define INCL_DOSSEMAPHORES

#include <os2.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>

#include "ui.h"
#include "ui_status.h"

#include "dialogs.h"
#include "dlg-drive.h"
#include "dlg-monitor.h"
#include "dlg-datasette.h"
#include "snippets\\pmwin2.h"
#include "lib.h"
#include "log.h"
#include "util.h"
#include "archdep.h"
#include "cmdline.h"
#include "machine.h"   // vsid_mode
#include "resources.h"
#include "translate.h"

/* ------------------------ ui resources ------------------------ */

HMTX hmtxKey;
int PM_winActive;
ui_status_t ui_status;

/* Flag: Use keyboard LEDs?  */
int use_leds;

static int set_use_leds(int val, void *param)
{
    use_leds = val;
    return 0;
}

static const resource_int_t resources_int[] = {
    { "UseLeds", 1, RES_EVENT_NO, NULL,
      &use_leds, set_use_leds, NULL },
    { NULL }
};

int ui_resources_init(void)
{
    return vsid_mode ? 0 : resources_register_int(resources_int);
}

void ui_resources_shutdown(void)
{
}

static const cmdline_option_t cmdline_options[] = {
    { "-leds", SET_RESOURCE, 0,
      NULL, NULL, "UseLeds", (resource_value_t) 1,
      USE_PARAM_STRING, USE_DESCRIPTION_STRING,
      IDCLS_UNUSED, IDCLS_UNUSED,
      NULL, "Enable usage of PC keyboard LEDs" },
    { "+leds", SET_RESOURCE, 0,
      NULL, NULL, "UseLeds", (resource_value_t) 0,
      USE_PARAM_STRING, USE_DESCRIPTION_STRING,
      IDCLS_UNUSED, IDCLS_UNUSED,
      NULL, "Disable usage of PC keyboard LEDs" },
    { NULL }
};

int ui_cmdline_options_init(void)
{
    return vsid_mode?0:cmdline_register_options(cmdline_options);
}

int machine_ui_init(void)
{
    return 0;
}

int c64ui_init(void)
{
    return 0;
}

int c64dtvui_init(void)
{
    return 0;
}

int c128ui_init(void)
{
    return 0;
}

int vic20ui_init(void)
{
    return 0;
}

int petui_init(void)
{
    return 0;
}

int plus4ui_init(void)
{
    return 0;
}

int cbm2ui_init(void)
{
    return 0;
}

int ui_init(int *argc, char **argv)
{
    return 0;
}

void ui_shutdown(void)
{
}

void c64ui_shutdown(void)
{
}

void c64dtvui_shutdown(void)
{
}

void c128ui_shutdown(void)
{
}

void vic20ui_shutdown(void)
{
}

void petui_shutdown(void)
{
}

void plus4ui_shutdown(void)
{
}

void cbm2ui_shutdown(void)
{
}

int ui_init_finish(void)
{
    DATETIME DT = { 0 }; // Date and time information

    DosGetDateTime(&DT);

    log_message(LOG_DEFAULT, "VICE/2-Port done by");
    log_message(LOG_DEFAULT, "T. Bretz.\n");

    log_message(LOG_DEFAULT, "Starting Vice/2 at %d.%d.%d %d:%02d:%02d\n", DT.day, DT.month, DT.year, DT.hours, DT.minutes, DT.seconds);

    return 0;
}

int ui_init_finalize(void)
{
    return 0;
}

/* --------------------------- Tape related UI -------------------------- */

void ui_set_tape_status(int tape_status)
{
    if (ui_status.lastTapeStatus == tape_status) {
        return;
    }
    ui_status.lastTapeStatus = tape_status;
    WinSendMsg(hwndDatasette, WM_TAPESTAT, (void*)ui_status.lastTapeCtrlStat, (void*)tape_status);
}

void ui_display_tape_motor_status(int motor)
{
    if (ui_status.lastTapeMotor == motor) {
        return;
    }
    ui_status.lastTapeMotor = motor;
    WinSendMsg(hwndDatasette, WM_SPINNING, (void*)motor, (void*)ui_status.lastTapeStatus);
}

void ui_display_tape_control_status(int control)
{
    if (ui_status.lastTapeCtrlStat == control) {
        return;
    }
    ui_status.lastTapeCtrlStat = control;
    WinSendMsg(hwndDatasette, WM_TAPESTAT, (void*)control, (void*)ui_status.lastTapeStatus);
}

void ui_display_tape_counter(int counter)
{
    if (ui_status.lastTapeCounter == counter) {
        return;
    }
    ui_status.lastTapeCounter = counter;
    WinSendMsg(hwndDatasette, WM_COUNTER, (void*)counter, 0);
}

void ui_display_tape_current_image(const char *image)
{
}

/* --------------------------- Drive related UI ------------------------ */

void ui_display_drive_led(int drive_number, unsigned int led_pwm1, unsigned int led_pwm2)
{
    BYTE keyState[256];
    int status = 0;

    if (led_pwm1 > 100) {
        status |= 1;
    }
    if (led_pwm2 > 100) {
        status |= 2;
    }

    DosRequestMutexSem(hmtxKey, SEM_INDEFINITE_WAIT);
    if (PM_winActive && use_leds) {
        WinSetKeyboardStateTable(HWND_DESKTOP, keyState, FALSE);
        keyState[VK_CAPSLOCK] = (status != 0);
        WinSetKeyboardStateTable(HWND_DESKTOP, keyState, TRUE);
    }
    DosReleaseMutexSem(hmtxKey);

    WinSendMsg(hwndDrive, WM_DRIVELEDS, (void*)drive_number, (void*)status);
}

void ui_display_drive_track(unsigned int drive_number, unsigned int drive_base, unsigned int half_track_number)
{
    double track_number = (double)half_track_number / 2.0;

    ui_status.lastTrack[drive_number] = track_number;
    WinSendMsg(hwndDrive, WM_TRACK, (void*)drive_number, (void*)(int)(track_number * 2));
}

void ui_enable_drive_status(ui_drive_enable_t state, int *drive_led_color)
{
    ui_status.lastDriveState = state;
    WinSendMsg(hwndDrive, WM_DRIVESTATE,(void*)state, NULL);
    if (state & 1) {
        ui_display_drive_led(0, 0, 0);
    }
    if (state & 2) {
        ui_display_drive_led(1, 0, 0);
    }
}

void ui_display_drive_current_image(unsigned int drive_number, const char *image)
{
    if (image && *image) {
        int pos = 0, i;

        while (strcmp(ui_status.imageHist[pos], image) && ui_status.imageHist[pos][0] && pos < 9) {
            pos++;
        }
        for (i = pos; i > 0; i--) {
            strcpy(ui_status.imageHist[i], ui_status.imageHist[i - 1]);
        }
        strcpy(ui_status.imageHist[0], image);
    }

    WinSendMsg(hwndDrive, WM_DRIVEIMAGE, (void*)image, (void*)drive_number);

    if (image) {
        strcpy(ui_status.lastImage[drive_number], image);
    }
}


void ui_display_recording(int recording_status)
{
}

void ui_display_playback(int playback_status, char *version)
{
}

void ui_display_event_time(unsigned int current, unsigned int total)
{
}

void ui_display_joyport(BYTE *joyport)
{
}

void ui_display_volume(int vol)
{
}

/* --------------------------- Dialog Windows --------------------------- */

void ui_error(const char *format,...)
{
    char *txt, *tmp;
    va_list ap;

    va_start(ap, format);
    tmp = lib_mvsprintf(format, ap);
    txt = util_concat(" Error in emulation thread:\n ", tmp, NULL);
    lib_free(tmp);

    log_message(LOG_DEFAULT, txt);
    ViceErrorDlg(HWND_DESKTOP, PTR_SKULL, txt);

    lib_free(txt);
}

void ui_message(const char *format,...)
{
    char *txt, *tmp;
    va_list ap;

    va_start(ap, format);
    tmp = lib_mvsprintf(format, ap);
    txt = util_concat(" Message from emulation thread:\n ", tmp, NULL);
    lib_free(tmp);

    ViceErrorDlg(HWND_DESKTOP, PTR_SKULL, txt);

    lib_free(txt);
}

ui_jam_action_t ui_jam_dialog(const char *format,...)
{
    ULONG rc;
    char *txt, *tmp;
    va_list ap;
    const int sz = sizeof(MB2INFO) + 3 * sizeof(MB2D);
    MB2INFO *mb = malloc(sz);

    mb->cb = sz;
    mb->hIcon = WinLoadPointer(HWND_DESKTOP, NULLHANDLE, PTR_SKULL);
    mb->cButtons = 4;
    mb->flStyle = MB_CUSTOMICON | WS_VISIBLE;
    mb->hwndNotify = NULLHANDLE;
    strcpy(mb->mb2d[0].achText, "  ~Hard Reset  ");
    strcpy(mb->mb2d[1].achText, "  ~Soft Reset  ");
    strcpy(mb->mb2d[2].achText, "  ~Monitor     ");
    strcpy(mb->mb2d[3].achText, "  ~Continue    ");
    mb->mb2d[0].idButton = UI_JAM_HARD_RESET;
    mb->mb2d[1].idButton = UI_JAM_RESET;
    mb->mb2d[2].idButton = UI_JAM_MONITOR;
    mb->mb2d[3].idButton = UI_JAM_NONE;
    mb->mb2d[0].flStyle = BS_DEFAULT;
    mb->mb2d[1].flStyle = 0;
    mb->mb2d[2].flStyle = 0;

    va_start(ap, format);
    tmp = lib_mvsprintf(format, ap);
    txt = util_concat("    Chipset reported:\n ", tmp, NULL);
    lib_free(tmp);

    rc = WinMessageBox2(HWND_DESKTOP, HWND_DESKTOP, txt, "VICE/2 Error", 0, mb);
    lib_free(txt);
    lib_free(mb);

    //
    // open monitor dialog
    //
    if (rc == UI_JAM_MONITOR) {
        WinShowWindow(hwndMonitor, 1);
    }

    return rc;
}

int ui_extend_image_dialog(void)
{
    return WinMessageBox(HWND_DESKTOP, HWND_DESKTOP, "Extend disk image in drive to 40 tracks?", "VICE/2 Extend Disk Image", 0, MB_YESNO) == MBID_YES;
}

//------------------------------------------------------------------------

void ui_update_menus(void)
{
}

void ui_display_statustext(const char *text, int fade_out)
{
}

char* ui_get_file(const char *format,...)
{
    return NULL;
}