-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathCHOOSE.PAS
361 lines (303 loc) · 7.9 KB
/
CHOOSE.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
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
352
353
354
355
356
357
358
359
360
361
{ The rasterbar system was coded by SPAWN/OBSESSiON
The textbar system was coded by BUGSY/OBSESSiON
Remember : The menu system is coded VERY FAST and I know part of the code
sucks, but you forgive me, right ? ;-}
Unit CHOOSE;
Interface
Const
KeyUp = Byte ('!');
KeyDown = Byte ('"');
KeyLeft = Byte ('#');
KeyRight = Byte ('¯');
KeyU1 = Byte ('U');
KeyU2 = Byte ('u');
KeyESC = 27;
KeyTAB = 9;
KeyReturn = 13;
KeyShTAB = 15;
BarColor = $5;
Procedure RestoreColor;
Procedure SetColor;
Function ActivateMenu( Y,Max,PalNumber,StartPos,TextY : Word; RasterBar : Boolean) : WORD;
Implementation
Uses
Crt;
Const
Bar : Array[1..17] Of Byte = ( $1c,$20,$26,$2a,$2e,$33,$39,$3c,$3c,$39,$33,$2e,$2a,$26,$20,$1c,$1c);
{ Bar2 : Array[1..18] Of Byte = ( $1c,$20,$26,$2a,$2e,$33,$39,$3c,$3c,$3c,$39,$33,$2e,$2a,$26,$20,$1c,$1c);}
OrgColor : Array[1..2*3] OF Byte = ( 0,40,40, 40,7,7); {Why not get them insted????????}
Var
Pal1 : Array[1..353*3] Of Byte;
Procedure RestoreColor; ASSEMBLER;
ASM
cld {Damn it was hard to find!}
mov si,offset OrgColor
mov dx,3c8h
mov al,3
out dx,al
inc dx
mov cx,6
@l:
lodsb
out dx,al
loop @l
END;
Procedure SetColor; ASSEMBLER;
ASM
cld {Damn it was hard to find!}
mov dx,3c8h
mov al,3
out dx,al
inc dx
mov cx,2
@l:
mov al,0
out dx,al
out dx,al
mov al,2ah
out dx,al
loop @l
END;
Function Menu( Y,Max,PalNumber,StartPos : Word ) : WORD; Assembler;
Var
Direction : Byte;
BlockPos : Byte;
MoveSize : Word;
Asm
cli
mov ax,ds
mov es,ax
mov direction,0
mov movesize,0
mov ax,StartPos
mov blockpos,al
xor dx,dx
mov bx,16
mul bx
inc BlockPos
mov si,offset Bar
mov di,offset pal1
add di,Y
add di,2
add di,ax
mov cx,16
cld
rep movsb
mov bx,3c9h
@Loop2:
cli
mov cx,353
mov si,offset Pal1
mov dx,3DAh
@VrtPau1:
in al,dx
test al,8
je @VrtPau1
@Loop1:
mov dx,3c8h
mov ax,PalNumber
out dx,al
mov dx,3DAh
@VRetrace:
in al,dx
test al,1
jne @VRetrace
@HRetrace:
in al,dx
test al,1
je @HRetrace
mov dx,3c9h
xor bx,bx
mov al,byte ptr ds:[si]
mov ah,al
xor al,0
jnz @NotOrgC
mov al,0
mov bl,al
mov bh,02ah
@NotOrgC:
out dx,al
mov al,bl
out dx,al
mov al,bh
out dx,al
inc si
loop @Loop1
cmp Direction,1 { 2 = Up, 1 = Down, 0 = Nothing}
jg @MoveLoopUp
jb @TestKey
cmp MoveSize,0
jne @NotEnd1
mov Direction,0
@NotEnd1:
mov si,offset Pal1
mov ax,max
inc al
cmp blockpos,al
jge @TestKey
std
dec MoveSize
mov al,byte ptr ds:[si+350]
mov cx,350
add si,349
mov di,si
inc di
rep movsb
mov si,offset Pal1
mov byte ptr ds:[si],al
jmp @Loop2
@MoveLoopUp:
cmp MoveSize,0
jne @NotEnd2
mov Direction,0
@NotEnd2:
cmp blockpos,0
je @TestKey
cld
mov si,offset Pal1
dec MoveSize
mov al,byte ptr ds:[si]
mov cx,350
mov di,si
inc si
rep movsb
mov byte ptr ds:[si],al
jmp @Loop2
@TestKey:
mov ah, 01h
int 16h
jz @Loop2
mov ah,6
mov dl,0ffh
int 21h
mov cl,al
cmp al,0
jne @NotExt
mov ah,6
int 21h
mov ch,al
cmp al, KeyShTAB
je @Done
cmp cx,4800h {Up}
je @UpKey
cmp cx,5000h {Down}
je @DownKey
cmp cx,4b00h {Left}
je @LeftKey
cmp cx,4d00h {Right}
je @RightKey
jmp @Loop2
@LeftKey:
mov al, KeyLeft
jmp @Done
@RightKey:
mov al, KeyRight
jmp @Done
@DownKey:
mov ax,Max
cmp BlockPos,al
jne @NotMax
mov al, KeyDown
jmp @Done
@NotMax:
mov MoveSize,15
mov Direction,1
inc BlockPos
jmp @Loop2
@UpKey:
cmp BlockPos,1
jne @NotMin
mov al, KeyUp
jmp @Done
@NotMin:
mov MoveSize,15
mov Direction,2
dec BlockPos
jmp @Loop2
@NotExt:
cmp al,KeyReturn { Return pressed }
je @Done
cmp al, KeyU1 { u key pressed }
je @Done
cmp al, KeyU2 { U key pressed }
je @Done
cmp al,KeyTAB { TAB key pressed }
je @Done
cmp al, KeyESC { ESC key pressed }
je @Done
jmp @Loop2
@Done:
mov ah,BlockPos
@GetOut:
sti
End;
Procedure DrawBar (XPos, BackColor, NewColor : Word);
Var
Ct : Byte;
MemPos : Word;
Begin
For Ct := 0 To 79 Do Begin
MemPos := (XPos)*160 + (Ct * 2) + 1;
If Mem[$b800:MemPos] AND $F0 = BackColor SHL 4 Then
Mem[$b800:MemPos] := Mem[$b800:MemPos] AND $0F + (NewColor SHL 4);
End;
End;
Function TextBar ( TopPos,MaxPos,CurrPos,PalNumber : Word ) : WORD;
Var
Ch : Char;
Quit : Boolean;
RetVal : Word;
Begin
RetVal := 0; {BUG BUG BUG}
Repeat
Quit := True;
DrawBar (CurrPos, PalNumber, BarColor);
While KeyPressed Do ReadKey;
Repeat Until KeyPressed;
Ch := ReadKey;
Case Ch Of
#27 : RetVal := KeyEsc;
#13 : RetVal := KeyReturn;
#09 : RetVal := KeyTab;
'U' : RetVal := KeyU1;
'u' : RetVal := KeyU2;
#00 : Begin
Ch := Upcase(ReadKey);
Case Ch Of
#15 : RetVal := KeyShTab;
#72 : Begin
RetVal := KeyUp;
If CurrPos <> TopPos Then Begin
Quit := False;
DrawBar(CurrPos, BarColor, PalNumber);
Dec(CurrPos);
End;
End;
#80 : Begin
RetVal := KeyDown;
If CurrPos <> MaxPos-2 Then Begin
Quit := False;
DrawBar(CurrPos, BarColor, PalNumber);
Inc(CurrPos);
End;
End;
#75 : RetVal := KeyLeft;
#77 : RetVal := KeyRight;
End;
End;
Else
Quit := False;
End;
Until Quit;
DrawBar(CurrPos, BarColor, PalNumber);
TextBar := (CurrPos-TopPos) SHL 8 + RetVal;
End;
Function ActivateMenu( Y,Max,PalNumber,StartPos,TextY : Word; RasterBar : Boolean) : Word;
Begin
If RasterBar Then Begin
FillChar( Pal1,353*3,0 );
ActivateMenu := Menu( Y,Max,PalNumber,StartPos );
End Else
ActivateMenu := TextBar (TextY,Max+1+TextY,StartPos+TextY,PalNumber) + $0100;
End;
END.