Example program for the Cidco MailStation Z80 computer
at main 72 lines 2.2 kB view raw
1# 2# convert a hex-exported bitmap font (like from gbdfed) to an asm include file 3# Copyright (c) 2019 joshua stein <jcs@jcs.org> 4# 5# Permission to use, copy, modify, and distribute this software for any 6# purpose with or without fee is hereby granted, provided that the above 7# copyright notice and this permission notice appear in all copies. 8# 9# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 10# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 11# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 12# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 13# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 14# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 15# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16# 17 18chars = [] 19char_size = 0 20all_bytes = [] 21 22if !ARGV[0] 23 puts "usage: #{$0} <hex file converted from bdf>" 24 exit 1 25end 26 27File.open(ARGV[0], "r") do |f| 28 char = 0 29 30 while f && !f.eof? 31 line = f.gets 32 33 # 0023:A0E0A0E0A000 34 if !(m = line.match(/^(....):(.+)$/)) 35 raise "unexpected format: #{line.inspect}" 36 end 37 38 char = m[1].to_i(16) 39 char_size = (m[2].length / 2) 40 41 # A0E0A0E0A000 42 # -> [ "A0", "e0", "A0", "e0", "A0", "00", "00" ] 43 bytes = m[2].scan(/(..)/).flatten 44 45 # -> [ 0xa0, 0xe0, 0xa0, 0xe0, 0xa0, 0x00, 0x00 ] 46 bytes = bytes.map{|c| c.to_i(16) } 47 48 # -> [ 101000000, 11100000, ... ] 49 # -> [ [ 1, 0, 1, 0, 0, 0, 0, 0 ], [ 1, 1, 1, 0, 0, 0, 0, 0 ], ... ] 50 bytes = bytes.map{|c| sprintf("%08b", c).split(//).map{|z| z.to_i } } 51 52 # -> [ [ 0, 0, 0, 0, 0, 1, 0, 1 ], [ 0, 0, 0, 0, 0, 1, 1, 1 ], ... ] 53 bytes = bytes.map{|a| a.reverse } 54 55 # -> [ 0x5, 0x7, ... ] 56 bytes = bytes.map{|a| a.join.to_i(2) } 57 58 chars[char] = bytes 59 end 60end 61 62(0 .. 255).each do |c| 63 if chars[c] && chars[c].any? 64 print ".db " << chars[c].map{|c| sprintf("#0x%02x", c) }.join(", ") 65 if c >= 32 && c <= 126 66 print "\t; #{sprintf("%.3d", c)} - #{c.chr}" 67 end 68 print "\n" 69 else 70 puts ".db " << char_size.times.map{|c| "#0x00" }.join(", ") 71 end 72end