Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

write\read from cmos

Status
Not open for further replies.

earlrainer

Programmer
Mar 1, 2002
170
IN
hi,

i wish to write and read some data from the cmos
through my delphi program.
is this possible in delphi??

bye
 
Hello,
You'll have to write the address of the cmos byte you want to read or write to I/O address $70, and then read or write the data from/to I/O address $71. You may need some special lib or driver to get direct HW access, as Windows normally abstracts all the hardware. Please get a list of the current position of values and meanings, before writing anything, as you'll also have to update the checksum ($2e high byte, $2f low byte) when writing to the bytes between $10 and $2D in cmos.
I once did this in an old basic program, back in 1988 :eek:), to control the settings of the FDD drives, after manually switching 5 1/4" 1.2 MB + 360 kB and 3 1/2" 1.44 MB drives in a special built 'write safely to any type of diskette' machine. (It had 3 FDD drives) It was too much trouble going to cmos setup everytime the switch was changed, so this was controlled from a batchmenu. Current cmos chips have much more nv-ram bytes aboard, but I never kept up on how to access those above 255 ($ff), but that should be easy to discover from the docs.
HTH
TonHu
 
Hello again,

After searching in my archives, I found a component called btbeeper, that directly accesses the speaker port on the mainboard, to play sounds. In the same fashion, and with the info from my previous post, you should be able to mock things up quite nicely ;-)

Here's the snippet (credited ofcourse)

(*-------------------------------------------------*)
{John Atkins [jatkins@paktel.compulink.co.uk] functions for playing beeps}
function _GetPort(address:word):word;
var
bValue: byte;
begin
asm
mov dx, address
in al, dx
mov bValue, al
end;
Result := bValue;
end;
(*----------------------------------------------*)
procedure _SetPort(address, Value:Word);
var
bValue: byte;
begin
bValue := Trunc(Value and 255);
asm
mov dx, address
mov al, bValue
out dx, al
end;
end;
{end snippet}

and remember that the cmos ports are $70 and $71 and you can hardly go wrong.

Here's the QuickBasic routine to calc the checksum I mentioned: (you should be able to translate that yourself)

{snippet start}
' Written by: TonHu, 1988-1989
SUB SetCheckCMOS (OldChecksum%) ' Update Checksum

SHARED Debug, Quiet

CurrentCheckSum% = ReadCMOS%("C", &H2E) ' Read current word
NewCheckSum = 0
FOR n% = &H10 TO &H2D ' Only checksum this part
NewCheckSum% = NewCheckSum% + ReadCMOS%("B", n%)
NEXT
NewCheckHigh% = INT(NewCheckSum% / 256)
IF Debug THEN PRINT "Checksums :"; NewCheckHigh%;
NewCheckLow% = NewCheckSum% - (NewCheckHigh% * 256)
IF Debug THEN PRINT NewCheckLow%; "("; NewCheckHigh% * 256 + NewCheckLow%; ")"

IF NewCheckSum% <> CurrentCheckSum% THEN
CALL WriteCMOS(&H2E, NewCheckHigh%)
CALL WriteCMOS(&H2F, NewCheckLow%)
IF Debug THEN PRINT &quot;CMOS Checksum updated.&quot;; CurrentCheckSum%; &quot;->&quot;; NewCheckSum%
ELSE
IF Debug THEN PRINT &quot;CMOS Checksum was Ok.&quot;
END IF

END SUB
{end snippet}

Remember, this is from a totally different app, but you should be able to get the hang of it.

HTH, X-)
TonHu
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top