mirror of
https://github.com/holub/mame
synced 2025-06-06 21:03:47 +03:00

[Aaron Giles] * these classes now no longer take a resource_pool; everything is managed globally -- this means that objects added to lists must be allocated with global_alloc * added new auto_pointer<> template which wraps a pointer and auto-frees it upon destruction; it also defaults to NULL so it doesn't need to be explicitly initialized * moved tagged_list template to tagmap.h Redo of the low-level memory tracking system: [Aaron Giles] * moved low-level tracking out of emu\emualloc into lib\util\corealloc so it can be shared among all components and used by core libraries * global_alloc and friends no longer use a resource pool to track allocations; turns out this was a wholly redundant system that wasted a lot of memory * removed global_resource_pool entirely * added global_free_array to delete arrays allocated with global_alloc_array * added tracking of object versus array allocation; we will now error if you use global_free on an array, or global_free_array on an object Added new utility helper const_string_pool which can be used to efficiently accumulate strings that are not intended to be modified. Used by updated makelist and software list code. [Aaron Giles] Updated png2bdc and makelist tools to not leak memory and use more modern techniques (no more MAX_DRIVERS in makelist, for example). [Aaron Giles] Deprecated auto_strdup and removed all uses by way of caller-managed astrings and the software list rewrite. [Aaron Giles] Rewrote software list management: [Aaron Giles] * removed the notion of a software_list that is separate from a software_list_device; they are one and the same now * moved several functions into device_image_interface since they really didn't belong in the core software list class * lots of simplification as a result of the above changes Additional notes (no whatsnew): Moved definition of FPTR to osdcomm.h. Some changes happened in the OSD code to fix issues, especially regarding freeing arrays. SDL folks may need to fix up some of these. The following devices still are using tokens and should be modernized (I found them because they kept their token as void * and tried to delete it, which you can't): namco_52xx_device (mame/audio/namco52.c) namco_54xx_device (mame/audio/namco54.c) namco_06xx_device (mame/machine/namco06.c) namco_50xx_device (mame/machine/namco50.c) namco_51xx_device (mame/machine/namco51.c) namco_53xx_device (mame/machine/namco53.c) voodoo_device (emu/video/voodoo.c) mos6581_device (emu/sound/mos6581.c) aica_device (emu/sound/aica.c) scsp_device (emu/sound/scsp.c) dmadac_sound_device (emu/sound/dmadac.c) s3c2440_device (emu/machine/s3c2440.c) wd1770_device (emu/machine/wd17xx.c) latch8_device (emu/machine/latch8.c) duart68681_device (emu/machine/68681.c) s3c2400_device (emu/machine/s3c2400.c) s3c2410_device (emu/machine/s3c2410.c) strataflash_device (mess/machine/strata.c) hd63450_device (mess/machine/hd63450.c) tap_990_device (mess/machine/ti99/990_tap.c) omti8621_device (mess/machine/omti8621.c) vdt911_device (mess/video/911_vdt.c) apollo_graphics_15i (mess/video/apollo.c) asr733_device (mess/video/733_asr.c)
171 lines
4.7 KiB
C++
171 lines
4.7 KiB
C++
// license:BSD-3-Clause
|
|
// copyright-holders:Aaron Giles
|
|
/***************************************************************************
|
|
|
|
fileio.h
|
|
|
|
Core file I/O interface functions and definitions.
|
|
|
|
***************************************************************************/
|
|
|
|
#pragma once
|
|
|
|
#ifndef __FILEIO_H__
|
|
#define __FILEIO_H__
|
|
|
|
#include "corefile.h"
|
|
#include "hash.h"
|
|
|
|
// some systems use macros for getc/putc rather than functions
|
|
#ifdef getc
|
|
#undef getc
|
|
#endif
|
|
|
|
//**************************************************************************
|
|
// TYPE DEFINITIONS
|
|
//**************************************************************************
|
|
|
|
// forward declarations
|
|
struct zip_file_header;
|
|
struct zip_file;
|
|
|
|
struct _7z_file_header;
|
|
struct _7z_file;
|
|
|
|
// ======================> path_iterator
|
|
|
|
// helper class for iterating over configured paths
|
|
class path_iterator
|
|
{
|
|
public:
|
|
// construction/destruction
|
|
path_iterator(const char *searchpath);
|
|
|
|
// getters
|
|
bool next(astring &buffer, const char *name = NULL);
|
|
|
|
// reset
|
|
void reset() { m_current = m_base; m_index = 0; }
|
|
|
|
private:
|
|
// internal state
|
|
const char * m_base;
|
|
const char * m_current;
|
|
int m_index;
|
|
};
|
|
|
|
|
|
|
|
// ======================> file_enumerator
|
|
|
|
// iterate over all files in all paths specified in the searchpath
|
|
class file_enumerator
|
|
{
|
|
public:
|
|
// construction/destruction
|
|
file_enumerator(const char *searchpath);
|
|
~file_enumerator();
|
|
|
|
// iterator
|
|
const osd_directory_entry *next();
|
|
|
|
private:
|
|
// internal state
|
|
path_iterator m_iterator;
|
|
osd_directory * m_curdir;
|
|
astring m_pathbuffer;
|
|
//int m_buflen;
|
|
};
|
|
|
|
|
|
|
|
// ======================> emu_file
|
|
|
|
class emu_file
|
|
{
|
|
public:
|
|
// file open/creation
|
|
emu_file(UINT32 openflags);
|
|
emu_file(const char *searchpath, UINT32 openflags);
|
|
virtual ~emu_file();
|
|
|
|
// getters
|
|
operator core_file *();
|
|
operator core_file &();
|
|
bool is_open() const { return (m_file != NULL); }
|
|
const char *filename() const { return m_filename; }
|
|
const char *fullpath() const { return m_fullpath; }
|
|
UINT32 openflags() const { return m_openflags; }
|
|
hash_collection &hashes(const char *types);
|
|
|
|
// setters
|
|
void remove_on_close() { m_remove_on_close = true; }
|
|
void set_openflags(UINT32 openflags) { assert(m_file == NULL); m_openflags = openflags; }
|
|
|
|
// open/close
|
|
file_error open(const char *name);
|
|
file_error open(const char *name1, const char *name2);
|
|
file_error open(const char *name1, const char *name2, const char *name3);
|
|
file_error open(const char *name1, const char *name2, const char *name3, const char *name4);
|
|
file_error open(const char *name, UINT32 crc);
|
|
file_error open(const char *name1, const char *name2, UINT32 crc);
|
|
file_error open(const char *name1, const char *name2, const char *name3, UINT32 crc);
|
|
file_error open(const char *name1, const char *name2, const char *name3, const char *name4, UINT32 crc);
|
|
file_error open_next();
|
|
file_error open_ram(const void *data, UINT32 length);
|
|
void close();
|
|
|
|
// control
|
|
file_error compress(int compress);
|
|
int seek(INT64 offset, int whence);
|
|
UINT64 tell();
|
|
bool eof();
|
|
UINT64 size();
|
|
|
|
// reading
|
|
UINT32 read(void *buffer, UINT32 length);
|
|
int getc();
|
|
int ungetc(int c);
|
|
char *gets(char *s, int n);
|
|
|
|
// writing
|
|
UINT32 write(const void *buffer, UINT32 length);
|
|
int puts(const char *s);
|
|
int vprintf(const char *fmt, va_list va);
|
|
int printf(const char *fmt, ...) ATTR_PRINTF(2,3);
|
|
|
|
private:
|
|
bool compressed_file_ready(void);
|
|
|
|
// internal helpers
|
|
file_error attempt_zipped();
|
|
file_error load_zipped_file();
|
|
bool zip_filename_match(const zip_file_header &header, const astring &filename);
|
|
bool zip_header_is_path(const zip_file_header &header);
|
|
|
|
file_error attempt__7zped();
|
|
file_error load__7zped_file();
|
|
|
|
// internal state
|
|
astring m_filename; // original filename provided
|
|
astring m_fullpath; // full filename
|
|
core_file * m_file; // core file pointer
|
|
path_iterator m_iterator; // iterator for paths
|
|
UINT32 m_crc; // iterator for paths
|
|
UINT32 m_openflags; // flags we used for the open
|
|
hash_collection m_hashes; // collection of hashes
|
|
|
|
zip_file * m_zipfile; // ZIP file pointer
|
|
dynamic_buffer m_zipdata; // ZIP file data
|
|
UINT64 m_ziplength; // ZIP file length
|
|
|
|
_7z_file * m__7zfile; // 7Z file pointer
|
|
dynamic_buffer m__7zdata; // 7Z file data
|
|
UINT64 m__7zlength; // 7Z file length
|
|
|
|
bool m_remove_on_close; // flag: remove the file when closing
|
|
};
|
|
|
|
|
|
#endif /* __FILEIO_H__ */
|