source: thomson/elec/CrO2/software/Tape.cpp@ f7791a2

main
Last change on this file since f7791a2 was f7791a2, checked in by Adrien Destugues <pulkomandy@…>, 11 years ago

Fix filetype detection

git-svn-id: svn://localhost/thomson@32 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 "Tape.h"
8
9#include "k5.h"
10#include "zxtape.h"
11
12#include <string.h>
13#include <string>
14#include <stdexcept>
15
16Tape::~Tape()
17{
18 for(Block* block: blocks) delete block;
19}
20
21Tape* Tape::load(const char* filename) throw (const char*)
22{
23 std::string fnam(filename);
24 try {
25 std::string fext(fnam.substr(fnam.length() - 3));
26
27 // Load formats identified only by extension last
28 if (fext == "TAP" || fext == "tap")
29 return new ZXTAP(filename);
30 if (fext == ".K5" || fext == ".k5")
31 return new K5(filename);
32 } catch(std::out_of_range e) {}
33 throw "Unable to guess tape format";
34}
35
36int Tape::getBlockCount() const
37{
38 return blocks.size();
39}
40
41Tape::Block& Tape::getBlock(int id)
42{
43 return *blocks[id];
44}
45
46const Tape::Block& Tape::getBlock(int id) const
47{
48 return *blocks[id];
49}
50
51// TAPE BLOCKS
52
53Tape::Block::Block(int length)
54{
55 this->length = length;
56 data = new uint8_t[length];
57}
58
59Tape::Block::Block(const Block& other)
60{
61 length = other.length;
62 data = new uint8_t[length];
63 memcpy(data, other.data, length);
64}
65
66const Tape::Block& Tape::Block::operator=(const Block& other)
67{
68 delete[] data;
69 // May not be null ?
70
71 length = other.length;
72 data = new uint8_t[length];
73 memcpy(data, other.data, length);
74
75 return *this;
76}
77
78Tape::Block::~Block()
79{
80 delete[] data;
81}
82
83
Note: See TracBrowser for help on using the repository browser.