From 76092e90937808b87e0b2c5314cb1c8c7f33046b Mon Sep 17 00:00:00 2001 From: Harrison <53527582+HTV04@users.noreply.github.com> Date: Mon, 22 Feb 2021 01:26:52 -0500 Subject: [PATCH] gba_db_builder Improvements Also fix gba_db.bin --- resources/gba_db.bin | Bin 686508 -> 686508 bytes resources/gba_db_builder.py | 133 ++++++++++++++++++++---------------- 2 files changed, 73 insertions(+), 60 deletions(-) diff --git a/resources/gba_db.bin b/resources/gba_db.bin index 743360f5a1b5cdea472b031c82a0a663ad82b294..41fd2e166ee489a727f1f3e93b2b6e7348cbdbcc 100644 GIT binary patch delta 1420 zcmXApU2IfU5XW=w=ehJssjRkQ6$k~kv=UAFKq9fXxC=`x@jg^3X~8vYZ3{F(sbT`g zjp1PHsZ{jr(fpd{Ljps zxwn6=vVX3!dyIt#a+etk_w;I$EIjzOekcGal&&fUl&w9Z0Y)n^W3a0VV?Er%#2Ih7 z4R9l3DInc+(1lQW8-y;jQ+9R_x(2<2lraAO^N)g6{>7Fj0kKSG9iZaYpB&)MjX8kv z1-XocWp^oi)&l09V5lQ|m$TbTfbpl9jZApT?{8u~MPN^DV|ZMi-_Ew1K)#cGr~{Kx zq6o$q6eZji!mPse*T@=fC8XL2@peLN4?;%vvb|3Mhm!2CGGKZ@>DGM3URVQy@n0z| zmS?X#0^!lW*|o=j$s!GBCPRz0+AY8%FKJ7I=zm8$w+I+XXa@}7NSF5eGa!@t7UwSF z8A9w5A@UtUR)4RNcGnH9b}`twKh#<8meQInXt%e5KmVNmZaJ{INymYTP)x_;!4{pa zO10}(OTgZDNS|B5>SQ#frMUsCqxr*$g4{;cBsIsL`;a4K?BFT(yC?kKhF zeZA=+uq(Jh>Pgq2xzCmuM{B@;c(XCI%%}@D`m*L#WB1G8N=k#CGJ4U#4U+kv3|t<$ zaNW?M-j9DXu#PE$%-%G{HbJm=rAhU86^b)!On6sc9A0NmGG9ikOnMeSWI|Ig?-uj3 zRluo)Niz$bFli>E-FV^5qAzXSIMMwBg*$(==>a!p z6^$!4e!z0HV5{NYvuQ5b1$Dghfhs9f!m*a%!yLa2u~0?kL^YXmXfvlNy7m0{ql^qYKbDTJ4Nz;Rn-;3G~y2>-aU8&0Xbjs2YF6Zl!lMx^djQSpD3+7aEs!N{4QL;IDlbLiVE_Z6FWIrQY!`yEmnf5UGlI0Atk{G1OgyXT99Rz!`73 z4RB*(DIn9d--V;fb~rlSLD9KA=o<3&Q^3S~Pu&kz zh$5U|P?T_639|}UULtFxjgW39Bs&O+JqQ`w%l1AB91hr@6~N4(%3F7aJ+m4TCV!!@ zM1j3<9~_VU#V$X<;xZ`FP%{}>tkrJ;z8lw;hJnFb+Q~)0SW0`%0FHKRzda6V(&tcj zk<1bj=LxZI5wi9>jdFKi)#?{R?)>j~H!i&!D%WgLyZJQ46`s`Jt^_tW=_sg(By_wU zZq@0jbccSa4D6Q==yQ*-sBB5=I2tk0k6~i;7)5`6T&KbtPAJZw)Sq1kw_?}y670Y6 zmdcj9qc`0Hb`>`$d*B+R`)rwUs1E!GHygvtjA;D1YFYQ9v3nc10%_1FTfQ-HgJj`H z1D8iGTrqU0_oH78tYexWbJvXVP0(cD3KQyqW~&ruR+})_s5rRRoWdq*Od5+HF`+5Y zyVd+`C2%@rl4g-lP10oStVw0A&#JiENlXL!Pno!GqU%3M=gS>;@fBYfnuWDoC&;{R z(e90etkUNpD%WYzE5!gt^iJ#+cW@gm5tMu;dM3^ zA?E9CEWO|%wHZ)94~pF!?wg_=tE9F2>*z(8;@d~FEjLmX<+RybJ~!WBBvhRe~4n_HdZ6jcc`f3znBfaSKUEjmWg^*qp--ww&*ENEt6sVKW~q2A??UH_-27cS9U^7iBvC E2T}3&W&i*H diff --git a/resources/gba_db_builder.py b/resources/gba_db_builder.py index 148bdfe..5579749 100644 --- a/resources/gba_db_builder.py +++ b/resources/gba_db_builder.py @@ -1,4 +1,4 @@ -# open_agb_firm gba_db.bin Builder +# open_agb_firm gba_db.bin Builder v1.1 # By HTV04 # This script parses MAME's gba.xml (found here: https://github.com/mamedev/mame/blob/master/hash/gba.xml) and converts it to a gba_db.bin file for open_agb_firm. @@ -8,65 +8,78 @@ import math import xml.etree.ElementTree as ET -root = ET.parse('gba.xml').getroot() - -gbadb = b'' - -for software in root.findall('software'): - # Obtain title - gbadb = gbadb + software.find('description').text.encode().ljust(200, b'\x00') # Pad to 200 bytes with null bytes +# Use title, title ID, SHA-1, size, and save type to generate gba_db.bin entry as binary string +def gbadbentry(title, titleid, sha, size, savetype): + entry = b'' - # Obtain title ID - titleid = b'\x00\x00\x00\x00' # If a title ID can't be found, default to null bytes - for info in software.findall('info'): - if info.get('name') == 'serial': - for i in info.get('value').split('-'): # Hacky script that checks for the part of the serial that has 4 characters, since serials vary - s = i.strip().encode() - if len(s) == 4: - titleid = s - - break - gbadb = gbadb + titleid + entry += title.encode().ljust(200, b'\x00') # Pad to 200 bytes with null bytes + entry += titleid.encode() + entry += bytes.fromhex(sha) + entry += (int(math.log(size, 2)) << 27 | savetype).to_bytes(4, 'little') # Save type is stored weirdly - for part in software.findall('part'): - if part.get('name') == 'cart': - # Obtain SHA-1 - for dataarea in part.findall('dataarea'): - if dataarea.get('name') == 'rom': - size = int(dataarea.get('size'), 0) - - gbadb = gbadb + bytes.fromhex(dataarea.find('rom').get('sha1')) - - break - - # Obtain save type - savetype = 15 # If a save type can't be found or is unknown, set to "SAVE_TYPE_NONE" - for feature in software.findall('feature'): - if feature.get('name') == 'slot': - slottype = feature.get('value') - if slottype == 'gba_eeprom_4k': - savetype = 0 # SAVE_TYPE_EEPROM_8k - if size > 16777216: # If greater than 16 MB, change save type - savetype += 1 # SAVE_TYPE_EEPROM_8k_2 - elif slottype == 'gba_eeprom_64k': - savetype = 2 # SAVE_TYPE_EEPROM_64k - if size > 16777216: # If greater than 16 MB, change save type - savetype += 1 # SAVE_TYPE_EEPROM_64k_2 - elif slottype == 'gba_flash_rtc': - savetype = 8 # SAVE_TYPE_FLASH_512k_PSC_RTC - elif slottype == 'gba_flash_512': - savetype = 9 # SAVE_TYPE_FLASH_512k_PSC - elif slottype == 'gba_flash_1m_rtc': - savetype = 10 #SAVE_TYPE_FLASH_1m_MRX_RTC - elif slottype == 'gba_flash_1m': - savetype = 11 # SAVE_TYPE_FLASH_1m_MRX - elif slottype == 'gba_sram': - savetype = 14 # SAVE_TYPE_SRAM_256k - - break - - gbadb = gbadb + (int(math.log(size, 2)) << 27 | savetype).to_bytes(4, 'little') # Save type is stored weirdly + return entry -# Create and write to gba_db.bin -with open('gba_db.bin', 'wb') as f: - f.write(gbadb) +if __name__ == '__main__': + root = ET.parse('gba.xml').getroot() + + gbadb = b'' + + for software in root.findall('software'): + # Obtain title + title = software.find('description').text + + # Obtain title ID + titleid = '\x00\x00\x00\x00' # If a title ID can't be found, default to null bytes + for info in software.findall('info'): + if info.get('name') == 'serial': + for i in info.get('value').split('-'): # Hacky script that checks for the first part of the serial that has 4 characters, since serials vary + s = i.strip() + if len(s) == 4: + titleid = s + + break + + break + + for part in software.findall('part'): + if part.get('name') == 'cart': + # Obtain SHA-1 + for dataarea in part.findall('dataarea'): + if dataarea.get('name') == 'rom': + size = int(dataarea.get('size'), 0) # Base 0 so int can decide whether string is decimal or hex + + sha = dataarea.find('rom').get('sha1') + + break + + # Obtain save type + savetype = 15 # If a save type can't be found or is unknown, set to "SAVE_TYPE_NONE" + for feature in software.findall('feature'): + if feature.get('name') == 'slot': + slottype = feature.get('value') + if slottype == 'gba_eeprom_4k': + savetype = 0 # SAVE_TYPE_EEPROM_8k + if size > 16777216: # If greater than 16 MB, change save type + savetype += 1 # SAVE_TYPE_EEPROM_8k_2 + elif slottype == 'gba_eeprom_64k': + savetype = 2 # SAVE_TYPE_EEPROM_64k + if size > 16777216: # If greater than 16 MB, change save type + savetype += 1 # SAVE_TYPE_EEPROM_64k_2 + elif slottype == 'gba_flash_rtc': + savetype = 8 # SAVE_TYPE_FLASH_512k_PSC_RTC + elif slottype == 'gba_flash_512': + savetype = 9 # SAVE_TYPE_FLASH_512k_PSC + elif slottype == 'gba_flash_1m_rtc': + savetype = 10 #SAVE_TYPE_FLASH_1m_MRX_RTC + elif slottype == 'gba_flash_1m': + savetype = 11 # SAVE_TYPE_FLASH_1m_MRX + elif slottype == 'gba_sram': + savetype = 14 # SAVE_TYPE_SRAM_256k + + break + + gbadb += gbadbentry(title, titleid, sha, size, savetype) + + # Create and write to gba_db.bin + with open('gba_db.bin', 'wb') as f: + f.write(gbadb)