#include "bury.h"

/*k_noに16色文字のキャラフォントを設定*/
void wwc_text_font_set(int k_no, unsigned char moji)
{
	static BYTE mono_moji[8];
	static BYTE color_moji[32];
	int    i, j;
	BYTE   wk[8];

	text_get_fontdata(moji, mono_moji);

	/*横書きフォントを縦書きに変換*/
	for (i=0; i<8; i++) {
		wk[i] = mono_moji[i];
		mono_moji[i]=0;
	}

	for (i=0; i<8; i++) {
		for (j=7; j>-1; j--) {
			mono_moji[i] = mono_moji[i] | (wk[j] & (1 << (7-i))) >>(7-i) << j;
		}
	}

	/*16色文字に変換*/
	for (i=0; i<8; i++) {
		for (j=0; j<4; j++) {
			color_moji[i*4+j] = mono_moji[i];
		}
	}

	wwc_font_set_colordata(k_no, 1, color_moji);
}

/*（スプライトで）一文字表示*/
void wwc_text_put_char(int x, int y, int s_no, int k_no, unsigned char moji)
{
	int ;

	wwc_text_font_set(k_no, moji);
	sprite_set_char_location(s_no, k_no | CFM_SPR_UPPER | PALETTE(15), x, y);
}

void wwc_text_put_string(int x, int y, int s_no, int k_no, const unsigned char *str)
{
	char len = 0;
	static unsigned char moji;

	while (*str != '\0') {
		moji = *str++;
		wwc_text_put_char(x, y+len*8, s_no+len, k_no+len, moji);
		len++;
	}
}

void ten_view(unsigned ten)
{
	static unsigned char ten_str[6];
	int					 i, ct;

	sprintf(ten_str, "%05d", ten);

	for (i=0; i<5; i++) {
		/*数字（文字コード）から48を引くと数字のと同じ値の数値になる*/
		ct = ten_str[i] - 48;
		sprite_set_char_location(5+i, (224+ct | CFM_SPR_UPPER | PALETTE(15)), 216, 96+i*8);
	}
}
