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

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

Port to Haiku. Untested.

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

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