-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtzxloader.h
56 lines (40 loc) · 1.51 KB
/
tzxloader.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// ==============================================================================
// PROJECT: zqloader
// FILE: tzxloader.h
// DESCRIPTION: Definition of class TzxLoader.
//
// Copyright (c) 2023 Daan Scherft [Oxidaan]
// This project uses the MIT license. See LICENSE.txt for details.
// ==============================================================================
#pragma once
#include <cstdint>
#include <functional>
#include <string>
#include "datablock.h"
/// Loads TZX files.
/// Found blocks are handled through function set at SetOnHandleTapBlock.
/// See: http://k1.spdns.de/Develop/Projects/zasm/Info/TZX%20format.html
/// or: https://worldofspectrum.net/TZXformat.html
class TzxLoader
{
using HandleTapBlockFun = std::function<bool (DataBlock, std::string)>;
public:
/// CTOR.
TzxLoader()
{}
/// Loads given tzx file from given file. Ignores until given zxfilename is found.
template <typename TPath>
TzxLoader& Load(const TPath &p_filename, const std::string &p_zxfilename);
/// Set callback when tapblock found
TzxLoader& SetOnHandleTapBlock(HandleTapBlockFun p_fun)
{
m_OnHandleTapBlock = std::move(p_fun);
return *this;
}
private:
bool HandleTapBlock(std::istream& p_stream, std::string p_zxfilename, int p_length);
// Loads tzx file from given stream. Ignores until given zxfilename is ound.
TzxLoader& Read(std::istream& p_stream, const std::string &p_zxfilename);
private:
HandleTapBlockFun m_OnHandleTapBlock;
};