From 6b898215a56732348e0b477c8505458da8bc83ca Mon Sep 17 00:00:00 2001 From: AJR Date: Mon, 23 Dec 2024 16:46:18 -0500 Subject: 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 --- src/lib/formats/fs_vtech.cpp | 22 ++++++++++++---------- src/lib/formats/fsmeta.cpp | 1 - src/lib/formats/fsmeta.h | 1 - 3 files changed, 12 insertions(+), 12 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 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 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 &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> 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 &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 &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); diff --git a/src/lib/formats/fsmeta.cpp b/src/lib/formats/fsmeta.cpp index f3e91e706a0..3c731f21939 100644 --- a/src/lib/formats/fsmeta.cpp +++ b/src/lib/formats/fsmeta.cpp @@ -14,7 +14,6 @@ namespace fs { const char *meta_data::entry_name(meta_name name) { switch(name) { - case meta_name::basic: return "basic"; case meta_name::creation_date: return "creation_date"; case meta_name::length: return "length"; case meta_name::loading_address: return "loading_address"; diff --git a/src/lib/formats/fsmeta.h b/src/lib/formats/fsmeta.h index 0f6baf20133..ff0b505ab8b 100644 --- a/src/lib/formats/fsmeta.h +++ b/src/lib/formats/fsmeta.h @@ -21,7 +21,6 @@ namespace fs { enum class meta_name { - basic, creation_date, length, loading_address, -- cgit v1.2.3