disable lcd controller when booting linux, this prevents ghost-lines while
[linexec-j720] / graphics.cpp
1 #include "stdafx.h"
2 #include "tester1.h"
3 #include <commctrl.h>
4 //#include <aygshell.h>
5 #include <sipapi.h>
6 #include "setup.h"
7
8
9 /* TO DO: Detect whether we're running on an AXIM or an iPAQ at runtime,
10    and set accordingly. */
11
12 #ifdef AXIM
13 #  define FB_ADR        0x14042000
14 #else
15 #  define FB_ADR        0xA0051000
16 #endif
17
18
19
20 #define SET 0xffffffff
21 #define LCD_X_RES 240
22 #define LCD_Y_RES 320
23 UINT16 *fb;
24
25
26 void init_fb()
27 {
28         fb=(UINT16*)VirtualAlloc((void*)0x0,LCD_X_RES*LCD_Y_RES*2, MEM_RESERVE,PAGE_READWRITE);
29         VirtualCopy((void*)fb,(void *) (FB_ADR/256),LCD_X_RES*LCD_Y_RES*2, PAGE_READWRITE|PAGE_NOCACHE|PAGE_PHYSICAL);
30 }
31
32 void try_fb()
33 {
34 //      fb[1]=SET;
35 }
36
37 Image ReadBMP(char FileName[30])
38 {
39  FILE *stream;
40  char buff[29];
41  UINT32 x,y;
42  unsigned char red,green,blue;
43  unsigned long offset;
44  UINT16 *p,c;
45  Image image={NULL};
46  stream=fopen(FileName,"rb");
47  if(!stream) return image;
48  fread(buff,26,1,stream);
49
50  offset=(unsigned char)buff[13]*16777216+(unsigned char)buff[12]*65536+(unsigned char)buff[11]*256+(unsigned char)buff[10];
51  x=(unsigned char)buff[21]*256*256*256+(unsigned char)buff[20]*256*256+(unsigned char)buff[19]*256+(unsigned char)buff[18];
52  y=(unsigned char)buff[25]*256*256*256+(unsigned char)buff[24]*256*256+(unsigned char)buff[23]*256+(unsigned char)buff[22];
53 // offset=54;
54  UINT32 imgx=x,imgy=y;
55  if(x<32) x=32;
56  if(y<32) y=32;
57  p=image.p=(UINT16*)malloc(x*y*2);
58  if(!image.p) return(image);
59  fseek(stream,offset,SEEK_SET);
60  p+=(x*y+x);
61
62 for(UINT32 zz=0;zz<y;zz++)
63  {
64  p-=2*x;
65
66  for(UINT32 yy=0;yy<x;yy++)
67   {
68    blue=fgetc(stream);
69    green=fgetc(stream);
70    red=fgetc(stream);
71    c=(red/8)*2048+(green/4)*32+blue/8;
72    *p=c;
73    p++;
74
75   }
76
77 }
78 //image.p=p;
79 image.x=imgx;
80 image.y=imgy-1;
81 fclose(stream);
82 return(image);
83 }
84
85 // shows picture pointed to by p, with res (x by y), at (x_pos, y_pos)
86 void ShowImage(UINT16 *p, int x, int y,int x_pos,int y_pos)
87 {
88         UINT16 *fb=::fb;
89         if(!p) return;
90         fb+=y_pos*LCD_X_RES+x_pos;
91         for(int yy=0;yy<y;yy++)
92         {
93                 for(int xx=0;xx<x;xx++)
94                 {
95                         *fb=*p;
96                 fb++;
97                 p++;
98                 }
99                 if(x<LCD_X_RES) fb+=LCD_X_RES-x;
100         }
101 }