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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
|
// license:BSD-3-Clause
// copyright-holders:Olivier Galibert
// Creation of Apple ProDOS floppy images
#include "emu.h"
#include "fs_prodos.h"
#include "ap_dsk35.h"
const u8 fs_prodos::impl::boot[512] = {
0x01, 0x38, 0xb0, 0x03, 0x4c, 0x1c, 0x09, 0x78, 0x86, 0x43, 0xc9, 0x03, 0x08, 0x8a, 0x29, 0x70,
0x4a, 0x4a, 0x4a, 0x4a, 0x09, 0xc0, 0x85, 0x49, 0xa0, 0xff, 0x84, 0x48, 0x28, 0xc8, 0xb1, 0x48,
0xd0, 0x3a, 0xb0, 0x0e, 0xa9, 0x03, 0x8d, 0x00, 0x08, 0xe6, 0x3d, 0xa5, 0x49, 0x48, 0xa9, 0x5b,
0x48, 0x60, 0x85, 0x40, 0x85, 0x48, 0xa0, 0x5e, 0xb1, 0x48, 0x99, 0x94, 0x09, 0xc8, 0xc0, 0xeb,
0xd0, 0xf6, 0xa2, 0x06, 0xbc, 0x32, 0x09, 0xbd, 0x39, 0x09, 0x99, 0xf2, 0x09, 0xbd, 0x40, 0x09,
0x9d, 0x7f, 0x0a, 0xca, 0x10, 0xee, 0xa9, 0x09, 0x85, 0x49, 0xa9, 0x86, 0xa0, 0x00, 0xc9, 0xf9,
0xb0, 0x2f, 0x85, 0x48, 0x84, 0x60, 0x84, 0x4a, 0x84, 0x4c, 0x84, 0x4e, 0x84, 0x47, 0xc8, 0x84,
0x42, 0xc8, 0x84, 0x46, 0x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, 0x38, 0xc6, 0x52, 0xf0, 0xce, 0x18, 0x08, 0x88,
0xf0, 0xf5, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};
void fs_prodos::enumerate_f(floppy_enumerator &fe, uint32_t form_factor, const std::vector<uint32_t> &variants) const
{
if(has(form_factor, variants, floppy_image::FF_35, floppy_image::DSDD))
fe.add(this, FLOPPY_APPLE_GCR_FORMAT, 819200, "prodos_800k", "Apple ProDOS 800K");
if(has(form_factor, variants, floppy_image::FF_35, floppy_image::SSDD))
fe.add(this, FLOPPY_APPLE_GCR_FORMAT, 409600, "prodos_400k", "Apple ProDOS 400K");
}
std::unique_ptr<filesystem_t> fs_prodos::mount(fsblk_t &blockdev) const
{
return std::make_unique<impl>(blockdev);
}
bool fs_prodos::can_format() const
{
return true;
}
bool fs_prodos::can_read() const
{
return false;
}
bool fs_prodos::can_write() const
{
return false;
}
char fs_prodos::directory_separator() const
{
return '/';
}
std::vector<fs_meta_description> fs_prodos::volume_meta_description() const
{
std::vector<fs_meta_description> res;
res.emplace_back(fs_meta_description(fs_meta_name::name, fs_meta_type::string, "UNTITLED", false, [](const fs_meta &m) { std::string n = std::get<std::string>(m); return n.size() <= 15; }, "Volume name, up to 15 characters"));
return res;
}
std::vector<fs_meta_description> fs_prodos::file_meta_description() const
{
std::vector<fs_meta_description> res;
return res;
}
std::vector<fs_meta_description> fs_prodos::directory_meta_description() const
{
std::vector<fs_meta_description> res;
return res;
}
void fs_prodos::impl::format(const fs_meta_data &meta)
{
std::string volume_name = std::get<std::string>(meta.find(fs_meta_name::name)->second);
u32 blocks = m_blockdev.block_count();
m_blockdev.get(0).copy(0x000, boot, 0x200); // Standard ProDOS boot sector as written by a 2gs
m_blockdev.get(1).fill(0x00); // No SOS boot sector
auto kblk1 = m_blockdev.get(2); // key block first block
auto kblk2 = m_blockdev.get(3); // key block second block
auto kblk3 = m_blockdev.get(4); // key block third block
auto kblk4 = m_blockdev.get(5); // key block fourth block
kblk1.w16l(0x00, 0x0000); // Backwards key block pointer (null)
kblk1.w16l(0x02, 0x0003); // Forwards key block pointer
kblk1.w8 (0x04, 0xf0 | volume_name.size()); // Block type (f, key block) and name size
kblk1.wstr(0x05, volume_name); // Volume name, up to 15 characters
kblk1.w32b(0x16, 0x642a250d); // ??? date & time
kblk1.w16b(0x1a, 0x80ff); // ???
kblk1.w32b(0x1c, 0x642a250d); // Creation date & time
kblk1.w8 (0x20, 0x05); // ProDOS version (2gs)
kblk1.w8 (0x21, 0x00); // ProDOS minimum version
kblk1.w8 (0x22, 0xc3); // Allowed access (destroy, rename, !backup, 3x0, write read)
kblk1.w8 (0x23, 0x27); // Directory entry length (fixed)
kblk1.w8 (0x24, 0x0d); // Entries per block (fixed)
kblk1.w16l(0x25, 0x0000); // Number of file entries in the directory
kblk1.w16l(0x27, 0x0006); // Bitmap block pointer
kblk1.w16l(0x29, blocks); // Number of blocks
kblk2.w16l(0x00, 0x0002); // Backwards block pointer of the second volume block
kblk2.w16l(0x02, 0x0004); // Forwards block pointer of the second volume block
kblk3.w16l(0x00, 0x0003); // Backwards block pointer of the third volume block
kblk3.w16l(0x02, 0x0005); // Forwards block pointer of the third volume block
kblk4.w16l(0x00, 0x0004); // Backwards block pointer of the fourth volume block
kblk4.w16l(0x02, 0x0000); // Forwards block pointer of the fourth volume block (null)
auto fmap = m_blockdev.get(6);
u8 *fdata = fmap.data();
// Mark blocks 7 to max as free
for(u32 i = 7; i != blocks; i++)
fdata[i >> 3] |= 0x80 >> (i & 7);
}
const filesystem_manager_type FS_PRODOS = &filesystem_manager_creator<fs_prodos>;;
|