Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
Robbbert committed Oct 11, 2024
2 parents 672de63 + 5eb6183 commit c207fd6
Show file tree
Hide file tree
Showing 8 changed files with 129 additions and 62 deletions.
41 changes: 38 additions & 3 deletions src/devices/cpu/olms66k/msm665xx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ DEFINE_DEVICE_TYPE(MSM66573, msm66573_device, "msm66573", "Oki MSM66573")
msm665xx_device::msm665xx_device(const machine_config &mconfig, device_type type, const char *tag, device_t *owner, u32 clock, address_map_constructor mem_map, address_map_constructor data_map)
: cpu_device(mconfig, type, tag, owner, clock)
, m_program_config("program", ENDIANNESS_LITTLE, 8, 20, 0, mem_map)
, m_data_config("iram", ENDIANNESS_LITTLE, 16, 20, 0, data_map)
, m_data_config("data", ENDIANNESS_LITTLE, 16, 20, 0, data_map)
, m_acc(0)
, m_pc(0)
, m_ppc(0)
Expand All @@ -30,6 +30,7 @@ msm665xx_device::msm665xx_device(const machine_config &mconfig, device_type type
, m_dsr(0)
, m_tsr(0)
, m_romwin(0x30)
, m_memscon(0)
, m_icount(0)
{
}
Expand Down Expand Up @@ -64,6 +65,8 @@ void msm66573_device::data_map(address_map &map)
map(0x00008, 0x00008).rw(FUNC(msm66573_device::tsr_r), FUNC(msm66573_device::tsr_w));
map(0x00009, 0x00009).rw(FUNC(msm66573_device::dsr_r), FUNC(msm66573_device::dsr_w));
map(0x0000b, 0x0000b).rw(FUNC(msm66573_device::romwin_r), FUNC(msm66573_device::romwin_w));
map(0x00010, 0x00010).w(FUNC(msm66573_device::memsacp_w));
map(0x00011, 0x00011).rw(FUNC(msm66573_device::memscon_r), FUNC(msm66573_device::memscon_w));
// TODO: many, many other SFRs
map(0x00200, 0x011ff).ram().share("internal");
}
Expand All @@ -90,7 +93,7 @@ void msm665xx_device::device_start()
[this](u32 data) { m_csr = (data >> 16) & 0x0f; m_pc = data & 0xffff; m_ppc = data & 0xfffff; }
).mask(0xfffff).noshow();
state_add(MSM665XX_PSW, "PSW", m_psw);
//state_add(STATE_GENFLAGS, "FLAGS", m_psw).formatstr("%9s").noshow(); // TODO
state_add(STATE_GENFLAGS, "FLAGS", m_psw).formatstr("%8s").noshow();
state_add(MSM665XX_LRB, "LRB", m_lrb);
state_add(MSM665XX_SSP, "SSP", m_ssp);
u16 *fixed = static_cast<u16 *>(memshare("internal")->ptr());
Expand All @@ -99,6 +102,8 @@ void msm665xx_device::device_start()
[this, fixed, n]() { return fixed[(m_psw & 0x07) << 2 | n]; },
[this, fixed, n](u16 data) { fixed[(m_psw & 0x07) << 2 | n] = data; }
);
// NOTE: This assumes internal RAM is large enough (≥2KB) to provide all 256 register banks.
// While most nX-8/500S MCUs have that much internal RAM, ML66514 has only 1KB.
for (int n = 0; n < 4; n++)
state_add<u16>(MSM665XX_ER0 + n, util::string_format("ER%d", n).c_str(),
[this, fixed, n]() { return fixed[(m_lrb & 0x00ff) << 2 | n]; },
Expand All @@ -113,6 +118,7 @@ void msm665xx_device::device_start()
state_add(MSM665XX_DSR, "DSR", m_dsr).mask(0x0f);
state_add(MSM665XX_TSR, "TSR", m_tsr).mask(0x0f);
state_add(MSM665XX_ROMWIN, "ROMWIN", m_romwin);
state_add(MSM665XX_MEMSCON, "MEMSCON", m_memscon).mask(0x03);

// save state
save_item(NAME(m_acc));
Expand All @@ -136,6 +142,7 @@ void msm665xx_device::device_reset()
m_csr = 0;
m_dsr = 0;
m_tsr = 0;
m_memscon = 0;
}


Expand Down Expand Up @@ -186,6 +193,8 @@ u8 msm665xx_device::dsr_r()

void msm665xx_device::dsr_w(u8 data)
{
if (!BIT(m_memscon, 0))
logerror("%02X:%04X: Writing %02X to DSR without data memory space expansion\n", m_csr, m_pc, data);
m_dsr = data & 0x0f;
}

Expand All @@ -196,6 +205,8 @@ u8 msm665xx_device::tsr_r()

void msm665xx_device::tsr_w(u8 data)
{
if (!BIT(m_memscon, 1))
logerror("%02X:%04X: Writing %02X to TSR without program memory space expansion\n", m_csr, m_pc, data);
m_tsr = data & 0x0f;
}

Expand All @@ -210,6 +221,22 @@ void msm665xx_device::romwin_w(u8 data)
m_romwin = data | 0x30;
}

void msm665xx_device::memsacp_w(u8 data)
{
logerror("%02X:%04X: Writing %02X to MEMSCAP\n", m_csr, m_pc, data);
}

u8 msm665xx_device::memscon_r()
{
return m_memscon | 0xfc;
}

void msm665xx_device::memscon_w(u8 data)
{
// FIXME: may be written only once after reset after double write to MEMSACP
m_memscon = data & 0x03;
}


void msm665xx_device::execute_run()
{
Expand All @@ -227,7 +254,15 @@ void msm665xx_device::state_string_export(const device_state_entry &entry, std::
switch (entry.index())
{
case STATE_GENFLAGS:
// TODO
str = util::string_format("%c%c%c%c%c%c%c%c",
BIT(m_psw, 15) ? 'C' : '.',
BIT(m_psw, 14) ? 'Z' : '.',
BIT(m_psw, 13) ? 'H' : '.',
BIT(m_psw, 12) ? 'D' : '.',
BIT(m_psw, 11) ? 'S' : '.',
BIT(m_psw, 10) ? 'P' : '.',
BIT(m_psw, 9) ? 'V' : '.',
BIT(m_psw, 8) ? 'I' : '.');
break;
}
}
6 changes: 5 additions & 1 deletion src/devices/cpu/olms66k/msm665xx.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class msm665xx_device : public cpu_device
MSM665XX_R0, MSM665XX_R1, MSM665XX_R2, MSM665XX_R3,
MSM665XX_R4, MSM665XX_R5, MSM665XX_R6, MSM665XX_R7,
MSM665XX_CSR, MSM665XX_DSR, MSM665XX_TSR,
MSM665XX_ROMWIN
MSM665XX_ROMWIN, MSM665XX_MEMSCON
};

// TODO: port callbacks
Expand Down Expand Up @@ -58,6 +58,9 @@ class msm665xx_device : public cpu_device
void tsr_w(u8 data);
u8 romwin_r();
void romwin_w(u8 data);
void memsacp_w(u8 data);
u8 memscon_r();
void memscon_w(u8 data);

private:
address_space_config m_program_config;
Expand All @@ -77,6 +80,7 @@ class msm665xx_device : public cpu_device
u8 m_dsr;
u8 m_tsr;
u8 m_romwin;
u8 m_memscon;
s32 m_icount;
};

Expand Down
79 changes: 51 additions & 28 deletions src/lib/util/chd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ struct chd_file::metadata_hash
// stream in bigendian order
//-------------------------------------------------

inline util::sha1_t chd_file::be_read_sha1(const uint8_t *base)const
inline util::sha1_t chd_file::be_read_sha1(const uint8_t *base) const noexcept
{
util::sha1_t result;
memcpy(&result.m_raw[0], base, sizeof(result.m_raw));
Expand All @@ -148,7 +148,7 @@ inline util::sha1_t chd_file::be_read_sha1(const uint8_t *base)const
// stream in bigendian order
//-------------------------------------------------

inline void chd_file::be_write_sha1(uint8_t *base, util::sha1_t value)
inline void chd_file::be_write_sha1(uint8_t *base, util::sha1_t value) noexcept
{
memcpy(base, &value.m_raw[0], sizeof(value.m_raw));
}
Expand Down Expand Up @@ -339,7 +339,7 @@ bool chd_file::parent_missing() const noexcept
* @return A sha1_t.
*/

util::sha1_t chd_file::sha1()
util::sha1_t chd_file::sha1() const noexcept
{
try
{
Expand All @@ -350,7 +350,7 @@ util::sha1_t chd_file::sha1()
}
catch (std::error_condition const &)
{
// on failure, return nullptr
// on failure, return null
return util::sha1_t::null;
}
}
Expand All @@ -368,7 +368,7 @@ util::sha1_t chd_file::sha1()
* @return A sha1_t.
*/

util::sha1_t chd_file::raw_sha1()
util::sha1_t chd_file::raw_sha1() const noexcept
{
try
{
Expand All @@ -383,7 +383,7 @@ util::sha1_t chd_file::raw_sha1()
}
catch (std::error_condition const &)
{
// on failure, return nullptr
// on failure, return null
return util::sha1_t::null;
}
}
Expand All @@ -401,7 +401,7 @@ util::sha1_t chd_file::raw_sha1()
* @return A sha1_t.
*/

util::sha1_t chd_file::parent_sha1()
util::sha1_t chd_file::parent_sha1() const noexcept
{
try
{
Expand Down Expand Up @@ -542,20 +542,34 @@ std::error_condition chd_file::hunk_info(uint32_t hunknum, chd_codec_type &compr
* @param rawdata The rawdata.
*/

void chd_file::set_raw_sha1(util::sha1_t rawdata)
std::error_condition chd_file::set_raw_sha1(util::sha1_t rawdata) noexcept
{
uint64_t const offset = (m_rawsha1_offset != 0) ? m_rawsha1_offset : m_sha1_offset;
assert(offset != 0);

// create a big-endian version
uint8_t rawbuf[sizeof(util::sha1_t)];
be_write_sha1(rawbuf, rawdata);

// write to the header
uint64_t offset = (m_rawsha1_offset != 0) ? m_rawsha1_offset : m_sha1_offset;
assert(offset != 0);
file_write(offset, rawbuf, sizeof(rawbuf));
try
{
// write to the header
file_write(offset, rawbuf, sizeof(rawbuf));

// if we have a separate rawsha1_offset, update the full sha1 as well
if (m_rawsha1_offset != 0)
metadata_update_hash();
// if we have a separate rawsha1_offset, update the full sha1 as well
if (m_rawsha1_offset != 0)
metadata_update_hash();
}
catch (std::error_condition const &err)
{
return err;
}
catch (std::bad_alloc const &)
{
return std::errc::not_enough_memory;
}

return std::error_condition();
}

/**
Expand All @@ -570,19 +584,23 @@ void chd_file::set_raw_sha1(util::sha1_t rawdata)
* @param parent The parent.
*/

void chd_file::set_parent_sha1(util::sha1_t parent)
std::error_condition chd_file::set_parent_sha1(util::sha1_t parent) noexcept
{
// if no file, fail
if (!m_file)
throw std::error_condition(error::INVALID_FILE);
return std::error_condition(error::INVALID_FILE);

assert(m_parentsha1_offset != 0);

// create a big-endian version
uint8_t rawbuf[sizeof(util::sha1_t)];
be_write_sha1(rawbuf, parent);

// write to the header
assert(m_parentsha1_offset != 0);
file_write(m_parentsha1_offset, rawbuf, sizeof(rawbuf));
try { file_write(m_parentsha1_offset, rawbuf, sizeof(rawbuf)); }
catch (std::error_condition const &err) { return err; }

return std::error_condition();
}

/**
Expand Down Expand Up @@ -969,9 +987,9 @@ std::error_condition chd_file::read_hunk(uint32_t hunknum, void *buffer)
if (blockoffs != 0)
file_read(blockoffs, dest, m_hunkbytes);
else if (m_parent_missing)
throw std::error_condition(error::REQUIRES_PARENT);
return std::error_condition(error::REQUIRES_PARENT);
else if (m_parent)
m_parent->read_hunk(hunknum, dest);
return m_parent->read_hunk(hunknum, dest);
else
memset(dest, 0, m_hunkbytes);
return std::error_condition();
Expand Down Expand Up @@ -2608,7 +2626,7 @@ void chd_file::hunk_copy_from_self(uint32_t hunknum, uint32_t otherhunk)

// only permitted to reference prior hunks
if (otherhunk >= hunknum)
throw std::error_condition(std::errc::invalid_argument);
throw std::error_condition(error::HUNK_OUT_OF_RANGE);

// update the map entry
uint8_t *rawmap = &m_rawmap[hunknum * 12];
Expand Down Expand Up @@ -3009,7 +3027,9 @@ std::error_condition chd_file_compressor::compress_continue(double &progress, do
osd_work_queue_wait(m_read_queue, 30 * osd_ticks_per_second());
if (!compressed())
return std::error_condition();
set_raw_sha1(m_compsha1.finish());
std::error_condition err = set_raw_sha1(m_compsha1.finish());
if (err)
return err;
return compress_v5_map();
}
}
Expand Down Expand Up @@ -3166,23 +3186,26 @@ void chd_file_compressor::async_read()
{
// do the read
uint8_t *dest = &m_work_buffer[0] + (m_read_done_offset % work_buffer_bytes);
assert(dest == &m_work_buffer[0] || dest == &m_work_buffer[work_buffer_bytes/2]);
assert(dest == &m_work_buffer[0] || dest == &m_work_buffer[work_buffer_bytes / 2]);
uint64_t end_offset = m_read_done_offset + numbytes;

// if walking the parent, read in hunks from the parent CHD
if (m_walking_parent)
{
// if walking the parent, read in hunks from the parent CHD
uint8_t *curdest = dest;
for (uint64_t curoffs = m_read_done_offset; curoffs < end_offset + 1; curoffs += hunk_bytes())
{
m_parent->read_hunk(curoffs / hunk_bytes(), curdest);
std::error_condition err = m_parent->read_hunk(curoffs / hunk_bytes(), curdest);
if (err)
throw err;
curdest += hunk_bytes();
}
}

// otherwise, call the virtual function
else
{
// otherwise, call the virtual function
read_data(dest, m_read_done_offset, numbytes);
}

// spawn off work for each hunk
for (uint64_t curoffs = m_read_done_offset; curoffs < end_offset; curoffs += hunk_bytes())
Expand Down
16 changes: 8 additions & 8 deletions src/lib/util/chd.h
Original file line number Diff line number Diff line change
Expand Up @@ -309,18 +309,18 @@ class chd_file
uint32_t hunk_count() const noexcept { return m_hunkcount; }
uint32_t unit_bytes() const noexcept { return m_unitbytes; }
uint64_t unit_count() const noexcept { return m_unitcount; }
bool compressed() const { return (m_compression[0] != CHD_CODEC_NONE); }
bool compressed() const noexcept { return (m_compression[0] != CHD_CODEC_NONE); }
chd_codec_type compression(int index) const noexcept { return m_compression[index]; }
chd_file *parent() const noexcept { return m_parent.get(); }
bool parent_missing() const noexcept;
util::sha1_t sha1();
util::sha1_t raw_sha1();
util::sha1_t parent_sha1();
util::sha1_t sha1() const noexcept;
util::sha1_t raw_sha1() const noexcept;
util::sha1_t parent_sha1() const noexcept;
std::error_condition hunk_info(uint32_t hunknum, chd_codec_type &compressor, uint32_t &compbytes);

// setters
void set_raw_sha1(util::sha1_t rawdata);
void set_parent_sha1(util::sha1_t parent);
std::error_condition set_raw_sha1(util::sha1_t rawdata) noexcept;
std::error_condition set_parent_sha1(util::sha1_t parent) noexcept;

// file create
std::error_condition create(std::string_view filename, uint64_t logicalbytes, uint32_t hunkbytes, uint32_t unitbytes, const chd_codec_type (&compression)[4]);
Expand Down Expand Up @@ -372,8 +372,8 @@ class chd_file
struct metadata_hash;

// inline helpers
util::sha1_t be_read_sha1(const uint8_t *base) const;
void be_write_sha1(uint8_t *base, util::sha1_t value);
util::sha1_t be_read_sha1(const uint8_t *base) const noexcept;
void be_write_sha1(uint8_t *base, util::sha1_t value) noexcept;
void file_read(uint64_t offset, void *dest, uint32_t length) const;
void file_write(uint64_t offset, const void *source, uint32_t length);
uint64_t file_append(const void *source, uint32_t length, uint32_t alignment = 0);
Expand Down
Loading

0 comments on commit c207fd6

Please sign in to comment.