cmos内存的读写

cmos内存的读写


一、CMOS内存信息详解
一般的PC/AT、286、386、486等微机均配有CMOS芯片,CMOS&127;芯片包含了一个实时钟
和64个字节的CMOS内存。在CMOS内存中,0-0DH为实时钟的有关信息,0E-&127;3FH包含
计算机的硬件配置信息,如常规内存的大小、扩展内存的大小、&127;软盘的类型、固定
盘的类型及其物理参数、显示器的类型等,这些参数与计算机能否正常工作具有密切的
关系,另外还有计算机的开机口令和其它辅助设置信息。表1列出了&127;CMOS内存各字
节的用途。
表1 CMOS内存配置信息的含义
地 址
 功能
 说明
0,1
 秒,秒报警
  
2,3
 分,分报警
  
4,5
 时,时报警
  
6
 星期几
  
7,8,9
 日,月,年
  
A
 状态寄存器A
  
B
 状态寄存器B
  
C
 状态寄存器C
  
D
 状态寄存器D
 0=电池失效,80=电池有效
E
 诊断状态
  
F
 关机状态
 由上电诊断定义
10
 软驱
 高4位为A驱,低4位为B驱,0=无, 1=360KB, 2=1.2KB, 4=1.44KB, 6=720KB
11
 保留
  
12
 固定盘
 高4位为C驱,低4位为D驱,0=无,F=用户定义盘, 其它为系统定义盘
13
 保留
  
14
 设备状态
 标志驱动器数、显示器类型、有无数学处理器等
15-16
 内存
 以KB计的常规内存数,100H=256KB,200H=512KB, 280H=640KB
17-18
 扩展内存
 以KB计的扩展内存数,200H=512KB,400H=1024KB等
19
 C盘类型数
 根据具体硬盘类型而定
1A
 D盘类型数
 根据具体硬盘类型而定
1B-1C
 保留
  
1D-1E
 C盘柱体数
 1D-2CH只有当硬盘为用户自定义类型时起作用
1F
 C盘面数
  
20-21
 C盘WP
  
22-23
 C盘LZ
  
24
 C盘每柱扇区
  
25-26
 D盘柱体数
  
27
 D盘面数
  
28-29
 D盘WP
  
2A-2B
 D盘LZ
  
2C
 D盘每柱扇区
  
2D
 保留
  
2E-2F
 校验和
 为10-2DH共30个字节的和数,2EH为高位,2FH为低位
30-31
 扩展内存
  
32
 日期的世纪数
 BCD码的世纪值,如1995年的世纪数为19
33
 标志信息
  
34-3F
 保留
  
                *地址栏均为16进制表示
二、读写CMOS内存的方法
CMOS内存的地址口和数据口的口地址分别为70H和71H。在对CMOS内存进行写操作时,首先
将要写入的CMOS内存的地址送到口地址70H,&127;再将要写入的数据送口地址71H。在对
CMOS内存进行读操作时,首先将要读出的CMOS内存的地址送到口地址70H,再从口地址71H
读出数据到AL寄存器。
三、程序设计与使用
为了方便系统信息丢失后CMOS信息的恢复,作者用BORLAND PASCAL&127;设计了一个CMOS
.PAS的程序,它可以将CMOS内存中的信息直接写入文件,也可以把文件中的信息写入CMOS
内存,同时可以对CMOS内存中的信息进行编辑修改,并重新写回CMOS内存。它不仅解决了
没有SETUP程序的计算机在加电时不能设置CMOS内存的问题,同时解决了CMOS信息的保存
和恢复问题,是广大计算机用户的一个好帮手。
该程序的使用很简单,在DOS提示符下打CMOS,即显示该程序的使用方法,&127;具体使用
方法是:
CMOS [/开关]
开关有3个:
R --- 读取CMOS内存信息,并将其存入CMOS.DAT的文件,共占64个字节。
W --- 从CMOS.DAT中读取信息,并将其写入CMOS内存。&127;注意这样写入的CMOS信息,其
时间和日期是不正确的,写完之后应当用DOS命令DATE和TIME&127;设置正确的日期和时间

M --- 从CMOS中读取当前信息,进行修改,然后将其写入CMOS内存和CMOS.DAT的文件。
四、程序清单
由于篇幅的限制,程序中略去了用TURBO &127;VISION&127;编写的程序界面部分。
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]);
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.
 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值