home *** CD-ROM | disk | FTP | other *** search
- { TurboCOLOR - Changes color of TURBO editor or any TURBO program.
- Copyright 1986 by Scott Reedstrom.
- Released into the public domain for non-commercial use.
- This program may be freely distributed.
- If you find this program usesfull, a $5.00 donation would be appreciated.
- Please send to
- SAR Designs
- 774 Doris Ave.
- Shoreview, MN 55126 }
-
- const
- esc = #27 ;
- sbar = 25 ;
- BufSize = 100 ;
-
- type
- Block = array [0..127] of byte ;
- str10 = string[10] ;
- MonType = (Col,Mono,BW,Unknown) ;
-
- var
- TName : string[30] ;
- ScreenType : MonType ;
- Monitor : MonType ;
- TurbFile : file ;
- TurbOut : file ;
- Header : Block ;
- Blocks : array [1..BufSize] of Block ;
- err : integer ;
- Color : array[0..5] of integer ;
- ColorBar : integer ;
-
- procedure ToHome ;
- begin
- Gotoxy(1,1) ;
- TextColor(White) ;
- TextBackground(Black) ;
- end ;
-
- procedure InitTurbo ;
- begin
- Assign(TurbFile,TName) ;
- {$I-}
- Reset(TurbFile) ;
- {$I+}
- if IOresult <> 0 then
- begin
- writeln('Can''t find file ',TName) ;
- Writeln(' Proper syntax is ');
- Writeln(' TCOLOR [filename.COM]');
- Writeln(' If the filename not provided, it defaults to TURBO.COM.');
- Halt ;
- end ;
- BlockRead(TurbFile,Header,1) ;
- end ;
-
- function Attr(n:integer):integer ;
- var
- fg,bg : integer ;
- begin
- case (n div 2) of
- 0 : begin fg := 00 ; bg := 00 ; end ; { blank }
- 1 : begin fg := 07 ; bg := 00 ; end ; { normal display }
- 2 : begin fg := 01 ; bg := 00 ; end ; { underlined }
- 3 : begin fg := 00 ; bg := 07 ; end ; { reverse video }
- 4 : begin fg := 08 ; bg := 00 ; end ; { bright blank }
- 5 : begin fg := 15 ; bg := 00 ; end ; { bright }
- 6 : begin fg := 09 ; bg := 00 ; end ; { bright & underlined }
- 7 : begin fg := 08 ; bg := 07 ; end ; { bright & reversed }
- end {case} ;
- attr := fg + 16*bg ;
- end ;
-
- function ColAttr(n:integer):integer ;
- var
- i,tmp : integer ;
- begin
- tmp := 1 ;
- for i := 15 downto 0 do
- if Attr(i)=n then tmp:=i ;
- ColAttr := tmp ;
- end ;
-
- function Mon(n:integer):MonType ;
- begin
- case n of
- 0 : Mon := BW ;
- 1 : Mon := Col ;
- 2 : Mon := BW ;
- 3 : Mon := Col ;
- 4 : Mon := Col ;
- 5 : Mon := Col ;
- 6 : Mon := Col ;
- 7 : Mon := Mono ;
- else Mon := Unknown ;
- end ;
- end ;
-
- function MonByte:byte ;
- type
- regtype = record ax,bx,cx,dx,bp,si,di,ds,es,flags:integer ; end ;
- var
- reg : regtype ;
- begin
- Reg.AX := $0F00 ;
- Intr($10,Reg) ;
- MonByte := Lo(Reg.Ax) ;
- end ;
-
- procedure InitColors ;
- var
- i : integer ;
- c : char ;
- begin
- ScreenType := Mon(MonByte) ;
- if ScreenType = Mono then { Monochrome screen }
- begin
- Writeln('Monochrome Monitor with a Monochrome Card');
- Color[0] := ColAttr(Header[$6F]) ;
- Color[1] := ColAttr(Header[$70]) ;
- Color[2] := ColAttr(Header[$71]) ;
- end ;
- if ScreenType=BW then { Color card with B/W monitor }
- begin
- Writeln('Monochrome Monitor with a Color Card');
- Color[0] := Header[$73] and 15 ;
- Color[1] := Header[$73] shr 4 ;
- Color[2] := Header[$74] and 15 ;
- Color[3] := Header[$74] shr 4 ;
- Color[4] := Header[$75] and 15 ;
- Color[5] := Header[$75] shr 4 ;
- end ;
- if ScreenType=Col then { Color card with Color Monitor }
- begin
- Writeln('Color Monitor');
- Color[0] := Header[$77] and 15 ;
- Color[1] := Header[$77] shr 4 ;
- Color[2] := Header[$78] and 15 ;
- Color[3] := Header[$78] shr 4 ;
- Color[4] := Header[$79] and 15 ;
- Color[5] := Header[$79] shr 4 ;
- end ;
- delay(2000) ;
- end ;
-
- procedure GotoBar(Bar,Colr:integer) ;
- var
- x,y : integer ;
- begin
- x := Colr*3+sbar+1 ;
- if ScreenType=Mono then x := x+1 ;
- y := 13+(bar*2) ;
- gotoxy(x,y) ;
- TextColor(White) ;
- TextBackground(Black) ;
- end ;
-
- procedure DrawText ;
- begin
- TextColor(Color[0]) ;
- TextBackground(Color[1]) ;
- if ScreenType=Mono then
- begin
- TextColor(Attr(Color[0]) and 15);
- TextBackground(Attr(Color[0]) shr 4);
- end ;
- GotoXY(1,2) ;
- ClrEol;Writeln('Begin') ;
- ClrEol;Writeln(' This is the color/attributes of normal text. ') ;
- ClrEol;Writeln(' This is the color/attributes of ') ;
- ClrEol;Writeln(' normal, source code text. ') ;
- GotoXY(1,9) ;
- ClrEol;Writeln(' This is the color/attributes of normal text. ') ;
- ClrEol;Writeln('End ;') ;
- end ;
-
- procedure DrawInfo ;
- begin
- TextColor(Color[2]) ;
- TextBackground(Color[3]) ;
- if ScreenType=Mono then
- begin
- TextColor(Attr(Color[1]) and 15);
- TextBackground(Attr(Color[1]) shr 4) ;
- end ;
- GotoXY(1,1) ;
- ClrEol;Writeln(' This is the color/attributes of the dim info line across the top of the screen');
- end ;
-
- procedure DrawHighl ;
- begin
- TextColor(Color[4]) ;
- TextBackground(Color[5]) ;
- if ScreenType=Mono then
- begin
- TextColor(Attr(Color[2]) and 15) ;
- TextBackground(Attr(Color[2]) shr 4) ;
- end ;
- GotoXY(1,6) ;
- ClrEol;Writeln(' This is the color/attributes of highlighted text. ') ;
- ClrEol;Writeln(' This is the color/attributes of ') ;
- ClrEol;Writeln(' highlighted source code text. ') ;
- end ;
-
- procedure DrawBar(b:integer) ;
- var
- i : integer ;
- fb,fg,bg : integer ;
- begin
- for i := 0 to 15 do
- begin
- if ScreenType=Mono then
- begin
- fb := attr(i) ;
- fg := fb and 15 ;
- bg := fb shr 4 ;
- TextColor(fg) ;
- TextBackground(bg) ;
- case (i mod 2) of
- 0 : write('-AB');
- 1 : write('C--');
- end ;
- end
- else
- begin
- TextColor(i) ;
- Write(#219,#219,#219) ;
- end ;
- end ;
- end ;
-
- procedure DrawColors ;
- var
- b : integer ;
- begin
- Gotoxy(sbar-1,11) ;
- TextColor(White) ;
- TextBackground(Black) ;
- Write('╔═════════════════════════════════════════════════╗');
- for b := 0 to 5 do
- begin
- gotoxy(1,12+2*b) ;
- TextColor(White) ;
- TextBackground(Black) ;
- if ScreenType = Mono then
- begin
- if b<3 then
- begin
- case b of
- 0 : Write('Normal Text Attr') ;
- 1 : Write('Dim Text Attributes') ;
- 2 : Write('Highlighted Text Attr') ;
- end {case} ;
- gotoxy(sbar,12+2*b) ;
- DrawBar(b) ;
- GotoBar(b,Color[b]) ;
- Write(#04) ;
- end ;
- end
- else
- begin
- case b of
- 0 : Write('Normal Text Color') ;
- 1 : Write('Normal Background') ;
- 2 : Write('Dim Text Color') ;
- 3 : Write('Dim Text Background') ;
- 4 : Write('Highlighted Text Color') ;
- 5 : Write('Highlighted Text Backg') ;
- end ;
- gotoxy(sbar,12+2*b) ;
- DrawBar(b) ;
- GotoBar(b,Color[b]) ;
- Write(#04) ;
- end ;
- GotoXY(sbar-1,12+2*b) ; Write('║') ;
- GotoXY(sbar-1,13+2*b) ; Write('║') ;
- GotoXY(sbar+49,12+2*b) ; Write('║') ;
- GotoXY(sbar+49,13+2*b) ; Write('║') ;
- end ;
- GotoXY(sbar-1,24);
- Write('╚═════════════════════════════════════════════════╝');
- end ;
-
- procedure SetColor ;
- begin
- if ScreenType=Mono then
- begin
- case ColorBar of
- 0 : DrawText ;
- 1 : DrawInfo ;
- 2 : DrawHighl ;
- end {case} ;
- ToHome ;
- end
- else
- begin
- case ColorBar of
- 0 : DrawText ;
- 1 : DrawText ;
- 2 : DrawInfo ;
- 3 : DrawInfo ;
- 4 : DrawHighl ;
- 5 : DrawHighl ;
- end {case} ;
- ToHome ;
- end ;
- end ;
-
- procedure DnColor ;
- var
- MaxBar : integer ;
- begin
- MaxBar := 5 ;
- if (ScreenType=Mono) then MaxBar := 2 ;
- GotoBar(ColorBar,Color[ColorBar]) ;
- Write(#04) ;
- ColorBar := (ColorBar+1) ;
- if Colorbar > MaxBar then ColorBar := 0 ;
- if COlorBar < 0 then ColorBar := MaxBar ;
- GotoBar(ColorBar,Color[ColorBar]) ;
- TextColor(White+blink) ;
- Write(#24) ;
- ToHome ;
- end ;
-
- procedure UpColor ;
- var
- MaxBar : integer ;
- begin
- MaxBar := 5 ;
- if (ScreenType=Mono) then MaxBar := 2 ;
- GotoBar(ColorBar,Color[ColorBar]) ;
- Write(#04) ;
- ColorBar := (ColorBar-1) ;
- if Colorbar > MaxBar then ColorBar := 0 ;
- if COlorBar < 0 then ColorBar := MaxBar ;
- GotoBar(ColorBar,Color[ColorBar]) ;
- TextColor(White+blink) ;
- Write(#24) ;
- ToHome ;
- end ;
-
- procedure RtColor ;
- begin
- GotoBar(ColorBar,Color[ColorBar]) ;
- Write(' ') ;
- Color[ColorBar] := Color[ColorBar] + 1 ;
- if ScreenType=Mono then Color[ColorBar] := Color[ColorBar]+1 ;
- if Color[COlorBar] > 15 then Color[ColorBar] := 0 ;
- if Odd(ColorBar) and (Color[ColorBar] > 7) and not(ScreenType=Mono)
- then Color[ColorBar] := 0 ;
- GotoBar(ColorBar,Color[ColorBar]) ;
- TextColor(White+blink) ;
- Write(#24) ;
- SetColor ;
- end ;
-
- procedure LfColor ;
- begin
- GotoBar(ColorBar,Color[ColorBar]) ;
- Write(' ') ;
- Color[ColorBar] := Color[ColorBar] - 1 ;
- if (ScreenType=Mono) then Color[ColorBar] := Color[ColorBar]-1 ;
- if Odd(ColorBar) and (Color[ColorBar] < 0) and not(ScreenType=Mono)
- then Color[ColorBar] := 7 ;
- if Color[ColorBar] < 0 then Color[ColorBar] := 15 ;
- GotoBar(ColorBar,Color[ColorBar]) ;
- TextColor(White+blink) ;
- Write(#24) ;
- SetColor ;
- end ;
-
- procedure DrawScreen ;
- begin
- TextColor(white) ;
- TextBackground(black) ;
- ClrScr ;
- DrawInfo ;
- DrawText ;
- DrawHighl ;
- DrawColors ;
- ColorBar := 1 ;
- UpColor ;
- Gotoxy(1,25) ;
- TextColor(White) ;
- TextBackground(red) ;
- ClrEol ;
- Write(' Use cursor keys to move arrows - press [ESC] to end');
- TOHome ;
- end ;
-
- procedure ChangeHeader ;
- var
- Message : string[30] ;
- i : integer ;
- begin
- case ScreenType of
- Mono : begin
- Header[$6F] := Attr(Color[0]) ;
- Header[$70] := Attr(Color[1]) ;
- Header[$71] := Attr(Color[2]) ;
- Message := 'Customized Mono' ;
- end ;
- BW : begin
- Header[$73] := Color[0] or (Color[1] shl 4) ;
- Header[$74] := Color[2] or (Color[3] shl 4) ;
- Header[$75] := Color[4] or (Color[5] shl 4) ;
- Message := 'Customized B/W' ;
- end ;
- Col : begin
- Header[$77] := Color[0] or (Color[1] shl 4) ;
- Header[$78] := Color[2] or (Color[3] shl 4) ;
- Header[$79] := Color[4] or (Color[5] shl 4) ;
- Message := 'Customized Color' ;
- end ;
- end ;
- Header[$6D] := $FF ; { always make actual program default monitor }
- for i := 0 to length(Message) do Header[$55+i] := ord(Message[i]) ;
- end ;
-
- procedure SaveTurbo ;
- var
- RecRead : integer ;
- begin
- Write(' - Changing ',TName) ;
- Assign(TurbOut ,'Colored.$$$') ;
- {$I-}
- Rewrite(TurbOut ) ;
- {$I+}
- if IOResult<>0 then
- begin
- Write('Not enough room on disk. No changes made.');
- Halt ;
- end ;
- Reset(TurbFile) ;
- ChangeHeader ;
- BlockWrite(TurbOut,Header,1) ;
- BlockRead(TurbFile,blocks,1) ;
- repeat
- BlockRead(TurbFile,Blocks,BufSize,RecRead) ;
- BlockWrite(TurbOut,BLocks,RecRead) ;
- until RecRead=0 ;
- close(TurbFile) ;
- close(TurbOut) ;
- {$I-}
- Reset(TurbOut) ;
- {$I+}
- if IOresult=0 then {Good copy}
- begin
- close(TurbOut) ;
- erase(TurbFile) ;
- rename(TurbOut,TName) ;
- end ;
- end ;
-
- function AreYouSure : boolean ;
- var
- c : char ;
- begin
- TextColor(White) ;
- TextBackground(red) ;
- gotoXY(1,25);
- ClrEol ;
- Write(' Are you sure you want to leave? ') ;
- read(kbd,c) ;
- write(Upcase(c)) ;
- if UpCase(c) = 'Y' then
- begin
- AreYouSure := true ;
- GotoXY(1,25) ;
- ClrEol ;
- Write(' Want to make changes permanent? ') ;
- read(kbd,c) ;
- write(Upcase(c)) ;
- if UpCase(c) = 'Y' then SaveTurbo ;
- end
- else
- begin
- AreYouSure := false ;
- GotoXY(1,25) ; CLrEol ;
- Write(' Use cursor keys to move arrows - press [ESC] to end');
- end ;
- ToHome ;
- end ;
-
- procedure ChngColor ;
- var
- EndChng : boolean ;
- c : char ;
- begin
- DrawScreen ;
- EndChng := false ;
- repeat
- read(kbd,c) ;
- if c=esc then
- begin
- if keypressed then
- begin
- read(kbd,c) ;
- case c of
- #72 : UpColor ;
- #80 : DnColor ;
- #75 : LfColor ;
- #77 : RtColor ;
- end {case} ;
- end
- else if AreYouSure then EndChng := true ;
- end
- until EndChng ;
- end ;
-
- Procedure WriteBeg ;
- var
- c : char ;
- Begin
- ClrScr ;
- Writeln(' TurboCOLOR - Changes color of TURBO editor or any TURBO program. ');
- Writeln(' Copyright 1986 by Scott Reedstrom.');
- Writeln(' Released into the public domain for non-commercial use.');
- Writeln(' This program may be freely distributed without charge.');
- Writeln(' If you find this program usesfull, a $5.00 donation would be appreciated.');
- Writeln(' Please send to');
- Writeln(' SAR Designs');
- Writeln(' 774 Doris Ave.');
- Writeln(' Shoreview, MN 55126');
- Writeln ;
- Writeln(' Press any key to continue ... ');
- read(kbd,c) ;
- end ;
-
-
- Begin
- if ParamCount=0 then TName := 'TURBO.COM' else TName := ParamStr(1) ;
- InitTurbo ;
- InitColors ;
- ChngColor ;
- ClrScr ;
- end .