source: thomson/elec/CrO2/software/zxtape.cpp@ 4a558d7

main
Last change on this file since 4a558d7 was 53c4be3, checked in by Adrien Destugues <pulkomandy@…>, 12 years ago
  • Support for ZX spectrup TAP files.

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

  • Property mode set to 100644
File size: 1.1 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 "zxtape.h"
8
9#include <fstream>
10#include <iostream>
11#include <string.h>
12
13ZXTAP::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
33ZXTAP::Block::Block(int length)
34 : Tape::Block(length)
35{
36}
37
38bool ZXTAP::Block::isFile() const
39{
40 return data[0] == 0;
41}
42
43bool ZXTAP::Block::isControl() const
44{
45 return isFile();
46}
47
48const 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.