From a5bcc7da17a348009122640f1f01ffb17d43e1b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Le=20Bihan?= Date: Sun, 11 Jul 2021 17:52:27 +0200 Subject: [PATCH] adding python script --- {Utils => utils}/pythonvram.py | 78 ++++++++++++++++++---------------- 1 file changed, 41 insertions(+), 37 deletions(-) rename {Utils => utils}/pythonvram.py (50%) diff --git a/Utils/pythonvram.py b/utils/pythonvram.py similarity index 50% rename from Utils/pythonvram.py rename to utils/pythonvram.py index 45674ea..e5babb5 100755 --- a/Utils/pythonvram.py +++ b/utils/pythonvram.py @@ -1,10 +1,11 @@ +#!/usr/bin/env python3 + # python script to convert tile indexes to correct values in vram depending on the bpp def getVRAMValue2bpp(nums): vramValues = [] - - + valHex1 = 0 valHex2 = 0 for i in nums: @@ -15,62 +16,65 @@ def getVRAMValue2bpp(nums): valHex1 += (j & 1) << shift valHex2 += ((j & 2) >> 1) << shift shift -= 1 - + vramValues.append((valHex1 << 8) + valHex2) - + padding = 4 for i in vramValues: - print('{0:0{1}X}'.format(i, 4), end=' ') + print(f"{i:0{padding}X}", end=' ') print("") + def getVRAMValue4bpp(nums): getVRAMValue2bpp(extract2BppBitPlans(nums, 0)) getVRAMValue2bpp(extract2BppBitPlans(nums, 1)) + def getVRAMValue8bpp(nums): getVRAMValue2bpp(extract2BppBitPlans(nums, 0)) getVRAMValue2bpp(extract2BppBitPlans(nums, 1)) getVRAMValue2bpp(extract2BppBitPlans(nums, 2)) getVRAMValue2bpp(extract2BppBitPlans(nums, 3)) + def extract2BppBitPlans(nums, index): high = [] for i in nums: high.append([(j & (0x3 << (2 * index))) >> (index * 2) for j in i]) return high - -result2 = [ - [0, 1, 1, 1, 1, 1, 0, 0], - [1, 2, 3, 3, 3, 2, 1, 0], - [1, 2, 3, 3, 3, 2, 1, 0], - [0, 1, 1, 1, 1, 1, 0, 0], - [0, 0, 0, 1, 0, 0, 0, 0], - [1, 1, 0, 1, 0, 1, 1, 0], - [0, 1, 1, 1, 1, 1, 0, 0], - [0, 0, 1, 1, 1, 0, 0, 0] - ] - -result2 = [ - [0, 7, 7, 7, 7, 7, 0, 0], - [7, 2, 6, 8, 6, 2, 7, 0], - [7, 2, 2, 2, 2, 2, 7, 0], - [0, 7, 7, 7, 7, 7, 0, 0], - [0, 0, 0, 4, 0, 0, 0, 0], - [3, 5, 0, 5, 0, 5, 3, 0], - [0, 3, 4, 5, 4, 3, 0, 0], - [0, 0, 3, 3, 3, 0, 0, 0], - ] + result2 = [ - [0x00, 0x22, 0x22, 0x22, 0x23, 0x23, 0x00, 0x00], - [0x22, 0x11, 0x42, 0x21, 0x41, 0x11, 0x24, 0x00], - [0x23, 0x11, 0x12, 0x12, 0x12, 0x12, 0x24, 0x00], - [0x00, 0x24, 0x25, 0x25, 0x25, 0x25, 0x00, 0x00], - [0x00, 0x00, 0x00, 0x33, 0x00, 0x00, 0x00, 0x00], - [0x35, 0x32, 0x00, 0x31, 0x00, 0x31, 0x35, 0x00], - [0x00, 0x34, 0x33, 0x31, 0x33, 0x34, 0x00, 0x00], - [0x00, 0x00, 0x35, 0x36, 0x36, 0x00, 0x00, 0x00] - ] + [0, 1, 1, 1, 1, 1, 0, 0], + [1, 2, 3, 3, 3, 2, 1, 0], + [1, 2, 3, 3, 3, 2, 1, 0], + [0, 1, 1, 1, 1, 1, 0, 0], + [0, 0, 0, 1, 0, 0, 0, 0], + [1, 1, 0, 1, 0, 1, 1, 0], + [0, 1, 1, 1, 1, 1, 0, 0], + [0, 0, 1, 1, 1, 0, 0, 0] +] + +result2 = [ + [0, 7, 7, 7, 7, 7, 0, 0], + [7, 2, 6, 8, 6, 2, 7, 0], + [7, 2, 2, 2, 2, 2, 7, 0], + [0, 7, 7, 7, 7, 7, 0, 0], + [0, 0, 0, 4, 0, 0, 0, 0], + [3, 5, 0, 5, 0, 5, 3, 0], + [0, 3, 4, 5, 4, 3, 0, 0], + [0, 0, 3, 3, 3, 0, 0, 0], +] + +result2 = [ + [0x00, 0x22, 0x22, 0x22, 0x23, 0x23, 0x00, 0x00], + [0x22, 0x11, 0x42, 0x21, 0x41, 0x11, 0x24, 0x00], + [0x23, 0x11, 0x12, 0x12, 0x12, 0x12, 0x24, 0x00], + [0x00, 0x24, 0x25, 0x25, 0x25, 0x25, 0x00, 0x00], + [0x00, 0x00, 0x00, 0x33, 0x00, 0x00, 0x00, 0x00], + [0x35, 0x32, 0x00, 0x31, 0x00, 0x31, 0x35, 0x00], + [0x00, 0x34, 0x33, 0x31, 0x33, 0x34, 0x00, 0x00], + [0x00, 0x00, 0x35, 0x36, 0x36, 0x00, 0x00, 0x00] +] getVRAMValue8bpp(result2) -