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] - Rev 36

Go to most recent revision | Compare with Previous | Blame | View Log

#!/usr/bin/ruby 

# Translate PSF (PostScript Font) files to XilinX COE file format 
# for embbed a console font into a ROM (Xilinx read-only BRAM)
#
# $Id: psf2coe.rb,v 1.1 2008-12-01 02:00:10 hharte Exp $

# Read header and retrieve font information
# Read the data
# Write the COE file

$i_filename = ARGV[0]
$o_filename = "output.coe"
if ARGV.length == 0
  puts "Usage: psf2coe file.psf"
  exit
end

str = IO.read($i_filename)

# Header
magic = str[0..1].unpack('H4')[0]
fmode = str[2].to_i
heigh = str[3].to_i
width = 8
pdata = str[4..str.length]

# Check magic numbers hdr[0]
if magic == "3604"
  puts "Format : PSF1"
  puts "Mode   : " + fmode.to_s
  puts "Width  : 8 pixels"
  puts "Heigh  : " + heigh.to_s + " pixels"
else 
  puts "I only understand PSF1 format file. Sorry"
  exit
end

# Write COE file
File.open($o_filename, "w") do |file|
  
  file.puts <<END_OF_STRING
; DO NOT EDIT THIS FILE BY HAND
; This file has been generated automaticaly by psf2coe utility.
; Original file: #{$i_filename}

  memory_initialization_radix  = 16;
  memory_initialization_vector =
END_OF_STRING
    
  # there is exactly 256 caracters in the file
  (256 * heigh).times do |i| 
    file.puts sprintf("%02X\n", pdata[i]) 
  end
  
  file.puts "; END"
end

puts "DONE."

Go to most recent revision | Compare with Previous | Blame | View Log

powered by: WebSVN 2.1.0

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