summaryrefslogtreecommitdiff
path: root/Source/Tools/BMPFont2CD/main.cpp
blob: 33c50283239b47434783ef3ea25a98855058e4de (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include <iostream>
#include <fstream>

#define BMP_CHARWIDTH 9

#define CHARHEIGHT 16

#define CHARACTERS 256

using namespace std;

int main() {
	ifstream f("ConsoleFont.raw", ios::in | ios::binary);

	bool Chars[CHARACTERS][8][CHARHEIGHT];

	for (int y = 0; y < CHARHEIGHT; y++) {
		for (int x = 0; x < CHARACTERS * BMP_CHARWIDTH; x++) {
			char temp; f.read(&temp, 1);
			int cc = x / BMP_CHARWIDTH;
			int xx = x % BMP_CHARWIDTH;
			if (xx < 8) Chars[cc][xx][y] = (temp != 0);
		}
	}
	f.close();

	ofstream cdfont("ConsoleFont.cd", ios::out);
	cdfont << "char consoleFont[" << CHARACTERS << "][" << CHARHEIGHT << "] = {" << endl;

	for (int i = 0; i < CHARACTERS; i++) {
		cdfont << hex << "/* 0x" << (i < 16 ? "0" : "") << i << " */\t{";
		for (int y = 0; y < CHARHEIGHT; y++) {
			int n = 0;
			for (int x = 0; x < 8; x++) {
				n = n << 1;
				n += (Chars[i][x][y] ? 1 : 0);
			}
			cdfont << (y == 0 ? "0x" : ", 0x") << (n < 16 ? "0" : "") << hex << n;
		}
		cdfont << "}," << endl;
	}
	cdfont << "};" << endl;
}