#include <stdio.h>
#if PROTOS_AVAIL
#include <stddef.h>
#include <malloc.h>
#include <stdlib.h>
void main(int argc,char *argv[]);
#else
void* malloc();
#endif
#include "speedo.h"
#include "keys.h"
#define DEBUG 0
#if DEBUG
#define SHOW(X) printf("X = %d\n", X)
#else
#define SHOW(X)
#endif
#define MAX_BITS 256
#if PROTOS_AVAIL
fix31 read_4b(ufix8 FONTFAR *ptr);
fix15 read_2b(ufix8 FONTFAR *ptr);
#else
fix31 read_4b();
fix15 read_2b();
#endif
static char pathname[100];
static ufix8 FONTFAR *font_buffer;
static ufix8 FONTFAR *char_buffer;
static buff_t font;
#if INCL_LCD
static buff_t char_data;
#endif
static FILE *fdescr;
static ufix16 char_index;
static ufix16 char_id;
static ufix16 minchrsz;
static ufix8 key[] =
{
KEY0,
KEY1,
KEY2,
KEY3,
KEY4,
KEY5,
KEY6,
KEY7,
KEY8
};
static fix15 raswid;
static fix15 rashgt;
static fix15 offhor;
static fix15 offver;
static fix15 set_width;
static fix15 y_cur;
static char line_of_bits[2 * MAX_BITS + 1];
#if INCL_MULTIDEV
#if INCL_BLACK || INCL_SCREEN || INCL_2D
bitmap_t bfuncs = { sp_open_bitmap, sp_set_bitmap_bits, sp_close_bitmap };
#endif
#if INCL_OUTLINE
outline_t ofuncs = { sp_open_outline, sp_start_new_char, sp_start_contour, sp_curve_to,
sp_line_to, sp_close_contour, sp_close_outline };
#endif
#endif
ufix8 temp[16];
FUNCTION void main(argc,argv)
int argc;
char *argv[];
{
ufix16 bytes_read;
specs_t specs;
int first_char_index;
int no_layout_chars;
ufix32 i;
ufix32 minbufsz;
ufix16 cust_no;
ufix8 FONTFAR *byte_ptr;
#if REENTRANT_ALLOC
SPEEDO_GLOBALS* sp_global_ptr;
#endif
if (argc != 2)
{
fprintf(stderr,"Usage: nsample {fontfile}\n\n");
exit (1);
}
sprintf(pathname, argv[1]);
fdescr = fopen (pathname, "rb");
if (fdescr == NULL)
{
printf("****** Cannot open file %s\n", pathname);
return;
}
bytes_read = fread(temp, sizeof(ufix8), 16, fdescr);
if (bytes_read != 16)
{
printf("****** Error on reading %s: %x\n", pathname, bytes_read);
fclose(fdescr);
return;
}
#if INCL_LCD
minbufsz = (ufix32)read_4b(temp+FH_FBFSZ);
#else
minbufsz = (ufix32)read_4b(temp+FH_FNTSZ);
if (minbufsz >= 0x10000)
{
printf("****** Cannot process fonts greater than 64K - use dynamic character loading configuration option\n");
fclose(fdescr);
return;
}
#endif
#if (defined(M_I86SM) || defined(M_I86MM))
font_buffer = (ufix8 FONTFAR *)_fmalloc((ufix16)minbufsz);
#else
font_buffer = (ufix8 *)malloc((ufix16)minbufsz);
#endif
if (font_buffer == NULL)
{
printf("****** Unable to allocate memory for font buffer\n");
fclose(fdescr);
return;
}
#if DEBUG
printf("Loading font file %s\n", pathname);
#endif
fseek(fdescr, (ufix32)0, 0);
#if (defined(M_I86SM) || (defined(M_I86MM)))
byte_ptr = font_buffer;
for (i=0; i< minbufsz; i++){
int ch;
ch = getc(fdescr);
if (ch == EOF)
{printf ("Premature EOF in reading font buffer, %ld bytes read\n",i);
exit(2);}
*byte_ptr=(ufix8)ch;
byte_ptr++;
}
bytes_read = i;
#else
bytes_read = fread((ufix8 *)font_buffer, sizeof(ufix8), (ufix16)minbufsz, fdescr);
if (bytes_read == 0)
{
printf("****** Error on reading %s: %x\n", pathname, bytes_read);
fclose(fdescr);
return;
}
#endif
#if INCL_LCD
minchrsz = read_2b(font_buffer+FH_CBFSZ);
#if (defined(M_I86SM) || (defined(M_I86MM)))
char_buffer = (ufix8 FONTFAR *)_fmalloc(minchrsz);
#else
char_buffer = (ufix8*)malloc(minchrsz);
#endif
if (char_buffer == NULL)
{
printf("****** Unable to allocate memory for character buffer\n");
fclose(fdescr);
return;
}
#endif
#if DYNAMIC_ALLOC || REENTRANT_ALLOC
sp_global_ptr = (SPEEDO_GLOBALS *)malloc(sizeof(SPEEDO_GLOBALS));
memset(sp_global_ptr,(ufix8)0,sizeof(SPEEDO_GLOBALS));
#endif
#if REENTRANT_ALLOC
sp_reset(sp_global_ptr);
#else
sp_reset();
#endif
font.org = font_buffer;
font.no_bytes = bytes_read;
#if REENTRANT_ALLOC
if ((cust_no=sp_get_cust_no(sp_global_ptr,font)) != CUS0 &&
#else
if ((cust_no=sp_get_cust_no(font)) != CUS0 &&
#endif
cust_no != 0)
{
#if REENTRANT_ALLOC
printf("Unable to use fonts for customer number %d\n",
sp_get_cust_no(sp_global_ptr(font)));
#else
printf("Unable to use fonts for customer number %d\n",
sp_get_cust_no(font));
#endif
fclose(fdescr);
return;
}
#if INCL_KEYS
#if REENTRANT_ALLOC
sp_set_key(sp_global_ptr,key);
#else
sp_set_key(key);
#endif
#endif
#if INCL_MULTIDEV
#if INCL_BLACK || INCL_SCREEN || INCL_2D
#if REENTRANT_ALLOC
sp_set_bitmap_device(sp_global_ptr,&bfuncs,sizeof(bfuncs));
#else
sp_set_bitmap_device(&bfuncs,sizeof(bfuncs));
#endif
#endif
#if INCL_OUTLINE
#if REENTRANT_ALLOC
sp_set_outline_device(sp_global_ptr,&ofuncs,sizeof(ofuncs));
#else
sp_set_outline_device(&ofuncs,sizeof(ofuncs));
#endif
#endif
#endif
first_char_index = read_2b(font_buffer + FH_FCHRF);
no_layout_chars = read_2b(font_buffer + FH_NCHRL);
specs.pfont = &font;
specs.xxmult = 25L << 16;
specs.xymult = 0L << 16;
specs.xoffset = 0L << 16;
specs.yxmult = 0L << 16;
specs.yymult = 25L << 16;
specs.yoffset = 0L << 16;
specs.flags = 0;
specs.out_info = NULL;
#if REENTRANT_ALLOC
if (!sp_set_specs(sp_global_ptr,&specs))
#else
if (!sp_set_specs(&specs))
#endif
{
printf("****** Cannot set requested specs\n");
}
else
{
for (i = 0; i < no_layout_chars; i++)
{
char_index = i + first_char_index;
#if REENTRANT_ALLOC
char_id = sp_get_char_id(sp_global_ptr,char_index);
#else
char_id = sp_get_char_id(char_index);
#endif
if (char_id != 0)
{
#if REENTRANT_ALLOC
if (!sp_make_char(sp_global_ptr,char_index))
#else
if (!sp_make_char(char_index))
#endif
{
printf("****** Cannot generate character %d\n", char_index);
}
}
}
}
fclose(fdescr);
}
#if INCL_LCD
#if REENTRANT_ALLOC
FUNCTION buff_t *sp_load_char_data(sp_global_ptr, file_offset, no_bytes, cb_offset)
SPEEDO_GLOBALS *sp_global_ptr;
#else
FUNCTION buff_t *sp_load_char_data(file_offset, no_bytes, cb_offset)
#endif
fix31 file_offset;
fix15 no_bytes;
fix15 cb_offset;
{
int bytes_read;
#if DEBUG
printf("\nCharacter data(%d, %d, %d) requested\n", file_offset, no_bytes, cb_offset);
#endif
if (fseek(fdescr, (long)file_offset, (int)0) != 0)
{
printf("****** Error in seeking character\n");
fclose(fdescr);
exit(1);
}
if ((no_bytes + cb_offset) > minchrsz)
{
printf("****** Character buffer overflow\n");
fclose(fdescr);
exit(3);
}
bytes_read = fread((char_buffer + cb_offset), sizeof(ufix8), no_bytes, fdescr);
if (bytes_read != no_bytes)
{
printf("****** Error on reading character data\n");
fclose(fdescr);
exit(2);
}
#if DEBUG
printf("Character data loaded\n");
#endif
char_data.org = (ufix8 FONTFAR *)char_buffer + cb_offset;
char_data.no_bytes = no_bytes;
return &char_data;
}
#endif
#if REENTRANT_ALLOC
FUNCTION void sp_report_error(sp_global_ptr,n)
SPEEDO_GLOBALS *sp_global_ptr;
#else
FUNCTION void sp_report_error(n)
#endif
fix15 n;
{
switch(n)
{
case 1:
printf("Insufficient font data loaded\n");
break;
case 3:
printf("Transformation matrix out of range\n");
break;
case 4:
printf("Font format error\n");
break;
case 5:
printf("Requested specs not compatible with output module\n");
break;
case 7:
printf("Intelligent transformation requested but not supported\n");
break;
case 8:
printf("Unsupported output mode requested\n");
break;
case 9:
printf("Extended font loaded but only compact fonts supported\n");
break;
case 10:
printf("Font specs not set prior to use of font\n");
break;
case 12:
break;
case 13:
printf("Track kerning data not available()\n");
break;
case 14:
printf("Pair kerning data not available()\n");
break;
default:
printf("report_error(%d)\n", n);
break;
}
}
#if REENTRANT_ALLOC
FUNCTION void sp_open_bitmap(sp_global_ptr, x_set_width, y_set_width, xorg, yorg, xsize, ysize)
SPEEDO_GLOBALS *sp_global_ptr;
#else
FUNCTION void sp_open_bitmap(x_set_width, y_set_width, xorg, yorg, xsize, ysize)
#endif
fix31 x_set_width;
fix31 y_set_width;
fix31 xorg;
fix31 yorg;
fix15 xsize;
fix15 ysize;
{
fix15 i;
#if DEBUG
printf("open_bitmap(%3.1f, %3.1f, %3.1f, %3.1f, %d, %d)\n",
(real)x_set_width / 65536.0, (real)y_set_width / 65536.0,
(real)xorg / 65536.0, (real)yorg / 65536.0, (int)xsize, (int)ysize);
#endif
raswid = xsize;
rashgt = ysize;
offhor = (fix15)(xorg >> 16);
offver = (fix15)(yorg >> 16);
if (raswid > MAX_BITS)
raswid = MAX_BITS;
printf("\nCharacter index = %d, ID = %d\n", char_index, char_id);
printf("set width = %3.1f, %3.1f\n", (real)x_set_width / 65536.0, (real)y_set_width / 65536.0);
printf("X offset = %d\n", offhor);
printf("Y offset = %d\n\n", offver);
for (i = 0; i < raswid; i++)
{
line_of_bits[i << 1] = '.';
line_of_bits[(i << 1) + 1] = ' ';
}
line_of_bits[raswid << 1] = '\0';
y_cur = 0;
}
#if REENTRANT_ALLOC
FUNCTION void sp_set_bitmap_bits (sp_global_ptr, y, xbit1, xbit2)
SPEEDO_GLOBALS *sp_global_ptr;
#else
FUNCTION void sp_set_bitmap_bits (y, xbit1, xbit2)
#endif
fix15 y;
fix15 xbit1;
fix15 xbit2;
{
fix15 i;
#if DEBUG
printf("set_bitmap_bits(%d, %d, %d)\n", (int)y, (int)xbit1, (int)xbit2);
#endif
if (xbit1 > MAX_BITS)
xbit1 = MAX_BITS;
if (xbit2 > MAX_BITS)
xbit2 = MAX_BITS;
while (y_cur != y)
{
printf(" %s\n", line_of_bits);
for (i = 0; i < raswid; i++)
{
line_of_bits[i << 1] = '.';
}
y_cur++;
}
for (i = xbit1; i < xbit2; i++)
{
line_of_bits[i << 1] = 'X';
}
}
#if REENTRANT_ALLOC
FUNCTION void sp_close_bitmap(sp_global_ptr)
SPEEDO_GLOBALS *sp_global_ptr;
#else
FUNCTION void sp_close_bitmap()
#endif
{
#if DEBUG
printf("close_bitmap()\n");
#endif
printf(" %s\n", line_of_bits);
}
#if INCL_OUTLINE
#if REENTRANT_ALLOC
FUNCTION void sp_open_outline(sp_global_ptr, x_set_width, y_set_width, xmin, xmax, ymin, ymax)
SPEEDO_GLOBALS *sp_global_ptr;
#else
FUNCTION void sp_open_outline(x_set_width, y_set_width, xmin, xmax, ymin, ymax)
#endif
fix31 x_set_width;
fix31 y_set_width;
fix31 xmin;
fix31 xmax;
fix31 ymin;
fix31 ymax;
{
printf("\nopen_outline(%3.1f, %3.1f, %3.1f, %3.1f, %3.1f, %3.1f)\n",
(real)x_set_width / 65536.0, (real)y_set_width / 65536.0,
(real)xmin / 65536.0, (real)xmax / 65536.0, (real)ymin / 65536.0, (real)ymax / 65536.0);
}
#if REENTRANT_ALLOC
FUNCTION void sp_start_new_char(sp_global_ptr)
SPEEDO_GLOBALS *sp_global_ptr;
#else
FUNCTION void sp_start_new_char()
#endif
{
printf("start_new_char()\n");
}
#if REENTRANT_ALLOC
FUNCTION void sp_start_contour(sp_global_ptr, x, y, outside)
SPEEDO_GLOBALS *sp_global_ptr;
#else
FUNCTION void sp_start_contour(x, y, outside)
#endif
fix31 x;
fix31 y;
boolean outside;
{
printf("start_contour(%3.1f, %3.1f, %s)\n",
(real)x / 65536.0, (real)y / 65536.0,
outside? "outside": "inside");
}
#if REENTRANT_ALLOC
FUNCTION void sp_curve_to(sp_global_ptr, x1, y1, x2, y2, x3, y3)
SPEEDO_GLOBALS *sp_global_ptr;
#else
FUNCTION void sp_curve_to(x1, y1, x2, y2, x3, y3)
#endif
fix31 x1;
fix31 y1;
fix31 x2;
fix31 y2;
fix31 x3;
fix31 y3;
{
printf("curve_to(%3.1f, %3.1f, %3.1f, %3.1f, %3.1f, %3.1f)\n",
(real)x1 / 65536.0, (real)y1 / 65536.0,
(real)x2 / 65536.0, (real)y2 / 65536.0,
(real)x3 / 65536.0, (real)y3 / 65536.0);
}
#if REENTRANT_ALLOC
FUNCTION void sp_line_to(sp_global_ptr, x, y)
SPEEDO_GLOBALS *sp_global_ptr;
#else
FUNCTION void sp_line_to(x, y)
#endif
fix31 x;
fix31 y;
{
printf("line_to(%3.1f, %3.1f)\n",
(real)x / 65536.0, (real)y / 65536.0);
}
#if REENTRANT_ALLOC
FUNCTION void sp_close_contour(sp_global_ptr)
SPEEDO_GLOBALS *sp_global_ptr;
#else
FUNCTION void sp_close_contour()
#endif
{
printf("close_contour()\n");
}
#if REENTRANT_ALLOC
FUNCTION void sp_close_outline(sp_global_ptr)
SPEEDO_GLOBALS *sp_global_ptr;
#else
FUNCTION void sp_close_outline()
#endif
{
printf("close_outline()\n");
}
#endif
FUNCTION fix15 read_2b(pointer)
ufix8 FONTFAR *pointer;
{
fix15 temp;
temp = *pointer++;
temp = (temp << 8) + *(pointer);
return temp;
}
FUNCTION fix31 read_4b(pointer)
ufix8 FONTFAR *pointer;
{
fix31 temp;
temp = *pointer++;
temp = (temp << 8) + *(pointer++);
temp = (temp << 8) + *(pointer++);
temp = (temp << 8) + *(pointer);
return temp;
}