1 | /* CrO2 datassette emulator
|
---|
2 | * Copyright 2012, Adrien Destugues <pulkomandy@pulkomandy.ath.cx>
|
---|
3 | *
|
---|
4 | * Distributed under the terms of the MIT licence.
|
---|
5 | */
|
---|
6 |
|
---|
7 | #include "gui.h"
|
---|
8 |
|
---|
9 | #include "device.h"
|
---|
10 | #include "k5.h"
|
---|
11 |
|
---|
12 | #include <stdint.h>
|
---|
13 | #include <iupcontrols.h>
|
---|
14 |
|
---|
15 | // Start status poller "thread"
|
---|
16 | int pollStatus(Ihandle* ih)
|
---|
17 | {
|
---|
18 | try {
|
---|
19 | Ihandle* motoron = (Ihandle*)IupGetAttribute(ih, "target");
|
---|
20 |
|
---|
21 | uint8_t status = Device::getDevice().getStatus();
|
---|
22 | if (status & 8)
|
---|
23 | IupSetAttribute(motoron, "VALUE", "0"); // motor OFF
|
---|
24 | else
|
---|
25 | IupSetAttribute(motoron, "VALUE", "1"); // motor ON
|
---|
26 | } catch(const char*) {
|
---|
27 | // Silently ignore exception if device is not available - not a good
|
---|
28 | // idea to handle it from a timer...
|
---|
29 | // Keep the timer running so it starts working when the device is
|
---|
30 | // plugged
|
---|
31 | }
|
---|
32 | return IUP_DEFAULT;
|
---|
33 | }
|
---|
34 |
|
---|
35 | void startPolling(Ihandle* target) {
|
---|
36 | Ihandle* timer = IupTimer();
|
---|
37 |
|
---|
38 | IupSetAttribute(timer, "target", (const char*)target);
|
---|
39 |
|
---|
40 | IupSetAttribute(timer, "TIME", "300");
|
---|
41 | IupSetCallback(timer, "ACTION_CB", pollStatus);
|
---|
42 | IupSetAttribute(timer, "RUN", "YES");
|
---|
43 | }
|
---|
44 |
|
---|
45 | /* UI */
|
---|
46 |
|
---|
47 | Gui::Gui(int* argc, char*** argv)
|
---|
48 | {
|
---|
49 | file = NULL;
|
---|
50 |
|
---|
51 | IupOpen(argc, argv);
|
---|
52 | // IupControlsOpen();
|
---|
53 |
|
---|
54 | Ihandle* menu_open = IupItem("Open", NULL);
|
---|
55 | Ihandle* menu_exit = IupItem("Exit", NULL);
|
---|
56 | Callback<Gui>::create(menu_open, "ACTION", this, &Gui::menu_open);
|
---|
57 | Callback<Gui>::create(menu_exit, "ACTION", this, &Gui::menu_exit);
|
---|
58 |
|
---|
59 | Ihandle* menu = IupMenu(
|
---|
60 | IupSubmenu("File",
|
---|
61 | IupMenu(
|
---|
62 | menu_open,
|
---|
63 | menu_exit,
|
---|
64 | NULL
|
---|
65 | )
|
---|
66 | ),
|
---|
67 | NULL
|
---|
68 | );
|
---|
69 |
|
---|
70 | // CONTROL
|
---|
71 | Ihandle* motoron = IupProgressBar();
|
---|
72 | IupSetAttribute(motoron, "RASTERSIZE", "16x16");
|
---|
73 |
|
---|
74 | // EXPLORE
|
---|
75 | Ihandle* platformlist = IupList(NULL);
|
---|
76 | IupSetAttribute(platformlist, "EXPAND", "HORIZONTAL");
|
---|
77 | IupSetAttribute(platformlist, "DROPDOWN", "YES");
|
---|
78 | IupSetAttribute(platformlist, "1", "MO5");
|
---|
79 | IupSetAttribute(platformlist, "VALUE", "1");
|
---|
80 |
|
---|
81 | Ihandle* blocklist = IupTree();
|
---|
82 | IupSetAttribute(blocklist, "EXPAND", "VERTICAL");
|
---|
83 |
|
---|
84 | Ihandle* playToggle = IupToggle("play", NULL);
|
---|
85 | Callback<Gui, int>::create(playToggle, "ACTION", this, &Gui::setPlaying);
|
---|
86 |
|
---|
87 | Ihandle* tabs = IupTabs(
|
---|
88 | IupVbox(
|
---|
89 | IupHbox(
|
---|
90 | IupLabel("Motor"),
|
---|
91 | motoron,
|
---|
92 | NULL
|
---|
93 | ),
|
---|
94 | IupHbox(
|
---|
95 | playToggle,
|
---|
96 | IupToggle("REC",NULL),
|
---|
97 | NULL
|
---|
98 | ),
|
---|
99 | NULL
|
---|
100 | ),
|
---|
101 | IupVbox(
|
---|
102 | IupHbox(
|
---|
103 | IupLabel("Format:"),
|
---|
104 | platformlist,
|
---|
105 | NULL
|
---|
106 | ),
|
---|
107 | IupHbox(
|
---|
108 | blocklist,
|
---|
109 | IupVbox(
|
---|
110 | // IupMatrix(NULL),
|
---|
111 | IupLabel("Checksum:"),
|
---|
112 | NULL
|
---|
113 | ),
|
---|
114 | NULL
|
---|
115 | )
|
---|
116 | ),
|
---|
117 | NULL
|
---|
118 | );
|
---|
119 |
|
---|
120 | IupSetAttribute(tabs,"TABTITLE0", "Control");
|
---|
121 | IupSetAttribute(tabs,"TABTITLE1", "Explore");
|
---|
122 |
|
---|
123 | Ihandle* dialog = IupDialog(tabs);
|
---|
124 | IupSetAttribute(dialog, "TITLE", "CrO2 tape emulator");
|
---|
125 | IupSetAttributeHandle(dialog, "MENU", menu);
|
---|
126 | IupShow(dialog);
|
---|
127 |
|
---|
128 | // Run the timer
|
---|
129 | startPolling(motoron);
|
---|
130 |
|
---|
131 | IupMainLoop();
|
---|
132 |
|
---|
133 | IupClose();
|
---|
134 | }
|
---|
135 |
|
---|
136 |
|
---|
137 | Gui::~Gui()
|
---|
138 | {
|
---|
139 | delete file;
|
---|
140 | }
|
---|
141 |
|
---|
142 |
|
---|
143 | int Gui::menu_open()
|
---|
144 | {
|
---|
145 | char name[65536];
|
---|
146 | name[0] = 0;
|
---|
147 | if (IupGetFile(name) == 0)
|
---|
148 | {
|
---|
149 | // Load file
|
---|
150 | file = new K5(name);
|
---|
151 | }
|
---|
152 | return IUP_DEFAULT;
|
---|
153 | }
|
---|
154 |
|
---|
155 | int Gui::menu_exit()
|
---|
156 | {
|
---|
157 | return IUP_CLOSE;
|
---|
158 | }
|
---|
159 |
|
---|
160 | int Gui::setPlaying(int state)
|
---|
161 | {
|
---|
162 | if (state == 0)
|
---|
163 | {
|
---|
164 | // pause
|
---|
165 | } else {
|
---|
166 | // play
|
---|
167 | Device::getDevice().write(*file);
|
---|
168 | }
|
---|
169 |
|
---|
170 | return IUP_DEFAULT;
|
---|
171 | }
|
---|