Forums

Sega Master System / Mark III / Game Gear
SG-1000 / SC-3000 / SF-7000 / OMV
Home - Forums - Games - Scans - Maps - Cheats - Credits
Music - Videos - Development - Hacks - Translations - Homebrew

View topic - cpi2hex - a utility for extracting code page fonts

Reply to topic
Author Message
  • Joined: 25 Jul 2007
  • Posts: 729
  • Location: Melbourne, Australia
Reply with quote
cpi2hex - a utility for extracting code page fonts
Post Posted: Sun Oct 15, 2017 7:01 am
Last edited by thatawesomeguy on Mon Oct 16, 2017 1:13 pm; edited 1 time in total
I wanted a way to get ASCII standard fonts for use in projects so I made a utility that will extract code page fonts (such as the common CP437) into a format that can be directly used with devkitSMS.

It works with CPI files which are commonly found in DOS and similar distributions.

Usage is straight forward: cpi2hex filename.cpi

There are command line options for specifying specific code pages within the file or ranges of characters you want to extract.

I've open sourced it for anyone that wants to tinker. https://github.com/pmckeon/cpi2hex

cpi2hex-1.0.1-win32-x86.zip

cpi2hex-1.0.1-win32-x64.zip
  View user's profile Send private message
  • Joined: 05 Sep 2013
  • Posts: 3794
  • Location: Stockholm, Sweden
Reply with quote
Post Posted: Sun Oct 15, 2017 8:35 am
interesting!

are CPI files always holding 8x8 pixel fonts? I remember from the EGA/VGA times that the fonts were some 9x15 or so...

The output file is 1bpp data array in C source format, I seem to understand. Can it create the same data in binary format also? (so that it can be put into assets folder with all the other assets and let assets2bank do its work)
  View user's profile Send private message Visit poster's website
  • Joined: 25 Jul 2007
  • Posts: 729
  • Location: Melbourne, Australia
Reply with quote
Post Posted: Sun Oct 15, 2017 9:10 am
sverx wrote
are CPI files always holding 8x8 pixel fonts? I remember from the EGA/VGA times that the fonts were some 9x15 or so...


There's typically 8x16, 8x14 and 8x8 in each code page (though other variations exist like 8x6). My understanding is that 8x8 is pretty much always present to retain CGA graphics compatibility.

Either way I haven't limited it to strictly 8x8 output in case someone maybe did want to use a bigger font.

Quote
The output file is 1bpp data array in C source format, I seem to understand. Can it create the same data in binary format also? (so that it can be put into assets folder with all the other assets and let assets2bank do its work)


That is correct, I've pretty much gone with your own sample and run with it.

Typical output is something like:


const unsigned char CP437_8x8__1bpp[2048] = {
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x7E,0x81,0xA5,0x81,0xBD,0x99,0x81,0x7E,
0x7E,0xFF,0xDB,0xFF,0xC3,0xE7,0xFF,0x7E,
0x6C,0xFE,0xFE,0xFE,0x7C,0x38,0x10,0x00,
0x10,0x38,0x7C,0xFE,0x7C,0x38,0x10,0x00,
0x38,0x7C,0x38,0xFE,0xFE,0xD6,0x10,0x38,
0x10,0x38,0x7C,0xFE,0xFE,0x7C,0x10,0x38,
.......................................
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};


At the moment it doesn't output in any other format because that was all I needed, but if you had a sample of what the binary data should look like I could always updated it support binary output.
  View user's profile Send private message
  • Joined: 05 Sep 2013
  • Posts: 3794
  • Location: Stockholm, Sweden
Reply with quote
Post Posted: Sun Oct 15, 2017 10:24 am
djbass wrote
At the moment it doesn't output in any other format because that was all I needed, but if you had a sample of what the binary data should look like I could always updated it support binary output.


The binary file is just a .bin file containing exactly those bytes you put in that array.
  View user's profile Send private message Visit poster's website
  • Joined: 25 Jul 2007
  • Posts: 729
  • Location: Melbourne, Australia
Reply with quote
Post Posted: Sun Oct 15, 2017 11:06 am
Last edited by thatawesomeguy on Tue Oct 17, 2017 9:09 pm; edited 1 time in total
sverx wrote
The binary file is just a .bin file containing exactly those bytes you put in that array.


So just the raw output, are any headers used by assets2bank or is it specified on the command line?

I have attached a sample of the full CP437 8x8 character set (2048 bytes, 256 characters), is this the sort of thing you are looking for?

  View user's profile Send private message
  • Joined: 05 Sep 2013
  • Posts: 3794
  • Location: Stockholm, Sweden
Reply with quote
Post Posted: Sun Oct 15, 2017 9:53 pm
just raw data, no headers.
assets2banks will convert those files to arrays, allocating them in the data bank where they fits better (and latest version can even create already compiled data banks so you just need to link those to your code, no more C 'data' files to compile...)
  View user's profile Send private message Visit poster's website
  • Joined: 25 Jul 2007
  • Posts: 729
  • Location: Melbourne, Australia
Reply with quote
Post Posted: Mon Oct 16, 2017 1:14 pm
Done. You can now add the -b option to output data as raw binary files.
  View user's profile Send private message
  • Joined: 05 Sep 2013
  • Posts: 3794
  • Location: Stockholm, Sweden
Reply with quote
Post Posted: Mon Oct 16, 2017 2:34 pm
is it
-b <filename>
or
-o <filename> -b
?
  View user's profile Send private message Visit poster's website
  • Joined: 25 Jul 2007
  • Posts: 729
  • Location: Melbourne, Australia
Reply with quote
Post Posted: Mon Oct 16, 2017 8:39 pm
Just -b

It will autogenerate file names based on the font size and code page.

-o will have no effect in binary mode as it doesn't make sense to generate one monolithic file.
  View user's profile Send private message
  • Joined: 05 Sep 2013
  • Posts: 3794
  • Location: Stockholm, Sweden
Reply with quote
Post Posted: Tue Oct 17, 2017 7:52 am
... oh, now I get it!! You're creating multiple files!
OK thanks :)
  View user's profile Send private message Visit poster's website
  • Joined: 25 Jul 2007
  • Posts: 729
  • Location: Melbourne, Australia
Reply with quote
Post Posted: Tue Oct 17, 2017 11:57 am
Yep

A CPI file can (and often does) have multiple code pages for different languages as well as multiple sizes for each font.

The way I am handling this is that if you don't specify any options it will just dump every font it can find.

You can limit the output by using -c to choose a specific code page number, and/or -r to use a range of characters out of the 256 available (eg:: -r 32-127 to get the most common printable characters).
  View user's profile Send private message
  • Joined: 05 Sep 2013
  • Posts: 3794
  • Location: Stockholm, Sweden
Reply with quote
Post Posted: Tue Oct 17, 2017 1:45 pm
clear! :)
  View user's profile Send private message Visit poster's website
  • Joined: 05 Sep 2013
  • Posts: 3794
  • Location: Stockholm, Sweden
Reply with quote
Post Posted: Tue Oct 17, 2017 1:53 pm
djbass wrote
I have attached a sample of the full CP437 8x8 character set (2048 bytes, 256 characters), is this the sort of thing you are looking for?


mmm... it's 4096 bytes :(
  View user's profile Send private message Visit poster's website
  • Joined: 25 Jul 2007
  • Posts: 729
  • Location: Melbourne, Australia
Reply with quote
Post Posted: Tue Oct 17, 2017 9:11 pm
sverx wrote
djbass wrote
I have attached a sample of the full CP437 8x8 character set (2048 bytes, 256 characters), is this the sort of thing you are looking for?


mmm... it's 4096 bytes :(


oops, you are correct that was the 8x16 font. I have updated the file.

If you want to try extracting your own there is a sample file under:

https://github.com/pmckeon/cpi2hex/blob/master/test/DOS/EGA.CPI
  View user's profile Send private message
Reply to topic



Back to the top of this page

Back to SMS Power!