jeste k radio karte
Michal Leinweber
M.Leinweber
Středa Březen 17 11:44:47 CET 2004
Moje packalska unitka predelana z ceckovyho zdrojaku.
McLEI
unit Card;
interface
procedure CardOff;
procedure VolumeDown;
procedure VolumeUp;
procedure Tune(freq:real);
procedure CardMute(mute:boolean);
function IsTuned:boolean;
implementation
uses Crt;
const
RadioBase = $20C;
function read_card(sub_port:integer):byte;
{ /* reads a byte in from the card */ }
begin
read_card := port[RadioBase+sub_port];
end;
procedure write_card(sub_port:integer; value:byte);
{ /* writes a byte to the card */ }
begin
port[RadioBase+sub_port]:=value;
end;
procedure CardOff;
{ /* switch card off */ }
begin
write_card(0,$00);
write_card(0,$00);
end;
procedure VolumeDown;
{ /* vol down a notch */ }
begin
write_card(0,$48);
delay(100);
write_card(0,$c8);
end;
procedure VolumeUp;
{ /* vol up a notch */ }
begin
write_card(0,$88);
delay(100);
write_card(0,$c8);
end;
procedure Tune(freq:real);
{ /* tunes the radio to the desired frequency */ }
var
{ unsigned long int bits;} bits:longint;
{ int i,mask;} i,mask:longint;
begin
{ write('Tune ', Freq:6:3);}
bits:=round((freq*40)+10486188);
{ /* yes, i know. now where does THAT come from?
* working out that bits=(freq*multiplier)+base
* was hard, and working out the base and multiplier
* was tricky. */}
mask:=1;
for i:=0 to 23 do begin
{ Inc(I);}
if bits and mask = 0 then begin
{/* 0 bit */}
write_card(0,$1);
write_card(0,$1);
write_card(0,$3);
write_card(0,$3);
end
else begin
{ /* bit is 1 */ }
write_card(0,$5);
write_card(0,$5);
write_card(0,$7);
write_card(0,$7);
end;
Mask:=mask*2;
end;
{ /* termination sequence? */}
write_card(0,$0);
delay(10);
write_card(0,$c8);
end;
{/* CardMute basis from Frans Brinkmann adapted to card.c */}
procedure CardMute(mute:boolean);
begin
if mute then begin
{/* shut it up */}
write_card(0,$0);
write_card(0,$0);
end
else begin
{ /* turn sound on */ }
write_card(0,$0);
write_card(0,$c8);
end;
end;
{/* IsTuned from Frans Brinkmann adapted to card.c */}
function IsTuned:boolean;
var
x:integer;
begin
x:=0;
{
/* test tuning */
/*
DO NOT CHANGE THE TIMING !?!?!?
Scanning seems to be pretty unreliable, or at least using
the one card I've got. A shorter wait will miss lots of valid
stations, longer ones will make it find lots of noisy signals.
Should anyone ever find out how it is supposed to work please
let me know. For absolutely no reason that I can see it also seems
to work slightly better if the frequencies used are multiples
of .05, but that might just be coincidence
*/}
write_card(0, $f8);
delay(200); { /* any faster and it won't work? */}
x := read_card(0);
{ /* x = inb(RadioBase); */}
delay(25); { /* set from 10000 to 25000. is this better?
*/}
write_card(0,$e8);
{ /* if x == ff not tuned, if x == fd then tuned */}
if (( x and 255) <> $ff) then IsTuned := true
else IsTuned := false;
end;
end.
Další informace o konferenci Hw-list