(nw) formats: reduce dependencies on libemu

The only link dependency left is emu_fatalerror.  The format handlers
really shouldn't be throwing fatal errors at all - they should just
fail to load an image they can't handle.  Maybe the interface should
be enhanced to allow better propagation of errors up from the format
handlers so they can be displayed in a UI rather than just logged.

The only other two dependencies are on logmacro.h (pure macros) and
the PAIR type from emucore.h (possibly worth moving to util).
This commit is contained in:
Vas Crabb 2020-04-13 19:14:36 +10:00
parent 404e7321a6
commit de72f97b90
27 changed files with 105 additions and 81 deletions

View File

@ -98,12 +98,12 @@
*********************************************************************/
#include <cstdio>
#include <cassert>
#include "emu.h" // logerror
#include "ap_dsk35.h"
#include <cassert>
#include <cstdio>
struct apple35_tag
{
uint32_t data_offset;

View File

@ -8,10 +8,13 @@
***************************************************************************/
#include "emu.h"
#include "imageutl.h"
#include "apridisk.h"
#include "imageutl.h"
#include "emucore.h" // emu_fatalerror
apridisk_format::apridisk_format()
{
}
@ -97,7 +100,7 @@ bool apridisk_format::load(io_generic *io, uint32_t form_factor, floppy_image *i
uint16_t length = pick_integer_le(comp, 0, 2);
if (length != SECTOR_SIZE)
fatalerror("apridisk_format: Invalid compression length %04x\n", length);
throw emu_fatalerror("apridisk_format: Invalid compression length %04x\n", length);
memset(data_ptr, comp[2], SECTOR_SIZE);
}
@ -108,7 +111,7 @@ bool apridisk_format::load(io_generic *io, uint32_t form_factor, floppy_image *i
break;
default:
fatalerror("apridisk_format: Invalid compression %04x\n", compression);
throw emu_fatalerror("apridisk_format: Invalid compression %04x\n", compression);
}
sectors[track][head][sector - 1].data = data_ptr;

View File

@ -23,10 +23,9 @@ Each byte is 8 bits (MSB first) with no start or stop bits.
********************************************************************/
#include "emu.h" // for popmessage and <string>
#include "camplynx_cas.h"
#define WAVEENTRY_LOW -32768
#define WAVEENTRY_HIGH 32767

View File

@ -39,11 +39,8 @@
*********************************************************************/
#include "emu.h" // fatalerror
#include "cbm_crt.h"
#include "corefile.h"
//**************************************************************************
// MACROS/CONSTANTS

View File

@ -14,6 +14,8 @@
#include "formats/imageutl.h"
#include "corefile.h"
//**************************************************************************
// MACROS/CONSTANTS

View File

@ -8,9 +8,11 @@
*********************************************************************/
#include "emu.h" // BIT
#include "formats/ccvf_dsk.h"
#include "coretmpl.h" // BIT
ccvf_format::ccvf_format()
{
formats = file_formats;
@ -124,7 +126,7 @@ bool ccvf_format::load(io_generic *io, uint32_t form_factor, floppy_image *image
for (int i=0; i<1920 && pos<size; i++, pos++) {
for (int bit=0; bit<8; bit++) {
bit_w(buffer, BIT(bytes[pos], bit), f.cell_size);
bit_w(buffer, util::BIT(bytes[pos], bit), f.cell_size);
}
}

View File

@ -33,9 +33,11 @@
**************************************************************************/
#include "emu.h" // PAIR
#include "coco_cas.h"
#include "emucore.h" // PAIR
#define COCO_WAVESAMPLES_HEADER (1.0)
#define COCO_WAVESAMPLES_TRAILER (1.0)
#define COCO_LONGSILENCE (5.0)

View File

@ -10,9 +10,11 @@
*********************************************************************/
#include "emu.h" // emu_fatalerror, fatalerror
#include "formats/d64_dsk.h"
#include "emucore.h" // emu_fatalerror
d64_format::d64_format()
{
formats = file_formats;

View File

@ -11,9 +11,12 @@
* Correctly note exact index timing.
*/
#include "emu.h" // fatalerror
#include "dfi_dsk.h"
#include "emucore.h" // emu_fatalerror
#include <zlib.h>
#define NUMBER_OF_MULTIREADS 3
// thresholds for brickwall windowing
//define DFI_MIN_CLOCKS 65
@ -59,8 +62,8 @@ int dfi_format::identify(io_generic *io, uint32_t form_factor)
{
char sign[4];
io_generic_read(io, sign, 0, 4);
if (memcmp(sign, "DFER", 4)==0)
fatalerror("Old type Discferret image detected; the mess Discferret decoder will not handle this properly, bailing out!\n");
if (memcmp(sign, "DFER", 4) == 0)
throw emu_fatalerror("Old type Discferret image detected; the mess Discferret decoder will not handle this properly, bailing out!\n");
return memcmp(sign, "DFE2", 4) ? 0 : 100;
}

View File

@ -8,6 +8,14 @@
*********************************************************************/
#include "flopimg.h"
#include "imageutl.h"
#include "emucore.h" // emu_fatalerror
#include "osdcore.h"
#include "ioprocs.h"
#include "pool.h"
#include <cstdlib>
#include <cstring>
#include <cstdio>
@ -15,13 +23,6 @@
#include <climits>
#include <cassert>
#include "emu.h" // emu_fatalerror
#include "osdcore.h"
#include "ioprocs.h"
#include "flopimg.h"
#include "pool.h"
#include "imageutl.h"
#define TRACK_LOADED 0x01
#define TRACK_DIRTY 0x02

View File

@ -8,7 +8,6 @@
***************************************************************************/
#include "emu.h"
#include "fsd_dsk.h"

View File

@ -10,9 +10,11 @@
*********************************************************************/
#include "emu.h" // emu_fatalerror
#include "formats/g64_dsk.h"
#include "emucore.h" // emu_fatalerror
#define G64_FORMAT_HEADER "GCR-1541"
g64_format::g64_format()

View File

@ -45,12 +45,14 @@
*********************************************************************/
#include "emu.h"
#include "hpi_dsk.h"
#include "coretmpl.h" // BIT
// Debugging
#define VERBOSE 0
#define LOG(...) do { if (VERBOSE) printf(__VA_ARGS__); } while (false)
#define LOG(...) do { if (VERBOSE) osd_printf_info(__VA_ARGS__); } while (false)
constexpr unsigned IL_OFFSET = 0x12; // Position of interleave factor in HPI image (2 bytes, big-endian)
constexpr unsigned DEFAULT_IL = 7; // Default interleaving factor
@ -260,7 +262,7 @@ void hpi_format::write_mmfm_bit(std::vector<uint32_t> &buffer , bool data_bit ,
void hpi_format::write_mmfm_byte(std::vector<uint32_t> &buffer , uint8_t data , uint8_t clock)
{
for (unsigned i = 0; i < 8; i++) {
write_mmfm_bit(buffer , BIT(data , i) , BIT(clock , i));
write_mmfm_bit(buffer , util::BIT(data , i) , util::BIT(clock , i));
}
}
@ -281,7 +283,7 @@ void hpi_format::write_crc(std::vector<uint32_t> &buffer , uint16_t crc)
{
// Note that CRC is stored with MSB (x^15) first
for (unsigned i = 0; i < 16; i++) {
write_mmfm_bit(buffer , BIT(crc , 15 - i) , 0);
write_mmfm_bit(buffer , util::BIT(crc , 15 - i) , 0);
}
}
@ -371,7 +373,7 @@ std::vector<uint8_t> hpi_format::get_next_id_n_block(const uint8_t *bitstream ,
uint32_t sr = 0;
// Look for either sync + ID AM or sync + DATA AM
while (pos < bitstream_size && sr != ID_CD_PATTERN && sr != DATA_CD_PATTERN) {
bool bit = BIT(bitstream[ pos >> 3 ] , 7 - (pos & 7));
bool bit = util::BIT(bitstream[ pos >> 3 ] , 7 - (pos & 7));
pos++;
sr = (sr << 1) | bit;
}
@ -396,7 +398,7 @@ std::vector<uint8_t> hpi_format::get_next_id_n_block(const uint8_t *bitstream ,
uint8_t byte = 0;
unsigned j;
for (j = 0; j < 8 && pos < bitstream_size; j++) {
bool bit = BIT(bitstream[ pos >> 3 ] , 7 - (pos & 7));
bool bit = util::BIT(bitstream[ pos >> 3 ] , 7 - (pos & 7));
pos += 2;
byte >>= 1;
if (bit) {

View File

@ -30,10 +30,10 @@
*********************************************************************/
#include <assert.h>
#include "ibmxdf_dsk.h"
#include "emucore.h" // emu_fatalerror
#include "emu.h" // emu_fatalerror
#include "formats/ibmxdf_dsk.h"
ibmxdf_format::ibmxdf_format() : wd177x_format(formats)
{

View File

@ -8,9 +8,12 @@
*********************************************************************/
#include <cstring>
#include "imd_dsk.h"
#include <cassert>
#include "flopimg.h"
#include <cstring>
struct imddsk_tag
{
@ -373,9 +376,6 @@ FLOPPY_CONSTRUCT( imd_dsk_construct )
*********************************************************************/
#include "emu.h" // emu_fatalerror
#include "imd_dsk.h"
imd_format::imd_format()
{
}

View File

@ -14,9 +14,11 @@
*********************************************************************/
#include "emu.h"
#include "img_dsk.h"
#include "coretmpl.h" // BIT
// Debugging
#define VERBOSE 0
#define LOG(...) do { if (VERBOSE) osd_printf_info(__VA_ARGS__); } while (false)
@ -159,7 +161,7 @@ void img_format::write_mmfm_bit(std::vector<uint32_t> &buffer , bool data_bit ,
bit_w(buffer , clock_bit , CELL_SIZE);
bit_w(buffer , data_bit , CELL_SIZE);
if (BIT(m_crc , 15) ^ data_bit) {
if (util::BIT(m_crc , 15) ^ data_bit) {
m_crc = (m_crc << 1) ^ CRC_POLY;
} else {
m_crc <<= 1;
@ -169,7 +171,7 @@ void img_format::write_mmfm_bit(std::vector<uint32_t> &buffer , bool data_bit ,
void img_format::write_mmfm_byte(std::vector<uint32_t> &buffer , uint8_t data , uint8_t clock)
{
for (int i = 7; i >= 0; i--) {
write_mmfm_bit(buffer , BIT(data , i) , BIT(clock , i));
write_mmfm_bit(buffer , util::BIT(data , i) , util::BIT(clock , i));
}
}
@ -182,7 +184,7 @@ void img_format::write_crc(std::vector<uint32_t> &buffer , uint16_t crc)
{
// Note that CRC is stored with MSB (x^15) first
for (unsigned i = 0; i < 16; i++) {
write_mmfm_bit(buffer , BIT(crc , 15 - i) , 0);
write_mmfm_bit(buffer , util::BIT(crc , 15 - i) , 0);
}
}
@ -268,10 +270,10 @@ std::vector<uint8_t> img_format::get_next_id_n_block(const uint8_t *bitstream ,
do {
unsigned cnt_trans = 0;
while (pos < bitstream_size && cnt_trans < 34) {
bool bit = BIT(bitstream[ pos >> 3 ] , ~pos & 7);
bool bit = util::BIT(bitstream[ pos >> 3 ] , ~pos & 7);
pos++;
if (cnt_trans < 32) {
if (!(BIT(cnt_trans , 0) ^ bit)) {
if (!(util::BIT(cnt_trans , 0) ^ bit)) {
cnt_trans++;
} else {
cnt_trans = 0;
@ -298,10 +300,10 @@ std::vector<uint8_t> img_format::get_next_id_n_block(const uint8_t *bitstream ,
// Get AM
data_sr = clock_sr = 0;
for (unsigned i = 0; i < 7; ++i) {
bool bit = BIT(bitstream[ pos >> 3 ] , ~pos & 7);
bool bit = util::BIT(bitstream[ pos >> 3 ] , ~pos & 7);
pos++;
clock_sr = (clock_sr << 1) | bit;
bit = BIT(bitstream[ pos >> 3 ] , ~pos & 7);
bit = util::BIT(bitstream[ pos >> 3 ] , ~pos & 7);
pos++;
data_sr = (data_sr << 1) | bit;
}
@ -327,7 +329,7 @@ std::vector<uint8_t> img_format::get_next_id_n_block(const uint8_t *bitstream ,
data_sr = 0;
unsigned j;
for (j = 0; j < 8 && pos < bitstream_size; j++) {
bool bit = BIT(bitstream[ pos >> 3 ] , ~pos & 7);
bool bit = util::BIT(bitstream[ pos >> 3 ] , ~pos & 7);
pos += 2;
data_sr = (data_sr << 1) | bit;
}

View File

@ -104,10 +104,11 @@
***************************************************************************/
#include "emu.h"
#include "imageutl.h"
#include "jvc_dsk.h"
#include "emucore.h" // emu_fatalerror
jvc_format::jvc_format()
{
}

View File

@ -116,7 +116,6 @@
**************************************************************************/
#include "emu.h"
#include "mfm_hd.h"
#include "imageutl.h"

View File

@ -8,9 +8,9 @@
*********************************************************************/
#include "emu.h" // logerror
#include "formats/oric_dsk.h"
oric_dsk_format::oric_dsk_format()
{
}

View File

@ -44,10 +44,11 @@
*********************************************************************/
#include "emu.h"
#include "formats/os9_dsk.h"
#include "os9_dsk.h"
#include "imageutl.h"
#include "coretmpl.h" // BIT
#include "formats/imageutl.h"
os9_format::os9_format() : wd177x_format(formats)
{
@ -85,7 +86,7 @@ int os9_format::find_size(io_generic *io, uint32_t form_factor)
io_generic_read(io, os9_header, 0, sizeof(os9_header));
int os9_total_sectors = pick_integer_be(os9_header, 0x00, 3);
int os9_heads = BIT(os9_header[0x10], 0) ? 2 : 1;
int os9_heads = util::BIT(os9_header[0x10], 0) ? 2 : 1;
int os9_sectors = pick_integer_be(os9_header, 0x11, 2);
if (os9_total_sectors <= 0 || os9_heads <= 0 || os9_sectors <= 0)
@ -103,19 +104,19 @@ int os9_format::find_size(io_generic *io, uint32_t form_factor)
int opt_track0_sectors = pick_integer_be(os9_header, 0x3f + 11, 2);
int opt_interleave = os9_header[0x3f + 13];
int opt_mfm = BIT(opt_density, 0);
int opt_mfm = util::BIT(opt_density, 0);
// The NitrOS9 rb1773 driver uses bit 1 of opt_type to distinguish
// between a sector base ID of zero or one, so recognise that here.
int opt_sector_base_id = BIT(opt_type, 1) ? 0 : 1;
int opt_sector_size = BIT(opt_type, 2) ? 512 : 256;
int opt_coco = BIT(opt_type, 5);
int opt_sector_base_id = util::BIT(opt_type, 1) ? 0 : 1;
int opt_sector_size = util::BIT(opt_type, 2) ? 512 : 256;
int opt_coco = util::BIT(opt_type, 5);
// Some OS9 versions appear to use bit 7 of the opt_density rather
// than bit 5 of opt_type to signify a COCO format disk. E.g. Gimix
// OS9 is documented to use this bit and had a floppy driver that
// could read both non-COCO and COCO format disks.
if (BIT(opt_density, 7))
if (util::BIT(opt_density, 7))
opt_coco = 1;
// COCO format disks are expected for have an opt_dtype of 1.

View File

@ -1,6 +1,5 @@
// license:BSD-3-Clause
// copyright-holders:Olivier Galibert
#include "emu.h" // logerror
#include "pasti_dsk.h"
// Pasti format supported using the documentation at

View File

@ -40,18 +40,18 @@
********************************************************************/
#include "ti99_dsk.h"
#include "imageutl.h"
#include "osdcore.h" // osd_printf_* (in osdcore.h)
#include <cstring>
#include <ctime>
#include <cassert>
#include <iomanip>
#include "emu.h" // osd_printf_* (in osdcore.h)
#include "imageutl.h"
#include "ti99_dsk.h"
#define SECTOR_SIZE 256
#undef LOG_OUTPUT_FUNC
#define LOG_OUTPUT_FUNC osd_printf_info
#define LOG_WARN (1U<<1) // Warnings
@ -64,8 +64,10 @@
#define VERBOSE ( LOG_WARN )
#define __EMU_H__ // logmacro wasn't really intended to be used outside stuff that uses libemu
#include "logmacro.h"
// ====================================================
// Common methods for both formats.
// ====================================================

View File

@ -27,11 +27,12 @@ TODO:
*/
#include <cassert>
#include "tzx_cas.h"
#include "formats/imageutl.h"
#include "emu.h"
#include "imageutl.h"
#include <cassert>
#include <cmath>
#define TZX_WAV_FREQUENCY 44100
#define WAVE_LOW -0x5a9e
@ -435,7 +436,7 @@ static int tzx_handle_generalized(int16_t **buffer, const uint8_t *bytes, int pa
const uint8_t *symtable = bytes;
const uint8_t *table2 = bytes + (2 * npd + 1)*asd;
int NB = ceil(compute_log2(asd)); // number of bits needed to represent each symbol
int NB = std::ceil(compute_log2(asd)); // number of bits needed to represent each symbol
uint8_t stream_bit = 0;
uint32_t stream_byte = 0;

View File

@ -8,9 +8,11 @@
*********************************************************************/
#include "emu.h" // emu_fatalerror
#include "formats/upd765_dsk.h"
#include "emucore.h" // emu_fatalerror
upd765_format::upd765_format(const format *_formats) : file_header_skip_bytes(0), file_footer_skip_bytes(0), formats(_formats)
{
}

View File

@ -10,7 +10,6 @@
***************************************************************************/
#include "emu.h"
#include "vdk_dsk.h"
vdk_format::vdk_format()

View File

@ -97,9 +97,11 @@
zone.
*/
#include "emu.h" // osd_printf_verbose, BIT, emu_fatalerror
#include "formats/victor9k_dsk.h"
#include "emucore.h" // emu_fatalerror
victor9k_format::victor9k_format()
{
}
@ -173,7 +175,7 @@ void victor9k_format::log_boot_sector(uint8_t *data)
osd_printf_verbose("Boot start: %04x\n", (data[29] << 8) | data[30]);
// Flags
osd_printf_verbose("%s sided\n", BIT(data[33], 0) ? "Double" : "Single");
osd_printf_verbose("%s sided\n", util::BIT(data[33], 0) ? "Double" : "Single");
osd_printf_verbose("Interleave factor: %u\n", data[32] >> 4);
// Disc type

View File

@ -8,9 +8,11 @@
*********************************************************************/
#include "emu.h" // emu_fatalerror
#include "formats/wd177x_dsk.h"
#include "emucore.h" // emu_fatalerror
wd177x_format::wd177x_format(const format *_formats)
{
formats = _formats;