Fix reflash data key bug and UI issues

This commit is contained in:
spicyjpeg 2023-06-27 16:25:52 +02:00
parent fbc9026628
commit 7c488e3495
No known key found for this signature in database
GPG Key ID: 5CC87404C01DF393
10 changed files with 47 additions and 33 deletions

View File

@ -1,6 +1,12 @@
cart_tool - (C) 2022-2023 spicyjpeg
Konami System 573 security cartridge tool
# Open source licenses
(C) 2022-2023 spicyjpeg
WARNING: This tool is experimental and provided with no warranty whatsoever. It
is not guaranteed to work and improper usage can PERMANENTLY BRICK your System
573 security cartridges. Use this tool at your own risk.
# Third-party licenses
This tool embeds several third-party libraries and projects:

View File

@ -54,7 +54,7 @@
"CartActionsScreen": {
"title": "{CART_ICON} Cartridge options",
"itemPrompt": "{RIGHT_ARROW} Press {START_BUTTON} to confirm, hold {LEFT_BUTTON} + {RIGHT_BUTTON} to go back",
"itemPrompt": "{RIGHT_ARROW} Press {START_BUTTON} to select, hold {LEFT_BUTTON} + {RIGHT_BUTTON} to go back",
"qrDump": {
"name": "Dump cartridge as QR code",
@ -187,7 +187,7 @@
"MainMenuScreen": {
"title": "{CART_ICON} Main menu",
"itemPrompt": "{RIGHT_ARROW} Press {START_BUTTON} to confirm",
"itemPrompt": "{RIGHT_ARROW} Select by pressing {START_BUTTON}",
"cartInfo": {
"name": "Manage security cartridge",
@ -219,7 +219,7 @@
"ReflashGameScreen": {
"title": "{CART_ICON} Select game to convert cartridge to",
"prompt": "Make sure you select the correct region. Note that cartridges can only be converted for use with games that accept the same cartridge type.",
"itemPrompt": "{RIGHT_ARROW} Press {START_BUTTON} to confirm, hold {LEFT_BUTTON} + {RIGHT_BUTTON} to go back"
"itemPrompt": "{RIGHT_ARROW} Press {START_BUTTON} to select, hold {LEFT_BUTTON} + {RIGHT_BUTTON} to go back"
},
"SystemIDEntryScreen": {
@ -237,7 +237,7 @@
"UnlockKeyScreen": {
"title": "{CART_ICON} Select unlocking key",
"prompt": "If the cartridge has been converted before, select the game it was last converted to. If it is currently blank, select 00-00-00-00-00-00-00-00.",
"itemPrompt": "{RIGHT_ARROW} Press {START_BUTTON} to confirm, hold {LEFT_BUTTON} + {RIGHT_BUTTON} to go back",
"itemPrompt": "{RIGHT_ARROW} Press {START_BUTTON} to select, hold {LEFT_BUTTON} + {RIGHT_BUTTON} to go back",
"autoUnlock": "Use key from identified game (recommended)",
"useCustomKey": "Enter key manually...",

View File

@ -252,7 +252,7 @@ bool App::_hddDumpWorker(void) {
return false;
}
_workerStatus.setNextScreen(_cartInfoScreen);
_workerStatus.setNextScreen(_cartActionsScreen);
return true;
}
@ -321,13 +321,12 @@ bool App::_cartReflashWorker(void) {
_parser->setYear(_selectedEntry->year);
_parser->flush();
uint8_t key[8];
auto error = _driver->writeData();
auto error = _driver->setDataKey(_selectedEntry->dataKey);
if (!error) {
_selectedEntry->copyKeyTo(key);
error = _driver->setDataKey(key);
}
if (error)
LOG("failed to set data key");
else
error = _driver->writeData();
_cartDetectWorker();
@ -341,7 +340,6 @@ bool App::_cartReflashWorker(void) {
return false;
}
_dump.copyKeyFrom(key);
return _cartUnlockWorker();
}
@ -362,7 +360,6 @@ bool App::_cartEraseWorker(void) {
return false;
}
_dump.clearKey();
return _cartUnlockWorker();
}

View File

@ -202,7 +202,7 @@ void QRCodeScreen::show(ui::Context &ctx, bool goBack) {
void QRCodeScreen::update(ui::Context &ctx) {
if (ctx.buttons.pressed(ui::BTN_START))
ctx.show(APP->_cartInfoScreen, true, true);
ctx.show(APP->_cartActionsScreen, true, true);
}
void HexdumpScreen::show(ui::Context &ctx, bool goBack) {
@ -220,6 +220,8 @@ void HexdumpScreen::show(ui::Context &ctx, bool goBack) {
*(ptr++) = '\n';
}
*(--ptr) = 0;
TextScreen::show(ctx, goBack);
}
@ -227,7 +229,7 @@ void HexdumpScreen::update(ui::Context &ctx) {
TextScreen::update(ctx);
if (ctx.buttons.pressed(ui::BTN_START))
ctx.show(APP->_cartInfoScreen, true, true);
ctx.show(APP->_cartActionsScreen, true, true);
}
const char *ReflashGameScreen::_getItemName(ui::Context &ctx, int index) const {

View File

@ -81,7 +81,7 @@ public:
void (MainMenuScreen::*target)(ui::Context &ctx);
};
static constexpr int _NUM_MENU_ENTRIES = 5;
static constexpr int _NUM_MENU_ENTRIES = 3;
static const MenuEntry _MENU_ENTRIES[_NUM_MENU_ENTRIES]{
{
@ -89,6 +89,7 @@ static const MenuEntry _MENU_ENTRIES[_NUM_MENU_ENTRIES]{
.prompt = "MainMenuScreen.cartInfo.prompt"_h,
.target = &MainMenuScreen::cartInfo
}, {
#if 0
.name = "MainMenuScreen.dump.name"_h,
.prompt = "MainMenuScreen.dump.prompt"_h,
.target = &MainMenuScreen::dump
@ -97,6 +98,7 @@ static const MenuEntry _MENU_ENTRIES[_NUM_MENU_ENTRIES]{
.prompt = "MainMenuScreen.restore.prompt"_h,
.target = &MainMenuScreen::restore
}, {
#endif
.name = "MainMenuScreen.about.name"_h,
.prompt = "MainMenuScreen.about.prompt"_h,
.target = &MainMenuScreen::about

View File

@ -196,7 +196,7 @@ DriverError X76Driver::_x76Command(
}
#ifdef ENABLE_I2C_LOGGING
char buffer[32];
char buffer[48];
util::hexToString(buffer, _dump.dataKey, sizeof(_dump.dataKey), ' ');
LOG("S: %02X %02X %s", cmd, param, buffer);
@ -386,7 +386,7 @@ DriverError ZS01Driver::_transact(
io::i2cStart();
#ifdef ENABLE_I2C_LOGGING
char buffer[32];
char buffer[48];
util::hexToString(buffer, &request.command, sizeof(zs01::Packet), ' ');
LOG("S: %s", buffer);
@ -553,13 +553,13 @@ DriverError ZS01Driver::erase(void) {
DriverError ZS01Driver::setDataKey(const uint8_t *key) {
zs01::Packet request, response;
zs01::Key newKey;
zs01::Key oldKey;
newKey.unpackFrom(_dump.dataKey);
oldKey.unpackFrom(_dump.dataKey);
request.address = zs01::ADDR_DATA_KEY;
request.copyFrom(key);
request.encodeWriteRequest(newKey, _encoderState);
request.encodeWriteRequest(oldKey, _encoderState);
DriverError error = _transact(request, response);
if (error)

View File

@ -64,9 +64,9 @@ class CartDriver : public Driver {
public:
inline CartDriver(Dump &dump, ChipType chipType = NONE, uint8_t flags = 0)
: Driver(dump) {
dump.clearIdentifiers();
dump.clearKey();
dump.clearData();
//dump.clearIdentifiers();
//dump.clearKey();
//dump.clearData();
dump.chipType = chipType;
dump.flags = flags;

View File

@ -55,10 +55,10 @@ void Font::draw(
int w = size & 0x7f; size >>= 7;
int h = size & 0x7f; size >>= 7;
if (y > (clipRect.y2 - h))
if (y > clipRect.y2)
return;
if (
(x >= (clipRect.x1 - w)) && (x <= (clipRect.x2 - w)) &&
(x >= (clipRect.x1 - w)) && (x <= clipRect.x2) &&
(y >= (clipRect.y1 - h))
) {
auto cmd = ctx.newPacket(4);

View File

@ -334,7 +334,8 @@ void ModalScreen::draw(Context &ctx, bool active) const {
rect.x1 = TITLE_BAR_PADDING;
rect.y1 = TITLE_BAR_PADDING;
rect.x2 = _width - TITLE_BAR_PADDING;
rect.y2 = TITLE_BAR_HEIGHT - TITLE_BAR_PADDING;
rect.y2 = TITLE_BAR_PADDING + gpu::FONT_LINE_HEIGHT;
//rect.y2 = TITLE_BAR_HEIGHT - TITLE_BAR_PADDING;
ctx.font.draw(ctx.gpuCtx, _title, rect, COLOR_TITLE);
rect.y1 = TITLE_BAR_HEIGHT + MODAL_PADDING;

View File

@ -42,7 +42,8 @@ void MessageScreen::draw(Context &ctx, bool active) const {
rect.y = buttonY + BUTTON_PADDING;
rect.w = _getButtonWidth();
rect.h = BUTTON_HEIGHT - BUTTON_PADDING * 2;
rect.h = rect.y + gpu::FONT_LINE_HEIGHT;
//rect.h = BUTTON_HEIGHT - BUTTON_PADDING * 2;
for (int i = 0; i < _numButtons; i++) {
rect.x = buttonX +
@ -301,7 +302,8 @@ void TextScreen::draw(Context &ctx, bool active) const {
ctx.font.draw(ctx.gpuCtx, _prompt, rect, COLOR_TEXT1, true);
int bodyOffset = gpu::FONT_LINE_HEIGHT + SCREEN_BLOCK_MARGIN;
int bodyHeight = screenHeight - (bodyOffset + SCREEN_PROMPT_HEIGHT_MIN);
int bodyHeight = screenHeight -
(bodyOffset + SCREEN_PROMPT_HEIGHT_MIN + SCREEN_BLOCK_MARGIN);
// Scrollable text
_newLayer(
@ -326,7 +328,8 @@ void TextScreen::update(Context &ctx) {
int screenHeight = ctx.gpuCtx.height - SCREEN_MARGIN_Y * 2;
int bodyOffset = gpu::FONT_LINE_HEIGHT + SCREEN_BLOCK_MARGIN;
int bodyHeight = screenHeight - (bodyOffset + SCREEN_PROMPT_HEIGHT_MIN);
int bodyHeight = screenHeight -
(bodyOffset + SCREEN_PROMPT_HEIGHT_MIN + SCREEN_BLOCK_MARGIN);
int scrollHeight = _textHeight - util::min(_textHeight, bodyHeight);
@ -420,10 +423,11 @@ void ListScreen::_drawItems(Context &ctx) const {
rect.x1 = LIST_BOX_PADDING + LIST_ITEM_PADDING;
rect.x2 = itemWidth - LIST_ITEM_PADDING;
rect.y2 = listHeight;
//rect.y2 = listHeight;
for (int i = 0; (i < _listLength) && (itemY < listHeight); i++) {
int itemHeight = gpu::FONT_LINE_HEIGHT + LIST_ITEM_PADDING * 2;
if (i == _activeItem)
itemHeight += gpu::FONT_LINE_HEIGHT;
@ -439,10 +443,12 @@ void ListScreen::_drawItems(Context &ctx) const {
);
rect.y1 = itemY + LIST_ITEM_PADDING + gpu::FONT_LINE_HEIGHT;
rect.y2 = rect.y1 + gpu::FONT_LINE_HEIGHT;
ctx.font.draw(ctx.gpuCtx, _itemPrompt, rect, COLOR_SUBTITLE);
}
rect.y1 = itemY + LIST_ITEM_PADDING;
rect.y2 = rect.y1 + gpu::FONT_LINE_HEIGHT;
ctx.font.draw(ctx.gpuCtx, _getItemName(ctx, i), rect, COLOR_TITLE);
}