pub const fn to_sprite_pointer(address: u16) -> u8Expand description
Calculate sprite pointer from pattern address
To make a given sprite show the pattern that’s stored in RAM at address
(which must be divisible with 64), set the contents of the corresponding
sprite pointer address to address divided by 64. For instance, if the sprite pattern
begins at address 704, the pointer value will be 704 / 64 = 11.
§Examples
const SPRITE_ADDRESS: u16 = 0x2000;
const SPRITE_PTR: u8 = to_sprite_pointer(SPRITE_ADDRESS);When called as const, assertions are done at compile time:
ⓘ
const INVALID_SPRITE_ADDRESS: u16 = 0x2001; // compile time error§Image conversion
Image files can be converted using ImageMagick:
convert image.png -alpha off -resize 24x21! -monochrome sprite.pngand then converted into a byte array using Python:
import numpy as np
from PIL import Image
image = Image.open('sprite.png')
bits = (~np.asarray(image).reshape(int(24*21/8), 8))
for bits_in_byte in bits.astype(int):
print(int(''.join('01'[i] for i in bits_in_byte), 2), end=',')