/
fonts.c
70 lines (62 loc) · 3.26 KB
/
fonts.c
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/*---------------------------------------------------------------------------
-- EtherChess --
-----------------------------------------------------------------------------
-- --
-- EtherChess is an example game for MaRTE OS. --
-- --
-- author: Alvaro Garcia Cuesta --
-- email: alvaro@binarynonsense.com --
-- website: www.binarynonsense.com --
-- --
-- file: fonts.c --
-- --
-- this file contains the functions used to print strings --
-- using a bitmap font --
-----------------------------------------------------------------------------
-- License --
-----------------------------------------------------------------------------
-- --
-- EtherChess is free software; you can redistribute it and/or modify it --
-- under the terms of the GNU General Public License version 2 as --
-- published by the Free Software Foundation. --
-- See COPYING file for more info about the license --
-- --
-----------------------------------------------------------------------------
-- last update: 09 Jun 09 --
---------------------------------------------------------------------------*/
#include <string.h>
#include "vga.h"
#include "font.h"
#include "fonts.h"
int *theFont=font_img;
int screenWidth = 320;
int fontWidth=8;
int fontHeight=16;
int fontFileWidth=128;
void bmpfont_print(char *theString, int x, int y,int color,unsigned char *backBuffer){
int length;
length = strlen(theString);
int charPosition,charValue,fontPositionX,fontPositionY,fColor;
int xf,yf,initX,initY;
for(charPosition=0;charPosition<length;charPosition++){
charValue=theString[charPosition];
if(charValue<128){
fontPositionY=charValue/16;
fontPositionX=charValue-(fontPositionY*16);
initX=fontPositionX*fontWidth;
initY=fontPositionY*fontHeight;
for(xf=0;xf<fontWidth;xf++){
for(yf=0;yf<fontHeight;yf++){
fColor=theFont[fontFileWidth*(yf+initY)+(xf+initX)];
if(fColor!=0){
backBuffer[screenWidth*(y+yf)+(x+xf+charPosition*fontWidth)]=color;//white
}
//ONLY FOR ETHERCHESS
else{
backBuffer[screenWidth*(y+yf)+(x+xf+charPosition*fontWidth)]=0;//black
}
}
}
}
}
}