import sys
import Image
from array import array
from encode import encode


def main():
    font88 = array('B', open("font8x8").read())
    picdata = array('B', [0] * 4096)
    chrdata = array('B', [0] * 4096)
    paldata = array('B', [0] * 2048)
    for i in range(256):
        paldata[8 * i:8 * (i + 1)] = array('B', [0x00,0x0f,255,255,255,255,255,255])
    for i,c in enumerate(font88):
        chrdata[32 * 16 + 2 * i] = c >> 4
        chrdata[32 * 16 + 2 * i + 1] = c & 0xf
        # inversion video versions
        chrdata[2048 + 32 * 16 + 2 * i] = 0xf ^ (c >> 4)
        chrdata[2048 + 32 * 16 + 2 * i + 1] = 0xf ^ (c & 0xf)
        
    mem = array('B', [0] * 16384)
    mem[0:0x1000] = picdata
    mem[0x1000:0x2000] = chrdata
    mem[0x2000:0x2800] = paldata

    mem[0] = ord('a')
    mem[63] = ord('b')
    mem[63 * 64] = ord('c')
    mem[63 * 64 + 63] = ord('d')
    mem[10] = 0x80 + ord('A')
    mem[11] = 0x80 + ord('B')

    memf = open("standard" + ".mem", "w")
    print >>memf, "@ 0"
    for b in mem[0:0x2800]:
        print >>memf, "%02x" % b

if __name__ == "__main__":
    main()
