summaryrefslogtreecommitdiffstatshomepage
path: root/src/lib/formats/fs_vtech.cpp
diff options
context:
space:
mode:
author AJR <ariedlmayer@gmail.com>2024-12-23 16:46:18 -0500
committer AJR <ariedlmayer@gmail.com>2024-12-23 16:46:18 -0500
commit6b898215a56732348e0b477c8505458da8bc83ca (patch)
tree980553195b4a1c801a9ea483222c665c8932ce66 /src/lib/formats/fs_vtech.cpp
parent6e711389acddf3a7d22c7ccb1a925f0965f174b8 (diff)
formats/fs_vtech.cpp: Fixes and improvements
- Fix incorrect directory sector offset value for file read/write operations - Allow file types other than T and B
Diffstat (limited to 'src/lib/formats/fs_vtech.cpp')
-rw-r--r--src/lib/formats/fs_vtech.cpp22
1 files changed, 12 insertions, 10 deletions
diff --git a/src/lib/formats/fs_vtech.cpp b/src/lib/formats/fs_vtech.cpp
index 27e7f93a056..03ceffbab5b 100644
--- a/src/lib/formats/fs_vtech.cpp
+++ b/src/lib/formats/fs_vtech.cpp
@@ -114,7 +114,9 @@ std::vector<meta_description> vtech_image::file_meta_description() const
res.emplace_back(meta_description(meta_name::name, "", false, [](const meta_value &m) { return m.as_string().size() <= 8; }, "File name, 8 chars"));
res.emplace_back(meta_description(meta_name::loading_address, 0x7ae9, false, [](const meta_value &m) { return m.as_number() < 0x10000; }, "Loading address of the file"));
res.emplace_back(meta_description(meta_name::length, 0, true, nullptr, "Size of the file in bytes"));
- res.emplace_back(meta_description(meta_name::basic, true, true, nullptr, "Basic file"));
+ res.emplace_back(meta_description(meta_name::file_type, "T", true,
+ [](const meta_value &m) { return m.as_string().size() == 1 && m.as_string()[0] >= 'A' && m.as_string()[0] <= 'Z'; },
+ "File type (e.g. T = text, B = binary)"));
return res;
}
@@ -143,7 +145,7 @@ meta_data vtech_impl::file_metadata(const u8 *entry)
meta_data res;
res.set(meta_name::name, trim_end_spaces(rstr(entry+2, 8)));
- res.set(meta_name::basic, entry[0] == 'T');
+ res.set(meta_name::file_type, std::string{ char(entry[0]) });
res.set(meta_name::loading_address, get_u16le(entry + 0xc));
res.set(meta_name::length, ((get_u16le(entry + 0xe) - get_u16le(entry + 0xc) + 1) & 0xffff));
@@ -157,12 +159,12 @@ std::tuple<fsblk_t::block_t, u32> vtech_impl::file_find(std::string_view name)
for(u32 i = 0; i != 8; i ++) {
u32 off = i*16;
u8 type = bdir.r8(off);
- if(type != 'T' && type != 'B')
+ if(type < 'A' || type > 'Z')
continue;
if(bdir.r8(off+1) != ':')
continue;
if(trim_end_spaces(bdir.rstr(off+2, 8)) == name) {
- return std::make_tuple(bdir, i);
+ return std::make_tuple(bdir, off);
}
}
}
@@ -187,12 +189,12 @@ err_t vtech_impl::metadata_change(const std::vector<std::string> &path, const me
return ERR_NOT_FOUND;
auto [bdir, off] = file_find(path[0]);
- if(!off)
+ if(off == 0xffffffff)
return ERR_NOT_FOUND;
u8 *entry = bdir.data() + off;
- if(meta.has(meta_name::basic))
- entry[0x0] = meta.get_flag(meta_name::basic) ? 'T' : 'B';
+ if(meta.has(meta_name::file_type))
+ entry[0x0] = meta.get_string(meta_name::file_type)[0];
if(meta.has(meta_name::name)) {
std::string name = meta.get_string(meta_name::name);
name.resize(8, ' ');
@@ -224,7 +226,7 @@ std::pair<err_t, std::vector<dir_entry>> vtech_impl::directory_contents(const st
for(u32 i = 0; i != 8; i ++) {
u32 off = i*16;
u8 type = bdir.r8(off);
- if(type != 'T' && type != 'B')
+ if(type < 'A' || type > 'Z')
continue;
if(bdir.r8(off+1) != ':')
continue;
@@ -241,7 +243,7 @@ err_t vtech_impl::rename(const std::vector<std::string> &opath, const std::vecto
return ERR_NOT_FOUND;
auto [bdir, off] = file_find(opath[0]);
- if(!off)
+ if(off == 0xffffffff)
return ERR_NOT_FOUND;
std::string name = npath[0];
@@ -272,7 +274,7 @@ err_t vtech_impl::file_create(const std::vector<std::string> &path, const meta_d
std::string fname = meta.get_string(meta_name::name, "");
fname.resize(8, ' ');
- bdir.w8 (off+0x0, meta.get_flag(meta_name::basic, true) ? 'T' : 'B');
+ bdir.w8 (off+0x0, meta.get_string(meta_name::file_type, "T")[0]);
bdir.w8 (off+0x1, ':');
bdir.wstr(off+0x2, fname);
bdir.w8 (off+0xa, 0x00);