mirror of
https://github.com/holub/mame
synced 2025-04-23 00:39:36 +03:00
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
This commit is contained in:
parent
0af125686b
commit
f5066881db
@ -15,6 +15,8 @@
|
||||
|
||||
#include "fs_coco_os9.h"
|
||||
#include "coco_rawdsk.h"
|
||||
|
||||
#include "multibyte.h"
|
||||
#include "strformat.h"
|
||||
|
||||
|
||||
@ -115,7 +117,6 @@ public:
|
||||
|
||||
static std::string pick_os9_string(std::string_view raw_string);
|
||||
static std::string to_os9_string(std::string_view s, size_t length);
|
||||
static u32 pick_integer_be(const u8 *data, int length);
|
||||
static util::arbitrary_datetime from_os9_date(u32 os9_date, u16 os9_time = 0);
|
||||
static std::tuple<u32, u16> to_os9_date(const util::arbitrary_datetime &datetime);
|
||||
static bool is_ignored_filename(std::string_view name);
|
||||
@ -522,7 +523,7 @@ void coco_os9_impl::iterate_directory_entries(const file_header &header, const s
|
||||
continue;
|
||||
|
||||
// set up the child header
|
||||
u32 lsn = pick_integer_be(&directory_data[i * 32] + 29, 3);
|
||||
u32 lsn = get_u24be(&directory_data[i * 32] + 29);
|
||||
|
||||
// invoke the callback
|
||||
done = callback(std::move(filename), lsn);
|
||||
@ -598,19 +599,6 @@ std::string coco_os9_impl::to_os9_string(std::string_view s, size_t length)
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------
|
||||
// pick_integer_be
|
||||
//-------------------------------------------------
|
||||
|
||||
u32 coco_os9_impl::pick_integer_be(const u8 *data, int length)
|
||||
{
|
||||
u32 result = 0;
|
||||
for (int i = 0; i < length; i++)
|
||||
result |= u32(data[length - i - 1]) << i * 8;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------
|
||||
// from_os9_date
|
||||
//-------------------------------------------------
|
||||
|
@ -6,6 +6,8 @@
|
||||
#include "fs_oric_jasmin.h"
|
||||
#include "oric_dsk.h"
|
||||
|
||||
#include "multibyte.h"
|
||||
|
||||
#include <stdexcept>
|
||||
|
||||
using namespace fs;
|
||||
@ -291,8 +293,8 @@ std::string oric_jasmin_impl::file_name_read(const u8 *p)
|
||||
|
||||
bool oric_jasmin_impl::file_is_system(const u8 *entry)
|
||||
{
|
||||
u16 ref = r16b(entry);
|
||||
return ref == 0 && r32b(entry+0xb) == 0x2e535953;
|
||||
u16 ref = get_u16be(entry);
|
||||
return ref == 0 && get_u32be(entry+0xb) == 0x2e535953;
|
||||
}
|
||||
|
||||
|
||||
@ -303,14 +305,14 @@ meta_data oric_jasmin_impl::file_metadata(const u8 *entry)
|
||||
res.set(meta_name::name, file_name_read(entry + 3));
|
||||
res.set(meta_name::locked, entry[2] == 'L');
|
||||
res.set(meta_name::sequential, entry[0xf] == 'S');
|
||||
res.set(meta_name::size_in_blocks, r16l(entry + 0x10));
|
||||
res.set(meta_name::size_in_blocks, get_u16le(entry + 0x10));
|
||||
|
||||
bool sys = file_is_system(entry);
|
||||
if(sys)
|
||||
res.set(meta_name::length, 0x3e00);
|
||||
|
||||
else {
|
||||
u16 ref = r16b(entry);
|
||||
u16 ref = get_u16be(entry);
|
||||
auto dblk = m_blockdev.get(cs_to_block(ref));
|
||||
res.set(meta_name::loading_address, dblk.r16l(2));
|
||||
res.set(meta_name::length, dblk.r16l(4));
|
||||
@ -365,13 +367,13 @@ err_t oric_jasmin_impl::metadata_change(const std::vector<std::string> &path, co
|
||||
|
||||
u8 *entry = bdir.data() + off;
|
||||
if(meta.has(meta_name::locked))
|
||||
w8 (entry+0x02, meta.get_flag(meta_name::locked) ? 'L' : 'U');
|
||||
entry[0x02] = meta.get_flag(meta_name::locked) ? 'L' : 'U';
|
||||
if(meta.has(meta_name::name))
|
||||
wstr(entry+0x03, file_name_prepare(meta.get_string(meta_name::name)));
|
||||
if(meta.has(meta_name::sequential))
|
||||
w8 (entry+0x0f, meta.get_flag(meta_name::sequential) ? 'D' : 'S');
|
||||
entry[0x0f] = meta.get_flag(meta_name::sequential) ? 'D' : 'S';
|
||||
if(!sys && meta.has(meta_name::loading_address))
|
||||
m_blockdev.get(cs_to_block(r16b(entry))).w16l(2, meta.get_number(meta_name::loading_address));
|
||||
m_blockdev.get(cs_to_block(get_u16be(entry))).w16l(2, meta.get_number(meta_name::loading_address));
|
||||
|
||||
return ERR_OK;
|
||||
}
|
||||
@ -500,7 +502,7 @@ std::pair<err_t, std::vector<u8>> oric_jasmin_impl::file_read(const std::vector<
|
||||
|
||||
} else {
|
||||
const u8 *entry = bdir.rodata() + off;
|
||||
u16 ref = r16b(entry);
|
||||
u16 ref = get_u16be(entry);
|
||||
auto iblk = m_blockdev.get(cs_to_block(ref));
|
||||
u32 length = iblk.r16l(4);
|
||||
while(ref_valid(ref)) {
|
||||
@ -545,7 +547,7 @@ err_t oric_jasmin_impl::file_write(const std::vector<std::string> &path, const s
|
||||
|
||||
} else {
|
||||
u8 *entry = bdir.data() + off;
|
||||
u32 cur_ns = r16l(entry + 0x10);
|
||||
u32 cur_ns = get_u16le(entry + 0x10);
|
||||
// Data sectors first
|
||||
u32 need_ns = (data.size() + 255) / 256;
|
||||
if(need_ns == 0)
|
||||
@ -559,7 +561,7 @@ err_t oric_jasmin_impl::file_write(const std::vector<std::string> &path, const s
|
||||
|
||||
u16 load_address = 0;
|
||||
std::vector<u16> tofree;
|
||||
u16 iref = r16b(entry);
|
||||
u16 iref = get_u16be(entry);
|
||||
for(u32 i=0; i < cur_ns; i += 125+1) {
|
||||
auto iblk = m_blockdev.get(cs_to_block(iref));
|
||||
if(!i)
|
||||
@ -597,8 +599,8 @@ err_t oric_jasmin_impl::file_write(const std::vector<std::string> &path, const s
|
||||
}
|
||||
}
|
||||
}
|
||||
w16l(entry + 0x10, need_ns);
|
||||
w16b(entry + 0x00, blocks[0]);
|
||||
put_u16le(entry + 0x10, need_ns);
|
||||
put_u16be(entry + 0x00, blocks[0]);
|
||||
}
|
||||
return ERR_OK;
|
||||
}
|
||||
|
@ -6,6 +6,7 @@
|
||||
#include "fs_prodos.h"
|
||||
#include "ap_dsk35.h"
|
||||
|
||||
#include "multibyte.h"
|
||||
#include "strformat.h"
|
||||
|
||||
#include <stdexcept>
|
||||
@ -359,21 +360,21 @@ std::pair<err_t, meta_data> prodos_impl::metadata(const std::vector<std::string>
|
||||
|
||||
meta_data res;
|
||||
if(dir) {
|
||||
u8 type = r8(entry);
|
||||
std::string name = rstr(entry+1, type & 0xf);
|
||||
u8 type = entry[0];
|
||||
std::string_view name = rstr(entry+1, type & 0xf);
|
||||
res.set(meta_name::name, name);
|
||||
} else {
|
||||
u8 type = r8(entry);
|
||||
std::string name = rstr(entry+1, type & 0xf);
|
||||
u8 type = entry[0];
|
||||
std::string_view name = rstr(entry+1, type & 0xf);
|
||||
type >>= 4;
|
||||
res.set(meta_name::name, name);
|
||||
if(type == 5) {
|
||||
auto rootblk = m_blockdev.get(r16l(entry+0x11));
|
||||
auto rootblk = m_blockdev.get(get_u16le(entry+0x11));
|
||||
res.set(meta_name::length, rootblk.r24l(0x005));
|
||||
res.set(meta_name::rsrc_length, rootblk.r24l(0x105));
|
||||
|
||||
} else if(type >= 1 && type <= 3)
|
||||
res.set(meta_name::length, r24l(entry + 0x15));
|
||||
res.set(meta_name::length, get_u24le(entry + 0x15));
|
||||
|
||||
else
|
||||
return std::make_pair(ERR_UNSUPPORTED, meta_data());
|
||||
@ -440,13 +441,13 @@ std::pair<err_t, std::vector<u8>> prodos_impl::file_read(const std::vector<std::
|
||||
return std::make_pair(ERR_NOT_FOUND, std::vector<u8>());
|
||||
|
||||
const u8 *entry = blk.rodata() + off;
|
||||
u8 type = r8(entry) >> 4;
|
||||
u8 type = entry[0] >> 4;
|
||||
|
||||
if(type >= 1 && type <= 3)
|
||||
return any_read(type, r16l(entry+0x11), r24l(entry + 0x15));
|
||||
return any_read(type, get_u16le(entry+0x11), get_u24le(entry + 0x15));
|
||||
|
||||
else if(type == 5) {
|
||||
auto kblk = m_blockdev.get(r16l(entry+0x11));
|
||||
auto kblk = m_blockdev.get(get_u16le(entry+0x11));
|
||||
return any_read(kblk.r8(0x000), kblk.r16l(0x001), kblk.r24l(0x005));
|
||||
|
||||
} else
|
||||
@ -460,10 +461,10 @@ std::pair<err_t, std::vector<u8>> prodos_impl::file_rsrc_read(const std::vector<
|
||||
return std::make_pair(ERR_NOT_FOUND, std::vector<u8>());
|
||||
|
||||
const u8 *entry = blk.rodata() + off;
|
||||
u8 type = r8(entry) >> 4;
|
||||
u8 type = entry[0] >> 4;
|
||||
|
||||
if(type == 5) {
|
||||
auto kblk = m_blockdev.get(r16l(entry+0x11));
|
||||
auto kblk = m_blockdev.get(get_u16le(entry+0x11));
|
||||
return any_read(kblk.r8(0x100), kblk.r16l(0x101), kblk.r24l(0x105));
|
||||
|
||||
} else
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -7,6 +7,7 @@
|
||||
|
||||
#include "fsmgr.h"
|
||||
|
||||
#include "multibyte.h"
|
||||
#include "strformat.h"
|
||||
|
||||
#include <stdexcept>
|
||||
@ -124,238 +125,110 @@ const u8 *fsblk_t::iblock_t::rooffset(const char *function, u32 off, u32 size)
|
||||
|
||||
void fsblk_t::block_t::copy(u32 offset, const u8 *src, u32 size)
|
||||
{
|
||||
u8 *blk = m_object->offset("copy", offset, size);
|
||||
memcpy(blk, src, size);
|
||||
memcpy(m_object->offset("copy", offset, size), src, size);
|
||||
}
|
||||
|
||||
void fsblk_t::block_t::fill(u32 offset, u8 data, u32 size)
|
||||
{
|
||||
u8 *blk = m_object->offset("fill", offset, size);
|
||||
memset(blk, data, size);
|
||||
memset(m_object->offset("fill", offset, size), data, size);
|
||||
}
|
||||
|
||||
void fsblk_t::block_t::fill(u8 data)
|
||||
{
|
||||
u8 *blk = m_object->data();
|
||||
memset(blk, data, m_object->size());
|
||||
memset(m_object->data(), data, m_object->size());
|
||||
}
|
||||
|
||||
void fsblk_t::block_t::wstr(u32 offset, const std::string &str)
|
||||
void fsblk_t::block_t::wstr(u32 offset, std::string_view str)
|
||||
{
|
||||
u8 *blk = m_object->offset("wstr", offset, str.size());
|
||||
memcpy(blk, str.data(), str.size());
|
||||
memcpy(m_object->offset("wstr", offset, str.size()), str.data(), str.size());
|
||||
}
|
||||
|
||||
void fsblk_t::block_t::w8(u32 offset, u8 data)
|
||||
{
|
||||
u8 *blk = m_object->offset("w8", offset, 1);
|
||||
blk[0] = data;
|
||||
m_object->offset("w8", offset, 1)[0] = data;
|
||||
}
|
||||
|
||||
void fsblk_t::block_t::w16b(u32 offset, u16 data)
|
||||
{
|
||||
u8 *blk = m_object->offset("w16b", offset, 2);
|
||||
blk[0] = data >> 8;
|
||||
blk[1] = data;
|
||||
put_u16be(m_object->offset("w16b", offset, 2), data);
|
||||
}
|
||||
|
||||
void fsblk_t::block_t::w24b(u32 offset, u32 data)
|
||||
{
|
||||
u8 *blk = m_object->offset("w24b", offset, 3);
|
||||
blk[0] = data >> 16;
|
||||
blk[1] = data >> 8;
|
||||
blk[2] = data;
|
||||
put_u24be(m_object->offset("w24b", offset, 3), data);
|
||||
}
|
||||
|
||||
void fsblk_t::block_t::w32b(u32 offset, u32 data)
|
||||
{
|
||||
u8 *blk = m_object->offset("w32b", offset, 4);
|
||||
blk[0] = data >> 24;
|
||||
blk[1] = data >> 16;
|
||||
blk[2] = data >> 8;
|
||||
blk[3] = data;
|
||||
put_u32be(m_object->offset("w32b", offset, 4), data);
|
||||
}
|
||||
|
||||
void fsblk_t::block_t::w16l(u32 offset, u16 data)
|
||||
{
|
||||
u8 *blk = m_object->offset("w16l", offset, 2);
|
||||
blk[0] = data;
|
||||
blk[1] = data >> 8;
|
||||
put_u16le(m_object->offset("w16l", offset, 2), data);
|
||||
}
|
||||
|
||||
void fsblk_t::block_t::w24l(u32 offset, u32 data)
|
||||
{
|
||||
u8 *blk = m_object->offset("w24l", offset, 3);
|
||||
blk[0] = data;
|
||||
blk[1] = data >> 8;
|
||||
blk[2] = data >> 16;
|
||||
put_u24le(m_object->offset("w24l", offset, 3), data);
|
||||
}
|
||||
|
||||
void fsblk_t::block_t::w32l(u32 offset, u32 data)
|
||||
{
|
||||
u8 *blk = m_object->offset("w32l", offset, 4);
|
||||
blk[0] = data;
|
||||
blk[1] = data >> 8;
|
||||
blk[2] = data >> 16;
|
||||
blk[3] = data >> 24;
|
||||
put_u32le(m_object->offset("w32l", offset, 4), data);
|
||||
}
|
||||
|
||||
std::string fsblk_t::block_t::rstr(u32 offset, u32 size) const
|
||||
std::string_view fsblk_t::block_t::rstr(u32 offset, u32 size) const
|
||||
{
|
||||
const u8 *d = m_object->rooffset("rstr", offset, size);
|
||||
return std::string(d, d + size);
|
||||
return std::string_view(reinterpret_cast<const char *>(d), size);
|
||||
}
|
||||
|
||||
u8 fsblk_t::block_t::r8(u32 offset) const
|
||||
{
|
||||
const u8 *blk = m_object->offset("r8", offset, 1);
|
||||
return blk[0];
|
||||
return m_object->offset("r8", offset, 1)[0];
|
||||
}
|
||||
|
||||
u16 fsblk_t::block_t::r16b(u32 offset) const
|
||||
{
|
||||
const u8 *blk = m_object->offset("r16b", offset, 2);
|
||||
return (blk[0] << 8) | blk[1];
|
||||
return get_u16be(m_object->offset("r16b", offset, 2));
|
||||
}
|
||||
|
||||
u32 fsblk_t::block_t::r24b(u32 offset) const
|
||||
{
|
||||
const u8 *blk = m_object->offset("r24b", offset, 3);
|
||||
return (blk[0] << 16) | (blk[1] << 8) | blk[2];
|
||||
return get_u24be(m_object->offset("r24b", offset, 3));
|
||||
}
|
||||
|
||||
u32 fsblk_t::block_t::r32b(u32 offset) const
|
||||
{
|
||||
const u8 *blk = m_object->offset("r32b", offset, 4);
|
||||
return (blk[0] << 24) | (blk[1] << 16) | (blk[2] << 8) | blk[3];
|
||||
return get_u32be(m_object->offset("r32b", offset, 4));
|
||||
}
|
||||
|
||||
u16 fsblk_t::block_t::r16l(u32 offset) const
|
||||
{
|
||||
const u8 *blk = m_object->offset("r16l", offset, 2);
|
||||
return blk[0] | (blk[1] << 8);
|
||||
return get_u16le(m_object->offset("r16l", offset, 2));
|
||||
}
|
||||
|
||||
u32 fsblk_t::block_t::r24l(u32 offset) const
|
||||
{
|
||||
const u8 *blk = m_object->offset("r24l", offset, 3);
|
||||
return blk[0] | (blk[1] << 8) | (blk[2] << 16);
|
||||
return get_u24le(m_object->offset("r24l", offset, 3));
|
||||
}
|
||||
|
||||
u32 fsblk_t::block_t::r32l(u32 offset) const
|
||||
{
|
||||
const u8 *blk = m_object->offset("r32l", offset, 4);
|
||||
return blk[0] | (blk[1] << 8) | (blk[2] << 16) | (blk[3] << 24);
|
||||
return get_u32le(m_object->offset("r32l", offset, 4));
|
||||
}
|
||||
|
||||
|
||||
|
||||
void filesystem_t::copy(u8 *p, const u8 *src, u32 size)
|
||||
{
|
||||
memcpy(p, src, size);
|
||||
}
|
||||
|
||||
void filesystem_t::fill(u8 *p, u8 data, u32 size)
|
||||
{
|
||||
memset(p, data, size);
|
||||
}
|
||||
|
||||
void filesystem_t::wstr(u8 *p, const std::string &str)
|
||||
void filesystem_t::wstr(u8 *p, std::string_view str)
|
||||
{
|
||||
memcpy(p, str.data(), str.size());
|
||||
}
|
||||
|
||||
void filesystem_t::w8(u8 *p, u8 data)
|
||||
std::string_view filesystem_t::rstr(const u8 *p, u32 size)
|
||||
{
|
||||
p[0] = data;
|
||||
}
|
||||
|
||||
void filesystem_t::w16b(u8 *p, u16 data)
|
||||
{
|
||||
p[0] = data >> 8;
|
||||
p[1] = data;
|
||||
}
|
||||
|
||||
void filesystem_t::w24b(u8 *p, u32 data)
|
||||
{
|
||||
p[0] = data >> 16;
|
||||
p[1] = data >> 8;
|
||||
p[2] = data;
|
||||
}
|
||||
|
||||
void filesystem_t::w32b(u8 *p, u32 data)
|
||||
{
|
||||
p[0] = data >> 24;
|
||||
p[1] = data >> 16;
|
||||
p[2] = data >> 8;
|
||||
p[3] = data;
|
||||
}
|
||||
|
||||
void filesystem_t::w16l(u8 *p, u16 data)
|
||||
{
|
||||
p[0] = data;
|
||||
p[1] = data >> 8;
|
||||
}
|
||||
|
||||
void filesystem_t::w24l(u8 *p, u32 data)
|
||||
{
|
||||
p[0] = data;
|
||||
p[1] = data >> 8;
|
||||
p[2] = data >> 16;
|
||||
}
|
||||
|
||||
void filesystem_t::w32l(u8 *p, u32 data)
|
||||
{
|
||||
p[0] = data;
|
||||
p[1] = data >> 8;
|
||||
p[2] = data >> 16;
|
||||
p[3] = data >> 24;
|
||||
}
|
||||
|
||||
std::string filesystem_t::rstr(const u8 *p, u32 size)
|
||||
{
|
||||
return std::string(p, p + size);
|
||||
}
|
||||
|
||||
u8 filesystem_t::r8(const u8 *p)
|
||||
{
|
||||
return p[0];
|
||||
}
|
||||
|
||||
u16 filesystem_t::r16b(const u8 *p)
|
||||
{
|
||||
return (p[0] << 8) | p[1];
|
||||
}
|
||||
|
||||
u32 filesystem_t::r24b(const u8 *p)
|
||||
{
|
||||
return (p[0] << 16) | (p[1] << 8) | p[2];
|
||||
}
|
||||
|
||||
u32 filesystem_t::r32b(const u8 *p)
|
||||
{
|
||||
return (p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3];
|
||||
}
|
||||
|
||||
u16 filesystem_t::r16l(const u8 *p)
|
||||
{
|
||||
return p[0] | (p[1] << 8);
|
||||
}
|
||||
|
||||
u32 filesystem_t::r24l(const u8 *p)
|
||||
{
|
||||
return p[0] | (p[1] << 8) | (p[2] << 16);
|
||||
}
|
||||
|
||||
u32 filesystem_t::r32l(const u8 *p)
|
||||
{
|
||||
return p[0] | (p[1] << 8) | (p[2] << 16) | (p[3] << 24);
|
||||
}
|
||||
|
||||
std::string filesystem_t::trim_end_spaces(const std::string &str)
|
||||
{
|
||||
const auto i = str.find_last_not_of(' ');
|
||||
return str.substr(0, (std::string::npos != i) ? (i + 1) : 0);
|
||||
return std::string_view(reinterpret_cast<const char *>(p), size);
|
||||
}
|
||||
|
||||
meta_data filesystem_t::volume_metadata()
|
||||
|
@ -174,7 +174,7 @@ public:
|
||||
void copy(u32 offset, const u8 *src, u32 size);
|
||||
void fill( u8 data);
|
||||
void fill(u32 offset, u8 data, u32 size);
|
||||
void wstr(u32 offset, const std::string &str);
|
||||
void wstr(u32 offset, std::string_view str);
|
||||
void w8( u32 offset, u8 data);
|
||||
void w16b(u32 offset, u16 data);
|
||||
void w24b(u32 offset, u32 data);
|
||||
@ -183,7 +183,7 @@ public:
|
||||
void w24l(u32 offset, u32 data);
|
||||
void w32l(u32 offset, u32 data);
|
||||
|
||||
std::string rstr(u32 offset, u32 size) const;
|
||||
std::string_view rstr(u32 offset, u32 size) const;
|
||||
u8 r8( u32 offset) const;
|
||||
u16 r16b(u32 offset) const;
|
||||
u32 r24b(u32 offset) const;
|
||||
@ -253,33 +253,15 @@ public:
|
||||
// Format an image, provide the volume metadata
|
||||
virtual err_t format(const meta_data &meta);
|
||||
|
||||
static void copy(u8 *p, const u8 *src, u32 size);
|
||||
static void fill(u8 *p, u8 data, u32 size);
|
||||
static void wstr(u8 *p, const std::string &str);
|
||||
static void w8( u8 *p, u8 data);
|
||||
static void w16b(u8 *p, u16 data);
|
||||
static void w24b(u8 *p, u32 data);
|
||||
static void w32b(u8 *p, u32 data);
|
||||
static void w16l(u8 *p, u16 data);
|
||||
static void w24l(u8 *p, u32 data);
|
||||
static void w32l(u8 *p, u32 data);
|
||||
static void wstr(u8 *p, std::string_view str);
|
||||
|
||||
static std::string rstr(const u8 *p, u32 size);
|
||||
static u8 r8( const u8 *p);
|
||||
static u16 r16b(const u8 *p);
|
||||
static u32 r24b(const u8 *p);
|
||||
static u32 r32b(const u8 *p);
|
||||
static u16 r16l(const u8 *p);
|
||||
static u32 r24l(const u8 *p);
|
||||
static u32 r32l(const u8 *p);
|
||||
static std::string_view rstr(const u8 *p, u32 size);
|
||||
|
||||
protected:
|
||||
filesystem_t(fsblk_t &blockdev, u32 size) : m_blockdev(blockdev) {
|
||||
m_blockdev.set_block_size(size);
|
||||
}
|
||||
|
||||
static std::string trim_end_spaces(const std::string &str);
|
||||
|
||||
fsblk_t &m_blockdev;
|
||||
};
|
||||
|
||||
|
@ -12,6 +12,7 @@
|
||||
#include "ioprocs.h"
|
||||
#include "ioprocsfill.h"
|
||||
#include "ioprocsvec.h"
|
||||
#include "multibyte.h"
|
||||
#include "strformat.h"
|
||||
|
||||
|
||||
@ -159,15 +160,14 @@ std::vector<u8> image_handler::fload_rsrc(std::string path)
|
||||
auto filedata = fload(path);
|
||||
const u8 *head = filedata.data();
|
||||
|
||||
using fs::filesystem_t;
|
||||
if(filesystem_t::r32b(head+0x00) == 0x00051607 &&
|
||||
filesystem_t::r32b(head+0x04) == 0x00020000) {
|
||||
u16 nent = filesystem_t::r16b(head+0x18);
|
||||
if(get_u32be(head+0x00) == 0x00051607 &&
|
||||
get_u32be(head+0x04) == 0x00020000) {
|
||||
u16 nent = get_u16be(head+0x18);
|
||||
for(u16 i=0; i != nent; i++) {
|
||||
const u8 *e = head + 12*i;
|
||||
if(filesystem_t::r32b(e+0) == 2) {
|
||||
u32 start = filesystem_t::r32b(e+4);
|
||||
u32 len = filesystem_t::r32b(e+8);
|
||||
if(get_u32be(e+0) == 2) {
|
||||
u32 start = get_u32be(e+4);
|
||||
u32 len = get_u32be(e+8);
|
||||
filedata.erase(filedata.begin(), filedata.begin() + start);
|
||||
filedata.erase(filedata.begin() + len, filedata.end());
|
||||
return filedata;
|
||||
@ -194,14 +194,13 @@ void image_handler::fsave_rsrc(std::string path, const std::vector<u8> &data)
|
||||
{
|
||||
u8 head[0x2a];
|
||||
|
||||
using fs::filesystem_t;
|
||||
filesystem_t::w32b(head+0x00, 0x00051607); // Magic
|
||||
filesystem_t::w32b(head+0x04, 0x00020000); // Version
|
||||
filesystem_t::fill(head+0x08, 0, 16); // Filler
|
||||
filesystem_t::w16b(head+0x18, 1); // Number of entries
|
||||
filesystem_t::w32b(head+0x1a, 2); // Resource fork
|
||||
filesystem_t::w32b(head+0x22, 0x2a); // Offset in the file
|
||||
filesystem_t::w32b(head+0x26, data.size()); // Length
|
||||
put_u32be(head+0x00, 0x00051607); // Magic
|
||||
put_u32be(head+0x04, 0x00020000); // Version
|
||||
memset(head+0x08, 0, 16); // Filler
|
||||
put_u16be(head+0x18, 1); // Number of entries
|
||||
put_u32be(head+0x1a, 2); // Resource fork
|
||||
put_u32be(head+0x22, 0x2a); // Offset in the file
|
||||
put_u32be(head+0x26, data.size()); // Length
|
||||
|
||||
auto fo = fopen(path.c_str(), "wb");
|
||||
if(!fo) {
|
||||
|
Loading…
Reference in New Issue
Block a user