Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
670 | bw | 1 | unit LRLRoutines; |
2 | |||
3 | {$mode objfpc} |
||
4 | {$asmmode intel} |
||
5 | |||
6 | |||
7 | interface |
||
8 | |||
9 | |||
10 | procedure ImagePut(var Screen, ImageBuffer; X, Y: Integer; Winx1, Winy1, Winx2, Winy2: Word); |
||
11 | procedure ImagePutTransparent(var Screen, ImageBuffer; X, Y: Integer; Winx1, Winy1, Winx2, Winy2: Word); |
||
12 | procedure ImageFill(var ImageBuffer; SizeX, SizeY: Word; Value: Byte); |
||
13 | function ImageSizeX(var ImageBuffer): Word; |
||
14 | function ImageSizeY(var ImageBuffer): Word; |
||
15 | procedure ImageStringGet(Source: String; var FontData, Buffer; ColorOffs: Byte); |
||
16 | procedure ScreenApply(var Buffer); |
||
17 | procedure ImageClear(var Buffer); |
||
18 | |||
19 | procedure Palette256Set(var Palette256); |
||
20 | procedure Palette256Get(var Palette256); |
||
21 | procedure Palette256Grayscale(var Palette256; StartElement, EndElement: Byte); |
||
22 | procedure Palette256Darken(var Palette256; StartElement, EndElement, Decrement, MinValue: Byte); |
||
23 | procedure Palette256Transform(var SourcePalette, DestinationPalette); |
||
24 | function DataByteGet(var Buffer; BufferOffset: Word): Byte; |
||
25 | procedure DataBytePut(var Buffer; BufferOffset: Word; Value: Byte); |
||
26 | function DataWordGet(var Buffer; BufferOffset: Word): Word; |
||
27 | procedure DataWordPut(var Buffer; BufferOffset: Word; Value: Word); |
||
28 | procedure DataMove(var Source, Destination; Count: Word; SourceOffset, DestinationOffset: Word); |
||
29 | procedure DataAdd(var Buffer; Count: Word; Amount: Byte; BufferOffset: Word); |
||
30 | procedure DataFill(var Buffer; Count: Word; Value: Byte; BufferOffset: Word); |
||
31 | function DataIdentical(var Array1, Array2; Count: Word; Array1Offset, Array2Offset: Word): Boolean; |
||
32 | function ReadKey: Word; |
||
33 | function Keypressed: Boolean; |
||
34 | function SetInterrupt(Int: Byte; NewAddress: Pointer): Pointer; |
||
35 | procedure FadeClear; |
||
36 | procedure FadeTo(pal: Pointer); |
||
37 | procedure DecompressRepByte(var InArray, OutArray; InArraySize: Word; var OutArraySize: Word); |
||
38 | function MSMouseInArea(x1, y1, x2, y2: Integer): Boolean; |
||
39 | function MSMouseDriverExist: Boolean; |
||
40 | procedure MSMouseGetXY(var x, y: Integer); |
||
41 | function MSMouseButtonStatusGet: Word; |
||
42 | function MSMouseButtonWasPressed(Button: Word; var x, y: Integer): Boolean; |
||
43 | function MSMouseButtonWasReleased(Button: Word; var x, y: Integer): Boolean; |
||
44 | procedure MSMouseSetXY(x, y: Integer); |
||
45 | procedure KeyboardFlush; |
||
46 | function GetInterrupt(Int: Byte): Pointer; |
||
47 | |||
48 | procedure AssignFile(var AFile: File; AFileName: String); |
||
49 | function LastDosTick(): Longword; |
||
50 | |||
51 | |||
52 | implementation |
||
53 | |||
54 | |||
55 | uses |
||
56 | SysUtils; |
||
57 | |||
58 | |||
59 | const |
||
60 | SCREEN_WIDTH = 320; |
||
61 | SCREEN_HEIGHT = 200; |
||
62 | |||
63 | type |
||
64 | PRGBColor = ^TRGBColor; |
||
65 | TRGBColor = packed record |
||
66 | R, G, B: Byte; |
||
67 | end; |
||
68 | |||
69 | PRGBPalette = ^TRGBPalette; |
||
70 | TRGBPalette = array[Byte] of TRGBColor; |
||
71 | |||
72 | var |
||
73 | ScreenRGBPalette: TRGBPalette; |
||
74 | ScreenRGBBuffer : array[0..SCREEN_HEIGHT - 1, 0..SCREEN_WIDTH - 1] of TRGBColor; |
||
75 | ScreenBuffer : array[0..SCREEN_WIDTH * SCREEN_HEIGHT - 1] of Byte; |
||
76 | |||
77 | AlreadyKeyPressed: Boolean = False; |
||
78 | |||
79 | |||
80 | procedure Paint; |
||
81 | begin |
||
82 | kos_begindraw(); |
||
83 | kos_definewindow(500, 100, SCREEN_WIDTH - 1, SCREEN_HEIGHT - 1, $01000000); |
||
84 | kos_drawimage24(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, @ScreenRGBBuffer); |
||
85 | kos_enddraw(); |
||
86 | end; |
||
87 | |||
88 | procedure UpdateRGBBuffer; |
||
89 | var |
||
90 | I, J: Longint; |
||
91 | B: PByte; |
||
92 | begin |
||
93 | B := @ScreenBuffer; |
||
94 | for I := 0 to SCREEN_HEIGHT - 1 do |
||
95 | for J := 0 to SCREEN_WIDTH - 1 do |
||
96 | begin |
||
97 | ScreenRGBBuffer[I, J] := ScreenRGBPalette[B^]; |
||
98 | Inc(B); |
||
99 | end; |
||
100 | Paint; |
||
101 | end; |
||
102 | |||
103 | |||
104 | procedure ImagePut(var Screen, ImageBuffer; X, Y: Integer; WinX1, WinY1, WinX2, WinY2: Word); |
||
105 | var |
||
106 | Width, Height: Word; |
||
107 | I, J, K: Integer; |
||
108 | P: Pointer; |
||
109 | begin |
||
110 | Width := PWord(@ImageBuffer)[0]; |
||
111 | Height := PWord(@ImageBuffer)[1]; |
||
112 | |||
113 | P := @ImageBuffer + 4; |
||
114 | for I := Y to Y + Height - 1 do |
||
115 | begin |
||
116 | if (I >= 0) and (I < SCREEN_HEIGHT) and (I >= WinY1) and (I <= WinY2) then |
||
117 | begin |
||
118 | if X < WinX1 then |
||
119 | J := WinX1 - X else |
||
120 | J := 0; |
||
121 | K := Width - J; |
||
122 | if WinX1 + K - 1 > WinX2 then |
||
123 | K := WinX2 - WinX1 + 1; |
||
124 | Move((P + J)^, (@Screen + I * SCREEN_WIDTH + X + J)^, K); |
||
125 | end; |
||
126 | Inc(P, Width); |
||
127 | end; |
||
128 | end; |
||
129 | |||
130 | procedure ImagePutTransparent(var Screen, ImageBuffer; X, Y: Integer; Winx1, Winy1, Winx2, Winy2: Word); |
||
131 | begin |
||
132 | ImagePut(Screen, ImageBuffer, X, Y, Winx1, Winy1, Winx2, Winy2); |
||
133 | end; |
||
134 | |||
135 | procedure ImageFill(var ImageBuffer; SizeX, SizeY: Word; Value: Byte); |
||
136 | begin |
||
137 | PWord(@ImageBuffer)^ := SizeX; |
||
138 | PWord(@ImageBuffer + 2)^ := SizeY; |
||
139 | FillChar((@ImageBuffer + 4)^, SizeX * SizeY, Value); |
||
140 | end; |
||
141 | |||
142 | function ImageSizeX(var ImageBuffer): Word; |
||
143 | begin |
||
144 | Result := PWord(@ImageBuffer)^; |
||
145 | end; |
||
146 | |||
147 | function ImageSizeY(var ImageBuffer): Word; |
||
148 | begin |
||
149 | Result := PWord(@ImageBuffer + 2)^; |
||
150 | end; |
||
151 | |||
152 | procedure ImageStringGet(Source: String; var FontData, Buffer; ColorOffs: Byte); |
||
153 | var |
||
154 | Width, Height: Word; |
||
155 | Table: PWord; |
||
156 | P, B: PByte; |
||
157 | X, I, J, K, C: Word; |
||
158 | begin |
||
159 | Height := PWord(@FontData + 2)^; |
||
160 | Table := PWord(@FontData + 4); |
||
161 | |||
162 | { расчет длины строки } |
||
163 | Width := 0; |
||
164 | for I := 1 to Length(Source) do |
||
165 | begin |
||
166 | P := @Table[Ord(Source[I])]; |
||
167 | Inc(Width, PWord(P + PWord(P)^)^); |
||
168 | end; |
||
169 | |||
170 | PWord(@Buffer)^ := Width; |
||
171 | PWord(@Buffer + 2)^ := Height; |
||
172 | |||
173 | { вывод строки } |
||
174 | X := 0; |
||
175 | for I := 1 to Length(Source) do |
||
176 | begin |
||
177 | P := @Table[Ord(Source[I])]; |
||
178 | B := PByte(P + PWord(P)^); |
||
179 | C := PWord(B)^; |
||
180 | Inc(B, 2); |
||
181 | |||
182 | P := PByte(@Buffer + 4 + X); |
||
183 | for K := 0 to Height - 1 do |
||
184 | begin |
||
185 | for J := 0 to C - 1 do |
||
186 | begin |
||
187 | if B^ = 0 then |
||
188 | P^ := 0 else |
||
189 | P^ := B^ + ColorOffs; |
||
190 | Inc(P); |
||
191 | Inc(B); |
||
192 | end; |
||
193 | Inc(P, Width - C); |
||
194 | end; |
||
195 | |||
196 | Inc(X, C); |
||
197 | end; |
||
198 | end; |
||
199 | |||
200 | procedure ScreenApply(var Buffer); |
||
201 | begin |
||
202 | Move(Buffer, ScreenBuffer, SizeOf(ScreenBuffer)); |
||
203 | UpdateRGBBuffer; |
||
204 | end; |
||
205 | |||
206 | |||
207 | procedure ImageClear(var Buffer); |
||
208 | begin |
||
209 | FillChar(Buffer, SCREEN_WIDTH * SCREEN_HEIGHT, 0); |
||
210 | end; |
||
211 | |||
212 | |||
213 | procedure Palette256Set(var Palette256); |
||
214 | var |
||
215 | I: Longint; |
||
216 | P: PRGBColor; |
||
217 | begin |
||
218 | P := @Palette256; |
||
219 | for I := 0 to 255 do |
||
220 | with ScreenRGBPalette[I] do |
||
221 | begin |
||
222 | R := Round(P^.B / 63 * 255); |
||
223 | G := Round(P^.G / 63 * 255); |
||
224 | B := Round(P^.R / 63 * 255); |
||
225 | Inc(P); |
||
226 | end; |
||
227 | UpdateRGBBuffer; |
||
228 | end; |
||
229 | |||
230 | procedure Palette256Get(var Palette256); |
||
231 | var |
||
232 | I: Longint; |
||
233 | P: PRGBColor; |
||
234 | begin |
||
235 | P := @Palette256; |
||
236 | for I := 0 to 255 do |
||
237 | with ScreenRGBPalette[I] do |
||
238 | begin |
||
239 | P^.R := Round(B / 255 * 63); |
||
240 | P^.G := Round(G / 255 * 63); |
||
241 | P^.B := Round(R / 255 * 63); |
||
242 | Inc(P); |
||
243 | end; |
||
244 | end; |
||
245 | |||
246 | procedure Palette256Grayscale(var Palette256; StartElement, EndElement: Byte); |
||
247 | begin |
||
248 | end; |
||
249 | |||
250 | procedure Palette256Darken(var Palette256; StartElement, EndElement, Decrement, MinValue: Byte); |
||
251 | begin |
||
252 | end; |
||
253 | |||
254 | procedure Palette256Transform(var SourcePalette, DestinationPalette); |
||
255 | var |
||
256 | I: Longint; |
||
257 | S, D: PByte; |
||
258 | begin |
||
259 | S := @SourcePalette; |
||
260 | D := @DestinationPalette; |
||
261 | for I := 0 to 767 do |
||
262 | begin |
||
263 | if S^ < D^ then Inc(S^) else |
||
264 | if S^ > D^ then Dec(S^); |
||
265 | Inc(S); |
||
266 | Inc(D); |
||
267 | end; |
||
268 | end; |
||
269 | |||
270 | function DataByteGet(var Buffer; BufferOffset: Word): Byte; |
||
271 | begin |
||
272 | Result := PByte(@Buffer + BufferOffset)^; |
||
273 | end; |
||
274 | |||
275 | procedure DataBytePut(var Buffer; BufferOffset: Word; Value: Byte); |
||
276 | begin |
||
277 | PByte(@Buffer + BufferOffset)^ := Value; |
||
278 | end; |
||
279 |