-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDRK_PCX.PAS
244 lines (224 loc) · 3.64 KB
/
DRK_PCX.PAS
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
unit drk_pcx;
interface
const maxmem=10000;
var filename: string;
pcx_file: string;
bytes,w1,w2,filehandle: word;
w3: longint;
error: boolean;
data: array[1..maxmem] of byte;
palette: array[0..767] of byte;
procedure loadpcx(dest:word;colors:boolean);
procedure setcolors;
implementation
procedure movepointer (movh,movl:word;mode: byte);assembler;
asm
mov ah, 42h
mov al, mode
mov bx, filehandle
mov dx, movl
mov cx, movh
int 21h
jnc @wentok
mov error, true
mov w1, ax
jmp @end
@wentok:
mov [w1], dx
mov [w2], ax
@end:
end;
procedure fileopen(access:byte);
begin
asm
mov ah, 3dh
mov al, access
lea dx, filename+1
int 21h
jnc @wentok
mov error, 1
@wentok:
mov filehandle, ax
end;
end;
procedure fileclose;
begin
asm
mov ah, 3eh
mov bx, filehandle
int 21h
jnc @wentok
mov error, 1
@wentok:
end;
end;
procedure fileread (xy:word);assembler;
asm
mov ah, 3fh
mov bx, filehandle
mov cx, xy
lea dx, data
int 21h
mov bytes, ax
cmp ax, xy
je @wentok
mov error, true
@wentok:
end;
procedure setreg (dacreg,r,g,b: byte);assembler;
asm
mov dx, 3c8h
mov al, dacreg
out dx, al
inc dx
mov al, r
out dx, al
mov al, g
out dx, al
mov al, b
out dx, al
end;
procedure setcolors;
var a: word;
begin
for a:=0 to 255 do
setreg(a, palette[a*3],palette[a*3+1],palette[a*3+2]);
end;
procedure loadpcx(dest:word;colors:boolean);
var pos,xco, yco: word;
c1,times: byte;
ymin,bytesperline,xmin,xmax,ymax: word;
begin
error:=false;
fileopen(0);
if error=true then exit;
movepointer(0,4,0);
fileread(8);
xmin:=data[1]+data[2]shl 8;
ymin:=data[3]+data[4]shl 8;
xmax:=data[5]+data[6]shl 8;
ymax:=data[7]+data[8]shl 8;
movepointer(0,66,0);
fileread(2);
bytesperline:=data[1]+data[2]*255;
xmin:=((319-xmax) div 2);
xmax:=319-xmin;
ymin:=((199-ymax) div 2);
ymax:=199-ymin;
movepointer(0,0,2);
w3:=w1*65536+w2;
dec(w3,768);
w1:=w3 div 65536;
w2:=w3 mod 65536;
movepointer(w1,w2,0);
fileread(768);
if colors then
for w3:=0 to 255 do
setreg(w3,data[w3*3+1] shr 2,data[w3*3+2] shr 2,data[w3*3+3] shr 2)
else
for w3:=0 to 767 do
palette[w3]:=data[w3+1] shr 2;
if error=true then exit;
movepointer(0,$80,0);
fileread(maxmem);
asm
push di
push es
mov ax, dest
mov es, ax
mov cx, xmin
mov dx, ymin
xor di, di
@goto:
mov al, ds:[offset data+di]
mov ah, al
and al, 192
cmp al, 192
jne @nopack
inc di
cmp di, maxmem-1
ja @load1
@cont:
mov al, ds:[offset data+di]
and ah, 63
@cont1:
dec ah
push di
mov di, dx
mov bx, dx
shl di, 8
shl bx, 6
add di, bx
add di, cx
mov es:[di], al
pop di
inc cx
cmp cx, xmax
ja @incdx1
@cont2:
cmp ah,0
ja @cont1
jmp @nextbyte
@nopack:
push di
mov di, dx
mov bx, dx
shl di, 8
shl bx, 6
add di, cx
add di, bx
mov es:[di], ah
pop di
inc cx
cmp cx, xmax
jna @nextbyte
mov cx, xmin
inc dx
@nextbyte:
cmp dx, ymax
jae @end
inc di
cmp di, maxmem-1
jna @goto
push cx
push dx
mov ah, 3fh
mov bx, filehandle
mov cx, maxmem
lea dx, data
int 21h
mov di, 0
pop dx
pop cx
jmp @goto
@load1:
push dx
push cx
push ax
mov ah, 3fh
mov bx, filehandle
mov cx, maxmem
lea dx, data
int 21h
mov di, 0
pop ax
pop cx
pop dx
jmp @cont
@incdx1:
inc dx
mov cx, xmin
jmp @cont2
@end:
pop es
pop di
mov ah, 3eh
mov bx, filehandle
int 21h
jnc @wentok
mov error, 1
@wentok:
end;
end;
begin
end.