8 Commits
0.3 ... 0.10

Author SHA1 Message Date
Lesserkuma
f756a705ae New config option + autoboot if there is only one game in the list 2024-01-06 11:47:03 +01:00
Lesserkuma
d51437552e - 2023-12-17 01:03:38 +01:00
Lesserkuma
12d953d8fd - 2023-12-17 00:46:37 +01:00
Lesserkuma
1bf4927d6b Support for MSP54LV100 2023-11-24 18:05:40 +01:00
Lesserkuma
a3c4a44893 0.7 2023-11-01 20:36:02 +01:00
Lesserkuma
cbe17ef7c5 0.6 2023-09-24 12:54:20 +02:00
Lesserkuma
8dc1d10a95 0.5 2023-08-17 17:57:35 +02:00
Lesserkuma
bcb9ae5d65 - 2023-08-01 12:47:35 +02:00
7 changed files with 240 additions and 80 deletions

View File

@@ -183,7 +183,9 @@ $(shell touch $(CURDIR)/../$(SOURCES)/version.h)
%.gba: %.elf %.gba: %.elf
@$(OBJCOPY) -O binary $< $@ @$(OBJCOPY) -O binary $< $@
@gbafix $@ "-tLK MULTIMENU" "-cAGBJ" "-mLK" "-r0" @gbafix $@ "-tLK MULTIMENU" "-cAGBJ" "-mLK" "-r0"
@echo Copying to ROM builder folder
@cp $@ "$(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))/rom_builder/lk_multimenu.gba" @cp $@ "$(shell dirname $(realpath $(firstword $(MAKEFILE_LIST))))/rom_builder/lk_multimenu.gba"
@echo Done!
#--------------------------------------------------------------------------------------- #---------------------------------------------------------------------------------------
endif endif

View File

@@ -15,15 +15,19 @@ The following section must be edited in order to specify the cartridge type to u
```json ```json
"cartridge": { "cartridge": {
"type": 2, "type": 2,
"battery_present": false "battery_present": false,
"min_rom_size": 4194304
}, },
``` ```
Set `type` to `1` or `2`: Set `type` to `1` or `2`:
- `1` = MSP55LV100S (e.g. The Legend of Zelda Collection - Classic Edition 7-in-1) - `1` = MSP55LV100S (e.g. The Legend of Zelda Collection - Classic Edition 7-in-1, 64 MiB)
- `2` = 6600M0U0BE (e.g. 369IN1 2048M) - `2` = 6600M0U0BE (e.g. 369IN1 2048M, 256 MiB)
- `3` = MSP54LV100 (e.g. The Legend of Zelda Collection - Classic Edition 7-in-1, 128 MiB)
Set `battery_present` to `true` or `false`. This will enable enhanced save data handling which will only be functional with a working battery. Set `battery_present` to `true` or `false`. This will enable enhanced save data handling which will only be functional with a working battery.
Set `min_rom_size` to whatever your cartridge supports as the smallest possible ROM size. Many newer cartridges only support ROMs no smaller than 4 MiB (`4194304`) while some older cartridges can go as low as 512 KiB (`524288`).
In the `games` section, you can edit the game-related stuff: In the `games` section, you can edit the game-related stuff:
```json ```json
"games": [ "games": [
@@ -47,6 +51,7 @@ In the `games` section, you can edit the game-related stuff:
- `6` = Pokémon Black & White condensed battle font - `6` = Pokémon Black & White condensed battle font
- `save_slot` defines which save slot your game uses. Set it to `null` for no saving or a number starting from `1`. Multiple games can share a save slot. - `save_slot` defines which save slot your game uses. Set it to `null` for no saving or a number starting from `1`. Multiple games can share a save slot.
- `map_256m`, if set to `true`, can serve as a workaround for a glitch with the cartridge mapper that causes games to freeze with screeching noises upon launch. - `map_256m`, if set to `true`, can serve as a workaround for a glitch with the cartridge mapper that causes games to freeze with screeching noises upon launch.
- `keys` will let you specify a list of keys that must be held down at startup for this ROM to appear in the menu, e. g. `[ "L", "R", "DOWN" ]`.
### ROM Builder Command Line Arguments ### ROM Builder Command Line Arguments
@@ -71,15 +76,18 @@ If the cartridge has a battery installed, the ROMs must be SRAM-patched with [GB
If the cartridge has no battery installed, the ROMs must be patched for batteryless SRAM saving with maniac's [Automatic batteryless saving patcher](https://github.com/metroid-maniac/gba-auto-batteryless-patcher/). If the cartridge has no battery installed, the ROMs must be patched for batteryless SRAM saving with maniac's [Automatic batteryless saving patcher](https://github.com/metroid-maniac/gba-auto-batteryless-patcher/).
On battery-equipped cartridges, when starting a game from the menu, the previously played game's save data will be read from SRAM and stored to permanent flash memory. To skip this, you can hold the SELECT button while starting the game.
## Compatibility ## Compatibility
Tested repro cartridges: Tested repro cartridges:
- 100BS6600_48BALL_V4 with 6600M0U0BE
- 100SOP with MSP55LV100S - 100SOP with MSP55LV100S
- 100BS6600_48BALL_V4 with 6600M0U0BE
- SUN100S_MSP54_XXX_BGA48 with MSP54LV100
The generated compilation ROM can be written and read using a [GBxCart RW v1.4+](https://www.gbxcart.com/) device by insideGadgets and the [FlashGBX](https://github.com/lesserkuma/FlashGBX) software. The generated compilation ROM can be written and read using a [GBxCart RW v1.4+](https://www.gbxcart.com/) device by insideGadgets and the [FlashGBX](https://github.com/lesserkuma/FlashGBX) software.
## Thanks ## Thanks
Thanks to FraX, Ausar, liuyunx, BennVenn Thanks to FraX, Ausar, liuyunx, BennVenn, Jenetrix
## Screenshots ## Screenshots

View File

@@ -5,7 +5,7 @@
import sys, os, glob, json, math, re, struct, hashlib, argparse, datetime import sys, os, glob, json, math, re, struct, hashlib, argparse, datetime
# Configuration # Configuration
app_version = "0.3" app_version = "0.10"
default_file = "LK_MULTIMENU_<CODE>.gba" default_file = "LK_MULTIMENU_<CODE>.gba"
################################ ################################
@@ -51,6 +51,12 @@ cartridge_types = [
"sector_size":0x40000, "sector_size":0x40000,
"block_size":0x80000, "block_size":0x80000,
}, },
{
"name":"MSP54LV100",
"flash_size":0x8000000,
"sector_size":0x20000,
"block_size":0x80000,
},
] ]
now = datetime.datetime.now() now = datetime.datetime.now()
log = "" log = ""
@@ -83,19 +89,27 @@ if not os.path.exists(args.config):
games = [] games = []
cartridge_type = 1 cartridge_type = 1
battery_present = False battery_present = False
min_rom_size = 0x400000
for file in files: for file in files:
games.append({ d = {
"enabled": True, "enabled": True,
"file": os.path.split(file)[1], "file": os.path.split(file)[1],
"title": os.path.splitext(os.path.split(file)[1])[0], "title": os.path.splitext(os.path.split(file)[1])[0],
"title_font": 1, "title_font": 1,
"save_slot": save_slot, "save_slot": save_slot,
}) }
with open(file, "rb") as f:
f.seek(0xAC)
code = f.read(0x4)
if code[:3] in (b"BPG", b"BPR"):
d["map_256m"] = True
games.append(d)
save_slot += 1 save_slot += 1
obj = { obj = {
"cartridge": { "cartridge": {
"type": cartridge_type + 1, "type": cartridge_type + 1,
"battery_present": battery_present, "battery_present": battery_present,
"min_rom_size": min_rom_size,
}, },
"games": games, "games": games,
} }
@@ -118,6 +132,10 @@ else:
games = j["games"] games = j["games"]
cartridge_type = j["cartridge"]["type"] - 1 cartridge_type = j["cartridge"]["type"] - 1
battery_present = j["cartridge"]["battery_present"] battery_present = j["cartridge"]["battery_present"]
if "min_rom_size" in j["cartridge"]:
min_rom_size = j["cartridge"]["min_rom_size"]
else:
min_rom_size = 0x400000
# Prepare compilation # Prepare compilation
flash_size = cartridge_types[cartridge_type]["flash_size"] flash_size = cartridge_types[cartridge_type]["flash_size"]
@@ -127,6 +145,7 @@ block_size = cartridge_types[cartridge_type]["block_size"]
block_count = flash_size // block_size block_count = flash_size // block_size
sectors_per_block = 0x80000 // sector_size sectors_per_block = 0x80000 // sector_size
compilation = bytearray() compilation = bytearray()
roms_keys = [0]
for i in range(flash_size // 0x2000000): for i in range(flash_size // 0x2000000):
chunk = bytearray([0xFF] * 0x2000000) chunk = bytearray([0xFF] * 0x2000000)
compilation += chunk compilation += chunk
@@ -166,6 +185,13 @@ for game in games:
x = 0x80000 x = 0x80000
while (x < size): x *= 2 while (x < size): x *= 2
size = x size = x
if size < 0x400000:
with open(f"roms/{game['file']}", "rb") as f:
buffer = f.read()
if b"Batteryless mod by Lesserkuma" in buffer:
size = max(0x400000, min_rom_size)
else:
size = max(size, min_rom_size)
game["index"] = index game["index"] = index
game["size"] = size game["size"] = size
if "title_font" in game: if "title_font" in game:
@@ -173,7 +199,36 @@ for game in games:
else: else:
game["title_font"] = 0 game["title_font"] = 0
game["sector_count"] = int(size / sector_size) game["sector_count"] = int(size / sector_size)
# Hidden ROMs
keys = 0
if "keys" in game:
for key in game["keys"]:
if key.upper() == "A":
keys |= (1 << 0)
elif key.upper() == "B":
keys |= (1 << 1)
elif key.upper() == "SELECT":
keys |= (1 << 2)
elif key.upper() == "START":
keys |= (1 << 3)
elif key.upper() == "RIGHT":
keys |= (1 << 4)
elif key.upper() == "LEFT":
keys |= (1 << 5)
elif key.upper() == "UP":
keys |= (1 << 6)
elif key.upper() == "DOWN":
keys |= (1 << 7)
elif key.upper() == "R":
keys |= (1 << 8)
elif key.upper() == "L":
keys |= (1 << 9)
game["keys"] = keys
if keys > 0:
roms_keys.append(keys)
roms_keys = list(set(roms_keys))
if battery_present and game["save_slot"] is not None: if battery_present and game["save_slot"] is not None:
game["save_type"] = 2 game["save_type"] = 2
game["save_slot"] -= 1 game["save_slot"] -= 1
@@ -215,7 +270,6 @@ for game in games:
# Read ROM data # Read ROM data
games.sort(key=lambda game: game["size"], reverse=True) games.sort(key=lambda game: game["size"], reverse=True)
c = 0
for game in games: for game in games:
found = False found = False
for i in range(save_end_offset, len(sector_map)): for i in range(save_end_offset, len(sector_map)):
@@ -266,33 +320,39 @@ else:
toc_sep = "----+-----------+-----------+--------------------------------------------------" toc_sep = "----+-----------+-----------+--------------------------------------------------"
item_list = bytearray() item_list = bytearray()
for game in games:
title = game["title"]
if len(title) > 0x30: title = title[:0x2F] + ""
table_line = \ for key in roms_keys:
f"{game['index'] + 1:3d} | " \ c = 0
f"0x{game['block_offset'] * block_size:07X} | "\ for game in games:
f"0x{game['block_count'] * block_size:07X} | " if game["keys"] != key: continue
if battery_present:
if game['save_type'] > 0: title = game["title"]
table_line += f"{game['save_slot']+1:2d} (0x{(save_data_sector_offset + game['save_slot']) * sector_size:07X}) | " if len(title) > 0x30: title = title[:0x2F] + ""
else:
table_line += " | " table_line = \
table_line += f"{title}" f"{game['index'] + 1:3d} | " \
if c % 8 == 0: logp(toc_sep) f"0x{game['block_offset'] * block_size:07X} | "\
logp(table_line) f"0x{game['block_count'] * block_size:07X} | "
c += 1 if battery_present:
if game['save_type'] > 0:
title = title.ljust(0x30, "\0") table_line += f"{game['save_slot']+1:2d} (0x{(save_data_sector_offset + game['save_slot']) * sector_size:07X}) | "
item_list += bytearray(struct.pack("B", game["title_font"])) else:
item_list += bytearray(struct.pack("B", len(game["title"]))) table_line += " | "
item_list += bytearray(struct.pack("<H", game["block_offset"])) table_line += f"{title}"
item_list += bytearray(struct.pack("<H", game["block_count"])) if c % 8 == 0: logp(toc_sep)
item_list += bytearray(struct.pack("B", game["save_type"])) logp(table_line)
item_list += bytearray(struct.pack("B", game["save_slot"])) c += 1
item_list += bytearray([0] * 8)
item_list += bytearray(title.encode("UTF-16LE")) title = title.ljust(0x30, "\0")
item_list += bytearray(struct.pack("B", game["title_font"]))
item_list += bytearray(struct.pack("B", len(game["title"])))
item_list += bytearray(struct.pack("<H", game["block_offset"]))
item_list += bytearray(struct.pack("<H", game["block_count"]))
item_list += bytearray(struct.pack("B", game["save_type"]))
item_list += bytearray(struct.pack("B", game["save_slot"]))
item_list += bytearray(struct.pack("<H", game["keys"]))
item_list += bytearray([0] * 6)
item_list += bytearray(title.encode("UTF-16LE"))
compilation[item_list_offset * sector_size:item_list_offset * sector_size + len(item_list)] = item_list compilation[item_list_offset * sector_size:item_list_offset * sector_size + len(item_list)] = item_list
rom_code = "L{:s}".format(hashlib.sha1(status + item_list).hexdigest()[:3]).upper() rom_code = "L{:s}".format(hashlib.sha1(status + item_list).hexdigest()[:3]).upper()
@@ -310,7 +370,7 @@ logp("Menu ROM: 0x{:07X}0x{:07X}".format(0, len(menu_rom)))
logp("Game List: 0x{:07X}0x{:07X}".format(item_list_offset * sector_size, item_list_offset * sector_size + len(item_list))) logp("Game List: 0x{:07X}0x{:07X}".format(item_list_offset * sector_size, item_list_offset * sector_size + len(item_list)))
logp("Status Area: 0x{:07X}0x{:07X}".format(status_offset * sector_size, status_offset * sector_size + 0x1000)) logp("Status Area: 0x{:07X}0x{:07X}".format(status_offset * sector_size, status_offset * sector_size + 0x1000))
logp("") logp("")
logp("Cartridge Type: {:d} ({:s} {:s})".format(cartridge_type, cartridge_types[cartridge_type]["name"], "with battery" if battery_present else "without battery")) logp("Cartridge Type: {:d} ({:s}) {:s}".format(cartridge_type + 1, cartridge_types[cartridge_type]["name"], "with battery" if battery_present else "without battery"))
logp("Output ROM Size: {:.2f} MiB".format(rom_size / 1024 / 1024)) logp("Output ROM Size: {:.2f} MiB".format(rom_size / 1024 / 1024))
logp("Output ROM Code: {:s}".format(rom_code)) logp("Output ROM Code: {:s}".format(rom_code))
output_file = output_file.replace("<CODE>", rom_code) output_file = output_file.replace("<CODE>", rom_code)
@@ -320,7 +380,7 @@ if args.split:
size = 0x2000000 size = 0x2000000
if pos > len(compilation[:rom_size]): break if pos > len(compilation[:rom_size]): break
if pos + size > rom_size: size = rom_size - pos if pos + size > rom_size: size = rom_size - pos
output_file_part = "{:s}_part{:d}{:s}".format(os.path.splitext(output_file)[0], i + 1, os.path.splitext(output_file)[1]) output_file_part = "{:s}_part{:d}{:s}".format(os.path.splitext(output_file)[0], i, os.path.splitext(output_file)[1])
with open(output_file_part, "wb") as f: f.write(compilation[pos:pos+size]) with open(output_file_part, "wb") as f: f.write(compilation[pos:pos+size])
else: else:
with open(output_file, "wb") as f: f.write(compilation[:rom_size]) with open(output_file, "wb") as f: f.write(compilation[:rom_size])

View File

@@ -66,6 +66,22 @@ IWRAM_CODE void FlashDetectType(void)
return; return;
} }
// 1G cart with MSP54LV100S (Zelda Classic Collection 7-in-1)
_FLASH_WRITE(0, 0xF0);
_FLASH_WRITE(0xAAA, 0xA9);
_FLASH_WRITE(0x555, 0x56);
_FLASH_WRITE(0xAAA, 0x90);
data = *(vu32 *)AGB_ROM;
_FLASH_WRITE(0, 0xF0);
if (data == 0x227D0002)
{
REG_IE = ie;
flash_type = 3;
flash_sector_size = 0x20000;
FlashCalcOffsets();
return;
}
// Unknown type // Unknown type
REG_IE = ie; REG_IE = ie;
flash_type = 0; flash_type = 0;
@@ -119,6 +135,24 @@ IWRAM_CODE void FlashEraseSector(u32 address)
} }
_FLASH_WRITE(address, 0xF0F0); _FLASH_WRITE(address, 0xF0F0);
} }
else if (_flash_type == 3)
{
_FLASH_WRITE(0xAAA, 0xA9);
_FLASH_WRITE(0x555, 0x56);
_FLASH_WRITE(0xAAA, 0x80);
_FLASH_WRITE(0xAAA, 0xA9);
_FLASH_WRITE(0x555, 0x56);
_FLASH_WRITE(address, 0x30);
while (1)
{
__asm("nop");
if ((*((vu16 *)(AGB_ROM + address))) == 0xFFFF)
{
break;
}
}
_FLASH_WRITE(address, 0xF0);
}
REG_IE = ie; REG_IE = ie;
} }
@@ -191,6 +225,33 @@ IWRAM_CODE void FlashWriteData(u32 address, u32 length)
} }
_FLASH_WRITE(address, 0xF0F0); _FLASH_WRITE(address, 0xF0F0);
} }
else if (_flash_type == 3)
{
for (int j = 0; j < (int)(length / 0x40); j++)
{
_FLASH_WRITE(0xAAA, 0xA9);
_FLASH_WRITE(0x555, 0x56);
_FLASH_WRITE(address + (j * 0x40), 0x26);
_FLASH_WRITE(address + (j * 0x40), 0x1F);
u16 data = 0;
for (int i = 0; i < 0x40; i += 2)
{
__asm("nop");
data = data_buffer[(j * 0x40) + i + 1] << 8 | data_buffer[(j * 0x40) + i];
_FLASH_WRITE(address + (j * 0x40) + i, data);
}
_FLASH_WRITE(address + (j * 0x40), 0x2A);
while (1)
{
__asm("nop");
if (p_rom[(j * 0x20) + 0x1F] == data)
{
break;
}
}
}
_FLASH_WRITE(address, 0xF0);
}
REG_IE = ie; REG_IE = ie;
} }
@@ -215,14 +276,11 @@ IWRAM_CODE u8 BootGame(ItemConfig config, FlashStatus status)
if (_flash_type == 0) if (_flash_type == 0)
return 1; return 1;
// Temporarily store SRAM values at mapper registers // Temporarily store SRAM values located at mapper registers
if (status.last_boot_save_type == SRAM_NONE) sram_register_backup[0] = *(vu8 *)MAPPER_CONFIG1;
{ sram_register_backup[1] = *(vu8 *)MAPPER_CONFIG2;
sram_register_backup[0] = *(vu8 *)MAPPER_CONFIG1; sram_register_backup[2] = *(vu8 *)MAPPER_CONFIG3;
sram_register_backup[1] = *(vu8 *)MAPPER_CONFIG2; sram_register_backup[3] = *(vu8 *)MAPPER_CONFIG4;
sram_register_backup[2] = *(vu8 *)MAPPER_CONFIG3;
sram_register_backup[3] = *(vu8 *)MAPPER_CONFIG4;
}
// Enable SRAM access // Enable SRAM access
*(vu8 *)MAPPER_CONFIG4 = 1; *(vu8 *)MAPPER_CONFIG4 = 1;
@@ -243,16 +301,16 @@ IWRAM_CODE u8 BootGame(ItemConfig config, FlashStatus status)
FlashEraseSector((_flash_save_block_offset + status.last_boot_save_index) * _flash_sector_size); FlashEraseSector((_flash_save_block_offset + status.last_boot_save_index) * _flash_sector_size);
FlashWriteData((_flash_save_block_offset + status.last_boot_save_index) * _flash_sector_size, SRAM_SIZE); FlashWriteData((_flash_save_block_offset + status.last_boot_save_index) * _flash_sector_size, SRAM_SIZE);
} }
// Save status to flash
status.last_boot_save_index = config.save_index;
status.last_boot_save_type = config.save_type;
memset((void *)data_buffer, 0, 0x1000);
memcpy(data_buffer, &status, sizeof(status));
FlashEraseSector(_flash_status_block_offset * flash_sector_size);
FlashWriteData(_flash_status_block_offset * flash_sector_size, 0x1000);
} }
// Save status to flash
status.last_boot_save_index = config.save_index;
status.last_boot_save_type = config.save_type;
memset((void *)data_buffer, 0, 0x1000);
memcpy(data_buffer, &status, sizeof(status));
FlashEraseSector(_flash_status_block_offset * flash_sector_size);
FlashWriteData(_flash_status_block_offset * flash_sector_size, 0x1000);
// Disable SRAM access // Disable SRAM access
*(vu8 *)MAPPER_CONFIG4 = 0; *(vu8 *)MAPPER_CONFIG4 = 0;

View File

@@ -15,7 +15,6 @@ Author: Lesserkuma (github.com/lesserkuma)
} }
#define MAGIC_FLASH_STATUS 0x414D554B #define MAGIC_FLASH_STATUS 0x414D554B
#define FLASH_STATUS_LOCATION 0xA0000
typedef struct __attribute__((packed)) FlashStatus_ typedef struct __attribute__((packed)) FlashStatus_
{ {

View File

@@ -60,6 +60,7 @@ int main(void) {
u8 redraw_items = 0xFF; u8 redraw_items = 0xFF;
u8 roms_page = 7; u8 roms_page = 7;
u16 kHeld = 0; u16 kHeld = 0;
u16 kHeld_boot = 0;
BOOL show_debug = FALSE; BOOL show_debug = FALSE;
BOOL show_credits = FALSE; BOOL show_credits = FALSE;
BOOL boot_failed = FALSE; BOOL boot_failed = FALSE;
@@ -90,21 +91,32 @@ int main(void) {
SetMode(MODE_4 | BG2_ENABLE); SetMode(MODE_4 | BG2_ENABLE);
dmaCopy(bgBitmap, (void*)AGB_VRAM+0xA000, SCREEN_WIDTH * SCREEN_HEIGHT); dmaCopy(bgBitmap, (void*)AGB_VRAM+0xA000, SCREEN_WIDTH * SCREEN_HEIGHT);
// Count number of ROMs // Check on-boot keys
for (roms_total = 0; roms_total < 512; roms_total++) { scanKeys();
if ((itemlist[(0x70*roms_total+1)] == 0) || (itemlist[(0x70*roms_total+1)] == 0xFF)) break; kHeld = keysHeld();
kHeld_boot = kHeld;
if ((kHeld & KEY_SELECT) && (kHeld & KEY_R)) {
show_credits = TRUE;
} else if (kHeld & KEY_SELECT) {
show_debug = TRUE;
} }
if (roms_total == 0) { if (kHeld) {
LoadFont(2); u16 itemlist_offset = 0;
DrawText(0, 64, ALIGN_CENTER, u"Please use the ROM Builder to", 48, font, (void*)AGB_VRAM+0xA000, FALSE); BOOL found_keys = FALSE;
DrawText(0, 64 + sFontSpecs.max_height, ALIGN_CENTER, u"create your own compilation.", 48, font, (void*)AGB_VRAM+0xA000, FALSE); for (itemlist_offset = 0; itemlist_offset < 0x924; itemlist_offset += 0x70) {
LoadFont(0); memcpy(&sItemConfig, ((u8*)itemlist)+itemlist_offset, sizeof(sItemConfig));
DrawText(0, 127, ALIGN_CENTER, u"https://github.com/lesserkuma/GBA_MultiMenu", 48, font, (void*)AGB_VRAM+0xA000, FALSE); if (sItemConfig.title_length == 0) break;
DrawText(14, SCREEN_HEIGHT - sFontSpecs.max_height - 3 - FontMarginBottom, ALIGN_RIGHT, u"No ROMs", 10, font, (void*)AGB_VRAM+0xA000, FALSE); if (sItemConfig.title_length == 0xFF) break;
REG_DISPCNT ^= 0x0010; if (sItemConfig.keys == kHeld) {
while (1) { VBlankIntrWait(); } itemlist += itemlist_offset;
found_keys = TRUE;
break;
}
}
if (!found_keys) {
kHeld = 0;
}
} }
page_total = (roms_total + 8.0 - 1) / 8.0;
memcpy(&sFlashStatus, (void *)(AGB_ROM + flash_status_sector_offset * flash_sector_size), sizeof(sFlashStatus)); memcpy(&sFlashStatus, (void *)(AGB_ROM + flash_status_sector_offset * flash_sector_size), sizeof(sFlashStatus));
if ((sFlashStatus.magic != MAGIC_FLASH_STATUS) || (sFlashStatus.last_boot_menu_index >= roms_total)) { if ((sFlashStatus.magic != MAGIC_FLASH_STATUS) || (sFlashStatus.last_boot_menu_index >= roms_total)) {
@@ -119,15 +131,29 @@ int main(void) {
page_active = sFlashStatus.last_boot_menu_index / 8; page_active = sFlashStatus.last_boot_menu_index / 8;
} }
// Check on-boot keys // Count number of ROMs
scanKeys(); for (roms_total = 0; roms_total < 512; roms_total++) {
kHeld = keysHeld(); memcpy(&sItemConfig, ((u8*)itemlist)+(0x70*roms_total), sizeof(sItemConfig));
if ((kHeld & KEY_SELECT) && (kHeld & KEY_R)) { if (sItemConfig.keys != kHeld) break;
show_credits = TRUE; if (sItemConfig.title_length == 0) break;
} else if (kHeld & KEY_SELECT) { if (sItemConfig.title_length == 0xFF) break;
show_debug = TRUE;
} }
if (roms_total == 0) {
LoadFont(2);
DrawText(0, 64, ALIGN_CENTER, u"Please use the ROM Builder to", 48, font, (void*)AGB_VRAM+0xA000, FALSE);
DrawText(0, 64 + sFontSpecs.max_height, ALIGN_CENTER, u"create your own compilation.", 48, font, (void*)AGB_VRAM+0xA000, FALSE);
LoadFont(0);
DrawText(0, 127, ALIGN_CENTER, u"https://github.com/lesserkuma/GBA_MultiMenu", 48, font, (void*)AGB_VRAM+0xA000, FALSE);
DrawText(14, SCREEN_HEIGHT - sFontSpecs.max_height - 3 - FontMarginBottom, ALIGN_RIGHT, u"No ROMs", 10, font, (void*)AGB_VRAM+0xA000, FALSE);
REG_DISPCNT ^= 0x0010;
while (1) { VBlankIntrWait(); }
} else if (roms_total == 1) {
memcpy(&sItemConfig, ((u8*)itemlist), sizeof(sItemConfig));
u8 error_code = BootGame(sItemConfig, sFlashStatus);
boot_failed = error_code;
}
page_total = (roms_total + 8.0 - 1) / 8.0;
s32 wait = 0; s32 wait = 0;
u8 f = 0; u8 f = 0;
while (1) { while (1) {
@@ -212,6 +238,11 @@ int main(void) {
// Check for menu keys // Check for menu keys
scanKeys(); scanKeys();
kHeld = keysHeld(); kHeld = keysHeld();
if ((kHeld_boot == 0) || (kHeld != kHeld_boot)) {
kHeld_boot = 0;
} else {
kHeld = 0;
}
if (kHeld != 0) { if (kHeld != 0) {
wait++; wait++;
} else { } else {
@@ -233,13 +264,15 @@ int main(void) {
sFlashStatus.last_boot_menu_index = page_active * 8 + cursor_pos; sFlashStatus.last_boot_menu_index = page_active * 8 + cursor_pos;
if (!show_credits && !show_debug) { if (!show_credits && !show_debug) {
LoadFont(0); LoadFont(0);
if (sFlashStatus.battery_present == 1) { DrawText(5, SCREEN_HEIGHT - sFontSpecs.max_height - 3 - FontMarginBottom, ALIGN_LEFT, u"Loading… Don't turn off the power!", 48, font, (void*)AGB_VRAM+0xA000, FALSE);
DrawText(5, SCREEN_HEIGHT - sFontSpecs.max_height - 3 - FontMarginBottom, ALIGN_LEFT, u"Loading… Don't turn off the power!", 48, font, (void*)AGB_VRAM+0xA000, FALSE);
}
REG_DISPCNT ^= 0x0010; REG_DISPCNT ^= 0x0010;
dmaCopy((void*)AGB_VRAM+0xA000, (void*)AGB_VRAM, SCREEN_WIDTH * SCREEN_HEIGHT); dmaCopy((void*)AGB_VRAM+0xA000, (void*)AGB_VRAM, SCREEN_WIDTH * SCREEN_HEIGHT);
REG_DISPCNT ^= 0x0010; REG_DISPCNT ^= 0x0010;
} }
if (kHeld & KEY_SELECT) {
// Skips reading latest save data from SRAM
sFlashStatus.last_boot_save_type = SRAM_NONE;
}
u8 error_code = BootGame(sItemConfig, sFlashStatus); u8 error_code = BootGame(sItemConfig, sFlashStatus);
boot_failed = error_code; boot_failed = error_code;
redraw_items = 0xFF; redraw_items = 0xFF;

View File

@@ -66,7 +66,7 @@ typedef struct ItemConfig_
u16 rom_size; u16 rom_size;
SAVE_TYPE save_type; SAVE_TYPE save_type;
u8 save_index; u8 save_index;
u16 index; u16 keys;
u8 reserved[6]; u8 reserved[6];
u16 title[0x30]; u16 title[0x30];
} ItemConfig; } ItemConfig;