VirtualC64 v5.0 beta
Commodore 64 Emulator
Loading...
Searching...
No Matches
FlashRom.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 "SubComponent.h"
16#include "CartridgeTypes.h"
17
18namespace vc64 {
19
20/* This class implements a Flash Rom module of type Am29F040B. Flash Roms
21 * of this type are used, e.g., by the EasyFlash cartridge. The implementation
22 * is based on the following ressources:
23 *
24 * 29F040.pdf : Data sheet published by AMD
25 * flash040core.c : Part of the VICE emulator
26 */
27class FlashRom final : public SubComponent {
28
29 Descriptions descriptions = {{
30
31 .name = "FlashRom",
32 .description = "Flash ROM"
33 }};
34
35 // Number of sectors in this Flash Rom
36 static const isize numSectors = 8;
37
38 // Size of a single sector in bytes (64 KB)
39 static const isize sectorSize = 0x10000;
40
41 // Total size of the Flash Rom in bytes (512 KB)
42 static const isize romSize = 0x80000;
43
44 // Current Flash Rom state
45 FlashState state;
46
47 // State taken after an operations has been completed
48 FlashState baseState;
49
50 // Flash Rom data
51 u8 *rom = nullptr;
52
53
54 //
55 // Class methods
56 //
57
58public:
59
60 // Checks whether the provided number is a valid bank number
61 static bool isBankNumber(isize bank) { return bank < 64; }
62
63 // Converts a Flash Rom state to a string
64 static const char *getStateAsString(FlashState state);
65
66
67 //
68 // Methods
69 //
70
71public:
72
73 FlashRom(C64 &ref);
74 ~FlashRom();
75
76 FlashRom& operator= (const FlashRom& other) {
77
78 CLONE(state)
79 CLONE(baseState)
80
81 return *this;
82 }
83
84
85 //
86 // Methods from Serializable
87 //
88
89public:
90
91 template <class T>
92 void serialize(T& worker)
93 {
94 if (isResetter(worker)) return;
95
96 worker
97
98 << state
99 << baseState;
100 }
101
102 void operator << (SerResetter &worker) override { serialize(worker); }
103 void operator << (SerChecker &worker) override { serialize(worker); }
104 void operator << (SerCounter &worker) override;
105 void operator << (SerReader &worker) override;
106 void operator << (SerWriter &worker) override;
107
108
109 //
110 // Methods from CoreComponent
111 //
112
113public:
114
115 const Descriptions &getDescriptions() const override { return descriptions; }
116
117private:
118
119 void _dump(Category category, std::ostream& os) const override;
120 void _reset(bool hard) override;
121
122
123 //
124 // Loading banks
125 //
126
127public:
128
129 /* Loads an 8 KB chunk of Rom data from a buffer. This method is used when
130 * loading the contents from a CRT file.
131 */
132 void loadBank(isize bank, u8 *data);
133
134
135 //
136 // Accessing memory
137 //
138
139public:
140
141 u8 peek(u32 addr);
142 u8 peek(isize bank, u16 addr);
143
144 u8 spypeek(u32 addr) const;
145 u8 spypeek(isize bank, u16 addr) const;
146
147 void poke(u32 addr, u8 value);
148 void poke(isize bank, u16 addr, u8 value);
149
150
151 //
152 // Performing flash operations
153 //
154
155 // Checks if addr serves as the first command address
156 bool firstCommandAddr(u32 addr) { return (addr & 0x7FF) == 0x555; }
157
158 // Checks if addr serves as the second command address
159 bool secondCommandAddr(u32 addr) { return (addr & 0x7FF) == 0x2AA; }
160
161 // Performs a "Byte Program" operation
162 bool doByteProgram(u32 addr, u8 value);
163 bool doByteProgram(isize bank, u16 addr, u8 value);
164
165 // Performs a "Sector Erase" operation
166 void doSectorErase(u32 addr);
167 void doSectorErase(isize bank, u16 addr);
168
169 // Performs a "Chip Erase" operation
170 void doChipErase();
171};
172
173}
VirtualC64 project namespace.
Definition CmdQueue.cpp:16