Changeset 53c4be3 in thomson
- Timestamp:
- Feb 5, 2012, 3:25:32 PM (12 years ago)
- Branches:
- main
- Children:
- 1b74fa2
- Parents:
- c2a9854
- Location:
- elec/CrO2/software
- Files:
-
- 4 added
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
elec/CrO2/software/Makefile
rc2a9854 r53c4be3 23 23 all: $(PROGRAM) 24 24 25 $(PROGRAM): $(PROJECT).o device.o gui.o k5.o 25 $(PROGRAM): $(PROJECT).o device.o gui.o k5.o Tape.o zxtape.o 26 26 $(CC) -o $(PROGRAM) $^ $(LIBS) 27 27 -
elec/CrO2/software/cro2.cpp
rc2a9854 r53c4be3 36 36 37 37 // load file 38 K5 file(argv[2]);38 Tape* file = Tape::load(argv[2]); 39 39 40 dev.write(file); 40 dev.write(*file); 41 42 delete file; 41 43 }else{ 42 44 // TODO print usage -
elec/CrO2/software/device.cpp
rc2a9854 r53c4be3 9 9 #include "device.h" 10 10 #include "k5.h" 11 12 #include <typeinfo> 11 13 12 14 bool Device::initOnce = false; … … 134 136 135 137 136 int Device::write( uint8_t* buffer, size_t size, int blktype)138 int Device::write(const uint8_t* buffer, size_t size, int blktype) 137 139 { 138 140 int rqtype = (size == 0) ? USB_ENDPOINT_IN:USB_ENDPOINT_OUT; … … 143 145 144 146 145 void Device::write( K5& file)147 void Device::write(const Tape& file) throw (const char*) 146 148 { 147 149 for (int k = 0; k < file.getBlockCount(); k++) … … 151 153 Sleep(1000); 152 154 153 K5::Block block = file.getBlock(k); 154 155 int nBytes = write(block.data, block.length - 1, block.type); 156 // TODO error handling 155 const Tape::Block& block = file.getBlock(k); 156 try { 157 const K5::Block& moblock = dynamic_cast<const K5::Block&>(block); 158 write(moblock.data, moblock.length - 1, moblock.type); 159 // TODO error handling on write 160 } catch (std::bad_cast x) { 161 throw "Only MO5 files supported so far. Sorry!"; 162 }; 157 163 158 164 // TODO wait for correct time (read status from usb OR compute from size+type) -
elec/CrO2/software/device.h
rc2a9854 r53c4be3 10 10 #include <lusb0_usb.h> 11 11 12 class K5;12 class Tape; 13 13 14 14 class Device … … 20 20 21 21 int read(uint8_t* buffer, size_t max); // Fill the buffer with data from device 22 int write( uint8_t* buffer, size_t size, int blktype);23 void write( K5& file);22 int write(const uint8_t* buffer, size_t size, int blktype); 23 void write(const Tape& file) throw (const char*); 24 24 uint8_t getStatus(); 25 25 -
elec/CrO2/software/gui.cpp
rc2a9854 r53c4be3 13 13 #include <string.h> 14 14 #include <sstream> 15 #include <ios tream>15 #include <ios> 16 16 17 17 #include <iupcontrols.h> … … 94 94 Callback<Gui, int, int, int>::create(blocklist, "SELECTION_CB", this, &Gui::selectBlock); 95 95 96 Ihandle*hexEd = IupMatrix(NULL);96 hexEd = IupMatrix(NULL); 97 97 98 98 // Setup title cells 99 IupSetAttribute(hexEd, "NUMLIN", "16"); 99 IupSetAttribute(hexEd, "FONT", "Courier, 10"); 100 IupSetAttribute(hexEd, "FONT*:17", "Courier, 10"); 100 101 IupSetAttribute(hexEd, "NUMCOL", "17"); 101 IupSetAttribute(hexEd, "WIDTHDEF", "12"); 102 IupSetAttribute(hexEd, "WIDTH17", "48"); 103 IupSetAttribute(hexEd, "USETITLESIZE", "YES"); 104 IupSetAttribute(hexEd, "FONT", "Courier, Bold 12"); 102 IupSetAttribute(hexEd, "WIDTHDEF", "10"); 103 IupSetAttribute(hexEd, "WIDTH17", "105"); 104 IupSetAttribute(hexEd, "WIDTH0", "12"); 105 IupSetAttribute(hexEd, "HEIGHT0", "8"); 106 IupSetAttribute(hexEd, "SIZE", "400x230"); 105 107 IupSetAttribute(hexEd, "EXPAND", "YES"); 108 IupSetAttribute(hexEd, "ALIGNMENT", "ALEFT"); 106 109 Callback<Gui, const char*, int, int>::create(hexEd, "VALUE_CB", this, &Gui::matVal); 107 110 … … 173 176 { 174 177 // Load file 175 file = new K5(name); 178 try { 179 file = Tape::load(name); 180 } catch (const char* error) { 181 puts(error); 182 return IUP_DEFAULT; 183 } 176 184 177 185 // Fill in EXPLORE tab … … 179 187 int lastfile = -1; 180 188 189 IupSetAttribute(blocklist, "DELNODE", "ALL"); 190 181 191 for (int i = 0; i < count; ++i) 182 192 { 183 const K5::Block& blk = file->getBlock(i);184 switch(blk.type)193 const Tape::Block& blk = file->getBlock(i); 194 if (blk.isFile()) 185 195 { 186 case 0: 187 //start block 188 char name[12]; 189 memcpy(name, blk.data, 11); 190 name[11] = 0; 191 192 IupSetAttributeId(blocklist, "INSERTBRANCH", lastfile, name); 193 lastfile = i; 194 break; 195 case 0xFF: 196 // end block 197 IupSetAttributeId(blocklist, "ADDLEAF", i-1, "EOF"); 196 IupSetAttributeId(blocklist, "INSERTBRANCH", lastfile, blk.getName().c_str()); 197 lastfile = i; 198 } else { 199 IupSetAttributeId(blocklist, "ADDLEAF", i-1, blk.getName().c_str()); 200 if (blk.isControl()) 198 201 IupSetAttributeId(blocklist, "IMAGE", i, "IMGLEAF"); 199 break;200 default:201 // regular block202 IupSetAttributeId(blocklist, "ADDLEAF", i-1, "DATA");203 break;204 202 } 205 203 } … … 217 215 if (what) 218 216 { 219 IupSetAttribute(hexEd, "REDRAW", "ALL"); 217 selblock = id; 218 std::ostringstream att; 219 att << (file->getBlock(id).length / 16); 220 IupSetAttribute(hexEd, "NUMLIN", att.str().c_str()); 221 222 IupSetAttribute(hexEd, IUP_REDRAW, "ALL"); 223 } else if (selblock == id) { 224 selblock = -1; 220 225 } 221 226 … … 223 228 } 224 229 225 const char* Gui::matVal(int x, int y)226 { 227 if ( x== 0)228 { 229 switch( y)230 const char* Gui::matVal(int y, int x) 231 { 232 if (y == 0) 233 { 234 switch(x) 230 235 { 231 236 case 0: … … 237 242 std::ostringstream name; 238 243 name << std::hex; 239 name << ( y-1);244 name << (x-1); 240 245 return name.str().c_str(); 241 246 } … … 243 248 } 244 249 245 if (y == 0) 246 { 247 return "C"; 248 } 249 250 return "V"; 250 if (x == 0) 251 { 252 std::ostringstream name; 253 name << std::hex; 254 name << (y-1)*16; 255 return name.str().c_str(); 256 } 257 258 if (file == NULL || selblock < 0 || selblock >= file->getBlockCount()) 259 return ""; 260 const Tape::Block& block = file->getBlock(selblock); 261 262 if (x == 17) 263 { 264 int off = (y-1)*16; 265 std::ostringstream txt; 266 for(int j = 0; j < 16; j++) 267 { 268 if (off + j >= block.length) 269 break; 270 char c = block.data[off+j]; 271 if (isprint(c)) 272 txt << c; 273 else 274 txt << '.'; 275 } 276 return txt.str().c_str(); 277 } else { 278 279 int pos = (y-1) * 16 + (x-1); 280 if (pos >= block.length) 281 return ""; 282 283 return toHex(block.data[pos]); 284 } 251 285 } 252 286 … … 263 297 return IUP_DEFAULT; 264 298 } 299 300 const char* Gui::toHex(int val) 301 { 302 std::ostringstream str; 303 str.flags(std::ios_base::hex | std::ios_base::uppercase); 304 str.width(2); 305 str.fill('0'); 306 str << val; 307 return str.str().c_str(); 308 } -
elec/CrO2/software/gui.h
rc2a9854 r53c4be3 9 9 #include <cstdio> 10 10 11 class K5;11 class Tape; 12 12 13 13 class Gui { … … 20 20 int menu_exit(); 21 21 22 K5* file;22 Tape* file; 23 23 24 24 // Control … … 27 27 // Explore 28 28 int selectBlock(int id, int what); 29 const char* matVal(int x, int y); 29 const char* matVal(int y, int x); 30 const char* toHex(int val); 31 32 int selblock; 30 33 Ihandle* blocklist; 31 34 Ihandle* hexEd; -
elec/CrO2/software/k5.cpp
rc2a9854 r53c4be3 10 10 #include <string.h> 11 11 12 K5::Block::Block(int length,uint8_t type) 13 { 14 this->length = length; 15 data = new uint8_t[length]; 16 this->type = type; 17 } 18 19 K5::Block::Block(const Block& other) 20 { 21 length = other.length; 22 type = other.type; 23 data = new uint8_t[length]; 24 memcpy(data, other.data, length); 25 } 26 27 const K5::Block& K5::Block::operator=(const Block& other) 28 { 29 delete[] data; 30 // May not be null ? 31 32 length = other.length; 33 type = other.type; 34 data = new uint8_t[length]; 35 memcpy(data, other.data, length); 36 37 return *this; 38 } 39 40 K5::Block::~Block() 41 { 42 delete[] data; 43 } 44 45 46 K5::K5(const char* name) 12 K5::K5(const char* name) throw (const char*) 47 13 { 48 14 std::ifstream stream(name, std::ifstream::in | std::ifstream::binary); … … 65 31 if (blksize == 0) blksize = 256; 66 32 blksize --; 67 Block block(blksize, blktype);68 stream.read((char*)block .data, block.length);33 Block* block = new Block(blksize, blktype); 34 stream.read((char*)block->data, block->length); 69 35 70 36 blocks.push_back(block); 71 /*72 if (block.type == 0)73 {74 printf("FILE: %.11s\n",block.data);75 }76 77 printf("blk type %d size %d (%d)\n", block.type, block.length, (int)stream.tellg());78 */79 37 } while (stream.good()); 80 38 … … 83 41 } 84 42 85 int K5::getBlockCount() 43 44 K5::Block::Block(int length, uint8_t type) 45 : Tape::Block(length) 86 46 { 87 return blocks.size();47 this->type = type; 88 48 } 89 49 90 K5::Block K5::getBlock(int id) 50 bool K5::Block::isFile() const 91 51 { 92 return blocks[id];52 return type == 0; 93 53 } 54 55 bool K5::Block::isControl() const 56 { 57 return (type == 0) || (type == 0xFF); 58 } 59 60 const std::string K5::Block::getName() const 61 { 62 if (isFile()) 63 { 64 char name[12]; 65 memcpy(name, data, 11); 66 name[11] = 0; 67 return std::string(name); 68 } 69 70 if (isControl()) return std::string("EOF"); 71 return std::string("DATA"); 72 } -
elec/CrO2/software/k5.h
rc2a9854 r53c4be3 5 5 */ 6 6 7 #include <stdint.h> 8 #include <vector> 7 #include "Tape.h" 9 8 10 class K5 {9 class K5: public Tape { 11 10 public: 12 K5(const char* filename);11 friend class Tape; 13 12 14 class Block { 13 class Block: public Tape::Block 14 { 15 15 public: 16 16 Block(int length, uint8_t type); 17 Block(const Block& other);18 ~Block();19 const Block& operator=(const Block& other);20 17 21 int length; 22 uint8_t* data; 18 bool isFile() const; 19 bool isControl() const; 20 const std::string getName() const; 21 23 22 uint8_t type; 24 23 private: 25 Block() ;24 Block() = delete; 26 25 }; 27 26 28 int getBlockCount();29 Block getBlock(int number);30 31 27 private: 32 K5( );33 std::vector<Block> blocks;28 K5(const char* filename) throw (const char*); 29 K5() = delete; 34 30 };
Note:
See TracChangeset
for help on using the changeset viewer.