source: thomson/elec/CrO2/software/cro2.cpp@ 32c7682

main
Last change on this file since 32c7682 was 32c7682, checked in by Adrien Destugues <pulkomandy@…>, 12 years ago
  • Poll motor on pin status and report it in the GUI.
  • Some cleanup of device class.

git-svn-id: svn://localhost/thomson@12 85ae3b6b-dc8f-4344-a89d-598714f2e4e5

  • Property mode set to 100644
File size: 3.4 KB
Line 
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 <iostream>
8#include <stdio.h>
9#include <stdlib.h>
10#include <string.h>
11#include <stdint.h>
12#include <unistd.h>
13
14#include <iup.h>
15#include <iupcontrols.h>
16
17#include "device.h"
18#include "poller.h"
19
20/* UI */
21int menu_open(Ihandle* that)
22{
23 IupPopup(IupFileDlg(), IUP_CENTER, IUP_CENTER);
24 return IUP_DEFAULT;
25}
26
27int menu_exit(Ihandle* that)
28{
29 return IUP_CLOSE;
30}
31
32
33Ihandle* motoron;
34void GUI_open(int* argc, char*** argv)
35{
36 IupOpen(argc, argv);
37// IupControlsOpen();
38
39 IupSetFunction("OPEN", menu_open);
40 IupSetFunction("EXIT", menu_exit);
41
42 Ihandle* menu = IupMenu(
43 IupSubmenu("File",
44 IupMenu(
45 IupItem("Open", "OPEN"),
46 IupItem("Exit", "EXIT"),
47 NULL
48 )
49 ),
50 NULL
51 );
52
53 // CONTROL
54 motoron = IupProgressBar();
55 IupSetAttribute(motoron, "RASTERSIZE", "16x16");
56
57 // EXPLORE
58 Ihandle* platformlist = IupList(NULL);
59 IupSetAttribute(platformlist, "EXPAND", "HORIZONTAL");
60 IupSetAttribute(platformlist, "DROPDOWN", "YES");
61 IupSetAttribute(platformlist, "1", "MO5");
62 IupSetAttribute(platformlist, "VALUE", "1");
63
64 Ihandle* blocklist = IupTree();
65 IupSetAttribute(blocklist, "EXPAND", "VERTICAL");
66
67 Ihandle* tabs = IupTabs(
68 IupVbox(
69 IupHbox(
70 IupLabel("Motor"),
71 motoron,
72 NULL
73 ),
74 IupHbox(
75 IupToggle("play",NULL),
76 IupToggle("REC",NULL),
77 NULL
78 ),
79 NULL
80 ),
81 IupVbox(
82 IupHbox(
83 IupLabel("Format:"),
84 platformlist,
85 NULL
86 ),
87 IupHbox(
88 blocklist,
89 IupVbox(
90// IupMatrix(NULL),
91 IupLabel("Checksum:"),
92 NULL
93 ),
94 NULL
95 )
96 ),
97 NULL
98 );
99
100 IupSetAttribute(tabs,"TABTITLE0", "Control");
101 IupSetAttribute(tabs,"TABTITLE1", "Explore");
102
103 Ihandle* dialog = IupDialog(tabs);
104 IupSetAttribute(dialog, "TITLE", "CrO2 tape emulator");
105 IupSetAttributeHandle(dialog, "MENU", menu);
106 IupShow(dialog);
107
108 // Run the timer
109 startPolling();
110
111 IupMainLoop();
112
113 IupClose();
114}
115
116
117int main(int argc, char **argv)
118{
119 //usb_dev_handle *handle = NULL;
120 unsigned char buffer[275];
121 int nBytes = 0;
122
123 if(argc < 2){
124 GUI_open(&argc, &argv);
125 exit(0);
126 }
127
128 try {
129 Device& dev = Device::getDevice(); // Constructor inits communication.
130
131 if(strcmp(argv[1], "get") == 0){
132 memset(buffer, 0, 275);
133 nBytes = dev.read(buffer, sizeof(buffer));
134 }else if(strcmp(argv[1], "put") == 0){
135
136 // wait for motor on
137 while (dev.getStatus() & 8)
138 usleep(1000000);
139
140 // load file
141 FILE* fptr = fopen(argv[2], "rb");
142 int blockid;
143 uint8_t blktype, blksize;
144 sscanf(argv[3], "%d", &blockid);
145
146 // fast-forward to requested block
147 do
148 {
149 do
150 {
151 fread(&blktype, 1, 1, fptr);
152 if (feof(fptr))
153 {
154 fprintf(stderr, "end of file.\n");
155 fclose(fptr);
156 exit(0);
157 }
158 }
159 while(blktype != 0x5A); // skip sync header
160
161 fread(&blktype, 1, 1, fptr);
162 fread(&blksize, 1, 1, fptr);
163 blksize -= 2;
164 fread(buffer, 1, blksize + 1, fptr);
165 if (blktype == 0)
166 {
167 // new file
168 printf("%.11s\n",buffer);
169 }
170 }
171 while (blockid --);
172
173 fclose(fptr);
174
175 nBytes = dev.write(buffer, blksize, blktype);
176 }else{
177 // TODO print usage
178 exit(2);
179 }
180
181 if (nBytes < 0) fprintf(stderr, "USB error %s\n", usb_strerror());
182 return 0;
183 }
184 catch(const char* error)
185 {
186 std::cerr << error << std::endl;
187 }
188}
189
Note: See TracBrowser for help on using the repository browser.