From 6029b563e2f8510780a18b360c1637fa19811fc1 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Wed, 24 Sep 2025 02:19:12 +0100 Subject: [PATCH] Add skeleton for writable cdrom image file. --- src/cdrom/CMakeLists.txt | 1 + src/cdrom/cdrom_image_writable.c | 197 +++++++++++++++++++++++ src/include/86box/cdrom_image_writable.h | 34 ++++ 3 files changed, 232 insertions(+) create mode 100644 src/cdrom/cdrom_image_writable.c create mode 100644 src/include/86box/cdrom_image_writable.h diff --git a/src/cdrom/CMakeLists.txt b/src/cdrom/CMakeLists.txt index 6208111de..17aeb6a8c 100644 --- a/src/cdrom/CMakeLists.txt +++ b/src/cdrom/CMakeLists.txt @@ -24,6 +24,7 @@ add_library(cdrom OBJECT cdrom_image.c cdrom_image_viso.c cdrom_mke.c + cdrom_image_writable.c ) if(NOT WIN32) target_include_directories(86Box PRIVATE PkgConfig::SNDFILE) diff --git a/src/cdrom/cdrom_image_writable.c b/src/cdrom/cdrom_image_writable.c new file mode 100644 index 000000000..cad79c727 --- /dev/null +++ b/src/cdrom/cdrom_image_writable.c @@ -0,0 +1,197 @@ +/* + * 86Box A hypervisor and IBM PC system emulator that specializes in + * running old operating systems and software designed for IBM + * PC systems and compatibles from 1981 through fairly recent + * system designs based on the PCI bus. + * + * This file is part of the 86Box distribution. + * + * CD-R(W) writable image file handling module. + * + * Authors: Nat Portillo, + * + * Copyright 2025 Nat Portillo. + */ + +#define __STDC_FORMAT_MACROS +#include +#include + +#ifdef ENABLE_IMAGE_LOG +#include +#endif +#include +#include +#include +#include +#include +#include <86box/log.h> +#include <86box/cdrom.h> +#include <86box/cdrom_image_writable.h> + +#include + +#define MAX_LINE_LENGTH 512 +#define MAX_FILENAME_LENGTH 256 +#define CROSS_LEN 512 + +static char temp_keyword[1024]; + +typedef struct track_index_t { + int64_t start; + uint64_t length; + uint64_t file_start; + uint64_t file_length; + track_file_t *file; +} track_index_t; + +typedef struct track_t { + uint8_t session; + uint8_t attr; + uint8_t tno; + uint8_t point; + uint8_t extra[4]; + uint8_t mode; + uint8_t form; + uint8_t subch_type; + uint8_t skip; + uint8_t max_index; + uint32_t sector_size; + track_index_t idx[100]; +} track_t; + +typedef struct cd_image_t { + cdrom_t *dev; + void *log; + int has_audio; + int32_t tracks_num; + track_t *tracks; +} cd_image_t; + +#ifdef ENABLE_IMAGE_LOG +int image_do_log = ENABLE_IMAGE_LOG; + +void +image_log(void *priv, const char *fmt, ...) +{ + va_list ap; + + if (image_do_log) { + va_start(ap, fmt); + log_out(priv, fmt, ap); + va_end(ap); + } +} + +static char *cit[4] = { "SPECIAL", "NONE", "ZERO", "NORMAL" }; +#else +# define image_log(priv, fmt, ...) +#endif + + +static int +wimage_get_track_info(const void *local, const uint32_t track, + const int end, track_info_t *ti) +{ + // TODO: Not implemented + + return -1; +} + +static void +wimage_get_raw_track_info(const void *local, int *num, uint8_t *buffer) +{ + // TODO: Not implemented +} + +static int +wimage_is_track_pre(const void *local, const uint32_t sector) +{ + // TODO: Not implemented + + return -1; +} + +static int +wimage_read_sector(const void *local, uint8_t *buffer, + const uint32_t sector) +{ + // TODO: Not implemented + + return -1; +} + +static uint8_t +wimage_get_track_type(const void *local, const uint32_t sector) +{ + // TODO: Not implemented + + return 0; +} + +static uint32_t +wimage_get_last_block(const void *local) +{ + // TODO: Not implemented + + return 0; +} + +static int +wimage_read_dvd_structure(const void *local, const uint8_t layer, const uint8_t format, + uint8_t *buffer, uint32_t *info) +{ + // TODO: Not implemented + + return -1; +} + +static int +wimage_is_dvd(const void *local) +{ + // TODO: Not implemented + + return 0; +} + +static int +wimage_has_audio(const void *local) +{ + // TODO: Not implemented + + return 0; +} + +static void +wimage_close(void *local) +{ + // TODO: Not implemented +} + +static const cdrom_ops_t image_ops = { + wimage_get_track_info, + wimage_get_raw_track_info, + wimage_is_track_pre, + wimage_read_sector, + wimage_get_track_type, + wimage_get_last_block, + wimage_read_dvd_structure, + wimage_is_dvd, + wimage_has_audio, + NULL, + wimage_close, + NULL +}; + +/* Public functions. */ +void * +wimage_open(cdrom_t *dev, const char *path) +{ + cd_image_t *img = (cd_image_t *) calloc(1, sizeof(cd_image_t)); + + dev->ops = &image_ops; + + // TODO: Not implemented + + return img; +} \ No newline at end of file diff --git a/src/include/86box/cdrom_image_writable.h b/src/include/86box/cdrom_image_writable.h new file mode 100644 index 000000000..63a49b2f7 --- /dev/null +++ b/src/include/86box/cdrom_image_writable.h @@ -0,0 +1,34 @@ +/* + * 86Box A hypervisor and IBM PC system emulator that specializes in + * running old operating systems and software designed for IBM + * PC systems and compatibles from 1981 through fairly recent + * system designs based on the PCI bus. + * + * This file is part of the 86Box distribution. + * + * CD-R(W) writable image file handling module. + * + * Authors: Nat Portillo, + * + * Copyright 2025 Nat Portillo. + */ +#ifndef CDROM_IMAGE_WRITABLE_H +#define CDROM_IMAGE_WRITABLE_H + +/* Track file struct. */ +typedef struct track_file_t { + int (*read)(void *priv, uint8_t *buffer, uint64_t seek, size_t count); + uint64_t (*get_length)(void *priv); + void (*close)(void *priv); + + char fn[260]; + FILE *fp; + void *priv; + void *log; + + int motorola; +} track_file_t; + +extern void *wimage_open(cdrom_t *dev, const char *path); + +#endif /*CDROM_IMAGE_WRITABLE_H*/