-
Notifications
You must be signed in to change notification settings - Fork 0
/
vid.c
executable file
·381 lines (337 loc) · 8.24 KB
/
vid.c
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
/********************************************************************
Copyright 2010-2017 K.C. Wang, <[email protected]>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
********************************************************************/
// vid.c file: implement fbuf for the ARM PL110 LCD display
/**************** Reference: ARM PL110 and DUI02241 ********************
Color LCD base address: 0x10120000 - 0x1012FFFF
00 timing0
04 timing1
08 timing2
0C timing3
10 upperPanelframeBaseAddressRegister // use only ONE panel
14 lowerPanelFrameBaseAddressRegister // some display allows 2 panels
18 interruptMaskClrregister
1C controlRegister
20 interruptStatusReg
etc
************************************************************************/
#include "font0" // NOTE: font0 is NOT a bitmap but char fonts0={ char map }
extern int color;
extern char *tab;
u8 cursor;
int volatile *fb;
unsigned char *font;
int row, col, scrow_row = 4;
int WIDTH = 640;
extern uprintf(char *fmt, ...);
int fbuf_init()
{
int x; int i;
/**** for SVGA 800X600 these values are in ARM DUI02241 *********
*(volatile unsigned int *)(0x1000001c) = 0x2CAC; // 800x600
*(volatile unsigned int *)(0x10120000) = 0x1313A4C4;
*(volatile unsigned int *)(0x10120004) = 0x0505F6F7;
*(volatile unsigned int *)(0x10120008) = 0x071F1800;
*(volatile unsigned int *)(0x10120010) = (1*1024*1024); *(volatile unsigned t *)(0x10120018) = 0x82B;
***************************************************************/
/********* for VGA 640x480 ************************/
*(volatile unsigned int *)(0x1000001c) = 0x2C77; // LCDCLK SYS_OSCCLK
*(volatile unsigned int *)(0x10120000) = 0x3F1F3F9C; // time0
*(volatile unsigned int *)(0x10120004) = 0x090B61DF; // time1
*(volatile unsigned int *)(0x10120008) = 0x067F1800; // time2
*(volatile unsigned int *)(0x10120010) = (6*1024*1024); // panelBaseAddress
*(volatile unsigned int *)(0x10120018) = 0x82B; // control register
/****** at 0x200-0x3FC are LCDpalletes of 128 words ***************
unsigned int *inten = (unsigned int *)(0x10120200);
for (i=0; i<128; i++){
inten[i]=0x8F008F00;
}
******** yet to figure out HOW TO use these palletes *************/
fb = (int *)(6*1024*1024); // at 1MB area; enough for 800x600 SVGA
font = fonts0; // use fonts0 for char bit patterns
// for (x = 0; x < (800 * 600); ++x) // for one BAND
/******** these will show 3 bands of BLUE, GREEN, RED *********
for (x = 0; x < (212*480); ++x)
fb[x] = 0x00FF0000; //00BBGGRR
for (x = 212*480+1; x < (424*480); ++x)
fb[x] = 0x0000FF00; //00BBGGRR
for (x = 424*480+1; x < (640*480); ++x)
fb[x] = 0x000000FF; //00BBGGRR
************* used only during intial testing ****************/
// for 640x480 VGA mode display
for (x=0; x<640*480; x++)
fb[x] = 0x00000000; // clean screen; all pixels are BLACK
cursor = 127; // cursor bit map in font0 at 127
}
int clrpix(int x, int y)
{
int pix = y*640 + x;
fb[pix] = 0x00000000;
}
int setpix(int x, int y)
{
int pix = y*640 + x;
if (color==RED)
fb[pix] = 0x000000FF;
if (color==BLUE)
fb[pix] = 0x00FF0000;
if (color==GREEN)
fb[pix] = 0x0000FF00;
if (color==WHITE)
fb[pix] = 0x00FFFFFF;
if (color==YELLOW)
fb[pix] = 0x0000FFFF;
if (color==CYAN)
fb[pix] = 0x00FFFF00;
}
int dchar(unsigned char c, int x, int y)
{
int r, bit;
unsigned char *caddress, byte;
caddress = font + c*16;
// printf("c=%x %c caddr=%x\n", c, c, caddress);
for (r=0; r<16; r++){
byte = *(caddress + r);
for (bit=0; bit<8; bit++){
if (byte & (1<<bit))
setpix(x+bit, y+r);
}
}
}
int undchar(unsigned char c, int x, int y)
{
int row, bit;
unsigned char *caddress, byte;
caddress = font + c*16;
// printf("c=%x %c caddr=%x\n", c, c, caddress);
for (row=0; row<16; row++){
byte = *(caddress + row);
for (bit=0; bit<8; bit++){
if (byte & (1<<bit))
clrpix(x+bit, y+row);
}
}
}
int dstring(char *s, int x, int y)
{
while(*s){
dchar(*s, x, y);
x+=8;
s++;
}
}
/************
int scroll()
{
int i;
for (i=0; i<640*480-640*16; i++){
fb[i] = fb[i+ 640*16];
}
}
************/
int scroll()
{
int i;
for (i=scrow_row*16*640; i<640*480-640*16; i++){
fb[i] = fb[i+ 640*16];
}
}
int kpchar(char c, int ro, int co)
{
int x, y;
x = co*8;
y = ro*16;
//printf("c=%x [%d%d] (%d%d)\n", c, ro,co,x,y);
dchar(c, x, y);
}
int unkpchar(char c, int ro, int co)
{
int x, y;
x = co*8;
y = ro*16;
//printf("c=%x [%d%d] (%d%d)\n", c, ro,co,x,y);
undchar(c, x, y);
}
int erasechar()
{
// erase char at (row,col)
int r, bit, x, y;
unsigned char *caddress, byte;
x = col*8;
y = row*16;
//printf("ERASE: row=%d col=%d x=%d y=%d\n",row,col,x,y);
for (r=0; r<16; r++){
for (bit=0; bit<8; bit++){
clrpix(x+bit, y+r);
}
}
}
int clrcursor()
{
unkpchar(cursor, row, col);
}
int putcursor(unsigned char c)
{
kpchar(c, row, col);
}
int kputc(char c)
{
clrcursor();
if (c=='\r'){
col=0;
//printf("row=%d col=%d\n", row, col);
putcursor(cursor);
return;
}
if (c=='\n'){
row++;
if (row>=25){
row = 24;
scroll();
}
//printf("row=%d col=%d\n", row, col);
putcursor(cursor);
return;
}
if (c=='\b'){
if (col>0){
col--;
erasechar();
putcursor(cursor);
}
return;
}
// c is ordinary char
kpchar(c, row, col);
col++;
if (col>=80){
col = 0;
row++;
if (row >= 25){
row = 24;
scroll();
}
}
putcursor(cursor);
//printf("row=%d col=%d\n", row, col);
}
int kprints(char *s)
{
while(*s){
kputc(*s);
s++;
}
}
int krpx(int x)
{
char c;
if (x){
c = tab[x % 16];
krpx(x / 16);
}
kputc(c);
}
int kprintx(int x)
{
kputc('0'); kputc('x');
if (x==0)
kputc('0');
else
krpx(x);
kputc(' ');
}
int krpu(int x)
{
char c;
if (x){
c = tab[x % 10];
krpu(x / 10);
}
kputc(c);
}
int kprintu(int x)
{
if (x==0){
kputc(' ');kputc('0');
}
else
krpu(x);
kputc(' ');
}
int kprinti(int x)
{
if (x<0){
kputc('-');
x = -x;
}
kprintu(x);
}
int kprintf(char *fmt,...)
{
int *ip;
char *cp;
cp = fmt;
ip = (int *)&fmt + 1;
while(*cp){
if (*cp != '%'){
kputc(*cp);
if (*cp=='\n')
kputc('\r');
cp++;
continue;
}
cp++;
switch(*cp){
case 'c': kputc((char)*ip); break;
case 's': kprints((char *)*ip); break;
case 'd': kprinti(*ip); break;
case 'u': kprintu(*ip); break;
case 'x': kprintx(*ip); break;
}
cp++; ip++;
}
}
int show_bmp(char *p, int startRow, int startCol)
{
int h, w, pixel, r1, r2, i, j;
unsigned char r, g, b;
char *pp;
int *q = (int *)(p+14); // skip over 14 bytes file header
q++; // skip 4 bytes in image header
w = *q; // width in pixels
h = *(q + 1); // height in pixels
p += 54; // p point at pixels now
// but the picture is up-side DOWN
r1 = 3*w;
r2 = 4*((3*w+3)/4); // row size is a multiple of 4 bytes
//p = (char *)(pp + (h-1)*r2); // 3 bytes per pixel
// p += (h-1)*r2;
// p += h*r2;
p += (h-1)*r2;
for (i=startRow; i<h+startRow; i++){
pp = p;
// for (j=startCol; j<w+startCol; j++){
for (j=startCol; j<startCol+w; j++){
b = *pp; g = *(pp+1); r = *(pp+2);
pixel = (b<<16) + (g<<8) + r;
fb[i*640 + j] = pixel;
pp += 3; // back pp by 3 bytes
}
p -= r2;
}
/*********
row = 20;
kprintf("h=%d w=%d r1=%d r2=%d\n", h, w, r1, r2);
******/
uprintf("\nBMP image height=%d width=%d\n", h, w);
}