mirror of
https://github.com/spicyjpeg/573in1.git
synced 2025-01-22 19:52:05 +01:00
Fix IDE checksum bug, file destructor warnings
This commit is contained in:
parent
fa7beb023e
commit
9cf2908921
25
src/file.cpp
25
src/file.cpp
@ -13,6 +13,10 @@ namespace file {
|
||||
|
||||
/* File classes */
|
||||
|
||||
File::~File(void) {
|
||||
close();
|
||||
}
|
||||
|
||||
size_t HostFile::read(void *output, size_t length) {
|
||||
int actualLength = pcdrvRead(_fd, output, length);
|
||||
|
||||
@ -108,6 +112,10 @@ void FATFile::close(void) {
|
||||
|
||||
uint32_t currentSPUOffset = spu::DUMMY_BLOCK_END;
|
||||
|
||||
Provider::~Provider(void) {
|
||||
close();
|
||||
}
|
||||
|
||||
bool Provider::fileExists(const char *path) {
|
||||
auto file = openFile(path, READ);
|
||||
|
||||
@ -281,14 +289,23 @@ void FATProvider::close(void) {
|
||||
LOG("FAT unmount ok, drive=%s", _drive);
|
||||
}
|
||||
|
||||
bool FATProvider::_selectDrive(void) {
|
||||
if (!_drive[0])
|
||||
return false;
|
||||
|
||||
return !f_chdrive(_drive);
|
||||
}
|
||||
|
||||
bool FATProvider::fileExists(const char *path) {
|
||||
f_chdrive(_drive);
|
||||
if (!_selectDrive())
|
||||
return false;
|
||||
|
||||
return !f_stat(path, nullptr);
|
||||
}
|
||||
|
||||
bool FATProvider::createDirectory(const char *path) {
|
||||
f_chdrive(_drive);
|
||||
if (!_selectDrive())
|
||||
return false;
|
||||
|
||||
auto error = f_mkdir(path);
|
||||
|
||||
@ -301,13 +318,15 @@ bool FATProvider::createDirectory(const char *path) {
|
||||
}
|
||||
|
||||
File *FATProvider::openFile(const char *path, uint32_t flags) {
|
||||
f_chdrive(_drive);
|
||||
if (!_selectDrive())
|
||||
return nullptr;
|
||||
|
||||
auto file = new FATFile();
|
||||
auto error = f_open(&(file->_fd), path, uint8_t(flags));
|
||||
|
||||
if (error) {
|
||||
LOG("%s, drive=%s", util::getErrorString(error), _drive);
|
||||
delete file;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
12
src/file.hpp
12
src/file.hpp
@ -25,9 +25,7 @@ class File {
|
||||
public:
|
||||
uint64_t length;
|
||||
|
||||
inline ~File(void) {
|
||||
close();
|
||||
}
|
||||
virtual ~File(void);
|
||||
|
||||
virtual size_t read(void *output, size_t length) { return 0; }
|
||||
virtual size_t write(const void *input, size_t length) { return 0; }
|
||||
@ -70,10 +68,6 @@ extern uint32_t currentSPUOffset;
|
||||
|
||||
class Provider {
|
||||
public:
|
||||
inline ~Provider(void) {
|
||||
close();
|
||||
}
|
||||
|
||||
template<class T> inline size_t loadStruct(T &output, const char *path) {
|
||||
return loadData(&output, sizeof(output), path);
|
||||
}
|
||||
@ -81,6 +75,8 @@ public:
|
||||
return saveData(&input, sizeof(input), path);
|
||||
}
|
||||
|
||||
virtual ~Provider(void);
|
||||
|
||||
virtual void close(void) {}
|
||||
|
||||
virtual bool fileExists(const char *path);
|
||||
@ -108,6 +104,8 @@ private:
|
||||
FATFS _fs;
|
||||
char _drive[8];
|
||||
|
||||
bool _selectDrive(void);
|
||||
|
||||
public:
|
||||
inline FATProvider(void) {
|
||||
_drive[0] = 0;
|
||||
|
11
src/ide.cpp
11
src/ide.cpp
@ -59,9 +59,10 @@ bool IdentifyBlock::validateChecksum(void) const {
|
||||
if ((checksum & 0xff) != 0xa5)
|
||||
return true;
|
||||
|
||||
uint8_t value = (util::sum(
|
||||
// FIXME: is this right?
|
||||
uint8_t value = (-int(util::sum(
|
||||
reinterpret_cast<const uint8_t *>(&deviceFlags), ATA_SECTOR_SIZE - 1
|
||||
) & 0xff) ^ 0xff;
|
||||
))) & 0xff;
|
||||
|
||||
if (value != (checksum >> 8)) {
|
||||
LOG("mismatch, exp=0x%02x, got=0x%02x", value, checksum >> 8);
|
||||
@ -333,14 +334,14 @@ DeviceError Device::ideFlushCache(void) {
|
||||
);
|
||||
}
|
||||
|
||||
DeviceError Device::atapiPacket(Packet &packet) {
|
||||
DeviceError Device::atapiPacket(Packet &packet, size_t transferLength) {
|
||||
if (!(flags & DEVICE_ATAPI))
|
||||
return UNSUPPORTED_OP;
|
||||
|
||||
_select(0);
|
||||
|
||||
_write(CS0_CYLINDER_L, (2048 >> 0) & 0xff);
|
||||
_write(CS0_CYLINDER_H, (2048 >> 8) & 0xff);
|
||||
_write(CS0_CYLINDER_L, (transferLength >> 0) & 0xff);
|
||||
_write(CS0_CYLINDER_H, (transferLength >> 8) & 0xff);
|
||||
auto error = _command(ATA_PACKET, false);
|
||||
if (error)
|
||||
return error;
|
||||
|
@ -349,7 +349,9 @@ public:
|
||||
|
||||
DeviceError enumerate(void);
|
||||
DeviceError ideFlushCache(void);
|
||||
DeviceError atapiPacket(Packet &packet);
|
||||
DeviceError atapiPacket(
|
||||
Packet &packet, size_t transferLength = ATAPI_SECTOR_SIZE
|
||||
);
|
||||
};
|
||||
|
||||
extern Device devices[2];
|
||||
|
17
src/main.cpp
17
src/main.cpp
@ -7,6 +7,7 @@
|
||||
#include "defs.hpp"
|
||||
#include "file.hpp"
|
||||
#include "gpu.hpp"
|
||||
#include "ide.hpp"
|
||||
#include "io.hpp"
|
||||
#include "spu.hpp"
|
||||
#include "uibase.hpp"
|
||||
@ -116,16 +117,18 @@ int main(int argc, const char **argv) {
|
||||
|
||||
io::clearWatchdog();
|
||||
|
||||
ide::devices[0].enumerate();
|
||||
ide::devices[1].enumerate();
|
||||
|
||||
io::clearWatchdog();
|
||||
|
||||
file::FATProvider fileProvider;
|
||||
|
||||
// Attempt to initialize the secondary drive first, then in case of failure
|
||||
// try to initialize the primary drive instead.
|
||||
if (fileProvider.init("1:"))
|
||||
goto _fileInitDone;
|
||||
if (fileProvider.init("0:"))
|
||||
goto _fileInitDone;
|
||||
// Attempt to mount the secondary drive first, then in case of failure try
|
||||
// mounting the primary drive instead.
|
||||
if (!fileProvider.init("1:"))
|
||||
fileProvider.init("0:");
|
||||
|
||||
_fileInitDone:
|
||||
io::clearWatchdog();
|
||||
|
||||
// Load the resource archive, first from memory if a pointer was given and
|
||||
|
@ -51,7 +51,7 @@ static const uint32_t _BUTTON_MAPPINGS[NUM_BUTTON_MAPS][NUM_BUTTONS]{
|
||||
};
|
||||
|
||||
ButtonState::ButtonState(void)
|
||||
: _held(0), _repeatTimer(0) {}
|
||||
: _held(0), _repeatTimer(0), buttonMap(MAP_JOYSTICK) {}
|
||||
|
||||
void ButtonState::update(void) {
|
||||
_prevHeld = _held;
|
||||
|
Loading…
x
Reference in New Issue
Block a user