libmsx
C library for MSX
Loading...
Searching...
No Matches
memfile.h
Go to the documentation of this file.
1// -*- coding: utf-8-unix -*-
2/*
3 * Copyright (c) 2021-2025 Daishi Mori (mori0091)
4 *
5 * This software is released under the MIT License.\n
6 * See https://github.com/mori0091/libmsx/blob/main/LICENSE
7 *
8 * GitHub libmsx project\n
9 * https://github.com/mori0091/libmsx
10 */
27#ifndef MEMFILE_H_
28#define MEMFILE_H_
29
30#include <bmem.h>
31#include <stdbool.h>
32#include <stdint.h>
33
60#define MEM_SEEK_SET (0)
61
67#define MEM_SEEK_CUR (1)
68
74#define MEM_SEEK_END (2)
75
81typedef struct MemPos mempos_t;
82
88typedef struct MemFile MemFile;
89
98void mfopen_mem(MemFile * mf, uint8_t * p, size_t size);
99
111void mfopen_bmem(MemFile * mf, bmemptr_t p, uint32_t size);
112
121void mfslice(MemFile * dst, const MemFile * src, long size);
122
130bool mfeof(MemFile * mf);
131
139uint8_t mfread_u8(MemFile * mf);
140
150size_t mfread(MemFile * mf, void * ptr, size_t size);
151
159inline uint16_t mfread_u16(MemFile * mf) {
160 uint16_t x;
161 mfread(mf, &x, sizeof(x));
162 return x;
163}
164
172inline uint32_t mfread_u32(MemFile * mf) {
173 uint32_t x;
174 mfread(mf, &x, sizeof(x));
175 return x;
176}
177
189void mfseek(MemFile * mf, long offset, int whence);
190
198void mfgetpos(MemFile * mf, mempos_t * pos);
199
207void mfsetpos(MemFile * mf, const mempos_t * pos);
208
217void mfsetpos2(MemFile * mf, const mempos_t * base, long offset);
218
219
221
224#endif // MEMFILE_H_
Data types and functions for accessing banked memory.
uint32_t bmemptr_t
Type of an address of banked memory.
Definition bmem.h:75
bool mfeof(MemFile *mf)
Return true if reached to the end of stream.
void mfopen_mem(MemFile *mf, uint8_t *p, size_t size)
Open memory image in ROM/RAM as stream.
void mfopen_bmem(MemFile *mf, bmemptr_t p, uint32_t size)
Open memory image in banked memory (MegaROM) as stream.
void mfslice(MemFile *dst, const MemFile *src, long size)
Open a new stream with the specified size range from the current position.
size_t mfread(MemFile *mf, void *ptr, size_t size)
Read some bytes from stream pointed by mf.
uint8_t mfread_u8(MemFile *mf)
Read the next byte from stream pointed by mf.
uint16_t mfread_u16(MemFile *mf)
Read the next 16-bit of little-endian value from stream pointed by mf.
Definition memfile.h:159
uint32_t mfread_u32(MemFile *mf)
Read the next 32-bit of little-endian value from stream pointed by mf.
Definition memfile.h:172
void mfsetpos(MemFile *mf, const mempos_t *pos)
Set the stream position indicator of the stream pointed by mf.
void mfsetpos2(MemFile *mf, const mempos_t *base, long offset)
Set the stream position indicator of the stream pointed by mf.
void mfseek(MemFile *mf, long offset, int whence)
Set the stream position indicator for the stream pointed by mf.
void mfgetpos(MemFile *mf, mempos_t *pos)
Get the stream position indicator of the stream pointed by mf.
struct MemPos base
base position
Internal structure of MemFile type.
Internal structure of mempos_t type.