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
|
#include "all.h"
#include <libg.h>
#include <gnot.h>
enum {
Colldepth = 3,
Colmaxx = 640,
Colmaxxvis = 640,
Colmaxy = 480,
};
#define MINX 8
extern GSubfont defont0;
struct{
Point pos;
int bwid;
}out;
typedef struct Mode Mode;
struct Mode {
int x;
int y;
int d;
char* aperture;
int apsize;
};
GBitmap gscreen;
Point gchar(GBitmap*, Point, GFont*, int, Fcode);
int setcolor(ulong, ulong, ulong, ulong);
static void lcdinit(Mode*);
void
screeninit(void)
{
Mode m;
m.x = Colmaxx;
m.y = Colmaxy;
m.d = Colldepth;
m.aperture = 0;
lcdinit(&m);
if(m.aperture == 0)
return;
gscreen.ldepth = 3;
gscreen.base = (ulong*)m.aperture;
gscreen.width = Colmaxx/BY2WD;
gscreen.r = Rect(0, 0, Colmaxxvis, Colmaxy);
gscreen.clipr = gscreen.r;
/*
* For now, just use a fixed colormap:
* 0 == white and 255 == black
*/
setcolor(0, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF);
setcolor(255, 0x00000000, 0x00000000, 0x00000000);
gbitblt(&gscreen, Pt(0, 0), &gscreen, gscreen.r, Zero);
out.pos.x = MINX;
out.pos.y = 0;
out.bwid = defont0.info[' '].width;
}
void
screenputc(int c)
{
Fontchar *i;
Point p;
if(gscreen.base == nil)
return;
switch(c){
case '\n':
out.pos.x = MINX;
out.pos.y += defont0.height;
if(out.pos.y > gscreen.r.max.y-defont0.height)
out.pos.y = gscreen.r.min.y;
gbitblt(&gscreen, Pt(0, out.pos.y), &gscreen,
Rect(0, out.pos.y, gscreen.r.max.x, out.pos.y+2*defont0.height),
Zero);
break;
case '\t':
out.pos.x += (8-((out.pos.x-MINX)/out.bwid&7))*out.bwid;
if(out.pos.x >= gscreen.r.max.x)
screenputc('\n');
break;
case '\b':
if(out.pos.x >= out.bwid+MINX){
out.pos.x -= out.bwid;
screenputc(' ');
out.pos.x -= out.bwid;
}
break;
default:
if(out.pos.x >= gscreen.r.max.x-out.bwid)
screenputc('\n');
c &= 0x7f;
if(c <= 0 || c >= defont0.n)
break;
i = defont0.info + c;
p = out.pos;
gbitblt(&gscreen, Pt(p.x+i->left, p.y), defont0.bits,
Rect(i[0].x, 0, i[1].x, defont0.height),
S);
out.pos.x = p.x + i->width;
break;
}
}
void
screenputs(char *s, int n)
{
while(n-- > 0)
screenputc(*s++);
}
/*
* See section 5.2.1 (page 5-6) of the MPC823 manual
*/
static uchar lcdclock[17] = { /* (a<<2)|b => divisor of (1<<a)*((b<<1)+1) */
0, 0, (1<<2), 1,
(2<<2), 2, (1<<2)|1, 3,
(3<<2), (1<<2)|2, (1<<2)|2, (2<<2)|1,
(2<<2)|1, (1<<2)|3, (1<<2)|3, (4<<2),
(4<<2)
};
/*
* support for the Sharp LQ64D341 TFT colour display
*/
enum {
COLS = 640,
ROWS = 480,
LDEPTH = 3, /* screen depth */
LCDFREQ = 25000000,
/* lccr */
ClockLow = 1<<11,
OELow = 1<<10,
HsyncLow = 1<<9,
VsyncLow = 1<<8,
DataLow = 1<<7,
Passive8 = 1<<4,
DualScan = 1<<3,
IsColour = 1<<2,
IsTFT = 1<<1,
Enable = 1<<0,
/* lchcr */
BigEndian = 1<<24,
AT7 = 7<<21, /* access type */
/* sdcr */
LAM = 1<<6, /* ``LCD aggressive mode'' */
};
/*
* TO DO: most of the data could come from a table
*/
static void
lcdinit(Mode *mode)
{
IMM *io;
int i, d;
long hz;
io = m->iomem;
mode->y = ROWS;
mode->x = COLS;
mode->d = LDEPTH;
mode->aperture = ialloc(mode->x*mode->y, 16);
mode->apsize = mode->x*mode->y;
io->sdcr &= ~LAM; /* MPC823 errata: turn off LAM before disabling controller */
io->lcfaa = PADDR(mode->aperture);
io->lccr = (((mode->x*mode->y*(1<<LDEPTH)+127)/128) << 17) | (LDEPTH << 5) | IsColour | IsTFT | OELow | VsyncLow | ClockLow;
switch(LDEPTH){
default:
case 0:
/* monochrome/greyscale identity map */
for(i=0; i<16; i++)
io->lcdmap[i] = i;
break;
case 2:
/* 4-bit grey scale map */
for(i=0; i<16; i++)
io->lcdmap[0] = (i<<8)|(i<<4)|i;
break;
case 3:
/* 8-bit linear map */
for(i=0; i<256; i++)
io->lcdmap[i] = (i<<8)|(i<<4)|i;
break;
}
io->lcvcr = (mode->y << 11) | (1<<28) | 33; /* 2 line vsync pulse, 34 line wait between frames */
io->lchcr = (mode->x<<10) | BigEndian | 228; /* clock cycles between lines */
hz = m->cpuhz;
d = hz/LCDFREQ;
if(hz/d > LCDFREQ)
d++;
if(d >= 16)
d = 16;
/*
* enable LCD outputs
*/
io->pddat = 0;
io->pdpar = 0x1fff;
io->pdpar &= ~SIBIT(6); /* 823 bug fix? */
io->pddir = 0x1fff;
io->pbpar |= IBIT(31) | IBIT(19) | IBIT(17);
io->pbdir |= IBIT(31) | IBIT(19) | IBIT(17);
io->pbodr &= ~(IBIT(31) | IBIT(19) | IBIT(17));
eieio();
io->sccrk = KEEP_ALIVE_KEY;
eieio();
io->sccr = (io->sccr & ~0x1F) | lcdclock[d];
eieio();
io->sccrk = ~KEEP_ALIVE_KEY;
eieio();
gscreen.width = gscreen.width; /* access external memory before enabling (mpc823 errata) */
io->lcsr = 7; /* clear status */
eieio();
io->lccr |= Enable;
archbacklight(1);
}
int
setcolor(ulong p, ulong r, ulong g, ulong b)
{
r >>= 28;
g >>= 28;
b >>= 28;
m->iomem->lcdmap[~p&0xFF] = (r<<8) | (g<<4) | b; /* TO DO: it's a function of the ldepth */
return 1;
}
|