-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLCD.pas
More file actions
351 lines (295 loc) · 10.9 KB
/
LCD.pas
File metadata and controls
351 lines (295 loc) · 10.9 KB
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
// Interface to LCD Device Driver (Graphic Display Module)
// Date 26.05.22
// 25.07.17 nk opt for XE3 (AnsiString <-> string)
// 25.07.17 nk opt use string instead of ShortString (e.g. old=string[MAXBUFF])
unit LCD;
interface
uses
Forms, Types, Controls, Graphics, GraphUtil, SysUtils, ExtCtrls, USystem,
SYS, Global, Data, FLog, UPidi;
const
LCDTEXT = 0; // internal address for text
LCDGRAF = 1; // internal address for graphics
LCDPEN = 0; // default graphic pen
LCDDOTON = 0; // display dot modes
LCDDOTOFF = 1;
LCDDOTINV = 2;
LCDDOTNEG = 3;
LCDBYTE = 8; // number of dots per byte
LCDLAYER_1 = 1; // display screen layers
LCDLAYER_2 = 2;
LCDLAYER_3 = 3;
LCDRESETLEN = 50; // reset pulse length (50ms)
LCDSETTYPE = $90; // set LCD type
LCDSETCHARS = $9C; // set LCD characters/line (then make reset)
LCDSETMODE = $9D; // set LCD curser mode (0=wrap, 1=stay, 2=stop)
LCDSETPARAM = $9E; // set LCD initial parameter
LCDSETCPULOAD = $9F; // set LCD CPU load (4..128)
LCDSETINITIAL = $B0; // set LCD to initial state (SW reset)
LCDTEXTON = '<1Bh>T<1><0F0h>'; // text mode on
LCDTEXTOFF = '<1Bh>T<0><0F0h>'; // text mode off
LCDGRAFON = '<1Bh>G<1><0F0h>'; // graphic mode on
LCDGRAFOFF = '<1Bh>G<0><0F0h>'; // graphic mode off
LCDINTFONT = '<1Bh>m<0><0F0h>'; // internal char font
LCDEXTFONT = '<1Bh>m<8><0F0h>'; // external char font
LCDMODEOR = '<1Bh>m<0><0F0h>'; // mode OR
LCDMODEXOR = '<1Bh>m<1><0F0h>'; // mode XOR
LCDMODEAND = '<1Bh>m<3><0F0h>'; // mode AND
LCDCURSON1 = '<1Bh>c<0><0F0h>'; // cursor 1 pixel
LCDCURSON2 = '<1Bh>c<1><0F0h>'; // cursor 2 pixel
LCDCURSON3 = '<1Bh>c<8><0F0h>'; // cursor 1 pixel, blinking
LCDCURSON4 = '<1Bh>c<15><0F0h>'; // cursor 8 pixel, blinking
LCDCURSOFF = '<1Bh>c<10h><0F0h>'; // cursor off
LCDCURSHOME = '<02h>'; // cursor home position
LCDCURS_FS = '<05h>'; // cursor move right
LCDCURS_BS = '<08h>'; // cursor move left
LCDCURS_LF = '<0Ah>'; // cursor move down
LCDCURS_UP = '<0Bh>'; // cursor move up
LCDCURS_CR = '<0Dh>'; // cursor carriage return
LCDCLEAR = '<00>'; // display clear pattern
LCDUNIT = ' dots'; // display standard unit
LCDRESUNIT = ' bits'; // display resolution unit (DELPHI only)
var // module variables
LcdPenX: Byte; // DELPHI only
LcdPenY: Byte; // remember last line point
LcdInit: Byte; // graphic display init flag
LcdScale: Long; // graphic display scaling factor [%]
LcdBuff: string; // modul message buffer / old=[MAXTEMP]
LcdScreen: TRect; // display screen buffer
LcdBuffer: TImage; // display working buffer
LcdLayer1: TImage; // display layer buffer
LcdLayer2: TImage;
LcdLayer3: TImage;
// Tiger interface to LCD device driver (LCD.INC)
procedure InitLcd;
procedure ResetLcd(Delay: Byte);
procedure UpdateLcd;
procedure SaveLcd(Layer: Byte);
procedure LoadLcd(Layer: Byte);
// Tiger LCD device driver functions (LCD.TDD)
procedure Put_LCD(LCD: TBitmap; White, Black: Byte);
procedure SetDot(X, Y, Mode, Pen: Long);
procedure GraphicCopy(Bitmap: TImage; W, H, X, Y, W2, H2, X2, Y2, W3, H3, Mode: Long);
procedure GraphicFillMask(W, H, X, Y, W2, H2, Dot: Long);
implementation
uses FMain, FGui;
//------------------------------------------------------------------------------
// INITLCD - Initialize graphic display and controller
//------------------------------------------------------------------ 17.02.07 --
procedure InitLcd;
var
tb, sb: Long; //DELPHI only
bt, fr, h, w: Cardinal;
begin
LcdInit := cOFF;
ErrCode := cOFF;
LcdBuff := GetScreen(w, h, fr, bt);
LogEvent('InitLcd', 'Display settings', LcdBuff);
if bt < 16 then ErrCode := cON; // too little colors
if ErrCode > cOFF then begin // LCD driver error
LcdBuff := FloatToStr(bt) + LCDRESUNIT;
LogError('InitLcd', 'Color resolution too low', LcdBuff, $96);
ErrCode := cOFF;
end;
try
LcdBuff := 'Creating display buffers';
LcdBuffer := TImage.Create(Gui); // display working buffer
LcdLayer1 := TImage.Create(Gui); // display layer buffers
LcdLayer2 := TImage.Create(Gui);
LcdLayer3 := TImage.Create(Gui);
LcdBuff := 'Initializing screen buffer';
with LcdBuffer do begin
Width := LCDXRANGE;
Height := LCDYRANGE;
Visible := False; //02.03.07 nk del LoadBitmap
h := Round(Height * (LcdScale / PROCENT)) + Picture.Bitmap.Height;
w := Round(Width * (LcdScale / PROCENT)) + Picture.Bitmap.Width;
LcdScreen := Rect(0, 0, w, h);
end;
LcdBuff := 'Initializing graphic display';
with Gui do begin
sb := Width - ClientWidth; //05.05.07 nk add ff
tb := Height - ClientHeight;
if BorderStyle = bsSizeable then begin
Height := h + tb + 2;
Width := w + sb + 2;
end else begin
Height := h + tb;
Width := w + sb;
end;
end;
with Gui.Display do begin
Left := 0;
Top := 0;
Width := w;
Height := h;
Picture.Graphic := nil;
Visible := True;
BringToFront;
end;
with LcdLayer1 do begin
Width := LCDXRANGE;
Height := LCDYRANGE;
end;
with LcdLayer2 do begin
Width := LCDXRANGE;
Height := LCDYRANGE;
end;
with LcdLayer3 do begin
Width := LCDXRANGE;
Height := LCDYRANGE;
end;
except
LogError('InitLcd', LcdBuff, 'failed!', $A0);
Main.Close; // fatal error - abort program
WaitDuration(DISPDELAY);
Halt;
end;
LcdInit := cINIT;
LcdBuff := IntToStr(LCDXRANGE) + sDIM + IntToStr(LCDYRANGE) + LCDUNIT;
LogEvent('InitLcd', 'Graphic display initialized to ', LcdBuff);
end;
//------------------------------------------------------------------------------
// RESETLCD - Reset graphic display and controller
//------------------------------------------------------------------ 17.02.07 --
procedure ResetLcd(Delay: Byte);
begin
with Gui.Display do begin
Visible := False;
Picture.Graphic := nil;
if Delay = cOFF then
WaitDuration(LCDRESETLEN)
else
WaitDuration(Delay);
Visible := True;
WaitDuration(LCDRESETLEN);
end;
end;
//------------------------------------------------------------------------------
// UPDATELCD - Update the graphic display screen (for 8x8 font select only)
//------------------------------------------------------------------ 17.02.07 --
procedure UpdateLcd;
begin
with Gui.Display do begin
// swap display screen buffers
Canvas.StretchDraw(LcdScreen, LcdBuffer.Picture.Bitmap);
// DELPHI: simulate contrast and brightness
Put_LCD(Picture.Bitmap, Brightness, Contrast);
Application.ProcessMessages;
end;
end;
//------------------------------------------------------------------------------
// SAVELCD - Save actual screen buffer to a layer buffer (1..3)
//------------------------------------------------------------------ 17.02.07 --
procedure SaveLcd(Layer: Byte);
var
let: TRect;
begin
let := Rect(0, 0, LCDXRANGE, LCDYRANGE);
case Layer of
LCDLAYER_1: LcdLayer1.Canvas.CopyRect(let, LcdBuffer.Canvas, let);
LCDLAYER_2: LcdLayer2.Canvas.CopyRect(let, LcdBuffer.Canvas, let);
LCDLAYER_3: LcdLayer3.Canvas.CopyRect(let, LcdBuffer.Canvas, let);
else
LcdBuff := IntToStr(Layer);
LogError('SaveLcd', 'Unsupported screen layer', LcdBuff, $91);
end;
end;
//------------------------------------------------------------------------------
// LOADLCD - Load saved layer buffer into screen buffer
//------------------------------------------------------------------ 17.02.07 --
procedure LoadLcd(Layer: Byte);
var
let: TRect;
begin
let := Rect(0, 0, LCDXRANGE, LCDYRANGE);
case Layer of
LCDLAYER_1: LcdBuffer.Canvas.CopyRect(let, LcdLayer1.Canvas, let);
LCDLAYER_2: LcdBuffer.Canvas.CopyRect(let, LcdLayer2.Canvas, let);
LCDLAYER_3: LcdBuffer.Canvas.CopyRect(let, LcdLayer3.Canvas, let);
else
LcdBuff := IntToStr(Layer);
LogError('LoadLcd', 'Unsupported screen layer', LcdBuff, $91);
end;
end;
//------------------------------------------------------------------------------
// PUT_LCD - DELPHI implementation for Tiger put #LCD
//------------------------------------------------------------------ 17.02.07 --
procedure Put_LCD(LCD: TBitmap; White, Black: Byte);
var
x, y: Long;
p: PByteArray;
begin
LCD.PixelFormat := pf24Bit;
// simulate contrast and brightness
for y := 0 to LCD.Height - 1 do begin
p := LCD.ScanLine[y];
for x := 0 to LCD.Width * 3 - 1 do begin
if p[x] = 255 then p[x] := 12 * White div 10 + 135; // white dots 147..255
if p[x] = 0 then p[x] := 12 * (10 - Black div 10); // black dots 0..108
end;
end;
end;
//------------------------------------------------------------------------------
// SETDOT - DELPHI implementation for Tiger set_dot
//------------------------------------------------------------------ 17.02.07 --
procedure SetDot(X, Y, Mode, Pen: Long);
var
col: TColor; // Pen not used (=0)
begin
if Mode = 0 then
col := clBlack
else
col := clWhite;
LcdBuffer.Canvas.Pixels[X, Y] := col;
end;
//------------------------------------------------------------------------------
// GRAPHICCOPY - DELPHI implementation for Tiger graphic_copy
//------------------------------------------------------------------ 17.02.07 --
procedure GraphicCopy(Bitmap: TImage; W, H, X, Y, W2, H2, X2, Y2, W3, H3, Mode: Long);
var
mask, copy: TRect;
begin
copy := Rect(X2, Y2, X2 + W3, Y2 + H3);
mask := Rect(X, Y, X + W3, Y + H3);
case Mode of
0: LcdBuffer.Canvas.CopyMode := cmSrcCopy;
1: LcdBuffer.Canvas.CopyMode := cmSrcPaint;
2: LcdBuffer.Canvas.CopyMode := cmSrcAnd;
3: LcdBuffer.Canvas.CopyMode := cmMergePaint;
else
LcdBuffer.Canvas.CopyMode := cmSrcCopy;
end;
LcdBuffer.Canvas.CopyRect(mask, Bitmap.Canvas, copy);
end;
//------------------------------------------------------------------------------
// GRAPHICFILLMASK - DELPHI implementation for Tiger graphic_fill_mask
//------------------------------------------------------------------ 17.02.07 --
procedure GraphicFillMask(W, H, X, Y, W2, H2, Dot: Long);
var
mask: TRect;
begin
mask := Rect(X, Y, X + W2, Y + H2);
if Dot = 0 then
LcdBuffer.Canvas.Brush.Color := clWhite
else
LcdBuffer.Canvas.Brush.Color := clBlack;
LcdBuffer.Canvas.FillRect(mask);
end;
initialization // Tiger hardware configuration
LcdPenX := cCLEAR;
LcdPenY := cCLEAR;
LcdInit := cOFF;
LcdScale := 200; // [%]
LcdScreen := Rect(0, 0, LCDXRANGE, LCDYRANGE);
LcdBuff := sEMPTY;
finalization
LcdPenX := cCLEAR;
LcdPenY := cCLEAR;
LcdInit := cOFF;
LcdBuff := sEMPTY;
LcdBuffer := nil;
LcdLayer1 := nil;
LcdLayer2 := nil;
LcdLayer3 := nil;
end.