time in pmode

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
Hamza

time in pmode

Post by Hamza »

How can I get second of time in pmode from cmos area? Where is it?
Peter_Vigren

Re:time in pmode

Post by Peter_Vigren »

The second is where it is in real mode; in register 0 of CMOS (minute in reg 2 and hour in reg 4)...
Hamza

Re:time in pmode

Post by Hamza »

What register? Do u mean ports?? Can you give a simple example code to read second?
Peter_Vigren

Re:time in pmode

Post by Peter_Vigren »

Hamza wrote: What register? Do u mean ports?? Can you give a simple example code to read second?
Yes, I mean ports.

Of course.

Code: Select all

In Al,70h??????; Read current NMI status
And Al,10000000b???; Bit 7 controlls NMI, do not modify
Add Al,0??????; CMOS port for second
Out 70h,Al??????; Request value from port (invoke port)
Jmp short $+2??????; Create a tiny delay so port hardware have time
?????????; to recover and be set to the right register
In Al,71h??????; Read value
However, before you try to read the register you should check if the CMOS is updating time...

Code: Select all

CheckIfCMOSUpdateInProgress:
Push Eax
CheckIfCMOSUpdateInProgress_TestBit

In Al,70h??????; Read current NMI status
And Al,10000000b???; Bit 7 controlls NMI, do not modify
Add Al,0xA??????; CMOS port for Status A
Out 70h,Al??????; Request value from port (invoke port)
Jmp short $+2??????; Create a tiny delay so port hardware have time
?????????; to recover and be set to the right register
In Al,71h??????; Read value

Test Al,10000000b???; Test bit 7 - Update In Progress
Jnz CheckIfCMOSUpdateInProgress_TestBit
Pop Eax
Ret
I hope you can read the code even with the comments...

Hm... it may not be so easy to follow... you asked for simple code... Basicly, this is it:

Code: Select all

Mov Al,0
Out 70h,Al
Jmp short $+2
In Al,71h
You send the number of the register you wants to port 0x70 (70h). Then you use a short jmp (that jumps to the next instruction) in order to wait for the data to become available. After that, you read the data at port 0x71 (71h)...
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:time in pmode

Post by Pype.Clicker »

time to remove some mistery about hardware design:

a "register" is a scratch memory area where any kind of binary value may be stored.
when you modify the volume on a soundcard, you actually don't modify the volume itself, but a register on the soundcard that will store the value that the soundcard reuses for volume mixing.

Those registers act the very same way generic register do in the CPU, but as they're located on other chips, you can't access them directly. Instead, the CPU will issue an I./O cycle that will tell "read value from I/O address X" or "store value Y at I/O address X", and the address will be recognized by one of the external chip which will later decode it to find which of its internal registers it maps to ...

In some chips, each "accessible" register has a single I/O address (which is the case for instance for Sound Blaster, or for IDE controllers), while some other chips have so much registers that they actually only "export" two : the "address register" and the "data register". Writing a value in the "address register" tells which internal register should be mapped through the virtual "data register".
VGA cards, for instance, work this way, as does the CMOS chip (afaik)
adeelmahmood1

Re:time in pmode

Post by adeelmahmood1 »

well .. here is all what u need


[attachment deleted by admin]
Post Reply