source: thomson/elec/CrO2/software/k5.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.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 "k5.h"
8
9#include <fstream>
10#include <string.h>
11
12K5::K5(const char* name) throw (const char*)
13{
14 std::ifstream stream(name, std::ifstream::in | std::ifstream::binary);
15
16 if (!stream.is_open()) throw "Could not open file.";
17 if (!stream.good()) throw "File error.";
18
19 uint8_t byte;
20
21 do {
22 do {
23 byte = stream.get();
24 if (stream.eof())
25 return;
26 } while (byte != 0x5A); // Skip pilot tone and sync bytes
27 // TODO make sure this is a standard block ?
28
29 uint8_t blktype = stream.get();
30 int blksize = stream.get(); // includes checksum
31 if (blksize == 0) blksize = 256;
32 blksize --;
33 Block* block = new Block(blksize, blktype);
34 stream.read((char*)block->data, block->length);
35
36 blocks.push_back(block);
37 } while (stream.good());
38
39
40 stream.close();
41}
42
43
44K5::Block::Block(int length, uint8_t type)
45 : Tape::Block(length)
46{
47 this->type = type;
48}
49
50bool K5::Block::isFile() const
51{
52 return type == 0;
53}
54
55bool K5::Block::isControl() const
56{
57 return (type == 0) || (type == 0xFF);
58}
59
60const std::string K5::Block::getName() const
61{
62 if (isFile())
63 {
64 char name[12];
65 memcpy(name, data, 11);
66 name[11] = 0;
67 return std::string(name);
68 }
69
70 if (isControl()) return std::string("EOF");
71 return std::string("DATA");
72}
Note: See TracBrowser for help on using the repository browser.