summaryrefslogtreecommitdiffstats
path: root/src/lib/formats/vdk_dsk.cpp
diff options
context:
space:
mode:
author Vas Crabb <cuavas@users.noreply.github.com>2021-08-22 09:06:15 +1000
committer GitHub <noreply@github.com>2021-08-22 09:06:15 +1000
commite8bbea1fc6e94e14768509d322f6c624403ffb36 (patch)
tree74dd1606a900d83de8aecff17a6737af4113308d /src/lib/formats/vdk_dsk.cpp
parente319bde5fc3696d7f48f62b15b6366c4377fe5d1 (diff)
formats, osd, util: Started refactoring file I/O stuff. (#8456)
Added more modern generic I/O interfaces with implementation backed by stdio, osd_file and core_file, replacing io_generic. Also replaced core_file's build-in zlib compression with a filter. unzip.cpp, un7z.cpp: Added option to supply abstract I/O interface rather than filename. Converted osd_file, core_file, archive_file, chd_file and device_image_interface to use std::error_condition rather than their own error enums. Allow mounting TI-99 RPK from inside archives.
Diffstat (limited to 'src/lib/formats/vdk_dsk.cpp')
-rw-r--r--src/lib/formats/vdk_dsk.cpp42
1 files changed, 24 insertions, 18 deletions
diff --git a/src/lib/formats/vdk_dsk.cpp b/src/lib/formats/vdk_dsk.cpp
index 57c44f8bb29..759697f852f 100644
--- a/src/lib/formats/vdk_dsk.cpp
+++ b/src/lib/formats/vdk_dsk.cpp
@@ -12,6 +12,9 @@
#include "vdk_dsk.h"
+#include "ioprocs.h"
+
+
vdk_format::vdk_format()
{
}
@@ -31,10 +34,11 @@ const char *vdk_format::extensions() const
return "vdk";
}
-int vdk_format::identify(io_generic *io, uint32_t form_factor, const std::vector<uint32_t> &variants)
+int vdk_format::identify(util::random_read &io, uint32_t form_factor, const std::vector<uint32_t> &variants)
{
+ size_t actual;
uint8_t id[2];
- io_generic_read(io, id, 0, 2);
+ io.read_at(0, id, 2, actual);
if (id[0] == 'd' && id[1] == 'k')
return 50;
@@ -42,16 +46,21 @@ int vdk_format::identify(io_generic *io, uint32_t form_factor, const std::vector
return 0;
}
-bool vdk_format::load(io_generic *io, uint32_t form_factor, const std::vector<uint32_t> &variants, floppy_image *image)
+bool vdk_format::load(util::random_read &io, uint32_t form_factor, const std::vector<uint32_t> &variants, floppy_image *image)
{
+ size_t actual;
+ if (io.seek(0, SEEK_SET))
+ return false;
+
uint8_t header[0x100];
- io_generic_read(io, header, 0, 0x100);
+ io.read(header, 0x100, actual);
- int header_size = header[3] * 0x100 + header[2];
- int track_count = header[8];
- int head_count = header[9];
+ int const header_size = header[3] * 0x100 + header[2];
+ int const track_count = header[8];
+ int const head_count = header[9];
- int file_offset = header_size;
+ if (io.seek(header_size, SEEK_SET))
+ return false;
for (int track = 0; track < track_count; track++)
{
@@ -72,10 +81,9 @@ bool vdk_format::load(io_generic *io, uint32_t form_factor, const std::vector<ui
sectors[i].bad_crc = false;
sectors[i].data = &sector_data[sector_offset];
- io_generic_read(io, sectors[i].data, file_offset, SECTOR_SIZE);
+ io.read(sectors[i].data, SECTOR_SIZE, actual);
sector_offset += SECTOR_SIZE;
- file_offset += SECTOR_SIZE;
}
build_wd_track_mfm(track, head, image, 100000, SECTOR_COUNT, sectors, 22, 32, 24);
@@ -85,9 +93,11 @@ bool vdk_format::load(io_generic *io, uint32_t form_factor, const std::vector<ui
return true;
}
-bool vdk_format::save(io_generic *io, const std::vector<uint32_t> &variants, floppy_image *image)
+bool vdk_format::save(util::random_read_write &io, const std::vector<uint32_t> &variants, floppy_image *image)
{
- uint64_t file_offset = 0;
+ size_t actual;
+ if (io.seek(0, SEEK_SET))
+ return false;
int track_count, head_count;
image->get_actual_geometry(track_count, head_count);
@@ -108,8 +118,7 @@ bool vdk_format::save(io_generic *io, const std::vector<uint32_t> &variants, flo
header[10] = 0;
header[11] = 0;
- io_generic_write(io, header, file_offset, sizeof(header));
- file_offset += sizeof(header);
+ io.write(header, sizeof(header), actual);
// write disk data
for (int track = 0; track < track_count; track++)
@@ -120,10 +129,7 @@ bool vdk_format::save(io_generic *io, const std::vector<uint32_t> &variants, flo
auto sectors = extract_sectors_from_bitstream_mfm_pc(bitstream);
for (int i = 0; i < SECTOR_COUNT; i++)
- {
- io_generic_write(io, sectors[FIRST_SECTOR_ID + i].data(), file_offset, SECTOR_SIZE);
- file_offset += SECTOR_SIZE;
- }
+ io.write(sectors[FIRST_SECTOR_ID + i].data(), SECTOR_SIZE, actual);
}
}
s='insertions'>+1 | * einstein: Major cleanup, add a ADC0844 device Dirk Best2017-11-061-0/+2 | | | | | | | | The analogue joystick is now emulated. Also fixed a few minor issues with the memory map. This also adds a generic Z80 dasisy chain device, for use in drivers with non-Z80 peripherals. * srcclean (nw) Vas Crabb2017-10-221-1/+1 | * Preliminary SH3 / SH4 recompiler [David Haywood] (#2711) David Haywood2017-10-111-3/+5 | * use 'sh' instead of 'superh' David Haywood2017-10-021-31/+31 | * move sh2 / sh4 to a folder called superh David Haywood2017-10-021-44/+32 | * Create explicit i386dasm include for x86 DRC (nw) AJR2017-08-011-1/+2 | * need this for debug trace logging on DRC cores (nw) Vas Crabb2017-08-011-1/+1 | * Fix single build for i386-based drivers (nw) AJR2017-07-311-1/+1 | * Begin of HP80 emulation (#2448) fulivi2017-07-081-0/+16 | | | | | | | | | | | | | | | | | What works: * HP85A machine with 16K of RAM * Capricorn CPU works * Keyboard works (with minor issues) * CRT text / graphics modes work (correct speed is not emulated yet so service ROM complaints) * BASIC is usable What is missing (and I'll have hopefully working soon): * HW timers * Beeper * Integral printer * DC100 cassette drive * Extension ROMs * I/O modules (especially the HPIB interface so that we can hook up floppy drives) * Other models in the family (e.g. HP86) * create c-chip device with correct CPU type in it and a bunch of notes ↵ David Haywood2017-07-051-0/+2 | | | | | | | | | (pinout etc.) create a uPD78C11 derived CPU type for this purpose, with internal ROM map use internal ROM map for other uPD78C10 chips as it's always present. add missing NO_DUMP definitions to various games using C-Chips with correct size etc. pump megablast through the device code as really all it ever does is bank the c-chip window and test the RAM. * Rewrote 4004 core and disassembler: