Cmos修改程序,请教!!!(100分)

Z

zlwnet

Unregistered / Unconfirmed
GUEST, unregistred user!
以下代码出编译时出错,不能使用。大家能帮我改正出错的地方吗?
program CMOS;
type
TCMOSType = record
Seconds : byte;
SecondAlarm : byte;
Minutes : byte;
MinuteAlarm : byte;
Hours : byte;
HourAlarm : byte;
DayOfWeek : byte;
DayOfMonth : byte;
Month : byte;
Year : byte;
StatusRegA : byte;
StatusRegB : byte;
StatusRegC : byte;
StatusRegD : byte;
DiagStatus : Byte;
ShutDownStatus : Byte;
FloppyDrive : byte;
Reserved1 : byte;
FixedDrive : Byte;
Reserved2 : byte;
Equipment : byte;
RAM : word;
XMS : word;
FixedDriveType1 : byte;
FixedDriveType2 : byte;
Reserved3 : word;
Cylinder1 : word;
Head1 : byte;
WP1 : word;
LZ1 : word;
Sector1 : byte;
Cylinder2 : word;
Head2 : byte;
WP2 : word;
LZ2 : word;
Sector2 : byte;
Sys : byte;
CheckSum : word;
XMS1 : word;
DateCentury : byte;
InfoFlags : byte;
Reserved4: array[1..12] of byte;
end;
TByte64 = array[1..64] of byte;
TCMOS = object
CMOSRec : TCMOSType;
procedure ReadCMOS;
procedure WriteCMOS;
procedure DisplayCMOS;
procedure ModifyCMOS;
procedure ReadFile;
procedure WriteFile;
end;
procedure TCMOS.ReadFile;
var
f1 : file;
data : tbyte64 absolute CMOSRec;
ch : char;
begin
write('Please input the drive name (A/B/C/D): ');
readln(ch);
assign(f1,ch+':/CMOS.DAT');
reset(f1,1);
blockread(f1,data,sizeof(data));
close(f1);
end;
procedure TCMOS.WriteFile;
var
f1:file;
data : tbyte64 absolute CMOSRec;
ch : char;
begin
write('Please input the drive name (A/B/C/D): ');
readln(ch);
assign(f1,ch+':/CMOS.DAT');
rewrite(f1,1);
blockwrite(f1,data,sizeof(data));
close(f1);
end;
procedure TCMOS.ReadCMOS;
begin
asm
les di,self
add di,CMOSRec
MOV CX,40H
MOV AH,0H
MOV BX,0
@1:
MOV DX,70H
MOV AL,AH
OUT DX,AL
INC DX
in AL,dx
MOV BYTE PTR es:[di+BX],al
INC AH
INC BX
DEC CX
JNZ @1
end;
end;
procedure TCMOS.WriteCMOS;
begin
asm
les di,self
add di,CMOSRec
MOV CX,40H
MOV AH,0H
MOV BX,0
@1:
MOV DX,70H
MOV AL,AH
OUT DX,AL
MOV AL,BYTE PTR es:[di+BX]
INC DX
OUT DX,AL
INC AH
INC BX
DEC CX
JNZ @1
end;
end;
procedure TCMOS.DisplayCMOS;
var
hd1,hd2,fd1,fd2 : byte;
begin
Writeln(^J^M'CMOS RAM information:');
writeln('Date(MM-DD-YY): ',CMOSRec.Month shr 4,CMOSRec.Month and $f,
'-',CMOSRec.DayOfMonth shr 4,CMOSRec.DayOfMonth and $f,
'-',CMOSRec.Year shr 4,CMOSRec.Year and $f);
writeln('Time(HH:MM:SS): ',CMOSRec.Hours shr 4,CMOSRec.Hours and $f,
':',CMOSRec.Minutes shr 4,CMOSRec.Minutes and $f,
':',CMOSRec.Seconds shr 4,CMOSRec.Seconds and $f);
writeln('Conventional Memory: ',CMOSRec.Ram,'KB');
writeln('Extended Memory: ',CMOSRec.XMS,'KB');
hd2 := CMOSRec.FixedDrive and $f;
hd1 := CMOSRec.FixedDrive shr 4;
if (hd1 <> 0) then
begin
writeln('Fixed Drive 1: ',CMOSRec.FixedDriveType1);
writeln(' Cylinder : ',CMOSRec.Cylinder1);
writeln(' Head : ',CMOSRec.Head1);
writeln(' Sector: ',CMOSRec.Sector1);
writeln(' LZ: ',CMOSRec.LZ1);
writeln(' WP: ',CMOSRec.WP1);
end;
if (hd2 <> 0) then
begin
writeln('Fixed Drive 2: ',CMOSRec.FixedDriveType2);
writeln(' Cylinder : ',CMOSRec.Cylinder2);
writeln(' Head : ',CMOSRec.Head2);
writeln(' Sector: ',CMOSRec.Sector2);
writeln(' LZ: ',CMOSRec.LZ2);
writeln(' WP: ',CMOSRec.WP2);
end;
fd2 := CMOSRec.FloppyDrive and $f;
fd1 := CMOSRec.FloppyDrive shr 4;
if (fd1 <> 0) then
begin
write('Floppy Drive 1 : ');
case fd1 of
1 : writeln('360KB 5.25''');
2 : writeln('1.2MB 5.25''');
4 : writeln('1.44MB 3.5''');
6 : writeln('720KB 3.5''');
end;
end ;
if (fd2 <> 0) then
begin
write('Floppy Drive 2 : ');
case fd2 of
1 : writeln('360KB 5.25''');
2 : writeln('1.2MB 5.25''');
4 : writeln('1.44MB 3.5''');
6 : writeln('720KB 3.5''');
end;
end;
end;
procedure TCMOS.ModifyCMOS;
var
hd1,hd2,fd1,fd2 : byte;
data : tbyte64 absolute CMOSRec;
i : word;
begin
Writeln('Please input CORRECT CMOS information !');
write('Conventional Memory (',CMOSRec.ram,'KB): ');readln(CMOSRec.ram);
write('Extended Memory (',CMOSRec.XMS,'KB): ');readln(CMOSRec.XMS);
write('Type of Fixed Disk 1: (',CMOSRec.FixedDriveType1,'): ');readln(CMOSRe
c.FixedDriveType1);
write(' Cylinder (',CMOSRec.Cylinder1,'):'); readln(CMOSRec.Cylinder1);
write(' Head (',CMOSRec.Head1,'): ');readln(CMOSRec.Head1);
write(' Sector (',CMOSRec.Sector1,'): ');readln(CMOSRec.Sector1);
write(' LZ (',CMOSRec.LZ1,'): ');readln(CMOSRec.LZ1);
write(' WP (',CMOSRec.WP1,'): ');readln(CMOSRec.WP1);
write('Type of Fixed Disk 2: (',CMOSRec.FixedDriveType2,'): ');readln(CMOSRe
c.FixedDriveType2);
write(' Cylinder (',CMOSRec.Cylinder2,'):'); readln(CMOSRec.Cylinder2);
write(' Head (',CMOSRec.Head2,'): ');readln(CMOSRec.Head2);
write(' Sector (',CMOSRec.Sector2,'): ');readln(CMOSRec.Sector2);
write(' LZ (',CMOSRec.LZ2,'): ');readln(CMOSRec.LZ2);
write(' WP (',CMOSRec.WP2,'): ');readln(CMOSRec.WP2);
hd1 := 0; hd2 :=0;
if (CMOSRec.FixedDriveType1>46) then hd1 := $f;
if (CMOSRec.FixedDriveType2>46) then hd2 := $f;
CMOSRec.FixedDrive := hd1 shl 4 + hd2;
fd2 := CMOSRec.FloppyDrive and $f;
fd1 := CMOSRec.FloppyDrive shr 4;
write('Floppy Drive 1 (');
case fd1 of
1 : write('360KB 5.25''): ');
2 : write('1.2MB 5.25''): ');
4 : write('1.44MB 3.5''): ');
6 : write('720KB 3.5''): ');
end;
readln(fd1);
write('Floppy Drive 2 (');
case fd2 of
1 : write('360KB 5.25''): ');
2 : write('1.2MB 5.25''): ');
4 : write('1.44MB 3.5''): ');
6 : write('720KB 3.5''): ');
end;
readln(fd2);
CMOSRec.FloppyDrive := fd1 shl 4 + fd2;
CMOSRec.CheckSum := 0;
for i := 17 to 46 do inc(CMOSRec.CheckSum,data);
i := CMOSRec.CheckSum;
data[47] := hi(i);
data[48] := lo(i);
end;
procedure help;
begin
WriteLn('Syntex:'+^J^M+
' CMOS /R --- read information from CMOS RAM '+^J^M+
' and write it to CMOS.DAT file '+^J^M+
' CMOS /W --- read configuration information from CMOS.DAT '+^J^M+
' and write it to CMOS RAM');
Writeln(' CMOS /M --- modify CMOS information and save it'^J^M+
' Floppy Drive Type:'+^J^M+
' 1 : 360KB 5.25'''+^J^M+
' 2 : 1.2MB 5.25'''+^J^M+
' 4 : 1.44MB 3.5'''+^J^M+
' 6 : 720KB 3.5''');
end;
var ch : char;
temp : string;
ICMOS : TCMOS;
begin
WriteLn('CMOS Proctector 1.00, Copyright (c) 1995 Dong Zhanshan');
if paramcount = 1 then
begin
temp := paramstr(1);
ch := upcase(temp[2]);
case ch of
'M' : begin
ICMOS.ReadCMOS;
ICMOS.ModifyCMOS;
ICMOS.DisplayCMOS;
ICMOS.WriteFile;
ICMOS.WriteCMOS;
end;
'R' : begin
ICMOS.ReadCMOS;
ICMOS.DisplayCMOS;
ICMOS.WriteFile;

end;
'W' : begin
ICMOS.ReadFile;
ICMOS.DisplayCMOS;
ICMOS.WriteCMOS;
end;
else help;
end;
end
else
help;
end.
 
各位帮帮忙啊
 
没有人试过这个程序吗?
 
控制台程序吧,

不要Main()?
 
这个程序,很久前就有人发表过的,但现才找到,以前就没有人发现过吗?
 
呵呵,你是 2000 吧,2000 下不能直接操作端口的。
随便去什么地方下个操作端口的控件,改一下就可以了。
 
他用的汇编太多,其实几句汇编就可以了,没必要那么多呀
看不懂没关系呀,自己写就行了,很简单的

在Windows2000下不允许直接访问硬件端口地址,
在Win2000下用不成啦
 
我想知道怎么写,LiChaoHui,你给我写一段,好吗?

 
借用一下你的TCMOSType
先定义几个函数
{
CMos的读写原理
CMOS的内存是一块有主板供电的内存
大小为128字节,地址为0x00 --- 0x7f
读或写时先将地址写入索引寄存器,端口号为:$70
然后从数据寄存器读取或写入指定地址的数据 端口号为:$71

另外,在Windows 2000中是不允许直接访问这样的硬件地址的
可以通过其他的工具或组件,自己写驱动程序也可以的
}
function InPort(Port: Integer): Integer;
begin
asm
mov edx, Port
xor eax, eax
in al, dx
mov Result, eax
end;
end;

function OutPort(Port: Integer; Data: Integer): Integer;
begin
asm
mov edx, Port
mov eax, Data
out dx, al
end;
Result := Data and $ff;
end;

function ReadCMos(var CmosData: TCMOSType): Boolean;
var
i: Integer;
Ps: PChar;
begin
Ps := @CmosData;
for i := 0 to SizeOf(CmosData) - 1 do
begin
OutPort($70, i); //设置索引寄存器
Ps := Chr(InPort($71)); //读取当前寄存器数据
end;
end;

function WriteCmos(var CmosData: TCMOSType): Boolean;
var
i: Integer;
Ps: PChar;
begin
Ps := @CmosData;
for i := 0 to SizeOf(CmosData) - 1 do
begin
OutPort($70, i); //设置索引寄存器
OutPort($71, Ord(Ps)); //写当前寄存器
end;
end;

function CmosIsLock: Boolean;
begin
OutPort($70, $?); //在CMos内存中某个字节的某一位为锁定位
//表示此时Cmos内部电路正在修改时钟的时间,不允许写入
//一般情况下,写入时可以跳过Cmos内存中靠前的十几个字节,
//我们一般是不修改时间参数的,同时0x2e, 0x2f保存了之前数据的校验和
Result := (InPort($71) and $?) > 0;
end;
 
改了一下, 应该可以使用

program CMOS;

{$APPTYPE CONSOLE}

uses
SysUtils;

type
TCMOSType = packed record
Seconds : Byte;
SecondAlarm : Byte;
Minutes : Byte;
MinuteAlarm : Byte;
Hours : Byte;
HourAlarm : Byte;
DayOfWeek : Byte;
DayOfMonth : Byte;
Month : Byte;
Year : Byte;

StatusRegA : Byte;
StatusRegB : Byte;
StatusRegC : Byte;
StatusRegD : Byte;
DiagStatus : Byte;

ShutDownStatus : Byte;

FloppyDrive : Byte;
Reserved1 : Byte;

FixedDrive : Byte;
Reserved2 : Byte;

Equipment : Byte;
RAM : Word;
XMS : Word;

FixedDriveType1 : Byte;
FixedDriveType2 : Byte;
Reserved3 : Word;

Cylinder1 : Word;
Head1 : Byte;
WP1 : Word;
LZ1 : Word;
Sector1 : Byte;

Cylinder2 : Word;
Head2 : Byte;
WP2 : Word;
LZ2 : Word;
Sector2 : Byte;

Sys : Byte;
CheckSum : Word;
XMS1 : Word;
DateCentury : Byte;
InfoFlags : Byte;
Reserved4 : array[0..11] of Byte;
end;

PByte64 = ^TByte64;
TByte64 = array[0..63] of Byte;

type
TCMOS = class(TObject)
private
CMOSRec : TCMOSType;

public
procedure ReadCMOS;
procedure WriteCMOS;
procedure DisplayCMOS;
procedure ModifyCMOS;
procedure ReadFile;
procedure WriteFile;
end;


procedure TCMOS.ReadFile;
var
f1 : file;
ch : char;
begin
Write('Please input the drive name (A/B/C/D): ');
Readln(ch);
AssignFile(f1,ch+':/CMOS.DAT');
Reset(f1,1);
BlockRead(f1,CmosRec,sizeof(CmosRec));
CloseFile(f1);
end;

procedure TCMOS.WriteFile;
var
f1 : file;
ch : Char;
begin
Write('Please input the drive name (A/B/C/D): ');
Readln(ch);

AssignFile(f1, ch+':/CMOS.DAT');
Rewrite(f1, 1);
BlockWrite(f1, CmosRec, SizeOf(CmosRec));
CloseFile(f1);
end;

procedure TCMOS.ReadCMOS;
var
P : Pointer;
begin
P := @CMOSRec;

asm
PUSH EAX
PUSH EBX
PUSH ECX
PUSH EDX

MOV CX, 40H
XOR AH, AH
MOV EBX, P
@1:
MOV DX, 70H
MOV AL, AH
OUT DX, AL
INC DX
IN AL, DX
Mov Byte Ptr [EBX], AL
INC AH
INC EBX
DEC CX
JNZ @1

POP EDX
POP ECX
POP EBX
POP EAX
end;
end;

procedure TCMOS.WriteCMOS;
var
P : Pointer;
begin
P := @CMOSRec;

asm
PUSH EAX
PUSH EBX
PUSH ECX
PUSH EDX

MOV EBX, P
MOV CX, 40H
XOR AH, AH
@1:
MOV DX, 70H
MOV AL, AH
OUT DX, AL
MOV AL, BYTE PTR [EBX]
INC DX
OUT DX, AL
INC AH
INC EBX
DEC CX
JNZ @1

POP EDX
POP ECX
POP EBX
POP EAX
end;
end;

procedure TCMOS.DisplayCMOS;
var
hd1,hd2,fd1,fd2 : byte;
begin
Writeln(^J^M'CMOS RAM information:');
writeln('Date(MM-DD-YY): ',CMOSRec.Month shr 4,CMOSRec.Month and $f,
'-',CMOSRec.DayOfMonth shr 4,CMOSRec.DayOfMonth and $f,
'-',CMOSRec.Year shr 4,CMOSRec.Year and $f);
writeln('Time(HH:MM:SS): ',CMOSRec.Hours shr 4,CMOSRec.Hours and $f,
':',CMOSRec.Minutes shr 4,CMOSRec.Minutes and $f,
':',CMOSRec.Seconds shr 4,CMOSRec.Seconds and $f);
writeln('Conventional Memory: ',CMOSRec.Ram,'KB');
writeln('Extended Memory: ',CMOSRec.XMS,'KB');
hd2 := CMOSRec.FixedDrive and $f;
hd1 := CMOSRec.FixedDrive shr 4;
if (hd1 <> 0) then
begin
writeln('Fixed Drive 1: ',CMOSRec.FixedDriveType1);
writeln(' Cylinder : ',CMOSRec.Cylinder1);
writeln(' Head : ',CMOSRec.Head1);
writeln(' Sector: ',CMOSRec.Sector1);
writeln(' LZ: ',CMOSRec.LZ1);
writeln(' WP: ',CMOSRec.WP1);
end;
if (hd2 <> 0) then
begin
writeln('Fixed Drive 2: ',CMOSRec.FixedDriveType2);
writeln(' Cylinder : ',CMOSRec.Cylinder2);
writeln(' Head : ',CMOSRec.Head2);
writeln(' Sector: ',CMOSRec.Sector2);
writeln(' LZ: ',CMOSRec.LZ2);
writeln(' WP: ',CMOSRec.WP2);
end;
fd2 := CMOSRec.FloppyDrive and $f;
fd1 := CMOSRec.FloppyDrive shr 4;
if (fd1 <> 0) then
begin
write('Floppy Drive 1 : ');
case fd1 of
1 : writeln('360KB 5.25''');
2 : writeln('1.2MB 5.25''');
4 : writeln('1.44MB 3.5''');
6 : writeln('720KB 3.5''');
end;
end ;
if (fd2 <> 0) then
begin
write('Floppy Drive 2 : ');
case fd2 of
1 : writeln('360KB 5.25''');
2 : writeln('1.2MB 5.25''');
4 : writeln('1.44MB 3.5''');
6 : writeln('720KB 3.5''');
end;
end;
end;
procedure TCMOS.ModifyCMOS;
var
hd1,hd2,fd1,fd2 : byte;
i : word;
data : ^TByte64;
begin
Writeln('Please input CORRECT CMOS information !');
write('Conventional Memory (',CMOSRec.ram,'KB): ');readln(CMOSRec.ram);
write('Extended Memory (',CMOSRec.XMS,'KB): ');readln(CMOSRec.XMS);
write('Type of Fixed Disk 1: (',CMOSRec.FixedDriveType1,'): ');readln(CMOSRec.FixedDriveType1);
write(' Cylinder (',CMOSRec.Cylinder1,'):'); readln(CMOSRec.Cylinder1);
write(' Head (',CMOSRec.Head1,'): ');readln(CMOSRec.Head1);
write(' Sector (',CMOSRec.Sector1,'): ');readln(CMOSRec.Sector1);
write(' LZ (',CMOSRec.LZ1,'): ');readln(CMOSRec.LZ1);
write(' WP (',CMOSRec.WP1,'): ');readln(CMOSRec.WP1);
write('Type of Fixed Disk 2: (',CMOSRec.FixedDriveType2,'): ');readln(CMOSRec.FixedDriveType2);
write(' Cylinder (',CMOSRec.Cylinder2,'):'); readln(CMOSRec.Cylinder2);
write(' Head (',CMOSRec.Head2,'): ');readln(CMOSRec.Head2);
write(' Sector (',CMOSRec.Sector2,'): ');readln(CMOSRec.Sector2);
write(' LZ (',CMOSRec.LZ2,'): ');readln(CMOSRec.LZ2);
write(' WP (',CMOSRec.WP2,'): ');readln(CMOSRec.WP2);
hd1 := 0; hd2 :=0;
if (CMOSRec.FixedDriveType1>46) then hd1 := $f;
if (CMOSRec.FixedDriveType2>46) then hd2 := $f;
CMOSRec.FixedDrive := hd1 shl 4 + hd2;
fd2 := CMOSRec.FloppyDrive and $f;
fd1 := CMOSRec.FloppyDrive shr 4;
write('Floppy Drive 1 (');
case fd1 of
1 : write('360KB 5.25''): ');
2 : write('1.2MB 5.25''): ');
4 : write('1.44MB 3.5''): ');
6 : write('720KB 3.5''): ');
end;
readln(fd1);
write('Floppy Drive 2 (');
case fd2 of
1 : write('360KB 5.25''): ');
2 : write('1.2MB 5.25''): ');
4 : write('1.44MB 3.5''): ');
6 : write('720KB 3.5''): ');
end;
readln(fd2);
CMOSRec.FloppyDrive := fd1 shl 4 + fd2;
CMOSRec.CheckSum := 0;
data := @CMOSRec;
for i := 17 to 46 do inc(CMOSRec.CheckSum,data^);
i := CMOSRec.CheckSum;
data[47] := hi(i);
data[48] := lo(i);
end;

procedure help;
begin
WriteLn('Syntex:'+^J^M+
' CMOS /R --- read information from CMOS RAM '+^J^M+
' and write it to CMOS.DAT file '+^J^M+
' CMOS /W --- read configuration information from CMOS.DAT '+^J^M+
' and write it to CMOS RAM');
Writeln(' CMOS /M --- modify CMOS information and save it'^J^M+
' Floppy Drive Type:'+^J^M+
' 1 : 360KB 5.25'''+^J^M+
' 2 : 1.2MB 5.25'''+^J^M+
' 4 : 1.44MB 3.5'''+^J^M+
' 6 : 720KB 3.5''');
end;
var ch : char;
temp : string;
ICMOS : TCMOS;
begin
WriteLn('CMOS Proctector 1.00, Copyright (c) 1995 Dong Zhanshan');
ICmos := TCMOS.Create;
if paramcount = 1 then
begin
temp := paramstr(1);
ch := upcase(temp[2]);
case ch of
'M' : begin
ICMOS.ReadCMOS;
ICMOS.ModifyCMOS;
ICMOS.DisplayCMOS;
ICMOS.WriteFile;
ICMOS.WriteCMOS;
end;
'R' : begin
ICMOS.ReadCMOS;
ICMOS.DisplayCMOS;
ICMOS.WriteFile;

end;
'W' : begin
ICMOS.ReadFile;
ICMOS.DisplayCMOS;
ICMOS.WriteCMOS;
end;
else help;
end;
end
else
help;

ICMOS.Free;
end.
 
Beta,Tseug,你有没有更完善的读写CMOS的例子的程序呢?
我可另外再给分,如何???
 
顶部