main
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 |
|
---|
15 | Tape::~Tape()
|
---|
16 | {
|
---|
17 | for(Block* block: blocks) delete block;
|
---|
18 | }
|
---|
19 |
|
---|
20 | Tape* 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 |
|
---|
33 | int Tape::getBlockCount() const
|
---|
34 | {
|
---|
35 | return blocks.size();
|
---|
36 | }
|
---|
37 |
|
---|
38 | Tape::Block& Tape::getBlock(int id)
|
---|
39 | {
|
---|
40 | return *blocks[id];
|
---|
41 | }
|
---|
42 |
|
---|
43 | const Tape::Block& Tape::getBlock(int id) const
|
---|
44 | {
|
---|
45 | return *blocks[id];
|
---|
46 | }
|
---|
47 |
|
---|
48 | // TAPE BLOCKS
|
---|
49 |
|
---|
50 | Tape::Block::Block(int length)
|
---|
51 | {
|
---|
52 | this->length = length;
|
---|
53 | data = new uint8_t[length];
|
---|
54 | }
|
---|
55 |
|
---|
56 | Tape::Block::Block(const Block& other)
|
---|
57 | {
|
---|
58 | length = other.length;
|
---|
59 | data = new uint8_t[length];
|
---|
60 | memcpy(data, other.data, length);
|
---|
61 | }
|
---|
62 |
|
---|
63 | const 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 |
|
---|
75 | Tape::Block::~Block()
|
---|
76 | {
|
---|
77 | delete[] data;
|
---|
78 | }
|
---|
79 |
|
---|
80 |
|
---|
Note:
See
TracBrowser
for help on using the repository browser.