summaryrefslogtreecommitdiffstatshomepage
path: root/src/lib/formats/fs_vtech.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/formats/fs_vtech.cpp')
-rw-r--r--src/lib/formats/fs_vtech.cpp34
1 files changed, 18 insertions, 16 deletions
diff --git a/src/lib/formats/fs_vtech.cpp b/src/lib/formats/fs_vtech.cpp
index 27e7f93a056..6b414518437 100644
--- a/src/lib/formats/fs_vtech.cpp
+++ b/src/lib/formats/fs_vtech.cpp
@@ -19,7 +19,7 @@ namespace fs { const vtech_image VTECH; }
// Filesystem has no subdirectories.
//
// Track 0 sectors 0-14 have the file names. 16 bytes/entry
-// offset 0 : File type 'T' (basic) or 'B' (binary)
+// offset 0 : File type 'T' (basic), 'B' (binary), or some other letter (application-specific)
// offset 1 : 0x3a
// offset 2-9: File name
// offset a : Track number of first file sector
@@ -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,9 +145,9 @@ 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));
+ res.set(meta_name::length, (get_u16le(entry + 0xe) - get_u16le(entry + 0xc)) & 0xffff);
return res;
}
@@ -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,13 +274,13 @@ 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);
bdir.w8 (off+0xb, 0x00);
bdir.w16l(off+0xc, meta.get_number(meta_name::loading_address, 0x7ae9));
- bdir.w16l(off+0xe, bdir.r16l(off+0xc) - 1); // Size 0 initially
+ bdir.w16l(off+0xe, bdir.r16l(off+0xc)); // Size 0 initially
return ERR_OK;
}
}
@@ -301,7 +303,7 @@ std::pair<err_t, std::vector<u8>> vtech_impl::file_read(const std::vector<std::s
u8 track = entry[0xa];
u8 sector = entry[0xb];
- int len = ((get_u16le(entry + 0xe) - get_u16le(entry + 0xc)) & 0xffff) + 1;
+ int len = (get_u16le(entry + 0xe) - get_u16le(entry + 0xc)) & 0xffff;
data.resize(len, 0);
int pos = 0;
@@ -331,7 +333,7 @@ err_t vtech_impl::file_write(const std::vector<std::string> &path, const std::ve
u8 *entry = bdir.data() + off;
- u32 cur_len = ((get_u16le(entry + 0xe) - get_u16le(entry + 0xc) + 1) & 0xffff);
+ u32 cur_len = (get_u16le(entry + 0xe) - get_u16le(entry + 0xc)) & 0xffff;
u32 new_len = data.size();
if(new_len > 65535)
new_len = 65535;
@@ -370,7 +372,7 @@ err_t vtech_impl::file_write(const std::vector<std::string> &path, const std::ve
dblk.w16l(126, 0);
}
- u16 end_address = (get_u16le(entry + 0xc) + data.size() - 1) & 0xffff;
+ u16 end_address = (get_u16le(entry + 0xc) + data.size()) & 0xffff;
put_u16le(entry + 0xe, end_address);
if(need_ns) {
entry[0xa] = blocks[0].first;