libElysianVMU 1.6.0
Full-featured, accurate, cross-platform library emulating the Dreamcast's Visual Memory Unit
Loading...
Searching...
No Matches
evmu_vmi.h
Go to the documentation of this file.
1/*! \file
2 * \ingroup file_formats
3 * \brief EvmuVmi: Decoding and encoding of the .VMI format
4 *
5 * This file contains the structure and API around
6 * managing and working with the .VMI file format,
7 * whose data is represented by the EvmuVmi structure.
8 *
9 * The .VMI format basically serves as a metadata file
10 * descriptor for .VMS files, and were used as the VMU
11 * file format with Dreamcast web browsers.
12 *
13 * A web browser would follow a link to the .VMI file,
14 * which would then point to a corresponding .VMS file,
15 * and the two together would provide enough information
16 * to load the file onto the VMU.
17 *
18 * \warning
19 * Because the .VMI file is only a metadata descriptor
20 * file, it is never standalone, as it has no real data
21 * payload of its own. It must have a corresponding VMS
22 * file.
23 *
24 * \note
25 * At the low level, the .VMI format is essentially
26 * providing the filesystem with the same information
27 * as an \ref EvmuDirEntry, such as the size of the
28 * corresponding file, its filesystem name, file type,
29 * copy protection mode, etc.
30 *
31 * \author 2023 Falco Girgis
32 * \copyright MIT License
33 *
34 * \sa evmu_vms.h
35 */
36#ifndef EVMU_VMI_H
37#define EVMU_VMI_H
38
39#include "evmu_fat.h"
40
41#include <gimbal/strings/gimbal_string_buffer.h>
42#include <gimbal/utils/gimbal_date_time.h>
43
44/*! \name Sizes and Limits
45 * \brief Sizes for EvmuVmi and its fields
46 * @{
47*/
48#define EVMU_VMI_FILE_SIZE 108 //!< Size of a .vmi file the EvmuVmi structure
49#define EVMU_VMI_DESCRIPTION_SIZE 32 //!< Size of the EvmuVmi::description field
50#define EVMU_VMI_COPYRIGHT_SIZE 32 //!< Size of the EvmuVmi::copyright field
51#define EVMU_VMI_VMS_RESOURCE_SIZE 8 //!< Size of the EvmuVmi::vmsResourceName field
52#define EVMU_VMI_VMS_NAME_SIZE 12 //!< Size of the EvmuVmi::fileNameOnVms field
53//! @}
54
55/*! \name File Mode Flags
56 * \brief Bit positions and masks for EvmuVmi::fileMode fields
57 * @{
58*/
59#define EVMU_VMI_GAME_POS 1 //!< Bit of the GAME flag within EvmuVmi::fileMode
60#define EVMU_VMI_GAME_MASK 0x2 //!< Mask of the GAME flag within EvmuVmi::fileMode
61#define EVMU_VMI_PROTECTED_POS 0 //!< Bit of the PROTECTED flag within EvmuVmi::fileMode
62#define EVMU_VMI_PROTECTED_MASK 0x1 //!< Mask of the PROTECTED flag within EvmuVmi::fileMode
63//! @}
64
65#define EVMU_VMI_VERSION 0 //!< Value of the EvmuVmi::vmiVersion field
66
67#define GBL_SELF_TYPE EvmuVmi
68
69GBL_DECLS_BEGIN
70
71GBL_FORWARD_DECLARE_STRUCT(EvmuVms);
72
73/*! Structure of the .VMI file format
74 * \ingroup file_formats
75 *
76 * EvmuVmi offers a structure and C API around
77 * the decoded .VMI file format.
78 *
79 * \note
80 * All string fields are in Shift-JS format and
81 * are NOT NULL-terminated, hence the accessor
82 * utility methods.
83 *
84 * \sa EvmuVms
85 */
86typedef struct EvmuVmi {
87 uint32_t checksum; //!< Checksum value for entire structure
88 char description[EVMU_VMI_DESCRIPTION_SIZE]; //!< Description of VMI file string
89 char copyright[EVMU_VMI_COPYRIGHT_SIZE]; //!< Copyright information string
90 EvmuTimestamp creationTimestamp; //!< File creation date
91 uint16_t vmiVersion; //!< VMI version of the file, see \ref EVMU_VMI_VERSION
92 uint16_t fileNumber; //!< File number in a series
93 char vmsResourceName[EVMU_VMI_VMS_RESOURCE_SIZE]; //!< File name of the corresponding VMS file, expected within the same directory
94 char fileNameOnVms[EVMU_VMI_VMS_NAME_SIZE]; //!< File name field within the .VMS file
95 uint16_t fileMode; //!< File mode bitfield (GAME bit + PROTECTED bit)
96 uint16_t unknown; //!< Unknown and undocumented (assumed to be 0)
97 uint32_t fileSize; //!< File size of VMS (in bytes?)
98} EvmuVmi;
99
100GBL_STATIC_ASSERT(sizeof(EvmuVmi) == EVMU_VMI_FILE_SIZE)
101
102/*! \name Read Accessors
103 * \brief Methods for reading/Calculating fields
104 * \relatesalso EvmuVmi
105 * @{
106 */
107//! Returns whether the VMI structure passes a series of validation/sanity checks on its fields
108EVMU_EXPORT GblBool EvmuVmi_isValid (GBL_CSELF) GBL_NOEXCEPT;
109//! Copies the EvmuVmi::description field to the given buffer
110EVMU_EXPORT const char* EvmuVmi_description (GBL_CSELF, GblStringBuffer* pBuff) GBL_NOEXCEPT;
111//! Copies the EvmuVmi::copyright field to the given buffer
112EVMU_EXPORT const char* EvmuVmi_copyright (GBL_CSELF, GblStringBuffer* pBuff) GBL_NOEXCEPT;
113//! Converts the EvmuVmi::creationTimestamp field to GblDateTime
114EVMU_EXPORT GblDateTime* EvmuVmi_creation (GBL_CSELF, GblDateTime* pDateTime) GBL_NOEXCEPT;
115//! Copies the EvmuVmi::vmsResourceName field to the given buffer
116EVMU_EXPORT const char* EvmuVmi_vmsResource (GBL_CSELF, GblStringBuffer* pBuff) GBL_NOEXCEPT;
117//! Copies the EvmuVmi::fileNameOnVms field to the given buffer
118EVMU_EXPORT const char* EvmuVmi_fileName (GBL_CSELF, GblStringBuffer* pbuff) GBL_NOEXCEPT;
119//! Returns whether the EvmuVmi::fileMode type field signifies a GAME file
120EVMU_EXPORT GblBool EvmuVmi_isGame (GBL_CSELF) GBL_NOEXCEPT;
121//! Returns whether the EvmuVmi::fileMode protected field signifies copy protection
122EVMU_EXPORT GblBool EvmuVmi_isProtected (GBL_CSELF) GBL_NOEXCEPT;
123//! Computes the checksum for the given VMI data
124EVMU_EXPORT uint32_t EvmuVmi_computeChecksum (GBL_CSELF) GBL_NOEXCEPT;
125//! @}
126
127/*! \name Write Accessors
128 * \brief Methods for writing to fields
129 * \relatesalso EvmuVmi
130 * @{
131 */
132//! Sets the EvmuVmi::description field to the given string, returning the number of bytes copied
133EVMU_EXPORT size_t EvmuVmi_setDescription (GBL_SELF, const char* pStr) GBL_NOEXCEPT;
134//! Sets the EvmuVmi::copyright field to the given string, returning the number of bytes copied
135EVMU_EXPORT size_t EvmuVmi_setCopyright (GBL_SELF, const char* pStr) GBL_NOEXCEPT;
136//! Sets the EvmuVmi::creationTimestamp field to the given GblDateTime value
137EVMU_EXPORT void EvmuVmi_setCreation (GBL_SELF, const GblDateTime* pDt) GBL_NOEXCEPT;
138//! Sets the EvmuVmi::vmsResourceName field to the given string, returning the number of bytes copied
139EVMU_EXPORT size_t EvmuVmi_setVmsResource (GBL_SELF, const char* pStr) GBL_NOEXCEPT;
140//! Sets the EvmuVmi::fileNameOnVms field to the given string, returning the number of bytes copied
141EVMU_EXPORT size_t EvmuVmi_setFileName (GBL_SELF, const char* pStr) GBL_NOEXCEPT;
142//! Sets the EvmuVmi::fileMode type field signifying whether or not file is a GAME
143EVMU_EXPORT void EvmiVmi_setGame (GBL_SELF, GblBool val) GBL_NOEXCEPT;
144//! Sets the EvmuVmi::fileMode protected filed to signify whether or not the file is copy protected
145EVMU_EXPORT void EvmuVmi_setProtected (GBL_SELF, GblBool val) GBL_NOEXCEPT;
146//! @}
147
148/*! \name Utilities
149 * \brief Miscellaneous methods
150 * \relatesalso EvmuVmi
151 * @{
152 */
153//! Populates the given structure by loading its contents from an external .VMI file
154EVMU_EXPORT EVMU_RESULT EvmuVmi_load (GBL_SELF, const char* pPath) GBL_NOEXCEPT;
155//! Writes the contens of the given structure to an external .VMI file
156EVMU_EXPORT EVMU_RESULT EvmuVmi_save (GBL_CSELF, const char* pPath) GBL_NOEXCEPT;
157//! Logs the fields of the VMI file to the libGimbal log system
158EVMU_EXPORT void EvmuVmi_log (GBL_CSELF) GBL_NOEXCEPT;
159//! @}
160
161/*! \name Conversions
162 * \brief Methods for going to and from EvmuVmi and related types
163 * \relatesalso EvmuVmi
164 * @{
165 */
166//! Populates the given structure from an EvmuDirEntry, also needing a pointer to EvmuFat and a VMS name
167EVMU_EXPORT EVMU_RESULT EvmuVmi_fromDirEntry (GBL_SELF,
168 const EvmuFat* pFat,
169 const EvmuDirEntry* pDirEntry,
170 const char* pVmsName) GBL_NOEXCEPT;
171//! Populates the given structure from a VMS image, needing to know whether it's a GAME file or not
172EVMU_EXPORT EVMU_RESULT EvmuVmi_fromVmsFile (GBL_SELF,
173 const void* pData,
174 size_t bytes) GBL_NOEXCEPT;
175//! Finds the path for the VMS file coresponding to the given VMI file
176EVMU_EXPORT const char* EvmuVmi_findVmsPath (GBL_CSELF,
177 const char* pVmiPath,
178 GblStringBuffer* pVmsPath) GBL_NOEXCEPT;
179//! @}
180
181GBL_DECLS_END
182
183#undef GBL_SELF_TYPE
184
185#endif // EVMU_VMI_H
#define EVMU_EXPORT
Define used for adding attributes to export public symbols.
Definition evmu_api.h:18
#define EVMU_VMI_FILE_SIZE
Size of a .vmi file the EvmuVmi structure.
Definition evmu_vmi.h:48
#define EVMU_VMI_VMS_NAME_SIZE
Definition evmu_vmi.h:52
#define EVMU_VMI_DESCRIPTION_SIZE
Size of the EvmuVmi::description field.
Definition evmu_vmi.h:49
#define EVMU_VMI_COPYRIGHT_SIZE
Size of the EvmuVmi::copyright field.
Definition evmu_vmi.h:50
#define EVMU_VMI_VMS_RESOURCE_SIZE
Size of the EvmuVmi::vmsResourceName field.
Definition evmu_vmi.h:51
uint8_t GblBool
Structure of the .VMI file format.
Definition evmu_vmi.h:86
const char * EvmuVmi_fileName(const EvmuVmi *pSelf, GblStringBuffer *pbuff)
Copies the EvmuVmi::fileNameOnVms field to the given buffer.
EVMU_RESULT EvmuVmi_fromVmsFile(EvmuVmi *pSelf, const void *pData, size_t bytes)
Populates the given structure from a VMS image, needing to know whether it's a GAME file or not.
uint32_t checksum
Checksum value for entire structure.
Definition evmu_vmi.h:87
size_t EvmuVmi_setVmsResource(EvmuVmi *pSelf, const char *pStr)
Sets the EvmuVmi::vmsResourceName field to the given string, returning the number of bytes copied.
GblBool EvmuVmi_isValid(const EvmuVmi *pSelf)
Returns whether the VMI structure passes a series of validation/sanity checks on its fields.
GblDateTime * EvmuVmi_creation(const EvmuVmi *pSelf, GblDateTime *pDateTime)
Converts the EvmuVmi::creationTimestamp field to GblDateTime.
EVMU_RESULT EvmuVmi_load(EvmuVmi *pSelf, const char *pPath)
Populates the given structure by loading its contents from an external .VMI file.
EvmuTimestamp creationTimestamp
File creation date.
Definition evmu_vmi.h:90
size_t EvmuVmi_setDescription(EvmuVmi *pSelf, const char *pStr)
Sets the EvmuVmi::description field to the given string, returning the number of bytes copied.
size_t EvmuVmi_setFileName(EvmuVmi *pSelf, const char *pStr)
Sets the EvmuVmi::fileNameOnVms field to the given string, returning the number of bytes copied.
GblBool EvmuVmi_isGame(const EvmuVmi *pSelf)
Returns whether the EvmuVmi::fileMode type field signifies a GAME file.
void EvmuVmi_setCreation(EvmuVmi *pSelf, const GblDateTime *pDt)
Sets the EvmuVmi::creationTimestamp field to the given GblDateTime value.
uint16_t vmiVersion
VMI version of the file, see EVMU_VMI_VERSION.
Definition evmu_vmi.h:91
char fileNameOnVms[12]
File name field within the .VMS file.
Definition evmu_vmi.h:94
uint16_t unknown
Unknown and undocumented (assumed to be 0)
Definition evmu_vmi.h:96
void EvmuVmi_log(const EvmuVmi *pSelf)
Logs the fields of the VMI file to the libGimbal log system.
EVMU_RESULT EvmuVmi_fromDirEntry(EvmuVmi *pSelf, const EvmuFat *pFat, const EvmuDirEntry *pDirEntry, const char *pVmsName)
Populates the given structure from an EvmuDirEntry, also needing a pointer to EvmuFat and a VMS name.
uint32_t EvmuVmi_computeChecksum(const EvmuVmi *pSelf)
Computes the checksum for the given VMI data.
GblBool EvmuVmi_isProtected(const EvmuVmi *pSelf)
Returns whether the EvmuVmi::fileMode protected field signifies copy protection.
uint16_t fileNumber
File number in a series.
Definition evmu_vmi.h:92
char description[32]
Description of VMI file string.
Definition evmu_vmi.h:88
void EvmuVmi_setProtected(EvmuVmi *pSelf, GblBool val)
Sets the EvmuVmi::fileMode protected filed to signify whether or not the file is copy protected.
const char * EvmuVmi_copyright(const EvmuVmi *pSelf, GblStringBuffer *pBuff)
Copies the EvmuVmi::copyright field to the given buffer.
size_t EvmuVmi_setCopyright(EvmuVmi *pSelf, const char *pStr)
Sets the EvmuVmi::copyright field to the given string, returning the number of bytes copied.
char vmsResourceName[8]
File name of the corresponding VMS file, expected within the same directory.
Definition evmu_vmi.h:93
uint32_t fileSize
File size of VMS (in bytes?)
Definition evmu_vmi.h:97
const char * EvmuVmi_vmsResource(const EvmuVmi *pSelf, GblStringBuffer *pBuff)
Copies the EvmuVmi::vmsResourceName field to the given buffer.
const char * EvmuVmi_findVmsPath(const EvmuVmi *pSelf, const char *pVmiPath, GblStringBuffer *pVmsPath)
Finds the path for the VMS file coresponding to the given VMI file.
char copyright[32]
Copyright information string.
Definition evmu_vmi.h:89
uint16_t fileMode
File mode bitfield (GAME bit + PROTECTED bit)
Definition evmu_vmi.h:95
const char * EvmuVmi_description(const EvmuVmi *pSelf, GblStringBuffer *pBuff)
Copies the EvmuVmi::description field to the given buffer.
EVMU_RESULT EvmuVmi_save(const EvmuVmi *pSelf, const char *pPath)
Writes the contens of the given structure to an external .VMI file.
void EvmiVmi_setGame(EvmuVmi *pSelf, GblBool val)
Sets the EvmuVmi::fileMode type field signifying whether or not file is a GAME.