2010-08-09 13:28:56 +00:00
|
|
|
#ifndef NALL_FILE_HPP
|
|
|
|
#define NALL_FILE_HPP
|
|
|
|
|
2011-06-05 03:45:04 +00:00
|
|
|
#include <nall/platform.hpp>
|
2010-08-09 13:28:56 +00:00
|
|
|
#include <nall/stdint.hpp>
|
|
|
|
#include <nall/string.hpp>
|
|
|
|
#include <nall/utility.hpp>
|
2011-08-06 14:03:52 +00:00
|
|
|
#include <nall/windows/utf8.hpp>
|
Update to v088r03 release.
byuu says:
static vector<uint8_t> file::read(const string &filename); replaces:
static bool file::read(const string &filename, uint8_t *&data, unsigned
&size); This allows automatic deletion of the underlying data.
Added vectorstream, which is obviously a vector<uint8_t> wrapper for
a data stream. Plan is for all data accesses inside my emulation cores
to take stream objects, especially MSU1. This lets you feed the core
anything: memorystream, filestream, zipstream, gzipstream, httpstream,
etc. There will still be exceptions for link and serial, those need
actual library files on disk. But those aren't official hardware devices
anyway.
So to help with speed a bit, I'm rethinking the video rendering path.
Previous system:
- core outputs system-native samples (SNES = 19-bit LRGB, NES = 9-bit
emphasis+palette, DMG = 2-bit grayscale, etc.)
- interfaceSystem transforms samples to 30-bit via lookup table inside
the emulation core
- interfaceSystem masks off overscan areas, if enabled
- interfaceUI runs filter to produce new target buffer, if enabled
- interfaceUI transforms 30-bit video to native display depth (24-bit or
30-bit), and applies color-adjustments (gamma, etc) at the same time
New system:
- all cores now generate an internal palette, and call
Interface::videoColor(uint32_t source, uint16_t red, uint16_t green,
uint16_t blue) to get native display color post-adjusted (gamma, etc
applied already.)
- all cores output to uint32_t* buffer now (output video.palette[color]
instead of just color)
- interfaceUI runs filter to produce new target buffer, if enabled
- interfaceUI memcpy()'s buffer to the video card
videoColor() is pretty neat. source is the raw pixel (as per the
old-format, 19-bit SNES, 9-bit NES, etc), and you can create a color
from that if you really want to. Or return that value to get a buffer
just like v088 and below. red, green, blue are 16-bits per channel,
because why the hell not, right? Just lop off all the bits you don't
want. If you have more bits on your display than that, fuck you :P
The last step is extremely difficult to avoid. Video cards can and do
have pitches that differ from the width of the texture. Trying to make
the core account for this would be really awful. And even if we did
that, the emulation routine would need to write directly to a video card
RAM buffer. Some APIs require you to lock the video buffer while
writing, so this would leave the video buffer locked for a long time.
Probably not catastrophic, but still awful. And lastly, if the
emulation core tried writing directly to the display texture, software
filters would no longer be possible (unless you -really- jump through
hooks and divert to a memory buffer when a filter is enabled, but ...
fuck.)
Anyway, the point of all that work was to eliminate an extra video copy,
and the need for a really painful 30-bit to 24-bit conversion (three
shifts, three masks, three array indexes.) So this basically reverts us,
performance-wise, to where we were pre-30 bit support.
[...]
The downside to this is that we're going to need a filter for each
output depth. Since the array type is uint32_t*, and I don't intend to
support higher or lower depths, we really only need 24+30-bit versions
of each filter. Kinda shitty, but oh well.
2012-04-27 12:12:53 +00:00
|
|
|
#include <nall/stream/memory.hpp>
|
2010-08-09 13:28:56 +00:00
|
|
|
|
|
|
|
namespace nall {
|
2011-07-23 10:14:47 +00:00
|
|
|
inline FILE* fopen_utf8(const string &utf8_filename, const char *mode) {
|
2010-08-09 13:28:56 +00:00
|
|
|
#if !defined(_WIN32)
|
|
|
|
return fopen(utf8_filename, mode);
|
|
|
|
#else
|
|
|
|
return _wfopen(utf16_t(utf8_filename), utf16_t(mode));
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
Update to v088r03 release.
byuu says:
static vector<uint8_t> file::read(const string &filename); replaces:
static bool file::read(const string &filename, uint8_t *&data, unsigned
&size); This allows automatic deletion of the underlying data.
Added vectorstream, which is obviously a vector<uint8_t> wrapper for
a data stream. Plan is for all data accesses inside my emulation cores
to take stream objects, especially MSU1. This lets you feed the core
anything: memorystream, filestream, zipstream, gzipstream, httpstream,
etc. There will still be exceptions for link and serial, those need
actual library files on disk. But those aren't official hardware devices
anyway.
So to help with speed a bit, I'm rethinking the video rendering path.
Previous system:
- core outputs system-native samples (SNES = 19-bit LRGB, NES = 9-bit
emphasis+palette, DMG = 2-bit grayscale, etc.)
- interfaceSystem transforms samples to 30-bit via lookup table inside
the emulation core
- interfaceSystem masks off overscan areas, if enabled
- interfaceUI runs filter to produce new target buffer, if enabled
- interfaceUI transforms 30-bit video to native display depth (24-bit or
30-bit), and applies color-adjustments (gamma, etc) at the same time
New system:
- all cores now generate an internal palette, and call
Interface::videoColor(uint32_t source, uint16_t red, uint16_t green,
uint16_t blue) to get native display color post-adjusted (gamma, etc
applied already.)
- all cores output to uint32_t* buffer now (output video.palette[color]
instead of just color)
- interfaceUI runs filter to produce new target buffer, if enabled
- interfaceUI memcpy()'s buffer to the video card
videoColor() is pretty neat. source is the raw pixel (as per the
old-format, 19-bit SNES, 9-bit NES, etc), and you can create a color
from that if you really want to. Or return that value to get a buffer
just like v088 and below. red, green, blue are 16-bits per channel,
because why the hell not, right? Just lop off all the bits you don't
want. If you have more bits on your display than that, fuck you :P
The last step is extremely difficult to avoid. Video cards can and do
have pitches that differ from the width of the texture. Trying to make
the core account for this would be really awful. And even if we did
that, the emulation routine would need to write directly to a video card
RAM buffer. Some APIs require you to lock the video buffer while
writing, so this would leave the video buffer locked for a long time.
Probably not catastrophic, but still awful. And lastly, if the
emulation core tried writing directly to the display texture, software
filters would no longer be possible (unless you -really- jump through
hooks and divert to a memory buffer when a filter is enabled, but ...
fuck.)
Anyway, the point of all that work was to eliminate an extra video copy,
and the need for a really painful 30-bit to 24-bit conversion (three
shifts, three masks, three array indexes.) So this basically reverts us,
performance-wise, to where we were pre-30 bit support.
[...]
The downside to this is that we're going to need a filter for each
output depth. Since the array type is uint32_t*, and I don't intend to
support higher or lower depths, we really only need 24+30-bit versions
of each filter. Kinda shitty, but oh well.
2012-04-27 12:12:53 +00:00
|
|
|
struct file {
|
2012-06-25 12:49:39 +00:00
|
|
|
enum class mode : unsigned { read, write, modify, append, readwrite = modify, writeread = append };
|
2010-10-14 10:07:38 +00:00
|
|
|
enum class index : unsigned { absolute, relative };
|
2011-06-05 03:45:04 +00:00
|
|
|
enum class time : unsigned { create, modify, access };
|
2010-08-09 13:28:56 +00:00
|
|
|
|
2012-06-25 12:49:39 +00:00
|
|
|
static bool copy(const string &sourcename, const string &targetname) {
|
|
|
|
file rd, wr;
|
|
|
|
if(rd.open(sourcename, mode::read) == false) return false;
|
|
|
|
if(wr.open(targetname, mode::write) == false) return false;
|
|
|
|
for(unsigned n = 0; n < rd.size(); n++) wr.write(rd.read());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool move(const string &sourcename, const string &targetname) {
|
|
|
|
#if !defined(_WIN32)
|
|
|
|
return rename(sourcename, targetname) == 0;
|
|
|
|
#else
|
|
|
|
return _wrename(utf16_t(sourcename), utf16_t(targetname)) == 0;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
Update to v088r14 release.
byuu says:
Changelog:
- added NSS DIP switch settings window (when loading NSS carts with
appropriate manifest.xml file)
- added video shader selection (they go in ~/.config/bsnes/Video
Shaders/ now)
- added driver selection
- added timing settings (not only allows video/audio settings, also has
code to dynamically compute the values for you ... and it actually
works pretty good!)
- moved "None" controller device to bottom of list (it is the least
likely to be used, after all)
- added Interface::path() to support MSU1, USART, Link
- input and hotkey mappings remember list position after assignment
- and more!
target-ethos now has all of the functionality of target-ui, and more.
Final code size for the port is 101.2KB (ethos) vs 167.6KB (ui).
A ~67% reduction in code size, yet it does even more! And you can add or
remove an entire system with only three lines of code (Makefile include,
header include, interface append.)
The only problem left is that the BS-X BIOS won't load the BS Zelda no
Densetsu file.
I can't figure out why it's not working, would appreciate any
assistance, but otherwise I'm probably just going to leave it broken for
v089, sorry.
So the show stoppers for a new release at this point are:
- fix laevateinn to compile with the new interface changes (shouldn't be
too hard, it'll still use the old, direct interface.)
- clean up Emulator::Interface as much as possible (trim down
Information, mediaRequest should use an alternate struct designed to
load firmware / slots separately)
- enhance purify to strip SNES ROM headers, and it really needs a GUI
interface
- it would be highly desirable to make a launcher that can create
a cartridge folder from an existing ROM set (* ethos will need to
accept command-line arguments for this.)
- probably need to remember which controller was selected in each port
for each system across runs
- need to fix the cursor for Super Scope / Justifier games (move from
19-bit to 32-bit colors broke it)
- have to refactor that cache.(hv)offset thing to fix ASP
2012-05-06 23:27:42 +00:00
|
|
|
static bool remove(const string &filename) {
|
|
|
|
return unlink(filename) == 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool truncate(const string &filename, unsigned size) {
|
|
|
|
#if !defined(_WIN32)
|
|
|
|
return truncate(filename, size) == 0;
|
|
|
|
#else
|
|
|
|
bool result = false;
|
|
|
|
FILE *fp = fopen(filename, "rb+");
|
|
|
|
if(fp) {
|
|
|
|
result = _chsize(fileno(fp), size) == 0;
|
|
|
|
fclose(fp);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
Update to v088r03 release.
byuu says:
static vector<uint8_t> file::read(const string &filename); replaces:
static bool file::read(const string &filename, uint8_t *&data, unsigned
&size); This allows automatic deletion of the underlying data.
Added vectorstream, which is obviously a vector<uint8_t> wrapper for
a data stream. Plan is for all data accesses inside my emulation cores
to take stream objects, especially MSU1. This lets you feed the core
anything: memorystream, filestream, zipstream, gzipstream, httpstream,
etc. There will still be exceptions for link and serial, those need
actual library files on disk. But those aren't official hardware devices
anyway.
So to help with speed a bit, I'm rethinking the video rendering path.
Previous system:
- core outputs system-native samples (SNES = 19-bit LRGB, NES = 9-bit
emphasis+palette, DMG = 2-bit grayscale, etc.)
- interfaceSystem transforms samples to 30-bit via lookup table inside
the emulation core
- interfaceSystem masks off overscan areas, if enabled
- interfaceUI runs filter to produce new target buffer, if enabled
- interfaceUI transforms 30-bit video to native display depth (24-bit or
30-bit), and applies color-adjustments (gamma, etc) at the same time
New system:
- all cores now generate an internal palette, and call
Interface::videoColor(uint32_t source, uint16_t red, uint16_t green,
uint16_t blue) to get native display color post-adjusted (gamma, etc
applied already.)
- all cores output to uint32_t* buffer now (output video.palette[color]
instead of just color)
- interfaceUI runs filter to produce new target buffer, if enabled
- interfaceUI memcpy()'s buffer to the video card
videoColor() is pretty neat. source is the raw pixel (as per the
old-format, 19-bit SNES, 9-bit NES, etc), and you can create a color
from that if you really want to. Or return that value to get a buffer
just like v088 and below. red, green, blue are 16-bits per channel,
because why the hell not, right? Just lop off all the bits you don't
want. If you have more bits on your display than that, fuck you :P
The last step is extremely difficult to avoid. Video cards can and do
have pitches that differ from the width of the texture. Trying to make
the core account for this would be really awful. And even if we did
that, the emulation routine would need to write directly to a video card
RAM buffer. Some APIs require you to lock the video buffer while
writing, so this would leave the video buffer locked for a long time.
Probably not catastrophic, but still awful. And lastly, if the
emulation core tried writing directly to the display texture, software
filters would no longer be possible (unless you -really- jump through
hooks and divert to a memory buffer when a filter is enabled, but ...
fuck.)
Anyway, the point of all that work was to eliminate an extra video copy,
and the need for a really painful 30-bit to 24-bit conversion (three
shifts, three masks, three array indexes.) So this basically reverts us,
performance-wise, to where we were pre-30 bit support.
[...]
The downside to this is that we're going to need a filter for each
output depth. Since the array type is uint32_t*, and I don't intend to
support higher or lower depths, we really only need 24+30-bit versions
of each filter. Kinda shitty, but oh well.
2012-04-27 12:12:53 +00:00
|
|
|
static vector<uint8_t> read(const string &filename) {
|
|
|
|
vector<uint8_t> memory;
|
2011-08-06 14:03:52 +00:00
|
|
|
file fp;
|
Update to v088r03 release.
byuu says:
static vector<uint8_t> file::read(const string &filename); replaces:
static bool file::read(const string &filename, uint8_t *&data, unsigned
&size); This allows automatic deletion of the underlying data.
Added vectorstream, which is obviously a vector<uint8_t> wrapper for
a data stream. Plan is for all data accesses inside my emulation cores
to take stream objects, especially MSU1. This lets you feed the core
anything: memorystream, filestream, zipstream, gzipstream, httpstream,
etc. There will still be exceptions for link and serial, those need
actual library files on disk. But those aren't official hardware devices
anyway.
So to help with speed a bit, I'm rethinking the video rendering path.
Previous system:
- core outputs system-native samples (SNES = 19-bit LRGB, NES = 9-bit
emphasis+palette, DMG = 2-bit grayscale, etc.)
- interfaceSystem transforms samples to 30-bit via lookup table inside
the emulation core
- interfaceSystem masks off overscan areas, if enabled
- interfaceUI runs filter to produce new target buffer, if enabled
- interfaceUI transforms 30-bit video to native display depth (24-bit or
30-bit), and applies color-adjustments (gamma, etc) at the same time
New system:
- all cores now generate an internal palette, and call
Interface::videoColor(uint32_t source, uint16_t red, uint16_t green,
uint16_t blue) to get native display color post-adjusted (gamma, etc
applied already.)
- all cores output to uint32_t* buffer now (output video.palette[color]
instead of just color)
- interfaceUI runs filter to produce new target buffer, if enabled
- interfaceUI memcpy()'s buffer to the video card
videoColor() is pretty neat. source is the raw pixel (as per the
old-format, 19-bit SNES, 9-bit NES, etc), and you can create a color
from that if you really want to. Or return that value to get a buffer
just like v088 and below. red, green, blue are 16-bits per channel,
because why the hell not, right? Just lop off all the bits you don't
want. If you have more bits on your display than that, fuck you :P
The last step is extremely difficult to avoid. Video cards can and do
have pitches that differ from the width of the texture. Trying to make
the core account for this would be really awful. And even if we did
that, the emulation routine would need to write directly to a video card
RAM buffer. Some APIs require you to lock the video buffer while
writing, so this would leave the video buffer locked for a long time.
Probably not catastrophic, but still awful. And lastly, if the
emulation core tried writing directly to the display texture, software
filters would no longer be possible (unless you -really- jump through
hooks and divert to a memory buffer when a filter is enabled, but ...
fuck.)
Anyway, the point of all that work was to eliminate an extra video copy,
and the need for a really painful 30-bit to 24-bit conversion (three
shifts, three masks, three array indexes.) So this basically reverts us,
performance-wise, to where we were pre-30 bit support.
[...]
The downside to this is that we're going to need a filter for each
output depth. Since the array type is uint32_t*, and I don't intend to
support higher or lower depths, we really only need 24+30-bit versions
of each filter. Kinda shitty, but oh well.
2012-04-27 12:12:53 +00:00
|
|
|
if(fp.open(filename, mode::read)) {
|
|
|
|
memory.resize(fp.size());
|
|
|
|
fp.read(memory.data(), memory.size());
|
|
|
|
}
|
|
|
|
return memory;
|
2011-08-14 10:34:11 +00:00
|
|
|
}
|
|
|
|
|
2012-07-15 09:47:35 +00:00
|
|
|
static bool read(const string &filename, uint8_t *data, unsigned size) {
|
|
|
|
file fp;
|
|
|
|
if(fp.open(filename, mode::read) == false) return false;
|
|
|
|
fp.read(data, size);
|
|
|
|
fp.close();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
Update to v091r05 release.
[No prior releases were posted to the WIP thread. -Ed.]
byuu says:
Super Famicom mapping system has been reworked as discussed with the
mask= changes. offset becomes base, mode is gone. Also added support for
comma-separated fields in the address fields, to reduce the number of
map lines needed.
<?xml version="1.0" encoding="UTF-8"?>
<cartridge region="NTSC">
<superfx revision="2">
<rom name="program.rom" size="0x200000"/>
<ram name="save.rwm" size="0x8000"/>
<map id="io" address="00-3f,80-bf:3000-32ff"/>
<map id="rom" address="00-3f:8000-ffff" mask="0x8000"/>
<map id="rom" address="40-5f:0000-ffff"/>
<map id="ram" address="00-3f,80-bf:6000-7fff" size="0x2000"/>
<map id="ram" address="70-71:0000-ffff"/>
</superfx>
</cartridge>
Or in BML:
cartridge region=NTSC
superfx revision=2
rom name=program.rom size=0x200000
ram name=save.rwm size=0x8000
map id=io address=00-3f,80-bf:3000-32ff
map id=rom address=00-3f:8000-ffff mask=0x8000
map id=rom address=40-5f:0000-ffff
map id=ram address=00-3f,80-bf:6000-7fff size=0x2000
map id=ram address=70-71:0000-ffff
As a result of the changes, old mappings will no longer work. The above
XML example will run Super Mario World 2: Yoshi's Island. Otherwise,
you'll have to write your own.
All that's left now is to work some sort of database mapping system in,
so I can start dumping carts en masse.
The NES changes that FitzRoy asked for are mostly in as well.
Also, part of the reason I haven't released a WIP ... but fuck it, I'm
not going to wait forever to post a new WIP.
I've added a skeleton driver to emulate Campus Challenge '92 and
Powerfest '94. There's no actual emulation, except for the stuff I can
glean from looking at the pictures of the board. It has a DSP-1 (so
SR/DR registers), four ROMs that map in and out, RAM, etc.
I've also added preliminary mapping to upload high scores to a website,
but obviously I need the ROMs first.
2012-10-09 08:25:32 +00:00
|
|
|
static bool write(const string &filename, const vector<uint8_t> &buffer) {
|
|
|
|
file fp;
|
|
|
|
if(fp.open(filename, mode::write) == false) return false;
|
|
|
|
fp.write(buffer.data(), buffer.size());
|
|
|
|
fp.close();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-08-06 14:03:52 +00:00
|
|
|
static bool write(const string &filename, const uint8_t *data, unsigned size) {
|
|
|
|
file fp;
|
|
|
|
if(fp.open(filename, mode::write) == false) return false;
|
|
|
|
fp.write(data, size);
|
|
|
|
fp.close();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
Update to v091r06 release.
byuu says:
This release adds initial database support.
The way it works is you can now load game folders as you always have, or
you can load a game file. If you load a game file, it tries to create
a game folder for you by looking up the file's sha256 in a database. If
it can't find it, sorry, the game won't play. I'm not hooking up the
oldschool "make up a manifest" code here. The easiest way to handle this
is to get me every game so I can dump it and add it to the database :D
The database entries are complete entries that can be copied directly.
So it describes the board, the information, file layout, etc. That'll be
what comes with higan releases in the future.
Internally, I'm separating the information and board descriptions, and
will use a tool to merge the two together.
Here's a current database copy, with one game in it. Still hammering out
some details, but it's mostly how it's going to look.
cartridge region=NTSC
board type=1CB5B-20
superfx revision=2
rom name=program.rom size=0x200000
ram name=save.rwm size=0x8000
map id=io address=00-3f,80-bf:3000-32ff
map id=rom address=00-3f:8000-ffff mask=0x8000
map id=rom address=40-5f:0000-ffff
map id=ram address=00-3f,80-bf:6000-7fff size=0x2000
map id=ram address=70-71:0000-ffff
information
name: Super Mario World 2 - Yoshi's Island (SNS) (1.1)
title: Super Mario World 2: Yoshi's Island
sha256: bd763c1a56365c244be92e6cffefd318780a2a19eda7d5baf1c6d5bd6c1b3e06
board: SHVC-1CB5B-20
rom: 0x200000
ram: 0x8000
layout
file name=program.rom size=0x200000
2012-10-13 09:26:19 +00:00
|
|
|
static string sha256(const string &filename) {
|
|
|
|
auto buffer = read(filename);
|
|
|
|
return nall::sha256(buffer.data(), buffer.size());
|
|
|
|
}
|
|
|
|
|
2010-08-09 13:28:56 +00:00
|
|
|
uint8_t read() {
|
|
|
|
if(!fp) return 0xff; //file not open
|
2010-10-14 10:07:38 +00:00
|
|
|
if(file_mode == mode::write) return 0xff; //reads not permitted
|
2010-08-09 13:28:56 +00:00
|
|
|
if(file_offset >= file_size) return 0xff; //cannot read past end of file
|
|
|
|
buffer_sync();
|
|
|
|
return buffer[(file_offset++) & buffer_mask];
|
|
|
|
}
|
|
|
|
|
|
|
|
uintmax_t readl(unsigned length = 1) {
|
|
|
|
uintmax_t data = 0;
|
|
|
|
for(int i = 0; i < length; i++) {
|
|
|
|
data |= (uintmax_t)read() << (i << 3);
|
|
|
|
}
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
|
|
|
uintmax_t readm(unsigned length = 1) {
|
|
|
|
uintmax_t data = 0;
|
|
|
|
while(length--) {
|
|
|
|
data <<= 8;
|
|
|
|
data |= read();
|
|
|
|
}
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
|
|
|
void read(uint8_t *buffer, unsigned length) {
|
|
|
|
while(length--) *buffer++ = read();
|
|
|
|
}
|
|
|
|
|
|
|
|
void write(uint8_t data) {
|
2010-10-14 10:07:38 +00:00
|
|
|
if(!fp) return; //file not open
|
|
|
|
if(file_mode == mode::read) return; //writes not permitted
|
2010-08-09 13:28:56 +00:00
|
|
|
buffer_sync();
|
|
|
|
buffer[(file_offset++) & buffer_mask] = data;
|
|
|
|
buffer_dirty = true;
|
|
|
|
if(file_offset > file_size) file_size = file_offset;
|
|
|
|
}
|
|
|
|
|
|
|
|
void writel(uintmax_t data, unsigned length = 1) {
|
|
|
|
while(length--) {
|
|
|
|
write(data);
|
|
|
|
data >>= 8;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void writem(uintmax_t data, unsigned length = 1) {
|
|
|
|
for(int i = length - 1; i >= 0; i--) {
|
|
|
|
write(data >> (i << 3));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void write(const uint8_t *buffer, unsigned length) {
|
|
|
|
while(length--) write(*buffer++);
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename... Args> void print(Args... args) {
|
|
|
|
string data(args...);
|
|
|
|
const char *p = data;
|
|
|
|
while(*p) write(*p++);
|
|
|
|
}
|
|
|
|
|
|
|
|
void flush() {
|
|
|
|
buffer_flush();
|
|
|
|
fflush(fp);
|
|
|
|
}
|
|
|
|
|
2010-10-14 10:07:38 +00:00
|
|
|
void seek(int offset, index index_ = index::absolute) {
|
2010-08-09 13:28:56 +00:00
|
|
|
if(!fp) return; //file not open
|
|
|
|
buffer_flush();
|
|
|
|
|
|
|
|
uintmax_t req_offset = file_offset;
|
2010-10-14 10:07:38 +00:00
|
|
|
switch(index_) {
|
|
|
|
case index::absolute: req_offset = offset; break;
|
|
|
|
case index::relative: req_offset += offset; break;
|
2010-08-09 13:28:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if(req_offset < 0) req_offset = 0; //cannot seek before start of file
|
|
|
|
if(req_offset > file_size) {
|
2010-10-14 10:07:38 +00:00
|
|
|
if(file_mode == mode::read) { //cannot seek past end of file
|
2010-08-09 13:28:56 +00:00
|
|
|
req_offset = file_size;
|
|
|
|
} else { //pad file to requested location
|
|
|
|
file_offset = file_size;
|
|
|
|
while(file_size < req_offset) write(0x00);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
file_offset = req_offset;
|
|
|
|
}
|
|
|
|
|
Update to v088r10 release.
byuu says:
ethos is going to be absolutely amazing. You guys are in for a treat :D
I'm impressing the hell out of myself with how well-structured this code
is, it's allowing me to do amazing new things.
Just a small sampling of what's in store (and already implemented):
The file browser will display folders as "[ folder name ]", and
cartridge folders as "Game Name" (no extension, no /) [icons would be
nicer, but well ... phoenix.]
Folders are sorted above cartridge folders.
Cartridge folders for other systems do not show up in the list.
Not only are unique paths stored for each image type, your position in
the list is saved across runs.
Some voodoo was added to GTK+ so that all targets even scroll directly
to that item when you open the list. Load->System->Enter restarts your
last game.
That sounds really simple and obvious, but it makes an -incredible-
difference. Didn't realize it until I tried an implementation of it,
wow.
The input mapping list now lets you bind as many hotkeys as you want to
any given input.
So SFC::Port1::Joypad::B = Keyboard::Z or Joypad::Button1 ... no need to
remap everything to switch between keyboard and joypad. Either one
activates the key.
There is a separate Hotkeys tab now. This should hopefully end the
confusion about how to remap hotkeys that users experience.
Hotkeys are different, too. Instead of OR logic, they use AND logic.
So Fullscreen = Keyboard::Alt and Keyboard::Enter. Both must be pressed
to enter the key. This lets you easily implement "super" modifier keys.
The actual codebase has new features the old UI never had, and has about
~50% of the old functionality (so far, of course), yet is only ~25% as
much code.
The entire GUI no longer needs to pull in all the headers for each
emulated system. It just needs a small interface header file.
Then bind the entire system with exactly **two** lines of code.
Everything is dynamically generated for you after that.
2012-04-30 23:43:23 +00:00
|
|
|
unsigned offset() const {
|
|
|
|
if(!fp) return 0; //file not open
|
2010-08-09 13:28:56 +00:00
|
|
|
return file_offset;
|
|
|
|
}
|
|
|
|
|
Update to v088r10 release.
byuu says:
ethos is going to be absolutely amazing. You guys are in for a treat :D
I'm impressing the hell out of myself with how well-structured this code
is, it's allowing me to do amazing new things.
Just a small sampling of what's in store (and already implemented):
The file browser will display folders as "[ folder name ]", and
cartridge folders as "Game Name" (no extension, no /) [icons would be
nicer, but well ... phoenix.]
Folders are sorted above cartridge folders.
Cartridge folders for other systems do not show up in the list.
Not only are unique paths stored for each image type, your position in
the list is saved across runs.
Some voodoo was added to GTK+ so that all targets even scroll directly
to that item when you open the list. Load->System->Enter restarts your
last game.
That sounds really simple and obvious, but it makes an -incredible-
difference. Didn't realize it until I tried an implementation of it,
wow.
The input mapping list now lets you bind as many hotkeys as you want to
any given input.
So SFC::Port1::Joypad::B = Keyboard::Z or Joypad::Button1 ... no need to
remap everything to switch between keyboard and joypad. Either one
activates the key.
There is a separate Hotkeys tab now. This should hopefully end the
confusion about how to remap hotkeys that users experience.
Hotkeys are different, too. Instead of OR logic, they use AND logic.
So Fullscreen = Keyboard::Alt and Keyboard::Enter. Both must be pressed
to enter the key. This lets you easily implement "super" modifier keys.
The actual codebase has new features the old UI never had, and has about
~50% of the old functionality (so far, of course), yet is only ~25% as
much code.
The entire GUI no longer needs to pull in all the headers for each
emulated system. It just needs a small interface header file.
Then bind the entire system with exactly **two** lines of code.
Everything is dynamically generated for you after that.
2012-04-30 23:43:23 +00:00
|
|
|
unsigned size() const {
|
|
|
|
if(!fp) return 0; //file not open
|
2010-08-09 13:28:56 +00:00
|
|
|
return file_size;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool truncate(unsigned size) {
|
|
|
|
if(!fp) return false; //file not open
|
|
|
|
#if !defined(_WIN32)
|
|
|
|
return ftruncate(fileno(fp), size) == 0;
|
|
|
|
#else
|
|
|
|
return _chsize(fileno(fp), size) == 0;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
bool end() {
|
|
|
|
if(!fp) return true; //file not open
|
|
|
|
return file_offset >= file_size;
|
|
|
|
}
|
|
|
|
|
2011-07-23 10:14:47 +00:00
|
|
|
static bool exists(const string &filename) {
|
2010-08-09 13:28:56 +00:00
|
|
|
#if !defined(_WIN32)
|
2011-06-05 03:45:04 +00:00
|
|
|
struct stat64 data;
|
|
|
|
return stat64(filename, &data) == 0;
|
2010-08-09 13:28:56 +00:00
|
|
|
#else
|
2011-06-05 03:45:04 +00:00
|
|
|
struct __stat64 data;
|
|
|
|
return _wstat64(utf16_t(filename), &data) == 0;
|
2010-08-09 13:28:56 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2011-07-23 10:14:47 +00:00
|
|
|
static uintmax_t size(const string &filename) {
|
2011-06-05 03:45:04 +00:00
|
|
|
#if !defined(_WIN32)
|
|
|
|
struct stat64 data;
|
|
|
|
stat64(filename, &data);
|
|
|
|
#else
|
|
|
|
struct __stat64 data;
|
|
|
|
_wstat64(utf16_t(filename), &data);
|
|
|
|
#endif
|
|
|
|
return S_ISREG(data.st_mode) ? data.st_size : 0u;
|
|
|
|
}
|
|
|
|
|
2011-07-23 10:14:47 +00:00
|
|
|
static time_t timestamp(const string &filename, file::time mode = file::time::create) {
|
2010-08-09 13:28:56 +00:00
|
|
|
#if !defined(_WIN32)
|
2011-06-05 03:45:04 +00:00
|
|
|
struct stat64 data;
|
|
|
|
stat64(filename, &data);
|
2010-08-09 13:28:56 +00:00
|
|
|
#else
|
2011-06-05 03:45:04 +00:00
|
|
|
struct __stat64 data;
|
|
|
|
_wstat64(utf16_t(filename), &data);
|
2010-08-09 13:28:56 +00:00
|
|
|
#endif
|
2011-06-05 03:45:04 +00:00
|
|
|
switch(mode) { default:
|
|
|
|
case file::time::create: return data.st_ctime;
|
|
|
|
case file::time::modify: return data.st_mtime;
|
|
|
|
case file::time::access: return data.st_atime;
|
2010-08-09 13:28:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-15 08:29:57 +00:00
|
|
|
bool open() const {
|
2010-08-09 13:28:56 +00:00
|
|
|
return fp;
|
|
|
|
}
|
|
|
|
|
2011-07-23 10:14:47 +00:00
|
|
|
bool open(const string &filename, mode mode_) {
|
2010-08-09 13:28:56 +00:00
|
|
|
if(fp) return false;
|
|
|
|
|
2010-10-14 10:07:38 +00:00
|
|
|
switch(file_mode = mode_) {
|
2010-08-09 13:28:56 +00:00
|
|
|
#if !defined(_WIN32)
|
2011-06-05 03:45:04 +00:00
|
|
|
case mode::read: fp = fopen(filename, "rb" ); break;
|
|
|
|
case mode::write: fp = fopen(filename, "wb+"); break; //need read permission for buffering
|
|
|
|
case mode::readwrite: fp = fopen(filename, "rb+"); break;
|
|
|
|
case mode::writeread: fp = fopen(filename, "wb+"); break;
|
2010-08-09 13:28:56 +00:00
|
|
|
#else
|
2011-06-05 03:45:04 +00:00
|
|
|
case mode::read: fp = _wfopen(utf16_t(filename), L"rb" ); break;
|
|
|
|
case mode::write: fp = _wfopen(utf16_t(filename), L"wb+"); break;
|
|
|
|
case mode::readwrite: fp = _wfopen(utf16_t(filename), L"rb+"); break;
|
|
|
|
case mode::writeread: fp = _wfopen(utf16_t(filename), L"wb+"); break;
|
2010-08-09 13:28:56 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
if(!fp) return false;
|
|
|
|
buffer_offset = -1; //invalidate buffer
|
|
|
|
file_offset = 0;
|
|
|
|
fseek(fp, 0, SEEK_END);
|
|
|
|
file_size = ftell(fp);
|
|
|
|
fseek(fp, 0, SEEK_SET);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void close() {
|
|
|
|
if(!fp) return;
|
|
|
|
buffer_flush();
|
|
|
|
fclose(fp);
|
|
|
|
fp = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
file() {
|
|
|
|
memset(buffer, 0, sizeof buffer);
|
Update to v088r10 release.
byuu says:
ethos is going to be absolutely amazing. You guys are in for a treat :D
I'm impressing the hell out of myself with how well-structured this code
is, it's allowing me to do amazing new things.
Just a small sampling of what's in store (and already implemented):
The file browser will display folders as "[ folder name ]", and
cartridge folders as "Game Name" (no extension, no /) [icons would be
nicer, but well ... phoenix.]
Folders are sorted above cartridge folders.
Cartridge folders for other systems do not show up in the list.
Not only are unique paths stored for each image type, your position in
the list is saved across runs.
Some voodoo was added to GTK+ so that all targets even scroll directly
to that item when you open the list. Load->System->Enter restarts your
last game.
That sounds really simple and obvious, but it makes an -incredible-
difference. Didn't realize it until I tried an implementation of it,
wow.
The input mapping list now lets you bind as many hotkeys as you want to
any given input.
So SFC::Port1::Joypad::B = Keyboard::Z or Joypad::Button1 ... no need to
remap everything to switch between keyboard and joypad. Either one
activates the key.
There is a separate Hotkeys tab now. This should hopefully end the
confusion about how to remap hotkeys that users experience.
Hotkeys are different, too. Instead of OR logic, they use AND logic.
So Fullscreen = Keyboard::Alt and Keyboard::Enter. Both must be pressed
to enter the key. This lets you easily implement "super" modifier keys.
The actual codebase has new features the old UI never had, and has about
~50% of the old functionality (so far, of course), yet is only ~25% as
much code.
The entire GUI no longer needs to pull in all the headers for each
emulated system. It just needs a small interface header file.
Then bind the entire system with exactly **two** lines of code.
Everything is dynamically generated for you after that.
2012-04-30 23:43:23 +00:00
|
|
|
buffer_offset = -1; //invalidate buffer
|
2010-08-09 13:28:56 +00:00
|
|
|
buffer_dirty = false;
|
|
|
|
fp = 0;
|
|
|
|
file_offset = 0;
|
|
|
|
file_size = 0;
|
2010-10-14 10:07:38 +00:00
|
|
|
file_mode = mode::read;
|
2010-08-09 13:28:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
~file() {
|
|
|
|
close();
|
|
|
|
}
|
|
|
|
|
|
|
|
file& operator=(const file&) = delete;
|
|
|
|
file(const file&) = delete;
|
|
|
|
|
|
|
|
private:
|
|
|
|
enum { buffer_size = 1 << 12, buffer_mask = buffer_size - 1 };
|
|
|
|
char buffer[buffer_size];
|
|
|
|
int buffer_offset;
|
|
|
|
bool buffer_dirty;
|
|
|
|
FILE *fp;
|
|
|
|
unsigned file_offset;
|
|
|
|
unsigned file_size;
|
2010-10-14 10:07:38 +00:00
|
|
|
mode file_mode;
|
2010-08-09 13:28:56 +00:00
|
|
|
|
|
|
|
void buffer_sync() {
|
|
|
|
if(!fp) return; //file not open
|
|
|
|
if(buffer_offset != (file_offset & ~buffer_mask)) {
|
|
|
|
buffer_flush();
|
|
|
|
buffer_offset = file_offset & ~buffer_mask;
|
|
|
|
fseek(fp, buffer_offset, SEEK_SET);
|
|
|
|
unsigned length = (buffer_offset + buffer_size) <= file_size ? buffer_size : (file_size & buffer_mask);
|
|
|
|
if(length) unsigned unused = fread(buffer, 1, length, fp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void buffer_flush() {
|
2010-10-14 10:07:38 +00:00
|
|
|
if(!fp) return; //file not open
|
|
|
|
if(file_mode == mode::read) return; //buffer cannot be written to
|
|
|
|
if(buffer_offset < 0) return; //buffer unused
|
|
|
|
if(buffer_dirty == false) return; //buffer unmodified since read
|
2010-08-09 13:28:56 +00:00
|
|
|
fseek(fp, buffer_offset, SEEK_SET);
|
|
|
|
unsigned length = (buffer_offset + buffer_size) <= file_size ? buffer_size : (file_size & buffer_mask);
|
|
|
|
if(length) unsigned unused = fwrite(buffer, 1, length, fp);
|
2010-10-14 10:07:38 +00:00
|
|
|
buffer_offset = -1; //invalidate buffer
|
2010-08-09 13:28:56 +00:00
|
|
|
buffer_dirty = false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|