Quote
Asbj?rn <bh...@sn.no> wrote:
> Daniel ?berg wrote:
> > Hello!
> > I need an example that does two things at the same time. There are a
> > couple units out there on the net that takes all the computer power. I
> > want to run one of these units but I want to use my nice Pascal program
> > at the same time.
Here is some code I wrote a while ago as part of a demo, it draws
the fire in the background and does what ever you want in the
background.
{if you get superfluous line breaks - blame a Mac, but it should
look ok under dos}
<start code>
{$X+F+}
uses crt,dos;
var
rand : array[0..255] of integer;
ind : byte;
const
mcga=$A000;
timerintr = 8;
var BIOSTimerHandler : procedure;
clock_ticks, counter : longint;
procedure SetTimer(TimerHandler : pointer; frequency : word);
begin
clock_ticks := 0;
counter := $1234DD div frequency;
GetIntVec(8, @BIOSTimerHandler);
SetIntVec(8, TimerHandler);
Port[$43] := $34;
Port[$40] := counter mod 256;
Port[$40] := counter div 256;
end;
procedure CleanUpTimer;
begin
Port[$43] := $34;
Port[$40] := 0;
Port[$40] := 0;
SetIntVec(8, @BIOSTimerHandler);
end;
Procedure SetTEXT; Assembler;
asm
MOV AH,00
MOV AL,03
INT $10
end;
Procedure SetMCGA; Assembler;
asm
MOV AH,0
MOV AL,$13
INT $10
end;
Procedure SetPalEntryMCGA(col,r,g,b:byte); Assembler;
asm
MOV DX,$3C8
MOV AL,col
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 ClsMCGA(col : byte;where : word); Assembler;
asm
MOV ES,where
XOR DI,DI
MOV CX,32000
MOV AH,col
MOV AL,AH
REP STOSW
end;
Procedure Fire; Assembler;
label
xloop,yloop,start,endl;
asm
{This fire code is copyright David Singleton.
Please do not use it in your own programs
(but feel free to use it to experiment)
start:
MOV CX,140
MOV AX,$A000
MOV ES,AX
yloop:
INC CX
MOV BX,20
CMP CX,200
JA endl
MOV DI,BX
MOV AX,CX
MOV DX,AX
SHL DX,8
SHL AX,6
ADD DX,AX
ADD DI,DX
xloop:
INC BX
CMP BX,60
JA yloop
MOV AL,ES:[DI+321]
MOV DX,AX
MOV AL,ES:[DI+319]
ADD DX,AX
MOV AL,ES:[DI+1]
ADD DX,AX
MOV AL,ES:[DI-1]
ADD DX,AX
SHR DX,2
MOV AX,DX
STOSB
PUSH DI
ADD DI,40
STOSB
ADD DI,40
STOSB
ADD DI,40
STOSB
ADD DI,40
STOSB
ADD DI,40
STOSB
ADD DI,40
STOSB
POP DI
JMP xloop
endl:
end;
Procedure DoFire;
var
a:integer;
begin
for a:=1 to 5 do
begin
Mem[MCGA:(rand[ind])+64320]:=63;
inc(ind);
end;
Mem[MCGA:(rand[ind])+64320]:=0;
inc(ind);
fire;
end;
procedure Handler; Interrupt;
begin
DoFire;
clock_ticks := clock_ticks + counter;
if clock_ticks >= $10000 then
begin
clock_ticks := clock_ticks - $10000;
asm pushf end;
BIOSTimerHandler;
end
else
Port[$20] := $20;
end;
var
p,r,po:integer;
begin
Randomize;
for p:=0 to 255 do
rand[p]:=random(41)+20;
writeln('Programmable Interrupt Timer "Multitasking" Demo');
writeln('By David Singleton 1997 [da...@tickle.clara.net]');
writeln('---------------------------------------------------------------
------');
writeln('This program demonstrates the use of the PIT for background
tasks.');
writeln('It is to some degree based on the PCGPE entry, but takes
the concepts');
writeln('*much* further. I have written a demo with a scrollie from
this code');
writeln('and will mail it to you if you want it');
writeln('---------------------------------------------------------------
------');
writeln('Enjoy - tap enter to start and escape to exit at any
time');
writeln('For proof that the fire is in the background, hit Pause!');
writeln('It will probably have trouble on <486 computers!');
readkey;
SetMCGA;
for p:=0 to 31 do
begin
SetPalEntryMCGA(p,p * 2,0,0);
end;
for p:=0 to 31 do
begin
SetPalEntryMCGA((p+32),63,(p * 2),0);
end;
ind:=0;
ClsMCGA(0,MCGA);
SetTimer(Addr(Handler), 10);
repeat
MemW[MCGA:random(140*320)]:=random(32);
until port[$60]=1;
CleanUpTimer;
ClsMCGA(0,MCGA);
SetTEXT;
end.
</end code>
See ya, David
check out: http://home.clara.net/tickle
--
.-----------------.---------------------------.
| David Singleton | david<at>tickle.clara.net |
`-----------------^---------------------------'