summaryrefslogtreecommitdiffstatshomepage
path: root/src/lib/formats/fs_vtech.cpp
diff options
context:
space:
mode:
author AJR <ajrhacker@users.noreply.github.com>2023-09-17 11:33:25 -0400
committer AJR <ajrhacker@users.noreply.github.com>2023-09-17 11:33:25 -0400
commitf5066881db7a601ba7031fbc996ab404e05e5dd5 (patch)
tree6803289651ccbc928e0141cf5a9392809e4dd00f /src/lib/formats/fs_vtech.cpp
parent0af125686b70300486cb23c4d32c9c92ec369008 (diff)
fsmgr.h: Cleanup
- Use multibyte.h functions for packing and unpacking words - Remove a few aliases for cstdlib functions - Convert rstr and wstr functions to std::string_view
Diffstat (limited to 'src/lib/formats/fs_vtech.cpp')
-rw-r--r--src/lib/formats/fs_vtech.cpp37
1 files changed, 20 insertions, 17 deletions
diff --git a/src/lib/formats/fs_vtech.cpp b/src/lib/formats/fs_vtech.cpp
index e4253638061..970d5fb6556 100644
--- a/src/lib/formats/fs_vtech.cpp
+++ b/src/lib/formats/fs_vtech.cpp
@@ -6,6 +6,9 @@
#include "fs_vtech.h"
#include "vt_dsk.h"
+#include "corestr.h"
+#include "multibyte.h"
+
#include <stdexcept>
using namespace fs;
@@ -52,7 +55,7 @@ public:
private:
meta_data file_metadata(const u8 *entry);
- std::tuple<fsblk_t::block_t, u32> file_find(std::string name);
+ std::tuple<fsblk_t::block_t, u32> file_find(std::string_view name);
std::vector<std::pair<u8, u8>> allocate_blocks(u32 count);
void free_blocks(const std::vector<std::pair<u8, u8>> &blocks);
u32 free_block_count();
@@ -139,15 +142,15 @@ 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::name, strtrimrightspace(rstr(entry+2, 8)));
res.set(meta_name::basic, entry[0] == 'T');
- res.set(meta_name::loading_address, r16l(entry + 0xc));
- res.set(meta_name::length, ((r16l(entry + 0xe) - r16l(entry + 0xc) + 1) & 0xffff));
+ 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));
return res;
}
-std::tuple<fsblk_t::block_t, u32> vtech_impl::file_find(std::string name)
+std::tuple<fsblk_t::block_t, u32> vtech_impl::file_find(std::string_view name)
{
for(int sect = 0; sect != 14; sect++) {
auto bdir = m_blockdev.get(sect);
@@ -158,7 +161,7 @@ std::tuple<fsblk_t::block_t, u32> vtech_impl::file_find(std::string name)
continue;
if(bdir.r8(off+1) != ':')
continue;
- if(trim_end_spaces(bdir.rstr(off+2, 8)) == name) {
+ if(strtrimrightspace(bdir.rstr(off+2, 8)) == name) {
return std::make_tuple(bdir, i);
}
}
@@ -189,7 +192,7 @@ err_t vtech_impl::metadata_change(const std::vector<std::string> &path, const me
u8 *entry = bdir.data() + off;
if(meta.has(meta_name::basic))
- w8 (entry+0x0, meta.get_flag(meta_name::basic) ? 'T' : 'B');
+ entry[0x0] = meta.get_flag(meta_name::basic) ? 'T' : 'B';
if(meta.has(meta_name::name)) {
std::string name = meta.get_string(meta_name::name);
name.resize(8, ' ');
@@ -197,9 +200,9 @@ err_t vtech_impl::metadata_change(const std::vector<std::string> &path, const me
}
if(meta.has(meta_name::loading_address)) {
u16 new_loading = meta.get_number(meta_name::loading_address);
- u16 new_end = r16l(entry + 0xe) - r16l(entry + 0xc) + new_loading;
- w16l(entry + 0xc, new_loading);
- w16l(entry + 0xe, new_end);
+ u16 new_end = get_u16le(entry + 0xe) - get_u16le(entry + 0xc) + new_loading;
+ put_u16le(entry + 0xc, new_loading);
+ put_u16le(entry + 0xe, new_end);
}
return ERR_OK;
@@ -298,7 +301,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 = ((r16l(entry + 0xe) - r16l(entry + 0xc)) & 0xffff) + 1;
+ int len = ((get_u16le(entry + 0xe) - get_u16le(entry + 0xc)) & 0xffff) + 1;
data.resize(len, 0);
int pos = 0;
@@ -328,7 +331,7 @@ err_t vtech_impl::file_write(const std::vector<std::string> &path, const std::ve
u8 *entry = bdir.data() + off;
- u32 cur_len = ((r16l(entry + 0xe) - r16l(entry + 0xc) + 1) & 0xffff);
+ u32 cur_len = ((get_u16le(entry + 0xe) - get_u16le(entry + 0xc) + 1) & 0xffff);
u32 new_len = data.size();
if(new_len > 65535)
new_len = 65535;
@@ -367,13 +370,13 @@ err_t vtech_impl::file_write(const std::vector<std::string> &path, const std::ve
dblk.w16l(126, 0);
}
- u16 end_address = (r16l(entry + 0xc) + data.size() - 1) & 0xffff;
- w16l(entry + 0xe, end_address);
+ u16 end_address = (get_u16le(entry + 0xc) + data.size() - 1) & 0xffff;
+ put_u16le(entry + 0xe, end_address);
if(need_ns) {
- w8(entry + 0xa, blocks[0].first);
- w8(entry + 0xb, blocks[0].second);
+ entry[0xa] = blocks[0].first;
+ entry[0xb] = blocks[0].second;
} else
- w16l(entry + 0xa, 0);
+ put_u16le(entry + 0xa, 0);
return ERR_OK;
}