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 "zxtape.h"
|
---|
8 |
|
---|
9 | #include <fstream>
|
---|
10 | #include <iostream>
|
---|
11 | #include <string.h>
|
---|
12 |
|
---|
13 | ZXTAP::ZXTAP(const char* name) throw (const char*)
|
---|
14 | {
|
---|
15 | std::ifstream stream(name, std::ifstream::in | std::ifstream::binary);
|
---|
16 |
|
---|
17 | if (!stream.is_open()) throw "Could not open file.";
|
---|
18 | if (!stream.good()) throw "File error.";
|
---|
19 |
|
---|
20 | uint16_t blksize;
|
---|
21 | do {
|
---|
22 | stream.read((char*)&blksize,sizeof(blksize));
|
---|
23 |
|
---|
24 | Block* block = new Block(blksize);
|
---|
25 | stream.read((char*)block->data, block->length);
|
---|
26 |
|
---|
27 | blocks.push_back(block);
|
---|
28 | } while (stream.good());
|
---|
29 |
|
---|
30 | stream.close();
|
---|
31 | }
|
---|
32 |
|
---|
33 | ZXTAP::Block::Block(int length)
|
---|
34 | : Tape::Block(length)
|
---|
35 | {
|
---|
36 | }
|
---|
37 |
|
---|
38 | bool ZXTAP::Block::isFile() const
|
---|
39 | {
|
---|
40 | return data[0] == 0;
|
---|
41 | }
|
---|
42 |
|
---|
43 | bool ZXTAP::Block::isControl() const
|
---|
44 | {
|
---|
45 | return isFile();
|
---|
46 | }
|
---|
47 |
|
---|
48 | const std::string ZXTAP::Block::getName() const
|
---|
49 | {
|
---|
50 | if (isFile())
|
---|
51 | {
|
---|
52 | char name[11];
|
---|
53 | memcpy(name, data+2, 10);
|
---|
54 | name[10] = 0;
|
---|
55 | return std::string(name);
|
---|
56 | }
|
---|
57 |
|
---|
58 | if (isControl()) return std::string("EOF");
|
---|
59 | return std::string("DATA");
|
---|
60 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.