2016-01-07 08:14:33 +00:00
|
|
|
#pragma once
|
2011-12-12 10:59:53 +00:00
|
|
|
|
2016-01-07 08:14:33 +00:00
|
|
|
namespace nall { namespace mosaic {
|
2011-12-12 10:59:53 +00:00
|
|
|
|
|
|
|
struct bitstream {
|
2015-12-14 09:41:06 +00:00
|
|
|
~bitstream() {
|
|
|
|
close();
|
|
|
|
}
|
2011-12-12 10:59:53 +00:00
|
|
|
|
Update to v097r14 release.
byuu says:
This is a few days old, but oh well.
This WIP changes nall,hiro,ruby,icarus back to (u)int(8,16,32,64)_t.
I'm slowly pushing for (u)int(8,16,32,64) to use my custom
Integer<Size>/Natural<Size> classes instead. But it's going to be one
hell of a struggle to get that into higan.
2016-02-16 09:11:58 +00:00
|
|
|
auto read(uint64_t addr) const -> bool {
|
2011-12-12 10:59:53 +00:00
|
|
|
if(data == nullptr || (addr >> 3) >= size) return 0;
|
2015-12-14 09:41:06 +00:00
|
|
|
uint mask = endian == 0 ? (0x01 << (addr & 7)) : (0x80 >> (addr & 7));
|
2011-12-12 10:59:53 +00:00
|
|
|
return data[addr >> 3] & mask;
|
|
|
|
}
|
|
|
|
|
Update to v097r14 release.
byuu says:
This is a few days old, but oh well.
This WIP changes nall,hiro,ruby,icarus back to (u)int(8,16,32,64)_t.
I'm slowly pushing for (u)int(8,16,32,64) to use my custom
Integer<Size>/Natural<Size> classes instead. But it's going to be one
hell of a struggle to get that into higan.
2016-02-16 09:11:58 +00:00
|
|
|
auto write(uint64_t addr, bool value) -> void {
|
2011-12-12 10:59:53 +00:00
|
|
|
if(data == nullptr || readonly == true || (addr >> 3) >= size) return;
|
2015-12-14 09:41:06 +00:00
|
|
|
uint mask = endian == 0 ? (0x01 << (addr & 7)) : (0x80 >> (addr & 7));
|
2011-12-12 10:59:53 +00:00
|
|
|
if(value == 0) data[addr >> 3] &= ~mask;
|
|
|
|
if(value == 1) data[addr >> 3] |= mask;
|
|
|
|
}
|
|
|
|
|
2015-12-14 09:41:06 +00:00
|
|
|
auto open(const string& filename) -> bool {
|
2011-12-12 10:59:53 +00:00
|
|
|
readonly = false;
|
|
|
|
if(fp.open(filename, filemap::mode::readwrite) == false) {
|
|
|
|
readonly = true;
|
|
|
|
if(fp.open(filename, filemap::mode::read) == false) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
data = fp.data();
|
|
|
|
size = fp.size();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-12-14 09:41:06 +00:00
|
|
|
auto close() -> void {
|
2011-12-12 10:59:53 +00:00
|
|
|
fp.close();
|
|
|
|
data = nullptr;
|
|
|
|
}
|
|
|
|
|
2015-12-14 09:41:06 +00:00
|
|
|
filemap fp;
|
Update to v097r14 release.
byuu says:
This is a few days old, but oh well.
This WIP changes nall,hiro,ruby,icarus back to (u)int(8,16,32,64)_t.
I'm slowly pushing for (u)int(8,16,32,64) to use my custom
Integer<Size>/Natural<Size> classes instead. But it's going to be one
hell of a struggle to get that into higan.
2016-02-16 09:11:58 +00:00
|
|
|
uint8_t* data = nullptr;
|
2015-12-14 09:41:06 +00:00
|
|
|
uint size = 0;
|
|
|
|
bool readonly = false;
|
|
|
|
bool endian = 1;
|
2011-12-12 10:59:53 +00:00
|
|
|
};
|
|
|
|
|
2016-01-07 08:14:33 +00:00
|
|
|
}}
|