Fix bugs in dummy cart driver, ID entry screen

This commit is contained in:
spicyjpeg 2023-09-16 14:01:26 +02:00
parent 72580397a1
commit c29b4c98c3
No known key found for this signature in database
GPG Key ID: 5CC87404C01DF393
10 changed files with 76 additions and 44 deletions

View File

@ -25,10 +25,8 @@ void App::_unloadCartData(void) {
_parser = nullptr;
}
_dump.chipType = cart::NONE;
_dump._reserved[0] = 0;
_dump._reserved[1] = 0;
_dump.chipType = cart::NONE;
_dump.flags = 0;
_dump.clearIdentifiers();
_dump.clearData();
@ -77,7 +75,10 @@ bool App::_cartDetectWorker(void) {
_unloadCartData();
#ifdef ENABLE_DUMMY_DRIVER
if (_resourceProvider->loadStruct(_dump, "data/test.573")) {
if (!cart::dummyDriverDump.chipType)
_resourceProvider->loadStruct(cart::dummyDriverDump, "data/test.573");
if (cart::dummyDriverDump.chipType) {
LOG("using dummy cart driver");
_driver = new cart::DummyDriver(_dump);
} else {
@ -101,7 +102,7 @@ bool App::_cartDetectWorker(void) {
if (error)
LOG("read error [%s]", util::getErrorString(error));
else
else if (!_dump.isReadableDataEmpty())
_parser = cart::newCartParser(_dump);
LOG("cart parser @ 0x%08x", _parser);

View File

@ -154,6 +154,7 @@ void CartActionsScreen::editSystemID(ui::Context &ctx) {
STR("CartActionsScreen.editSystemID.error")
);
APP->_systemIDEntryScreen.getSystemID(*(APP->_parser));
ctx.show(APP->_systemIDEntryScreen, false, true);
}
@ -286,8 +287,6 @@ void SystemIDEntryScreen::show(ui::Context &ctx, bool goBack) {
_separator = '-';
HexEntryScreen::show(ctx, goBack);
APP->_parser->getIdentifiers()->systemID.copyTo(_buffer);
}
void SystemIDEntryScreen::update(ui::Context &ctx) {

View File

@ -61,6 +61,9 @@ public:
class SystemIDEntryScreen : public ui::HexEntryScreen {
public:
inline void getSystemID(cart::Parser &parser) {
parser.getIdentifiers()->systemID.copyTo(_buffer);
}
inline void setSystemID(cart::Parser &parser) const {
parser.getIdentifiers()->systemID.copyFrom(_buffer);
parser.flush();

View File

@ -164,6 +164,12 @@ public:
uint8_t dataKey[8], config[8];
uint8_t data[512];
inline Dump(void)
: chipType(NONE), flags(0) {
_reserved[0] = 0;
_reserved[1] = 0;
}
inline const ChipSize &getChipSize(void) const {
return CHIP_SIZES[chipType];
}

View File

@ -10,19 +10,11 @@ namespace cart {
/* Dummy cartridge driver */
static Dump _dummyDump{ .chipType = NONE };
DummyDriver::DummyDriver(Dump &dump)
: Driver(dump) {
if (!_dummyDump.chipType)
__builtin_memcpy(&_dummyDump, &dump, sizeof(Dump));
dump.flags &= DUMP_HAS_SYSTEM_ID | DUMP_HAS_CART_ID;
}
Dump dummyDriverDump;
DriverError DummyDriver::readSystemID(void) {
if (_dummyDump.flags & DUMP_SYSTEM_ID_OK) {
_dump.systemID.copyFrom(_dummyDump.systemID.data);
if (dummyDriverDump.flags & DUMP_SYSTEM_ID_OK) {
_dump.systemID.copyFrom(dummyDriverDump.systemID.data);
_dump.flags |= DUMP_SYSTEM_ID_OK;
return NO_ERROR;
}
@ -31,12 +23,12 @@ DriverError DummyDriver::readSystemID(void) {
}
DriverError DummyDriver::readCartID(void) {
if (_dummyDump.flags & DUMP_ZS_ID_OK) {
_dump.zsID.copyFrom(_dummyDump.zsID.data);
if (dummyDriverDump.flags & DUMP_ZS_ID_OK) {
_dump.zsID.copyFrom(dummyDriverDump.zsID.data);
_dump.flags |= DUMP_ZS_ID_OK;
}
if (_dummyDump.flags & DUMP_CART_ID_OK) {
_dump.cartID.copyFrom(_dummyDump.cartID.data);
if (dummyDriverDump.flags & DUMP_CART_ID_OK) {
_dump.cartID.copyFrom(dummyDriverDump.cartID.data);
_dump.flags |= DUMP_CART_ID_OK;
return NO_ERROR;
}
@ -45,11 +37,11 @@ DriverError DummyDriver::readCartID(void) {
}
DriverError DummyDriver::readPublicData(void) {
if (_dummyDump.chipType != ZS01)
if (dummyDriverDump.chipType != ZS01)
return UNSUPPORTED_OP;
if (_dummyDump.flags & DUMP_PUBLIC_DATA_OK) {
_dump.copyDataFrom(_dummyDump.data);
if (dummyDriverDump.flags & DUMP_PUBLIC_DATA_OK) {
_dump.copyDataFrom(dummyDriverDump.data);
_dump.flags |= DUMP_PUBLIC_DATA_OK;
return NO_ERROR;
}
@ -58,11 +50,11 @@ DriverError DummyDriver::readPublicData(void) {
}
DriverError DummyDriver::readPrivateData(void) {
if ((_dummyDump.flags & DUMP_PRIVATE_DATA_OK) && !__builtin_memcmp(
_dump.dataKey, _dummyDump.dataKey, sizeof(_dump.dataKey)
if ((dummyDriverDump.flags & DUMP_PRIVATE_DATA_OK) && !__builtin_memcmp(
_dump.dataKey, dummyDriverDump.dataKey, sizeof(_dump.dataKey)
)) {
_dump.copyDataFrom(_dummyDump.data);
_dump.copyConfigFrom(_dummyDump.config);
_dump.copyDataFrom(dummyDriverDump.data);
_dump.copyConfigFrom(dummyDriverDump.config);
_dump.flags |= DUMP_PRIVATE_DATA_OK | DUMP_CONFIG_OK;
return NO_ERROR;
}
@ -72,9 +64,9 @@ DriverError DummyDriver::readPrivateData(void) {
DriverError DummyDriver::writeData(void) {
if (!__builtin_memcmp(
_dump.dataKey, _dummyDump.dataKey, sizeof(_dump.dataKey)
_dump.dataKey, dummyDriverDump.dataKey, sizeof(_dump.dataKey)
)) {
_dummyDump.copyDataFrom(_dump.data);
dummyDriverDump.copyDataFrom(_dump.data);
return NO_ERROR;
}
@ -82,11 +74,17 @@ DriverError DummyDriver::writeData(void) {
}
DriverError DummyDriver::erase(void) {
char buf[128];
util::hexToString(buf,_dump.dataKey,8);
LOG("got %s",buf);
util::hexToString(buf,dummyDriverDump.dataKey,8);
LOG("exp %s",buf);
if (!__builtin_memcmp(
_dump.dataKey, _dummyDump.dataKey, sizeof(_dump.dataKey)
_dump.dataKey, dummyDriverDump.dataKey, sizeof(_dump.dataKey)
)) {
_dummyDump.clearData();
_dummyDump.clearKey();
dummyDriverDump.clearData();
dummyDriverDump.clearKey();
// TODO: clear config registers as well
_dump.clearKey();
@ -98,9 +96,9 @@ DriverError DummyDriver::erase(void) {
DriverError DummyDriver::setDataKey(const uint8_t *key) {
if (!__builtin_memcmp(
_dump.dataKey, _dummyDump.dataKey, sizeof(_dump.dataKey)
_dump.dataKey, dummyDriverDump.dataKey, sizeof(_dump.dataKey)
)) {
_dummyDump.copyKeyFrom(key);
dummyDriverDump.copyKeyFrom(key);
_dump.copyKeyFrom(key);
return NO_ERROR;

View File

@ -23,6 +23,8 @@ enum DriverError {
/* Base classes */
extern Dump dummyDriverDump;
class Driver {
protected:
Dump &_dump;
@ -48,7 +50,16 @@ private:
}
public:
DummyDriver(Dump &dump);
inline DummyDriver(Dump &dump)
: Driver(dump) {
//dump.clearIdentifiers();
//dump.clearKey();
//dump.clearData();
dump.chipType = dummyDriverDump.chipType;
dump.flags = dummyDriverDump.flags &
(DUMP_HAS_SYSTEM_ID | DUMP_HAS_CART_ID);
}
DriverError readSystemID(void);
DriverError readCartID(void);

View File

@ -106,9 +106,13 @@ public:
class FATProvider : public Provider {
private:
FATFS _fs;
char _drive[16];
char _drive[8];
public:
inline FATProvider(void) {
_drive[0] = 0;
}
bool init(const char *drive);
void close(void);

View File

@ -13,7 +13,11 @@ uint16_t _bankSwitchReg, _cartOutputReg, _miscOutputReg;
void init(void) {
_bankSwitchReg = 0;
_cartOutputReg = 0;
_miscOutputReg = 0x0107;
_miscOutputReg = 0
| SYS573_MISC_OUT_ADC_MOSI
| SYS573_MISC_OUT_ADC_CS
| SYS573_MISC_OUT_ADC_SCK
| SYS573_MISC_OUT_JVS_STAT;
BIU_DEV0_ADDR = DEV0_BASE & 0x1fffffff;
BIU_DEV0_CTRL = 0
@ -32,7 +36,11 @@ void init(void) {
SYS573_WATCHDOG = 0;
SYS573_BANK_CTRL = 0;
SYS573_CART_OUT = 0;
SYS573_MISC_OUT = 0x0107;
SYS573_MISC_OUT = 0
| SYS573_MISC_OUT_ADC_MOSI
| SYS573_MISC_OUT_ADC_CS
| SYS573_MISC_OUT_ADC_SCK
| SYS573_MISC_OUT_JVS_STAT;
// Some of the digital I/O board's light outputs are controlled by the FPGA
// and cannot be turned off until the FPGA is initialized.

View File

@ -34,7 +34,7 @@
typedef enum {
DEV0_BASE = 0xbf000000,
EXP1_BASE = 0xbf000000,
CACHE_BASE = 0x1f800000, // Cannot be accessed from KSEG1
CACHE_BASE = 0x9f800000, // Cannot be accessed from KSEG1
IO_BASE = 0xbf801000,
EXP2_BASE = 0xbf802000,
EXP3_BASE = 0xbfa00000,

View File

@ -121,13 +121,15 @@ void MessageBoxScreen::update(Context &ctx) {
}
HexEntryScreen::HexEntryScreen(void)
: _bufferLength(0) {}
: _bufferLength(0) {
__builtin_memset(_buffer, 0, _bufferLength);
}
void HexEntryScreen::show(Context &ctx, bool goBack) {
MessageBoxScreen::show(ctx, goBack);
_buttonIndexOffset = _bufferLength * 2;
__builtin_memset(_buffer, 0, _bufferLength);
//__builtin_memset(_buffer, 0, _bufferLength);
_charIndex = 0;
_cursorAnim.setValue(0);