Makefile: generate font image programmatically
This commit is contained in:
parent
ee9f81c8d5
commit
8ddecc8920
3 changed files with 80 additions and 0 deletions
18
Makefile
18
Makefile
|
|
@ -1,12 +1,30 @@
|
||||||
.PHONY: all
|
.PHONY: all
|
||||||
all: 80columns-compressed.prg 80c2-compressed.prg 80c3-compressed.prg 80c4-compressed.prg
|
all: 80columns-compressed.prg 80c2-compressed.prg 80c3-compressed.prg 80c4-compressed.prg
|
||||||
|
|
||||||
|
.INTERMEDIATE: charset.bin
|
||||||
|
charset.bin: charset.o charset.cfg
|
||||||
|
ld65 -C charset.cfg $< -o $@
|
||||||
|
|
||||||
|
charset%.bin: charset%.o charset.cfg
|
||||||
|
ld65 -C charset.cfg $< -o $@
|
||||||
|
|
||||||
%-compressed.prg: %-uncompressed.prg
|
%-compressed.prg: %-uncompressed.prg
|
||||||
exomizer sfx 51200 -q -n -o $@ $<
|
exomizer sfx 51200 -q -n -o $@ $<
|
||||||
|
|
||||||
%-uncompressed.prg: %.bin
|
%-uncompressed.prg: %.bin
|
||||||
(printf '\0\310'; cat $<) > $@
|
(printf '\0\310'; cat $<) > $@
|
||||||
|
|
||||||
|
.PHONY: update-font-images
|
||||||
|
update-font-images: charset.bin charset2.bin charset3.bin charset4.bin mkfontimg.py
|
||||||
|
python mkfontimg.py -l charset.bin img/t1.png
|
||||||
|
python mkfontimg.py charset.bin img/g1.png
|
||||||
|
python mkfontimg.py -l charset2.bin img/t2.png
|
||||||
|
python mkfontimg.py charset2.bin img/g2.png
|
||||||
|
python mkfontimg.py -l charset3.bin img/t3.png
|
||||||
|
python mkfontimg.py charset3.bin img/g3.png
|
||||||
|
python mkfontimg.py -l charset4.bin img/t4.png
|
||||||
|
python mkfontimg.py charset4.bin img/g4.png
|
||||||
|
|
||||||
.INTERMEDIATE: 80columns.bin
|
.INTERMEDIATE: 80columns.bin
|
||||||
80columns.bin: 80columns.o charset.o 80columns.cfg
|
80columns.bin: 80columns.o charset.o 80columns.cfg
|
||||||
ld65 -C 80columns.cfg $(filter %.o,$^) -o $@
|
ld65 -C 80columns.cfg $(filter %.o,$^) -o $@
|
||||||
|
|
|
||||||
7
charset.cfg
Normal file
7
charset.cfg
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
MEMORY {
|
||||||
|
CHARSET: start = $D000, size = $0800, fill=no;
|
||||||
|
}
|
||||||
|
|
||||||
|
SEGMENTS {
|
||||||
|
CHARSET: load = CHARSET, type = ro;
|
||||||
|
}
|
||||||
55
mkfontimg.py
Normal file
55
mkfontimg.py
Normal file
|
|
@ -0,0 +1,55 @@
|
||||||
|
#!/usr/bin/python
|
||||||
|
import sys
|
||||||
|
import PIL.Image as Image
|
||||||
|
|
||||||
|
text = """\
|
||||||
|
10 poke53280,0:poke53281,1
|
||||||
|
20 print"\xd0\xd3";
|
||||||
|
30 fory=0to7
|
||||||
|
40 forx=0to15
|
||||||
|
50 poke49152+111+x+80*y,x+16*y
|
||||||
|
60 next
|
||||||
|
70 next
|
||||||
|
80 list"""
|
||||||
|
|
||||||
|
lowercase = False
|
||||||
|
if sys.argv[1] == '-l':
|
||||||
|
lowercase = True
|
||||||
|
del sys.argv[1]
|
||||||
|
|
||||||
|
def toscreencode(ch):
|
||||||
|
cc = ord(ch)
|
||||||
|
if '`' <= ch <= '~': return cc - 96
|
||||||
|
return cc
|
||||||
|
|
||||||
|
charset = map(ord, open(sys.argv[1]).read())
|
||||||
|
|
||||||
|
|
||||||
|
def putcat(img, r, c, code, lowercase):
|
||||||
|
inverse = code & 128
|
||||||
|
code = code % 128
|
||||||
|
idx = code*8
|
||||||
|
for y in range(8):
|
||||||
|
data = charset[idx+y+lowercase*1024]
|
||||||
|
if not inverse: data = ~data
|
||||||
|
for x in range(4):
|
||||||
|
img.putpixel((4*c+x,8*r+y), data & (1<<(3-x)))
|
||||||
|
|
||||||
|
img = Image.frombytes('1', (188,64), '\xff' * 188*64)
|
||||||
|
|
||||||
|
r=c=0
|
||||||
|
for ch in text:
|
||||||
|
if ch == '\n':
|
||||||
|
r = r + 1
|
||||||
|
c = 0
|
||||||
|
continue
|
||||||
|
putcat(img, r, c, toscreencode(ch), lowercase)
|
||||||
|
c = c + 1
|
||||||
|
if c == 80:
|
||||||
|
r = r + 1
|
||||||
|
c = 0
|
||||||
|
for r in range(8):
|
||||||
|
for c in range(16):
|
||||||
|
putcat(img, r, c+31, r*16+c, lowercase)
|
||||||
|
|
||||||
|
img.save(sys.argv[2])
|
||||||
Loading…
Reference in a new issue