home *** CD-ROM | disk | FTP | other *** search
- {$F+,O+}
- unit dark;
-
- interface
- uses GTMouse;
- const
- SleepType : integer = 0;
- SleepSpeed : integer = 3;
-
- procedure InitSleeper( SType, TimeDelay,
- LeftUpX, LeftUpY,
- RightDnX, RightDnY : integer);
- { Init "Sleep" coordinates and time (sec) without event to sleep Screen }
- { By Default: InitSleeper(4,30,80,1,80,1); }
- { Example: }
- { ... }
- { InitSleeper(4,10,1,25,80,25); }
-
- procedure DarkScreen;
- procedure Sleeper;
- procedure JumpToOldIsr(OldIsr : Pointer);
- {-Jump to previous ISR from an interrupt procedure.}
- inline(
- $5B/ {pop bx }
- $58/ {pop ax }
- $87/$5E/$0E/ {xchg bx,[bp+14] }
- $87/$46/$10/ {xchg ax,[bp+16] }
- $89/$EC/ {mov sp,bp }
- $5D/ {pop bp }
- $07/ {pop es }
- $1F/ {pop ds }
- $5F/ {pop di }
- $5E/ {pop si }
- $5A/ {pop dx }
- $59/ {pop cx }
- $CB); {retf }
-
-
- implementation
-
- const
- MAX_STARS = 50;
- SleeperOff : boolean = false; { if true Wake Up }
- XYEvent : boolean =false; { if true time sleep ignore }
- showundersleep : boolean =false;
- type
- star_record = record
- x,y,nx,ny,maxn,mx,my,dx,dy,bf,col : longint;
- end;
- stars_table = array [1..MAX_STARS] of star_record;
- pST = ^stars_table;
- Scr = array [0..12999] of byte;
- pScr = ^Scr;
- CharIm = array[0..16] of byte;
- var
- OldInt09 : pointer; { Save Old interrupt vector }
- oldScreen : pScr;
- pScreen : pScr;
- prTimer : longint;
- VertSize,MaxY : integer;
- TimeDelay : integer;
- Stars : pST;
- EndDark : boolean;
- lScreen : integer;
- SleepOn : boolean;
- SleeperLx,SleeperLy,SleeperRx,SleeperRy : integer;
- const
- chlng =6;
- chmap : array [0..3,0..chlng] of charIm = (
- ((1,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00),
- (2,$00,$00,$00,$00,$00,$00,$10,$00,$00,$00,$00,$00,$00,$00,$00,$00),
- (3,$00,$00,$00,$00,$00,$10,$38,$10,$00,$00,$00,$00,$00,$00,$00,$00),
- (4,$00,$00,$00,$10,$10,$10,$38,$10,$10,$10,$00,$00,$00,$00,$00,$00),
- (5,$00,$00,$10,$10,$10,$38,$7C,$38,$10,$10,$10,$00,$00,$00,$00,$00),
- (6,$00,$10,$10,$10,$38,$38,$7C,$38,$38,$10,$10,$10,$00,$00,$00,$00),
- (7,$10,$10,$10,$38,$38,$7C,$FE,$7C,$38,$38,$10,$10,$10,$00,$00,$00)),
- ((1,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00),
- (2,$00,$00,$00,$00,$00,$10,$38,$10,$00,$00,$00,$00,$00,$00,$00,$00),
- (3,$00,$00,$00,$00,$10,$38,$6C,$38,$10,$00,$00,$00,$00,$00,$00,$00),
- (4,$00,$00,$10,$38,$38,$38,$6C,$38,$38,$10,$00,$00,$00,$00,$00,$00),
- (5,$00,$10,$38,$28,$28,$6C,$C6,$6C,$28,$28,$38,$10,$00,$00,$00,$00),
- (6,$10,$38,$28,$28,$6C,$44,$C6,$44,$6C,$28,$28,$38,$10,$00,$00,$00),
- (7,$38,$28,$6C,$44,$44,$C6,$82,$C6,$44,$44,$44,$6C,$38,$00,$00,$00)),
- ((1,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00),
- (2,$00,$00,$00,$00,$00,$10,$38,$10,$00,$00,$00,$00,$00,$00,$00,$00),
- (3,$00,$00,$00,$00,$10,$38,$7C,$38,$10,$00,$00,$00,$00,$00,$00,$00),
- (4,$00,$00,$00,$44,$38,$7C,$7C,$38,$44,$00,$00,$00,$00,$00,$00,$00),
- (5,$00,$00,$10,$54,$38,$7C,$7C,$38,$54,$10,$00,$00,$00,$00,$00,$00),
- (6,$00,$10,$54,$38,$BA,$7C,$7C,$BA,$38,$54,$10,$00,$00,$00,$00,$00),
- (7,$18,$99,$5A,$3C,$BD,$7E,$7E,$BD,$3C,$7E,$99,$18,$18,$00,$00,$00)),
- ((1,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00),
- (2,$00,$00,$00,$00,$00,$00,$10,$00,$00,$00,$00,$00,$00,$00,$00,$00),
- (3,$00,$00,$00,$00,$00,$18,$18,$18,$00,$00,$00,$00,$00,$00,$00,$00),
- (4,$00,$00,$00,$00,$38,$38,$38,$38,$38,$00,$00,$00,$00,$00,$00,$00),
- (5,$00,$00,$00,$7C,$7C,$7C,$7C,$7C,$7C,$7C,$7C,$00,$00,$00,$00,$00),
- (6,$00,$7E,$7E,$7E,$7E,$7E,$7E,$7E,$7E,$7E,$7E,$7E,$00,$00,$00,$00),
- (7,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$FF,$00,$00)));
-
- type
- ChArray = array [0..31] of charIm;
- pCharIm = ^ChArray;
- var
- pChSave : pCharIm;
-
- procedure MoveCharImage(Sourse, Dest:pointer);
- var
- i : integer;
- ofset : word;
- begin
- inline($fa);
- portw[$3c4]:=$0402;
- portw[$3c4]:=$0704;
- portw[$3ce]:=$0204;
- portw[$3ce]:=$0005;
- portw[$3ce]:=$0006;
- move(Sourse^,Dest^,16);
- portw[$3c4]:=$0302;
- portw[$3c4]:=$0304;
- portw[$3ce]:=$0004;
- portw[$3ce]:=$1005;
- portw[$3ce]:=$0E06;
- inline($fb);
- end;
-
- procedure Setfont;
- var
- i : integer;
- ofset : word;
- begin
- for i:=0 to chlng do
- begin
- ofset :=ord(ChMap[SleepType,i][0])*32;
- moveCharImage(addr(ChMap[SleepType,i][1]),ptr(SEGA000,ofset));
- end;
- end;
-
- procedure Savefont;
- var
- i : integer;
- ofset : word;
- begin
- for i:=0 to chlng do
- begin
- ofset :=ord(ChMap[SleepType][i][0])*32;
- moveCharImage(ptr(SEGA000,ofset),addr(pChSave^[i][1]));
- end;
- end;
-
- procedure RestoreFont;
- var
- i : integer;
- ofset : word;
- begin
- for i:=0 to chlng do
- begin
- ofset :=ord(ChMap[SleepType,i][0])*32;
- moveCharImage(addr(pChSave^[i][1]),ptr(SEGA000,ofset));
- end;
- end;
-
- procedure SavefontDark;
- var
- i : integer;
- ofset : word;
- begin
- for i:=224 to 255 do
- begin
- ofset :=i*32;
- moveCharImage(ptr(SEGA000,ofset),addr(pChSave^[i-224][1]));
- end;
- end;
-
- procedure RestoreFontDark;
- var
- i : integer;
- ofset : word;
- begin
- for i:=224 to 255 do
- begin
- ofset :=i*32;
- moveCharImage(addr(pChSave^[i-224][1]),ptr(SEGA000,ofset));
- end;
- end;
-
-
-
-
- procedure ChangeSymbols;
- var
- b : byte;
- i,j,k,h : integer;
- chb : array [1..512] of byte;
- charbuf : array [1..32] of byte;
- ofset : word;
-
- begin
- for i:=1 to 512 do chb[i]:=0;
- for i:=1 to 32 do charbuf[i]:=0;
- h := VertSize div 2;
- for i:=1 to h do
- for j:=1 to 4 do
- begin
- k:=(4*(i-1)+j-1)*VertSize;
- k:=k+(i-1)*2+1;
- chb[k]:=$c0 shr (2*(j-1));
- chb[k+1]:=chb[k];
- end;
- SaveFontDark;
- for i :=224 to 224+vertsize*2 do
- begin
- move(chb[(i-224)*vertsize+1],charbuf,vertsize);
- ofset :=i*32;
- moveCharImage(addr(charbuf),ptr($a000,ofset));
- end;
- end;
-
-
- procedure NewStar;
- var
- i,j : integer;
- begin
- i:=MAX_STARS+1;
- for j:=1 to MAX_STARS do
- if Stars^[j].col=0 then i:=j;
- if i<=MAX_STARS then
- with Stars^[i] do
- repeat
- x:=320;
- y:=MaxY div 2;
- nx:=random(200); ny:=200-nx;
- if nx>ny then maxn:=nx else maxn:=ny;
- mx:=0; my:=0;
- j:=random(10);
- if random(2)=0 then dx:=2 else dx:=-2;
- if random(2)=0 then dy:=2 else dy:=-2;
- col:=random(15)+1;
- x:=((x + (nx * dx * j) div 10) shl 1) shr 1;
- y:=((y + (ny * dy * j) div 10) shl 1) shr 1;
- bf:=(y div VertSize)*_ScreenWidth*2 + ((x shr 3) shl 1);
- until (bf < lScreen) and (bf >= 0);
- end;
-
-
- procedure DelStar(i:integer);
- begin
- Stars^[i].col:=0;
- pScreen^[Stars^[i].bf]:=$20;
- end;
-
-
- procedure SetVertSize;
- begin
- asm
- MOV AH,$11
- MOV AL,$30
- MOV BH,0
- MOV CX,$FFFF
- MOV DL,$FF
- INT $10
- mov VertSize,cx
- end;
- end;
-
- Function SaveScr: boolean;
- begin
- SaveScr:=false;
- lScreen:=_ScreenWidth*_ScreenHeight*2;
- if MemAvail < lScreen+SizeOf(Stars_table)+16*16 then Exit;
- if grMouse and grShow then begin HideGtMouse;showundersleep:=true;end;
- GetMem(oldScreen,lScreen);
- move(pScreen^,oldScreen^,lScreen);
- SaveScr:=true;
- end;
-
- procedure RestoreScr;
- begin
- move(OldScreen^,pScreen^,lScreen);
- FreeMem(OldScreen,lScreen);
- if grMouse and ShowUnderSleep then begin ShowGtMouse;ShowUnderSleep:=false;end;
- end;
-
-
- {$F+}
- Procedure NewKBD(Flags, CSi, IPi, AXi, BXi,CXi, DXi, SIi, DIi, DSi, ESi, BPi: Word);interrupt;
- begin
- lsTimer:=crTimer^;
- AnyEvent:=true;
- JumpToOldIsr(OldInt09);
- end;
- procedure testMouseRect;
- begin
- if grMouse then
- begin
- if ( SleeperLx<=_MouseWhere.X) and ( SleeperLy<=_MouseWhere.Y ) and ( SleeperRy>=_MouseWhere.Y)
- and ( SleeperRx>=_MouseWhere.X ) then begin if not XYEvent then begin anyEvent:=false;XYEvent:=true;end;end
- else begin XYEvent:=false;anyEvent:=true;end;
- MickyToXY;
- _MouseWhere:=grMouseWhere;
- end;
- if crTimer^ - lsTimer >dlTimer then begin AnyEvent:=false;end;
- end;
- procedure DarkScreen;
- var
- i,j,k : integer;
- begin
- if not SaveScr then Exit;
- if DisplayType in [ega,vga] then SetVertSize
- else VertSize:=0;
- new(Stars);
- GetVector($09,OldInt09);
- SetVector($09,addr(NewKBD));
- for i:=0 to lScreen div 2 do pScreen^[i*2+1]:=0;
- if VertSize>0 then
- begin
- MaxY:=_ScreenHeight*VertSize;
- ChangeSymbols;
- for i:=1 to MAX_STARS do begin Stars^[i].col:=0;Stars^[i].bf:=0;end;
- NewStar;
- prTimer:=crTimer^;
- EndDark:=false;
- TimeDelay:=SleepSpeed;
- while not AnyEvent do
- begin
- while prTimer=crTimer^ do;
- testMouseRect;
- prTimer:=crTimer^;
- Dec(TimeDelay);
- if TimeDelay=0 then begin NewStar; TimeDelay:=SleepSpeed; end;
- for i:=1 to MAX_STARS do
- if Stars^[i].col <> 0 then
- with Stars^[i] do
- begin
- mx:=mx+nx;
- if mx>=maxn then begin x:=x+dx; mx:=mx-maxn; end;
- my:=my+ny;
- if my>=maxn then begin y:=y+dy; my:=my-maxn; end;
- if (x<=0) or (x>=640) or (y<=0) or (y>=MaxY)
- then DelStar(i)
- else
- begin
- j:=(y div VertSize)*_ScreenWidth*2 + ((x shr 3) shl 1);
- pScreen^[bf]:=$20;
- k:=(((y mod VertSize) shr 1) shl 2) + ((x and $07) shr 1)+224;
- pScreen^[j]:=k;
- pScreen^[j+1]:=col;
- bf:=j;
- end;
- end;
- end;
- for i:=0 to lScreen div 2 do pScreen^[i*2+1]:=0;
- RestoreFontDark;
- RestoreScr;
- dispose(Stars);
- end
- else
- begin
- repeat
- until not AnyEvent;
- RestoreScr;
- end;
- setVector($09,OldInt09);
- end;
-
-
- Procedure DoneSleeper;
- var ofset,i : word;
- begin
- SetVector($09,OldInt09);
- SleeperOff:=false;
- RestoreFont;
- RestoreScr;
- ShowGtMouse;
- end;
-
-
- procedure Sleep;
-
- var
- i,xy : word;
- ichar,attr : byte;
-
- PROCEDURE Galaxy;
- var i : integer;
- begin
- olTimer:=crTimer^;
- for i:=0 to _ScreenWidth*_ScreenHeight-1 do
- begin
- ichar:=mem[SegB800 : i*2];
- if ichar<32 then
- if (mem[SegB800 : i*2+1] AND $0F)>7 then
- begin
- inc(ichar);
- if ichar>7 then
- begin
- ichar:=6;
- mem[SegB800:i*2]:=ichar;
- mem[SegB800:i*2+1]:=mem[SegB800:i*2+1] AND $f7;
- end
- else mem[SegB800:i*2]:=ichar;
- end
- else
- begin
- dec(ichar);
- if ichar<1 then
- begin
- mem[SegB800:i*2+1]:=0;
- mem[SegB800:i*2]:=32;
- repeat
- xy:=random(_ScreenWidth*_ScreenHeight);
- until mem[SegB800 : xy*2]=32;
- ichar:=1;
- attr:=Random(8)+8;
- mem[SegB800:xy*2+1]:=attr;
- mem[SegB800:xy*2]:=ichar;
- end
- else mem[SegB800:i*2]:=ichar;
- end;
- end;
- end;
-
- begin
- HideGtMouse;
- LScreen:=_ScreenHeight*_ScreenWidth*2;
- IF not SleeperOff then
- begin
- if not SaveScr then Exit;
- savefont;
- setfont;
- Randomize;
- GetVector($09,OldInt09);
- SetVector($09,addr(NewKBD));
- SleeperOff:=true;
- for i:=0 to LScreen div 2 do begin mem[SegB800:i*2]:=32;mem[SegB800:i*2+1]:=0;end;
- for i:=1 to 10 do
- begin
- xy:=Random(_ScreenWidth*_ScreenHeight);
- ichar:=Random(7)+1;
- attr:=Random(16);
- mem[SegB800:xy*2+1]:=attr;
- mem[SegB800:xy*2]:=ichar;
- end;
- end;
- repeat
- testMouseRect;
- if (olTimer<>crTimer^) and (crTimer^ mod 4 = 0) then gALAXY;
- until AnyEvent;
- doneSleeper;
- end;
-
- Procedure Sleeper;
- begin
- if SleepOn then
- begin
- if ( SleeperLx<=_MouseWhere.X) and ( SleeperLy<=_MouseWhere.Y ) and ( SleeperRy>=_MouseWhere.Y)
- and ( SleeperRx>=_MouseWhere.X ) then begin if not XYEvent then begin anyEvent:=false;XYEvent:=true;end;end
- else begin XYEvent:=false;anyEvent:=true;end;
- if crTimer^ - lsTimer >dlTimer then begin AnyEvent:=false;end;
- if not AnyEvent then
- begin
- if SleepType=4 then DarkScreen
- else Sleep;
- end;
- end;
- end;
-
- procedure InitSleeper(SType,TimeDelay, LeftUpX, LeftUpY, RightDnX, RightDnY : integer);
-
- begin
- SleeperLx := LeftUpX-1;
- SleeperLy := LeftUpY-1;
- SleeperRx := RightDnX-1;
- SleeperRy := RightDnY-1;
- dlTimer:=TimeDelay*18;
- SleepOn:=true;
- SleepType:=SType;
- end;
-
- begin
- pScreen:=ptr(SegB800,0);
- new(pChSave);
- InitSleeper(4,30,80,1,80,1);
- end.
-