convert bignum library; adapt serialVFD, CFontzPacket, IOWarrior

This commit is contained in:
marschap
2006-04-25 20:13:28 +00:00
parent 2d7bc08f12
commit 95a54cfbc1
11 changed files with 740 additions and 1037 deletions
+11 -202
View File
@@ -75,30 +75,7 @@
#include "report.h"
#include "lcd_lib.h"
#include "CFontz-charmap.h"
#define b_______ 0x00
#define b_____X_ 0x03
#define b_____XX 0x03
#define b____X__ 0x04
#define b____XX_ 0x06
#define b____XXX 0x07
#define b___X___ 0x08
#define b___XX__ 0x09
#define b___X_X_ 0x0A
#define b___XXX_ 0x0E
#define b___XXXX 0x0F
#define b__X____ 0x10
#define b__X___X 0x11
#define b__X_X_X 0x15
#define b__X_XX_ 0x16
#define b__XX___ 0x18
#define b__XX_XX 0x1B
#define b__XXX__ 0x1C
#define b__XXX_X 0x1D
#define b__XXXX_ 0x1E
#define b__XXXXX 0x1F
#define b_XXX___ 0x38
#define b_XXXXXX 0x3F
#include "adv_bignum.h"
#define CFP_KEY_UP 1
@@ -943,200 +920,32 @@ CFontzPacket_hbar (Driver *drvthis, int x, int y, int len, int promille, int opt
/*
* Inits big numbers
* Writes a big number.
*/
static void
CFontzPacket_init_num(Driver *drvthis)
MODULE_EXPORT void
CFontzPacket_num(Driver *drvthis, int x, int num)
{
PrivateData *p = drvthis->private_data;
int do_init = 0;
unsigned char bignum_ccs[8][CELLHEIGHT] = {
[0]
{ b_XXX___,
b_XXX___,
b_XXX___,
b_XXX___,
b_______,
b_______,
b_______,
b_______ },
[1]
{ b____XXX,
b____XXX,
b____XXX,
b____XXX,
b_XXX___,
b_XXX___,
b_XXX___,
b_XXX___ },
[2]
{ b_XXXXXX,
b_XXXXXX,
b_XXXXXX,
b_XXXXXX,
b_______,
b_______,
b_______,
b_______ },
[3]
{ b_______,
b_______,
b_______,
b_______,
b_XXX___,
b_XXX___,
b_XXX___,
b_XXX___ },
[4]
{ b_XXX___,
b_XXX___,
b_XXX___,
b_XXX___,
b____XXX,
b____XXX,
b____XXX,
b____XXX },
[5]
{ b_______,
b_______,
b_______,
b_______,
b_XXXXXX,
b_XXXXXX,
b_XXXXXX,
b_XXXXXX },
[6]
{ b_XXX___,
b_XXX___,
b_XXX___,
b_XXX___,
b_XXX___,
b_XXX___,
b_XXX___,
b_XXX___ },
[7]
{ b____XXX,
b____XXX,
b____XXX,
b____XXX,
b_______,
b_______,
b_______,
b_______ }
};
if ((num < 0) || (num > 10))
return;
if (p->ccmode != bignum) {
int i;
if (p->ccmode != standard) {
/* Not supported (yet) */
report(RPT_WARNING, "%s: init_num: cannot combine two modes using user defined characters",
report(RPT_WARNING, "%s: num: cannot combine two modes using user defined characters",
drvthis->name);
return;
}
p->ccmode = bignum;
for (i = 0; i < NUM_CCs; i++)
CFontzPacket_set_char(drvthis, i, bignum_ccs[i]);
do_init = 1;
}
}
/*
* Writes a big number.
* Only works on 4-line displays
*/
MODULE_EXPORT void
CFontzPacket_num(Driver *drvthis, int x, int num)
{
PrivateData *p = drvthis->private_data;
/* each bignum is constructed in a 3 x 4 matrix and consists
* of only the 8 characters defined above as well as ' '
*
* The following table defines the 11 big numbers '0'-'9', ':'
* and the custom base characters they consist of
*/
char bignum_map[11][4][3] = {
{ /* 0: */
{ 1, 2, 3 },
{ 6, 32, 6 },
{ 6, 32, 6 },
{ 7, 2, 32 } },
{ /* 1: */
{ 7, 6, 32 },
{ 32, 6, 32 },
{ 32, 6, 32 },
{ 7, 2, 32 } },
{ /* 2: */
{ 1, 2, 3 },
{ 32, 5, 0 },
{ 1, 32, 32 },
{ 2, 2, 0 } },
{ /* 3: */
{ 1, 2, 3 },
{ 32, 5, 0 },
{ 3, 32, 6 },
{ 7, 2, 32 } },
{ /* 4: */
{ 32, 3, 6 },
{ 1, 32, 6 },
{ 2, 2, 6 },
{ 32, 32, 0 } },
{ /* 5: */
{ 1, 2, 0 },
{ 2, 2, 3 },
{ 3, 32, 6 },
{ 7, 2, 32 } },
{ /* 6: */
{ 1, 2, 32 },
{ 6, 5, 32 },
{ 6, 32, 6 },
{ 7, 2, 32 } },
{ /* 7: */
{ 2, 2, 6 },
{ 32, 1, 32 },
{ 32, 6, 32 },
{ 32, 0, 32 } },
{ /* 8: */
{ 1, 2, 3 },
{ 4, 5, 0 },
{ 6, 32, 6 },
{ 7, 2, 32 } },
{ /* 9: */
{ 1, 2, 3 },
{ 4, 3, 6 },
{ 32, 1, 32 },
{ 7, 32, 32 } },
{ /* colon: (only 1st column used) */
{ 32, 32, 32 },
{ 0, 32, 32 },
{ 0, 32, 32 },
{ 32, 32, 32 } }
};
if ((num < 0) || (num > 10))
return;
if (p->height >= 4) {
int y = (p->height - 2) / 2; /* center vertically */
int x2, y2;
CFontzPacket_init_num(drvthis);
for (x2 = 0; x2 < 3; x2++) {
for (y2 = 0; y2 < 4; y2++) {
CFontzPacket_chr(drvthis, x+x2, y+y2, bignum_map[num][y2][x2]);
}
if (num == 10)
x2 = 2; /* = break, for colon only */
}
}
else {
CFontzPacket_chr(drvthis, x, 1 + (p->height - 1) / 2,
(num == 10) ? ':' : (num + '0'));
}
// Lib_adv_bignum does everything needed to show the bignumbers.
lib_adv_bignum(drvthis, x, num, do_init, NUM_CCs);
}