1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
|
#include "print_utils.h"
int term_fprint( screen_mode_e mode, FILE *f )
{
int ret=-1;
if (f == NULL)
return -1;
switch ( mode )
{
case SCREEN_MODE_80x24:
{
/*
const int m_x=80,m_y=24;
int x=0,y=0;
int fret=1;
char c;
while ((fret = fread(&c,1,1,f)) == 1)
{
if ( c != '\n' )
{
if ( (x < m_x) && (y < m_y) )
{
putc( c );
}
x+=1;
} else if ( c == '\n' )
{
x = 0;
y += 1;
}
}
*/
}
break;
default:
printf("Unknown screen mode\n");
}
return ret;
}
//print data to terminal starting from x,y
//return 0x0000yyyy0000xxxx, current stopped position
int term_print( term_screen *ts, const char *buf, size_t size,
int init_x, int init_y )
{
int posx=0, posy=0;
int ret=-1;
if ( buf == NULL )
{
return -1;
}
if ( size <= 0 )
{
return -1;
}
//calculate position
//fix for diff modes also needed
if ( ts->term_col > 80)
{
posx = (ts->term_col-80)/2;
}
if (ts->term_row > 24)
{
posy = (ts->term_row-24)/2;
}
switch ( ts->mode )
{
case SCREEN_MODE_80x24:
{
int m_x=80, m_y=24;
int x=init_x, y=init_y;
char c;
int i,j;
if (( init_x == 0 ) && (init_y == 0))
{
for (i=0; i<posx;i++)
printf(" ");
}
//draw image according to mode
for (i=0; i<size; i++)
{
c = buf[i];
if ( c == '\n' )
{
printf("\n");
//set
for (j=0; j<posx; j++)
printf(" ");
x = 0;
y += 1;
//printf("asdasdsad\n");
} else if ( c != '\n' )
{
if ( (x < m_x ) && (y < m_y) )
{
printf("%c",c);
}
x += 1;
}
}
ret = x&0x0000ffff | ((y&0x0000ffff)<<16);
//printf( "%08x\n", ret );
}
break;
default:
printf("Unknown mode\n");
}
return ret;
}
|