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-2024 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 */
26#ifndef MEMFILE_H_
27#define MEMFILE_H_
28
29#include <bmem.h>
30#include <stdbool.h>
31#include <stdint.h>
32
59#define MEM_SEEK_SET (0)
60
66#define MEM_SEEK_CUR (1)
67
73#define MEM_SEEK_END (2)
74
80typedef struct MemPos mempos_t;
81
87typedef struct MemFile MemFile;
88
97void mfopen_mem(MemFile * mf, uint8_t * p, size_t size);
98
110void mfopen_bmem(MemFile * mf, bmemptr_t p, uint32_t size);
111
120void mfslice(MemFile * dst, const MemFile * src, long size);
121
129bool mfeof(MemFile * mf);
130
138uint8_t mfread_u8(MemFile * mf);
139
149size_t mfread(MemFile * mf, void * ptr, size_t size);
150
158inline uint16_t mfread_u16(MemFile * mf) {
159 uint16_t x;
160 mfread(mf, &x, sizeof(x));
161 return x;
162}
163
171inline uint32_t mfread_u32(MemFile * mf) {
172 uint32_t x;
173 mfread(mf, &x, sizeof(x));
174 return x;
175}
176
188void mfseek(MemFile * mf, long offset, int whence);
189
197void mfgetpos(MemFile * mf, mempos_t * pos);
198
206void mfsetpos(MemFile * mf, const mempos_t * pos);
207
216void mfsetpos2(MemFile * mf, const mempos_t * base, long offset);
217
218
220
223#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:74
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:158
uint32_t mfread_u32(MemFile *mf)
Read the next 32-bit of little-endian value from stream pointed by mf.
Definition memfile.h:171
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.