libElysianVMU 1.6.0
Full-featured, accurate, cross-platform library emulating the Dreamcast's Visual Memory Unit
Loading...
Searching...
No Matches
evmu_vms.h
Go to the documentation of this file.
1/*! \file
2 * \ingroup file_formats
3 * \brief EvmuVms: Decoding and encoding of the .VMS format
4 *
5 * This file contains the structure and API around managing
6 * and working with the .VMS file format, whose header is
7 * represented by the EvmuVms structure.
8 *
9 * \warning
10 * When distributing a .VMS file, there should almost
11 * ALWAYS be a corresponding .VMI file providing its metadata
12 * information to Web Browsers and the filesystem. While EVMU
13 * can load GAME .VMS files without a corresponding .VMI file,
14 * this is not something typically supported. Make sure you have
15 * one if you choose to distribute a ROM file!
16 *
17 * \author 2023 Falco Girgis
18 * \copyright MIT License
19 *
20 * \sa evmu_vmi.h
21 */
22#ifndef EVMU_VMS_H
23#define EVMU_VMS_H
24
25#include "evmu_fat.h"
26
27#include <gimbal/strings/gimbal_string_buffer.h>
28#include <gimbal/utils/gimbal_byte_array.h>
29
30/*! \name Sizes and Limits
31 * \brief Sizes for EvmuVms and its fields
32 * @{
33*/
34#define EVMU_VMS_SIZE 128 //!< Size of the VMS header and EvmuVms structure
35#define EVMU_VMS_VMU_DESCRIPTION_SIZE 16 //!< Size of the EvmuVms::vmuDesc field
36#define EVMU_VMS_DC_DESCRIPTION_SIZE 32 //!< Size of the EvmuVms::dcDesc field
37#define EVMU_VMS_CREATOR_APP_SIZE 16 //!< Size of the EvmuVms::creatorApp field
38#define EVMU_VMS_RESERVED_SIZE 20 //!< Size of the EvmuVms::reserved field
39//! @}
40
41/*! \name Palette Colors
42 * \brief RGBA Bitfields for icon pallette color format
43 * @{
44*/
45#define EVMU_VMS_ICON_PALETTE_BLUE_POS 0 //!< Bit positon of the blue color channel within an EvmuVms::palette entry
46#define EVMU_VMS_ICON_PALETTE_BLUE_MASK 0x000f //!< Bit mask of the blue color channel within an EvmuVms::palette entry
47#define EVMU_VMS_ICON_PALETTE_GREEN_POS 4 //!< Bit position of the green color channel within an EvmuVms::palette entry
48#define EVMU_VMS_ICON_PALETTE_GREEN_MASK 0x00f0 //!< Bit mask of the green color channel within an EvmuVms::palette entry
49#define EVMU_VMS_ICON_PALETTE_RED_POS 8 //!< Bit position of the red color channel within an EvmuVms::palette entry
50#define EVMU_VMS_ICON_PALETTE_RED_MASK 0x0f00 //!< Bit mask of the red color channel within an EvmuVms::palette entry
51#define EVMU_VMS_ICON_PALETTE_ALPHA_POS 12 //!< Bit position of the alpha color channel within an EvmuVms::palette entry
52#define EVMU_VMS_ICON_PALETTE_ALPHA_MASK 0xf000 //!< Bit mask of the alpha color channel withiin an EvmuVms::palette entry
53//! @}
54
55/*! \name Icons
56 * \brief Sizes and static info for VMS icons
57 * @{
58*/
59#define EVMU_VMS_ICON_COUNT_MAX 3 //!< Maximum number of icons within a VMS file
60#define EVMU_VMS_ICON_PALETTE_SIZE 16 //!< Number of entries within a VMS icon palette
61#define EVMU_VMS_ICON_BITMAP_WIDTH 32 //!< Width of a VMS icon
62#define EVMU_VMS_ICON_BITMAP_HEIGHT 32 //!< Height of a VMS icon
63#define EVMU_VMS_ICON_BITMAP_SIZE 512 //!< Size of a single icon in bytes
64//! @}
65
66/*! \name Eyecatch
67 * \brief Sizes and static info for VMS eyecatches
68 * @{
69*/
70#define EVMU_VMS_EYECATCH_BITMAP_WIDTH 72 //!< Width of a VMS eyecatch
71#define EVMU_VMS_EYECATCH_BITMAP_HEIGHT 56 //!< Height of a VMS eyecatch
72#define EVMU_VMS_EYECATCH_PALETTE_SIZE_COLOR_256 512 //!< Palette size of a VMS eyecatch using 256 color mode
73#define EVMU_VMS_EYECATCH_PALETTE_SIZE_COLOR_16 32 //!< Palette size of a VMS eyecatch using 16 color mode
74#define EVMU_VMS_EYECATCH_BITMAP_SIZE_COLOR_16BIT 8064 //!< Size of a VMS eyecatch using 16-bit colors
75#define EVMU_VMS_EYECATCH_BITMAP_SIZE_COLOR_256 4032 //!< Size of a VMS eyecatch using a 256-color palette
76#define EVMU_VMS_EYECATCH_BITMAP_SIZE_COLOR_16 2016 //!< Size of a VMS eyecatch using a 16-color palette
77//! @}
78
79#define GBL_SELF_TYPE EvmuVms
80
81GBL_DECLS_BEGIN
82
83//! Types of different eyecatch formats
86 EVMU_VMS_EYECATCH_16BIT, //!< 16-bit Color
87 EVMU_VMS_EYECATCH_PALETTE_256, //!< 256-Entry Palleted
88 EVMU_VMS_EYECATCH_PALETTE_16, //!< 16-Entry Palleted
89 EVMU_VMS_EYECATCH_COUNT //!< Number of Formats
90} EVMU_VMS_EYECATCH_TYPE;
91
92/*! Structure of the .VMS file header
93 * \ingroup file_formats
94 *
95 * EvmuVms offers a struct and object-oriented API
96 * around the .VMS file format. This strucure only
97 * represents the header; however, the API expects
98 * that there is additional data beyond this header.
99 *
100 * \note
101 * Strings are JIS X 0201 encocded (included within
102 * Shift-JIS), and are not NULL-terminateed (hence
103 * the accessor methods).
104 *
105 * \sa EvmuVmi
106 */
107typedef struct EvmuVms {
108 char vmuDesc[EVMU_VMS_VMU_DESCRIPTION_SIZE]; //!< File description in VMU BIOS
109 char dcDesc[EVMU_VMS_DC_DESCRIPTION_SIZE]; //!< File description in DC BIOS
110 char creatorApp[EVMU_VMS_CREATOR_APP_SIZE]; //!< App used to create VMS file
111 uint16_t iconCount; //!< Number of icons in animation
112 uint16_t animSpeed; //!< Number of frames to wait before advancing icon animation
113 uint16_t eyecatchType; //!< Type of eyecatch graphic
114 uint16_t crc; //!< CRC for whole file
115 uint32_t dataBytes; //!< Size of actual file data, without header, icons, and eyecatch (ignored for GAME files)
116 char reserved[EVMU_VMS_RESERVED_SIZE]; //!< Reserved/unknown. Set to 0.
117 uint16_t palette[EVMU_VMS_ICON_PALETTE_SIZE]; //!< Palette color entries
118} EvmuVms;
119
120/*! \name Read Accessors
121 * \brief Reading/calculating fields
122 * \relatesalso EvmuVms
123 * @{
124*/
125//! Determine whether the given VMS header appears sane based on expected field values
126EVMU_EXPORT GblBool EvmuVms_isValid (GBL_CSELF) GBL_NOEXCEPT;
127//! Returns the number of bytes of the VMS header, including graphics
128EVMU_EXPORT size_t EvmuVms_headerBytes (GBL_CSELF) GBL_NOEXCEPT;
129//! Retruns the total calculated size of the VMS file, including header, icons, and eyecatch
130EVMU_EXPORT size_t EvmuVms_totalBytes (GBL_CSELF) GBL_NOEXCEPT;
131//! Computes the expected CRC for the entire VMS file
132EVMU_EXPORT uint16_t EvmuVms_computeCrc (GBL_CSELF) GBL_NOEXCEPT;
133//! Returns a pointer to the raw icon image data for the given \p index
134EVMU_EXPORT const void* EvmuVms_icon (GBL_CSELF, size_t index) GBL_NOEXCEPT;
135//! Returns a pointer to the raw eyecatch image data
136EVMU_EXPORT const void* EvmuVms_eyecatch (GBL_CSELF) GBL_NOEXCEPT;
137//! Copies EvmuVms::vmuDesc to the given buffer
138EVMU_EXPORT const char* EvmuVms_vmuDescription (GBL_CSELF,
139 GblStringBuffer* pBuffer) GBL_NOEXCEPT;
140//! Copies EvmuVms::dcDesc to the given buffer
141EVMU_EXPORT const char* EvmuVms_dcDescription (GBL_CSELF,
142 GblStringBuffer* pBuffer) GBL_NOEXCEPT;
143//! Copies EvmuVms::creatorApp to the given buffer
144EVMU_EXPORT const char* EvmuVms_creatorApp (GBL_CSELF,
145 GblStringBuffer* pBuffer) GBL_NOEXCEPT;
146//! Returns a string representation of the EvmuVms::eyecatchType
147EVMU_EXPORT const char* EvmuVms_eyecatchTypeStr (GBL_CSELF) GBL_NOEXCEPT;
148//! Attempts to autodetect the type of file represented by the VMS, usually for when no VMI is present
149EVMU_EXPORT EVMU_FILE_TYPE EvmuVms_guessFileType (GBL_CSELF) GBL_NOEXCEPT;
150//! @}
151
152/*! \name Write Accessors
153 * \brief Writing to fields
154 * \relatesalso EvmuVms
155 * @{
156*/
157//! Sets the EvmuVms::vmuDesc field to the given string, returning the number of bytes copied
158EVMU_EXPORT size_t EvmuVms_setVmuDescription (GBL_SELF, const char* pStr) GBL_NOEXCEPT;
159//! Sets the EvmuVms::dcDesc field to the given string, returning the number of bytes copied
160EVMU_EXPORT size_t EvmuVms_setDcDescription (GBL_SELF, const char* pStr) GBL_NOEXCEPT;
161//! Sets the EvmuVms::creatorApp field to the given string, returning the number of bytes copied
162EVMU_EXPORT size_t EvmuVms_setCreatorApp (GBL_SELF, const char* pStr) GBL_NOEXCEPT;
163//! @}
164
165/*! \name Utilities
166 * \brief Miscellaneous methods
167 * \relatesalso EvmuVms
168 * @{
169*/
170//! Logs the properties of the VMS file to the libGimbal log system
171EVMU_EXPORT void EvmuVms_log (GBL_CSELF) GBL_NOEXCEPT;
172//! Creates a GblRingList of GblByteArray instances containing ARGB444-encoded bitmaps for each icon
173EVMU_EXPORT GblRingList* EvmuVms_createIconsArgb4444 (GBL_CSELF) GBL_NOEXCEPT;
174//! Creates a GblByteArray containing an ARG444 encoded bitmap for the eyecatch
175EVMU_EXPORT GblByteArray* EvmuVms_createEyecatchArgb4444 (GBL_CSELF) GBL_NOEXCEPT;
176//! Tries to find a valid path for the VMI file corresponding to the given VMS file, returning the path or NULL if not found
177EVMU_EXPORT const char* EvmuVms_findVmiPath (const char* pPath,
178 GblStringBuffer* pBuffer) GBL_NOEXCEPT;
179//! @}
180
181GBL_DECLS_END
182
183#undef GBL_SELF_TYPE
184
185#endif // EVMU_VMS_H
#define EVMU_EXPORT
Define used for adding attributes to export public symbols.
Definition evmu_api.h:18
#define EVMU_VMS_RESERVED_SIZE
Definition evmu_vms.h:38
#define EVMU_VMS_ICON_PALETTE_SIZE
Number of entries within a VMS icon palette.
Definition evmu_vms.h:60
#define EVMU_VMS_VMU_DESCRIPTION_SIZE
Size of the EvmuVms::vmuDesc field.
Definition evmu_vms.h:35
EVMU_VMS_EYECATCH_TYPE
Types of different eyecatch formats.
Definition evmu_vms.h:84
@ EVMU_VMS_EYECATCH_COUNT
Number of Formats.
Definition evmu_vms.h:89
@ EVMU_VMS_EYECATCH_PALETTE_16
16-Entry Palleted
Definition evmu_vms.h:88
@ EVMU_VMS_EYECATCH_16BIT
16-bit Color
Definition evmu_vms.h:86
@ EVMU_VMS_EYECATCH_PALETTE_256
256-Entry Palleted
Definition evmu_vms.h:87
@ EVMU_VMS_EYECATCH_NONE
None.
Definition evmu_vms.h:85
#define EVMU_VMS_DC_DESCRIPTION_SIZE
Size of the EvmuVms::dcDesc field.
Definition evmu_vms.h:36
#define EVMU_VMS_CREATOR_APP_SIZE
Size of the EvmuVms::creatorApp field.
Definition evmu_vms.h:37
uint8_t GblBool
Structure of the .VMS file header.
Definition evmu_vms.h:107
const char * EvmuVms_creatorApp(const EvmuVms *pSelf, GblStringBuffer *pBuffer)
Copies EvmuVms::creatorApp to the given buffer.
uint16_t animSpeed
Number of frames to wait before advancing icon animation.
Definition evmu_vms.h:112
char dcDesc[32]
File description in DC BIOS.
Definition evmu_vms.h:109
const char * EvmuVms_eyecatchTypeStr(const EvmuVms *pSelf)
Returns a string representation of the EvmuVms::eyecatchType.
uint16_t crc
CRC for whole file.
Definition evmu_vms.h:114
EVMU_FILE_TYPE EvmuVms_guessFileType(const EvmuVms *pSelf)
Attempts to autodetect the type of file represented by the VMS, usually for when no VMI is present.
GblByteArray * EvmuVms_createEyecatchArgb4444(const EvmuVms *pSelf)
Creates a GblByteArray containing an ARG444 encoded bitmap for the eyecatch.
uint32_t dataBytes
Size of actual file data, without header, icons, and eyecatch (ignored for GAME files)
Definition evmu_vms.h:115
uint16_t iconCount
Number of icons in animation.
Definition evmu_vms.h:111
uint16_t palette[16]
Palette color entries.
Definition evmu_vms.h:117
const void * EvmuVms_icon(const EvmuVms *pSelf, size_t index)
Returns a pointer to the raw icon image data for the given index.
size_t EvmuVms_setVmuDescription(EvmuVms *pSelf, const char *pStr)
Sets the EvmuVms::vmuDesc field to the given string, returning the number of bytes copied.
const void * EvmuVms_eyecatch(const EvmuVms *pSelf)
Returns a pointer to the raw eyecatch image data.
char reserved[20]
Reserved/unknown.
Definition evmu_vms.h:116
GblRingList * EvmuVms_createIconsArgb4444(const EvmuVms *pSelf)
Creates a GblRingList of GblByteArray instances containing ARGB444-encoded bitmaps for each icon.
size_t EvmuVms_totalBytes(const EvmuVms *pSelf)
Retruns the total calculated size of the VMS file, including header, icons, and eyecatch.
uint16_t eyecatchType
Type of eyecatch graphic.
Definition evmu_vms.h:113
char creatorApp[16]
App used to create VMS file.
Definition evmu_vms.h:110
const char * EvmuVms_findVmiPath(const char *pPath, GblStringBuffer *pBuffer)
Tries to find a valid path for the VMI file corresponding to the given VMS file, returning the path o...
size_t EvmuVms_setDcDescription(EvmuVms *pSelf, const char *pStr)
Sets the EvmuVms::dcDesc field to the given string, returning the number of bytes copied.
void EvmuVms_log(const EvmuVms *pSelf)
Logs the properties of the VMS file to the libGimbal log system.
size_t EvmuVms_setCreatorApp(EvmuVms *pSelf, const char *pStr)
Sets the EvmuVms::creatorApp field to the given string, returning the number of bytes copied.
uint16_t EvmuVms_computeCrc(const EvmuVms *pSelf)
Computes the expected CRC for the entire VMS file.
size_t EvmuVms_headerBytes(const EvmuVms *pSelf)
Returns the number of bytes of the VMS header, including graphics.
const char * EvmuVms_dcDescription(const EvmuVms *pSelf, GblStringBuffer *pBuffer)
Copies EvmuVms::dcDesc to the given buffer.
GblBool EvmuVms_isValid(const EvmuVms *pSelf)
Determine whether the given VMS header appears sane based on expected field values.
char vmuDesc[16]
File description in VMU BIOS.
Definition evmu_vms.h:108
const char * EvmuVms_vmuDescription(const EvmuVms *pSelf, GblStringBuffer *pBuffer)
Copies EvmuVms::vmuDesc to the given buffer.