VirtualC64 v5.0 beta
Commodore 64 Emulator
Loading...
Searching...
No Matches
CRTFile.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 "CartridgeTypes.h"
16#include "AnyFile.h"
17
18namespace vc64 {
19
20/* For details about the .CRT format,
21 * see: http://vice-emu.sourceforge.net/vice_16.html
22 * http://ist.uwaterloo.ca/~schepers/formats/CRT.TXT
23 *
24 *
25 * As well read the Commodore 64 Programmers Reference Guide pages 260-267.
26 */
27
28class CRTFile : public AnyFile {
29
30 // Maximum number of chip packets in a CRT file
31 static const isize MAX_PACKETS = 128;
32
33 // Number of chips contained in cartridge file
34 isize numberOfChips = 0;
35
36 // Indicates where each chip section starts
37 u8 *chips[MAX_PACKETS] = {};
38
39public:
40
41 //
42 // Class methods
43 //
44
45 static string cartridgeTypeName(CartridgeType type);
46 static bool isCompatible(const fs::path &path);
47 static bool isCompatible(std::istream &stream);
48
49
50 //
51 // Initializing
52 //
53
54 CRTFile(const fs::path &path) throws { init(path); }
55 CRTFile(const u8 *buf, isize len) throws { init(buf, len); }
56
57
58 //
59 // Methods from CoreObject
60 //
61
62 const char *objectName() const override { return "CRTFile"; }
63
64
65 //
66 // Methods from AnyFile
67 //
68
69 bool isCompatiblePath(const fs::path &path) override { return isCompatible(path); }
70 bool isCompatibleStream(std::istream &stream) override { return isCompatible(stream); }
71 FileType type() const override { return FILETYPE_CRT; }
72 PETName<16> getName() const override;
73 void finalizeRead() override;
74
75
76 //
77 // Analyzing the cartridge
78 //
79
80 // Returns the version number of the cartridge
81 u16 cartridgeVersion() const;
82
83 // Returns the size of the cartridge header
84 u32 headerSize() const;
85
86 // Returns the cartridge type (e.g., SimonsBasic, FinalIII)
87 CartridgeType cartridgeType() const;
88
89 // Returns a textual description for the cartridge type
90 string cartridgeTypeName() const { return cartridgeTypeName(cartridgeType()); }
91
92 // Checks whether the cartridge type is supported by the emulator, yet
93 bool isSupported() const;
94
95 // Returns the initial value of the Exrom line and the Game line
96 bool initialExromLine() const { return data[0x18] != 0; }
97 bool initialGameLine() const { return data[0x19] != 0; }
98
99
100 //
101 // Analyzing chip packages
102 //
103
104 // Returns how many chips are contained in this cartridge
105 isize chipCount() const;
106
107 // Returns where the data of a certain chip can be found
108 u8 *chipData(isize nr) const;
109
110 // Returns the size of the chip (8 KB or 16 KB)
111 u16 chipSize(isize nr) const;
112
113 // Returns the type of the chip (0 = ROM, 1 = RAM, 2 = Flash ROM)
114 u16 chipType(isize nr) const;
115
116 // Returns the bank number for this chip
117 u16 chipBank(isize nr) const;
118
119 // Returns the start of the chip rom in address space
120 u16 chipAddr(isize nr) const;
121
122
123 //
124 // Debugging and repairing
125 //
126
127 // Prints some information about this cartridge
128 void dump() const;
129
130 // Fixes known inconsistencies of common CRT files
131 void repair();
132};
133
134}
VirtualC64 project namespace.
Definition CmdQueue.cpp:16