Skip to content

Instantly share code, notes, and snippets.

@jsmolina
Created January 8, 2021 08:32
Show Gist options
  • Save jsmolina/c023422d6824f5d59e6a10b553088c13 to your computer and use it in GitHub Desktop.
Save jsmolina/c023422d6824f5d59e6a10b553088c13 to your computer and use it in GitHub Desktop.
python3 script to determine which number corresponds to the specific zx spectrum color + paper + flash + bright
# python3 script to determine
# 1 flash, 1 bit bright,3 bits paper,3 bits ink
if __name__ == '__main__':
colors = {
"INK_BLACK": 0x00,
"INK_BLUE": 0x01,
"INK_RED": 0x02,
"INK_MAGENTA": 0x03,
"INK_GREEN": 0x04,
"INK_CYAN": 0x05,
"INK_YELLOW": 0x06,
"INK_WHITE": 0x07,
"PAPER_BLACK": 0x00,
"PAPER_BLUE": 0x08,
"PAPER_RED": 0x10,
"PAPER_MAGENTA": 0x18,
"PAPER_GREEN": 0x20,
"PAPER_CYAN": 0x28,
"PAPER_YELLOW": 0x30,
"PAPER_WHITE": 0x38,
"BRIGHT": 0x40,
"FLASH": 0x80,
}
ink = ""
paper = ""
bright = ""
flash = ""
VALID_COLORS = ("black", "blue", "red", "magenta", "green", "cyan", "yellow", "white")
VALID_ANSWERS = ("y", "n")
while ink not in VALID_COLORS:
ink = input("Input ink (black, blue, red, magenta, green, cyan, yellow, white): ")
ink = ink.strip()
while paper not in VALID_COLORS:
paper = input("Input paper (black, blue, red, magenta, green, cyan, yellow, white): ")
paper = paper.strip()
while bright not in VALID_ANSWERS:
bright = input("bright? (y/n) ")
while flash not in VALID_ANSWERS:
flash = input("flash? (y/n) ")
bright_value = 0
flash_value = 0
ink_value = colors.get('INK_{}'.format(ink.upper()))
paper_value = colors.get('PAPER_{}'.format(paper.upper()))
if bright == 'y':
bright_value = colors.get('BRIGHT')
if flash == 'y':
bright_value = colors.get('FLASH')
print("Result: ")
result = (ink_value | paper_value | bright_value | flash_value)
print("decimal: {} - hex: 0x{:02x} - binary: {:08b}".format(result, result, result))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment