VirtualC64 v5.0 beta
Commodore 64 Emulator
Loading...
Searching...
No Matches
Snapshot.h
1// -----------------------------------------------------------------------------
2// This file is part of VirtualC64
3//
4// Copyright (C) Dirk W. Hoffmann. www.dirkwhoffmann.de
5// This FILE is dual-licensed. You are free to choose between:
6//
7// - The GNU General Public License v3 (or any later version)
8// - The Mozilla Public License v2
9//
10// SPDX-License-Identifier: GPL-3.0-or-later OR MPL-2.0
11// -----------------------------------------------------------------------------
12
13#pragma once
14
15#include "AnyFile.h"
16#include "Constants.h"
17
18namespace vc64 {
19
20class C64;
21
22struct Thumbnail {
23
24 // Image size
25 isize width, height;
26
27 // Raw texture data
28 u32 screen[Texture::height * Texture::width];
29
30 // Creation date and time
31 time_t timestamp;
32
33 // Factory methods
34 static Thumbnail *makeWithC64(const C64 &c64, isize dx = 1, isize dy = 1);
35
36 // Takes a screenshot from the current texture
37 void take(const C64 &c64, isize dx = 1, isize dy = 1);
38};
39
40struct SnapshotHeader {
41
42 // Magic bytes ('V','C','6','4')
43 char magic[4];
44
45 // Version number (V major.minor.subminor)
46 u8 major;
47 u8 minor;
48 u8 subminor;
49 u8 beta;
50
51 // Preview image
52 Thumbnail screenshot;
53};
54
55class Snapshot : public AnyFile {
56
57public:
58
59 //
60 // Class methods
61 //
62
63 static bool isCompatible(const fs::path &path);
64 static bool isCompatible(std::istream &stream);
65
66
67 //
68 // Initializing
69 //
70
71 Snapshot(const fs::path &path) throws { init(path); }
72 Snapshot(const u8 *buf, isize len) throws { init(buf, len); }
73 Snapshot(isize capacity);
74 Snapshot(C64 &c64);
75
76
77 //
78 // Methods from CoreObject
79 //
80
81 const char *objectName() const override { return "Snapshot"; }
82
83
84 //
85 // Methods from AnyFile
86 //
87
88 FileType type() const override { return FILETYPE_SNAPSHOT; }
89 bool isCompatiblePath(const fs::path &path) override { return isCompatible(path); }
90 bool isCompatibleStream(std::istream &stream) override { return isCompatible(stream); }
91 void finalizeRead() throws override;
92
93
94 //
95 // Accessing
96 //
97
98 std::pair <isize,isize> previewImageSize() const override;
99 const u32 *previewImageData() const override;
100 time_t timestamp() const override;
101
102 // Checks the snapshot version number
103 bool isTooOld() const;
104 bool isTooNew() const;
105 bool isBeta() const;
106 bool matches() { return !isTooOld() && !isTooNew(); }
107
108 // Returns a pointer to the snapshot header
109 SnapshotHeader *getHeader() const { return (SnapshotHeader *)data; }
110
111 // Returns a pointer to the thumbnail image
112 const Thumbnail &getThumbnail() const { return getHeader()->screenshot; }
113
114 // Returns pointer to the core data
115 u8 *getSnapshotData() const { return data + sizeof(SnapshotHeader); }
116
117 // Records a screenshot
118 void takeScreenshot(C64 &c64);
119};
120
121}
static const long height
Height of the emulator texture in texels.
Definition Constants.h:105
static const long width
Width of the emulator texture in texels.
Definition Constants.h:108
VirtualC64 project namespace.
Definition CmdQueue.cpp:16