Skip to content

Commit

Permalink
- Add the backend code for changing shortcut text.
Browse files Browse the repository at this point in the history
- Fix a typo in the readme and small structure changes to the readme
  • Loading branch information
EricGoldsteinNz authored and EricGoldsteinNz committed Dec 28, 2023
1 parent aaf8a8c commit 9c45f48
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 37 deletions.
9 changes: 3 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Tadpole

by EricGoldstein

Tadpole is a device management tool for rthe SF2000 / Datafrog. It currently provides the following main features:
Tadpole is a device management tool for the SF2000 / Datafrog. It currently provides the following main features:
* Rebuilding of the console specific rom lists
* Changing the firmware to official releases or multicore (including rebuilding multicore gamelists)
* Merging ROM zips and jpg files with the same name to the relevant Zxx fileformat for each console
Expand All @@ -26,12 +26,9 @@ in the proper system categories instead of only being able to add them in the us
DISCLAIMER
----------

This program is experimental and you should use with caution!
This program is not developed or authorised by any company or individual connected with the SF2000 handheld and is based on public reverse engineering of SF2000 file formats.

It is not developed or authorised by any company or individual connected with the SF2000 handheld and is based on public
reverse engineering of SF2000 file formats.

Although it will back up the files it modifies, you should make your own backup of the Resources folder and ideally your
You should make your own backups of the Resources and bios folders and ideally your
whole SD card so you can restore the original state of your device if anything goes wrong.


Expand Down
4 changes: 2 additions & 2 deletions build.bat
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@echo off
set ver=1.3.2
set ver=1.3.3
rem build script for the distributable versions of tadpole
if not exist "venv\" (
python -m venv venv
Expand All @@ -13,4 +13,4 @@ if not exist "venv\Lib\site-packages\PIL" (
if not exist "venv\Lib\site-packages\PyQt5" (
venv\Scripts\python -m pip install PyQt5
)
python -m PyInstaller tadpole.py -n tadpole-%ver%.exe --onefile -F --icon frog.ico --clean --noconsole --version-file versioninfo --add-data="frog.ico;." --add-data="README.md;."
pyinstaller tadpole.py -n tadpole-%ver%.exe -F --icon frog.ico --clean --noconsole --version-file versioninfo --add-data="frog.ico;." --add-data="README.md;."
4 changes: 2 additions & 2 deletions tadpole.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,8 @@ def create_actions(self):

def testFunction(self):
drive = self.combobox_drive.currentText()
tadpole_functions.updateShortcutTextforConsole(drive, tadpole_functions._static_shortcut_ARCADE, "test1", "test2", "test3", "test4")

tadpole_functions.updateShortcutTextforConsole(drive, tadpole_functions._static_shortcut_ARCADE, "Call", "games", "anything", "you want")
print("finished test function")

def loadMenus(self):
self.menu_file = self.menuBar().addMenu("&File")
Expand Down
44 changes: 21 additions & 23 deletions tadpole_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import time

try:
from PIL import Image, ImageDraw
from PIL import Image, ImageDraw, ImageFont
image_lib_avail = True
except ImportError:
Image = None
Expand Down Expand Up @@ -1080,27 +1080,23 @@ def updateShortcutTextforConsole(drive: str, console: int, game1:str, game2:str,
raise Exception_InvalidConsole
gakne_path = os.path.join(drive, "Resources", "gakne.ctp")
try:
shortcutText = openBRGAasImage(gakne_path)
shortcutNewText = ImageDraw.Draw(Image.new("RGBA", (144, 32), (255, 255, 255, 255)))
shortcutNewText.text((0,0), game1, (255,255,255))
shortcutText.paste(shortcutNewText, (0,0), shortcutNewText)
shortcutNewText = ImageDraw.Draw(Image.new("RGBA", (144, 32), (255, 255, 255, 255)))
shortcutNewText.text((0,0), game2, (255,255,255))
shortcutText.paste(shortcutNewText, (0,0), shortcutNewText)
shortcutNewText = ImageDraw.Draw(Image.new("RGBA", (144, 32), (255, 255, 255, 255)))
shortcutNewText.text((0,0), game3, (255,255,255))
shortcutText.paste(shortcutNewText, (0,0), shortcutNewText)
shortcutNewText = ImageDraw.Draw(Image.new("RGBA", (144, 32), (255, 255, 255, 255)))
shortcutNewText.text((0,0), game4, (255,255,255))
shortcutText.paste(shortcutNewText, (0,0), shortcutNewText)

# Gakne is made up of 8 rows of 4 items for a total of 32 items.
# Each image is 144 x 32. Total image size 576 x 256.
# To only strip the shortcut text we want to leave the settings menu items. So we have to skip the first 18,432 bytes
# Console order: FC, SFC, MD, GB, GBC, GBA, ARCADE

newText = [game1,game2,game3,game4]
shortcutText = openBRGAasImage(gakne_path)
replaceMask = Image.new("RGBA", (144, 32), (255, 255, 255, 255))
fnt = ImageFont.truetype("arial.ttf", 24)
for i in range(len(newText)):
#Game Slot 1
img_g = Image.new("RGBA", (144, 32), (0, 0, 0, 0)) #In the alpha channel 0 is fully transparent, 255 is fully opaque
ImageDraw.Draw(img_g).text((72,16), newText[i], (255,255,255),font=fnt, anchor="mm")
shortcutText.paste(img_g, (144*i,(console+1)*32), replaceMask)

shortcutText.save("C:\\Users\\OEM\\Documents\\test.png")
# TODO XXXXXX
writeImagetoBGRAfile(gakne_path)
writeImagetoBGRAfile(shortcutText, gakne_path)
return True
except (OSError, IOError) as e:
print(f"! Failed updating shortcut labels. {e}")
Expand All @@ -1111,10 +1107,10 @@ def openBRGAasImage(inputFile):
with open(inputFile, 'rb') as file:
data = file.read()
# Unpack the BGRA8888 data
pixels = struct.unpack('<' + ('H' * (len(data) // 2)), data)
pixels = struct.unpack('>' + ('L' * (len(data) // 4)), data)
# Convert the BGRA8888 values to RGBA888 format
rgba8888_pixels = [
((pixel & 0xFF000000) >> 16, (pixel & 0x00FF0000) >> 8, (pixel & 0x0000FF00), (pixel & 0x000000FF))
((pixel & 0x0000FF00) >> 8, (pixel & 0x00FF0000) >> 16, (pixel & 0xFF000000) >> 24, (pixel & 0x000000FF))
for pixel in pixels
]
# Create an image from the pixels
Expand All @@ -1124,6 +1120,7 @@ def openBRGAasImage(inputFile):
image.putdata(rgba8888_pixels)
return image

#TODO why is it all coming out yellow???
def writeImagetoBGRAfile(image:Image, outfile:str):
try:
dest_file = open(outfile, "wb")
Expand All @@ -1134,7 +1131,7 @@ def writeImagetoBGRAfile(image:Image, outfile:str):
if not pixels:
logging.error(f"tadpole_functions~writeImagetoBGRAfile: Failed to load image")
return False

data = []
for h in range(image_height):
for w in range(image_width):
pixel = pixels[w, h]
Expand All @@ -1145,9 +1142,10 @@ def writeImagetoBGRAfile(image:Image, outfile:str):
g = pixel[1]
b = pixel[2]
a = pixel[3]
bgra = (b << 24) | (g << 16) | (r << 8) | a
outfile.write(struct.pack('H', bgra))
outfile.close()
bgra = (b) | (g << 16) | (r << 8) | (a << 24)
data.append(struct.pack('>L', bgra))
dest_file.write(b''.join(data))
dest_file.close()
return True
except (OSError, IOError):
logging.error(f"tadpole_functions~writeImagetoBGRAfile: Failed opening image file {outfile} for conversion")
Expand Down
8 changes: 4 additions & 4 deletions versioninfo
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
VSVersionInfo(
ffi=FixedFileInfo(
filevers=(1, 3, 2, 0),
prodvers=(1, 3, 2, 0),
filevers=(1, 3, 3, 0),
prodvers=(1, 3, 3, 0),
mask=0x3f,
flags=0x0,
OS=0x4,
Expand All @@ -15,12 +15,12 @@ VSVersionInfo(
u'080904B0',
[StringStruct(u'CompanyName', u'EricGoldstein'),
StringStruct(u'FileDescription', u'tadpole'),
StringStruct(u'FileVersion', u'1.3.2'),
StringStruct(u'FileVersion', u'1.3.3'),
StringStruct(u'InternalName', u'tadpole'),
StringStruct(u'LegalCopyright', u'by EricGoldstein 2023'),
StringStruct(u'OriginalFilename', u'tadpole.exe'),
StringStruct(u'ProductName', u'tadpole'),
StringStruct(u'ProductVersion', u'1.3.2')])
StringStruct(u'ProductVersion', u'1.3.3')])
]),
VarFileInfo([VarStruct(u'Translation', [2057, 1200])])
]
Expand Down

0 comments on commit 9c45f48

Please sign in to comment.