Changeset 53c4be3 in thomson for elec/CrO2/software/k5.cpp


Ignore:
Timestamp:
Feb 5, 2012, 3:25:32 PM (12 years ago)
Author:
Adrien Destugues <pulkomandy@…>
Branches:
main
Children:
1b74fa2
Parents:
c2a9854
Message:
  • Support for ZX spectrup TAP files.

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • elec/CrO2/software/k5.cpp

    rc2a9854 r53c4be3  
    1010#include <string.h>
    1111
    12 K5::Block::Block(int length,uint8_t type)
    13 {
    14         this->length = length;
    15         data = new uint8_t[length];
    16         this->type = type;
    17 }
    18 
    19 K5::Block::Block(const Block& other)
    20 {
    21         length = other.length;
    22         type = other.type;
    23         data = new uint8_t[length];
    24         memcpy(data, other.data, length);
    25 }
    26 
    27 const K5::Block& K5::Block::operator=(const Block& other)
    28 {
    29         delete[] data;
    30                 // May not be null ?
    31 
    32         length = other.length;
    33         type = other.type;
    34         data = new uint8_t[length];
    35         memcpy(data, other.data, length);
    36 
    37         return *this;
    38 }
    39 
    40 K5::Block::~Block()
    41 {
    42         delete[] data;
    43 }
    44 
    45 
    46 K5::K5(const char* name)
     12K5::K5(const char* name) throw (const char*)
    4713{
    4814        std::ifstream stream(name, std::ifstream::in | std::ifstream::binary);
     
    6531                if (blksize == 0) blksize = 256;
    6632                blksize --;
    67                 Block block(blksize, blktype);
    68                 stream.read((char*)block.data, block.length);
     33                Block* block = new Block(blksize, blktype);
     34                stream.read((char*)block->data, block->length);
    6935
    7036                blocks.push_back(block);
    71 /*
    72                 if (block.type == 0)
    73                 {
    74                         printf("FILE: %.11s\n",block.data);
    75                 }
    76                
    77                 printf("blk type %d size %d (%d)\n", block.type, block.length, (int)stream.tellg());
    78 */
    7937        } while (stream.good());
    8038
     
    8341}
    8442
    85 int K5::getBlockCount()
     43
     44K5::Block::Block(int length, uint8_t type)
     45        : Tape::Block(length)
    8646{
    87         return blocks.size();
     47        this->type = type;
    8848}
    8949
    90 K5::Block K5::getBlock(int id)
     50bool K5::Block::isFile() const
    9151{
    92         return blocks[id];
     52        return type == 0;
    9353}
     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 TracChangeset for help on using the changeset viewer.