Skip to content

Commit

Permalink
msx_dsk.cpp: Attempt to more strongly identify MSX-DOS disk images
Browse files Browse the repository at this point in the history
  • Loading branch information
ajrhacker committed Feb 24, 2024
1 parent d1501f2 commit d3c81ca
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
33 changes: 32 additions & 1 deletion src/lib/formats/msx_dsk.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// license:BSD-3-Clause
// copyright-holders:Olivier Galibert
// copyright-holders:Olivier Galibert, AJR
/*********************************************************************
formats/msx_dsk.cpp
Expand All @@ -10,6 +10,10 @@

#include "msx_dsk.h"

#include "ioprocs.h"
#include <cstring>


//msx_format::msx_format() : wd177x_format(formats)
msx_format::msx_format() : upd765_format(formats)
{
Expand Down Expand Up @@ -66,4 +70,31 @@ const msx_format::format msx_format::formats[] = {
{}
};

int msx_format::identify(util::random_read &io, uint32_t form_factor, const std::vector<uint32_t> &variants) const
{
int result = upd765_format::identify(io, form_factor, variants);

// Attempt to confirm some typical elements of MSX-DOS boot sectors
if(result & FIFID_SIZE) {
std::uint8_t sector0[0x100];
std::size_t actual;
// First byte of any bootable disk must be either EB or E9
if(!io.read_at(0, sector0, 0x100, actual) && actual == 0x100 && (sector0[0] & 0xfd) == 0xe9) {
// Z80 boot code is entered at offset 1E
if(sector0[0x1e] == 0xc9) {
// No actual boot code, so check for magic OEM name instead
if(!std::memcmp(&sector0[3], u8"-NO$MSX-", 8))
result |= FIFID_STRUCT;
} else if(sector0[0x1e] == 0xd0 || (sector0[0x1e] == 0x18 && sector0[0x1f] == 0x10)) {
int i = sector0[0x1e] == 0x18 ? 0x41 : 0x2f;
int j = sector0[i] + 1;
if(j <= 0x100 - (8+3) && !std::memcmp(&sector0[j], u8"MSXDOS SYS", 8+3))
result |= FIFID_STRUCT;
}
}
}

return result;
}

const msx_format FLOPPY_MSX_FORMAT;
2 changes: 2 additions & 0 deletions src/lib/formats/msx_dsk.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ class msx_format: public upd765_format
virtual const char *description() const noexcept override;
virtual const char *extensions() const noexcept override;

virtual int identify(util::random_read &io, uint32_t form_factor, const std::vector<uint32_t> &variants) const override;

private:
static const format formats[];
};
Expand Down

0 comments on commit d3c81ca

Please sign in to comment.