OpenCores
URL https://opencores.org/ocsvn/vg_z80_sbc/vg_z80_sbc/trunk

Subversion Repositories vg_z80_sbc

[/] [vg_z80_sbc/] [trunk/] [rtl/] [psf2coe.rb] - Blame information for rev 35

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 3 hharte
#!/usr/bin/ruby
2
 
3
# Translate PSF (PostScript Font) files to XilinX COE file format
4
# for embbed a console font into a ROM (Xilinx read-only BRAM)
5
#
6
# 2007 Javier Valcarce García, 
7
# $Id: psf2coe.rb,v 1.1 2008-12-01 02:00:10 hharte Exp $
8
 
9
# Read header and retrieve font information
10
# Read the data
11
# Write the COE file
12
 
13
$i_filename = ARGV[0]
14
$o_filename = "output.coe"
15
if ARGV.length == 0
16
  puts "Usage: psf2coe file.psf"
17
  exit
18
end
19
 
20
str = IO.read($i_filename)
21
 
22
# Header
23
magic = str[0..1].unpack('H4')[0]
24
fmode = str[2].to_i
25
heigh = str[3].to_i
26
width = 8
27
pdata = str[4..str.length]
28
 
29
# Check magic numbers hdr[0]
30
if magic == "3604"
31
  puts "Format : PSF1"
32
  puts "Mode   : " + fmode.to_s
33
  puts "Width  : 8 pixels"
34
  puts "Heigh  : " + heigh.to_s + " pixels"
35
else
36
  puts "I only understand PSF1 format file. Sorry"
37
  exit
38
end
39
 
40
# Write COE file
41
File.open($o_filename, "w") do |file|
42
 
43
  file.puts <
44
; DO NOT EDIT THIS FILE BY HAND
45
; This file has been generated automaticaly by psf2coe utility.
46
; Original file: #{$i_filename}
47
 
48
  memory_initialization_radix  = 16;
49
  memory_initialization_vector =
50
END_OF_STRING
51
 
52
  # there is exactly 256 caracters in the file
53
  (256 * heigh).times do |i|
54
    file.puts sprintf("%02X\n", pdata[i])
55
  end
56
 
57
  file.puts "; END"
58
end
59
 
60
puts "DONE."

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.