source: thomson/elec/CrO2/software/k5.cpp@ c7b4218

main
Last change on this file since c7b4218 was c7b4218, checked in by Adrien Destugues <pulkomandy@…>, 12 years ago
  • Move GUI in its own class
  • Design C++ callbacksystem for IUP
  • Load file from menu

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

  • Property mode set to 100644
File size: 1.5 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 "k5.h"
8
9#include <fstream>
10#include <string.h>
11
12K5::Block::Block(int length,uint8_t type)
13{
14 this->length = length;
15 data = new uint8_t[length];
16 this->type = type;
17}
18
19K5::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
27K5::Block::~Block()
28{
29 delete[] data;
30}
31
32
33K5::K5(const char* name)
34{
35 std::ifstream stream(name, std::ifstream::in | std::ifstream::binary);
36
37 if (!stream.is_open()) throw "Could not open file.";
38 if (!stream.good()) throw "File error.";
39
40 uint8_t byte;
41
42 do {
43 do {
44 byte = stream.get();
45 if (stream.eof())
46 return;
47 } while (byte != 0x5A); // Skip pilot tone and sync bytes
48 // TODO make sure this is a standard block ?
49
50 uint8_t blktype = stream.get();
51 int blksize = stream.get(); // includes checksum
52 if (blksize == 0) blksize = 256;
53 blksize --;
54 Block block(blksize, blktype);
55 stream.read((char*)block.data, block.length);
56
57 blocks.push_back(block);
58/*
59 if (block.type == 0)
60 {
61 printf("FILE: %.11s\n",block.data);
62 }
63
64 printf("blk type %d size %d (%d)\n", block.type, block.length, (int)stream.tellg());
65*/
66 } while (stream.good());
67
68
69 stream.close();
70}
71
72int K5::getBlockCount()
73{
74 return blocks.size();
75}
76
77K5::Block K5::getBlock(int id)
78{
79 return blocks[id];
80}
Note: See TracBrowser for help on using the repository browser.