Skip to content

Commit 447db08

Browse files
committed
and move it over to the Atari.
1 parent 25c3ed4 commit 447db08

File tree

1 file changed

+65
-78
lines changed

1 file changed

+65
-78
lines changed

src/atari/terminal_char_load.c

Lines changed: 65 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -10,61 +10,44 @@
1010
#include <string.h>
1111
#include <stdio.h>
1212
#include <stdarg.h>
13-
#include <peekpoke.h>
1413
#include "../terminal.h"
1514
#include "../protocol.h"
1615

17-
/* #define FONTPTR(a) (((a << 1) + a) << 1) */
18-
#define FONTPTR(aa) (aa*6)
16+
#define FONTPTR(a) (((a << 1) + a) << 1)
1917

18+
// Temporary PLATO character data, 8x16 matrix
2019
static unsigned char char_data[]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
21-
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
20+
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
2221

23-
static unsigned char shrunk_char_data[]={0x00,0x00,0x00,0x00,0x00,0x00};
22+
static unsigned char BTAB[]={0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01}; // flip one bit on (OR)
23+
static unsigned char BTAB_5[]={0x08,0x10,0x10,0x20,0x20,0x40,0x80,0x80}; // flip one bit on for the 5x6 matrix (OR)
2424

25-
const unsigned char BTAB[]={0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01}; // flip one bit on (OR)
26-
const unsigned char BTAB_5[]={0x08,0x10,0x10,0x20,0x20,0x40,0x80,0x80}; // flip one bit on for the 5x6 matrix (OR)
27-
const unsigned char TAB_0_5[]={0x00,0x00,0x00,0x01,0x01,0x01,0x02,0x02,0x03,0x03,0x04,0x04,0x04,0x05,0x05,0x05};
28-
const unsigned char TAB_0_4[]={0x00,0x00,0x01,0x02,0x02,0x03,0x03,0x04}; // return 0..4 given index 0 to 7
29-
const unsigned char TAB_0_25[]={0,5,10,15,20,25}; // Given index 0 of 5, return multiple of 5.
30-
const unsigned char TAB_0_25i[]={25,20,15,10,5,0};
25+
static unsigned char TAB_0_5[]={0x05,0x05,0x05,0x04,0x04,0x04,0x03,0x03,0x02,0x02,0x01,0x01,0x01,0x00,0x00,0x00};
26+
static unsigned char TAB_0_5i[]={0x00,0x00,0x00,0x01,0x01,0x01,0x02,0x02,0x03,0x03,0x04,0x04,0x04,0x05,0x05,0x05};
3127

32-
const unsigned char PIX_THRESH[]={0x03,0x02,0x03,0x03,0x02, // Pixel threshold table.
33-
0x03,0x02,0x03,0x03,0x02,
34-
0x02,0x01,0x02,0x02,0x01,
35-
0x02,0x01,0x02,0x02,0x01,
36-
0x03,0x02,0x03,0x03,0x02,
37-
0x03,0x02,0x03,0x03,0x02};
28+
static unsigned char TAB_0_4[]={0x00,0x00,0x01,0x02,0x02,0x03,0x03,0x04}; // return 0..4 given index 0 to 7
29+
30+
static unsigned char PIX_THRESH[]={0x03,0x02,0x03,0x03,0x02, // Pixel threshold table.
31+
0x03,0x02,0x03,0x03,0x02,
32+
0x02,0x01,0x02,0x02,0x01,
33+
0x02,0x01,0x02,0x02,0x01,
34+
0x03,0x02,0x03,0x03,0x02,
35+
0x03,0x02,0x03,0x03,0x02};
3836

3937
static unsigned char PIX_WEIGHTS[]={0x00,0x00,0x00,0x00,0x00, // Pixel weights
40-
0x00,0x00,0x00,0x00,0x00,
41-
0x00,0x00,0x00,0x00,0x00,
42-
0x00,0x00,0x00,0x00,0x00,
43-
0x00,0x00,0x00,0x00,0x00,
44-
0x00,0x00,0x00,0x00,0x00};
38+
0x00,0x00,0x00,0x00,0x00,
39+
0x00,0x00,0x00,0x00,0x00,
40+
0x00,0x00,0x00,0x00,0x00,
41+
0x00,0x00,0x00,0x00,0x00,
42+
0x00,0x00,0x00,0x00,0x00};
4543

46-
static unsigned char pix_cnt;
47-
static unsigned char curr_word;
48-
static unsigned char bb,cc,dd;
49-
static unsigned char algo_switch;
50-
static unsigned char flip_bits;
44+
static unsigned char TAB_0_25[]={0,5,10,15,20,25}; // Given index 0 of 5, return multiple of 5.
5145

52-
extern unsigned char fontm23[768];
46+
static unsigned char pix_cnt; // total # of pixels
47+
static unsigned char curr_word; // current word
48+
static unsigned char u,v; // loop counters
5349

54-
/**
55-
* Algorithm A - Approximately 54 to 85 pixels set, apply box filter
56-
*/
57-
void terminal_char_load_algo_a(void)
58-
{
59-
}
60-
61-
/**
62-
* Algorithm B - Either less than 53 pixels, or more than 84 pixels set, use a simple
63-
* scaling table.
64-
*/
65-
void terminal_char_load_algo_b(unsigned char flip_bits)
66-
{
67-
}
50+
extern unsigned char fontm23[768];
6851

6952
/**
7053
* terminal_char_load - Store a character into the user definable
@@ -73,60 +56,64 @@ void terminal_char_load_algo_b(unsigned char flip_bits)
7356
void terminal_char_load(padWord charnum, charData theChar)
7457
{
7558
// Clear char data.
76-
memset(char_data,0x00,sizeof(char_data));
59+
memset(char_data,0,sizeof(char_data));
7760
memset(PIX_WEIGHTS,0,sizeof(PIX_WEIGHTS));
7861
memset(&fontm23[FONTPTR(charnum)],0,6);
7962
pix_cnt=0;
8063

8164
// Transpose character data.
8265
for (curr_word=0;curr_word<8;curr_word++)
8366
{
84-
for (bb=16; bb-->0; )
67+
for (u=16; u-->0; )
8568
{
86-
if (theChar[curr_word] & 1<<bb)
69+
if (theChar[curr_word] & 1<<u)
8770
{
8871
pix_cnt++;
89-
PIX_WEIGHTS[TAB_0_25[TAB_0_5[bb]]+TAB_0_4[curr_word]]++;
90-
char_data[bb^0x0f]|=BTAB[curr_word];
72+
PIX_WEIGHTS[TAB_0_25[TAB_0_5[u]]+TAB_0_4[curr_word]]++;
73+
char_data[u^0x0F&0x0F]|=BTAB[curr_word];
9174
}
9275
}
9376
}
94-
77+
78+
// Determine algorithm to use for number of pixels.
79+
// Algorithm A is used when roughly half of the # of pixels are set.
80+
// Algorithm B is used either when the image is densely or sparsely populated (based on pix_cnt).
9581
if ((54 <= pix_cnt) && (pix_cnt < 85))
9682
{
97-
for (bb=6; bb-->0; )
83+
// Algorithm A - approx Half of pixels are set
84+
for (u=6; u-->0; )
85+
{
86+
for (v=5; v-->0; )
87+
{
88+
if (PIX_WEIGHTS[TAB_0_25[u]+v] >= PIX_THRESH[TAB_0_25[u]+v])
89+
fontm23[FONTPTR(charnum)+u]|=BTAB[v];
90+
}
91+
}
92+
}
93+
else if ((pix_cnt < 54) || (pix_cnt >= 85))
94+
{
95+
// Algorithm B - Sparsely or heavily populated bitmaps
96+
for (u=16; u-->0; )
9897
{
99-
for (cc=5; cc-->0; )
98+
if (pix_cnt >= 85)
99+
char_data[u]^=0xFF;
100+
101+
for (v=8; v-->0; )
100102
{
101-
if (PIX_WEIGHTS[TAB_0_25i[bb]+cc] >= PIX_THRESH[TAB_0_25i[bb]+cc])
102-
fontm23[FONTPTR(charnum)+bb]|=BTAB[cc];
103+
if (char_data[u] & (1<<v))
104+
{
105+
fontm23[FONTPTR(charnum)+TAB_0_5i[u]]|=BTAB_5[v];
106+
}
103107
}
104-
}
108+
}
109+
if (pix_cnt >= 85)
110+
{
111+
for (u=6; u-->0; )
112+
{
113+
fontm23[FONTPTR(charnum)+u]^=0xFF;
114+
fontm23[FONTPTR(charnum)+u]&=0xF8;
115+
}
116+
}
105117
}
106-
else if ((pix_cnt < 54) || (pix_cnt >= 85))
107-
{
108-
for (bb=16; bb-->0; )
109-
{
110-
// If dense, flip bits around.
111-
if (pix_cnt>=85)
112-
char_data[bb]^=0xff;
113-
114-
for (cc=8; cc-->0; )
115-
{
116-
if (char_data[bb] & (1<<cc))
117-
fontm23[FONTPTR(charnum)+TAB_0_5[bb]]|=BTAB_5[cc];
118-
}
119-
}
120-
121-
// Flip the bits back if densely packed.
122-
if (pix_cnt>=85)
123-
{
124-
for (bb=6; bb-->0; )
125-
{
126-
fontm23[FONTPTR(charnum)+bb]^=0xFF;
127-
fontm23[FONTPTR(charnum)+bb]&=0xF8;
128-
}
129-
}
130-
}
131118
}
132119

0 commit comments

Comments
 (0)