Files
bob16/kernel/bob_font.h
T
2026-10-08 23:36:34 +02:00

60 lines
2.5 KiB
C

#ifndef BOB_FONT_H
#define BOB_FONT_H
#include "bob_gfx.h"
/* 5x7 column bitmaps: blank, A-Z, 0-9, ?, !, -, .; lowercase maps to uppercase. */
static int bob_font5x7[41][5]={
{0,0,0,0,0},
{0x7e,0x11,0x11,0x11,0x7e},{0x7f,0x49,0x49,0x49,0x36},
{0x3e,0x41,0x41,0x41,0x22},{0x7f,0x41,0x41,0x22,0x1c},
{0x7f,0x49,0x49,0x49,0x41},{0x7f,0x09,0x09,0x09,0x01},
{0x3e,0x41,0x49,0x49,0x7a},{0x7f,0x08,0x08,0x08,0x7f},
{0x00,0x41,0x7f,0x41,0x00},{0x20,0x40,0x41,0x3f,0x01},
{0x7f,0x08,0x14,0x22,0x41},{0x7f,0x40,0x40,0x40,0x40},
{0x7f,0x02,0x0c,0x02,0x7f},{0x7f,0x04,0x08,0x10,0x7f},
{0x3e,0x41,0x41,0x41,0x3e},{0x7f,0x09,0x09,0x09,0x06},
{0x3e,0x41,0x51,0x21,0x5e},{0x7f,0x09,0x19,0x29,0x46},
{0x46,0x49,0x49,0x49,0x31},{0x01,0x01,0x7f,0x01,0x01},
{0x3f,0x40,0x40,0x40,0x3f},{0x1f,0x20,0x40,0x20,0x1f},
{0x3f,0x40,0x38,0x40,0x3f},{0x63,0x14,0x08,0x14,0x63},
{0x07,0x08,0x70,0x08,0x07},{0x61,0x51,0x49,0x45,0x43},
{0x3e,0x51,0x49,0x45,0x3e},{0x00,0x42,0x7f,0x40,0x00},
{0x62,0x51,0x49,0x49,0x46},{0x22,0x41,0x49,0x49,0x36},
{0x18,0x14,0x12,0x7f,0x10},{0x2f,0x49,0x49,0x49,0x31},
{0x3e,0x49,0x49,0x49,0x32},{0x01,0x71,0x09,0x05,0x03},
{0x36,0x49,0x49,0x49,0x36},{0x26,0x49,0x49,0x49,0x3e},
{0x02,0x01,0x51,0x09,0x06},{0x00,0x00,0x5f,0x00,0x00},
{0x08,0x08,0x08,0x08,0x08},{0x00,0x60,0x60,0x00,0x00}
};
/* Draws uppercase 5x7 glyphs at cell-pixel resolution; clips at the right edge. */
int bob_gfx_bitmap_text(int x,int y,const char *text,int color) {
int bitmap[560];
int length=0,width,max_chars,character,glyph,cell;
if(x<0||y<0||x>=80||y+7>25||color<0||color>15)return -1;
max_chars=(80-x+1)/6;
while(text[length]&&length<max_chars)length++;
if(!length)return 0;
width=length*6-1;
for(int i=0;i<width*7;i++)bitmap[i]=0;
for(int i=0;i<length;i++) {
character=text[i];
if(character>='a'&&character<='z')character-=32;
if(character==' ')glyph=0;
else if(character>='A'&&character<='Z')glyph=1+character-'A';
else if(character>='0'&&character<='9')glyph=27+character-'0';
else if(character=='!')glyph=38;
else if(character=='-')glyph=39;
else if(character=='.')glyph=40;
else glyph=37;
for(int column=0;column<5;column++)for(int row=0;row<7;row++) {
cell=(bob_font5x7[glyph][column]&(1<<row))?('#'|(color<<8)):0;
bitmap[row*width+i*6+column]=cell;
}
}
return bob_gfx_blit_color(x,y,width,7,bitmap);
}
#endif