removed entry for status bar
[kugel-rb.git] / firmware / ajf.c
blob82ba0b7939ab84bc270c64758be4ff8c01029b68
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2002 by Alex Gitelman
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
19 #ifdef SIMULATOR
20 #include <fcntl.h>
21 #endif
22 #include <file.h>
23 #include "ajf.h"
24 #include <string.h>
25 #include <errno.h>
26 #include <stdbool.h>
27 #include "debug.h"
29 static unsigned char font_buf[MAX_FONT_BUFLEN];
31 unsigned char* ajf_read_font(char* fname)
33 int count;
34 #ifdef WIN32
35 int fd = open(fname, O_RDONLY|O_BINARY);
36 #else
37 int fd = open(fname, O_RDONLY);
38 #endif
39 if (fd<0)
41 #ifdef SIMULATOR
42 #ifdef WIN32
43 DEBUGF("Failed opening font file: %d %s. ", _errno(), fname);
44 #else
45 DEBUGF("Failed opening font file: %d %s. ", errno, fname);
46 #endif
47 #endif
48 return NULL;
51 count = read(fd, font_buf, MAX_FONT_BUFLEN);
52 if (count==MAX_FONT_BUFLEN) {
53 DEBUGF("Font is larger than allocated %d bytes!\n",MAX_FONT_BUFLEN);
54 return NULL;
56 close(fd);
58 if (font_buf[0]!=MAGIC1 || font_buf[1]!=MAGIC2) {
59 DEBUGF("Bad magic word in font");
60 return NULL;
62 return font_buf;
66 unsigned char* ajf_get_charbuf(unsigned char c, unsigned char* font,
67 int *w, int *h)
69 int height = READ_SHORT(&font[HEIGHT_OFFSET]);
70 int size = READ_SHORT(&font[SIZE_OFFSET]);
71 int chars_offset = LOOKUP_MAP_OFFSET + size*3;
72 int rows = (height-1)/8 + 1;
73 int first_char = READ_SHORT(&font[FIRST_CHAR_OFFSET]);
74 int map_idx = LOOKUP_MAP_OFFSET + (c-first_char)*3;
75 int byte_count = font[map_idx];
76 int char_idx;
78 *h = height;
79 *w = byte_count/rows;
81 map_idx++;
82 char_idx = READ_SHORT(&font[map_idx]);
83 return &font[chars_offset + char_idx];
86 void ajf_get_charsize(unsigned char c, unsigned char* font,
87 int *width, int *height)
89 int first_char = READ_SHORT(&font[FIRST_CHAR_OFFSET]);
90 int map_idx = LOOKUP_MAP_OFFSET + (c-first_char)*3;
91 int rows = 1;
92 *height = READ_SHORT(&font[HEIGHT_OFFSET]);
93 rows = (*height-1)/8 + 1;
94 *width = font[map_idx]/rows;
97 int ajf_get_fontheight(unsigned char* font)
99 return READ_SHORT(&font[HEIGHT_OFFSET]);