~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
/*
 * vsidui.c - Implementation of the VSID UI.
 *
 * Written by
 *  Thomas Bretz <tbretz@ph.tum.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.
 *
 */

#define INCL_DOSPROCESS // DosSetPriority
#define INCL_WINDIALOGS // WinSendDlgItemMsg

#include "vice.h"

#include <os2.h>
#include <stdlib.h>

#ifdef WATCOM_COMPILE
#include <process.h>
#endif

#include "dialogs.h"
#include "dlg-vsid.h"
#include "dlg-emulator.h" // hwndVsidEmulator

#include "lib.h"
#include "log.h"
#include "machine.h"            // MACHINE_SYNC_PAL
#include "resources.h"
#include "snippets\pmwin2.h"  // Win*Spin

static log_t vsidlog = LOG_ERR;

extern int trigger_shutdown;

HWND hwndVsid = NULLHANDLE;

void vsid_mainloop(VOID *arg)
{
    APIRET rc;

    //
    // get pm anchor, create msg queue
    //
    HAB hab = WinInitialize(0);            // Initialize PM
    HMQ hmq = WinCreateMsgQueue(hab, 0);   // Create Msg Queue

    //
    // open dialog
    //
    hwndVsid = vsid_dialog();

    if (rc = DosSetPriority(PRTYS_THREAD, PRTYC_REGULAR, 1, 0)) {
        log_error(vsidlog, "DosSetPriority (rc=%li)", rc);
    }

    //
    // MAINLOOP
    //
    log_message(vsidlog, "PM initialized.");
    WinProcessDlg(hwndVsid);
    log_message(vsidlog, "Releasing PM.");

    //
    // WinProcessDlg() does NOT destroy the window on return! Do it here,
    // otherwise the window procedure won't ever get a WM_DESTROY,
    // which we may want :-)
    //
    WinDestroyWindow(hwndVsid);


    //
    // destroy msg queue, release pm anchor
    //
    if (!WinDestroyMsgQueue(hmq)) {
        log_error(vsidlog, "Destroying Msg Queue.");
    }
    if (!WinTerminate(hab)) {
        log_error(vsidlog, "Releasing PM anchor.");
    }

    log_message(vsidlog, "PM released.");

    //
    // shutdown emulator thread
    //
    trigger_shutdown = 1;

    DosSleep(5000); // wait 5 seconds
    log_error(vsidlog, "Brutal Exit!");
    exit(0);        // end VICE in all cases
}

int vsid_ui_init(void)
{
    vsidlog = log_open("Vsidui");

    _beginthread(vsid_mainloop, NULL, 0x4000, NULL);

    while (!hwndVsid) {
        DosSleep(1);
    }

    log_message(LOG_DEFAULT, "--> SID Player mode <--\n");

    return 0;
}

void vsid_ui_display_irqtype(const char *irq)
{
    char *txt = lib_msprintf("Interrupt: %s", irq);

    WinSetDlgItemText(hwndVsid, ID_TIRQ, txt);
    lib_free(txt);
}

void vsid_ui_display_name(const char *name)
{
    WinSetDlgItemText(hwndVsid, ID_TNAME, (char*)name);
}

void vsid_ui_display_author(const char *author)
{
    WinSetDlgItemText(hwndVsid, ID_TAUTHOR, (char*)author);
}

void vsid_ui_display_copyright(const char *copyright)
{
    WinSetDlgItemText(hwndVsid, ID_TCOPYRIGHT, (char*)copyright);
}

void vsid_ui_display_sync(int sync)
{
    char *txt;

    switch (sync) {
        case MACHINE_SYNC_PAL:
            txt = "Synchronization: PAL";
            break;
        case MACHINE_SYNC_NTSC:
            txt =  "Synchronization: NTSC";
            break;
        case MACHINE_SYNC_NTSCOLD:
            txt =  "Synchronization: NTSC (old)";
            break;
    }
    WinSetDlgItemText(hwndVsid, ID_TSYNC, txt);
}

void vsid_ui_display_sid_model(int model)
{
    WinSetDlgItemText(hwndVsid, ID_TSID, model ? "SID-Chip: MOS8580" : "SID-Chip: MOS6581");
}

void vsid_ui_set_default_tune(int nr)
{
}

void vsid_ui_display_tune_nr(int nr)
{
    char txt[3] = "-";

    if (nr < 100) {
        sprintf(txt, "%d", nr);
    }
    WinSetDlgItemText(hwndVsid, ID_TUNENO, txt);
    WinSetDlgSpinVal(hwndVsid, SPB_SETTUNE, nr);
}

void vsid_ui_display_nr_of_tunes(int count)
{
    char txt[3] = "-";

    if (count < 100) {
        sprintf(txt, "%d", count);
    }
    WinSetDlgItemText(hwndVsid, ID_TUNES, txt);
}

void vsid_ui_display_time(unsigned int sec)
{
    char txt[6] = "--:--";

    if (sec < 600) {
        sprintf(txt, "%02d:%02d", (sec/60)%100, sec%60);
    }
    WinSetDlgItemText(hwndVsid, ID_TIME, txt);
}

void vsid_ui_close(void)
{
}

void vsid_ui_setdrv(char* driver_info_text)
{
}